Bug 720794 - Part 1 (HAL) - Implement reading and event parts of Screen Orientation API. r=cjones

This commit is contained in:
Mounir Lamouri 2012-03-13 17:42:46 +01:00
Родитель ca7e35591f
Коммит 37b6a6d4ef
9 изменённых файлов: 252 добавлений и 2 удалений

Просмотреть файл

@ -113,6 +113,7 @@ EXPORTS_mozilla/dom = \
DOMError.h \
DOMRequest.h \
StructuredCloneTags.h \
ScreenOrientation.h \
$(NULL)
CPPSRCS = \

Просмотреть файл

@ -0,0 +1,59 @@
/* 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/. */
#ifndef mozilla_dom_ScreenOrientation_h
#define mozilla_dom_ScreenOrientation_h
namespace mozilla {
namespace dom {
enum ScreenOrientation {
eScreenOrientation_Current = 0,
eScreenOrientation_PortraitPrimary = 1, // 00000001
eScreenOrientation_PortraitSecondary = 2, // 00000010
eScreenOrientation_Portrait = 3, // 00000011
eScreenOrientation_LandscapePrimary = 4, // 00000100
eScreenOrientation_LandscapeSecondary = 8, // 00001000
eScreenOrientation_Landscape = 12, // 00001100
eScreenOrientation_EndGuard
};
/**
* ScreenOrientationWrapper is a class wrapping ScreenOrientation so it can be
* used with Observer<T> which is taking a class, not an enum.
* C++11 should make this useless.
*/
class ScreenOrientationWrapper {
public:
ScreenOrientationWrapper()
: orientation(eScreenOrientation_Current)
{}
ScreenOrientationWrapper(ScreenOrientation aOrientation)
: orientation(aOrientation)
{}
ScreenOrientation orientation;
};
} // namespace dom
} // namespace mozilla
namespace IPC {
/**
* Screen orientation serializer.
* Note that technically, 5, 6, 7, 9, 10 and 11 are illegal values but will
* not make the serializer to fail. We might want to write our own serializer.
*/
template <>
struct ParamTraits<mozilla::dom::ScreenOrientation>
: public EnumSerializer<mozilla::dom::ScreenOrientation,
mozilla::dom::eScreenOrientation_Current,
mozilla::dom::eScreenOrientation_EndGuard>
{};
} // namespace IPC
#endif // mozilla_dom_ScreenOrientation_h

Просмотреть файл

@ -19,6 +19,7 @@
#include "nsIDocShell.h"
#include "mozilla/ClearOnShutdown.h"
#include "WindowIdentifier.h"
#include "mozilla/dom/ScreenOrientation.h"
using namespace mozilla::services;
@ -294,6 +295,24 @@ protected:
static WakeLockObserversManager sWakeLockObservers;
class ScreenOrientationObserversManager : public CachingObserversManager<dom::ScreenOrientationWrapper>
{
protected:
void EnableNotifications() {
PROXY_IF_SANDBOXED(EnableScreenOrientationNotifications());
}
void DisableNotifications() {
PROXY_IF_SANDBOXED(DisableScreenOrientationNotifications());
}
void GetCurrentInformationInternal(dom::ScreenOrientationWrapper* aInfo) {
PROXY_IF_SANDBOXED(GetCurrentScreenOrientation(&(aInfo->orientation)));
}
};
static ScreenOrientationObserversManager sScreenOrientationObservers;
void
RegisterBatteryObserver(BatteryObserver* aObserver)
{
@ -508,5 +527,33 @@ NotifyWakeLockChange(const WakeLockInformation& aInfo)
sWakeLockObservers.BroadcastInformation(aInfo);
}
void
RegisterScreenOrientationObserver(hal::ScreenOrientationObserver* aObserver)
{
AssertMainThread();
sScreenOrientationObservers.AddObserver(aObserver);
}
void
UnregisterScreenOrientationObserver(hal::ScreenOrientationObserver* aObserver)
{
AssertMainThread();
sScreenOrientationObservers.RemoveObserver(aObserver);
}
void
GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation)
{
AssertMainThread();
*aScreenOrientation = sScreenOrientationObservers.GetCurrentInformation().orientation;
}
void
NotifyScreenOrientationChange(const dom::ScreenOrientation& aScreenOrientation)
{
sScreenOrientationObservers.CacheInformation(dom::ScreenOrientationWrapper(aScreenOrientation));
sScreenOrientationObservers.BroadcastCachedInformation();
}
} // namespace hal
} // namespace mozilla

Просмотреть файл

@ -16,6 +16,7 @@
#include "mozilla/dom/network/Types.h"
#include "mozilla/dom/power/Types.h"
#include "mozilla/hal_sandbox/PHal.h"
#include "mozilla/dom/ScreenOrientation.h"
/*
* Hal.h contains the public Hal API.
@ -36,8 +37,17 @@ class nsIDOMWindow;
namespace mozilla {
template <class T>
class Observer;
namespace dom {
class ScreenOrientationWrapper;
}
namespace hal {
typedef Observer<dom::ScreenOrientationWrapper> ScreenOrientationObserver;
class WindowIdentifier;
extern PRLogModuleInfo *sHalLog;
@ -290,6 +300,29 @@ void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLoc
*/
void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
/**
* Inform the backend there is a new screen orientation observer.
* @param aScreenOrientationObserver The observer that should be added.
*/
void RegisterScreenOrientationObserver(hal::ScreenOrientationObserver* aScreenOrientationObserver);
/**
* Inform the backend a screen orientation observer unregistered.
* @param aScreenOrientationObserver The observer that should be removed.
*/
void UnregisterScreenOrientationObserver(hal::ScreenOrientationObserver* aScreenOrientationObserver);
/**
* Returns the current screen orientation.
*/
void GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation);
/**
* Notify of a change in the screen orientation.
* @param aScreenOrientation The new screen orientation.
*/
void NotifyScreenOrientationChange(const dom::ScreenOrientation& aScreenOrientation);
} // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla

