2001-09-25 22:43:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-28 22:24:29 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-01-28 22:24:29 +00:00
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-01-28 22:24:29 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:43:09 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2000-02-08 13:40:10 +00:00
|
|
|
* Contributor(s):
|
2004-04-17 21:52:36 +00:00
|
|
|
* Travis Bogard <travis@netscape.com>
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:43:09 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:43:09 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-28 22:24:29 +00:00
|
|
|
|
2011-12-04 17:07:00 +00:00
|
|
|
#include "mozilla/Hal.h"
|
1999-01-28 22:24:29 +00:00
|
|
|
#include "nsScreen.h"
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsIDocShell.h"
|
2006-04-08 01:46:06 +00:00
|
|
|
#include "nsPresContext.h"
|
1999-06-11 21:19:24 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2011-10-03 19:11:31 +00:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2011-12-04 17:07:00 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2008-07-26 16:14:49 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-14 10:10:48 +00:00
|
|
|
#include "nsDOMEvent.h"
|
2011-12-04 17:07:00 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-03-14 10:10:48 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-12-04 17:07:00 +00:00
|
|
|
|
2012-03-14 18:14:53 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsChromeType(nsIDocShell *aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> ds = do_QueryInterface(aDocShell);
|
|
|
|
if (!ds) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 itemType;
|
|
|
|
ds->GetItemType(&itemType);
|
|
|
|
return itemType == nsIDocShellTreeItem::typeChrome;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2012-03-14 10:10:48 +00:00
|
|
|
/* static */ already_AddRefed<nsScreen>
|
|
|
|
nsScreen::Create(nsPIDOMWindow* aWindow)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2012-03-29 16:31:29 +00:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
2012-03-14 10:10:48 +00:00
|
|
|
if (!aWindow->GetDocShell()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2012-03-29 16:31:29 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo =
|
|
|
|
do_QueryInterface(static_cast<nsPIDOMWindow*>(aWindow));
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_ENSURE_TRUE(sgo, nsnull);
|
|
|
|
|
|
|
|
nsRefPtr<nsScreen> screen = new nsScreen();
|
|
|
|
screen->BindToOwner(aWindow);
|
|
|
|
|
|
|
|
hal::RegisterScreenOrientationObserver(screen);
|
|
|
|
hal::GetCurrentScreenOrientation(&(screen->mOrientation));
|
|
|
|
|
|
|
|
return screen.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreen::nsScreen()
|
2012-03-29 16:31:11 +00:00
|
|
|
: mEventListener(nsnull)
|
2012-03-14 10:10:48 +00:00
|
|
|
{
|
2012-02-09 10:29:09 +00:00
|
|
|
}
|
1999-01-28 22:24:29 +00:00
|
|
|
|
2012-02-09 15:55:54 +00:00
|
|
|
nsScreen::~nsScreen()
|
|
|
|
{
|
2012-03-15 09:58:56 +00:00
|
|
|
hal::UnregisterScreenOrientationObserver(this);
|
2012-02-09 15:55:54 +00:00
|
|
|
}
|
2012-02-09 10:29:09 +00:00
|
|
|
|
2012-02-09 15:55:54 +00:00
|
|
|
|
2012-02-09 16:42:07 +00:00
|
|
|
DOMCI_DATA(Screen, nsScreen)
|
2012-02-09 15:55:54 +00:00
|
|
|
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsScreen)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsScreen,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(mozorientationchange)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsScreen,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(mozorientationchange)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2004-12-10 19:48:22 +00:00
|
|
|
// QueryInterface implementation for nsScreen
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsScreen)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMScreen)
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScreen)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Screen)
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
2012-03-14 18:14:53 +00:00
|
|
|
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsScreen, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsScreen, nsDOMEventTargetHelper)
|
2012-03-14 18:14:53 +00:00
|
|
|
|
2012-03-14 10:10:48 +00:00
|
|
|
NS_IMPL_EVENT_HANDLER(nsScreen, mozorientationchange)
|
2012-03-14 18:14:53 +00:00
|
|
|
|
2000-04-20 02:00:55 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetTop(PRInt32* aTop)
|
2000-04-20 02:00:55 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetRect(rect);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aTop = rect.y;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
2000-04-20 02:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetLeft(PRInt32* aLeft)
|
2000-04-20 02:00:55 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetRect(rect);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aLeft = rect.x;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
2000-04-20 02:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-28 22:24:29 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetWidth(PRInt32* aWidth)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetRect(rect);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aWidth = rect.width;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetHeight(PRInt32* aHeight)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetRect(rect);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aHeight = rect.height;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetPixelDepth(PRInt32* aPixelDepth)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2011-04-17 01:22:44 +00:00
|
|
|
nsDeviceContext* context = GetDeviceContext();
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
if (!context) {
|
|
|
|
*aPixelDepth = -1;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-05-28 22:55:39 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
PRUint32 depth;
|
|
|
|
context->GetDepth(depth);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aPixelDepth = depth;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetColorDepth(PRInt32* aColorDepth)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
return GetPixelDepth(aColorDepth);
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetAvailWidth(PRInt32* aAvailWidth)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetAvailRect(rect);
|
1999-09-05 02:51:25 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aAvailWidth = rect.width;
|
1999-06-11 21:19:24 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetAvailHeight(PRInt32* aAvailHeight)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetAvailRect(rect);
|
1999-09-05 02:51:25 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aAvailHeight = rect.height;
|
1999-06-11 21:19:24 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetAvailLeft(PRInt32* aAvailLeft)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetAvailRect(rect);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aAvailLeft = rect.x;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetAvailTop(PRInt32* aAvailTop)
|
1999-01-28 22:24:29 +00:00
|
|
|
{
|
2003-09-19 21:06:52 +00:00
|
|
|
nsRect rect;
|
|
|
|
nsresult rv = GetAvailRect(rect);
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
*aAvailTop = rect.y;
|
2002-05-28 22:55:39 +00:00
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
return rv;
|
1999-01-28 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
2011-04-17 01:22:44 +00:00
|
|
|
nsDeviceContext*
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetDeviceContext()
|
1999-06-11 21:19:24 +00:00
|
|
|
{
|
2012-03-14 18:14:53 +00:00
|
|
|
return nsLayoutUtils::GetDeviceContextForScreenInfo(GetOwner());
|
1999-06-11 21:19:24 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 21:06:52 +00:00
|
|
|
nsresult
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetRect(nsRect& aRect)
|
2003-09-19 21:06:52 +00:00
|
|
|
{
|
2011-04-17 01:22:44 +00:00
|
|
|
nsDeviceContext *context = GetDeviceContext();
|
2003-09-19 21:06:52 +00:00
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->GetRect(aRect);
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x);
|
|
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y);
|
|
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width);
|
2003-09-19 21:06:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-12-10 19:48:22 +00:00
|
|
|
nsScreen::GetAvailRect(nsRect& aRect)
|
2003-09-19 21:06:52 +00:00
|
|
|
{
|
2011-04-17 01:22:44 +00:00
|
|
|
nsDeviceContext *context = GetDeviceContext();
|
2003-09-19 21:06:52 +00:00
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-01-28 22:24:29 +00:00
|
|
|
|
2003-09-20 11:41:22 +00:00
|
|
|
context->GetClientRect(aRect);
|
2003-09-19 21:06:52 +00:00
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x);
|
|
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y);
|
|
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width);
|
2003-09-19 21:06:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-12-04 17:07:00 +00:00
|
|
|
|
2012-03-14 10:10:48 +00:00
|
|
|
void
|
|
|
|
nsScreen::Notify(const ScreenOrientationWrapper& aOrientation)
|
|
|
|
{
|
|
|
|
ScreenOrientation previousOrientation = mOrientation;
|
|
|
|
mOrientation = aOrientation.orientation;
|
|
|
|
|
2012-03-29 19:43:16 +00:00
|
|
|
NS_ASSERTION(mOrientation != eScreenOrientation_None &&
|
2012-03-14 10:10:48 +00:00
|
|
|
mOrientation != eScreenOrientation_EndGuard &&
|
|
|
|
mOrientation != eScreenOrientation_Portrait &&
|
|
|
|
mOrientation != eScreenOrientation_Landscape,
|
|
|
|
"Invalid orientation value passed to notify method!");
|
|
|
|
|
|
|
|
if (mOrientation != previousOrientation) {
|
|
|
|
// TODO: use an helper method, see bug 720768.
|
|
|
|
nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nsnull, nsnull);
|
|
|
|
nsresult rv = event->InitEvent(NS_LITERAL_STRING("mozorientationchange"), false, false);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = event->SetTrusted(true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dummy;
|
|
|
|
rv = DispatchEvent(event, &dummy);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreen::GetMozOrientation(nsAString& aOrientation)
|
|
|
|
{
|
|
|
|
switch (mOrientation) {
|
2012-03-29 19:43:16 +00:00
|
|
|
case eScreenOrientation_None:
|
2012-03-14 10:10:48 +00:00
|
|
|
case eScreenOrientation_EndGuard:
|
|
|
|
case eScreenOrientation_Portrait:
|
|
|
|
case eScreenOrientation_Landscape:
|
|
|
|
NS_ASSERTION(false, "Shouldn't be used when getting value!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-29 19:43:16 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreen::MozLockOrientation(const nsAString& aOrientation, bool* aReturn)
|
|
|
|
{
|
|
|
|
ScreenOrientation orientation;
|
|
|
|
|
|
|
|
if (aOrientation.EqualsLiteral("portrait")) {
|
|
|
|
orientation = eScreenOrientation_Portrait;
|
|
|
|
} else if (aOrientation.EqualsLiteral("portrait-primary")) {
|
|
|
|
orientation = eScreenOrientation_PortraitPrimary;
|
|
|
|
} else if (aOrientation.EqualsLiteral("portrait-secondary")) {
|
|
|
|
orientation = eScreenOrientation_PortraitSecondary;
|
|
|
|
} else if (aOrientation.EqualsLiteral("landscape")) {
|
|
|
|
orientation = eScreenOrientation_Landscape;
|
|
|
|
} else if (aOrientation.EqualsLiteral("landscape-primary")) {
|
|
|
|
orientation = eScreenOrientation_LandscapePrimary;
|
|
|
|
} else if (aOrientation.EqualsLiteral("landscape-secondary")) {
|
|
|
|
orientation = eScreenOrientation_LandscapeSecondary;
|
|
|
|
} else {
|
|
|
|
*aReturn = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-29 16:31:29 +00:00
|
|
|
if (!GetOwner()) {
|
|
|
|
*aReturn = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsChromeType(GetOwner()->GetDocShell())) {
|
2012-04-10 13:38:59 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
GetOwner()->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (!doc) {
|
|
|
|
*aReturn = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-29 16:31:29 +00:00
|
|
|
bool fullscreen;
|
2012-04-10 13:38:59 +00:00
|
|
|
doc->GetMozFullScreen(&fullscreen);
|
2012-03-29 16:31:29 +00:00
|
|
|
if (!fullscreen) {
|
|
|
|
*aReturn = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-29 16:31:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
|
|
|
|
if (!target) {
|
|
|
|
*aReturn = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mEventListener) {
|
|
|
|
mEventListener = new FullScreenEventListener();
|
|
|
|
}
|
|
|
|
|
|
|
|
target->AddSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
|
|
mEventListener, true);
|
2012-03-29 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 19:43:16 +00:00
|
|
|
*aReturn = hal::LockScreenOrientation(orientation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreen::MozUnlockOrientation()
|
|
|
|
{
|
|
|
|
hal::UnlockScreenOrientation();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-29 16:31:11 +00: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 08:30:58 +00: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 16:31:11 +00:00
|
|
|
target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
|
|
this, true);
|
|
|
|
|
|
|
|
hal::UnlockScreenOrientation();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|