2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
#include "mozilla/dom/BarProps.h"
|
2013-06-01 01:53:00 -07:00
|
|
|
#include "mozilla/dom/BarPropBinding.h"
|
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIScrollable.h"
|
2013-08-15 11:17:48 -07:00
|
|
|
#include "nsIWebBrowserChrome.h"
|
2013-05-31 03:30:00 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// Basic (virtual) BarProp class implementation
|
|
|
|
//
|
2013-05-31 03:30:00 -07:00
|
|
|
BarProp::BarProp(nsGlobalWindow *aWindow)
|
2013-06-01 01:53:00 -07:00
|
|
|
: mDOMWindow(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
SetIsDOMBinding();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
BarProp::~BarProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
nsPIDOMWindow*
|
|
|
|
BarProp::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mDOMWindow;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
JSObject*
|
|
|
|
BarProp::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
|
|
|
{
|
|
|
|
return BarPropBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(BarProp, mDOMWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(BarProp)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(BarProp)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BarProp)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
BarProp::GetVisibleByFlag(uint32_t aChromeFlag, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-27 13:54:07 -07:00
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
|
2013-06-01 01:53:00 -07:00
|
|
|
NS_ENSURE_TRUE(browserChrome, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t chromeFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
return (chromeFlags & aChromeFlag);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
BarProp::SetVisibleByFlag(bool aVisible, uint32_t aChromeFlag,
|
|
|
|
ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-27 13:54:07 -07:00
|
|
|
nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
|
2013-06-01 01:53:00 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(browserChrome);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t chromeFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-27 13:54:07 -07:00
|
|
|
if (aVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
chromeFlags |= aChromeFlag;
|
|
|
|
else
|
|
|
|
chromeFlags &= ~aChromeFlag;
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
if (NS_FAILED(browserChrome->SetChromeFlags(chromeFlags))) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-27 13:54:07 -07:00
|
|
|
already_AddRefed<nsIWebBrowserChrome>
|
2013-05-31 03:30:00 -07:00
|
|
|
BarProp::GetBrowserChrome()
|
2011-04-27 13:54:07 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
if (!mDOMWindow) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2013-06-01 01:53:00 -07:00
|
|
|
}
|
2011-04-27 13:54:07 -07:00
|
|
|
|
2013-04-25 23:51:04 -07:00
|
|
|
return mDOMWindow->GetWebBrowserChrome();
|
2011-04-27 13:54:07 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// MenubarProp class implementation
|
|
|
|
//
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
MenubarProp::MenubarProp(nsGlobalWindow *aWindow)
|
|
|
|
: BarProp(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
MenubarProp::~MenubarProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
MenubarProp::GetVisible(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_MENUBAR, aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
MenubarProp::SetVisible(bool aVisible, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_MENUBAR, aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ToolbarProp class implementation
|
|
|
|
//
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
ToolbarProp::ToolbarProp(nsGlobalWindow *aWindow)
|
|
|
|
: BarProp(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
ToolbarProp::~ToolbarProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
ToolbarProp::GetVisible(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_TOOLBAR, aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
ToolbarProp::SetVisible(bool aVisible, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_TOOLBAR,
|
|
|
|
aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// LocationbarProp class implementation
|
|
|
|
//
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
LocationbarProp::LocationbarProp(nsGlobalWindow *aWindow)
|
|
|
|
: BarProp(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
LocationbarProp::~LocationbarProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
LocationbarProp::GetVisible(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_LOCATIONBAR,
|
|
|
|
aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
LocationbarProp::SetVisible(bool aVisible, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_LOCATIONBAR,
|
|
|
|
aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// PersonalbarProp class implementation
|
|
|
|
//
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
PersonalbarProp::PersonalbarProp(nsGlobalWindow *aWindow)
|
|
|
|
: BarProp(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
PersonalbarProp::~PersonalbarProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
PersonalbarProp::GetVisible(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR,
|
|
|
|
aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
PersonalbarProp::SetVisible(bool aVisible, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
BarProp::SetVisibleByFlag(aVisible,
|
|
|
|
nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR,
|
|
|
|
aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// StatusbarProp class implementation
|
|
|
|
//
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
StatusbarProp::StatusbarProp(nsGlobalWindow *aWindow)
|
|
|
|
: BarProp(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
StatusbarProp::~StatusbarProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
StatusbarProp::GetVisible(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_STATUSBAR, aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
StatusbarProp::SetVisible(bool aVisible, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-05-31 03:30:00 -07:00
|
|
|
return BarProp::SetVisibleByFlag(aVisible,
|
2013-06-01 01:53:00 -07:00
|
|
|
nsIWebBrowserChrome::CHROME_STATUSBAR, aRv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ScrollbarsProp class implementation
|
|
|
|
//
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
ScrollbarsProp::ScrollbarsProp(nsGlobalWindow *aWindow)
|
|
|
|
: BarProp(aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
ScrollbarsProp::~ScrollbarsProp()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
bool
|
|
|
|
ScrollbarsProp::GetVisible(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
if (!mDOMWindow) {
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
nsCOMPtr<nsIScrollable> scroller =
|
|
|
|
do_QueryInterface(mDOMWindow->GetDocShell());
|
|
|
|
|
|
|
|
if (!scroller) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t prefValue;
|
|
|
|
scroller->GetDefaultScrollbarPreferences(
|
|
|
|
nsIScrollable::ScrollOrientation_Y, &prefValue);
|
|
|
|
if (prefValue != nsIScrollable::Scrollbar_Never) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
scroller->GetDefaultScrollbarPreferences(
|
|
|
|
nsIScrollable::ScrollOrientation_X, &prefValue);
|
|
|
|
return prefValue != nsIScrollable::Scrollbar_Never;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
void
|
|
|
|
ScrollbarsProp::SetVisible(bool aVisible, ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-01 01:53:00 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Scrollbars, unlike the other barprops, implement visibility directly
|
|
|
|
rather than handing off to the superclass (and from there to the
|
|
|
|
chrome window) because scrollbar visibility uniquely applies only
|
|
|
|
to the window making the change (arguably. it does now, anyway.)
|
|
|
|
and because embedding apps have no interface for implementing this
|
|
|
|
themselves, and therefore the implementation must be internal. */
|
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
nsCOMPtr<nsIScrollable> scroller =
|
|
|
|
do_QueryInterface(mDOMWindow->GetDocShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
if (scroller) {
|
|
|
|
int32_t prefValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-01 01:53:00 -07:00
|
|
|
if (aVisible) {
|
|
|
|
prefValue = nsIScrollable::Scrollbar_Auto;
|
|
|
|
} else {
|
|
|
|
prefValue = nsIScrollable::Scrollbar_Never;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-06-01 01:53:00 -07:00
|
|
|
|
|
|
|
scroller->SetDefaultScrollbarPreferences(
|
|
|
|
nsIScrollable::ScrollOrientation_Y, prefValue);
|
|
|
|
scroller->SetDefaultScrollbarPreferences(
|
|
|
|
nsIScrollable::ScrollOrientation_X, prefValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Notably absent is the part where we notify the chrome window using
|
2011-04-27 13:54:07 -07:00
|
|
|
GetBrowserChrome()->SetChromeFlags(). Given the possibility of multiple
|
2007-03-22 10:30:00 -07:00
|
|
|
DOM windows (multiple top-level windows, even) within a single
|
|
|
|
chrome window, the historical concept of a single "has scrollbars"
|
|
|
|
flag in the chrome is inapplicable, and we can't tell at this level
|
|
|
|
whether we represent the particular DOM window that makes this decision
|
|
|
|
for the chrome.
|
|
|
|
|
|
|
|
So only this object (and its corresponding DOM window) knows whether
|
|
|
|
scrollbars are visible. The corresponding chrome window will need to
|
|
|
|
ask (one of) its DOM window(s) when it needs to know about scrollbar
|
|
|
|
visibility, rather than caching its own copy of that information.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2013-05-31 03:30:00 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|