gecko/layout/xul/nsXULTooltipListener.cpp
Robert O'Callahan 25007d1b83 Bug 945091. Part 3: Flatten layout/xul/base/* into layout/xul. r=glandium
--HG--
rename : layout/xul/base/src/crashtests/131008-1.xul => layout/xul/crashtests/131008-1.xul
rename : layout/xul/base/src/crashtests/137216-1.xul => layout/xul/crashtests/137216-1.xul
rename : layout/xul/base/src/crashtests/140218-1.xml => layout/xul/crashtests/140218-1.xml
rename : layout/xul/base/src/crashtests/151826-1.xul => layout/xul/crashtests/151826-1.xul
rename : layout/xul/base/src/crashtests/168724-1.xul => layout/xul/crashtests/168724-1.xul
rename : layout/xul/base/src/crashtests/189814-1.xul => layout/xul/crashtests/189814-1.xul
rename : layout/xul/base/src/crashtests/237787-1.xul => layout/xul/crashtests/237787-1.xul
rename : layout/xul/base/src/crashtests/265161-1.xul => layout/xul/crashtests/265161-1.xul
rename : layout/xul/base/src/crashtests/289410-1.xul => layout/xul/crashtests/289410-1.xul
rename : layout/xul/base/src/crashtests/291702-1.xul => layout/xul/crashtests/291702-1.xul
rename : layout/xul/base/src/crashtests/291702-2.xul => layout/xul/crashtests/291702-2.xul
rename : layout/xul/base/src/crashtests/291702-3.xul => layout/xul/crashtests/291702-3.xul
rename : layout/xul/base/src/crashtests/294371-1.xul => layout/xul/crashtests/294371-1.xul
rename : layout/xul/base/src/crashtests/311457-1.html => layout/xul/crashtests/311457-1.html
rename : layout/xul/base/src/crashtests/321056-1.xhtml => layout/xul/crashtests/321056-1.xhtml
rename : layout/xul/base/src/crashtests/322786-1.xul => layout/xul/crashtests/322786-1.xul
rename : layout/xul/base/src/crashtests/325377.xul => layout/xul/crashtests/325377.xul
rename : layout/xul/base/src/crashtests/326834-1-inner.xul => layout/xul/crashtests/326834-1-inner.xul
rename : layout/xul/base/src/crashtests/326834-1.html => layout/xul/crashtests/326834-1.html
rename : layout/xul/base/src/crashtests/326879-1.xul => layout/xul/crashtests/326879-1.xul
rename : layout/xul/base/src/crashtests/327776-1.xul => layout/xul/crashtests/327776-1.xul
rename : layout/xul/base/src/crashtests/328135-1.xul => layout/xul/crashtests/328135-1.xul
rename : layout/xul/base/src/crashtests/329327-1.xul => layout/xul/crashtests/329327-1.xul
rename : layout/xul/base/src/crashtests/329407-1.xml => layout/xul/crashtests/329407-1.xml
rename : layout/xul/base/src/crashtests/329477-1.xhtml => layout/xul/crashtests/329477-1.xhtml
rename : layout/xul/base/src/crashtests/336962-1.xul => layout/xul/crashtests/336962-1.xul
rename : layout/xul/base/src/crashtests/344228-1.xul => layout/xul/crashtests/344228-1.xul
rename : layout/xul/base/src/crashtests/346083-1.xul => layout/xul/crashtests/346083-1.xul
rename : layout/xul/base/src/crashtests/346281-1.xul => layout/xul/crashtests/346281-1.xul
rename : layout/xul/base/src/crashtests/350460.xul => layout/xul/crashtests/350460.xul
rename : layout/xul/base/src/crashtests/360642-1.xul => layout/xul/crashtests/360642-1.xul
rename : layout/xul/base/src/crashtests/365151.xul => layout/xul/crashtests/365151.xul
rename : layout/xul/base/src/crashtests/366112-1.xul => layout/xul/crashtests/366112-1.xul
rename : layout/xul/base/src/crashtests/369942-1.xhtml => layout/xul/crashtests/369942-1.xhtml
rename : layout/xul/base/src/crashtests/374102-1.xul => layout/xul/crashtests/374102-1.xul
rename : layout/xul/base/src/crashtests/376137-1.html => layout/xul/crashtests/376137-1.html
rename : layout/xul/base/src/crashtests/376137-2.html => layout/xul/crashtests/376137-2.html
rename : layout/xul/base/src/crashtests/377592-1.svg => layout/xul/crashtests/377592-1.svg
rename : layout/xul/base/src/crashtests/381862.html => layout/xul/crashtests/381862.html
rename : layout/xul/base/src/crashtests/382746-1.xul => layout/xul/crashtests/382746-1.xul
rename : layout/xul/base/src/crashtests/382899-1.xul => layout/xul/crashtests/382899-1.xul
rename : layout/xul/base/src/crashtests/383236-1.xul => layout/xul/crashtests/383236-1.xul
rename : layout/xul/base/src/crashtests/384037-1.xhtml => layout/xul/crashtests/384037-1.xhtml
rename : layout/xul/base/src/crashtests/384105-1-inner.xul => layout/xul/crashtests/384105-1-inner.xul
rename : layout/xul/base/src/crashtests/384105-1.html => layout/xul/crashtests/384105-1.html
rename : layout/xul/base/src/crashtests/384491-1.xhtml => layout/xul/crashtests/384491-1.xhtml
rename : layout/xul/base/src/crashtests/384871-1-inner.xul => layout/xul/crashtests/384871-1-inner.xul
rename : layout/xul/base/src/crashtests/384871-1.html => layout/xul/crashtests/384871-1.html
rename : layout/xul/base/src/crashtests/387033-1.xhtml => layout/xul/crashtests/387033-1.xhtml
rename : layout/xul/base/src/crashtests/387080-1.xul => layout/xul/crashtests/387080-1.xul
rename : layout/xul/base/src/crashtests/391974-1-inner.xul => layout/xul/crashtests/391974-1-inner.xul
rename : layout/xul/base/src/crashtests/391974-1.html => layout/xul/crashtests/391974-1.html
rename : layout/xul/base/src/crashtests/394120-1.xhtml => layout/xul/crashtests/394120-1.xhtml
rename : layout/xul/base/src/crashtests/397293.xhtml => layout/xul/crashtests/397293.xhtml
rename : layout/xul/base/src/crashtests/397304-1.html => layout/xul/crashtests/397304-1.html
rename : layout/xul/base/src/crashtests/398326-1.xhtml => layout/xul/crashtests/398326-1.xhtml
rename : layout/xul/base/src/crashtests/399013.xul => layout/xul/crashtests/399013.xul
rename : layout/xul/base/src/crashtests/400779-1.xhtml => layout/xul/crashtests/400779-1.xhtml
rename : layout/xul/base/src/crashtests/402912-1.xhtml => layout/xul/crashtests/402912-1.xhtml
rename : layout/xul/base/src/crashtests/408904-1.xul => layout/xul/crashtests/408904-1.xul
rename : layout/xul/base/src/crashtests/412479-1.xhtml => layout/xul/crashtests/412479-1.xhtml
rename : layout/xul/base/src/crashtests/415394-1.xhtml => layout/xul/crashtests/415394-1.xhtml
rename : layout/xul/base/src/crashtests/420424-1.xul => layout/xul/crashtests/420424-1.xul
rename : layout/xul/base/src/crashtests/430356-1.xhtml => layout/xul/crashtests/430356-1.xhtml
rename : layout/xul/base/src/crashtests/431738.xhtml => layout/xul/crashtests/431738.xhtml
rename : layout/xul/base/src/crashtests/432058-1.xul => layout/xul/crashtests/432058-1.xul
rename : layout/xul/base/src/crashtests/432068-1.xul => layout/xul/crashtests/432068-1.xul
rename : layout/xul/base/src/crashtests/432068-2.xul => layout/xul/crashtests/432068-2.xul
rename : layout/xul/base/src/crashtests/433296-1.xul => layout/xul/crashtests/433296-1.xul
rename : layout/xul/base/src/crashtests/433429.xul => layout/xul/crashtests/433429.xul
rename : layout/xul/base/src/crashtests/434458-1.xul => layout/xul/crashtests/434458-1.xul
rename : layout/xul/base/src/crashtests/452185.html => layout/xul/crashtests/452185.html
rename : layout/xul/base/src/crashtests/452185.xml => layout/xul/crashtests/452185.xml
rename : layout/xul/base/src/crashtests/460900-1.xul => layout/xul/crashtests/460900-1.xul
rename : layout/xul/base/src/crashtests/464149-1.xul => layout/xul/crashtests/464149-1.xul
rename : layout/xul/base/src/crashtests/464407-1.xhtml => layout/xul/crashtests/464407-1.xhtml
rename : layout/xul/base/src/crashtests/467080.xul => layout/xul/crashtests/467080.xul
rename : layout/xul/base/src/crashtests/467481-1.xul => layout/xul/crashtests/467481-1.xul
rename : layout/xul/base/src/crashtests/470063-1.html => layout/xul/crashtests/470063-1.html
rename : layout/xul/base/src/crashtests/470272.html => layout/xul/crashtests/470272.html
rename : layout/xul/base/src/crashtests/472189.xul => layout/xul/crashtests/472189.xul
rename : layout/xul/base/src/crashtests/475133.html => layout/xul/crashtests/475133.html
rename : layout/xul/base/src/crashtests/488210-1.xhtml => layout/xul/crashtests/488210-1.xhtml
rename : layout/xul/base/src/crashtests/495728-1.xul => layout/xul/crashtests/495728-1.xul
rename : layout/xul/base/src/crashtests/508927-1.xul => layout/xul/crashtests/508927-1.xul
rename : layout/xul/base/src/crashtests/508927-2.xul => layout/xul/crashtests/508927-2.xul
rename : layout/xul/base/src/crashtests/514300-1.xul => layout/xul/crashtests/514300-1.xul
rename : layout/xul/base/src/crashtests/536931-1.xhtml => layout/xul/crashtests/536931-1.xhtml
rename : layout/xul/base/src/crashtests/538308-1.xul => layout/xul/crashtests/538308-1.xul
rename : layout/xul/base/src/crashtests/557174-1.xml => layout/xul/crashtests/557174-1.xml
rename : layout/xul/base/src/crashtests/564705-1.xul => layout/xul/crashtests/564705-1.xul
rename : layout/xul/base/src/crashtests/583957-1.html => layout/xul/crashtests/583957-1.html
rename : layout/xul/base/src/crashtests/crashtests.list => layout/xul/crashtests/crashtests.list
rename : layout/xul/base/src/crashtests/menulist-focused.xhtml => layout/xul/crashtests/menulist-focused.xhtml
rename : layout/xul/base/src/moz.build => layout/xul/moz.build
rename : layout/xul/base/src/nsBox.cpp => layout/xul/nsBox.cpp
rename : layout/xul/base/src/nsBox.h => layout/xul/nsBox.h
rename : layout/xul/base/src/nsBoxFrame.cpp => layout/xul/nsBoxFrame.cpp
rename : layout/xul/base/src/nsBoxFrame.h => layout/xul/nsBoxFrame.h
rename : layout/xul/base/src/nsBoxLayout.cpp => layout/xul/nsBoxLayout.cpp
rename : layout/xul/base/src/nsBoxLayout.h => layout/xul/nsBoxLayout.h
rename : layout/xul/base/src/nsBoxLayoutState.cpp => layout/xul/nsBoxLayoutState.cpp
rename : layout/xul/base/src/nsBoxLayoutState.h => layout/xul/nsBoxLayoutState.h
rename : layout/xul/base/src/nsBoxObject.cpp => layout/xul/nsBoxObject.cpp
rename : layout/xul/base/src/nsBoxObject.h => layout/xul/nsBoxObject.h
rename : layout/xul/base/src/nsButtonBoxFrame.cpp => layout/xul/nsButtonBoxFrame.cpp
rename : layout/xul/base/src/nsButtonBoxFrame.h => layout/xul/nsButtonBoxFrame.h
rename : layout/xul/base/src/nsContainerBoxObject.cpp => layout/xul/nsContainerBoxObject.cpp
rename : layout/xul/base/src/nsDeckFrame.cpp => layout/xul/nsDeckFrame.cpp
rename : layout/xul/base/src/nsDeckFrame.h => layout/xul/nsDeckFrame.h
rename : layout/xul/base/src/nsDocElementBoxFrame.cpp => layout/xul/nsDocElementBoxFrame.cpp
rename : layout/xul/base/src/nsGroupBoxFrame.cpp => layout/xul/nsGroupBoxFrame.cpp
rename : layout/xul/base/public/nsIBoxObject.idl => layout/xul/nsIBoxObject.idl
rename : layout/xul/base/public/nsIBrowserBoxObject.idl => layout/xul/nsIBrowserBoxObject.idl
rename : layout/xul/base/public/nsIContainerBoxObject.idl => layout/xul/nsIContainerBoxObject.idl
rename : layout/xul/base/public/nsIEditorBoxObject.idl => layout/xul/nsIEditorBoxObject.idl
rename : layout/xul/base/public/nsIIFrameBoxObject.idl => layout/xul/nsIIFrameBoxObject.idl
rename : layout/xul/base/public/nsIListBoxObject.idl => layout/xul/nsIListBoxObject.idl
rename : layout/xul/base/public/nsIMenuBoxObject.idl => layout/xul/nsIMenuBoxObject.idl
rename : layout/xul/base/public/nsIPopupBoxObject.idl => layout/xul/nsIPopupBoxObject.idl
rename : layout/xul/base/src/nsIRootBox.h => layout/xul/nsIRootBox.h
rename : layout/xul/base/public/nsIScrollBoxObject.idl => layout/xul/nsIScrollBoxObject.idl
rename : layout/xul/base/public/nsIScrollbarMediator.h => layout/xul/nsIScrollbarMediator.h
rename : layout/xul/base/public/nsISliderListener.idl => layout/xul/nsISliderListener.idl
rename : layout/xul/base/src/nsImageBoxFrame.cpp => layout/xul/nsImageBoxFrame.cpp
rename : layout/xul/base/src/nsImageBoxFrame.h => layout/xul/nsImageBoxFrame.h
rename : layout/xul/base/src/nsLeafBoxFrame.cpp => layout/xul/nsLeafBoxFrame.cpp
rename : layout/xul/base/src/nsLeafBoxFrame.h => layout/xul/nsLeafBoxFrame.h
rename : layout/xul/base/src/nsListBoxBodyFrame.cpp => layout/xul/nsListBoxBodyFrame.cpp
rename : layout/xul/base/src/nsListBoxBodyFrame.h => layout/xul/nsListBoxBodyFrame.h
rename : layout/xul/base/src/nsListBoxLayout.cpp => layout/xul/nsListBoxLayout.cpp
rename : layout/xul/base/src/nsListBoxLayout.h => layout/xul/nsListBoxLayout.h
rename : layout/xul/base/src/nsListBoxObject.cpp => layout/xul/nsListBoxObject.cpp
rename : layout/xul/base/src/nsListItemFrame.cpp => layout/xul/nsListItemFrame.cpp
rename : layout/xul/base/src/nsListItemFrame.h => layout/xul/nsListItemFrame.h
rename : layout/xul/base/src/nsMenuBarFrame.cpp => layout/xul/nsMenuBarFrame.cpp
rename : layout/xul/base/src/nsMenuBarFrame.h => layout/xul/nsMenuBarFrame.h
rename : layout/xul/base/src/nsMenuBarListener.cpp => layout/xul/nsMenuBarListener.cpp
rename : layout/xul/base/src/nsMenuBarListener.h => layout/xul/nsMenuBarListener.h
rename : layout/xul/base/src/nsMenuBoxObject.cpp => layout/xul/nsMenuBoxObject.cpp
rename : layout/xul/base/src/nsMenuFrame.cpp => layout/xul/nsMenuFrame.cpp
rename : layout/xul/base/src/nsMenuFrame.h => layout/xul/nsMenuFrame.h
rename : layout/xul/base/src/nsMenuParent.h => layout/xul/nsMenuParent.h
rename : layout/xul/base/src/nsMenuPopupFrame.cpp => layout/xul/nsMenuPopupFrame.cpp
rename : layout/xul/base/src/nsMenuPopupFrame.h => layout/xul/nsMenuPopupFrame.h
rename : layout/xul/base/public/nsPIBoxObject.h => layout/xul/nsPIBoxObject.h
rename : layout/xul/base/src/nsPIListBoxObject.h => layout/xul/nsPIListBoxObject.h
rename : layout/xul/base/src/nsPopupBoxObject.cpp => layout/xul/nsPopupBoxObject.cpp
rename : layout/xul/base/src/nsPopupSetFrame.cpp => layout/xul/nsPopupSetFrame.cpp
rename : layout/xul/base/src/nsPopupSetFrame.h => layout/xul/nsPopupSetFrame.h
rename : layout/xul/base/src/nsProgressMeterFrame.cpp => layout/xul/nsProgressMeterFrame.cpp
rename : layout/xul/base/src/nsProgressMeterFrame.h => layout/xul/nsProgressMeterFrame.h
rename : layout/xul/base/src/nsRepeatService.cpp => layout/xul/nsRepeatService.cpp
rename : layout/xul/base/src/nsRepeatService.h => layout/xul/nsRepeatService.h
rename : layout/xul/base/src/nsResizerFrame.cpp => layout/xul/nsResizerFrame.cpp
rename : layout/xul/base/src/nsResizerFrame.h => layout/xul/nsResizerFrame.h
rename : layout/xul/base/src/nsRootBoxFrame.cpp => layout/xul/nsRootBoxFrame.cpp
rename : layout/xul/base/src/nsScrollBoxFrame.cpp => layout/xul/nsScrollBoxFrame.cpp
rename : layout/xul/base/src/nsScrollBoxObject.cpp => layout/xul/nsScrollBoxObject.cpp
rename : layout/xul/base/src/nsScrollbarButtonFrame.cpp => layout/xul/nsScrollbarButtonFrame.cpp
rename : layout/xul/base/src/nsScrollbarButtonFrame.h => layout/xul/nsScrollbarButtonFrame.h
rename : layout/xul/base/src/nsScrollbarFrame.cpp => layout/xul/nsScrollbarFrame.cpp
rename : layout/xul/base/src/nsScrollbarFrame.h => layout/xul/nsScrollbarFrame.h
rename : layout/xul/base/src/nsSliderFrame.cpp => layout/xul/nsSliderFrame.cpp
rename : layout/xul/base/src/nsSliderFrame.h => layout/xul/nsSliderFrame.h
rename : layout/xul/base/src/nsSplitterFrame.cpp => layout/xul/nsSplitterFrame.cpp
rename : layout/xul/base/src/nsSplitterFrame.h => layout/xul/nsSplitterFrame.h
rename : layout/xul/base/src/nsSprocketLayout.cpp => layout/xul/nsSprocketLayout.cpp
rename : layout/xul/base/src/nsSprocketLayout.h => layout/xul/nsSprocketLayout.h
rename : layout/xul/base/src/nsStackFrame.cpp => layout/xul/nsStackFrame.cpp
rename : layout/xul/base/src/nsStackFrame.h => layout/xul/nsStackFrame.h
rename : layout/xul/base/src/nsStackLayout.cpp => layout/xul/nsStackLayout.cpp
rename : layout/xul/base/src/nsStackLayout.h => layout/xul/nsStackLayout.h
rename : layout/xul/base/src/nsTextBoxFrame.cpp => layout/xul/nsTextBoxFrame.cpp
rename : layout/xul/base/src/nsTextBoxFrame.h => layout/xul/nsTextBoxFrame.h
rename : layout/xul/base/src/nsTitleBarFrame.cpp => layout/xul/nsTitleBarFrame.cpp
rename : layout/xul/base/src/nsTitleBarFrame.h => layout/xul/nsTitleBarFrame.h
rename : layout/xul/base/src/nsXULLabelFrame.cpp => layout/xul/nsXULLabelFrame.cpp
rename : layout/xul/base/src/nsXULLabelFrame.h => layout/xul/nsXULLabelFrame.h
rename : layout/xul/base/src/nsXULPopupManager.cpp => layout/xul/nsXULPopupManager.cpp
rename : layout/xul/base/public/nsXULPopupManager.h => layout/xul/nsXULPopupManager.h
rename : layout/xul/base/src/nsXULTooltipListener.cpp => layout/xul/nsXULTooltipListener.cpp
rename : layout/xul/base/src/nsXULTooltipListener.h => layout/xul/nsXULTooltipListener.h
rename : layout/xul/base/reftest/image-scaling-min-height-1-ref.xul => layout/xul/reftest/image-scaling-min-height-1-ref.xul
rename : layout/xul/base/reftest/image-scaling-min-height-1.xul => layout/xul/reftest/image-scaling-min-height-1.xul
rename : layout/xul/base/reftest/image-size-ref.xul => layout/xul/reftest/image-size-ref.xul
rename : layout/xul/base/reftest/image-size.xul => layout/xul/reftest/image-size.xul
rename : layout/xul/base/reftest/image4x3.png => layout/xul/reftest/image4x3.png
rename : layout/xul/base/reftest/popup-explicit-size-ref.xul => layout/xul/reftest/popup-explicit-size-ref.xul
rename : layout/xul/base/reftest/popup-explicit-size.xul => layout/xul/reftest/popup-explicit-size.xul
rename : layout/xul/base/reftest/reftest.list => layout/xul/reftest/reftest.list
rename : layout/xul/base/reftest/textbox-multiline-noresize.xul => layout/xul/reftest/textbox-multiline-noresize.xul
rename : layout/xul/base/reftest/textbox-multiline-ref.xul => layout/xul/reftest/textbox-multiline-ref.xul
rename : layout/xul/base/reftest/textbox-multiline-resize.xul => layout/xul/reftest/textbox-multiline-resize.xul
rename : layout/xul/base/test/test_bug381167.xhtml => layout/xul/test/test_bug381167.xhtml
rename : layout/xul/base/test/test_bug393970.xul => layout/xul/test/test_bug393970.xul
rename : layout/xul/base/test/test_bug477754.xul => layout/xul/test/test_bug477754.xul
rename : layout/xul/base/test/test_bug511075.html => layout/xul/test/test_bug511075.html
rename : layout/xul/base/test/test_popupSizeTo.xul => layout/xul/test/test_popupSizeTo.xul
rename : layout/xul/base/test/test_resizer.xul => layout/xul/test/test_resizer.xul
rename : layout/xul/base/test/test_resizer_incontent.xul => layout/xul/test/test_resizer_incontent.xul
rename : layout/xul/base/test/test_splitter.xul => layout/xul/test/test_splitter.xul
rename : layout/xul/base/test/test_stack.xul => layout/xul/test/test_stack.xul
rename : layout/xul/base/test/test_windowminmaxsize.xul => layout/xul/test/test_windowminmaxsize.xul
rename : layout/xul/base/test/window_resizer.xul => layout/xul/test/window_resizer.xul
rename : layout/xul/base/test/window_resizer_element.xul => layout/xul/test/window_resizer_element.xul
2013-12-04 14:06:16 +13:00

