Back out bug 735330, bug 737462, bug 734854 because they broke XUL Fennec

--HG--
rename : hal/cocoa/smslib.h => dom/system/cocoa/smslib.h
rename : hal/cocoa/smslib.mm => dom/system/cocoa/smslib.mm
This commit is contained in:
Matt Brubeck 2012-03-20 16:59:24 -07:00
parent 0f018487d9
commit 388850e1f0
44 changed files with 1585 additions and 365 deletions

View File

@ -96,6 +96,8 @@
#include "nsPermissionManager.h"
#endif
#include "nsDeviceMotion.h"
#if defined(MOZ_WIDGET_ANDROID)
#include "APKOpen.h"
#endif
@ -739,6 +741,28 @@ ContentChild::RecvAddPermission(const IPC::Permission& permission)
return true;
}
bool
ContentChild::RecvDeviceMotionChanged(const long int& type,
const double& x, const double& y,
const double& z)
{
nsCOMPtr<nsIDeviceMotionUpdate> dmu =
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
if (dmu)
dmu->DeviceMotionChanged(type, x, y, z);
return true;
}
bool
ContentChild::RecvNeedsCalibration()
{
nsCOMPtr<nsIDeviceMotionUpdate> dmu =
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
if (dmu)
dmu->NeedsCalibration();
return true;
}
bool
ContentChild::RecvScreenSizeChanged(const gfxIntSize& size)
{

View File

@ -158,6 +158,12 @@ public:
virtual bool RecvAddPermission(const IPC::Permission& permission);
virtual bool RecvDeviceMotionChanged(const long int& type,
const double& x, const double& y,
const double& z);
virtual bool RecvNeedsCalibration();
virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
virtual bool RecvFlushMemory(const nsString& reason);

View File

@ -96,6 +96,7 @@
#include "mozilla/hal_sandbox/PHalParent.h"
#include "mozilla/Services.h"
#include "mozilla/unused.h"
#include "nsDeviceMotion.h"
#include "mozilla/Util.h"
#include "nsIMemoryReporter.h"
@ -336,6 +337,7 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
}
RecvRemoveGeolocationListener();
RecvRemoveDeviceMotionListener();
nsCOMPtr<nsIThreadInternal>
threadInt(do_QueryInterface(NS_GetCurrentThread()));
@ -683,10 +685,11 @@ ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
return true;
}
NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent,
NS_IMPL_THREADSAFE_ISUPPORTS4(ContentParent,
nsIObserver,
nsIThreadObserver,
nsIDOMGeoPositionCallback)
nsIDOMGeoPositionCallback,
nsIDeviceMotionListener)
NS_IMETHODIMP
ContentParent::Observe(nsISupports* aSubject,
@ -1213,6 +1216,26 @@ ContentParent::RecvRemoveGeolocationListener()
return true;
}
bool
ContentParent::RecvAddDeviceMotionListener()
{
nsCOMPtr<nsIDeviceMotion> dm =
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
if (dm)
dm->AddListener(this);
return true;
}
bool
ContentParent::RecvRemoveDeviceMotionListener()
{
nsCOMPtr<nsIDeviceMotion> dm =
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
if (dm)
dm->RemoveListener(this);
return true;
}
NS_IMETHODIMP
ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
{
@ -1255,5 +1278,25 @@ ContentParent::RecvScriptError(const nsString& aMessage,
return true;
}
NS_IMETHODIMP
ContentParent::OnMotionChange(nsIDeviceMotionData *aDeviceData) {
PRUint32 type;
double x, y, z;
aDeviceData->GetType(&type);
aDeviceData->GetX(&x);
aDeviceData->GetY(&y);
aDeviceData->GetZ(&z);
unused << SendDeviceMotionChanged(type, x, y, z);
return NS_OK;
}
NS_IMETHODIMP
ContentParent::NeedsCalibration() {
unused << SendNeedsCalibration();
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -51,6 +51,7 @@
#include "nsIPrefService.h"
#include "nsIPermissionManager.h"
#include "nsIDOMGeoPositionCallback.h"
#include "nsIDeviceMotion.h"
#include "nsIMemoryReporter.h"
#include "nsCOMArray.h"
@ -70,6 +71,7 @@ class ContentParent : public PContentParent
, public nsIObserver
, public nsIThreadObserver
, public nsIDOMGeoPositionCallback
, public nsIDeviceMotionListener
{
private:
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
@ -83,6 +85,7 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSITHREADOBSERVER
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
NS_DECL_NSIDEVICEMOTIONLISTENER
TabParent* CreateTab(PRUint32 aChromeFlags);
@ -215,6 +218,8 @@ private:
virtual bool RecvAddGeolocationListener();
virtual bool RecvRemoveGeolocationListener();
virtual bool RecvAddDeviceMotionListener();
virtual bool RecvRemoveDeviceMotionListener();
virtual bool RecvConsoleMessage(const nsString& aMessage);
virtual bool RecvScriptError(const nsString& aMessage,

View File

@ -133,6 +133,9 @@ child:
// nsIPermissionManager messages
AddPermission(Permission permission);
DeviceMotionChanged(long type, double x, double y, double z);
NeedsCalibration();
ScreenSizeChanged(gfxIntSize size);
FlushMemory(nsString reason);
@ -197,6 +200,8 @@ parent:
AddGeolocationListener();
RemoveGeolocationListener();
AddDeviceMotionListener();
RemoveDeviceMotionListener();
ConsoleMessage(nsString message);
ScriptError(nsString message, nsString sourceName, nsString sourceLine,

View File

@ -53,6 +53,10 @@ ifneq (,$(filter windows,$(MOZ_WIDGET_TOOLKIT)))
DIRS = windows
endif
ifneq (,$(filter cocoa,$(MOZ_WIDGET_TOOLKIT)))
DIRS = cocoa
endif
ifneq (,$(filter android,$(MOZ_WIDGET_TOOLKIT)))
DIRS = android
endif
@ -92,6 +96,6 @@ include $(topsrcdir)/config/config.mk
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
EXPORT_LIBRARY = 1
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk

View File

@ -53,6 +53,7 @@ include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
CPPSRCS = \
nsDeviceMotionSystem.cpp \
AndroidLocationProvider.cpp \
nsHapticFeedback.cpp \
$(NULL)

View File

@ -0,0 +1,73 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Wu <mwu@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/dom/ContentChild.h"
#include "nsDeviceMotionSystem.h"
#include "AndroidBridge.h"
#include "nsXULAppAPI.h"
using namespace mozilla;
extern nsDeviceMotionSystem *gDeviceMotionSystem;
nsDeviceMotionSystem::nsDeviceMotionSystem()
{
gDeviceMotionSystem = this;
}
nsDeviceMotionSystem::~nsDeviceMotionSystem()
{
}
void nsDeviceMotionSystem::Startup()
{
if (XRE_GetProcessType() == GeckoProcessType_Default)
AndroidBridge::Bridge()->EnableDeviceMotion(true);
else
mozilla::dom::ContentChild::GetSingleton()->
SendAddDeviceMotionListener();
}
void nsDeviceMotionSystem::Shutdown()
{
if (XRE_GetProcessType() == GeckoProcessType_Default)
AndroidBridge::Bridge()->EnableDeviceMotion(false);
else
mozilla::dom::ContentChild::GetSingleton()->
SendRemoveDeviceMotionListener();
}

View File

@ -0,0 +1,54 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Wu <mwu@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDeviceMotionSystem_h
#define nsDeviceMotionSystem_h
#include "nsDeviceMotion.h"
class nsDeviceMotionSystem : public nsDeviceMotion
{
public:
nsDeviceMotionSystem();
virtual ~nsDeviceMotionSystem();
private:
virtual void Startup();
virtual void Shutdown();
};
#endif /* nsDeviceMotionSystem_h */

View File

@ -0,0 +1,62 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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/
#
# 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.
#
# The Original Code is mozilla.org build system.
#
# The Initial Developer of the Original Code is Mozilla Foundation
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mike Kristoffersen <mikek@mikek.dk>
#
# Alternatively, the contents of this file may be used under the terms of
# either 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"),
# 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
# use your version of this file under the terms of the MPL, indicate your
# 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
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
LIBRARY_NAME = domsystemcocoa_s
# we don't want the shared lib, but we want to force the creation of a static lib.
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
EXPORT_LIBRARY = 1
# We fire the nsDOMDeviceAcceleration
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
include $(topsrcdir)/config/config.mk
CMMSRCS = \
smslib.mm \
nsDeviceMotionSystem.mm \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,59 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Doug Turner <dougt@dougt.org>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDeviceMotionSystem_h
#define nsDeviceMotionSystem_h
#include <IOKit/IOKitLib.h>
#include <mach/mach_port.h>
#include "nsDeviceMotion.h"
class nsDeviceMotionSystem : public nsDeviceMotion
{
public:
nsDeviceMotionSystem();
~nsDeviceMotionSystem();
void Startup();
void Shutdown();
io_connect_t mSmsConnection;
nsCOMPtr<nsITimer> mUpdateTimer;
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
};
#endif

View File

@ -0,0 +1,96 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Doug Turner <dougt@dougt.org>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDeviceMotionSystem.h"
#include "nsIServiceManager.h"
#include "stdlib.h"
#include <sys/sysctl.h>
#include <sys/resource.h>
#include <sys/vm.h>
#import "smslib.h"
#define MEAN_GRAVITY 9.80665
#define DEFAULT_SENSOR_POLL 100
nsDeviceMotionSystem::nsDeviceMotionSystem()
{
}
nsDeviceMotionSystem::~nsDeviceMotionSystem()
{
}
void
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
{
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
if (!self) {
NS_ERROR("no self");
return;
}
sms_acceleration accel;
smsGetData(&accel);
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
accel.x * MEAN_GRAVITY,
accel.y * MEAN_GRAVITY,
accel.z * MEAN_GRAVITY);
}
void nsDeviceMotionSystem::Startup()
{
smsStartup(nil, nil);
smsLoadCalibration();
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mUpdateTimer)
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
this,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}
void nsDeviceMotionSystem::Shutdown()
{
if (mUpdateTimer) {
mUpdateTimer->Cancel();
mUpdateTimer = nsnull;
}
smsShutdown();
}

View File

@ -0,0 +1,47 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is Mozilla code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brad Lassey <blassey@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsHapticFeedback.h"
NS_IMPL_ISUPPORTS1(nsHapticFeedback, nsIHapticFeedback)
NS_IMETHODIMP
nsHapticFeedback::PerformSimpleAction(PRInt32 aType)
{
// Todo
return NS_OK;
}

View File

@ -0,0 +1,45 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is Mozilla code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brad Lassey <blassey@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIHapticFeedback.h"
class nsHapticFeedback : public nsIHapticFeedback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHAPTICFEEDBACK
};

View File

@ -34,9 +34,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/Hal.h"
#include "mozilla/HalSensor.h"
#include "nsDeviceMotion.h"
#include "nsAutoPtr.h"
@ -50,8 +47,8 @@
#include "nsIServiceManager.h"
#include "nsIPrefService.h"
using namespace mozilla;
using namespace hal;
using mozilla::TimeStamp;
using mozilla::TimeDuration;
// also see sDefaultSensorHint in mobile/android/base/GeckoAppShell.java
#define DEFAULT_SENSOR_POLL 100
@ -119,15 +116,12 @@ NS_IMETHODIMP nsDeviceMotionData::GetZ(double *aZ)
return NS_OK;
}
NS_IMPL_ISUPPORTS1(nsDeviceMotion, nsIDeviceMotion)
NS_IMPL_ISUPPORTS2(nsDeviceMotion, nsIDeviceMotion, nsIDeviceMotionUpdate)
nsDeviceMotion::nsDeviceMotion()
: mStarted(false),
mEnabled(true)
{
mLastDOMMotionEventTime = TimeStamp::Now();
mLastAccuracy = SENSOR_ACCURACY_UNKNOWN;
nsCOMPtr<nsIPrefBranch> prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefSrv) {
bool bvalue;
@ -140,9 +134,6 @@ nsDeviceMotion::nsDeviceMotion()
nsDeviceMotion::~nsDeviceMotion()
{
if (mStarted)
Shutdown();
if (mTimeoutTimer)
mTimeoutTimer->Cancel();
}
@ -228,24 +219,11 @@ NS_IMETHODIMP nsDeviceMotion::RemoveWindowListener(nsIDOMWindow *aWindow)
return NS_OK;
}
void
nsDeviceMotion::Notify(const mozilla::hal::SensorData& aSensorData)
NS_IMETHODIMP
nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
{
if (!mEnabled)
return;
PRUint32 type = aSensorData.sensor();
double x = aSensorData.values()[0];
double y = aSensorData.values()[1];
double z = aSensorData.values()[2];
SensorAccuracyType accuracy = aSensorData.accuracy();
if (accuracy <= SENSOR_ACCURACY_LOW && mLastAccuracy >= SENSOR_ACCURACY_MED) {
FireNeedsCalibration();
}
mLastAccuracy = accuracy;
return NS_ERROR_NOT_INITIALIZED;
nsCOMArray<nsIDeviceMotionListener> listeners = mListeners;
for (PRUint32 i = listeners.Count(); i > 0 ; ) {
@ -277,19 +255,20 @@ nsDeviceMotion::Notify(const mozilla::hal::SensorData& aSensorData)
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(windowListeners[i]);
if (type == nsIDeviceMotionData::TYPE_ACCELERATION ||
type == nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION ||
type == nsIDeviceMotionData::TYPE_GYROSCOPE)
type == nsIDeviceMotionData::TYPE_GYROSCOPE )
FireDOMMotionEvent(domdoc, target, type, x, y, z);
else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)
FireDOMOrientationEvent(domdoc, target, x, y, z);
}
}
return NS_OK;
}
void
nsDeviceMotion::FireNeedsCalibration()
NS_IMETHODIMP
nsDeviceMotion::NeedsCalibration()
{
if (!mEnabled)
return;
return NS_ERROR_NOT_INITIALIZED;
nsCOMArray<nsIDeviceMotionListener> listeners = mListeners;
for (PRUint32 i = listeners.Count(); i > 0 ; ) {
@ -321,6 +300,8 @@ nsDeviceMotion::FireNeedsCalibration()
FireNeedsCalibration(domdoc, target);
}
}
return NS_OK;
}
void
@ -428,23 +409,6 @@ nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
mLastAccelerationIncluduingGravity = nsnull;
mLastAcceleration = nsnull;
mLastDOMMotionEventTime = TimeStamp::Now();
}
void nsDeviceMotion::Startup()
{
// Bug 734855 - we probably can make this finer grain
// based on the DOM APIs that are being invoked.
RegisterSensorObserver(SENSOR_ACCELERATION, this);
RegisterSensorObserver(SENSOR_ORIENTATION, this);
RegisterSensorObserver(SENSOR_LINEAR_ACCELERATION, this);
RegisterSensorObserver(SENSOR_GYROSCOPE, this);
}
void nsDeviceMotion::Shutdown()
{
UnregisterSensorObserver(SENSOR_ACCELERATION, this);
UnregisterSensorObserver(SENSOR_ORIENTATION, this);
UnregisterSensorObserver(SENSOR_LINEAR_ACCELERATION, this);
UnregisterSensorObserver(SENSOR_GYROSCOPE, this);
}