Просмотреть файл

@ -77,6 +77,16 @@ void EnableNetworkNotifications();
*/
void DisableNetworkNotifications();
/**
* Enables screen orientation notifications from the backend.
*/
void EnableScreenOrientationNotifications();
/**
* Disables screen orientation notifications from the backend.
*/
void DisableScreenOrientationNotifications();
} // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla

Просмотреть файл

@ -71,6 +71,7 @@ CPPSRCS = \
SandboxHal.cpp \
WindowIdentifier.cpp \
HalWakeLock.cpp \
ScreenOrientationFallback.cpp \
$(NULL)
ifeq (android,$(MOZ_WIDGET_TOOLKIT))

Просмотреть файл

@ -0,0 +1,45 @@
/* 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/. */
#include "Hal.h"
#include "mozilla/dom/ScreenOrientation.h"
#include "nsIScreenManager.h"
namespace mozilla {
namespace hal_impl {
void
EnableScreenOrientationNotifications()
{
}
void
DisableScreenOrientationNotifications()
{
}
void
GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation)
{
nsresult result;
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1", &result);
if (NS_FAILED(result)) {
NS_ERROR("Can't find nsIScreenManager!");
return;
}
PRInt32 screenLeft, screenTop, screenWidth, screenHeight;
nsCOMPtr<nsIScreen> screen;
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
screen->GetRect(&screenLeft, &screenTop, &screenWidth, &screenHeight);
*aScreenOrientation = screenWidth >= screenHeight
? dom::eScreenOrientation_LandscapePrimary
: dom::eScreenOrientation_PortraitPrimary;
}
} // hal_impl
} // mozilla

Просмотреть файл

@ -42,6 +42,7 @@ include protocol PBrowser;
include "nspr/prtime.h";
include "mozilla/HalSensor.h";
include "mozilla/HalTypes.h";
include "mozilla/dom/ScreenOrientation.h";
using PRTime;
using mozilla::hal::FlashMode;
@ -49,6 +50,7 @@ using mozilla::hal::LightType;
using mozilla::hal::LightMode;
using mozilla::hal::SensorType;
using mozilla::hal::WakeLockControl;
using mozilla::dom::ScreenOrientation;
namespace mozilla {
@ -73,9 +75,7 @@ namespace hal {
PRTime timestamp;
float[] values;
};
}
namespace hal {
struct NetworkInformation {
double bandwidth;
bool canBeMetered;
@ -99,6 +99,7 @@ child:
NotifyBatteryChange(BatteryInformation aBatteryInfo);
NotifyNetworkChange(NetworkInformation aNetworkInfo);
NotifyWakeLockChange(WakeLockInformation aWakeLockInfo);
NotifyScreenOrientationChange(ScreenOrientation aScreenOrientation);
parent:
Vibrate(uint32[] pattern, uint64[] id, PBrowser browser);
@ -137,6 +138,11 @@ parent:
sync GetWakeLockInfo(nsString aTopic)
returns (WakeLockInformation aWakeLockInfo);
EnableScreenOrientationNotifications();
DisableScreenOrientationNotifications();
sync GetCurrentScreenOrientation()
returns (ScreenOrientation aScreenOrientation);
child:
NotifySensorChange(SensorData aSensorData);

Просмотреть файл

@ -12,6 +12,7 @@
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/battery/Types.h"
#include "mozilla/dom/network/Types.h"
#include "mozilla/dom/ScreenOrientation.h"
#include "mozilla/Observer.h"
#include "mozilla/unused.h"
#include "WindowIdentifier.h"
@ -91,6 +92,24 @@ GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo)
Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
}
void
EnableScreenOrientationNotifications()
{
Hal()->SendEnableScreenOrientationNotifications();
}
void
DisableScreenOrientationNotifications()
{
Hal()->SendDisableScreenOrientationNotifications();
}
void
GetCurrentScreenOrientation(ScreenOrientation* aScreenOrientation)
{
Hal()->SendGetCurrentScreenOrientation(aScreenOrientation);
}
bool
GetScreenEnabled()
{
@ -198,6 +217,7 @@ class HalParent : public PHalParent
, public NetworkObserver
, public ISensorObserver
, public WakeLockObserver
, public ScreenOrientationObserver
{
public:
NS_OVERRIDE virtual bool
@ -283,6 +303,28 @@ public:
unused << SendNotifyNetworkChange(aNetworkInfo);
}
NS_OVERRIDE virtual bool
RecvEnableScreenOrientationNotifications() {
hal::RegisterScreenOrientationObserver(this);
return true;
}
NS_OVERRIDE virtual bool
RecvDisableScreenOrientationNotifications() {
hal::UnregisterScreenOrientationObserver(this);
return true;
}
NS_OVERRIDE virtual bool
RecvGetCurrentScreenOrientation(ScreenOrientation* aScreenOrientation) {
hal::GetCurrentScreenOrientation(aScreenOrientation);
return true;
}
void Notify(const ScreenOrientationWrapper& aScreenOrientation) {
unused << SendNotifyScreenOrientationChange(aScreenOrientation.orientation);
}
NS_OVERRIDE virtual bool
RecvGetScreenEnabled(bool *enabled)
{
@ -427,6 +469,12 @@ public:
hal::NotifyWakeLockChange(aWakeLockInfo);
return true;
}
NS_OVERRIDE virtual bool
RecvNotifyScreenOrientationChange(const ScreenOrientation& aScreenOrientation) {
hal::NotifyScreenOrientationChange(aScreenOrientation);
return true;
}
};
bool