|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * |
|
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/. */ |
|
6 |
|
7 #ifndef nsDocShellTreeOwner_h__ |
|
8 #define nsDocShellTreeOwner_h__ |
|
9 |
|
10 // Helper Classes |
|
11 #include "nsCOMPtr.h" |
|
12 #include "nsString.h" |
|
13 |
|
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" |
|
31 #include "nsCommandHandler.h" |
|
32 |
|
33 namespace mozilla { |
|
34 namespace dom { |
|
35 class EventTarget; |
|
36 } |
|
37 } |
|
38 |
|
39 class nsWebBrowser; |
|
40 class ChromeTooltipListener; |
|
41 class ChromeContextMenuListener; |
|
42 |
|
43 // {6D10C180-6888-11d4-952B-0020183BF181} |
|
44 #define NS_ICDOCSHELLTREEOWNER_IID \ |
|
45 { 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } } |
|
46 |
|
47 /* |
|
48 * This is a fake 'hidden' interface that nsDocShellTreeOwner implements. |
|
49 * Classes such as nsCommandHandler can QI for this interface to be |
|
50 * sure that they're dealing with a valid nsDocShellTreeOwner and not some |
|
51 * other object that implements nsIDocShellTreeOwner. |
|
52 */ |
|
53 class nsICDocShellTreeOwner : public nsISupports |
|
54 { |
|
55 public: |
|
56 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID) |
|
57 }; |
|
58 |
|
59 NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner, |
|
60 NS_ICDOCSHELLTREEOWNER_IID) |
|
61 |
|
62 class nsDocShellTreeOwner : public nsIDocShellTreeOwner, |
|
63 public nsIBaseWindow, |
|
64 public nsIInterfaceRequestor, |
|
65 public nsIWebProgressListener, |
|
66 public nsIDOMEventListener, |
|
67 public nsICDocShellTreeOwner, |
|
68 public nsSupportsWeakReference |
|
69 { |
|
70 friend class nsWebBrowser; |
|
71 friend class nsCommandHandler; |
|
72 |
|
73 public: |
|
74 NS_DECL_ISUPPORTS |
|
75 |
|
76 NS_DECL_NSIBASEWINDOW |
|
77 NS_DECL_NSIDOCSHELLTREEOWNER |
|
78 NS_DECL_NSIDOMEVENTLISTENER |
|
79 NS_DECL_NSIINTERFACEREQUESTOR |
|
80 NS_DECL_NSIWEBPROGRESSLISTENER |
|
81 |
|
82 protected: |
|
83 nsDocShellTreeOwner(); |
|
84 virtual ~nsDocShellTreeOwner(); |
|
85 |
|
86 void WebBrowser(nsWebBrowser* aWebBrowser); |
|
87 |
|
88 nsWebBrowser* WebBrowser(); |
|
89 NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner); |
|
90 NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome); |
|
91 |
|
92 NS_IMETHOD AddChromeListeners(); |
|
93 NS_IMETHOD RemoveChromeListeners(); |
|
94 |
|
95 nsresult FindItemWithNameAcrossWindows(const char16_t* aName, |
|
96 nsIDocShellTreeItem* aRequestor, |
|
97 nsIDocShellTreeItem* aOriginalRequestor, |
|
98 nsIDocShellTreeItem **aFoundItem); |
|
99 |
|
100 void EnsurePrompter(); |
|
101 void EnsureAuthPrompter(); |
|
102 |
|
103 void AddToWatcher(); |
|
104 void RemoveFromWatcher(); |
|
105 |
|
106 // These helper functions return the correct instances of the requested |
|
107 // interfaces. If the object passed to SetWebBrowserChrome() implements |
|
108 // nsISupportsWeakReference, then these functions call QueryReferent on |
|
109 // that object. Otherwise, they return an addrefed pointer. If the |
|
110 // WebBrowserChrome object doesn't exist, they return nullptr. |
|
111 already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome(); |
|
112 already_AddRefed<nsIEmbeddingSiteWindow> GetOwnerWin(); |
|
113 already_AddRefed<nsIInterfaceRequestor> GetOwnerRequestor(); |
|
114 |
|
115 protected: |
|
116 |
|
117 // Weak References |
|
118 nsWebBrowser* mWebBrowser; |
|
119 nsIDocShellTreeOwner* mTreeOwner; |
|
120 nsIDocShellTreeItem* mPrimaryContentShell; |
|
121 |
|
122 nsIWebBrowserChrome* mWebBrowserChrome; |
|
123 nsIEmbeddingSiteWindow* mOwnerWin; |
|
124 nsIInterfaceRequestor* mOwnerRequestor; |
|
125 |
|
126 nsWeakPtr mWebBrowserChromeWeak; // nsIWebBrowserChrome |
|
127 |
|
128 // the objects that listen for chrome events like context menus and tooltips. |
|
129 // They are separate objects to avoid circular references between |this| |
|
130 // and the DOM. These are strong, owning refs. |
|
131 ChromeTooltipListener* mChromeTooltipListener; |
|
132 ChromeContextMenuListener* mChromeContextMenuListener; |
|
133 |
|
134 nsCOMPtr<nsIPrompt> mPrompter; |
|
135 nsCOMPtr<nsIAuthPrompt> mAuthPrompter; |
|
136 }; |
|
137 |
|
138 |
|
139 // |
|
140 // class ChromeTooltipListener |
|
141 // |
|
142 // The class that listens to the chrome events and tells the embedding |
|
143 // chrome to show tooltips, as appropriate. Handles registering itself |
|
144 // with the DOM with AddChromeListeners() and removing itself with |
|
145 // RemoveChromeListeners(). |
|
146 // |
|
147 class ChromeTooltipListener : public nsIDOMEventListener |
|
148 { |
|
149 public: |
|
150 NS_DECL_ISUPPORTS |
|
151 |
|
152 ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ; |
|
153 virtual ~ChromeTooltipListener ( ) ; |
|
154 |
|
155 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); |
|
156 NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent); |
|
157 |
|
158 // Add/remove the relevant listeners, based on what interfaces |
|
159 // the embedding chrome implements. |
|
160 NS_IMETHOD AddChromeListeners(); |
|
161 NS_IMETHOD RemoveChromeListeners(); |
|
162 |
|
163 private: |
|
164 |
|
165 // various delays for tooltips |
|
166 enum { |
|
167 kTooltipAutoHideTime = 5000 // 5000ms = 5 seconds |
|
168 }; |
|
169 |
|
170 NS_IMETHOD AddTooltipListener(); |
|
171 NS_IMETHOD RemoveTooltipListener(); |
|
172 |
|
173 NS_IMETHOD ShowTooltip ( int32_t inXCoords, int32_t inYCoords, const nsAString & inTipText ) ; |
|
174 NS_IMETHOD HideTooltip ( ) ; |
|
175 |
|
176 nsWebBrowser* mWebBrowser; |
|
177 nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; |
|
178 nsCOMPtr<nsITooltipTextProvider> mTooltipTextProvider; |
|
179 |
|
180 // This must be a strong ref in order to make sure we can hide the tooltip |
|
181 // if the window goes away while we're displaying one. If we don't hold |
|
182 // a strong ref, the chrome might have been disposed of before we get a chance |
|
183 // to tell it, and no one would ever tell us of that fact. |
|
184 nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome; |
|
185 |
|
186 bool mTooltipListenerInstalled; |
|
187 |
|
188 nsCOMPtr<nsITimer> mTooltipTimer; |
|
189 static void sTooltipCallback ( nsITimer* aTimer, void* aListener ) ; |
|
190 int32_t mMouseClientX, mMouseClientY; // mouse coordinates for last mousemove event we saw |
|
191 int32_t mMouseScreenX, mMouseScreenY; // mouse coordinates for tooltip event |
|
192 bool mShowingTooltip; |
|
193 |
|
194 // a timer for auto-hiding the tooltip after a certain delay |
|
195 nsCOMPtr<nsITimer> mAutoHideTimer; |
|
196 static void sAutoHideCallback ( nsITimer* aTimer, void* aListener ) ; |
|
197 void CreateAutoHideTimer ( ) ; |
|
198 |
|
199 // The node hovered over that fired the timer. This may turn into the node that |
|
200 // triggered the tooltip, but only if the timer ever gets around to firing. |
|
201 // This is a strong reference, because the tooltip content can be destroyed while we're |
|
202 // waiting for the tooltip to pup up, and we need to detect that. |
|
203 // It's set only when the tooltip timer is created and launched. The timer must |
|
204 // either fire or be cancelled (or possibly released?), and we release this |
|
205 // reference in each of those cases. So we don't leak. |
|
206 nsCOMPtr<nsIDOMNode> mPossibleTooltipNode; |
|
207 |
|
208 }; // ChromeTooltipListener |
|
209 |
|
210 |
|
211 // |
|
212 // class ChromeContextMenuListener |
|
213 // |
|
214 // The class that listens to the chrome events and tells the embedding |
|
215 // chrome to show context menus, as appropriate. Handles registering itself |
|
216 // with the DOM with AddChromeListeners() and removing itself with |
|
217 // RemoveChromeListeners(). |
|
218 // |
|
219 class ChromeContextMenuListener : public nsIDOMEventListener |
|
220 { |
|
221 public: |
|
222 NS_DECL_ISUPPORTS |
|
223 |
|
224 ChromeContextMenuListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ; |
|
225 virtual ~ChromeContextMenuListener ( ) ; |
|
226 |
|
227 // nsIDOMContextMenuListener |
|
228 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); |
|
229 |
|
230 // Add/remove the relevant listeners, based on what interfaces |
|
231 // the embedding chrome implements. |
|
232 NS_IMETHOD AddChromeListeners(); |
|
233 NS_IMETHOD RemoveChromeListeners(); |
|
234 |
|
235 private: |
|
236 |
|
237 NS_IMETHOD AddContextMenuListener(); |
|
238 NS_IMETHOD RemoveContextMenuListener(); |
|
239 |
|
240 bool mContextMenuListenerInstalled; |
|
241 |
|
242 nsWebBrowser* mWebBrowser; |
|
243 nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; |
|
244 nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome; |
|
245 |
|
246 }; // class ChromeContextMenuListener |
|
247 |
|
248 |
|
249 |
|
250 #endif /* nsDocShellTreeOwner_h__ */ |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |