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
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.
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__
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"
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"
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
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
,
97 public nsIInterfaceRequestor
,
98 public nsIWebProgressListener
,
99 public nsICDocShellTreeOwner
,
100 public nsSupportsWeakReference
102 friend class nsWebBrowser
;
103 friend class nsCommandHandler
;
108 NS_DECL_NSIBASEWINDOW
109 NS_DECL_NSIDOCSHELLTREEOWNER
110 NS_DECL_NSIINTERFACEREQUESTOR
111 NS_DECL_NSIWEBPROGRESSLISTENER
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
FindChildWithName(const PRUnichar
*aName
,
127 PRBool aRecurse
, nsIDocShellTreeItem
* aRequestor
,
128 nsIDocShellTreeItem
* aOriginalRequestor
,
129 nsIDocShellTreeItem
**aFoundItem
);
130 nsresult
FindItemWithNameAcrossWindows(const PRUnichar
* aName
,
131 nsIDocShellTreeItem
* aRequestor
,
132 nsIDocShellTreeItem
* aOriginalRequestor
,
133 nsIDocShellTreeItem
**aFoundItem
);
135 void EnsurePrompter();
136 void EnsureAuthPrompter();
139 void RemoveFromWatcher();
141 // These helper functions return the correct instances of the requested
142 // interfaces. If the object passed to SetWebBrowserChrome() implements
143 // nsISupportsWeakReference, then these functions call QueryReferent on
144 // that object. Otherwise, they return an addrefed pointer. If the
145 // WebBrowserChrome object doesn't exist, they return nsnull.
146 already_AddRefed
<nsIWebBrowserChrome
> GetWebBrowserChrome();
147 already_AddRefed
<nsIEmbeddingSiteWindow
> GetOwnerWin();
148 already_AddRefed
<nsIInterfaceRequestor
> GetOwnerRequestor();
153 nsWebBrowser
* mWebBrowser
;
154 nsIDocShellTreeOwner
* mTreeOwner
;
155 nsIDocShellTreeItem
* mPrimaryContentShell
;
157 nsIWebBrowserChrome
* mWebBrowserChrome
;
158 nsIEmbeddingSiteWindow
* mOwnerWin
;
159 nsIInterfaceRequestor
* mOwnerRequestor
;
161 nsWeakPtr mWebBrowserChromeWeak
; // nsIWebBrowserChrome
163 // the objects that listen for chrome events like context menus and tooltips.
164 // They are separate objects to avoid circular references between |this|
165 // and the DOM. These are strong, owning refs.
166 ChromeTooltipListener
* mChromeTooltipListener
;
167 ChromeContextMenuListener
* mChromeContextMenuListener
;
168 nsCOMPtr
<nsIDragDropHandler
> mChromeDragHandler
;
170 nsCOMPtr
<nsIPrompt
> mPrompter
;
171 nsCOMPtr
<nsIAuthPrompt
> mAuthPrompter
;
176 // class ChromeTooltipListener
178 // The class that listens to the chrome events and tells the embedding
179 // chrome to show tooltips, as appropriate. Handles registering itself
180 // with the DOM with AddChromeListeners() and removing itself with
181 // RemoveChromeListeners().
183 class ChromeTooltipListener
: public nsIDOMMouseListener
,
184 public nsIDOMKeyListener
,
185 public nsIDOMMouseMotionListener
190 ChromeTooltipListener ( nsWebBrowser
* inBrowser
, nsIWebBrowserChrome
* inChrome
) ;
191 virtual ~ChromeTooltipListener ( ) ;
193 // nsIDOMMouseListener
194 NS_IMETHOD
HandleEvent(nsIDOMEvent
* aEvent
) { return NS_OK
; }
195 NS_IMETHOD
MouseDown(nsIDOMEvent
* aMouseEvent
);
196 NS_IMETHOD
MouseUp(nsIDOMEvent
* aMouseEvent
);
197 NS_IMETHOD
MouseClick(nsIDOMEvent
* aMouseEvent
);
198 NS_IMETHOD
MouseDblClick(nsIDOMEvent
* aMouseEvent
);
199 NS_IMETHOD
MouseOver(nsIDOMEvent
* aMouseEvent
);
200 NS_IMETHOD
MouseOut(nsIDOMEvent
* aMouseEvent
);
202 // nsIDOMMouseMotionListener
203 NS_IMETHOD
MouseMove(nsIDOMEvent
* aMouseEvent
);
204 NS_IMETHOD
DragMove(nsIDOMEvent
* aMouseEvent
) { return NS_OK
; }
207 NS_IMETHOD
KeyDown(nsIDOMEvent
* aKeyEvent
) ;
208 NS_IMETHOD
KeyUp(nsIDOMEvent
* aKeyEvent
) ;
209 NS_IMETHOD
KeyPress(nsIDOMEvent
* aKeyEvent
) ;
211 // Add/remove the relevant listeners, based on what interfaces
212 // the embedding chrome implements.
213 NS_IMETHOD
AddChromeListeners();
214 NS_IMETHOD
RemoveChromeListeners();
218 // various delays for tooltips
220 kTooltipAutoHideTime
= 5000, // 5000ms = 5 seconds
221 kTooltipShowTime
= 500 // 500ms = 0.5 seconds
224 NS_IMETHOD
AddTooltipListener();
225 NS_IMETHOD
RemoveTooltipListener();
227 NS_IMETHOD
ShowTooltip ( PRInt32 inXCoords
, PRInt32 inYCoords
, const nsAString
& inTipText
) ;
228 NS_IMETHOD
HideTooltip ( ) ;
230 nsWebBrowser
* mWebBrowser
;
231 nsCOMPtr
<nsPIDOMEventTarget
> mEventTarget
;
232 nsCOMPtr
<nsITooltipTextProvider
> mTooltipTextProvider
;
234 // This must be a strong ref in order to make sure we can hide the tooltip
235 // if the window goes away while we're displaying one. If we don't hold
236 // a strong ref, the chrome might have been disposed of before we get a chance
237 // to tell it, and no one would ever tell us of that fact.
238 nsCOMPtr
<nsIWebBrowserChrome
> mWebBrowserChrome
;
240 PRPackedBool mTooltipListenerInstalled
;
242 nsCOMPtr
<nsITimer
> mTooltipTimer
;
243 static void sTooltipCallback ( nsITimer
* aTimer
, void* aListener
) ;
244 PRInt32 mMouseClientX
, mMouseClientY
; // mouse coordinates for last mousemove event we saw
245 PRInt32 mMouseScreenX
, mMouseScreenY
; // mouse coordinates for tooltip event
246 PRBool mShowingTooltip
;
248 // a timer for auto-hiding the tooltip after a certain delay
249 nsCOMPtr
<nsITimer
> mAutoHideTimer
;
250 static void sAutoHideCallback ( nsITimer
* aTimer
, void* aListener
) ;
251 void CreateAutoHideTimer ( ) ;
253 // The node hovered over that fired the timer. This may turn into the node that
254 // triggered the tooltip, but only if the timer ever gets around to firing.
255 // This is a strong reference, because the tooltip content can be destroyed while we're
256 // waiting for the tooltip to pup up, and we need to detect that.
257 // It's set only when the tooltip timer is created and launched. The timer must
258 // either fire or be cancelled (or possibly released?), and we release this
259 // reference in each of those cases. So we don't leak.
260 nsCOMPtr
<nsIDOMNode
> mPossibleTooltipNode
;
262 }; // ChromeTooltipListener
266 // class ChromeContextMenuListener
268 // The class that listens to the chrome events and tells the embedding
269 // chrome to show context menus, as appropriate. Handles registering itself
270 // with the DOM with AddChromeListeners() and removing itself with
271 // RemoveChromeListeners().
273 class ChromeContextMenuListener
: public nsIDOMContextMenuListener
278 ChromeContextMenuListener ( nsWebBrowser
* inBrowser
, nsIWebBrowserChrome
* inChrome
) ;
279 virtual ~ChromeContextMenuListener ( ) ;
281 // nsIDOMContextMenuListener
282 NS_IMETHOD
HandleEvent(nsIDOMEvent
* aEvent
) { return NS_OK
; }
283 NS_IMETHOD
ContextMenu ( nsIDOMEvent
* aEvent
);
285 // Add/remove the relevant listeners, based on what interfaces
286 // the embedding chrome implements.
287 NS_IMETHOD
AddChromeListeners();
288 NS_IMETHOD
RemoveChromeListeners();
292 NS_IMETHOD
AddContextMenuListener();
293 NS_IMETHOD
RemoveContextMenuListener();
295 PRPackedBool mContextMenuListenerInstalled
;
297 nsWebBrowser
* mWebBrowser
;
298 nsCOMPtr
<nsPIDOMEventTarget
> mEventTarget
;
299 nsCOMPtr
<nsIWebBrowserChrome
> mWebBrowserChrome
;
301 }; // class ChromeContextMenuListener
305 #endif /* nsDocShellTreeOwner_h__ */