View File

@ -47,8 +47,6 @@
#include "nsIDOMDeviceMotionEvent.h"
#include "nsDOMDeviceMotionEvent.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/HalSensor.h"
#define NS_DEVICE_MOTION_CID \
{ 0xecba5203, 0x77da, 0x465a, \
@ -58,18 +56,17 @@
class nsIDOMWindow;
class nsDeviceMotion : public nsIDeviceMotion, public mozilla::hal::ISensorObserver
class nsDeviceMotion : public nsIDeviceMotionUpdate
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDEVICEMOTION
NS_DECL_NSIDEVICEMOTIONUPDATE
nsDeviceMotion();
virtual ~nsDeviceMotion();
void Notify(const mozilla::hal::SensorData& aSensorData);
private:
nsCOMArray<nsIDeviceMotionListener> mListeners;
nsTArray<nsIDOMWindow*> mWindowListeners;
@ -82,7 +79,6 @@ private:
static void TimeoutHandler(nsITimer *aTimer, void *aClosure);
protected:
void FireNeedsCalibration();
void FireNeedsCalibration(nsIDOMDocument *domdoc,
nsIDOMEventTarget *target);
@ -100,15 +96,15 @@ private:
double y,
double z);
void Startup();
void Shutdown();
virtual void Startup() = 0;
virtual void Shutdown() = 0;
bool mEnabled;
mozilla::TimeStamp mLastDOMMotionEventTime;
mozilla::hal::SensorAccuracyType mLastAccuracy;
nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
};
#endif

View File

