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
|
|
|
|
2011-12-04 09:07:00 -08:00
|
|
|
#include "mozilla/Hal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsScreen.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2011-12-04 09:07:00 -08:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2008-07-26 09:14:49 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-14 03:10:48 -07:00
|
|
|
#include "nsDOMEvent.h"
|
2012-05-10 17:49:34 -07:00
|
|
|
#include "nsGlobalWindow.h"
|
2012-09-11 03:55:08 -07:00
|
|
|
#include "nsJSUtils.h"
|
2012-10-14 00:40:11 -07:00
|
|
|
#include "mozilla/dom/ScreenBinding.h"
|
2011-12-04 09:07:00 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-03-14 03:10:48 -07:00
|
|
|
using namespace mozilla::dom;
|
2011-12-04 09:07:00 -08:00
|
|
|
|
2012-03-14 11:14:53 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsChromeType(nsIDocShell *aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> ds = do_QueryInterface(aDocShell);
|
|
|
|
if (!ds) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t itemType;
|
2012-03-14 11:14:53 -07:00
|
|
|
ds->GetItemType(&itemType);
|
|
|
|
return itemType == nsIDocShellTreeItem::typeChrome;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2012-03-14 03:10:48 -07:00
|
|
|
/* static */ already_AddRefed<nsScreen>
|
|
|
|
nsScreen::Create(nsPIDOMWindow* aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-29 09:31:29 -07:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
2012-03-14 03:10:48 -07:00
|
|
|
if (!aWindow->GetDocShell()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-14 03:10:48 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 09:31:29 -07:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo =
|
|
|
|
do_QueryInterface(static_cast<nsPIDOMWindow*>(aWindow));
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(sgo, nullptr);
|
2012-03-14 03:10:48 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsScreen> screen = new nsScreen();
|
|
|
|
screen->BindToOwner(aWindow);
|
|
|
|
|
2012-05-08 14:36:07 -07:00
|
|
|
hal::RegisterScreenConfigurationObserver(screen);
|
|
|
|
hal::ScreenConfiguration config;
|
|
|
|
hal::GetCurrentScreenConfiguration(&config);
|
|
|
|
screen->mOrientation = config.orientation();
|
2012-03-14 03:10:48 -07:00
|
|
|
|
|
|
|
return screen.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreen::nsScreen()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mEventListener(nullptr)
|
2012-03-14 03:10:48 -07:00
|
|
|
{
|
2012-02-09 02:29:09 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-22 01:52:47 -07:00
|
|
|
void
|
|
|
|
nsScreen::Reset()
|
|
|
|
{
|
|
|
|
hal::UnlockScreenOrientation();
|
2012-06-22 01:53:23 -07:00
|
|
|
|
|
|
|
if (mEventListener) {
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
|
|
|
|
if (target) {
|
|
|
|
target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
2012-09-11 06:15:43 -07:00
|
|
|
mEventListener, /* usecapture */ true);
|
2012-06-22 01:53:23 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mEventListener = nullptr;
|
2012-06-22 01:53:23 -07:00
|
|
|
}
|
2012-06-22 01:52:47 -07:00
|
|
|
}
|
|
|
|
|
2012-02-09 07:55:54 -08:00
|
|
|
nsScreen::~nsScreen()
|
|
|
|
{
|
2012-06-22 01:52:47 -07:00
|
|
|
Reset();
|
2012-05-08 14:36:07 -07:00
|
|
|
hal::UnregisterScreenConfigurationObserver(this);
|
2012-02-09 07:55:54 -08:00
|
|
|
}
|
2012-02-09 02:29:09 -08:00
|
|
|
|
2012-02-09 07:55:54 -08:00
|
|
|
|
2012-02-09 08:42:07 -08:00
|
|
|
DOMCI_DATA(Screen, nsScreen)
|
2012-02-09 07:55:54 -08:00
|
|
|
|
2012-03-14 03:10:48 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsScreen)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsScreen,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsScreen,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsScreen
|
2012-03-14 03:10:48 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsScreen)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMScreen)
|
2012-03-14 03:10:48 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScreen)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Screen)
|
2012-03-14 03:10:48 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
2012-03-14 11:14:53 -07:00
|
|
|
|
2012-03-14 03:10:48 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsScreen, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsScreen, nsDOMEventTargetHelper)
|
2012-03-14 11:14:53 -07:00
|
|
|
|
2012-03-14 03:10:48 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(nsScreen, mozorientationchange)
|
2012-03-14 11:14:53 -07:00
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
int32_t
|
|
|
|
nsScreen::GetPixelDepth(ErrorResult& aRv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext* context = GetDeviceContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!context) {
|
2012-10-14 00:40:11 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t depth;
|
2007-03-22 10:30:00 -07:00
|
|
|
context->GetDepth(depth);
|
2012-10-14 00:40:11 -07:00
|
|
|
return depth;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
#define FORWARD_LONG_GETTER(_name) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsScreen::Get ## _name(int32_t* aOut) \
|
|
|
|
{ \
|
|
|
|
ErrorResult rv; \
|
|
|
|
*aOut = Get ## _name(rv); \
|
|
|
|
return rv.ErrorCode(); \
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
FORWARD_LONG_GETTER(AvailWidth)
|
|
|
|
FORWARD_LONG_GETTER(AvailHeight)
|
|
|
|
FORWARD_LONG_GETTER(Width)
|
|
|
|
FORWARD_LONG_GETTER(Height)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
FORWARD_LONG_GETTER(Top)
|
|
|
|
FORWARD_LONG_GETTER(Left)
|
|
|
|
FORWARD_LONG_GETTER(AvailTop)
|
|
|
|
FORWARD_LONG_GETTER(AvailLeft)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
FORWARD_LONG_GETTER(PixelDepth)
|
|
|
|
FORWARD_LONG_GETTER(ColorDepth)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsScreen::GetDeviceContext()
|
|
|
|
{
|
2012-03-14 11:14:53 -07:00
|
|
|
return nsLayoutUtils::GetDeviceContextForScreenInfo(GetOwner());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScreen::GetRect(nsRect& aRect)
|
|
|
|
{
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *context = GetDeviceContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->GetRect(aRect);
|
|
|
|
|
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x);
|
|
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y);
|
|
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScreen::GetAvailRect(nsRect& aRect)
|
|
|
|
{
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *context = GetDeviceContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->GetClientRect(aRect);
|
|
|
|
|
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x);
|
|
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y);
|
|
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-12-04 09:07:00 -08:00
|
|
|
|
2012-03-14 03:10:48 -07:00
|
|
|
void
|
2012-05-08 14:36:07 -07:00
|
|
|
nsScreen::Notify(const hal::ScreenConfiguration& aConfiguration)
|
2012-03-14 03:10:48 -07:00
|
|
|
{
|
|
|
|
ScreenOrientation previousOrientation = mOrientation;
|
2012-05-08 14:36:07 -07:00
|
|
|
mOrientation = aConfiguration.orientation();
|
2012-03-14 03:10:48 -07:00
|
|
|
|
2012-09-19 09:28:16 -07:00
|
|
|
NS_ASSERTION(mOrientation == eScreenOrientation_PortraitPrimary ||
|
|
|
|
mOrientation == eScreenOrientation_PortraitSecondary ||
|
|
|
|
mOrientation == eScreenOrientation_LandscapePrimary ||
|
|
|
|
mOrientation == eScreenOrientation_LandscapeSecondary,
|
2012-03-14 03:10:48 -07:00
|
|
|
"Invalid orientation value passed to notify method!");
|
|
|
|
|
|
|
|
if (mOrientation != previousOrientation) {
|
2012-09-27 13:11:31 -07:00
|
|
|
DispatchTrustedEvent(NS_LITERAL_STRING("mozorientationchange"));
|
2012-03-14 03:10:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
void
|
|
|
|
nsScreen::GetMozOrientation(nsString& aOrientation)
|
2012-03-14 03:10:48 -07:00
|
|
|
{
|
|
|
|
switch (mOrientation) {
|
2012-10-14 00:40:11 -07:00
|
|
|
case eScreenOrientation_PortraitPrimary:
|
|
|
|
aOrientation.AssignLiteral("portrait-primary");
|
|
|
|
break;
|
|
|
|
case eScreenOrientation_PortraitSecondary:
|
|
|
|
aOrientation.AssignLiteral("portrait-secondary");
|
|
|
|
break;
|
|
|
|
case eScreenOrientation_LandscapePrimary:
|
|
|
|
aOrientation.AssignLiteral("landscape-primary");
|
|
|
|
break;
|
|
|
|
case eScreenOrientation_LandscapeSecondary:
|
|
|
|
aOrientation.AssignLiteral("landscape-secondary");
|
|
|
|
break;
|
|
|
|
case eScreenOrientation_None:
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Unacceptable mOrientation value");
|
2012-03-14 03:10:48 -07:00
|
|
|
}
|
2012-10-14 00:40:11 -07:00
|
|
|
}
|
2012-03-14 03:10:48 -07:00
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreen::GetSlowMozOrientation(nsAString& aOrientation)
|
|
|
|
{
|
|
|
|
nsString orientation;
|
|
|
|
GetMozOrientation(orientation);
|
|
|
|
aOrientation = orientation;
|
2012-03-14 03:10:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-29 12:43:16 -07:00
|
|
|
|
2012-09-11 06:15:43 -07:00
|
|
|
nsScreen::LockPermission
|
|
|
|
nsScreen::GetLockOrientationPermission() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
|
|
|
|
if (!owner) {
|
|
|
|
return LOCK_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chrome can always lock the screen orientation.
|
|
|
|
if (IsChromeType(owner->GetDocShell())) {
|
|
|
|
return LOCK_ALLOWED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
owner->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (!doc) {
|
|
|
|
return LOCK_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apps can always lock the screen orientation.
|
|
|
|
if (doc->NodePrincipal()->GetAppStatus() >=
|
|
|
|
nsIPrincipal::APP_STATUS_INSTALLED) {
|
|
|
|
return LOCK_ALLOWED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other content must be full-screen in order to lock orientation.
|
|
|
|
bool fullscreen;
|
|
|
|
domDoc->GetMozFullScreen(&fullscreen);
|
|
|
|
|
|
|
|
return fullscreen ? FULLSCREEN_LOCK_ALLOWED : LOCK_DENIED;
|
|
|
|
}
|
|
|
|
|
2012-03-29 12:43:16 -07:00
|
|
|
NS_IMETHODIMP
|
2012-10-14 00:39:34 -07:00
|
|
|
nsScreen::MozLockOrientation(const JS::Value& aOrientation, JSContext* aCx,
|
|
|
|
bool* aReturn)
|
2012-03-29 12:43:16 -07:00
|
|
|
{
|
2012-10-14 00:39:34 -07:00
|
|
|
if (aOrientation.isObject() && IsArrayLike(aCx, &aOrientation.toObject())) {
|
|
|
|
JSObject* seq = &aOrientation.toObject();
|
2012-09-11 03:55:08 -07:00
|
|
|
uint32_t length;
|
2012-10-14 00:39:34 -07:00
|
|
|
// JS_GetArrayLength actually works on all objects
|
|
|
|
if (!JS_GetArrayLength(aCx, seq, &length)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-11 03:55:08 -07:00
|
|
|
}
|
|
|
|
|
2012-10-14 00:39:34 -07:00
|
|
|
Sequence<nsString> orientations;
|
|
|
|
if (!orientations.SetCapacity(length)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2012-09-11 03:55:08 -07:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2012-10-14 00:39:34 -07:00
|
|
|
JS::Value temp;
|
|
|
|
if (!JS_GetElement(aCx, seq, i, &temp)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
js::RootedString jsString(aCx, JS_ValueToString(aCx, temp));
|
|
|
|
if (!jsString) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentJSString str;
|
|
|
|
if (!str.init(aCx, jsString)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-11 03:55:08 -07:00
|
|
|
}
|
|
|
|
|
2012-10-14 00:39:34 -07:00
|
|
|
*orientations.AppendElement() = str;
|
2012-09-11 03:55:08 -07:00
|
|
|
}
|
2012-10-14 00:39:34 -07:00
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn = MozLockOrientation(orientations, rv);
|
|
|
|
return rv.ErrorCode();
|
2012-09-11 03:55:08 -07:00
|
|
|
}
|
|
|
|
|
2012-10-14 00:39:34 -07:00
|
|
|
js::RootedString jsString(aCx, JS_ValueToString(aCx, aOrientation));
|
|
|
|
if (!jsString) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentJSString orientation;
|
|
|
|
if (!orientation.init(aCx, jsString)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn = MozLockOrientation(orientation, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreen::MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsString orientation(aOrientation);
|
|
|
|
Sequence<nsString> orientations;
|
|
|
|
if (!orientations.AppendElement(orientation)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return MozLockOrientation(orientations, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreen::MozLockOrientation(const Sequence<nsString>& aOrientations,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2012-09-11 03:55:08 -07:00
|
|
|
ScreenOrientation orientation = eScreenOrientation_None;
|
|
|
|
|
2012-10-14 00:39:34 -07:00
|
|
|
for (uint32_t i = 0; i < aOrientations.Length(); ++i) {
|
|
|
|
const nsString& item = aOrientations[i];
|
2012-09-11 03:55:08 -07:00
|
|
|
|
|
|
|
if (item.EqualsLiteral("portrait")) {
|
2012-09-19 09:28:16 -07:00
|
|
|
orientation |= eScreenOrientation_PortraitPrimary |
|
|
|
|
eScreenOrientation_PortraitSecondary;
|
2012-09-11 03:55:08 -07:00
|
|
|
} else if (item.EqualsLiteral("portrait-primary")) {
|
|
|
|
orientation |= eScreenOrientation_PortraitPrimary;
|
|
|
|
} else if (item.EqualsLiteral("portrait-secondary")) {
|
|
|
|
orientation |= eScreenOrientation_PortraitSecondary;
|
|
|
|
} else if (item.EqualsLiteral("landscape")) {
|
2012-09-19 09:28:16 -07:00
|
|
|
orientation |= eScreenOrientation_LandscapePrimary |
|
|
|
|
eScreenOrientation_LandscapeSecondary;
|
2012-09-11 03:55:08 -07:00
|
|
|
} else if (item.EqualsLiteral("landscape-primary")) {
|
|
|
|
orientation |= eScreenOrientation_LandscapePrimary;
|
|
|
|
} else if (item.EqualsLiteral("landscape-secondary")) {
|
|
|
|
orientation |= eScreenOrientation_LandscapeSecondary;
|
|
|
|
} else {
|
2012-10-14 00:39:34 -07:00
|
|
|
// If we don't recognize the token, we should just return 'false'
|
2012-09-11 03:55:08 -07:00
|
|
|
// without throwing.
|
2012-10-14 00:39:34 -07:00
|
|
|
return false;
|
2012-09-11 03:55:08 -07:00
|
|
|
}
|
2012-03-29 12:43:16 -07:00
|
|
|
}
|
|
|
|
|
2012-09-11 06:15:43 -07:00
|
|
|
switch (GetLockOrientationPermission()) {
|
|
|
|
case LOCK_DENIED:
|
2012-10-14 00:39:34 -07:00
|
|
|
return false;
|
2012-09-11 06:15:43 -07:00
|
|
|
case LOCK_ALLOWED:
|
2012-10-14 00:39:34 -07:00
|
|
|
return hal::LockScreenOrientation(orientation);
|
|
|
|
case FULLSCREEN_LOCK_ALLOWED: {
|
|
|
|
if (!hal::LockScreenOrientation(orientation)) {
|
|
|
|
return false;
|
2012-09-11 06:15:43 -07:00
|
|
|
}
|
2012-03-29 09:31:11 -07:00
|
|
|
|
2012-09-11 06:15:43 -07:00
|
|
|
// We are fullscreen and lock has been accepted.
|
|
|
|
// Now, we need to register a listener so we learn when we leave
|
|
|
|
// full-screen and when we will have to unlock the screen.
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
|
|
|
|
if (!target) {
|
2012-10-14 00:39:34 -07:00
|
|
|
// XXX: Bug 796873
|
|
|
|
return true;
|
2012-09-11 06:15:43 -07:00
|
|
|
}
|
2012-03-29 09:31:11 -07:00
|
|
|
|
2012-09-11 06:15:43 -07:00
|
|
|
if (!mEventListener) {
|
|
|
|
mEventListener = new FullScreenEventListener();
|
|
|
|
}
|
2012-08-13 09:58:38 -07:00
|
|
|
|
2012-10-14 00:39:34 -07:00
|
|
|
aRv = target->AddSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
|
|
mEventListener, /* useCapture = */ true);
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-29 09:31:29 -07:00
|
|
|
}
|
|
|
|
|
2012-09-11 06:15:43 -07:00
|
|
|
// This is only for compilers that don't understand that the previous switch
|
|
|
|
// will always return.
|
|
|
|
MOZ_NOT_REACHED();
|
2012-10-14 00:39:34 -07:00
|
|
|
return false;
|
2012-03-29 12:43:16 -07:00
|
|
|
}
|
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
void
|
2012-03-29 12:43:16 -07:00
|
|
|
nsScreen::MozUnlockOrientation()
|
|
|
|
{
|
|
|
|
hal::UnlockScreenOrientation();
|
2012-10-14 00:40:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreen::SlowMozUnlockOrientation()
|
|
|
|
{
|
|
|
|
MozUnlockOrientation();
|
2012-03-29 12:43:16 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-29 09:31:11 -07:00
|
|
|
|
2012-10-14 00:40:11 -07:00
|
|
|
/* virtual */
|
|
|
|
JSObject*
|
|
|
|
nsScreen::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
|
|
|
|
{
|
|
|
|
return ScreenBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
|
|
|
}
|
|
|
|
|
2012-03-29 09:31:11 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsScreen::FullScreenEventListener, nsIDOMEventListener)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreen::FullScreenEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
|
|
|
|
MOZ_ASSERT(eventType.EqualsLiteral("mozfullscreenchange"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
aEvent->GetCurrentTarget(getter_AddRefs(target));
|
|
|
|
|
2012-04-23 01:30:58 -07:00
|
|
|
// We have to make sure that the event we got is the event sent when
|
|
|
|
// fullscreen is disabled because we could get one when fullscreen
|
|
|
|
// got enabled if the lock call is done at the same moment.
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(target);
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
window->GetDocument(getter_AddRefs(doc));
|
|
|
|
// If we have no doc, we will just continue, remove the event and unlock.
|
|
|
|
// This is an edge case were orientation lock and fullscreen is meaningless.
|
|
|
|
if (doc) {
|
|
|
|
bool fullscreen;
|
|
|
|
doc->GetMozFullScreen(&fullscreen);
|
|
|
|
if (fullscreen) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 09:31:11 -07:00
|
|
|
target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
|
|
this, true);
|
|
|
|
|
|
|
|
hal::UnlockScreenOrientation();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|