2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsXULTooltipListener_h__
|
|
|
|
#define nsXULTooltipListener_h__
|
|
|
|
|
2011-06-30 14:19:40 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsITreeBoxObject.h"
|
|
|
|
#include "nsITreeColumns.h"
|
|
|
|
#endif
|
2008-02-20 11:00:10 -08:00
|
|
|
#include "nsWeakPtr.h"
|
2012-06-18 20:26:34 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-21 17:05:20 -07:00
|
|
|
class nsIContent;
|
|
|
|
|
2012-06-18 20:26:34 -07:00
|
|
|
class nsXULTooltipListener MOZ_FINAL : public nsIDOMEventListener
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2008-02-20 11:00:10 -08:00
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-30 14:19:40 -07:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-30 14:19:40 -07:00
|
|
|
void MouseOut(nsIDOMEvent* aEvent);
|
|
|
|
void MouseMove(nsIDOMEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult AddTooltipSupport(nsIContent* aNode);
|
|
|
|
nsresult RemoveTooltipSupport(nsIContent* aNode);
|
2007-04-12 13:59:01 -07:00
|
|
|
static nsXULTooltipListener* GetInstance() {
|
|
|
|
if (!mInstance)
|
2007-04-25 10:18:50 -07:00
|
|
|
mInstance = new nsXULTooltipListener();
|
2007-04-12 13:59:01 -07:00
|
|
|
return mInstance;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
static void ClearTooltipCache() { mInstance = nullptr; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2007-04-12 13:59:01 -07:00
|
|
|
nsXULTooltipListener();
|
|
|
|
~nsXULTooltipListener();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// pref callback for when the "show tooltips" pref changes
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sShowTooltips;
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t sTooltipListenerCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void KillTooltipTimer();
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent);
|
|
|
|
nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult ShowTooltip();
|
2007-04-16 16:22:34 -07:00
|
|
|
void LaunchTooltip();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult HideTooltip();
|
|
|
|
nsresult DestroyTooltip();
|
|
|
|
// 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).
|
|
|
|
nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip);
|
|
|
|
|
2007-04-12 13:59:01 -07:00
|
|
|
static nsXULTooltipListener* mInstance;
|
2013-12-10 15:10:01 -08:00
|
|
|
static void ToolbarTipsPrefChanged(const char *aPref, void *aClosure);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 11:00:10 -08:00
|
|
|
nsWeakPtr mSourceNode;
|
|
|
|
nsWeakPtr mTargetNode;
|
|
|
|
nsWeakPtr mCurrentTooltip;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// a timer for showing the tooltip
|
|
|
|
nsCOMPtr<nsITimer> mTooltipTimer;
|
|
|
|
static void sTooltipCallback (nsITimer* aTimer, void* aListener);
|
2008-02-20 12:16:55 -08:00
|
|
|
|
|
|
|
// screen coordinates of the last mousemove event, stored so that the
|
|
|
|
// tooltip can be opened at this location.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mMouseScreenX, mMouseScreenY;
|
2008-02-20 12:16:55 -08:00
|
|
|
|
2009-04-12 11:06:22 -07:00
|
|
|
// various constants for tooltips
|
2007-03-22 10:30:00 -07:00
|
|
|
enum {
|
2011-12-19 19:46:39 -08:00
|
|
|
kTooltipMouseMoveTolerance = 7 // 7 pixel tolerance for mousemove event
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-04-12 11:06:22 -07: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-28 23:19:26 -07:00
|
|
|
bool mTooltipShownOnce;
|
2009-04-12 11:06:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// special members for handling trees
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsSourceTree;
|
|
|
|
bool mNeedTitletip;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mLastTreeRow;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsITreeColumn> mLastTreeCol;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXULTooltipListener
|