@ -53,6 +53,12 @@ include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
ifndef MOZ_ENABLE_QTMOBILITY
CPPSRCS = \
nsDeviceMotionSystem.cpp \
$(NULL)
endif
ifdef MOZ_MAEMO_LIBLOCATION
CPPSRCS += MaemoLocationProvider.cpp
LOCAL_INCLUDES += $(MOZ_PLATFORM_MAEMO_CFLAGS) \
@ -65,9 +71,10 @@ CPPSRCS += nsHapticFeedback.cpp
LOCAL_INCLUDES += $(MOZ_DBUS_CFLAGS) \
$(NULL)
ifdef MOZ_ENABLE_QTMOBILITY
MOCSRCS += moc_QTMLocationProvider.cpp
MOCSRCS += moc_QTMLocationProvider.cpp moc_nsQTMDeviceMotionSystem.cpp
CPPSRCS += $(MOCSRCS) \
QTMLocationProvider.cpp \
nsQTMDeviceMotionSystem.cpp \
$(NULL)
LOCAL_INCLUDES += $(MOZ_QT_CFLAGS) \
-I$(topsrcdir)/dom/src/geolocation \
@ -75,4 +82,7 @@ LOCAL_INCLUDES += $(MOZ_QT_CFLAGS) \
endif
endif
# We fire the nsDOMDeviceAcceleration
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,253 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Ventnor <m.ventnor@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <unistd.h>
#include "mozilla/Util.h"
#include "nsDeviceMotionSystem.h"
#include "nsIServiceManager.h"
#define DEFAULT_SENSOR_POLL 100
using namespace mozilla;
typedef struct {
const char* mPosition;
const char* mCalibrate;
nsAccelerometerSystemDriver mToken;
} AccelerometerData;
static const AccelerometerData gAccelerometers[] = {
// MacBook
{"/sys/devices/platform/applesmc.768/position",
"/sys/devices/platform/applesmc.768/calibrate",
eAppleSensor},
// Thinkpad
{"/sys/devices/platform/hdaps/position",
"/sys/devices/platform/hdaps/calibrate",
eIBMSensor},
// Maemo Fremantle
{"/sys/class/i2c-adapter/i2c-3/3-001d/coord",
NULL,
eMaemoSensor},
// HP Pavilion dv7
{"/sys/devices/platform/lis3lv02d/position",
"/sys/devices/platform/lis3lv02d/calibrate",
eHPdv7Sensor},
};
nsDeviceMotionSystem::nsDeviceMotionSystem() :
mPositionFile(NULL),
mCalibrateFile(NULL),
mType(eNoSensor)
{
}
nsDeviceMotionSystem::~nsDeviceMotionSystem()
{
}
void
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
{
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
if (!self) {
NS_ERROR("no self");
return;
}
float xf, yf, zf;
switch (self->mType) {
case eAppleSensor:
{
int x, y, z, calibrate_x, calibrate_y;
fflush(self->mCalibrateFile);
rewind(self->mCalibrateFile);
fflush(self->mPositionFile);
rewind(self->mPositionFile);
if (fscanf(self->mCalibrateFile, "(%d, %d)", &calibrate_x, &calibrate_y) <= 0)
return;
if (fscanf(self->mPositionFile, "(%d, %d, %d)", &x, &y, &z) <= 0)
return;
// In applesmc:
// - the x calibration value is negated
// - a negative z actually means a correct-way-up computer
// - dividing by 255 gives us the intended value of -1 to 1
xf = ((float)(x + calibrate_x)) / 255.0;
yf = ((float)(y - calibrate_y)) / 255.0;
zf = ((float)z) / -255.0;
break;
}
case eIBMSensor:
{
int x, y, calibrate_x, calibrate_y;
fflush(self->mCalibrateFile);
rewind(self->mCalibrateFile);
fflush(self->mPositionFile);
rewind(self->mPositionFile);
if (fscanf(self->mCalibrateFile, "(%d, %d)", &calibrate_x, &calibrate_y) <= 0)
return;
if (fscanf(self->mPositionFile, "(%d, %d)", &x, &y) <= 0)
return;
xf = ((float)(x - calibrate_x)) / 180.0;
yf = ((float)(y - calibrate_y)) / 180.0;
zf = 1.0f;
break;
}
case eMaemoSensor:
{
int x, y, z;
fflush(self->mPositionFile);
rewind(self->mPositionFile);
if (fscanf(self->mPositionFile, "%d %d %d", &x, &y, &z) <= 0)
return;
xf = ((float)x) / -1000.0;
yf = ((float)y) / -1000.0;
zf = ((float)z) / -1000.0;
break;
}
case eHPdv7Sensor:
{
int x, y, z, calibrate_x, calibrate_y, calibrate_z;
fflush(self->mCalibrateFile);
rewind(self->mCalibrateFile);
fflush(self->mPositionFile);
rewind(self->mPositionFile);
if (fscanf(self->mCalibrateFile, "(%d,%d,%d)", &calibrate_x, &calibrate_y, &calibrate_z) <= 0)
return;
if (fscanf(self->mPositionFile, "(%d,%d,%d)", &x, &y, &z) <= 0)
return;
// Example data:
//
// Calibration (-4,0,51)
// flat on the table (-5,-2,50)
// Tilted on its left side (-60,0,-4)
// Tilted on its right side (51,1,-1)
// upside down (-2,3,-60)
//
// So assuming the calibration data shows the acceleration
// (1G) measured with the notebook laying flat on the table
// it would mean that our best bet, is to ignore the z-axis
// calibration... We are still way off, but it's hard to
// see how to get better data without doing calibration with
// user intervention (like: Turn your notbook slowly around
// so every edge and the top and bottom points up in turn)
xf = ((float)(x - calibrate_x)) / 60.0;
yf = ((float)(y - calibrate_y)) / 60.0;
zf = ((float)(z)) / 60.0;
break;
}
case eNoSensor:
default:
return;
}
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, xf, yf, zf );
}
void nsDeviceMotionSystem::Startup()
{
// Accelerometers in Linux are used by reading a file (yay UNIX!), which is
// in a slightly different location depending on the driver.
for (unsigned int i = 0; i < ArrayLength(gAccelerometers); i++) {
if (!(mPositionFile = fopen(gAccelerometers[i].mPosition, "r")))
continue;
mType = gAccelerometers[i].mToken;
if (gAccelerometers[i].mCalibrate) {
mCalibrateFile = fopen(gAccelerometers[i].mCalibrate, "r");
if (!mCalibrateFile) {
fclose(mPositionFile);
mPositionFile = nsnull;
return;
}
}
break;
}
if (mType == eNoSensor)
return;
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mUpdateTimer)
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
this,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}
void nsDeviceMotionSystem::Shutdown()
{
if (mPositionFile) {
fclose(mPositionFile);
mPositionFile = nsnull;
}
// Fun fact: writing to the calibrate file causes the
// driver to re-calibrate the accelerometer
if (mCalibrateFile) {
fclose(mCalibrateFile);
mCalibrateFile = nsnull;
}
mType = eNoSensor;
if (mUpdateTimer) {
mUpdateTimer->Cancel();
mUpdateTimer = nsnull;
}
}

View File

@ -0,0 +1,71 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Ventnor <m.ventnor@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDeviceMotionSystem_h
#define nsDeviceMotionSystem_h
#include <unistd.h>
#include <stdio.h>
#include "nsDeviceMotion.h"
enum nsAccelerometerSystemDriver
{
eNoSensor,
eAppleSensor,
eIBMSensor,
eMaemoSensor,
eHPdv7Sensor
};
class nsDeviceMotionSystem : public nsDeviceMotion
{
public:
nsDeviceMotionSystem();
~nsDeviceMotionSystem();
void Startup();
void Shutdown();
FILE* mPositionFile;
FILE* mCalibrateFile;
nsAccelerometerSystemDriver mType;
nsCOMPtr<nsITimer> mUpdateTimer;
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
};
#endif

View File

