1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsXULTooltipListener_h__
39 : #define nsXULTooltipListener_h__
40 :
41 : #include "nsIDOMEventListener.h"
42 : #include "nsIDOMMouseEvent.h"
43 : #include "nsIContent.h"
44 : #include "nsIDOMElement.h"
45 : #include "nsITimer.h"
46 : #include "nsCOMPtr.h"
47 : #include "nsString.h"
48 : #ifdef MOZ_XUL
49 : #include "nsITreeBoxObject.h"
50 : #include "nsITreeColumns.h"
51 : #endif
52 : #include "nsWeakPtr.h"
53 :
54 : class nsXULTooltipListener : public nsIDOMEventListener
55 : {
56 : public:
57 : NS_DECL_ISUPPORTS
58 : NS_DECL_NSIDOMEVENTLISTENER
59 :
60 : void MouseOut(nsIDOMEvent* aEvent);
61 : void MouseMove(nsIDOMEvent* aEvent);
62 :
63 : nsresult AddTooltipSupport(nsIContent* aNode);
64 : nsresult RemoveTooltipSupport(nsIContent* aNode);
65 0 : static nsXULTooltipListener* GetInstance() {
66 0 : if (!mInstance)
67 0 : mInstance = new nsXULTooltipListener();
68 0 : return mInstance;
69 : }
70 0 : static void ClearTooltipCache() { mInstance = nsnull; }
71 :
72 : protected:
73 :
74 : nsXULTooltipListener();
75 : ~nsXULTooltipListener();
76 :
77 : // pref callback for when the "show tooltips" pref changes
78 : static bool sShowTooltips;
79 : static PRUint32 sTooltipListenerCount;
80 :
81 : void KillTooltipTimer();
82 :
83 : #ifdef MOZ_XUL
84 : void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent);
85 : nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject);
86 : #endif
87 :
88 : nsresult ShowTooltip();
89 : void LaunchTooltip();
90 : nsresult HideTooltip();
91 : nsresult DestroyTooltip();
92 : // This method tries to find a tooltip for aTarget.
93 : nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip);
94 : // This method calls FindTooltip and checks that the tooltip
95 : // can be really used (i.e. tooltip is not a menu).
96 : nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip);
97 :
98 : static nsXULTooltipListener* mInstance;
99 : static int ToolbarTipsPrefChanged(const char *aPref, void *aClosure);
100 :
101 : nsWeakPtr mSourceNode;
102 : nsWeakPtr mTargetNode;
103 : nsWeakPtr mCurrentTooltip;
104 :
105 : // a timer for showing the tooltip
106 : nsCOMPtr<nsITimer> mTooltipTimer;
107 : static void sTooltipCallback (nsITimer* aTimer, void* aListener);
108 :
109 : // screen coordinates of the last mousemove event, stored so that the
110 : // tooltip can be opened at this location.
111 : PRInt32 mMouseScreenX, mMouseScreenY;
112 :
113 : // various constants for tooltips
114 : enum {
115 : kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event
116 : };
117 :
118 : // flag specifying if the tooltip has already been displayed by a MouseMove
119 : // event. The flag is reset on MouseOut so that the tooltip will display
120 : // the next time the mouse enters the node (bug #395668).
121 : bool mTooltipShownOnce;
122 :
123 : #ifdef MOZ_XUL
124 : // special members for handling trees
125 : bool mIsSourceTree;
126 : bool mNeedTitletip;
127 : PRInt32 mLastTreeRow;
128 : nsCOMPtr<nsITreeColumn> mLastTreeCol;
129 : #endif
130 : };
131 :
132 : #endif // nsXULTooltipListener
|