Bug 545431, fix versioning of mac sdks, r=ted.mielczarek
[gecko.git] / embedding / browser / webBrowser / nsDocShellTreeOwner.h
blobde48b51c84f52f06551391caacb824e3f28894ab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is the Mozilla browser.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications, Inc.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Travis Bogard <travis@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsDocShellTreeOwner_h__
41 #define nsDocShellTreeOwner_h__
43 // Helper Classes
44 #include "nsCOMPtr.h"
45 #include "nsString.h"
47 // Interfaces Needed
48 #include "nsIBaseWindow.h"
49 #include "nsIDocShellTreeOwner.h"
50 #include "nsIInterfaceRequestor.h"
51 #include "nsIInterfaceRequestorUtils.h"
52 #include "nsIWebBrowserChrome.h"
53 #include "nsIDOMMouseListener.h"
54 #include "nsIDOMDocument.h"
55 #include "nsIDOMEventTarget.h"
56 #include "nsIEmbeddingSiteWindow.h"
57 #include "nsIWebProgressListener.h"
58 #include "nsWeakReference.h"
59 #include "nsIDOMKeyListener.h"
60 #include "nsIDOMMouseMotionListener.h"
61 #include "nsIDOMContextMenuListener.h"
62 #include "nsITimer.h"
63 #include "nsIPrompt.h"
64 #include "nsIAuthPrompt.h"
65 #include "nsITooltipListener.h"
66 #include "nsITooltipTextProvider.h"
67 #include "nsCTooltipTextProvider.h"
68 #include "nsIDragDropHandler.h"
69 #include "nsPIDOMEventTarget.h"
70 #include "nsCommandHandler.h"
72 class nsWebBrowser;
73 class ChromeTooltipListener;
74 class ChromeContextMenuListener;
76 // {6D10C180-6888-11d4-952B-0020183BF181}
77 #define NS_ICDOCSHELLTREEOWNER_IID \
78 { 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
81 * This is a fake 'hidden' interface that nsDocShellTreeOwner implements.
82 * Classes such as nsCommandHandler can QI for this interface to be
83 * sure that they're dealing with a valid nsDocShellTreeOwner and not some
84 * other object that implements nsIDocShellTreeOwner.
86 class nsICDocShellTreeOwner : public nsISupports
88 public:
89 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID)
92 NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner,
93 NS_ICDOCSHELLTREEOWNER_IID)
95 class nsDocShellTreeOwner : public nsIDocShellTreeOwner,
96 public nsIBaseWindow,
97 public nsIInterfaceRequestor,
98 public nsIWebProgressListener,
99 public nsICDocShellTreeOwner,
100 public nsSupportsWeakReference
102 friend class nsWebBrowser;
103 friend class nsCommandHandler;
105 public:
106 NS_DECL_ISUPPORTS
108 NS_DECL_NSIBASEWINDOW
109 NS_DECL_NSIDOCSHELLTREEOWNER
110 NS_DECL_NSIINTERFACEREQUESTOR
111 NS_DECL_NSIWEBPROGRESSLISTENER
113 protected:
114 nsDocShellTreeOwner();
115 virtual ~nsDocShellTreeOwner();
117 void WebBrowser(nsWebBrowser* aWebBrowser);
119 nsWebBrowser* WebBrowser();
120 NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner);
121 NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome);
123 NS_IMETHOD AddChromeListeners();
124 NS_IMETHOD RemoveChromeListeners();
126 nsresult FindItemWithNameAcrossWindows(const PRUnichar* aName,
127 nsIDocShellTreeItem* aRequestor,
128 nsIDocShellTreeItem* aOriginalRequestor,
129 nsIDocShellTreeItem **aFoundItem);
131 void EnsurePrompter();
132 void EnsureAuthPrompter();
134 void AddToWatcher();
135 void RemoveFromWatcher();
137 // These helper functions return the correct instances of the requested
138 // interfaces. If the object passed to SetWebBrowserChrome() implements
139 // nsISupportsWeakReference, then these functions call QueryReferent on
140 // that object. Otherwise, they return an addrefed pointer. If the
141 // WebBrowserChrome object doesn't exist, they return nsnull.
142 already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome();
143 already_AddRefed<nsIEmbeddingSiteWindow> GetOwnerWin();
144 already_AddRefed<nsIInterfaceRequestor> GetOwnerRequestor();
146 protected:
148 // Weak References
149 nsWebBrowser* mWebBrowser;
150 nsIDocShellTreeOwner* mTreeOwner;
151 nsIDocShellTreeItem* mPrimaryContentShell;
153 nsIWebBrowserChrome* mWebBrowserChrome;
154 nsIEmbeddingSiteWindow* mOwnerWin;
155 nsIInterfaceRequestor* mOwnerRequestor;
157 nsWeakPtr mWebBrowserChromeWeak; // nsIWebBrowserChrome
159 // the objects that listen for chrome events like context menus and tooltips.
160 // They are separate objects to avoid circular references between |this|
161 // and the DOM. These are strong, owning refs.
162 ChromeTooltipListener* mChromeTooltipListener;
163 ChromeContextMenuListener* mChromeContextMenuListener;
164 nsCOMPtr<nsIDragDropHandler> mChromeDragHandler;
166 nsCOMPtr<nsIPrompt> mPrompter;
167 nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
172 // class ChromeTooltipListener
174 // The class that listens to the chrome events and tells the embedding
175 // chrome to show tooltips, as appropriate. Handles registering itself
176 // with the DOM with AddChromeListeners() and removing itself with
177 // RemoveChromeListeners().
179 class ChromeTooltipListener : public nsIDOMMouseListener,
180 public nsIDOMKeyListener,
181 public nsIDOMMouseMotionListener
183 public:
184 NS_DECL_ISUPPORTS
186 ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
187 virtual ~ChromeTooltipListener ( ) ;
189 // nsIDOMMouseListener
190 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
191 NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
192 NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
193 NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
194 NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
195 NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
196 NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
198 // nsIDOMMouseMotionListener
199 NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
200 NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
202 // nsIDOMKeyListener
203 NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent) ;
204 NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) ;
205 NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent) ;
207 // Add/remove the relevant listeners, based on what interfaces
208 // the embedding chrome implements.
209 NS_IMETHOD AddChromeListeners();
210 NS_IMETHOD RemoveChromeListeners();
212 private:
214 // various delays for tooltips
215 enum {
216 kTooltipAutoHideTime = 5000, // 5000ms = 5 seconds
217 kTooltipShowTime = 500 // 500ms = 0.5 seconds
220 NS_IMETHOD AddTooltipListener();
221 NS_IMETHOD RemoveTooltipListener();
223 NS_IMETHOD ShowTooltip ( PRInt32 inXCoords, PRInt32 inYCoords, const nsAString & inTipText ) ;
224 NS_IMETHOD HideTooltip ( ) ;
226 nsWebBrowser* mWebBrowser;
227 nsCOMPtr<nsPIDOMEventTarget> mEventTarget;
228 nsCOMPtr<nsITooltipTextProvider> mTooltipTextProvider;
230 // This must be a strong ref in order to make sure we can hide the tooltip
231 // if the window goes away while we're displaying one. If we don't hold
232 // a strong ref, the chrome might have been disposed of before we get a chance
233 // to tell it, and no one would ever tell us of that fact.
234 nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
236 PRPackedBool mTooltipListenerInstalled;
238 nsCOMPtr<nsITimer> mTooltipTimer;
239 static void sTooltipCallback ( nsITimer* aTimer, void* aListener ) ;
240 PRInt32 mMouseClientX, mMouseClientY; // mouse coordinates for last mousemove event we saw
241 PRInt32 mMouseScreenX, mMouseScreenY; // mouse coordinates for tooltip event
242 PRBool mShowingTooltip;
244 // a timer for auto-hiding the tooltip after a certain delay
245 nsCOMPtr<nsITimer> mAutoHideTimer;
246 static void sAutoHideCallback ( nsITimer* aTimer, void* aListener ) ;
247 void CreateAutoHideTimer ( ) ;
249 // The node hovered over that fired the timer. This may turn into the node that
250 // triggered the tooltip, but only if the timer ever gets around to firing.
251 // This is a strong reference, because the tooltip content can be destroyed while we're
252 // waiting for the tooltip to pup up, and we need to detect that.
253 // It's set only when the tooltip timer is created and launched. The timer must
254 // either fire or be cancelled (or possibly released?), and we release this
255 // reference in each of those cases. So we don't leak.
256 nsCOMPtr<nsIDOMNode> mPossibleTooltipNode;
258 }; // ChromeTooltipListener
262 // class ChromeContextMenuListener
264 // The class that listens to the chrome events and tells the embedding
265 // chrome to show context menus, as appropriate. Handles registering itself
266 // with the DOM with AddChromeListeners() and removing itself with
267 // RemoveChromeListeners().
269 class ChromeContextMenuListener : public nsIDOMContextMenuListener
271 public:
272 NS_DECL_ISUPPORTS
274 ChromeContextMenuListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
275 virtual ~ChromeContextMenuListener ( ) ;
277 // nsIDOMContextMenuListener
278 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
279 NS_IMETHOD ContextMenu ( nsIDOMEvent* aEvent );
281 // Add/remove the relevant listeners, based on what interfaces
282 // the embedding chrome implements.
283 NS_IMETHOD AddChromeListeners();
284 NS_IMETHOD RemoveChromeListeners();
286 private:
288 NS_IMETHOD AddContextMenuListener();
289 NS_IMETHOD RemoveContextMenuListener();
291 PRPackedBool mContextMenuListenerInstalled;
293 nsWebBrowser* mWebBrowser;
294 nsCOMPtr<nsPIDOMEventTarget> mEventTarget;
295 nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
297 }; // class ChromeContextMenuListener
301 #endif /* nsDocShellTreeOwner_h__ */