From 63408865d2c5b70d55eeded1ffd1f133ab4baea0 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Wed, 2 May 2012 09:43:45 -0700 Subject: [PATCH] Bug 738131 - implement device proximity. r=smaug * * * Bug 738131 - implement device proximity. gonk implementation. r=mwu --- content/base/src/nsGkAtomList.h | 3 +- content/events/public/nsEventNameList.h | 4 + content/events/public/nsIPrivateDOMEvent.h | 2 + content/events/src/Makefile.in | 3 +- .../events/src/nsDOMDeviceProximityEvent.cpp | 81 +++++++++++++++++++ .../events/src/nsDOMDeviceProximityEvent.h | 38 +++++++++ content/events/src/nsDOMEvent.cpp | 5 +- content/events/src/nsDOMEvent.h | 3 +- content/events/src/nsEventListenerManager.cpp | 8 ++ content/events/test/test_eventctors.html | 11 +++ dom/base/nsDOMClassInfo.cpp | 12 +++ dom/base/nsDOMClassInfoClasses.h | 1 + dom/interfaces/base/nsIDOMWindow.idl | 3 +- dom/interfaces/events/Makefile.in | 3 +- .../events/nsIDOMDeviceProximityEvent.idl | 27 +++++++ dom/system/nsDeviceSensors.cpp | 27 +++++++ dom/system/nsDeviceSensors.h | 8 +- hal/gonk/GonkSensor.cpp | 12 +++ js/xpconnect/src/dictionary_helper_gen.conf | 3 +- mobile/android/base/GeckoAppShell.java | 2 +- mobile/android/base/GeckoEvent.java | 3 + widget/nsGUIEvent.h | 1 + 22 files changed, 251 insertions(+), 9 deletions(-) create mode 100644 content/events/src/nsDOMDeviceProximityEvent.cpp create mode 100644 content/events/src/nsDOMDeviceProximityEvent.h create mode 100644 dom/interfaces/events/nsIDOMDeviceProximityEvent.idl diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 99415c2d242..81c628a881d 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -1711,8 +1711,9 @@ GK_ATOM(onMozTouchMove, "onMozTouchMove") GK_ATOM(onMozTouchUp, "onMozTouchUp") // orientation support -GK_ATOM(ondeviceorientation, "ondeviceorientation") GK_ATOM(ondevicemotion, "ondevicemotion") +GK_ATOM(ondeviceorientation, "ondeviceorientation") +GK_ATOM(ondeviceproximity, "ondeviceproximity") //--------------------------------------------------------------------------- // Special atoms diff --git a/content/events/public/nsEventNameList.h b/content/events/public/nsEventNameList.h index 505ec7c99f4..ed96bb2ac0c 100644 --- a/content/events/public/nsEventNameList.h +++ b/content/events/public/nsEventNameList.h @@ -455,6 +455,10 @@ WINDOW_ONLY_EVENT(deviceorientation, NS_DEVICE_ORIENTATION, EventNameType_None, NS_EVENT) +WINDOW_ONLY_EVENT(deviceproximity, + NS_DEVICE_PROXIMITY, + EventNameType_None, + NS_EVENT) TOUCH_EVENT(touchstart, NS_TOUCH_START, diff --git a/content/events/public/nsIPrivateDOMEvent.h b/content/events/public/nsIPrivateDOMEvent.h index cfabc915bcb..0737586865f 100644 --- a/content/events/public/nsIPrivateDOMEvent.h +++ b/content/events/public/nsIPrivateDOMEvent.h @@ -92,6 +92,8 @@ NS_NewDOMMutationEvent(nsIDOMEvent** aResult NS_OUTPARAM, nsPresContext* aPresCo nsresult NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent); nsresult +NS_NewDOMDeviceProximityEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent *aEvent); +nsresult NS_NewDOMDeviceOrientationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent); nsresult NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent); diff --git a/content/events/src/Makefile.in b/content/events/src/Makefile.in index eaf50509f93..830e6576187 100644 --- a/content/events/src/Makefile.in +++ b/content/events/src/Makefile.in @@ -51,7 +51,7 @@ EXPORTS = \ nsEventListenerManager.h \ nsDOMEventTargetHelper.h \ $(NULL) - + CPPSRCS = \ nsEventListenerManager.cpp \ nsEventStateManager.cpp \ @@ -65,6 +65,7 @@ CPPSRCS = \ nsDOMDragEvent.cpp \ nsDOMMutationEvent.cpp \ nsDOMPopupBlockedEvent.cpp \ + nsDOMDeviceProximityEvent.cpp \ nsDOMDeviceOrientationEvent.cpp \ nsDOMDeviceMotionEvent.cpp \ nsDOMBeforeUnloadEvent.cpp \ diff --git a/content/events/src/nsDOMDeviceProximityEvent.cpp b/content/events/src/nsDOMDeviceProximityEvent.cpp new file mode 100644 index 00000000000..5e39adc210e --- /dev/null +++ b/content/events/src/nsDOMDeviceProximityEvent.cpp @@ -0,0 +1,81 @@ +/* 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 "nsDOMDeviceProximityEvent.h" +#include "nsContentUtils.h" +#include "DictionaryHelpers.h" + +NS_IMPL_ADDREF_INHERITED(nsDOMDeviceProximityEvent, nsDOMEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMDeviceProximityEvent, nsDOMEvent) + +DOMCI_DATA(DeviceProximityEvent, nsDOMDeviceProximityEvent) + +NS_INTERFACE_MAP_BEGIN(nsDOMDeviceProximityEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceProximityEvent) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceProximityEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent) + +NS_IMETHODIMP +nsDOMDeviceProximityEvent::InitDeviceProximityEvent(const nsAString & aEventTypeArg, + bool aCanBubbleArg, + bool aCancelableArg, + double aValue, + double aMin, + double aMax) +{ + nsresult rv = nsDOMEvent::InitEvent(aEventTypeArg, aCanBubbleArg, aCancelableArg); + NS_ENSURE_SUCCESS(rv, rv); + + mValue = aValue; + mMin = aMin; + mMax = aMax; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDeviceProximityEvent::GetValue(double *aValue) +{ + NS_ENSURE_ARG_POINTER(aValue); + + *aValue = mValue; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDeviceProximityEvent::GetMin(double *aMin) +{ + NS_ENSURE_ARG_POINTER(aMin); + + *aMin = mMin; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDeviceProximityEvent::GetMax(double *aMax) +{ + NS_ENSURE_ARG_POINTER(aMax); + + *aMax = mMax; + return NS_OK; +} + +nsresult +nsDOMDeviceProximityEvent::InitFromCtor(const nsAString& aType, + JSContext* aCx, jsval* aVal) +{ + mozilla::dom::DeviceProximityEventInit d; + nsresult rv = d.Init(aCx, aVal); + NS_ENSURE_SUCCESS(rv, rv); + return InitDeviceProximityEvent(aType, d.bubbles, d.cancelable, d.value, d.min, d.max); +} + +nsresult +NS_NewDOMDeviceProximityEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsEvent *aEvent) +{ + NS_ENSURE_ARG_POINTER(aInstancePtrResult); + nsDOMDeviceProximityEvent* it = new nsDOMDeviceProximityEvent(aPresContext, aEvent); + return CallQueryInterface(it, aInstancePtrResult); +} diff --git a/content/events/src/nsDOMDeviceProximityEvent.h b/content/events/src/nsDOMDeviceProximityEvent.h new file mode 100644 index 00000000000..cdae784a904 --- /dev/null +++ b/content/events/src/nsDOMDeviceProximityEvent.h @@ -0,0 +1,38 @@ +/* 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 nsDOMDeviceProximityEvent_h__ +#define nsDOMDeviceProximityEvent_h__ + +#include "nsIDOMDeviceProximityEvent.h" +#include "nsDOMEvent.h" + +class nsDOMDeviceProximityEvent + : public nsDOMEvent + , public nsIDOMDeviceProximityEvent +{ +public: + + nsDOMDeviceProximityEvent(nsPresContext* aPresContext, nsEvent* aEvent) + : nsDOMEvent(aPresContext, aEvent), + mValue(-1), + mMin(0), + mMax(0) {} + + NS_DECL_ISUPPORTS_INHERITED + + // Forward to nsDOMEvent + NS_FORWARD_TO_NSDOMEVENT + + // nsIDOMDeviceProximityEvent Interface + NS_DECL_NSIDOMDEVICEPROXIMITYEVENT + + virtual nsresult InitFromCtor(const nsAString& aType, + JSContext* aCx, + jsval* aVal); +protected: + double mValue, mMin, mMax; +}; + +#endif diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 36ca6bc74b6..9a6ddafac39 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -126,7 +126,8 @@ static const char* const sEventNames[] = { "animationend", "animationiteration", "devicemotion", - "deviceorientation" + "deviceorientation", + "deviceproximity" }; static char *sPopupAllowedEvents; @@ -1553,6 +1554,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return sEventNames[eDOMEvents_devicemotion]; case NS_DEVICE_ORIENTATION: return sEventNames[eDOMEvents_deviceorientation]; + case NS_DEVICE_PROXIMITY: + return sEventNames[eDOMEvents_deviceproximity]; case NS_FULLSCREENCHANGE: return sEventNames[eDOMEvents_mozfullscreenchange]; case NS_FULLSCREENERROR: diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 4fe206588c2..bb00d7f7d3c 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -209,7 +209,8 @@ public: eDOMEvents_animationend, eDOMEvents_animationiteration, eDOMEvents_devicemotion, - eDOMEvents_deviceorientation + eDOMEvents_deviceorientation, + eDOMEvents_deviceproximity }; nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent); diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index f4048c8fb21..dd3312a2994 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -290,6 +290,8 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, } } else if (aTypeAtom == nsGkAtoms::ondeviceorientation) { EnableDevice(NS_DEVICE_ORIENTATION); + } else if (aTypeAtom == nsGkAtoms::ondeviceproximity) { + EnableDevice(NS_DEVICE_PROXIMITY); } else if (aTypeAtom == nsGkAtoms::ondevicemotion) { EnableDevice(NS_DEVICE_MOTION); } else if ((aType >= NS_MOZTOUCH_DOWN && aType <= NS_MOZTOUCH_UP) || @@ -346,6 +348,9 @@ nsEventListenerManager::EnableDevice(PRUint32 aType) case NS_DEVICE_ORIENTATION: window->EnableDeviceSensor(SENSOR_ORIENTATION); break; + case NS_DEVICE_PROXIMITY: + window->EnableDeviceSensor(SENSOR_PROXIMITY); + break; case NS_DEVICE_MOTION: window->EnableDeviceSensor(SENSOR_ACCELERATION); window->EnableDeviceSensor(SENSOR_LINEAR_ACCELERATION); @@ -376,6 +381,9 @@ nsEventListenerManager::DisableDevice(PRUint32 aType) window->DisableDeviceSensor(SENSOR_LINEAR_ACCELERATION); window->DisableDeviceSensor(SENSOR_GYROSCOPE); break; + case NS_DEVICE_PROXIMITY: + window->DisableDeviceSensor(SENSOR_PROXIMITY); + break; default: NS_WARNING("Disabling an unknown device sensor."); break; diff --git a/content/events/test/test_eventctors.html b/content/events/test/test_eventctors.html index ecad322eb0b..cad3a396035 100644 --- a/content/events/test/test_eventctors.html +++ b/content/events/test/test_eventctors.html @@ -369,6 +369,17 @@ is(e.storageArea, localStorage, "Wrong value"); document.dispatchEvent(e); is(receivedEvent, e, "Wrong event!"); +// DeviceProximityEvent +e = new DeviceProximityEvent("hello", {min: 0, value: 1, max: 2}); +ok(e.type, "hello", "Wrong event type!"); +ok(!e.isTrusted, "Event should not be trusted"); +is(e.value, 1, "value should be 1"); +is(e.min, 0, "min should be 0"); +is(e.max, 2, "max should be 2"); +document.dispatchEvent(e); +is(receivedEvent, e, "Wrong event!"); + + // MouseEvent try { diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index fc6fb76cae3..12e5d5a4a02 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -325,6 +325,7 @@ #include "nsIDOMCSSStyleRule.h" #include "nsIDOMCSSStyleSheet.h" #include "nsDOMCSSValueList.h" +#include "nsIDOMDeviceProximityEvent.h" #include "nsIDOMDeviceOrientationEvent.h" #include "nsIDOMDeviceMotionEvent.h" #include "nsIDOMRange.h" @@ -813,6 +814,9 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(PopupBlockedEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) + // Device Proximity + NS_DEFINE_CLASSINFO_DATA(DeviceProximityEvent, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) // Device Orientation NS_DEFINE_CLASSINFO_DATA(DeviceOrientationEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1692,6 +1696,8 @@ NS_DEFINE_EVENT_CTOR(CloseEvent) NS_DEFINE_EVENT_CTOR(MozSettingsEvent) NS_DEFINE_EVENT_CTOR(UIEvent) NS_DEFINE_EVENT_CTOR(MouseEvent) +NS_DEFINE_EVENT_CTOR(DeviceProximityEvent) + nsresult NS_DOMStorageEventCtor(nsISupports** aInstancePtrResult) { @@ -1725,6 +1731,7 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] = NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozSettingsEvent) NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(UIEvent) NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MouseEvent) + NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(DeviceProximityEvent) NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(StorageEvent) NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozSmsFilter, sms::SmsFilter::NewSmsFilter) }; @@ -2605,6 +2612,11 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_EVENT_MAP_ENTRIES DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(DeviceProximityEvent, nsIDOMDeviceProximityEvent) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceProximityEvent) + DOM_CLASSINFO_EVENT_MAP_ENTRIES + DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN(DeviceOrientationEvent, nsIDOMDeviceOrientationEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceOrientationEvent) DOM_CLASSINFO_EVENT_MAP_ENTRIES diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index a761ce8c259..57a1475ad6a 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -79,6 +79,7 @@ DOMCI_CLASS(DragEvent) DOMCI_CLASS(KeyboardEvent) DOMCI_CLASS(CompositionEvent) DOMCI_CLASS(PopupBlockedEvent) +DOMCI_CLASS(DeviceProximityEvent) DOMCI_CLASS(DeviceOrientationEvent) DOMCI_CLASS(DeviceMotionEvent) DOMCI_CLASS(DeviceAcceleration) diff --git a/dom/interfaces/base/nsIDOMWindow.idl b/dom/interfaces/base/nsIDOMWindow.idl index ab59d52ea51..f83290853cf 100644 --- a/dom/interfaces/base/nsIDOMWindow.idl +++ b/dom/interfaces/base/nsIDOMWindow.idl @@ -69,7 +69,7 @@ interface nsIDOMMozURLProperty : nsISupports * @see */ -[scriptable, uuid(f6e3b10d-d5f4-4fcd-aa4c-5f98626d428a)] +[scriptable, uuid(627fa383-cb3c-498a-a5ed-ef2e9a827839)] interface nsIDOMWindow : nsISupports { // the current browsing context @@ -464,6 +464,7 @@ interface nsIDOMWindow : nsISupports */ [implicit_jscontext] attribute jsval ondevicemotion; [implicit_jscontext] attribute jsval ondeviceorientation; + [implicit_jscontext] attribute jsval ondeviceproximity; [implicit_jscontext] attribute jsval onmouseenter; [implicit_jscontext] attribute jsval onmouseleave; diff --git a/dom/interfaces/events/Makefile.in b/dom/interfaces/events/Makefile.in index 1e8a145e791..7f0285e86d2 100644 --- a/dom/interfaces/events/Makefile.in +++ b/dom/interfaces/events/Makefile.in @@ -75,7 +75,8 @@ XPIDLSRCS = \ nsIDOMPaintRequestList.idl \ nsIDOMSimpleGestureEvent.idl \ nsIDOMMozTouchEvent.idl \ - nsIDOMDeviceOrientationEvent.idl\ + nsIDOMDeviceProximityEvent.idl \ + nsIDOMDeviceOrientationEvent.idl \ nsIDOMDeviceMotionEvent.idl \ nsIDOMScrollAreaEvent.idl \ nsIDOMTransitionEvent.idl \ diff --git a/dom/interfaces/events/nsIDOMDeviceProximityEvent.idl b/dom/interfaces/events/nsIDOMDeviceProximityEvent.idl new file mode 100644 index 00000000000..84834d28f16 --- /dev/null +++ b/dom/interfaces/events/nsIDOMDeviceProximityEvent.idl @@ -0,0 +1,27 @@ +/* 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 "nsIDOMEvent.idl" + +[scriptable, uuid(4bb21c9b-381f-4c73-9000-5eb838f58738)] +interface nsIDOMDeviceProximityEvent : nsIDOMEvent +{ + [noscript] void initDeviceProximityEvent(in DOMString eventTypeArg, + in boolean canBubbleArg, + in boolean cancelableArg, + in double value, + in double min, + in double max); + readonly attribute double value; + readonly attribute double min; + readonly attribute double max; +}; + + +dictionary DeviceProximityEventInit : EventInit +{ + double value; + double min; + double max; +}; diff --git a/dom/system/nsDeviceSensors.cpp b/dom/system/nsDeviceSensors.cpp index 8b2d8b8d603..81eef0b4711 100644 --- a/dom/system/nsDeviceSensors.cpp +++ b/dom/system/nsDeviceSensors.cpp @@ -220,10 +220,37 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) FireDOMMotionEvent(domdoc, target, type, x, y, z); else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) FireDOMOrientationEvent(domdoc, target, x, y, z); + else if (type == nsIDeviceSensorData::TYPE_PROXIMITY) + FireDOMProximityEvent(target, x, y, z); } } } +void +nsDeviceSensors::FireDOMProximityEvent(nsIDOMEventTarget *aTarget, + double aValue, + double aMin, + double aMax) +{ + nsCOMPtr event; + NS_NewDOMDeviceProximityEvent(getter_AddRefs(event), nsnull, nsnull); + nsCOMPtr oe = do_QueryInterface(event); + + oe->InitDeviceProximityEvent(NS_LITERAL_STRING("deviceproximity"), + true, + false, + aValue, + aMin, + aMax); + + nsCOMPtr privateEvent = do_QueryInterface(event); + if (privateEvent) { + privateEvent->SetTrusted(true); + } + bool defaultActionEnabled; + aTarget->DispatchEvent(event, &defaultActionEnabled); +} + void nsDeviceSensors::FireDOMOrientationEvent(nsIDOMDocument *domdoc, nsIDOMEventTarget *target, diff --git a/dom/system/nsDeviceSensors.h b/dom/system/nsDeviceSensors.h index 5cb0dc1bf5f..656b1fe151d 100644 --- a/dom/system/nsDeviceSensors.h +++ b/dom/system/nsDeviceSensors.h @@ -44,6 +44,7 @@ #include "nsCOMPtr.h" #include "nsITimer.h" #include "nsIDOMDeviceOrientationEvent.h" +#include "nsIDOMDeviceProximityEvent.h" #include "nsIDOMDeviceMotionEvent.h" #include "nsDOMDeviceMotionEvent.h" #include "mozilla/TimeStamp.h" @@ -73,7 +74,12 @@ public: private: // sensor -> window listener nsTArray* > mWindowListeners; - + + void FireDOMProximityEvent(nsIDOMEventTarget *aTarget, + double aValue, + double aMin, + double aMax); + void FireDOMOrientationEvent(class nsIDOMDocument *domDoc, class nsIDOMEventTarget *target, double alpha, diff --git a/hal/gonk/GonkSensor.cpp b/hal/gonk/GonkSensor.cpp index 013873969c7..38036cac9ce 100644 --- a/hal/gonk/GonkSensor.cpp +++ b/hal/gonk/GonkSensor.cpp @@ -109,6 +109,18 @@ public: mSensorValues.AppendElement(radToDeg(data.data[0])); mSensorValues.AppendElement(radToDeg(data.data[1])); mSensorValues.AppendElement(radToDeg(data.data[2])); + } else if (mSensorData.sensor() == SENSOR_PROXIMITY) { + mSensorValues.AppendElement(data.data[0]); + mSensorValues.AppendElement(0); + + // Determine the maxRange for this sensor. + const sensor_t* sensors = NULL; + size_t size = SensorDevice::getInstance().getSensorList(&sensors); + for (size_t i = 0; i < size; i++) { + if (sensors[i].type == SENSOR_TYPE_PROXIMITY) { + mSensorValues.AppendElement(sensors[i].maxRange); + } + } } else { mSensorValues.AppendElement(data.data[0]); mSensorValues.AppendElement(data.data[1]); diff --git a/js/xpconnect/src/dictionary_helper_gen.conf b/js/xpconnect/src/dictionary_helper_gen.conf index 82cc0b5c3f0..37997dddc72 100644 --- a/js/xpconnect/src/dictionary_helper_gen.conf +++ b/js/xpconnect/src/dictionary_helper_gen.conf @@ -14,7 +14,8 @@ dictionaries = [ [ 'BlobPropertyBag', 'nsIDOMFile.idl' ], [ 'MutationObserverInit', 'nsIDOMMutationObserver.idl' ], [ 'SettingsEventInit', 'nsIDOMSettingsManager.idl' ], - [ 'GeoPositionOptions', 'nsIDOMGeoGeolocation.idl'] + [ 'GeoPositionOptions', 'nsIDOMGeoGeolocation.idl' ], + [ 'DeviceProximityEventInit', 'nsIDOMDeviceProximityEvent.idl' ] ] # include file names diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 1375565895f..a5b80011f5b 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -690,7 +690,7 @@ public class GeckoAppShell if(gProximitySensor == null) gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (gProximitySensor != null) - sm.registerListener(GeckoApp.mAppContext, gProximitySensor, sDefaultSensorHint); + sm.registerListener(GeckoApp.mAppContext, gProximitySensor, SensorManager.SENSOR_DELAY_NORMAL); break; case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION: diff --git a/mobile/android/base/GeckoEvent.java b/mobile/android/base/GeckoEvent.java index 737f6f6a414..bdb39219505 100644 --- a/mobile/android/base/GeckoEvent.java +++ b/mobile/android/base/GeckoEvent.java @@ -357,7 +357,10 @@ public class GeckoEvent { case Sensor.TYPE_PROXIMITY: event = new GeckoEvent(SENSOR_EVENT); event.mFlags = GeckoHalDefines.SENSOR_PROXIMITY; + event.mMetaState = HalSensorAccuracyFor(s.accuracy); event.mX = s.values[0]; + event.mY = 0; + event.mZ = s.sensor.getMaximumRange(); break; } return event; diff --git a/widget/nsGUIEvent.h b/widget/nsGUIEvent.h index 375951fb09f..a45493756dd 100644 --- a/widget/nsGUIEvent.h +++ b/widget/nsGUIEvent.h @@ -542,6 +542,7 @@ class nsHashKey; #define NS_DEVICE_ORIENTATION_START 4900 #define NS_DEVICE_ORIENTATION (NS_DEVICE_ORIENTATION_START) #define NS_DEVICE_MOTION (NS_DEVICE_ORIENTATION_START+1) +#define NS_DEVICE_PROXIMITY (NS_DEVICE_ORIENTATION_START+2) #define NS_SHOW_EVENT 5000