Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsXULTooltipListener_h__
7 : #define nsXULTooltipListener_h__
8 :
9 : #include "nsIDOMEventListener.h"
10 : #include "nsIDOMMouseEvent.h"
11 : #include "nsIDOMElement.h"
12 : #include "nsITimer.h"
13 : #include "nsCOMPtr.h"
14 : #include "nsString.h"
15 : #ifdef MOZ_XUL
16 : #include "nsITreeBoxObject.h"
17 : #include "nsITreeColumns.h"
18 : #endif
19 : #include "nsWeakPtr.h"
20 : #include "mozilla/Attributes.h"
21 :
22 : class nsIContent;
23 :
24 : class nsXULTooltipListener final : public nsIDOMEventListener
25 : {
26 : public:
27 : NS_DECL_ISUPPORTS
28 : NS_DECL_NSIDOMEVENTLISTENER
29 :
30 : void MouseOut(nsIDOMEvent* aEvent);
31 : void MouseMove(nsIDOMEvent* aEvent);
32 :
33 : nsresult AddTooltipSupport(nsIContent* aNode);
34 : nsresult RemoveTooltipSupport(nsIContent* aNode);
35 60 : static nsXULTooltipListener* GetInstance() {
36 60 : if (!mInstance)
37 1 : mInstance = new nsXULTooltipListener();
38 60 : return mInstance;
39 : }
40 0 : static void ClearTooltipCache() { mInstance = nullptr; }
41 :
42 : protected:
43 :
44 : nsXULTooltipListener();
45 : ~nsXULTooltipListener();
46 :
47 : // pref callback for when the "show tooltips" pref changes
48 : static bool sShowTooltips;
49 : static uint32_t sTooltipListenerCount;
50 :
51 : void KillTooltipTimer();
52 :
53 : #ifdef MOZ_XUL
54 : void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent);
55 : nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject);
56 : #endif
57 :
58 : nsresult ShowTooltip();
59 : void LaunchTooltip();
60 : nsresult HideTooltip();
61 : nsresult DestroyTooltip();
62 : // This method tries to find a tooltip for aTarget.
63 : nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip);
64 : // This method calls FindTooltip and checks that the tooltip
65 : // can be really used (i.e. tooltip is not a menu).
66 : nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip);
67 :
68 : static nsXULTooltipListener* mInstance;
69 : static void ToolbarTipsPrefChanged(const char *aPref, void *aClosure);
70 :
71 : nsWeakPtr mSourceNode;
72 : nsWeakPtr mTargetNode;
73 : nsWeakPtr mCurrentTooltip;
74 :
75 : // a timer for showing the tooltip
76 : nsCOMPtr<nsITimer> mTooltipTimer;
77 : static void sTooltipCallback (nsITimer* aTimer, void* aListener);
78 :
79 : // screen coordinates of the last mousemove event, stored so that the
80 : // tooltip can be opened at this location.
81 : int32_t mMouseScreenX, mMouseScreenY;
82 :
83 : // various constants for tooltips
84 : enum {
85 : kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event
86 : };
87 :
88 : // flag specifying if the tooltip has already been displayed by a MouseMove
89 : // event. The flag is reset on MouseOut so that the tooltip will display
90 : // the next time the mouse enters the node (bug #395668).
91 : bool mTooltipShownOnce;
92 :
93 : #ifdef MOZ_XUL
94 : // special members for handling trees
95 : bool mIsSourceTree;
96 : bool mNeedTitletip;
97 : int32_t mLastTreeRow;
98 : nsCOMPtr<nsITreeColumn> mLastTreeCol;
99 : #endif
100 : };
101 :
102 : #endif // nsXULTooltipListener
|