1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Travis Bogard <travis@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 #include "nsBarProps.h"
42 #include "nsGlobalWindow.h"
43 #include "nsStyleConsts.h"
44 #include "nsIDocShell.h"
45 #include "nsIScriptSecurityManager.h"
46 #include "nsIScrollable.h"
47 #include "nsIWebBrowserChrome.h"
48 #include "nsIDOMWindowInternal.h"
49 #include "nsDOMClassInfo.h"
52 // Basic (virtual) BarProp class implementation
54 nsBarProp::nsBarProp() : mBrowserChrome(nsnull
)
58 nsBarProp::~nsBarProp()
63 DOMCI_DATA(BarProp
, nsBarProp
)
65 // QueryInterface implementation for BarProp
66 NS_INTERFACE_MAP_BEGIN(nsBarProp
)
67 NS_INTERFACE_MAP_ENTRY(nsIDOMBarProp
)
68 NS_INTERFACE_MAP_ENTRY(nsISupports
)
69 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BarProp
)
73 NS_IMPL_ADDREF(nsBarProp
)
74 NS_IMPL_RELEASE(nsBarProp
)
78 nsBarProp::SetWebBrowserChrome(nsIWebBrowserChrome
* aBrowserChrome
)
80 mBrowserChrome
= aBrowserChrome
;
85 nsBarProp::GetVisibleByFlag(PRBool
*aVisible
, PRUint32 aChromeFlag
)
88 NS_ENSURE_TRUE(mBrowserChrome
, NS_OK
);
92 NS_ENSURE_SUCCESS(mBrowserChrome
->GetChromeFlags(&chromeFlags
),
94 if(chromeFlags
& aChromeFlag
)
101 nsBarProp::SetVisibleByFlag(PRBool aVisible
, PRUint32 aChromeFlag
)
103 NS_ENSURE_TRUE(mBrowserChrome
, NS_OK
);
105 PRBool enabled
= PR_FALSE
;
107 nsCOMPtr
<nsIScriptSecurityManager
>
108 securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID
));
110 securityManager
->IsCapabilityEnabled("UniversalBrowserWrite", &enabled
);
114 PRUint32 chromeFlags
;
116 NS_ENSURE_SUCCESS(mBrowserChrome
->GetChromeFlags(&chromeFlags
),
119 chromeFlags
|= aChromeFlag
;
121 chromeFlags
&= ~aChromeFlag
;
122 NS_ENSURE_SUCCESS(mBrowserChrome
->SetChromeFlags(chromeFlags
),
129 // MenubarProp class implementation
132 nsMenubarProp::nsMenubarProp()
136 nsMenubarProp::~nsMenubarProp()
141 nsMenubarProp::GetVisible(PRBool
*aVisible
)
143 return nsBarProp::GetVisibleByFlag(aVisible
,
144 nsIWebBrowserChrome::CHROME_MENUBAR
);
148 nsMenubarProp::SetVisible(PRBool aVisible
)
150 return nsBarProp::SetVisibleByFlag(aVisible
,
151 nsIWebBrowserChrome::CHROME_MENUBAR
);
155 // ToolbarProp class implementation
158 nsToolbarProp::nsToolbarProp()
162 nsToolbarProp::~nsToolbarProp()
167 nsToolbarProp::GetVisible(PRBool
*aVisible
)
169 return nsBarProp::GetVisibleByFlag(aVisible
,
170 nsIWebBrowserChrome::CHROME_TOOLBAR
);
174 nsToolbarProp::SetVisible(PRBool aVisible
)
176 return nsBarProp::SetVisibleByFlag(aVisible
,
177 nsIWebBrowserChrome::CHROME_TOOLBAR
);
181 // LocationbarProp class implementation
184 nsLocationbarProp::nsLocationbarProp()
188 nsLocationbarProp::~nsLocationbarProp()
193 nsLocationbarProp::GetVisible(PRBool
*aVisible
)
196 nsBarProp::GetVisibleByFlag(aVisible
,
197 nsIWebBrowserChrome::CHROME_LOCATIONBAR
);
201 nsLocationbarProp::SetVisible(PRBool aVisible
)
204 nsBarProp::SetVisibleByFlag(aVisible
,
205 nsIWebBrowserChrome::CHROME_LOCATIONBAR
);
209 // PersonalbarProp class implementation
212 nsPersonalbarProp::nsPersonalbarProp()
216 nsPersonalbarProp::~nsPersonalbarProp()
221 nsPersonalbarProp::GetVisible(PRBool
*aVisible
)
224 nsBarProp::GetVisibleByFlag(aVisible
,
225 nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR
);
229 nsPersonalbarProp::SetVisible(PRBool aVisible
)
232 nsBarProp::SetVisibleByFlag(aVisible
,
233 nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR
);
237 // StatusbarProp class implementation
240 nsStatusbarProp::nsStatusbarProp()
244 nsStatusbarProp::~nsStatusbarProp()
249 nsStatusbarProp::GetVisible(PRBool
*aVisible
)
251 return nsBarProp::GetVisibleByFlag(aVisible
,
252 nsIWebBrowserChrome::CHROME_STATUSBAR
);
256 nsStatusbarProp::SetVisible(PRBool aVisible
)
258 return nsBarProp::SetVisibleByFlag(aVisible
,
259 nsIWebBrowserChrome::CHROME_STATUSBAR
);
263 // ScrollbarsProp class implementation
266 nsScrollbarsProp::nsScrollbarsProp(nsGlobalWindow
*aWindow
)
268 mDOMWindow
= aWindow
;
269 nsISupports
*supwin
= static_cast<nsIScriptGlobalObject
*>(aWindow
);
270 mDOMWindowWeakref
= do_GetWeakReference(supwin
);
273 nsScrollbarsProp::~nsScrollbarsProp()
278 nsScrollbarsProp::GetVisible(PRBool
*aVisible
)
280 *aVisible
= PR_TRUE
; // one assumes
282 nsCOMPtr
<nsIDOMWindow
> domwin(do_QueryReferent(mDOMWindowWeakref
));
283 if (domwin
) { // dom window not deleted
284 nsCOMPtr
<nsIScrollable
> scroller
=
285 do_QueryInterface(mDOMWindow
->GetDocShell());
289 scroller
->GetDefaultScrollbarPreferences(
290 nsIScrollable::ScrollOrientation_Y
, &prefValue
);
291 if (prefValue
== nsIScrollable::Scrollbar_Never
) // try the other way
292 scroller
->GetDefaultScrollbarPreferences(
293 nsIScrollable::ScrollOrientation_X
, &prefValue
);
295 if (prefValue
== nsIScrollable::Scrollbar_Never
)
296 *aVisible
= PR_FALSE
;
304 nsScrollbarsProp::SetVisible(PRBool aVisible
)
306 PRBool enabled
= PR_FALSE
;
308 nsCOMPtr
<nsIScriptSecurityManager
>
309 securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID
));
311 securityManager
->IsCapabilityEnabled("UniversalBrowserWrite", &enabled
);
315 /* Scrollbars, unlike the other barprops, implement visibility directly
316 rather than handing off to the superclass (and from there to the
317 chrome window) because scrollbar visibility uniquely applies only
318 to the window making the change (arguably. it does now, anyway.)
319 and because embedding apps have no interface for implementing this
320 themselves, and therefore the implementation must be internal. */
322 nsCOMPtr
<nsIDOMWindow
> domwin(do_QueryReferent(mDOMWindowWeakref
));
323 if (domwin
) { // dom window must still exist. use away.
324 nsCOMPtr
<nsIScrollable
> scroller
=
325 do_QueryInterface(mDOMWindow
->GetDocShell());
331 prefValue
= nsIScrollable::Scrollbar_Auto
;
333 prefValue
= nsIScrollable::Scrollbar_Never
;
336 scroller
->SetDefaultScrollbarPreferences(
337 nsIScrollable::ScrollOrientation_Y
, prefValue
);
338 scroller
->SetDefaultScrollbarPreferences(
339 nsIScrollable::ScrollOrientation_X
, prefValue
);
343 /* Notably absent is the part where we notify the chrome window using
344 mBrowserChrome->SetChromeFlags(). Given the possibility of multiple
345 DOM windows (multiple top-level windows, even) within a single
346 chrome window, the historical concept of a single "has scrollbars"
347 flag in the chrome is inapplicable, and we can't tell at this level
348 whether we represent the particular DOM window that makes this decision
351 So only this object (and its corresponding DOM window) knows whether
352 scrollbars are visible. The corresponding chrome window will need to
353 ask (one of) its DOM window(s) when it needs to know about scrollbar
354 visibility, rather than caching its own copy of that information.