mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 740188 - Screen Orientation API locking (1/3): DOM/HAL boilerplate. r=smaug sr=sicking
This commit is contained in:
parent
cb4e86ba64
commit
de3ed2a2f0
@ -12,7 +12,7 @@ namespace dom {
|
||||
// * mobile/android/base/GeckoScreenOrientationListener.java
|
||||
// * embedding/android/GeckoScreenOrientationListener.java
|
||||
enum ScreenOrientation {
|
||||
eScreenOrientation_Current = 0,
|
||||
eScreenOrientation_None = 0,
|
||||
eScreenOrientation_PortraitPrimary = 1, // 00000001
|
||||
eScreenOrientation_PortraitSecondary = 2, // 00000010
|
||||
eScreenOrientation_Portrait = 3, // 00000011
|
||||
@ -30,7 +30,7 @@ enum ScreenOrientation {
|
||||
class ScreenOrientationWrapper {
|
||||
public:
|
||||
ScreenOrientationWrapper()
|
||||
: orientation(eScreenOrientation_Current)
|
||||
: orientation(eScreenOrientation_None)
|
||||
{}
|
||||
|
||||
ScreenOrientationWrapper(ScreenOrientation aOrientation)
|
||||
@ -53,7 +53,7 @@ namespace IPC {
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::ScreenOrientation>
|
||||
: public EnumSerializer<mozilla::dom::ScreenOrientation,
|
||||
mozilla::dom::eScreenOrientation_Current,
|
||||
mozilla::dom::eScreenOrientation_None,
|
||||
mozilla::dom::eScreenOrientation_EndGuard>
|
||||
{};
|
||||
|
||||
|
@ -380,7 +380,7 @@ nsScreen::Notify(const ScreenOrientationWrapper& aOrientation)
|
||||
ScreenOrientation previousOrientation = mOrientation;
|
||||
mOrientation = aOrientation.orientation;
|
||||
|
||||
NS_ASSERTION(mOrientation != eScreenOrientation_Current &&
|
||||
NS_ASSERTION(mOrientation != eScreenOrientation_None &&
|
||||
mOrientation != eScreenOrientation_EndGuard &&
|
||||
mOrientation != eScreenOrientation_Portrait &&
|
||||
mOrientation != eScreenOrientation_Landscape,
|
||||
@ -411,7 +411,7 @@ NS_IMETHODIMP
|
||||
nsScreen::GetMozOrientation(nsAString& aOrientation)
|
||||
{
|
||||
switch (mOrientation) {
|
||||
case eScreenOrientation_Current:
|
||||
case eScreenOrientation_None:
|
||||
case eScreenOrientation_EndGuard:
|
||||
case eScreenOrientation_Portrait:
|
||||
case eScreenOrientation_Landscape:
|
||||
@ -433,3 +433,36 @@ nsScreen::GetMozOrientation(nsAString& aOrientation)
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
*aReturn = hal::LockScreenOrientation(orientation);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreen::MozUnlockOrientation()
|
||||
{
|
||||
hal::UnlockScreenOrientation();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
#include "nsIDOMEventTarget.idl"
|
||||
|
||||
[scriptable, uuid(6366afc9-0072-4231-a4ec-98cd65f350ef)]
|
||||
[scriptable, uuid(8a66b30c-9a32-4b17-ab4e-ca8b7b588243)]
|
||||
interface nsIDOMScreen : nsIDOMEventTarget
|
||||
{
|
||||
readonly attribute long top;
|
||||
@ -84,4 +84,14 @@ interface nsIDOMScreen : nsIDOMEventTarget
|
||||
readonly attribute DOMString mozOrientation;
|
||||
|
||||
attribute nsIDOMEventListener onmozorientationchange;
|
||||
|
||||
/**
|
||||
* Lock screen orientation to the specified type.
|
||||
*/
|
||||
boolean mozLockOrientation(in DOMString orientation);
|
||||
|
||||
/**
|
||||
* Unlock the screen orientation.
|
||||
*/
|
||||
void mozUnlockOrientation();
|
||||
};
|
||||
|
14
hal/Hal.cpp
14
hal/Hal.cpp
@ -566,5 +566,19 @@ NotifyScreenOrientationChange(const dom::ScreenOrientation& aScreenOrientation)
|
||||
sScreenOrientationObservers.BroadcastCachedInformation();
|
||||
}
|
||||
|
||||
bool
|
||||
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
||||
{
|
||||
AssertMainThread();
|
||||
RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation));
|
||||
}
|
||||
|
||||
void
|
||||
UnlockScreenOrientation()
|
||||
{
|
||||
AssertMainThread();
|
||||
PROXY_IF_SANDBOXED(UnlockScreenOrientation());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
} // namespace mozilla
|
||||
|
11
hal/Hal.h
11
hal/Hal.h
@ -323,6 +323,17 @@ void GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation);
|
||||
*/
|
||||
void NotifyScreenOrientationChange(const dom::ScreenOrientation& aScreenOrientation);
|
||||
|
||||
/**
|
||||
* Lock the screen orientation to the specific orientation.
|
||||
* @return Whether the lock has been accepted.
|
||||
*/
|
||||
bool LockScreenOrientation(const dom::ScreenOrientation& aOrientation);
|
||||
|
||||
/**
|
||||
* Unlock the screen orientation.
|
||||
*/
|
||||
void UnlockScreenOrientation();
|
||||
|
||||
} // namespace MOZ_HAL_NAMESPACE
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -217,6 +217,17 @@ GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation)
|
||||
*aScreenOrientation = orientationWrapper.orientation;
|
||||
}
|
||||
|
||||
bool
|
||||
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
UnlockScreenOrientation()
|
||||
{
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
||||
|
||||
|
@ -41,5 +41,16 @@ GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation)
|
||||
: dom::eScreenOrientation_PortraitPrimary;
|
||||
}
|
||||
|
||||
bool
|
||||
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
UnlockScreenOrientation()
|
||||
{
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
||||
|
@ -144,6 +144,9 @@ parent:
|
||||
DisableScreenOrientationNotifications();
|
||||
sync GetCurrentScreenOrientation()
|
||||
returns (ScreenOrientation aScreenOrientation);
|
||||
sync LockScreenOrientation(ScreenOrientation aOrientation)
|
||||
returns (bool allowed);
|
||||
UnlockScreenOrientation();
|
||||
|
||||
child:
|
||||
NotifySensorChange(SensorData aSensorData);
|
||||
|
@ -110,6 +110,20 @@ GetCurrentScreenOrientation(ScreenOrientation* aScreenOrientation)
|
||||
Hal()->SendGetCurrentScreenOrientation(aScreenOrientation);
|
||||
}
|
||||
|
||||
bool
|
||||
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
||||
{
|
||||
bool allowed;
|
||||
Hal()->SendLockScreenOrientation(aOrientation, &allowed);
|
||||
return allowed;
|
||||
}
|
||||
|
||||
void
|
||||
UnlockScreenOrientation()
|
||||
{
|
||||
Hal()->SendUnlockScreenOrientation();
|
||||
}
|
||||
|
||||
bool
|
||||
GetScreenEnabled()
|
||||
{
|
||||
@ -321,6 +335,20 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvLockScreenOrientation(const dom::ScreenOrientation& aOrientation, bool* aAllowed)
|
||||
{
|
||||
*aAllowed = hal::LockScreenOrientation(aOrientation);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvUnlockScreenOrientation()
|
||||
{
|
||||
hal::UnlockScreenOrientation();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Notify(const ScreenOrientationWrapper& aScreenOrientation) {
|
||||
unused << SendNotifyScreenOrientationChange(aScreenOrientation.orientation);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user