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 #include "mozilla/dom/BarProps.h"
8 #include "mozilla/dom/BarPropBinding.h"
9 #include "nsContentUtils.h"
10 #include "nsDocShell.h"
11 #include "nsGlobalWindow.h"
12 #include "nsIWebBrowserChrome.h"
18 // Basic (virtual) BarProp class implementation
20 BarProp::BarProp(nsGlobalWindowInner
* aWindow
) : mDOMWindow(aWindow
) {}
22 BarProp::~BarProp() = default;
24 nsPIDOMWindowInner
* BarProp::GetParentObject() const { return mDOMWindow
; }
26 JSObject
* BarProp::WrapObject(JSContext
* aCx
,
27 JS::Handle
<JSObject
*> aGivenProto
) {
28 return BarProp_Binding::Wrap(aCx
, this, aGivenProto
);
31 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BarProp
, mDOMWindow
)
32 NS_IMPL_CYCLE_COLLECTING_ADDREF(BarProp
)
33 NS_IMPL_CYCLE_COLLECTING_RELEASE(BarProp
)
34 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BarProp
)
35 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
36 NS_INTERFACE_MAP_ENTRY(nsISupports
)
39 bool BarProp::GetVisibleByFlag(uint32_t aChromeFlag
, ErrorResult
& aRv
) {
40 nsCOMPtr
<nsIWebBrowserChrome
> browserChrome
= GetBrowserChrome();
41 NS_ENSURE_TRUE(browserChrome
, false);
45 if (NS_FAILED(browserChrome
->GetChromeFlags(&chromeFlags
))) {
46 aRv
.Throw(NS_ERROR_FAILURE
);
50 return (chromeFlags
& aChromeFlag
);
53 void BarProp::SetVisibleByFlag(bool aVisible
, uint32_t aChromeFlag
,
54 CallerType aCallerType
, ErrorResult
& aRv
) {
55 nsCOMPtr
<nsIWebBrowserChrome
> browserChrome
= GetBrowserChrome();
56 NS_ENSURE_TRUE_VOID(browserChrome
);
58 if (aCallerType
!= CallerType::System
) {
64 if (NS_FAILED(browserChrome
->GetChromeFlags(&chromeFlags
))) {
65 aRv
.Throw(NS_ERROR_FAILURE
);
70 chromeFlags
|= aChromeFlag
;
72 chromeFlags
&= ~aChromeFlag
;
74 if (NS_FAILED(browserChrome
->SetChromeFlags(chromeFlags
))) {
75 aRv
.Throw(NS_ERROR_FAILURE
);
79 already_AddRefed
<nsIWebBrowserChrome
> BarProp::GetBrowserChrome() {
84 return mDOMWindow
->GetWebBrowserChrome();
88 // MenubarProp class implementation
91 MenubarProp::MenubarProp(nsGlobalWindowInner
* aWindow
) : BarProp(aWindow
) {}
93 MenubarProp::~MenubarProp() = default;
95 bool MenubarProp::GetVisible(CallerType aCallerType
, ErrorResult
& aRv
) {
96 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_MENUBAR
, aRv
);
99 void MenubarProp::SetVisible(bool aVisible
, CallerType aCallerType
,
101 BarProp::SetVisibleByFlag(aVisible
, nsIWebBrowserChrome::CHROME_MENUBAR
,
106 // ToolbarProp class implementation
109 ToolbarProp::ToolbarProp(nsGlobalWindowInner
* aWindow
) : BarProp(aWindow
) {}
111 ToolbarProp::~ToolbarProp() = default;
113 bool ToolbarProp::GetVisible(CallerType aCallerType
, ErrorResult
& aRv
) {
114 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_TOOLBAR
, aRv
);
117 void ToolbarProp::SetVisible(bool aVisible
, CallerType aCallerType
,
119 BarProp::SetVisibleByFlag(aVisible
, nsIWebBrowserChrome::CHROME_TOOLBAR
,
124 // LocationbarProp class implementation
127 LocationbarProp::LocationbarProp(nsGlobalWindowInner
* aWindow
)
128 : BarProp(aWindow
) {}
130 LocationbarProp::~LocationbarProp() = default;
132 bool LocationbarProp::GetVisible(CallerType aCallerType
, ErrorResult
& aRv
) {
133 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_LOCATIONBAR
,
137 void LocationbarProp::SetVisible(bool aVisible
, CallerType aCallerType
,
139 BarProp::SetVisibleByFlag(aVisible
, nsIWebBrowserChrome::CHROME_LOCATIONBAR
,
144 // PersonalbarProp class implementation
147 PersonalbarProp::PersonalbarProp(nsGlobalWindowInner
* aWindow
)
148 : BarProp(aWindow
) {}
150 PersonalbarProp::~PersonalbarProp() = default;
152 bool PersonalbarProp::GetVisible(CallerType aCallerType
, ErrorResult
& aRv
) {
153 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR
,
157 void PersonalbarProp::SetVisible(bool aVisible
, CallerType aCallerType
,
159 BarProp::SetVisibleByFlag(
160 aVisible
, nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR
, aCallerType
, aRv
);
164 // StatusbarProp class implementation
167 StatusbarProp::StatusbarProp(nsGlobalWindowInner
* aWindow
) : BarProp(aWindow
) {}
169 StatusbarProp::~StatusbarProp() = default;
171 bool StatusbarProp::GetVisible(CallerType aCallerType
, ErrorResult
& aRv
) {
172 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_STATUSBAR
, aRv
);
175 void StatusbarProp::SetVisible(bool aVisible
, CallerType aCallerType
,
177 return BarProp::SetVisibleByFlag(
178 aVisible
, nsIWebBrowserChrome::CHROME_STATUSBAR
, aCallerType
, aRv
);
182 // ScrollbarsProp class implementation
185 ScrollbarsProp::ScrollbarsProp(nsGlobalWindowInner
* aWindow
)
186 : BarProp(aWindow
) {}
188 ScrollbarsProp::~ScrollbarsProp() = default;
190 bool ScrollbarsProp::GetVisible(CallerType aCallerType
, ErrorResult
& aRv
) {
195 nsIDocShell
* ds
= mDOMWindow
->GetDocShell();
200 ScrollbarPreference pref
= nsDocShell::Cast(ds
)->ScrollbarPreference();
201 return pref
!= ScrollbarPreference::Never
;
204 void ScrollbarsProp::SetVisible(bool aVisible
, CallerType
, ErrorResult
&) {
209 } // namespace mozilla