Bug 1517921 [wpt PR 14728] - [manifest] Make sure deleted tests are removed from...
[gecko.git] / docshell / base / nsDocShellTreeOwner.h
blobd25a5e84d4197bc7b5df0d5fded7ea047a4ab5cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsDocShellTreeOwner_h__
8 #define nsDocShellTreeOwner_h__
10 // Helper Classes
11 #include "nsCOMPtr.h"
12 #include "nsString.h"
14 // Interfaces Needed
15 #include "nsIBaseWindow.h"
16 #include "nsIDocShellTreeOwner.h"
17 #include "nsIInterfaceRequestor.h"
18 #include "nsIInterfaceRequestorUtils.h"
19 #include "nsIWebBrowserChrome.h"
20 #include "nsIDOMEventListener.h"
21 #include "nsIEmbeddingSiteWindow.h"
22 #include "nsIWebProgressListener.h"
23 #include "nsWeakReference.h"
24 #include "nsITimer.h"
25 #include "nsIPrompt.h"
26 #include "nsIAuthPrompt.h"
27 #include "nsITooltipListener.h"
28 #include "nsITooltipTextProvider.h"
29 #include "nsCTooltipTextProvider.h"
30 #include "nsIDroppedLinkHandler.h"
32 namespace mozilla {
33 namespace dom {
34 class Event;
35 class EventTarget;
36 } // namespace dom
37 } // namespace mozilla
39 class nsWebBrowser;
40 class ChromeTooltipListener;
42 class nsDocShellTreeOwner final : public nsIDocShellTreeOwner,
43 public nsIBaseWindow,
44 public nsIInterfaceRequestor,
45 public nsIWebProgressListener,
46 public nsIDOMEventListener,
47 public nsSupportsWeakReference {
48 friend class nsWebBrowser;
50 public:
51 NS_DECL_ISUPPORTS
53 NS_DECL_NSIBASEWINDOW
54 NS_DECL_NSIDOCSHELLTREEOWNER
55 NS_DECL_NSIDOMEVENTLISTENER
56 NS_DECL_NSIINTERFACEREQUESTOR
57 NS_DECL_NSIWEBPROGRESSLISTENER
59 protected:
60 nsDocShellTreeOwner();
61 virtual ~nsDocShellTreeOwner();
63 void WebBrowser(nsWebBrowser* aWebBrowser);
65 nsWebBrowser* WebBrowser();
66 NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner);
67 NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome);
69 NS_IMETHOD AddChromeListeners();
70 NS_IMETHOD RemoveChromeListeners();
72 void EnsurePrompter();
73 void EnsureAuthPrompter();
75 void AddToWatcher();
76 void RemoveFromWatcher();
78 void EnsureContentTreeOwner();
80 // These helper functions return the correct instances of the requested
81 // interfaces. If the object passed to SetWebBrowserChrome() implements
82 // nsISupportsWeakReference, then these functions call QueryReferent on
83 // that object. Otherwise, they return an addrefed pointer. If the
84 // WebBrowserChrome object doesn't exist, they return nullptr.
85 already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome();
86 already_AddRefed<nsIEmbeddingSiteWindow> GetOwnerWin();
87 already_AddRefed<nsIInterfaceRequestor> GetOwnerRequestor();
89 protected:
90 // Weak References
91 nsWebBrowser* mWebBrowser;
92 nsIDocShellTreeOwner* mTreeOwner;
93 nsIDocShellTreeItem* mPrimaryContentShell;
95 nsIWebBrowserChrome* mWebBrowserChrome;
96 nsIEmbeddingSiteWindow* mOwnerWin;
97 nsIInterfaceRequestor* mOwnerRequestor;
99 nsWeakPtr mWebBrowserChromeWeak; // nsIWebBrowserChrome
101 // the objects that listen for chrome events like context menus and tooltips.
102 // They are separate objects to avoid circular references between |this|
103 // and the DOM.
104 RefPtr<ChromeTooltipListener> mChromeTooltipListener;
106 RefPtr<nsDocShellTreeOwner> mContentTreeOwner;
108 nsCOMPtr<nsIPrompt> mPrompter;
109 nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
110 nsCOMPtr<nsITabParent> mPrimaryTabParent;
113 // The class that listens to the chrome events and tells the embedding chrome to
114 // show tooltips, as appropriate. Handles registering itself with the DOM with
115 // AddChromeListeners() and removing itself with RemoveChromeListeners().
116 class ChromeTooltipListener final : public nsIDOMEventListener {
117 protected:
118 virtual ~ChromeTooltipListener();
120 public:
121 NS_DECL_ISUPPORTS
123 ChromeTooltipListener(nsWebBrowser* aInBrowser,
124 nsIWebBrowserChrome* aInChrome);
126 NS_DECL_NSIDOMEVENTLISTENER
127 NS_IMETHOD MouseMove(mozilla::dom::Event* aMouseEvent);
129 // Add/remove the relevant listeners, based on what interfaces the embedding
130 // chrome implements.
131 NS_IMETHOD AddChromeListeners();
132 NS_IMETHOD RemoveChromeListeners();
134 private:
135 // various delays for tooltips
136 enum {
137 kTooltipAutoHideTime = 5000, // ms
138 kTooltipMouseMoveTolerance = 7 // pixel tolerance for mousemove event
141 NS_IMETHOD AddTooltipListener();
142 NS_IMETHOD RemoveTooltipListener();
144 NS_IMETHOD ShowTooltip(int32_t aInXCoords, int32_t aInYCoords,
145 const nsAString& aInTipText,
146 const nsAString& aDirText);
147 NS_IMETHOD HideTooltip();
148 nsITooltipTextProvider* GetTooltipTextProvider();
150 nsWebBrowser* mWebBrowser;
151 nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
152 nsCOMPtr<nsITooltipTextProvider> mTooltipTextProvider;
154 // This must be a strong ref in order to make sure we can hide the tooltip if
155 // the window goes away while we're displaying one. If we don't hold a strong
156 // ref, the chrome might have been disposed of before we get a chance to tell
157 // it, and no one would ever tell us of that fact.
158 nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
160 bool mTooltipListenerInstalled;
162 nsCOMPtr<nsITimer> mTooltipTimer;
163 static void sTooltipCallback(nsITimer* aTimer, void* aListener);
165 // Mouse coordinates for last mousemove event we saw
166 int32_t mMouseClientX;
167 int32_t mMouseClientY;
169 // Mouse coordinates for tooltip event
170 int32_t mMouseScreenX;
171 int32_t mMouseScreenY;
173 bool mShowingTooltip;
175 bool mTooltipShownOnce;
177 // The string of text that we last displayed.
178 nsString mLastShownTooltipText;
180 // The node hovered over that fired the timer. This may turn into the node
181 // that triggered the tooltip, but only if the timer ever gets around to
182 // firing. This is a strong reference, because the tooltip content can be
183 // destroyed while we're waiting for the tooltip to pop up, and we need to
184 // detect that. It's set only when the tooltip timer is created and launched.
185 // The timer must either fire or be cancelled (or possibly released?), and we
186 // release this reference in each of those cases. So we don't leak.
187 nsCOMPtr<nsINode> mPossibleTooltipNode;
190 #endif /* nsDocShellTreeOwner_h__ */