@ -0,0 +1,126 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/dom/ContentChild.h"
#include "nsQTMDeviceMotionSystem.h"
#include <QObject>
#include <QtSensors/QAccelerometer>
#include <QtSensors/QRotationSensor>
#include "nsXULAppAPI.h"
using namespace mozilla;
using namespace QtMobility;
bool
MozQAccelerometerSensorFilter::filter(QAccelerometerReading* reading)
{
mSystem.DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
-reading->x(),
-reading->y(),
-reading->z());
return true;
}
bool
MozQRotationSensorFilter::filter(QRotationReading* reading)
{
// QRotationReading class:
// - the rotation around z axis (alpha) is given as z in QRotationReading;
// - the rotation around x axis (beta) is given as x in QRotationReading;
// - the rotation around y axis (gamma) is given as y in QRotationReading;
// See: http://doc.qt.nokia.com/qtmobility-1.0/qrotationreading.html
mSystem.DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
reading->z(),
reading->x(),
reading->y());
return true;
}
nsDeviceMotionSystem::nsDeviceMotionSystem()
{
if (XRE_GetProcessType() == GeckoProcessType_Default) {
mAccelerometer = new QAccelerometer();
mAccelerometerFilter = new MozQAccelerometerSensorFilter(*this);
mAccelerometer->addFilter(mAccelerometerFilter);
mRotation = new QRotationSensor();
mRotationFilter = new MozQRotationSensorFilter(*this);
mRotation->addFilter(mRotationFilter);
}
}
nsDeviceMotionSystem::~nsDeviceMotionSystem()
{
if (XRE_GetProcessType() == GeckoProcessType_Default) {
mAccelerometer->removeFilter(mAccelerometerFilter);
mAccelerometer->stop();
mRotation->removeFilter(mRotationFilter);
mRotation->stop();
delete mAccelerometer;
delete mAccelerometerFilter;
delete mRotation;
delete mRotationFilter;
}
}
void nsDeviceMotionSystem::Startup()
{
if (XRE_GetProcessType() == GeckoProcessType_Default) {
mAccelerometer->start();
if (!mAccelerometer->isActive()) {
NS_WARNING("AccelerometerSensor didn't start!");
}
mRotation->start();
if (!mRotation->isActive()) {
NS_WARNING("RotationSensor didn't start!");
}
}
else
mozilla::dom::ContentChild::GetSingleton()->
SendAddDeviceMotionListener();
}
void nsDeviceMotionSystem::Shutdown()
{
if (XRE_GetProcessType() == GeckoProcessType_Default) {
mAccelerometer->stop();
mRotation->stop();
}
else
mozilla::dom::ContentChild::GetSingleton()->
SendRemoveDeviceMotionListener();
}

View File

@ -0,0 +1,100 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDeviceMotionSystem_h
#define nsDeviceMotionSystem_h
#include <QObject>
#include <QtSensors/QAccelerometer>
#include <QtSensors/QRotationSensor>
#include "nsDeviceMotion.h"
using namespace QtMobility;
class MozQAccelerometerSensorFilter;
class MozQRotationSensorFilter;
class nsDeviceMotionSystem : public nsDeviceMotion
{
public:
nsDeviceMotionSystem();
virtual ~nsDeviceMotionSystem();
private:
virtual void Startup();
virtual void Shutdown();
QtMobility::QAccelerometer* mAccelerometer;
MozQAccelerometerSensorFilter* mAccelerometerFilter;
QtMobility::QRotationSensor* mRotation;
MozQRotationSensorFilter* mRotationFilter;
};
class MozQAccelerometerSensorFilter : public QObject, public QAccelerometerFilter
{
Q_OBJECT
public:
MozQAccelerometerSensorFilter(nsDeviceMotionSystem& aSystem) : mSystem(aSystem) {}
virtual ~MozQAccelerometerSensorFilter(){}
virtual bool filter(QAccelerometerReading* reading);
private:
bool filter(QSensorReading *reading) { return filter(static_cast<QAccelerometerReading*>(reading)); }
nsDeviceMotionSystem& mSystem;
};
class MozQRotationSensorFilter : public QObject, public QRotationFilter
{
Q_OBJECT
public:
MozQRotationSensorFilter(nsDeviceMotionSystem& aSystem) : mSystem(aSystem) {}
virtual ~MozQRotationSensorFilter(){}
virtual bool filter(QRotationReading* reading);
private:
bool filter(QSensorReading *reading) { return filter(static_cast<QRotationReading*>(reading)); }
nsDeviceMotionSystem& mSystem;
};
#endif /* nsDeviceMotionSystem_h */

View File

@ -55,6 +55,7 @@ LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
include $(topsrcdir)/config/config.mk
CPPSRCS = \
nsDeviceMotionSystem.cpp \
nsHapticFeedback.cpp \
$(NULL)

View File

@ -0,0 +1,175 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Doug Turner <dougt@dougt.org>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jesper Kristensen <mail@jesperkristensen.dk>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDeviceMotionSystem.h"
#include "nsIServiceManager.h"
#include "windows.h"
#define DEFAULT_SENSOR_POLL 100
////////////////////////////
// ThinkPad
////////////////////////////
typedef struct {
int status; // Current internal state
unsigned short x; // raw value
unsigned short y; // raw value
unsigned short xx; // avg. of 40ms
unsigned short yy; // avg. of 40ms
char temp; // raw value (could be deg celsius?)
unsigned short x0; // Used for "auto-center"
unsigned short y0; // Used for "auto-center"
} ThinkPadAccelerometerData;
typedef void (__stdcall *ShockproofGetAccelerometerData)(ThinkPadAccelerometerData*);
ShockproofGetAccelerometerData gShockproofGetAccelerometerData = nsnull;
class ThinkPadSensor : public Sensor
{
public:
ThinkPadSensor();
~ThinkPadSensor();
bool Startup();
void Shutdown();
void GetValues(double *x, double *y, double *z);
private:
HMODULE mLibrary;
};
ThinkPadSensor::ThinkPadSensor()
{
}
ThinkPadSensor::~ThinkPadSensor()
{
}
bool
ThinkPadSensor::Startup()
{
mLibrary = LoadLibraryW(L"sensor.dll");
if (!mLibrary)
return false;
gShockproofGetAccelerometerData = (ShockproofGetAccelerometerData)
GetProcAddress(mLibrary, "ShockproofGetAccelerometerData");
if (!gShockproofGetAccelerometerData) {
FreeLibrary(mLibrary);
mLibrary = nsnull;
return false;
}
return true;
}
void
ThinkPadSensor::Shutdown()
{
if (mLibrary == nsnull)
return;
FreeLibrary(mLibrary);
mLibrary = nsnull;
gShockproofGetAccelerometerData = nsnull;
}
void
ThinkPadSensor::GetValues(double *x, double *y, double *z)
{
ThinkPadAccelerometerData accelData;
gShockproofGetAccelerometerData(&accelData);
// accelData.x and accelData.y is the acceleration measured from the accelerometer.
// x and y is switched from what we use, and the accelerometer does not support z axis.
// Balance point (526, 528) and 90 degree tilt (144) determined experimentally.
*x = ((double)(accelData.y - 526)) / 144;
*y = ((double)(accelData.x - 528)) / 144;
*z = 1.0;
}
nsDeviceMotionSystem::nsDeviceMotionSystem(){}
nsDeviceMotionSystem::~nsDeviceMotionSystem(){}
void
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
{
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
if (!self || !self->mSensor) {
NS_ERROR("no self or sensor");
return;
}
double x, y, z;
self->mSensor->GetValues(&x, &y, &z);
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, x, y, z);
}
void nsDeviceMotionSystem::Startup()
{
NS_ASSERTION(!mSensor, "mSensor should be null. Startup called twice?");
bool started = false;
mSensor = new ThinkPadSensor();
if (mSensor)
started = mSensor->Startup();
if (!started) {
mSensor = nsnull;
return;
}
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mUpdateTimer)
mUpdateTimer->InitWithFuncCallback(UpdateHandler,
this,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}
void nsDeviceMotionSystem::Shutdown()
{
if (mUpdateTimer) {
mUpdateTimer->Cancel();
mUpdateTimer = nsnull;
}
if (mSensor)
mSensor->Shutdown();
}

View File

@ -0,0 +1,66 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Doug Turner <dougt@dougt.org>
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDeviceMotionSystem_h
#define nsDeviceMotionSystem_h
#include "nsDeviceMotion.h"
#include "nsAutoPtr.h"
class Sensor
{
public:
virtual bool Startup() = 0;
virtual void Shutdown() = 0;
virtual void GetValues(double *x, double *y, double *z) = 0;
};
class nsDeviceMotionSystem : public nsDeviceMotion
{
public:
nsDeviceMotionSystem();
~nsDeviceMotionSystem();
void Startup();
void Shutdown();
nsCOMPtr<nsITimer> mUpdateTimer;
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
nsAutoPtr<Sensor> mSensor;
};
#endif

View File

@ -415,7 +415,7 @@ DisableSensorNotifications(SensorType aSensor) {
}
typedef mozilla::ObserverList<SensorData> SensorObserverList;
static SensorObserverList* gSensorObservers = NULL;
static SensorObserverList *gSensorObservers = NULL;
static SensorObserverList &
GetSensorObservers(SensorType sensor_type) {
@ -447,8 +447,6 @@ UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
observers.RemoveObserver(aObserver);
if(observers.Length() == 0) {
DisableSensorNotifications(aSensor);
delete [] gSensorObservers;
gSensorObservers = nsnull;
}
}

View File

