michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * 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 nsDocShellTreeOwner_h__ michael@0: #define nsDocShellTreeOwner_h__ michael@0: michael@0: // Helper Classes michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: // Interfaces Needed michael@0: #include "nsIBaseWindow.h" michael@0: #include "nsIDocShellTreeOwner.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsIInterfaceRequestorUtils.h" michael@0: #include "nsIWebBrowserChrome.h" michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsIEmbeddingSiteWindow.h" michael@0: #include "nsIWebProgressListener.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsITimer.h" michael@0: #include "nsIPrompt.h" michael@0: #include "nsIAuthPrompt.h" michael@0: #include "nsITooltipListener.h" michael@0: #include "nsITooltipTextProvider.h" michael@0: #include "nsCTooltipTextProvider.h" michael@0: #include "nsIDroppedLinkHandler.h" michael@0: #include "nsCommandHandler.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class EventTarget; michael@0: } michael@0: } michael@0: michael@0: class nsWebBrowser; michael@0: class ChromeTooltipListener; michael@0: class ChromeContextMenuListener; michael@0: michael@0: // {6D10C180-6888-11d4-952B-0020183BF181} michael@0: #define NS_ICDOCSHELLTREEOWNER_IID \ michael@0: { 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } } michael@0: michael@0: /* michael@0: * This is a fake 'hidden' interface that nsDocShellTreeOwner implements. michael@0: * Classes such as nsCommandHandler can QI for this interface to be michael@0: * sure that they're dealing with a valid nsDocShellTreeOwner and not some michael@0: * other object that implements nsIDocShellTreeOwner. michael@0: */ michael@0: class nsICDocShellTreeOwner : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID) michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner, michael@0: NS_ICDOCSHELLTREEOWNER_IID) michael@0: michael@0: class nsDocShellTreeOwner : public nsIDocShellTreeOwner, michael@0: public nsIBaseWindow, michael@0: public nsIInterfaceRequestor, michael@0: public nsIWebProgressListener, michael@0: public nsIDOMEventListener, michael@0: public nsICDocShellTreeOwner, michael@0: public nsSupportsWeakReference michael@0: { michael@0: friend class nsWebBrowser; michael@0: friend class nsCommandHandler; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: NS_DECL_NSIBASEWINDOW michael@0: NS_DECL_NSIDOCSHELLTREEOWNER michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: NS_DECL_NSIINTERFACEREQUESTOR michael@0: NS_DECL_NSIWEBPROGRESSLISTENER michael@0: michael@0: protected: michael@0: nsDocShellTreeOwner(); michael@0: virtual ~nsDocShellTreeOwner(); michael@0: michael@0: void WebBrowser(nsWebBrowser* aWebBrowser); michael@0: michael@0: nsWebBrowser* WebBrowser(); michael@0: NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner); michael@0: NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome); michael@0: michael@0: NS_IMETHOD AddChromeListeners(); michael@0: NS_IMETHOD RemoveChromeListeners(); michael@0: michael@0: nsresult FindItemWithNameAcrossWindows(const char16_t* aName, michael@0: nsIDocShellTreeItem* aRequestor, michael@0: nsIDocShellTreeItem* aOriginalRequestor, michael@0: nsIDocShellTreeItem **aFoundItem); michael@0: michael@0: void EnsurePrompter(); michael@0: void EnsureAuthPrompter(); michael@0: michael@0: void AddToWatcher(); michael@0: void RemoveFromWatcher(); michael@0: michael@0: // These helper functions return the correct instances of the requested michael@0: // interfaces. If the object passed to SetWebBrowserChrome() implements michael@0: // nsISupportsWeakReference, then these functions call QueryReferent on michael@0: // that object. Otherwise, they return an addrefed pointer. If the michael@0: // WebBrowserChrome object doesn't exist, they return nullptr. michael@0: already_AddRefed GetWebBrowserChrome(); michael@0: already_AddRefed GetOwnerWin(); michael@0: already_AddRefed GetOwnerRequestor(); michael@0: michael@0: protected: michael@0: michael@0: // Weak References michael@0: nsWebBrowser* mWebBrowser; michael@0: nsIDocShellTreeOwner* mTreeOwner; michael@0: nsIDocShellTreeItem* mPrimaryContentShell; michael@0: michael@0: nsIWebBrowserChrome* mWebBrowserChrome; michael@0: nsIEmbeddingSiteWindow* mOwnerWin; michael@0: nsIInterfaceRequestor* mOwnerRequestor; michael@0: michael@0: nsWeakPtr mWebBrowserChromeWeak; // nsIWebBrowserChrome michael@0: michael@0: // the objects that listen for chrome events like context menus and tooltips. michael@0: // They are separate objects to avoid circular references between |this| michael@0: // and the DOM. These are strong, owning refs. michael@0: ChromeTooltipListener* mChromeTooltipListener; michael@0: ChromeContextMenuListener* mChromeContextMenuListener; michael@0: michael@0: nsCOMPtr mPrompter; michael@0: nsCOMPtr mAuthPrompter; michael@0: }; michael@0: michael@0: michael@0: // michael@0: // class ChromeTooltipListener michael@0: // michael@0: // The class that listens to the chrome events and tells the embedding michael@0: // chrome to show tooltips, as appropriate. Handles registering itself michael@0: // with the DOM with AddChromeListeners() and removing itself with michael@0: // RemoveChromeListeners(). michael@0: // michael@0: class ChromeTooltipListener : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ; michael@0: virtual ~ChromeTooltipListener ( ) ; michael@0: michael@0: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); michael@0: NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent); michael@0: michael@0: // Add/remove the relevant listeners, based on what interfaces michael@0: // the embedding chrome implements. michael@0: NS_IMETHOD AddChromeListeners(); michael@0: NS_IMETHOD RemoveChromeListeners(); michael@0: michael@0: private: michael@0: michael@0: // various delays for tooltips michael@0: enum { michael@0: kTooltipAutoHideTime = 5000 // 5000ms = 5 seconds michael@0: }; michael@0: michael@0: NS_IMETHOD AddTooltipListener(); michael@0: NS_IMETHOD RemoveTooltipListener(); michael@0: michael@0: NS_IMETHOD ShowTooltip ( int32_t inXCoords, int32_t inYCoords, const nsAString & inTipText ) ; michael@0: NS_IMETHOD HideTooltip ( ) ; michael@0: michael@0: nsWebBrowser* mWebBrowser; michael@0: nsCOMPtr mEventTarget; michael@0: nsCOMPtr mTooltipTextProvider; michael@0: michael@0: // This must be a strong ref in order to make sure we can hide the tooltip michael@0: // if the window goes away while we're displaying one. If we don't hold michael@0: // a strong ref, the chrome might have been disposed of before we get a chance michael@0: // to tell it, and no one would ever tell us of that fact. michael@0: nsCOMPtr mWebBrowserChrome; michael@0: michael@0: bool mTooltipListenerInstalled; michael@0: michael@0: nsCOMPtr mTooltipTimer; michael@0: static void sTooltipCallback ( nsITimer* aTimer, void* aListener ) ; michael@0: int32_t mMouseClientX, mMouseClientY; // mouse coordinates for last mousemove event we saw michael@0: int32_t mMouseScreenX, mMouseScreenY; // mouse coordinates for tooltip event michael@0: bool mShowingTooltip; michael@0: michael@0: // a timer for auto-hiding the tooltip after a certain delay michael@0: nsCOMPtr mAutoHideTimer; michael@0: static void sAutoHideCallback ( nsITimer* aTimer, void* aListener ) ; michael@0: void CreateAutoHideTimer ( ) ; michael@0: michael@0: // The node hovered over that fired the timer. This may turn into the node that michael@0: // triggered the tooltip, but only if the timer ever gets around to firing. michael@0: // This is a strong reference, because the tooltip content can be destroyed while we're michael@0: // waiting for the tooltip to pup up, and we need to detect that. michael@0: // It's set only when the tooltip timer is created and launched. The timer must michael@0: // either fire or be cancelled (or possibly released?), and we release this michael@0: // reference in each of those cases. So we don't leak. michael@0: nsCOMPtr mPossibleTooltipNode; michael@0: michael@0: }; // ChromeTooltipListener michael@0: michael@0: michael@0: // michael@0: // class ChromeContextMenuListener michael@0: // michael@0: // The class that listens to the chrome events and tells the embedding michael@0: // chrome to show context menus, as appropriate. Handles registering itself michael@0: // with the DOM with AddChromeListeners() and removing itself with michael@0: // RemoveChromeListeners(). michael@0: // michael@0: class ChromeContextMenuListener : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: ChromeContextMenuListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ; michael@0: virtual ~ChromeContextMenuListener ( ) ; michael@0: michael@0: // nsIDOMContextMenuListener michael@0: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); michael@0: michael@0: // Add/remove the relevant listeners, based on what interfaces michael@0: // the embedding chrome implements. michael@0: NS_IMETHOD AddChromeListeners(); michael@0: NS_IMETHOD RemoveChromeListeners(); michael@0: michael@0: private: michael@0: michael@0: NS_IMETHOD AddContextMenuListener(); michael@0: NS_IMETHOD RemoveContextMenuListener(); michael@0: michael@0: bool mContextMenuListenerInstalled; michael@0: michael@0: nsWebBrowser* mWebBrowser; michael@0: nsCOMPtr mEventTarget; michael@0: nsCOMPtr mWebBrowserChrome; michael@0: michael@0: }; // class ChromeContextMenuListener michael@0: michael@0: michael@0: michael@0: #endif /* nsDocShellTreeOwner_h__ */ michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: