2001-12-05 02:45:22 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-12-05 02:45:22 +03:00
|
|
|
|
|
|
|
#ifndef nsXULTooltipListener_h__
|
|
|
|
#define nsXULTooltipListener_h__
|
|
|
|
|
2011-07-01 01:19:40 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2001-12-05 02:45:22 +03:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsITimer.h"
|
2001-12-08 03:24:23 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-12-05 02:45:22 +03:00
|
|
|
#include "nsString.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsITreeBoxObject.h"
|
2004-04-17 09:53:38 +04:00
|
|
|
#include "nsITreeColumns.h"
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2008-02-20 22:00:10 +03:00
|
|
|
#include "nsWeakPtr.h"
|
2012-06-19 07:26:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2001-12-05 02:45:22 +03:00
|
|
|
|
2013-03-22 04:05:20 +04:00
|
|
|
class nsIContent;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXULTooltipListener final : public nsIDOMEventListener
|
2001-12-05 02:45:22 +03:00
|
|
|
{
|
|
|
|
public:
|
2008-02-20 22:00:10 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2011-07-01 01:19:40 +04:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2001-12-05 02:45:22 +03:00
|
|
|
|
2011-07-01 01:19:40 +04:00
|
|
|
void MouseOut(nsIDOMEvent* aEvent);
|
|
|
|
void MouseMove(nsIDOMEvent* aEvent);
|
2001-12-05 02:45:22 +03:00
|
|
|
|
|
|
|
nsresult AddTooltipSupport(nsIContent* aNode);
|
|
|
|
nsresult RemoveTooltipSupport(nsIContent* aNode);
|
2007-04-13 00:59:01 +04:00
|
|
|
static nsXULTooltipListener* GetInstance() {
|
|
|
|
if (!mInstance)
|
2007-04-25 21:18:50 +04:00
|
|
|
mInstance = new nsXULTooltipListener();
|
2007-04-13 00:59:01 +04:00
|
|
|
return mInstance;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
static void ClearTooltipCache() { mInstance = nullptr; }
|
2001-12-05 02:45:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2007-04-13 00:59:01 +04:00
|
|
|
nsXULTooltipListener();
|
|
|
|
~nsXULTooltipListener();
|
|
|
|
|
2001-12-05 02:45:22 +03:00
|
|
|
// pref callback for when the "show tooltips" pref changes
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sShowTooltips;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sTooltipListenerCount;
|
2001-12-05 02:45:22 +03:00
|
|
|
|
|
|
|
void KillTooltipTimer();
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent);
|
|
|
|
nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject);
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2001-12-05 02:45:22 +03:00
|
|
|
|
|
|
|
nsresult ShowTooltip();
|
2007-04-17 03:22:34 +04:00
|
|
|
void LaunchTooltip();
|
2001-12-05 02:45:22 +03:00
|
|
|
nsresult HideTooltip();
|
|
|
|
nsresult DestroyTooltip();
|
2006-08-02 12:24:21 +04:00
|
|
|
// This method tries to find a tooltip for aTarget.
|
|
|
|
nsresult FindTooltip(nsIContent* aTarget, nsIContent** aTooltip);
|
|
|
|
// This method calls FindTooltip and checks that the tooltip
|
|
|
|
// can be really used (i.e. tooltip is not a menu).
|
2001-12-05 02:45:22 +03:00
|
|
|
nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip);
|
|
|
|
|
2007-04-13 00:59:01 +04:00
|
|
|
static nsXULTooltipListener* mInstance;
|
2013-12-11 03:10:01 +04:00
|
|
|
static void ToolbarTipsPrefChanged(const char *aPref, void *aClosure);
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2008-02-20 22:00:10 +03:00
|
|
|
nsWeakPtr mSourceNode;
|
|
|
|
nsWeakPtr mTargetNode;
|
|
|
|
nsWeakPtr mCurrentTooltip;
|
2001-12-05 02:45:22 +03:00
|
|
|
|
|
|
|
// a timer for showing the tooltip
|
|
|
|
nsCOMPtr<nsITimer> mTooltipTimer;
|
|
|
|
static void sTooltipCallback (nsITimer* aTimer, void* aListener);
|
2008-02-20 23:16:55 +03:00
|
|
|
|
|
|
|
// screen coordinates of the last mousemove event, stored so that the
|
|
|
|
// tooltip can be opened at this location.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mMouseScreenX, mMouseScreenY;
|
2008-02-20 23:16:55 +03:00
|
|
|
|
2009-04-12 22:06:22 +04:00
|
|
|
// various constants for tooltips
|
2001-12-05 02:45:22 +03:00
|
|
|
enum {
|
2011-12-20 07:46:39 +04:00
|
|
|
kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event
|
2001-12-05 02:45:22 +03:00
|
|
|
};
|
|
|
|
|
2009-04-12 22:06:22 +04:00
|
|
|
// flag specifying if the tooltip has already been displayed by a MouseMove
|
|
|
|
// event. The flag is reset on MouseOut so that the tooltip will display
|
|
|
|
// the next time the mouse enters the node (bug #395668).
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mTooltipShownOnce;
|
2009-04-12 22:06:22 +04:00
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
// special members for handling trees
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsSourceTree;
|
|
|
|
bool mNeedTitletip;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mLastTreeRow;
|
2004-04-17 09:53:38 +04:00
|
|
|
nsCOMPtr<nsITreeColumn> mLastTreeCol;
|
2003-04-11 04:56:27 +04:00
|
|
|
#endif
|
2001-12-05 02:45:22 +03:00
|
|
|
};
|
|
|
|
|
2001-12-05 08:19:53 +03:00
|
|
|
#endif // nsXULTooltipListener
|