@ -63,25 +63,10 @@ class SensorData;
typedef Observer<SensorData> ISensorObserver;
/**
* Enumeration of sensor accuracy types.
*/
enum SensorAccuracyType {
SENSOR_ACCURACY_UNKNOWN = -1,
SENSOR_ACCURACY_UNRELIABLE,
SENSOR_ACCURACY_LOW,
SENSOR_ACCURACY_MED,
SENSOR_ACCURACY_HIGH,
NUM_SENSOR_ACCURACY_TYPE
};
class SensorAccuracy;
typedef Observer<SensorAccuracy> ISensorAccuracyObserver;
}
}
#include "IPC/IPCMessageUtils.h"
namespace IPC {
@ -95,13 +80,6 @@ namespace IPC {
mozilla::hal::NUM_SENSOR_TYPE> {
};
template <>
struct ParamTraits<mozilla::hal::SensorAccuracyType>:
public EnumSerializer<mozilla::hal::SensorAccuracyType,
mozilla::hal::SENSOR_ACCURACY_UNKNOWN,
mozilla::hal::NUM_SENSOR_ACCURACY_TYPE> {
};
} // namespace IPC
#endif /* __HAL_SENSOR_H_ */

View File

@ -46,7 +46,6 @@ VPATH = \
$(srcdir)/sandbox \
$(srcdir)/linux \
$(srcdir)/windows \
$(srcdir)/cocoa \
$(NULL)
include $(DEPTH)/config/autoconf.mk
@ -100,14 +99,6 @@ CPPSRCS += \
WindowsBattery.cpp \
FallbackSensor.cpp \
$(NULL)
else ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
CPPSRCS += \
FallbackHal.cpp \
$(NULL)
CMMSRCS += \
CocoaSensor.mm \
smslib.mm \
$(NULL)
else
CPPSRCS += \
FallbackHal.cpp \

View File

@ -43,14 +43,32 @@ using namespace mozilla::hal;
namespace mozilla {
namespace hal_impl {
/**
* Translate ID of sensor type from Sensor service to Android.
*
* Must be consistent with the definition of sensor types in
* embedding/android/GeckoAppShell.java
*/
static int
MapSensorType(SensorType aSensorType) {
return (SENSOR_UNKNOWN <= aSensorType && aSensorType < NUM_SENSOR_TYPE) ?
aSensorType + 1 : -1;
}
void
EnableSensorNotifications(SensorType aSensor) {
AndroidBridge::Bridge()->EnableSensor(aSensor);
int androidSensor = MapSensorType(aSensor);
MOZ_ASSERT(androidSensor != -1);
AndroidBridge::Bridge()->EnableSensor(androidSensor);
}
void
DisableSensorNotifications(SensorType aSensor) {
AndroidBridge::Bridge()->DisableSensor(aSensor);
int androidSensor = MapSensorType(aSensor);
MOZ_ASSERT(androidSensor != -1);
AndroidBridge::Bridge()->DisableSensor(androidSensor);
}
} // hal_impl

View File

@ -1,61 +0,0 @@
/* 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 "nsITimer.h"
#include "smslib.h"
#define MEAN_GRAVITY 9.80665
#define DEFAULT_SENSOR_POLL 100
using namespace mozilla::hal;
namespace mozilla {
namespace hal_impl {
static nsITimer* sUpdateTimer = nsnull;
void UpdateHandler(nsITimer *aTimer, void *aClosure)
{
sms_acceleration accel;
smsGetData(&accel);
InfallibleTArray<float> values;
values.AppendElement(accel.x * MEAN_GRAVITY);
values.AppendElement(accel.y * MEAN_GRAVITY);
values.AppendElement(accel.z * MEAN_GRAVITY);
hal::SensorData sdata(hal::SENSOR_ACCELERATION,
PR_Now(),
values,
hal::SENSOR_ACCURACY_UNKNOWN);
hal::NotifySensorChange(sdata);
}
void
EnableSensorNotifications(SensorType aSensor) {
if (sUpdateTimer)
return;
smsStartup(nil, nil);
smsLoadCalibration();
CallCreateInstance("@mozilla.org/timer;1", &sUpdateTimer);
if (sUpdateTimer)
sUpdateTimer->InitWithFuncCallback(UpdateHandler,
NULL,
DEFAULT_SENSOR_POLL,
nsITimer::TYPE_REPEATING_SLACK);
}
void
DisableSensorNotifications(SensorType aSensor) {
if (sUpdateTimer) {
sUpdateTimer->Cancel();
NS_RELEASE(sUpdateTimer);
}
smsShutdown();
}
} // hal_impl
} // mozilla

View File

@ -18,13 +18,6 @@ using namespace android;
namespace mozilla {
#define DEFAULT_DEVICE_POLL_RATE 100000000 /*100ms*/
double radToDeg(double a) {
return a * (180.0 / M_PI);
}
static SensorType
HardwareSensorToHalSensor(int type)
{
@ -35,20 +28,11 @@ HardwareSensorToHalSensor(int type)
return SENSOR_ACCELERATION;
case SENSOR_TYPE_PROXIMITY:
return SENSOR_PROXIMITY;
case SENSOR_TYPE_GYROSCOPE:
return SENSOR_GYROSCOPE;
case SENSOR_TYPE_LINEAR_ACCELERATION:
return SENSOR_LINEAR_ACCELERATION;
default:
return SENSOR_UNKNOWN;
}
}
static SensorAccuracyType
HardwareStatusToHalAccuracy(int status) {
return static_cast<SensorAccuracyType>(status);
}
static int
HalSensorToHardwareSensor(SensorType type)
{
@ -59,73 +43,41 @@ HalSensorToHardwareSensor(SensorType type)
return SENSOR_TYPE_ACCELEROMETER;
case SENSOR_PROXIMITY:
return SENSOR_TYPE_PROXIMITY;
case SENSOR_GYROSCOPE:
return SENSOR_TYPE_GYROSCOPE;
case SENSOR_LINEAR_ACCELERATION:
return SENSOR_TYPE_LINEAR_ACCELERATION;
default:
return -1;
}
}
static int
SensorseventStatus(const sensors_event_t& data)
static bool
SensorseventToSensorData(const sensors_event_t& data, SensorData* aSensorData)
{
int type = data.type;
switch(type) {
case SENSOR_ORIENTATION:
return data.orientation.status;
case SENSOR_LINEAR_ACCELERATION:
case SENSOR_ACCELERATION:
return data.acceleration.status;
case SENSOR_GYROSCOPE:
return data.gyro.status;
}
aSensorData->sensor() = HardwareSensorToHalSensor(data.type);
if (aSensorData->sensor() == SENSOR_UNKNOWN)
return false;
return SENSOR_STATUS_UNRELIABLE;
aSensorData->timestamp() = data.timestamp;
aSensorData->values()[0] = data.data[0];
aSensorData->values()[1] = data.data[1];
aSensorData->values()[2] = data.data[2];
return true;
}
class SensorRunnable : public nsRunnable
static void
onSensorChanged(const sensors_event_t& data, SensorData* aSensorData)
{
public:
SensorRunnable(const sensors_event_t& data)
{
mSensorData.sensor() = HardwareSensorToHalSensor(data.type);
mSensorData.accuracy() = HardwareStatusToHalAccuracy(SensorseventStatus(data));
mSensorData.timestamp() = data.timestamp;
if (mSensorData.sensor() == SENSOR_GYROSCOPE) {
// libhardware returns gyro as rad. convert.
mSensorValues.AppendElement(radToDeg(data.data[0]));
mSensorValues.AppendElement(radToDeg(data.data[1]));
mSensorValues.AppendElement(radToDeg(data.data[2]));
} else {
mSensorValues.AppendElement(data.data[0]);
mSensorValues.AppendElement(data.data[1]);
mSensorValues.AppendElement(data.data[2]);
}
mSensorData.values() = mSensorValues;
}
~SensorRunnable() {}
NS_IMETHOD Run()
{
NotifySensorChange(mSensorData);
return NS_OK;
}
private:
SensorData mSensorData;
InfallibleTArray<float> mSensorValues;
};
DebugOnly<bool> convertedData = SensorseventToSensorData(data, aSensorData);
MOZ_ASSERT(convertedData);
NotifySensorChange(*aSensorData);
}
namespace hal_impl {
static pthread_t sThread;
static bool sInitialized = false;
static bool sContinue = true;
static int sActivatedSensors = 0;
static bool sInitialized;
static bool sContinue;
static int sActivatedSensors;
static SensorData sSensordata[NUM_SENSOR_TYPE];
static nsCOMPtr<nsIThread> sSwitchThread;
static void*
@ -138,16 +90,12 @@ UpdateSensorData(void* /*unused*/)
while (sContinue) {
count = device.poll(buffer, numEventMax);
if (count < 0) {
continue;
}
for (int i=0; i<count; i++) {
if (SensorseventStatus(buffer[i]) == SENSOR_STATUS_UNRELIABLE) {
continue;
}
NS_DispatchToMainThread(new SensorRunnable(buffer[i]));
onSensorChanged(buffer[i], &sSensordata[HardwareSensorToHalSensor(buffer[i].type)]);
}
}
@ -157,10 +105,10 @@ UpdateSensorData(void* /*unused*/)
static void
InitializeResources()
{
sInitialized = true;
sContinue = true;
pthread_create(&sThread, NULL, &UpdateSensorData, NULL);
NS_NewThread(getter_AddRefs(sSwitchThread));
sInitialized = true;
sContinue = true;
}
static void
@ -183,7 +131,6 @@ class SensorInfo {
void Switch() {
SensorDevice& device = SensorDevice::getInstance();
device.activate((void*)threadId, sensor.handle, activate);
device.setDelay((void*)threadId, sensor.handle, DEFAULT_DEVICE_POLL_RATE);
}
protected:
@ -238,5 +185,10 @@ DisableSensorNotifications(SensorType aSensor)
}
}
void
GetCurrentSensorDataInformation(SensorType aSensor, SensorData* aSensorData) {
*aSensorData = sSensordata[aSensor];
}
} // hal_impl
} // mozilla

