1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/xul/nsXULTooltipListener.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsXULTooltipListener_h__ 1.10 +#define nsXULTooltipListener_h__ 1.11 + 1.12 +#include "nsIDOMEventListener.h" 1.13 +#include "nsIDOMMouseEvent.h" 1.14 +#include "nsIDOMElement.h" 1.15 +#include "nsITimer.h" 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsString.h" 1.18 +#ifdef MOZ_XUL 1.19 +#include "nsITreeBoxObject.h" 1.20 +#include "nsITreeColumns.h" 1.21 +#endif 1.22 +#include "nsWeakPtr.h" 1.23 +#include "mozilla/Attributes.h" 1.24 + 1.25 +class nsIContent; 1.26 + 1.27 +class nsXULTooltipListener MOZ_FINAL : public nsIDOMEventListener 1.28 +{ 1.29 +public: 1.30 + NS_DECL_ISUPPORTS 1.31 + NS_DECL_NSIDOMEVENTLISTENER 1.32 + 1.33 + void MouseOut(nsIDOMEvent* aEvent); 1.34 + void MouseMove(nsIDOMEvent* aEvent); 1.35 + 1.36 + nsresult AddTooltipSupport(nsIContent* aNode); 1.37 + nsresult RemoveTooltipSupport(nsIContent* aNode); 1.38 + static nsXULTooltipListener* GetInstance() { 1.39 + if (!mInstance) 1.40 + mInstance = new nsXULTooltipListener(); 1.41 + return mInstance; 1.42 + } 1.43 + static void ClearTooltipCache() { mInstance = nullptr; } 1.44 + 1.45 +protected: 1.46 + 1.47 + nsXULTooltipListener(); 1.48 + ~nsXULTooltipListener(); 1.49 + 1.50 + // pref callback for when the "show tooltips" pref changes 1.51 + static bool sShowTooltips; 1.52 + static uint32_t sTooltipListenerCount; 1.53 + 1.54 + void KillTooltipTimer(); 1.55 + 1.56 +#ifdef MOZ_XUL 1.57 + void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent); 1.58 + nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject); 1.59 +#endif 1.60 + 1.61 + nsresult ShowTooltip(); 1.62 + void LaunchTooltip(); 1.63 + nsresult HideTooltip(); 1.64 + nsresult DestroyTooltip(); 1.65 + // This method tries to find a tooltip for aTarget. 1.66 + nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip); 1.67 + // This method calls FindTooltip and checks that the tooltip 1.68 + // can be really used (i.e. tooltip is not a menu). 1.69 + nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip); 1.70 + 1.71 + static nsXULTooltipListener* mInstance; 1.72 + static void ToolbarTipsPrefChanged(const char *aPref, void *aClosure); 1.73 + 1.74 + nsWeakPtr mSourceNode; 1.75 + nsWeakPtr mTargetNode; 1.76 + nsWeakPtr mCurrentTooltip; 1.77 + 1.78 + // a timer for showing the tooltip 1.79 + nsCOMPtr<nsITimer> mTooltipTimer; 1.80 + static void sTooltipCallback (nsITimer* aTimer, void* aListener); 1.81 + 1.82 + // screen coordinates of the last mousemove event, stored so that the 1.83 + // tooltip can be opened at this location. 1.84 + int32_t mMouseScreenX, mMouseScreenY; 1.85 + 1.86 + // various constants for tooltips 1.87 + enum { 1.88 + kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event 1.89 + }; 1.90 + 1.91 + // flag specifying if the tooltip has already been displayed by a MouseMove 1.92 + // event. The flag is reset on MouseOut so that the tooltip will display 1.93 + // the next time the mouse enters the node (bug #395668). 1.94 + bool mTooltipShownOnce; 1.95 + 1.96 +#ifdef MOZ_XUL 1.97 + // special members for handling trees 1.98 + bool mIsSourceTree; 1.99 + bool mNeedTitletip; 1.100 + int32_t mLastTreeRow; 1.101 + nsCOMPtr<nsITreeColumn> mLastTreeCol; 1.102 +#endif 1.103 +}; 1.104 + 1.105 +#endif // nsXULTooltipListener