Bug 793244 - Part b: Convert Screen to WebIDL; r=bz

This commit is contained in:
Ms2ger 2012-10-14 09:40:11 +02:00
parent 770a639202
commit 0ad78542ff
7 changed files with 213 additions and 123 deletions

View File

@ -14,6 +14,7 @@
#include "nsDOMEvent.h"
#include "nsGlobalWindow.h"
#include "nsJSUtils.h"
#include "mozilla/dom/ScreenBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -111,120 +112,42 @@ NS_IMPL_RELEASE_INHERITED(nsScreen, nsDOMEventTargetHelper)
NS_IMPL_EVENT_HANDLER(nsScreen, mozorientationchange)
NS_IMETHODIMP
nsScreen::GetTop(int32_t* aTop)
{
nsRect rect;
nsresult rv = GetRect(rect);
*aTop = rect.y;
return rv;
}
NS_IMETHODIMP
nsScreen::GetLeft(int32_t* aLeft)
{
nsRect rect;
nsresult rv = GetRect(rect);
*aLeft = rect.x;
return rv;
}
NS_IMETHODIMP
nsScreen::GetWidth(int32_t* aWidth)
{
nsRect rect;
nsresult rv = GetRect(rect);
*aWidth = rect.width;
return rv;
}
NS_IMETHODIMP
nsScreen::GetHeight(int32_t* aHeight)
{
nsRect rect;
nsresult rv = GetRect(rect);
*aHeight = rect.height;
return rv;
}
NS_IMETHODIMP
nsScreen::GetPixelDepth(int32_t* aPixelDepth)
int32_t
nsScreen::GetPixelDepth(ErrorResult& aRv)
{
nsDeviceContext* context = GetDeviceContext();
if (!context) {
*aPixelDepth = -1;
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return -1;
}
uint32_t depth;
context->GetDepth(depth);
*aPixelDepth = depth;
return NS_OK;
return depth;
}
NS_IMETHODIMP
nsScreen::GetColorDepth(int32_t* aColorDepth)
{
return GetPixelDepth(aColorDepth);
}
#define FORWARD_LONG_GETTER(_name) \
NS_IMETHODIMP \
nsScreen::Get ## _name(int32_t* aOut) \
{ \
ErrorResult rv; \
*aOut = Get ## _name(rv); \
return rv.ErrorCode(); \
}
NS_IMETHODIMP
nsScreen::GetAvailWidth(int32_t* aAvailWidth)
{
nsRect rect;
nsresult rv = GetAvailRect(rect);
FORWARD_LONG_GETTER(AvailWidth)
FORWARD_LONG_GETTER(AvailHeight)
FORWARD_LONG_GETTER(Width)
FORWARD_LONG_GETTER(Height)
*aAvailWidth = rect.width;
FORWARD_LONG_GETTER(Top)
FORWARD_LONG_GETTER(Left)
FORWARD_LONG_GETTER(AvailTop)
FORWARD_LONG_GETTER(AvailLeft)
return rv;
}
NS_IMETHODIMP
nsScreen::GetAvailHeight(int32_t* aAvailHeight)
{
nsRect rect;
nsresult rv = GetAvailRect(rect);
*aAvailHeight = rect.height;
return rv;
}
NS_IMETHODIMP
nsScreen::GetAvailLeft(int32_t* aAvailLeft)
{
nsRect rect;
nsresult rv = GetAvailRect(rect);
*aAvailLeft = rect.x;
return rv;
}
NS_IMETHODIMP
nsScreen::GetAvailTop(int32_t* aAvailTop)
{
nsRect rect;
nsresult rv = GetAvailRect(rect);
*aAvailTop = rect.y;
return rv;
}
FORWARD_LONG_GETTER(PixelDepth)
FORWARD_LONG_GETTER(ColorDepth)
nsDeviceContext*
nsScreen::GetDeviceContext()
@ -287,28 +210,34 @@ nsScreen::Notify(const hal::ScreenConfiguration& aConfiguration)
}
}
NS_IMETHODIMP
nsScreen::GetMozOrientation(nsAString& aOrientation)
void
nsScreen::GetMozOrientation(nsString& aOrientation)
{
switch (mOrientation) {
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_ASSERT(false);
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;
case eScreenOrientation_None:
default:
MOZ_NOT_REACHED("Unacceptable mOrientation value");
}
}
NS_IMETHODIMP
nsScreen::GetSlowMozOrientation(nsAString& aOrientation)
{
nsString orientation;
GetMozOrientation(orientation);
aOrientation = orientation;
return NS_OK;
}
@ -478,13 +407,26 @@ nsScreen::MozLockOrientation(const Sequence<nsString>& aOrientations,
return false;
}
NS_IMETHODIMP
void
nsScreen::MozUnlockOrientation()
{
hal::UnlockScreenOrientation();
}
NS_IMETHODIMP
nsScreen::SlowMozUnlockOrientation()
{
MozUnlockOrientation();
return NS_OK;
}
/* virtual */
JSObject*
nsScreen::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
return ScreenBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
NS_IMPL_ISUPPORTS1(nsScreen::FullScreenEventListener, nsIDOMEventListener)
NS_IMETHODIMP

View File