View File

@ -49,7 +49,6 @@ using mozilla::hal::FlashMode;
using mozilla::hal::LightType;
using mozilla::hal::LightMode;
using mozilla::hal::SensorType;
using mozilla::hal::SensorAccuracyType;
using mozilla::hal::WakeLockControl;
using mozilla::dom::ScreenOrientation;
@ -75,7 +74,6 @@ namespace hal {
SensorType sensor;
PRTime timestamp;
float[] values;
SensorAccuracyType accuracy;
};
struct NetworkInformation {

View File

@ -156,11 +156,9 @@ using mozilla::dom::gonk::AudioManager;
#include "nsSystemPrincipal.h"
#include "nsNullPrincipal.h"
#include "nsNetCID.h"
#ifndef MOZ_WIDGET_GONK
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_PLATFORM_MAEMO)
#include "nsHapticFeedback.h"
#endif
#endif
#include "nsParserUtils.h"
#define NS_EDITORCOMMANDTABLE_CID \
@ -243,7 +241,14 @@ static void Shutdown();
#endif
#include "nsGeolocation.h"
#include "nsDeviceMotion.h"
#ifndef MOZ_WIDGET_GONK
#if defined(XP_UNIX) || \
defined(_WINDOWS) || \
defined(machintosh) || \
defined(android)
#include "nsDeviceMotionSystem.h"
#endif
#endif
#include "nsCSPService.h"
#include "nsISmsService.h"
#include "nsISmsDatabaseService.h"
@ -291,10 +296,13 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(SystemWorkerManager,
#ifdef MOZ_WIDGET_GONK
NS_GENERIC_FACTORY_CONSTRUCTOR(AudioManager)
#else
#if defined(XP_UNIX) || \
defined(_WINDOWS) || \
defined(machintosh) || \
defined(android)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceMotionSystem)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceMotion)
#ifndef MOZ_WIDGET_GONK
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback)
#endif
@ -785,9 +793,14 @@ NS_DEFINE_NAMED_CID(NS_NULLPRINCIPAL_CID);
NS_DEFINE_NAMED_CID(NS_SECURITYNAMESET_CID);
NS_DEFINE_NAMED_CID(THIRDPARTYUTIL_CID);
NS_DEFINE_NAMED_CID(NS_STRUCTUREDCLONECONTAINER_CID);
NS_DEFINE_NAMED_CID(NS_DEVICE_MOTION_CID);
#ifndef MOZ_WIDGET_GONK
#if defined(XP_UNIX) || \
defined(_WINDOWS) || \
defined(machintosh) || \
defined(android)
NS_DEFINE_NAMED_CID(NS_DEVICE_MOTION_CID);
#endif
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
NS_DEFINE_NAMED_CID(NS_HAPTICFEEDBACK_CID);
#endif
@ -1054,8 +1067,13 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_SYSTEMPRINCIPAL_CID, false, NULL, nsSystemPrincipalConstructor },
{ &kNS_NULLPRINCIPAL_CID, false, NULL, nsNullPrincipalConstructor },
{ &kNS_SECURITYNAMESET_CID, false, NULL, nsSecurityNameSetConstructor },
{ &kNS_DEVICE_MOTION_CID, false, NULL, nsDeviceMotionConstructor },
#ifndef MOZ_WIDGET_GONK
#if defined(XP_UNIX) || \
defined(_WINDOWS) || \
defined(machintosh) || \
defined(android)
{ &kNS_DEVICE_MOTION_CID, false, NULL, nsDeviceMotionSystemConstructor },
#endif
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
{ &kNS_HAPTICFEEDBACK_CID, false, NULL, nsHapticFeedbackConstructor },
#endif
@ -1188,8 +1206,13 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ NS_SYSTEMPRINCIPAL_CONTRACTID, &kNS_SYSTEMPRINCIPAL_CID },
{ NS_NULLPRINCIPAL_CONTRACTID, &kNS_NULLPRINCIPAL_CID },
{ NS_SECURITYNAMESET_CONTRACTID, &kNS_SECURITYNAMESET_CID },
{ NS_DEVICE_MOTION_CONTRACTID, &kNS_DEVICE_MOTION_CID },
#ifndef MOZ_WIDGET_GONK
#if defined(XP_UNIX) || \
defined(_WINDOWS) || \
defined(machintosh) || \
defined(android)
{ NS_DEVICE_MOTION_CONTRACTID, &kNS_DEVICE_MOTION_CID },
#endif
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
{ "@mozilla.org/widget/hapticfeedback;1", &kNS_HAPTICFEEDBACK_CID },
#endif

View File

@ -2790,10 +2790,15 @@ abstract public class GeckoApp
public LayerController getLayerController() { return mLayerController; }
// accelerometer
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
Log.w(LOGTAG, "onAccuracyChanged "+accuracy);
GeckoAppShell.sendEventToGecko(GeckoEvent.createSensorAccuracyEvent(accuracy));
}
public void onSensorChanged(SensorEvent event)
{
Log.w(LOGTAG, "onSensorChanged "+event);
GeckoAppShell.sendEventToGecko(GeckoEvent.createSensorEvent(event));
}
@ -2801,6 +2806,7 @@ abstract public class GeckoApp
public void onLocationChanged(Location location)
{
Log.w(LOGTAG, "onLocationChanged "+location);
GeckoAppShell.sendEventToGecko(GeckoEvent.createLocationEvent(location));
}

View File

@ -585,7 +585,6 @@ public class GeckoAppShell
switch(aSensortype) {
case GeckoHalDefines.SENSOR_ORIENTATION:
Log.i(LOGTAG, "Enabling SENSOR_ORIENTATION");
if(gOrientationSensor == null)
gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
if (gOrientationSensor != null)
@ -593,7 +592,6 @@ public class GeckoAppShell
break;
case GeckoHalDefines.SENSOR_ACCELERATION:
Log.i(LOGTAG, "Enabling SENSOR_ACCELERATION");
if(gAccelerometerSensor == null)
gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if (gAccelerometerSensor != null)
@ -601,7 +599,6 @@ public class GeckoAppShell
break;
case GeckoHalDefines.SENSOR_PROXIMITY:
Log.i(LOGTAG, "Enabling SENSOR_PROXIMITY");
if(gProximitySensor == null)
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
if (gProximitySensor != null)
@ -609,22 +606,19 @@ public class GeckoAppShell
break;
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
Log.i(LOGTAG, "Enabling SENSOR_LINEAR_ACCELERATION");
if(gLinearAccelerometerSensor == null)
gLinearAccelerometerSensor = sm.getDefaultSensor(10 /* API Level 9 - TYPE_LINEAR_ACCELERATION */);
gLinearAccelerometerSensor = sm.getDefaultSensor(10);
if (gLinearAccelerometerSensor != null)
sm.registerListener(GeckoApp.mAppContext, gLinearAccelerometerSensor, sDefaultSensorHint);
break;
case GeckoHalDefines.SENSOR_GYROSCOPE:
Log.i(LOGTAG, "Enabling SENSOR_GYROSCOPE");
if(gGyroscopeSensor == null)
gGyroscopeSensor = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
if (gGyroscopeSensor != null)
sm.registerListener(GeckoApp.mAppContext, gGyroscopeSensor, sDefaultSensorHint);
break;
default:
Log.e(LOGTAG, "Error! SENSOR type used " + aSensortype);
}
}
@ -634,36 +628,29 @@ public class GeckoAppShell
switch (aSensortype) {
case GeckoHalDefines.SENSOR_ORIENTATION:
Log.i(LOGTAG, "Disabling SENSOR_ORIENTATION");
if (gOrientationSensor != null)
sm.unregisterListener(GeckoApp.mAppContext, gOrientationSensor);
break;
case GeckoHalDefines.SENSOR_ACCELERATION:
Log.i(LOGTAG, "Disabling SENSOR_ACCELERATION");
if (gAccelerometerSensor != null)
sm.unregisterListener(GeckoApp.mAppContext, gAccelerometerSensor);
break;
case GeckoHalDefines.SENSOR_PROXIMITY:
Log.i(LOGTAG, "Disabling SENSOR_PROXIMITY");
if (gProximitySensor != null)
sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor);
break;
case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION:
Log.i(LOGTAG, "Disabling SENSOR_LINEAR_ACCELERATION");
if (gLinearAccelerometerSensor != null)
sm.unregisterListener(GeckoApp.mAppContext, gLinearAccelerometerSensor);
break;
case GeckoHalDefines.SENSOR_GYROSCOPE:
Log.i(LOGTAG, "Disabling SENSOR_GYROSCOPE");
if (gGyroscopeSensor != null)
sm.unregisterListener(GeckoApp.mAppContext, gGyroscopeSensor);
break;
default:
Log.e(LOGTAG, "Error! SENSOR type used " + aSensortype);
}
}

