michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXULTooltipListener_h__ michael@0: #define nsXULTooltipListener_h__ michael@0: michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsIDOMMouseEvent.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsITimer.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: #ifdef MOZ_XUL michael@0: #include "nsITreeBoxObject.h" michael@0: #include "nsITreeColumns.h" michael@0: #endif michael@0: #include "nsWeakPtr.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsIContent; michael@0: michael@0: class nsXULTooltipListener MOZ_FINAL : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: michael@0: void MouseOut(nsIDOMEvent* aEvent); michael@0: void MouseMove(nsIDOMEvent* aEvent); michael@0: michael@0: nsresult AddTooltipSupport(nsIContent* aNode); michael@0: nsresult RemoveTooltipSupport(nsIContent* aNode); michael@0: static nsXULTooltipListener* GetInstance() { michael@0: if (!mInstance) michael@0: mInstance = new nsXULTooltipListener(); michael@0: return mInstance; michael@0: } michael@0: static void ClearTooltipCache() { mInstance = nullptr; } michael@0: michael@0: protected: michael@0: michael@0: nsXULTooltipListener(); michael@0: ~nsXULTooltipListener(); michael@0: michael@0: // pref callback for when the "show tooltips" pref changes michael@0: static bool sShowTooltips; michael@0: static uint32_t sTooltipListenerCount; michael@0: michael@0: void KillTooltipTimer(); michael@0: michael@0: #ifdef MOZ_XUL michael@0: void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent); michael@0: nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject); michael@0: #endif michael@0: michael@0: nsresult ShowTooltip(); michael@0: void LaunchTooltip(); michael@0: nsresult HideTooltip(); michael@0: nsresult DestroyTooltip(); michael@0: // This method tries to find a tooltip for aTarget. michael@0: nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip); michael@0: // This method calls FindTooltip and checks that the tooltip michael@0: // can be really used (i.e. tooltip is not a menu). michael@0: nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip); michael@0: michael@0: static nsXULTooltipListener* mInstance; michael@0: static void ToolbarTipsPrefChanged(const char *aPref, void *aClosure); michael@0: michael@0: nsWeakPtr mSourceNode; michael@0: nsWeakPtr mTargetNode; michael@0: nsWeakPtr mCurrentTooltip; michael@0: michael@0: // a timer for showing the tooltip michael@0: nsCOMPtr mTooltipTimer; michael@0: static void sTooltipCallback (nsITimer* aTimer, void* aListener); michael@0: michael@0: // screen coordinates of the last mousemove event, stored so that the michael@0: // tooltip can be opened at this location. michael@0: int32_t mMouseScreenX, mMouseScreenY; michael@0: michael@0: // various constants for tooltips michael@0: enum { michael@0: kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event michael@0: }; michael@0: michael@0: // flag specifying if the tooltip has already been displayed by a MouseMove michael@0: // event. The flag is reset on MouseOut so that the tooltip will display michael@0: // the next time the mouse enters the node (bug #395668). michael@0: bool mTooltipShownOnce; michael@0: michael@0: #ifdef MOZ_XUL michael@0: // special members for handling trees michael@0: bool mIsSourceTree; michael@0: bool mNeedTitletip; michael@0: int32_t mLastTreeRow; michael@0: nsCOMPtr mLastTreeCol; michael@0: #endif michael@0: }; michael@0: michael@0: #endif // nsXULTooltipListener