730 lines
21 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsXULTooltipListener.h"
#include "nsDOMEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMXULElement.h"
#include "nsIDocument.h"
#include "nsGkAtoms.h"
#include "nsIPopupBoxObject.h"
#include "nsMenuPopupFrame.h"
#include "nsIServiceManager.h"
#include "nsIDragService.h"
#include "nsIDragSession.h"
#ifdef MOZ_XUL
#include "nsITreeView.h"
#endif
#include "nsIScriptContext.h"
#include "nsPIDOMWindow.h"
#ifdef MOZ_XUL
#include "nsXULPopupManager.h"
#endif
#include "nsIRootBox.h"
#include "nsIBoxObject.h"
#include "nsEventDispatcher.h"
#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/dom/Element.h"
using namespace mozilla;
using namespace mozilla::dom;
nsXULTooltipListener* nsXULTooltipListener::mInstance = nullptr;
//////////////////////////////////////////////////////////////////////////
//// nsISupports
nsXULTooltipListener::nsXULTooltipListener()
: mMouseScreenX(0)
, mMouseScreenY(0)
, mTooltipShownOnce(false)
#ifdef MOZ_XUL
, mIsSourceTree(false)
, mNeedTitletip(false)
, mLastTreeRow(-1)
#endif
{
if (sTooltipListenerCount++ == 0) {
// register the callback so we get notified of updates
Preferences::RegisterCallback(ToolbarTipsPrefChanged,
"browser.chrome.toolbar_tips");
// Call the pref callback to initialize our state.
ToolbarTipsPrefChanged("browser.chrome.toolbar_tips", nullptr);
}
}
nsXULTooltipListener::~nsXULTooltipListener()
{
if (nsXULTooltipListener::mInstance == this) {
ClearTooltipCache();
}
HideTooltip();
if (--sTooltipListenerCount == 0) {
// Unregister our pref observer
Preferences::UnregisterCallback(ToolbarTipsPrefChanged,
"browser.chrome.toolbar_tips");
}
}
NS_IMPL_ISUPPORTS1(nsXULTooltipListener, nsIDOMEventListener)
void
nsXULTooltipListener::MouseOut(nsIDOMEvent* aEvent)
{
// reset flag so that tooltip will display on the next MouseMove
mTooltipShownOnce = false;
// if the timer is running and no tooltip is shown, we
// have to cancel the timer here so that it doesn't
// show the tooltip if we move the mouse out of the window
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (mTooltipTimer && !currentTooltip) {
mTooltipTimer->Cancel();
mTooltipTimer = nullptr;
return;
}
#ifdef DEBUG_crap
if (mNeedTitletip)
return;
#endif
#ifdef MOZ_XUL
// check to see if the mouse left the targetNode, and if so,
// hide the tooltip
if (currentTooltip) {
// which node did the mouse leave?
nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(
aEvent->InternalDOMEvent()->GetTarget());
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
nsCOMPtr<nsIDOMNode> tooltipNode =
pm->GetLastTriggerTooltipNode(currentTooltip->GetCurrentDoc());
if (tooltipNode == targetNode) {
// if the target node is the current tooltip target node, the mouse
// left the node the tooltip appeared on, so close the tooltip.
HideTooltip();
// reset special tree tracking
if (mIsSourceTree) {
mLastTreeRow = -1;
mLastTreeCol = nullptr;
}
}
}
}
#endif
}
void
nsXULTooltipListener::MouseMove(nsIDOMEvent* aEvent)
{
if (!sShowTooltips)
return;
// stash the coordinates of the event so that we can still get back to it from within the
// timer callback. On win32, we'll get a MouseMove event even when a popup goes away --
// even when the mouse doesn't change position! To get around this, we make sure the
// mouse has really moved before proceeding.
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
if (!mouseEvent)
return;
int32_t newMouseX, newMouseY;
mouseEvent->GetScreenX(&newMouseX);
mouseEvent->GetScreenY(&newMouseY);
// filter out false win32 MouseMove event
if (mMouseScreenX == newMouseX && mMouseScreenY == newMouseY)
return;
// filter out minor movements due to crappy optical mice and shaky hands
// to prevent tooltips from hiding prematurely.
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if ((currentTooltip) &&
(abs(mMouseScreenX - newMouseX) <= kTooltipMouseMoveTolerance) &&
(abs(mMouseScreenY - newMouseY) <= kTooltipMouseMoveTolerance))
return;
mMouseScreenX = newMouseX;
mMouseScreenY = newMouseY;
nsCOMPtr<nsIContent> sourceContent = do_QueryInterface(
aEvent->InternalDOMEvent()->GetCurrentTarget());
mSourceNode = do_GetWeakReference(sourceContent);
#ifdef MOZ_XUL
mIsSourceTree = sourceContent->Tag() == nsGkAtoms::treechildren;
if (mIsSourceTree)
CheckTreeBodyMove(mouseEvent);
#endif
// as the mouse moves, we want to make sure we reset the timer to show it,
// so that the delay is from when the mouse stops moving, not when it enters
// the node.
KillTooltipTimer();
// If the mouse moves while the tooltip is up, hide it. If nothing is
// showing and the tooltip hasn't been displayed since the mouse entered
// the node, then start the timer to show the tooltip.
if (!currentTooltip && !mTooltipShownOnce) {
nsCOMPtr<EventTarget> eventTarget = aEvent->InternalDOMEvent()->GetTarget();
// don't show tooltips attached to elements outside of a menu popup
// when hovering over an element inside it. The popupsinherittooltip
// attribute may be used to disable this behaviour, which is useful for
// large menu hierarchies such as bookmarks.
if (!sourceContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::popupsinherittooltip,
nsGkAtoms::_true, eCaseMatters)) {
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(eventTarget);
while (targetContent && targetContent != sourceContent) {
nsIAtom* tag = targetContent->Tag();
if (targetContent->GetNameSpaceID() == kNameSpaceID_XUL &&
(tag == nsGkAtoms::menupopup ||
tag == nsGkAtoms::panel ||
tag == nsGkAtoms::tooltip)) {
mSourceNode = nullptr;
return;
}
targetContent = targetContent->GetParent();
}
}
mTooltipTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mTooltipTimer) {
mTargetNode = do_GetWeakReference(eventTarget);
if (mTargetNode) {
nsresult rv =
mTooltipTimer->InitWithFuncCallback(sTooltipCallback, this,
LookAndFeel::GetInt(LookAndFeel::eIntID_TooltipDelay, 500),
nsITimer::TYPE_ONE_SHOT);
if (NS_FAILED(rv)) {
mTargetNode = nullptr;
mSourceNode = nullptr;
}
}
}
return;
}
#ifdef MOZ_XUL
if (mIsSourceTree)
return;
#endif
HideTooltip();
// set a flag so that the tooltip is only displayed once until the mouse
// leaves the node
mTooltipShownOnce = true;
}
NS_IMETHODIMP
nsXULTooltipListener::HandleEvent(nsIDOMEvent* aEvent)
{
nsAutoString type;
aEvent->GetType(type);
if (type.EqualsLiteral("DOMMouseScroll") ||
type.EqualsLiteral("keydown") ||
type.EqualsLiteral("mousedown") ||
type.EqualsLiteral("mouseup") ||
type.EqualsLiteral("dragstart")) {
HideTooltip();
return NS_OK;
}
if (type.EqualsLiteral("popuphiding")) {
DestroyTooltip();
return NS_OK;
}
// Note that mousemove, mouseover and mouseout might be
// fired even during dragging due to widget's bug.
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
NS_ENSURE_TRUE(dragService, NS_OK);
nsCOMPtr<nsIDragSession> dragSession;
dragService->GetCurrentSession(getter_AddRefs(dragSession));
if (dragSession) {
return NS_OK;
}
// Not dragging.
if (type.EqualsLiteral("mousemove")) {
MouseMove(aEvent);
return NS_OK;
}
if (type.EqualsLiteral("mouseout")) {
MouseOut(aEvent);
return NS_OK;
}
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////
//// nsXULTooltipListener
// static
int
nsXULTooltipListener::ToolbarTipsPrefChanged(const char *aPref,
void *aClosure)
{
sShowTooltips =
Preferences::GetBool("browser.chrome.toolbar_tips", sShowTooltips);
return 0;
}
//////////////////////////////////////////////////////////////////////////
//// nsXULTooltipListener
bool nsXULTooltipListener::sShowTooltips = false;
uint32_t nsXULTooltipListener::sTooltipListenerCount = 0;
nsresult
nsXULTooltipListener::AddTooltipSupport(nsIContent* aNode)
{
if (!aNode)
return NS_ERROR_NULL_POINTER;
aNode->AddSystemEventListener(NS_LITERAL_STRING("mouseout"), this,
false, false);
aNode->AddSystemEventListener(NS_LITERAL_STRING("mousemove"), this,
false, false);
aNode->AddSystemEventListener(NS_LITERAL_STRING("mousedown"), this,
false, false);
aNode->AddSystemEventListener(NS_LITERAL_STRING("mouseup"), this,
false, false);
aNode->AddSystemEventListener(NS_LITERAL_STRING("dragstart"), this,
true, false);
return NS_OK;
}
nsresult
nsXULTooltipListener::RemoveTooltipSupport(nsIContent* aNode)
{
if (!aNode)
return NS_ERROR_NULL_POINTER;
aNode->RemoveSystemEventListener(NS_LITERAL_STRING("mouseout"), this, false);
aNode->RemoveSystemEventListener(NS_LITERAL_STRING("mousemove"), this, false);
aNode->RemoveSystemEventListener(NS_LITERAL_STRING("mousedown"), this, false);
aNode->RemoveSystemEventListener(NS_LITERAL_STRING("mouseup"), this, false);
aNode->RemoveSystemEventListener(NS_LITERAL_STRING("dragstart"), this, true);
return NS_OK;
}
#ifdef MOZ_XUL
void
nsXULTooltipListener::CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent)
{
nsCOMPtr<nsIContent> sourceNode = do_QueryReferent(mSourceNode);
if (!sourceNode)
return;
// get the boxObject of the documentElement of the document the tree is in
nsCOMPtr<nsIBoxObject> bx;
nsIDocument* doc = sourceNode->GetDocument();
if (doc) {
ErrorResult ignored;
bx = doc->GetBoxObjectFor(doc->GetRootElement(), ignored);
}
nsCOMPtr<nsITreeBoxObject> obx;
GetSourceTreeBoxObject(getter_AddRefs(obx));
if (bx && obx) {
int32_t x, y;
aMouseEvent->GetScreenX(&x);
aMouseEvent->GetScreenY(&y);
int32_t row;
nsCOMPtr<nsITreeColumn> col;
nsAutoCString obj;
// subtract off the documentElement's boxObject
int32_t boxX, boxY;
bx->GetScreenX(&boxX);
bx->GetScreenY(&boxY);
x -= boxX;
y -= boxY;
obx->GetCellAt(x, y, &row, getter_AddRefs(col), obj);
// determine if we are going to need a titletip
// XXX check the disabletitletips attribute on the tree content
mNeedTitletip = false;
if (row >= 0 && obj.EqualsLiteral("text")) {
obx->IsCellCropped(row, col, &mNeedTitletip);
}
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (currentTooltip && (row != mLastTreeRow || col != mLastTreeCol)) {
HideTooltip();
}
mLastTreeRow = row;
mLastTreeCol = col;
}
}
#endif
nsresult
nsXULTooltipListener::ShowTooltip()
{
nsCOMPtr<nsIContent> sourceNode = do_QueryReferent(mSourceNode);
// get the tooltip content designated for the target node
nsCOMPtr<nsIContent> tooltipNode;
GetTooltipFor(sourceNode, getter_AddRefs(tooltipNode));
if (!tooltipNode || sourceNode == tooltipNode)
return NS_ERROR_FAILURE; // the target node doesn't need a tooltip
// set the node in the document that triggered the tooltip and show it
nsCOMPtr<nsIDOMXULDocument> xulDoc(do_QueryInterface(tooltipNode->GetDocument()));
if (xulDoc) {
// Make sure the target node is still attached to some document.
// It might have been deleted.
if (sourceNode->GetDocument()) {
#ifdef MOZ_XUL
if (!mIsSourceTree) {
mLastTreeRow = -1;
mLastTreeCol = nullptr;
}
#endif
mCurrentTooltip = do_GetWeakReference(tooltipNode);
LaunchTooltip();
mTargetNode = nullptr;
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (!currentTooltip)
return NS_OK;
// listen for popuphidden on the tooltip node, so that we can
// be sure DestroyPopup is called even if someone else closes the tooltip
currentTooltip->AddSystemEventListener(NS_LITERAL_STRING("popuphiding"),
this, false, false);
// listen for mousedown, mouseup, keydown, and DOMMouseScroll events at document level
nsIDocument* doc = sourceNode->GetDocument();
if (doc) {
// Probably, we should listen to untrusted events for hiding tooltips
// on content since tooltips might disturb something of web
// applications. If we don't specify the aWantsUntrusted of
// AddSystemEventListener(), the event target sets it to TRUE if the
// target is in content.
doc->AddSystemEventListener(NS_LITERAL_STRING("DOMMouseScroll"),
this, true);
doc->AddSystemEventListener(NS_LITERAL_STRING("mousedown"),
this, true);
doc->AddSystemEventListener(NS_LITERAL_STRING("mouseup"),
this, true);
doc->AddSystemEventListener(NS_LITERAL_STRING("keydown"),
this, true);
}
mSourceNode = nullptr;
}
}
return NS_OK;
}
#ifdef MOZ_XUL
// XXX: "This stuff inside DEBUG_crap could be used to make tree tooltips work
// in the future."
#ifdef DEBUG_crap
static void
GetTreeCellCoords(nsITreeBoxObject* aTreeBox, nsIContent* aSourceNode,
int32_t aRow, nsITreeColumn* aCol, int32_t* aX, int32_t* aY)
{
int32_t junk;
aTreeBox->GetCoordsForCellItem(aRow, aCol, EmptyCString(), aX, aY, &junk, &junk);
nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(aSourceNode));
nsCOMPtr<nsIBoxObject> bx;
xulEl->GetBoxObject(getter_AddRefs(bx));
int32_t myX, myY;
bx->GetX(&myX);
bx->GetY(&myY);
*aX += myX;
*aY += myY;
}
#endif
static void
SetTitletipLabel(nsITreeBoxObject* aTreeBox, nsIContent* aTooltip,
int32_t aRow, nsITreeColumn* aCol)
{
nsCOMPtr<nsITreeView> view;
aTreeBox->GetView(getter_AddRefs(view));
if (view) {
nsAutoString label;
#ifdef DEBUG
nsresult rv =
#endif
view->GetCellText(aRow, aCol, label);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Couldn't get the cell text!");
aTooltip->SetAttr(kNameSpaceID_None, nsGkAtoms::label, label, true);
}
}
#endif
void
nsXULTooltipListener::LaunchTooltip()
{
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (!currentTooltip)
return;
#ifdef MOZ_XUL
if (mIsSourceTree && mNeedTitletip) {
nsCOMPtr<nsITreeBoxObject> obx;
GetSourceTreeBoxObject(getter_AddRefs(obx));
SetTitletipLabel(obx, currentTooltip, mLastTreeRow, mLastTreeCol);
if (!(currentTooltip = do_QueryReferent(mCurrentTooltip))) {
// Because of mutation events, currentTooltip can be null.
return;
}
currentTooltip->SetAttr(kNameSpaceID_None, nsGkAtoms::titletip, NS_LITERAL_STRING("true"), true);
} else {
currentTooltip->UnsetAttr(kNameSpaceID_None, nsGkAtoms::titletip, true);
}
if (!(currentTooltip = do_QueryReferent(mCurrentTooltip))) {
// Because of mutation events, currentTooltip can be null.
return;
}
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
nsCOMPtr<nsIContent> target = do_QueryReferent(mTargetNode);
pm->ShowTooltipAtScreen(currentTooltip, target, mMouseScreenX, mMouseScreenY);
// Clear the current tooltip if the popup was not opened successfully.
if (!pm->IsPopupOpen(currentTooltip))
mCurrentTooltip = nullptr;
}
#endif
}
nsresult
nsXULTooltipListener::HideTooltip()
{
#ifdef MOZ_XUL
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (currentTooltip) {
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm)
pm->HidePopup(currentTooltip, false, false, false);
}
#endif
DestroyTooltip();
return NS_OK;
}
static void
GetImmediateChild(nsIContent* aContent, nsIAtom *aTag, nsIContent** aResult)
{
*aResult = nullptr;
uint32_t childCount = aContent->GetChildCount();
for (uint32_t i = 0; i < childCount; i++) {
nsIContent *child = aContent->GetChildAt(i);
if (child->Tag() == aTag) {
*aResult = child;
NS_ADDREF(*aResult);
return;
}
}
return;
}
nsresult
nsXULTooltipListener::FindTooltip(nsIContent* aTarget, nsIContent** aTooltip)
{
if (!aTarget)
return NS_ERROR_NULL_POINTER;
// before we go on, make sure that target node still has a window
nsIDocument *document = aTarget->GetDocument();
if (!document) {
NS_WARNING("Unable to retrieve the tooltip node document.");
return NS_ERROR_FAILURE;
}
nsPIDOMWindow *window = document->GetWindow();
if (!window) {
return NS_OK;
}
bool closed;
window->GetClosed(&closed);
if (closed) {
return NS_OK;
}
nsAutoString tooltipText;
aTarget->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext, tooltipText);
if (!tooltipText.IsEmpty()) {
// specifying tooltiptext means we will always use the default tooltip
nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShell());
NS_ENSURE_STATE(rootBox);
*aTooltip = rootBox->GetDefaultTooltip();
if (*aTooltip) {
NS_ADDREF(*aTooltip);
(*aTooltip)->SetAttr(kNameSpaceID_None, nsGkAtoms::label, tooltipText, true);
}
return NS_OK;
}
nsAutoString tooltipId;
aTarget->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltip, tooltipId);
// if tooltip == _child, look for first <tooltip> child
if (tooltipId.EqualsLiteral("_child")) {
GetImmediateChild(aTarget, nsGkAtoms::tooltip, aTooltip);
return NS_OK;
}
if (!tooltipId.IsEmpty()) {
// tooltip must be an id, use getElementById to find it
nsCOMPtr<nsIContent> tooltipEl = document->GetElementById(tooltipId);
if (tooltipEl) {
#ifdef MOZ_XUL
mNeedTitletip = false;
#endif
tooltipEl.forget(aTooltip);
return NS_OK;
}
}
#ifdef MOZ_XUL
// titletips should just use the default tooltip
if (mIsSourceTree && mNeedTitletip) {
nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShell());
NS_ENSURE_STATE(rootBox);
NS_IF_ADDREF(*aTooltip = rootBox->GetDefaultTooltip());
}
#endif
return NS_OK;
}
nsresult
nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
{
*aTooltip = nullptr;
nsCOMPtr<nsIContent> tooltip;
nsresult rv = FindTooltip(aTarget, getter_AddRefs(tooltip));
if (NS_FAILED(rv) || !tooltip) {
return rv;
}
#ifdef MOZ_XUL
// Submenus can't be used as tooltips, see bug 288763.
nsIContent* parent = tooltip->GetParent();
if (parent) {
nsMenuFrame* menu = do_QueryFrame(parent->GetPrimaryFrame());
if (menu) {
NS_WARNING("Menu cannot be used as a tooltip");
return NS_ERROR_FAILURE;
}
}
#endif
tooltip.swap(*aTooltip);
return rv;
}
nsresult
nsXULTooltipListener::DestroyTooltip()
{
nsCOMPtr<nsIDOMEventListener> kungFuDeathGrip(this);
nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
if (currentTooltip) {
// release tooltip before removing listener to prevent our destructor from
// being called recursively (bug 120863)
mCurrentTooltip = nullptr;
// clear out the tooltip node on the document
nsCOMPtr<nsIDocument> doc = currentTooltip->GetDocument();
if (doc) {
// remove the mousedown and keydown listener from document
doc->RemoveSystemEventListener(NS_LITERAL_STRING("DOMMouseScroll"), this,
true);
doc->RemoveSystemEventListener(NS_LITERAL_STRING("mousedown"), this,
true);
doc->RemoveSystemEventListener(NS_LITERAL_STRING("mouseup"), this, true);
doc->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"), this, true);
}
// remove the popuphidden listener from tooltip
currentTooltip->RemoveSystemEventListener(NS_LITERAL_STRING("popuphiding"), this, false);
}
// kill any ongoing timers
KillTooltipTimer();
mSourceNode = nullptr;
#ifdef MOZ_XUL
mLastTreeCol = nullptr;
#endif
return NS_OK;
}
void
nsXULTooltipListener::KillTooltipTimer()
{
if (mTooltipTimer) {
mTooltipTimer->Cancel();
mTooltipTimer = nullptr;
mTargetNode = nullptr;
}
}
void
nsXULTooltipListener::sTooltipCallback(nsITimer *aTimer, void *aListener)
{
nsRefPtr<nsXULTooltipListener> instance = mInstance;
if (instance)
instance->ShowTooltip();
}
#ifdef MOZ_XUL
nsresult
nsXULTooltipListener::GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject)
{
*aBoxObject = nullptr;
nsCOMPtr<nsIContent> sourceNode = do_QueryReferent(mSourceNode);
if (mIsSourceTree && sourceNode) {
nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(sourceNode->GetParent()));
if (xulEl) {
nsCOMPtr<nsIBoxObject> bx;
xulEl->GetBoxObject(getter_AddRefs(bx));
nsCOMPtr<nsITreeBoxObject> obx(do_QueryInterface(bx));
if (obx) {
*aBoxObject = obx;
NS_ADDREF(*aBoxObject);
return NS_OK;
}
}
}
return NS_ERROR_FAILURE;
}
#endif