View File

@ -71,26 +71,28 @@ public class GeckoEvent {
private static final int KEY_EVENT = 1;
private static final int MOTION_EVENT = 2;
private static final int SENSOR_EVENT = 3;
private static final int LOCATION_EVENT = 4;
private static final int IME_EVENT = 5;
private static final int DRAW = 6;
private static final int SIZE_CHANGED = 7;
private static final int ACTIVITY_STOPPING = 8;
private static final int ACTIVITY_PAUSING = 9;
private static final int ACTIVITY_SHUTDOWN = 10;
private static final int LOAD_URI = 11;
private static final int SURFACE_CREATED = 12;
private static final int SURFACE_DESTROYED = 13;
private static final int GECKO_EVENT_SYNC = 14;
private static final int FORCED_RESIZE = 15;
private static final int ACTIVITY_START = 16;
private static final int BROADCAST = 17;
private static final int VIEWPORT = 18;
private static final int VISITED = 19;
private static final int NETWORK_CHANGED = 20;
private static final int ACTIVITY_RESUMING = 21;
private static final int SCREENSHOT = 22;
private static final int SCREENORIENTATION_CHANGED = 23;
private static final int UNUSED1_EVENT = 4;
private static final int LOCATION_EVENT = 5;
private static final int IME_EVENT = 6;
private static final int DRAW = 7;
private static final int SIZE_CHANGED = 8;
private static final int ACTIVITY_STOPPING = 9;
private static final int ACTIVITY_PAUSING = 10;
private static final int ACTIVITY_SHUTDOWN = 11;
private static final int LOAD_URI = 12;
private static final int SURFACE_CREATED = 13;
private static final int SURFACE_DESTROYED = 14;
private static final int GECKO_EVENT_SYNC = 15;
private static final int ACTIVITY_START = 17;
private static final int BROADCAST = 19;
private static final int VIEWPORT = 20;
private static final int VISITED = 21;
private static final int NETWORK_CHANGED = 22;
private static final int PROXIMITY_EVENT = 23;
private static final int ACTIVITY_RESUMING = 24;
private static final int SCREENSHOT = 25;
private static final int SENSOR_ACCURACY = 26;
private static final int SCREENORIENTATION_CHANGED = 27;
public static final int IME_COMPOSITION_END = 0;
public static final int IME_COMPOSITION_BEGIN = 1;
@ -122,6 +124,7 @@ public class GeckoEvent {
public Point[] mPointRadii;
public Rect mRect;
public double mX, mY, mZ;
public double mDistance;
public int mMetaState, mFlags;
public int mKeyCode, mUnicodeChar;
@ -280,20 +283,6 @@ public class GeckoEvent {
}
}
private static int HalSensorAccuracyFor(int androidAccuracy) {
switch (androidAccuracy) {
case SensorManager.SENSOR_STATUS_UNRELIABLE:
return GeckoHalDefines.SENSOR_ACCURACY_UNRELIABLE;
case SensorManager.SENSOR_STATUS_ACCURACY_LOW:
return GeckoHalDefines.SENSOR_ACCURACY_LOW;
case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM:
return GeckoHalDefines.SENSOR_ACCURACY_MED;
case SensorManager.SENSOR_STATUS_ACCURACY_HIGH:
return GeckoHalDefines.SENSOR_ACCURACY_HIGH;
}
return GeckoHalDefines.SENSOR_ACCURACY_UNKNOWN;
}
public static GeckoEvent createSensorEvent(SensorEvent s) {
int sensor_type = s.sensor.getType();
GeckoEvent event = null;
@ -303,7 +292,6 @@ public class GeckoEvent {
case Sensor.TYPE_ACCELEROMETER:
event = new GeckoEvent(SENSOR_EVENT);
event.mFlags = GeckoHalDefines.SENSOR_ACCELERATION;
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
event.mX = s.values[0];
event.mY = s.values[1];
event.mZ = s.values[2];
@ -312,7 +300,6 @@ public class GeckoEvent {
case 10 /* Requires API Level 9, so just use the raw value - Sensor.TYPE_LINEAR_ACCELEROMETER*/ :
event = new GeckoEvent(SENSOR_EVENT);
event.mFlags = GeckoHalDefines.SENSOR_LINEAR_ACCELERATION;
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
event.mX = s.values[0];
event.mY = s.values[1];
event.mZ = s.values[2];
@ -321,7 +308,6 @@ public class GeckoEvent {
case Sensor.TYPE_ORIENTATION:
event = new GeckoEvent(SENSOR_EVENT);
event.mFlags = GeckoHalDefines.SENSOR_ORIENTATION;
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
event.mX = s.values[0];
event.mY = s.values[1];
event.mZ = s.values[2];
@ -330,16 +316,16 @@ public class GeckoEvent {
case Sensor.TYPE_GYROSCOPE:
event = new GeckoEvent(SENSOR_EVENT);
event.mFlags = GeckoHalDefines.SENSOR_GYROSCOPE;
event.mMetaState = HalSensorAccuracyFor(s.accuracy);
event.mX = Math.toDegrees(s.values[0]);
event.mY = Math.toDegrees(s.values[1]);
event.mZ = Math.toDegrees(s.values[2]);
break;
case Sensor.TYPE_PROXIMITY:
event = new GeckoEvent(SENSOR_EVENT);
event.mFlags = GeckoHalDefines.SENSOR_PROXIMITY;
event.mX = s.values[0];
// bug 734854 - maybe we can get rid of this event. is
// values[1] and values[2] valid?
event = new GeckoEvent(PROXIMITY_EVENT);
event.mDistance = s.values[0];
break;
}
return event;
@ -455,6 +441,12 @@ public class GeckoEvent {
return event;
}
public static GeckoEvent createSensorAccuracyEvent(int accuracy) {
GeckoEvent event = new GeckoEvent(SENSOR_ACCURACY);
event.mFlags = accuracy;
return event;
}
public static GeckoEvent createScreenOrientationEvent(short aScreenOrientation) {
GeckoEvent event = new GeckoEvent(SCREENORIENTATION_CHANGED);
event.mScreenOrientation = aScreenOrientation;

View File

@ -46,10 +46,4 @@ public class GeckoHalDefines
public static final int SENSOR_PROXIMITY = 2;
public static final int SENSOR_LINEAR_ACCELERATION = 3;
public static final int SENSOR_GYROSCOPE = 4;
public static final int SENSOR_ACCURACY_UNKNOWN = -1;
public static final int SENSOR_ACCURACY_UNRELIABLE = 0;
public static final int SENSOR_ACCURACY_LOW = 1;
public static final int SENSOR_ACCURACY_MED = 2;
public static final int SENSOR_ACCURACY_HIGH = 3;
};

View File

@ -318,6 +318,28 @@ AndroidBridge::AcknowledgeEventSync()
env->CallStaticVoidMethod(mGeckoAppShellClass, jAcknowledgeEventSync);
}
void
AndroidBridge::EnableDeviceMotion(bool aEnable)
{
ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion");
// bug 734855 - we probably can make this finer grain based on
// the DOM APIs that are being invoked.
if (aEnable) {
EnableSensor(hal::SENSOR_ORIENTATION);
EnableSensor(hal::SENSOR_ACCELERATION);
EnableSensor(hal::SENSOR_LINEAR_ACCELERATION);
EnableSensor(hal::SENSOR_GYROSCOPE);
}
else {
DisableSensor(hal::SENSOR_ORIENTATION);
DisableSensor(hal::SENSOR_ACCELERATION);
DisableSensor(hal::SENSOR_LINEAR_ACCELERATION);
DisableSensor(hal::SENSOR_GYROSCOPE);
}
}
void
AndroidBridge::EnableLocation(bool aEnable)
{

View File

@ -176,6 +176,8 @@ public:
void AcknowledgeEventSync();
void EnableDeviceMotion(bool aEnable);
void EnableLocation(bool aEnable);
void EnableSensor(int aSensorType);

View File

@ -165,6 +165,7 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jXField = getField("mX", "D");
jYField = getField("mY", "D");
jZField = getField("mZ", "D");
jDistanceField = getField("mDistance", "D");
jRectField = getField("mRect", "Landroid/graphics/Rect;");
jCharactersField = getField("mCharacters", "Ljava/lang/String;");
@ -474,7 +475,6 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
mY = jenv->GetDoubleField(jobj, jYField);
mZ = jenv->GetDoubleField(jobj, jZField);
mFlags = jenv->GetIntField(jobj, jFlagsField);
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
break;
case LOCATION_EVENT: {
@ -506,6 +506,12 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
break;
}
case PROXIMITY_EVENT: {
mDistance = jenv->GetDoubleField(jobj, jDistanceField);
break;
}
case SENSOR_ACCURACY:
case ACTIVITY_STOPPING:
case ACTIVITY_START:
case ACTIVITY_PAUSING:
@ -528,7 +534,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
break;
}
#ifdef DEBUG_ANDROID_EVENTS
#ifndef DEBUG_ANDROID_EVENTS
ALOG("AndroidGeckoEvent: %p : %d", (void*)jobj, mType);
#endif
}

View File

@ -466,6 +466,7 @@ public:
double X() { return mX; }
double Y() { return mY; }
double Z() { return mZ; }
double Distance() { return mDistance; }
const nsIntRect& Rect() { return mRect; }
nsAString& Characters() { return mCharacters; }
nsAString& CharactersExtra() { return mCharactersExtra; }
@ -567,26 +568,29 @@ public:
KEY_EVENT = 1,
MOTION_EVENT = 2,
SENSOR_EVENT = 3,
LOCATION_EVENT = 4,
IME_EVENT = 5,
DRAW = 6,
SIZE_CHANGED = 7,
ACTIVITY_STOPPING = 8,
ACTIVITY_PAUSING = 9,
ACTIVITY_SHUTDOWN = 10,
LOAD_URI = 11,
SURFACE_CREATED = 12,
SURFACE_DESTROYED = 13,
GECKO_EVENT_SYNC = 14,
FORCED_RESIZE = 15,
ACTIVITY_START = 16,
BROADCAST = 17,
VIEWPORT = 18,
VISITED = 19,
NETWORK_CHANGED = 20,
ACTIVITY_RESUMING = 21,
SCREENSHOT = 22,
SCREENORIENTATION_CHANGED = 23,
UNUSED1_EVENT = 4,
LOCATION_EVENT = 5,
IME_EVENT = 6,
DRAW = 7,
SIZE_CHANGED = 8,
ACTIVITY_STOPPING = 9,
ACTIVITY_PAUSING = 10,
ACTIVITY_SHUTDOWN = 11,
LOAD_URI = 12,
SURFACE_CREATED = 13,
SURFACE_DESTROYED = 14,
GECKO_EVENT_SYNC = 15,
FORCED_RESIZE = 16,
ACTIVITY_START = 17,
BROADCAST = 19,
VIEWPORT = 20,
VISITED = 21,
NETWORK_CHANGED = 22,
PROXIMITY_EVENT = 23,
ACTIVITY_RESUMING = 24,
SCREENSHOT = 25,
SENSOR_ACCURACY = 26,
SCREENORIENTATION_CHANGED = 27,
dummy_java_enum_list_end
};

View File

@ -56,6 +56,7 @@
#include "prenv.h"
#include "AndroidBridge.h"
#include "nsDeviceMotionSystem.h"
#include <android/log.h>
#include <pthread.h>
#include <wchar.h>
@ -83,6 +84,7 @@ using namespace mozilla;
PRLogModuleInfo *gWidgetLog = nsnull;
#endif
nsDeviceMotionSystem *gDeviceMotionSystem = nsnull;
nsIGeolocationUpdate *gLocationCallback = nsnull;
nsAutoPtr<mozilla::AndroidGeckoEvent> gLastSizeChange;
@ -331,42 +333,46 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
NativeEventCallback();
break;
case AndroidGeckoEvent::SENSOR_ACCURACY:
if (curEvent->Flags() == 0)
gDeviceMotionSystem->NeedsCalibration();
break;
case AndroidGeckoEvent::SENSOR_EVENT:
{
mPendingSensorEvents = false;
InfallibleTArray<float> values;
mozilla::hal::SensorType type = (mozilla::hal::SensorType) curEvent->Flags();
switch (type) {
case hal::SENSOR_ORIENTATION:
values.AppendElement(curEvent->X());
values.AppendElement(-curEvent->Y());
values.AppendElement(-curEvent->Z());
switch (curEvent->Flags()) {
case hal::SENSOR_ORIENTATION:
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
curEvent->X(),
-curEvent->Y(),
-curEvent->Z());
break;
case hal::SENSOR_ACCELERATION:
case hal::SENSOR_LINEAR_ACCELERATION:
case hal::SENSOR_GYROSCOPE:
values.AppendElement(-curEvent->X());
values.AppendElement(curEvent->Y());
values.AppendElement(curEvent->Z());
case hal::SENSOR_ACCELERATION:
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
-curEvent->X(),
curEvent->Y(),
curEvent->Z());
break;
case hal::SENSOR_PROXIMITY:
values.AppendElement(curEvent->X());
case hal::SENSOR_LINEAR_ACCELERATION:
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION,
-curEvent->X(),
curEvent->Y(),
curEvent->Z());
break;
case hal::SENSOR_GYROSCOPE:
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_GYROSCOPE,
-curEvent->X(),
curEvent->Y(),
curEvent->Z());
break;
default:
__android_log_print(ANDROID_LOG_ERROR,
"Gecko", "### SENSOR_EVENT fired, but type wasn't known %d",
type);
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### SENSOR_EVENT fired, but type wasn't known %d", curEvent->Flags());
}
const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState();
hal::SensorData sdata(type, PR_Now(), values, accuracy);
hal::NotifySensorChange(sdata);
}
break;
break;
case AndroidGeckoEvent::LOCATION_EVENT: {
if (!gLocationCallback)
@ -380,6 +386,15 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
break;
}
case AndroidGeckoEvent::PROXIMITY_EVENT: {
InfallibleTArray<float> values;
values.AppendElement(curEvent->Distance());
hal::SensorData sdata(hal::SENSOR_PROXIMITY, PR_Now(), values);
hal::NotifySensorChange(sdata);
break;
}
case AndroidGeckoEvent::ACTIVITY_STOPPING: {
if (curEvent->Flags() > 0)
break;

View File

@ -41,12 +41,10 @@ interface nsIDOMWindow;
[scriptable, uuid(1B406E32-CF42-471E-A470-6FD600BF4C7B)]
interface nsIDeviceMotionData : nsISupports
{
// Keep in sync with hal/HalSensor.h
const unsigned long TYPE_ORIENTATION = 0;
const unsigned long TYPE_ACCELERATION = 1;
const unsigned long TYPE_PROXIMITY = 2;
const unsigned long TYPE_LINEAR_ACCELERATION = 3;
const unsigned long TYPE_GYROSCOPE = 4;
const unsigned long TYPE_ACCELERATION = 0;
const unsigned long TYPE_ORIENTATION = 1;
const unsigned long TYPE_LINEAR_ACCELERATION = 2;
const unsigned long TYPE_GYROSCOPE = 3;
readonly attribute unsigned long type;
@ -74,3 +72,14 @@ interface nsIDeviceMotion : nsISupports
[noscript] void removeWindowListener(in nsIDOMWindow aWindow);
};
/* for use by IPC system to notify non-chrome processes of
* device motion events
*/
[uuid(C12C0157-DCFF-41B5-83F3-89179BF6CA4E)]
interface nsIDeviceMotionUpdate : nsIDeviceMotion
{
/* must be called on the main thread or else */
void deviceMotionChanged(in unsigned long type, in double x, in double y, in double z);
void needsCalibration();
};