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/. */ 6 7 #ifndef nsXULTooltipListener_h__ 8 #define nsXULTooltipListener_h__ 9 10 #include "nsIDOMEventListener.h" 11 #include "nsITimer.h" 12 #include "nsCOMPtr.h" 13 #include "nsString.h" 14 #include "XULTreeElement.h" 15 #include "nsIWeakReferenceUtils.h" 16 #include "mozilla/Attributes.h" 17 18 class nsIContent; 19 class nsTreeColumn; 20 21 namespace mozilla { 22 namespace dom { 23 class Event; 24 class MouseEvent; 25 } // namespace dom 26 } // namespace mozilla 27 28 class nsXULTooltipListener final : public nsIDOMEventListener { 29 public: 30 NS_DECL_ISUPPORTS 31 NS_DECL_NSIDOMEVENTLISTENER 32 33 void MouseOut(mozilla::dom::Event* aEvent); 34 void MouseMove(mozilla::dom::Event* aEvent); 35 36 void AddTooltipSupport(nsIContent* aNode); 37 void RemoveTooltipSupport(nsIContent* aNode); GetInstance()38 static nsXULTooltipListener* GetInstance() { 39 if (!sInstance) sInstance = new nsXULTooltipListener(); 40 return sInstance; 41 } 42 43 protected: 44 nsXULTooltipListener(); 45 ~nsXULTooltipListener(); 46 47 // pref callback for when the "show tooltips" pref changes 48 static bool sShowTooltips; 49 50 void KillTooltipTimer(); 51 52 void CheckTreeBodyMove(mozilla::dom::MouseEvent* aMouseEvent); 53 mozilla::dom::XULTreeElement* GetSourceTree(); 54 55 nsresult ShowTooltip(); 56 void LaunchTooltip(); 57 nsresult HideTooltip(); 58 nsresult DestroyTooltip(); 59 // This method tries to find a tooltip for aTarget. 60 nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip); 61 // This method calls FindTooltip and checks that the tooltip 62 // can be really used (i.e. tooltip is not a menu). 63 nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip); 64 65 static nsXULTooltipListener* sInstance; 66 static void ToolbarTipsPrefChanged(const char* aPref, void* aClosure); 67 68 nsWeakPtr mSourceNode; 69 nsWeakPtr mTargetNode; 70 nsWeakPtr mCurrentTooltip; 71 nsWeakPtr mPreviousMouseMoveTarget; 72 73 // a timer for showing the tooltip 74 nsCOMPtr<nsITimer> mTooltipTimer; 75 static void sTooltipCallback(nsITimer* aTimer, void* aListener); 76 77 // Screen coordinates of the last mousemove event, stored so that the tooltip 78 // can be opened at this location. 79 // 80 // TODO(emilio): This duplicates a lot of code with ChromeTooltipListener. 81 mozilla::CSSIntPoint mMouseScreenPoint; 82 // Tolerance for mousemove event 83 static constexpr mozilla::CSSIntCoord kTooltipMouseMoveTolerance = 7; 84 85 // flag specifying if the tooltip has already been displayed by a MouseMove 86 // event. The flag is reset on MouseOut so that the tooltip will display 87 // the next time the mouse enters the node (bug #395668). 88 bool mTooltipShownOnce; 89 90 // special members for handling trees 91 bool mIsSourceTree; 92 bool mNeedTitletip; 93 int32_t mLastTreeRow; 94 RefPtr<nsTreeColumn> mLastTreeCol; 95 }; 96 97 #endif // nsXULTooltipListener 98