1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsXULTooltipListener_h__
8 #define nsXULTooltipListener_h__
10 #include "nsIDOMEventListener.h"
15 #include "nsIWeakReferenceUtils.h"
16 #include "mozilla/Attributes.h"
27 class WidgetKeyboardEvent
;
28 } // namespace mozilla
30 class nsXULTooltipListener final
: public nsIDOMEventListener
{
33 NS_DECL_NSIDOMEVENTLISTENER
35 void MouseOut(mozilla::dom::Event
* aEvent
);
36 void MouseMove(mozilla::dom::Event
* aEvent
);
38 void AddTooltipSupport(nsIContent
* aNode
);
39 void RemoveTooltipSupport(nsIContent
* aNode
);
40 static nsXULTooltipListener
* GetInstance() {
41 if (!sInstance
) sInstance
= new nsXULTooltipListener();
45 static bool KeyEventHidesTooltip(const mozilla::WidgetKeyboardEvent
&);
46 static bool ShowTooltips();
49 nsXULTooltipListener();
50 ~nsXULTooltipListener();
52 void KillTooltipTimer();
54 void CheckTreeBodyMove(mozilla::dom::MouseEvent
* aMouseEvent
);
55 mozilla::dom::XULTreeElement
* GetSourceTree();
57 nsresult
ShowTooltip();
59 nsresult
HideTooltip();
60 nsresult
DestroyTooltip();
61 // This method tries to find a tooltip for aTarget.
62 nsresult
FindTooltip(nsIContent
* aTarget
, nsIContent
** aTooltip
);
63 // This method calls FindTooltip and checks that the tooltip
64 // can be really used (i.e. tooltip is not a menu).
65 nsresult
GetTooltipFor(nsIContent
* aTarget
, nsIContent
** aTooltip
);
67 static nsXULTooltipListener
* sInstance
;
69 nsWeakPtr mSourceNode
;
70 nsWeakPtr mTargetNode
;
71 nsWeakPtr mCurrentTooltip
;
72 nsWeakPtr mPreviousMouseMoveTarget
;
74 // a timer for showing the tooltip
75 nsCOMPtr
<nsITimer
> mTooltipTimer
;
76 static void sTooltipCallback(nsITimer
* aTimer
, void* aListener
);
78 // Screen coordinates of the last mousemove event, stored so that the tooltip
79 // can be opened at this location.
81 // TODO(emilio): This duplicates a lot of code with ChromeTooltipListener.
82 mozilla::LayoutDeviceIntPoint mMouseScreenPoint
;
84 // Tolerance for mousemove event
85 static constexpr mozilla::LayoutDeviceIntCoord kTooltipMouseMoveTolerance
= 7;
87 // flag specifying if the tooltip has already been displayed by a MouseMove
88 // event. The flag is reset on MouseOut so that the tooltip will display
89 // the next time the mouse enters the node (bug #395668).
90 bool mTooltipShownOnce
;
92 // special members for handling trees
96 RefPtr
<nsTreeColumn
> mLastTreeCol
;
99 #endif // nsXULTooltipListener