@ -15,10 +15,10 @@
#include "nsIScriptContext.h"
#include "nsCOMPtr.h"
#include "nsDOMEventTargetHelper.h"
#include "nsRect.h"
class nsIDocShell;
class nsDeviceContext;
struct nsRect;
// Script "screen" object
class nsScreen : public nsDOMEventTargetHelper
@ -31,16 +31,101 @@ public:
void Reset();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMSCREEN
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
nsPIDOMWindow* GetParentObject() const
{
return GetOwner();
}
int32_t GetTop(ErrorResult& aRv)
{
nsRect rect;
aRv = GetRect(rect);
return rect.y;
}
int32_t GetLeft(ErrorResult& aRv)
{
nsRect rect;
aRv = GetRect(rect);
return rect.x;
}
int32_t GetWidth(ErrorResult& aRv)
{
nsRect rect;
aRv = GetRect(rect);
return rect.width;
}
int32_t GetHeight(ErrorResult& aRv)
{
nsRect rect;
aRv = GetRect(rect);
return rect.height;
}
int32_t GetPixelDepth(ErrorResult& aRv);
int32_t GetColorDepth(ErrorResult& aRv)
{
return GetPixelDepth(aRv);
}
int32_t GetAvailTop(ErrorResult& aRv)
{
nsRect rect;
aRv = GetAvailRect(rect);
return rect.y;
}
int32_t GetAvailLeft(ErrorResult& aRv)
{
nsRect rect;
aRv = GetAvailRect(rect);
return rect.x;
}
int32_t GetAvailWidth(ErrorResult& aRv)
{
nsRect rect;
aRv = GetAvailRect(rect);
return rect.width;
}
int32_t GetAvailHeight(ErrorResult& aRv)
{
nsRect rect;
aRv = GetAvailRect(rect);
return rect.height;
}
void GetMozOrientation(nsString& aOrientation);
JSObject* GetOnmozorientationchange(JSContext* aCx)
{
JS::Value val;
nsresult rv = GetOnmozorientationchange(aCx, &val);
return NS_SUCCEEDED(rv) ? val.toObjectOrNull() : nullptr;
}
void SetOnmozorientationchange(JSContext* aCx, JSObject* aCallback,
ErrorResult& aRv)
{
aRv = SetOnmozorientationchange(aCx, JS::ObjectOrNullValue(aCallback));
}
bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv);
bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations, ErrorResult& aRv);
void MozUnlockOrientation();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen,
nsDOMEventTargetHelper)
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap);
void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration);
protected:

View File

@ -292,6 +292,11 @@ DOMInterfaces = {
'resultNotAddRefed': [ 'item' ]
}],
'Screen': {
'nativeType': 'nsScreen',
'prefable': True,
},
'SVGLengthList': [
{
'nativeType': 'mozilla::DOMSVGLengthList',

View File

@ -14,6 +14,7 @@ FORCE_STATIC_LIB = 1
EXPORT_LIBRARY = 1
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
# Need this to find all our DOM source files.
include $(topsrcdir)/dom/dom-config.mk
@ -72,7 +73,9 @@ EXPORTS_$(binding_include_path) = \
LOCAL_INCLUDES += -I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/js/xpconnect/wrappers \
-I$(topsrcdir)/content/canvas/src \
-I$(topsrcdir)/content/html/content/src
-I$(topsrcdir)/content/html/content/src \
-I$(topsrcdir)/dom/base \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -24,6 +24,7 @@ interface nsIDOMScreen : nsIDOMEventTarget
* Can be: landscape-primary, landscape-secondary,
* portrait-primary or portrait-secondary.
*/
[binaryname(SlowMozOrientation)]
readonly attribute DOMString mozOrientation;
[implicit_jscontext] attribute jsval onmozorientationchange;
@ -57,5 +58,6 @@ interface nsIDOMScreen : nsIDOMEventTarget
/**
* Unlock the screen orientation.
*/
[binaryname(SlowMozUnlockOrientation)]
void mozUnlockOrientation();
};

52
dom/webidl/Screen.webidl Normal file
View File

@ -0,0 +1,52 @@
/* 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/. */
interface Screen : EventTarget {
// CSSOM-View
// http://dev.w3.org/csswg/cssom-view/#the-screen-interface
[Throws]
readonly attribute long availWidth;
[Throws]
readonly attribute long availHeight;
[Throws]
readonly attribute long width;
[Throws]
readonly attribute long height;
[Throws]
readonly attribute long colorDepth;
[Throws]
readonly attribute long pixelDepth;
[Throws]
readonly attribute long top;
[Throws]
readonly attribute long left;
[Throws]
readonly attribute long availTop;
[Throws]
readonly attribute long availLeft;
/**
* Returns the current screen orientation.
* Can be: landscape-primary, landscape-secondary,
* portrait-primary or portrait-secondary.
*/
readonly attribute DOMString mozOrientation;
[SetterThrows]
attribute EventHandler onmozorientationchange;
/**
* Lock screen orientation to the specified type.
*/
[Throws]
boolean mozLockOrientation(DOMString orientation);
[Throws]
boolean mozLockOrientation(sequence<DOMString> orientation);
/**
* Unlock the screen orientation.
*/
void mozUnlockOrientation();
};

View File

@ -35,6 +35,7 @@ webidl_files = \
Performance.webidl \
PerformanceNavigation.webidl \
PerformanceTiming.webidl \
Screen.webidl \
SVGLengthList.webidl \
SVGNumberList.webidl \
SVGPathSegList.webidl \