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

This commit is contained in:
Mounir Lamouri 2012-02-07 13:23:45 +01:00
Родитель 35e3bc75b1
Коммит aa389d8a9f
9 изменённых файлов: 252 добавлений и 2 удалений

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

@ -106,6 +106,7 @@ EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
DOMError.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

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

@ -25,6 +25,7 @@
#include "nsIDocShell.h"
#include "mozilla/ClearOnShutdown.h"
#include "WindowIdentifier.h"
#include "mozilla/dom/ScreenOrientation.h"
using namespace mozilla::services;
@ -264,6 +265,24 @@ protected:
static NetworkObserversManager sNetworkObservers;
class ScreenOrientationObserversManager : public ObserversManager<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)
{
@ -426,5 +445,33 @@ void PowerOff()
PROXY_IF_SANDBOXED(PowerOff());
}
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

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

@ -21,6 +21,7 @@
#include "mozilla/dom/battery/Types.h"
#include "mozilla/dom/network/Types.h"
#include "mozilla/hal_sandbox/PHal.h"
#include "mozilla/dom/ScreenOrientation.h"
/*
* Hal.h contains the public Hal API.
@ -41,8 +42,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;
@ -233,6 +243,29 @@ void Reboot();
*/
void PowerOff();
/**
* 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

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

@ -69,6 +69,7 @@ CPPSRCS = \
Hal.cpp \
SandboxHal.cpp \
WindowIdentifier.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,12 +42,14 @@ 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;
using mozilla::hal::LightType;
using mozilla::hal::LightMode;
using mozilla::hal::SensorType;
using mozilla::dom::ScreenOrientation;
namespace mozilla {
@ -72,9 +74,7 @@ namespace hal {
PRTime timestamp;
float[] values;
};
}
namespace hal {
struct NetworkInformation {
double bandwidth;
bool canBeMetered;
@ -89,6 +89,7 @@ sync protocol PHal {
child:
NotifyBatteryChange(BatteryInformation aBatteryInfo);
NotifyNetworkChange(NetworkInformation aNetworkInfo);
NotifyScreenOrientationChange(ScreenOrientation aScreenOrientation);
parent:
Vibrate(uint32[] pattern, uint64[] id, PBrowser browser);
@ -118,6 +119,11 @@ parent:
Reboot();
PowerOff();
EnableScreenOrientationNotifications();
DisableScreenOrientationNotifications();
sync GetCurrentScreenOrientation()
returns (ScreenOrientation aScreenOrientation);
child:
NotifySensorChange(SensorData aSensorData);

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

@ -18,6 +18,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"
@ -97,6 +98,24 @@ GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo)
Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
}
void
EnableScreenOrientationNotifications()
{
Hal()->SendEnableScreenOrientationNotifications();
}
void
DisableScreenOrientationNotifications()
{
Hal()->SendDisableScreenOrientationNotifications();
}
void
GetCurrentScreenOrientation(ScreenOrientation* aScreenOrientation)
{
Hal()->SendGetCurrentScreenOrientation(aScreenOrientation);
}
bool
GetScreenEnabled()
{
@ -167,6 +186,7 @@ class HalParent : public PHalParent
, public BatteryObserver
, public NetworkObserver
, public ISensorObserver
, public ScreenOrientationObserver
{
public:
NS_OVERRIDE virtual bool
@ -252,6 +272,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)
{
@ -341,6 +383,12 @@ public:
hal::NotifyNetworkChange(aNetworkInfo);
return true;
}
NS_OVERRIDE virtual bool
RecvNotifyScreenOrientationChange(const ScreenOrientation& aScreenOrientation) {
hal::NotifyScreenOrientationChange(aScreenOrientation);
return true;
}
};
bool