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 "XULTreeElement.h"
17 #include "nsIWeakReferenceUtils.h"
18 #include "mozilla/Attributes.h"
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();
46 nsXULTooltipListener();
47 ~nsXULTooltipListener();
49 // pref callback for when the "show tooltips" pref changes
50 static bool sShowTooltips
;
52 void KillTooltipTimer();
55 void CheckTreeBodyMove(mozilla::dom::MouseEvent
* aMouseEvent
);
56 mozilla::dom::XULTreeElement
* GetSourceTree();
59 nsresult
ShowTooltip();
61 nsresult
HideTooltip();
62 nsresult
DestroyTooltip();
63 // This method tries to find a tooltip for aTarget.
64 nsresult
FindTooltip(nsIContent
* aTarget
, nsIContent
** aTooltip
);
65 // This method calls FindTooltip and checks that the tooltip
66 // can be really used (i.e. tooltip is not a menu).
67 nsresult
GetTooltipFor(nsIContent
* aTarget
, nsIContent
** aTooltip
);
69 static nsXULTooltipListener
* sInstance
;
70 static void ToolbarTipsPrefChanged(const char* aPref
, void* aClosure
);
72 nsWeakPtr mSourceNode
;
73 nsWeakPtr mTargetNode
;
74 nsWeakPtr mCurrentTooltip
;
76 // a timer for showing the tooltip
77 nsCOMPtr
<nsITimer
> mTooltipTimer
;
78 static void sTooltipCallback(nsITimer
* aTimer
, void* aListener
);
80 // screen coordinates of the last mousemove event, stored so that the
81 // tooltip can be opened at this location.
82 int32_t mMouseScreenX
, mMouseScreenY
;
84 // various constants for tooltips
86 kTooltipMouseMoveTolerance
= 7 // 7 pixel tolerance for mousemove event
89 // flag specifying if the tooltip has already been displayed by a MouseMove
90 // event. The flag is reset on MouseOut so that the tooltip will display
91 // the next time the mouse enters the node (bug #395668).
92 bool mTooltipShownOnce
;
95 // special members for handling trees
99 RefPtr
<nsTreeColumn
> mLastTreeCol
;
103 #endif // nsXULTooltipListener