mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 751663 - Implement new device proximity like event that fires only when the screen is close to the user's face. r=smaug
This commit is contained in:
parent
91066e9c2a
commit
8313ba6d13
@ -1716,6 +1716,7 @@ GK_ATOM(onMozTouchUp, "onMozTouchUp")
|
||||
GK_ATOM(ondevicemotion, "ondevicemotion")
|
||||
GK_ATOM(ondeviceorientation, "ondeviceorientation")
|
||||
GK_ATOM(ondeviceproximity, "ondeviceproximity")
|
||||
GK_ATOM(onuserproximity, "onuserproximity")
|
||||
|
||||
// light sensor support
|
||||
GK_ATOM(ondevicelight, "ondevicelight")
|
||||
|
@ -459,6 +459,10 @@ WINDOW_ONLY_EVENT(deviceproximity,
|
||||
NS_DEVICE_PROXIMITY,
|
||||
EventNameType_None,
|
||||
NS_EVENT)
|
||||
WINDOW_ONLY_EVENT(userproximity,
|
||||
NS_USER_PROXIMITY,
|
||||
EventNameType_None,
|
||||
NS_EVENT)
|
||||
WINDOW_ONLY_EVENT(devicelight,
|
||||
NS_DEVICE_LIGHT,
|
||||
EventNameType_None,
|
||||
|
@ -94,6 +94,8 @@ NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, n
|
||||
nsresult
|
||||
NS_NewDOMDeviceProximityEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent *aEvent);
|
||||
nsresult
|
||||
NS_NewDOMUserProximityEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent *aEvent);
|
||||
nsresult
|
||||
NS_NewDOMDeviceOrientationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
|
||||
nsresult
|
||||
NS_NewDOMDeviceLightEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
|
||||
|
@ -66,6 +66,7 @@ CPPSRCS = \
|
||||
nsDOMMutationEvent.cpp \
|
||||
nsDOMPopupBlockedEvent.cpp \
|
||||
nsDOMDeviceProximityEvent.cpp \
|
||||
nsDOMUserProximityEvent.cpp \
|
||||
nsDOMDeviceLightEvent.cpp \
|
||||
nsDOMDeviceOrientationEvent.cpp \
|
||||
nsDOMDeviceMotionEvent.cpp \
|
||||
|
@ -128,6 +128,7 @@ static const char* const sEventNames[] = {
|
||||
"devicemotion",
|
||||
"deviceorientation",
|
||||
"deviceproximity",
|
||||
"userproximity",
|
||||
"devicelight"
|
||||
};
|
||||
|
||||
@ -1557,6 +1558,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
|
||||
return sEventNames[eDOMEvents_deviceorientation];
|
||||
case NS_DEVICE_PROXIMITY:
|
||||
return sEventNames[eDOMEvents_deviceproximity];
|
||||
case NS_USER_PROXIMITY:
|
||||
return sEventNames[eDOMEvents_userproximity];
|
||||
case NS_DEVICE_LIGHT:
|
||||
return sEventNames[eDOMEvents_devicelight];
|
||||
case NS_FULLSCREENCHANGE:
|
||||
|
@ -211,6 +211,7 @@ public:
|
||||
eDOMEvents_devicemotion,
|
||||
eDOMEvents_deviceorientation,
|
||||
eDOMEvents_deviceproximity,
|
||||
eDOMEvents_userproximity,
|
||||
eDOMEvents_devicelight
|
||||
};
|
||||
|
||||
|
57
content/events/src/nsDOMUserProximityEvent.cpp
Normal file
57
content/events/src/nsDOMUserProximityEvent.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* 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 "nsDOMUserProximityEvent.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "DictionaryHelpers.h"
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsDOMUserProximityEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(nsDOMUserProximityEvent, nsDOMEvent)
|
||||
|
||||
DOMCI_DATA(UserProximityEvent, nsDOMUserProximityEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMUserProximityEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMUserProximityEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(UserProximityEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMUserProximityEvent::InitUserProximityEvent(const nsAString & aEventTypeArg,
|
||||
bool aCanBubbleArg,
|
||||
bool aCancelableArg,
|
||||
bool aNear)
|
||||
{
|
||||
nsresult rv = nsDOMEvent::InitEvent(aEventTypeArg, aCanBubbleArg, aCancelableArg);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mNear = aNear;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMUserProximityEvent::GetNear(bool *aNear)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNear);
|
||||
*aNear = mNear;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMUserProximityEvent::InitFromCtor(const nsAString& aType,
|
||||
JSContext* aCx, jsval* aVal)
|
||||
{
|
||||
mozilla::dom::UserProximityEventInit d;
|
||||
nsresult rv = d.Init(aCx, aVal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return InitUserProximityEvent(aType, d.bubbles, d.cancelable, d.near);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewDOMUserProximityEvent(nsIDOMEvent** aInstancePtrResult,
|
||||
nsPresContext* aPresContext,
|
||||
nsEvent *aEvent)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
nsDOMUserProximityEvent* it = new nsDOMUserProximityEvent(aPresContext, aEvent);
|
||||
return CallQueryInterface(it, aInstancePtrResult);
|
||||
}
|
36
content/events/src/nsDOMUserProximityEvent.h
Normal file
36
content/events/src/nsDOMUserProximityEvent.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* 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 nsDOMUserProximityEvent_h__
|
||||
#define nsDOMUserProximityEvent_h__
|
||||
|
||||
#include "nsIDOMUserProximityEvent.h"
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
class nsDOMUserProximityEvent
|
||||
: public nsDOMEvent
|
||||
, public nsIDOMUserProximityEvent
|
||||
{
|
||||
public:
|
||||
|
||||
nsDOMUserProximityEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
||||
: nsDOMEvent(aPresContext, aEvent),
|
||||
mNear(false) {}
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// Forward to nsDOMEvent
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
|
||||
// nsIDOMUserProximityEvent Interface
|
||||
NS_DECL_NSIDOMUSERPROXIMITYEVENT
|
||||
|
||||
virtual nsresult InitFromCtor(const nsAString& aType,
|
||||
JSContext* aCx,
|
||||
jsval* aVal);
|
||||
protected:
|
||||
bool mNear;
|
||||
};
|
||||
|
||||
#endif
|
@ -290,7 +290,7 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
}
|
||||
} else if (aTypeAtom == nsGkAtoms::ondeviceorientation) {
|
||||
EnableDevice(NS_DEVICE_ORIENTATION);
|
||||
} else if (aTypeAtom == nsGkAtoms::ondeviceproximity) {
|
||||
} else if (aTypeAtom == nsGkAtoms::ondeviceproximity || aTypeAtom == nsGkAtoms::onuserproximity) {
|
||||
EnableDevice(NS_DEVICE_PROXIMITY);
|
||||
} else if (aTypeAtom == nsGkAtoms::ondevicelight) {
|
||||
EnableDevice(NS_DEVICE_LIGHT);
|
||||
@ -351,6 +351,7 @@ nsEventListenerManager::EnableDevice(PRUint32 aType)
|
||||
window->EnableDeviceSensor(SENSOR_ORIENTATION);
|
||||
break;
|
||||
case NS_DEVICE_PROXIMITY:
|
||||
case NS_USER_PROXIMITY:
|
||||
window->EnableDeviceSensor(SENSOR_PROXIMITY);
|
||||
break;
|
||||
case NS_DEVICE_LIGHT:
|
||||
@ -387,6 +388,7 @@ nsEventListenerManager::DisableDevice(PRUint32 aType)
|
||||
window->DisableDeviceSensor(SENSOR_GYROSCOPE);
|
||||
break;
|
||||
case NS_DEVICE_PROXIMITY:
|
||||
case NS_USER_PROXIMITY:
|
||||
window->DisableDeviceSensor(SENSOR_PROXIMITY);
|
||||
break;
|
||||
case NS_DEVICE_LIGHT:
|
||||
|
@ -379,6 +379,14 @@ is(e.max, 2, "max should be 2");
|
||||
document.dispatchEvent(e);
|
||||
is(receivedEvent, e, "Wrong event!");
|
||||
|
||||
// UserProximityEvent
|
||||
e = new UserProximityEvent("hello", {near: true});
|
||||
ok(e.type, "hello", "Wrong event type!");
|
||||
ok(!e.isTrusted, "Event should not be trusted");
|
||||
is(e.near, true, "near should be true");
|
||||
document.dispatchEvent(e);
|
||||
is(receivedEvent, e, "Wrong event!");
|
||||
|
||||
// DeviceLightEvent
|
||||
e = new DeviceLightEvent("hello", {value: 1} );
|
||||
ok(e.type, "hello", "Wrong event type!");
|
||||
|
@ -326,6 +326,7 @@
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsDOMCSSValueList.h"
|
||||
#include "nsIDOMDeviceProximityEvent.h"
|
||||
#include "nsIDOMUserProximityEvent.h"
|
||||
#include "nsIDOMDeviceLightEvent.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
@ -821,6 +822,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
// Device Proximity
|
||||
NS_DEFINE_CLASSINFO_DATA(DeviceProximityEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
// User Proximity
|
||||
NS_DEFINE_CLASSINFO_DATA(UserProximityEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
// Device Orientation
|
||||
NS_DEFINE_CLASSINFO_DATA(DeviceOrientationEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
@ -1697,6 +1701,7 @@ NS_DEFINE_EVENT_CTOR(UIEvent)
|
||||
NS_DEFINE_EVENT_CTOR(MouseEvent)
|
||||
NS_DEFINE_EVENT_CTOR(DeviceLightEvent)
|
||||
NS_DEFINE_EVENT_CTOR(DeviceProximityEvent)
|
||||
NS_DEFINE_EVENT_CTOR(UserProximityEvent)
|
||||
|
||||
nsresult
|
||||
NS_DOMStorageEventCtor(nsISupports** aInstancePtrResult)
|
||||
@ -1732,6 +1737,7 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] =
|
||||
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(UserProximityEvent)
|
||||
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(DeviceLightEvent)
|
||||
NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(StorageEvent)
|
||||
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozSmsFilter, sms::SmsFilter::NewSmsFilter)
|
||||
@ -2621,6 +2627,11 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(UserProximityEvent, nsIDOMUserProximityEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMUserProximityEvent)
|
||||
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
|
||||
|
@ -81,6 +81,7 @@ DOMCI_CLASS(CompositionEvent)
|
||||
DOMCI_CLASS(PopupBlockedEvent)
|
||||
DOMCI_CLASS(DeviceLightEvent)
|
||||
DOMCI_CLASS(DeviceProximityEvent)
|
||||
DOMCI_CLASS(UserProximityEvent)
|
||||
DOMCI_CLASS(DeviceOrientationEvent)
|
||||
DOMCI_CLASS(DeviceMotionEvent)
|
||||
DOMCI_CLASS(DeviceAcceleration)
|
||||
|
@ -69,7 +69,7 @@ interface nsIDOMMozURLProperty : nsISupports
|
||||
* @see <http://www.whatwg.org/html/#window>
|
||||
*/
|
||||
|
||||
[scriptable, uuid(e6198a86-1a46-46ec-9501-dfcd84a5f630)]
|
||||
[scriptable, uuid(a89569e6-4fef-49a5-a19b-612ac481fa2e)]
|
||||
interface nsIDOMWindow : nsISupports
|
||||
{
|
||||
// the current browsing context
|
||||
@ -465,6 +465,7 @@ interface nsIDOMWindow : nsISupports
|
||||
[implicit_jscontext] attribute jsval ondevicemotion;
|
||||
[implicit_jscontext] attribute jsval ondeviceorientation;
|
||||
[implicit_jscontext] attribute jsval ondeviceproximity;
|
||||
[implicit_jscontext] attribute jsval onuserproximity;
|
||||
[implicit_jscontext] attribute jsval ondevicelight;
|
||||
|
||||
[implicit_jscontext] attribute jsval onmouseenter;
|
||||
|
@ -77,6 +77,7 @@ XPIDLSRCS = \
|
||||
nsIDOMMozTouchEvent.idl \
|
||||
nsIDOMDeviceLightEvent.idl \
|
||||
nsIDOMDeviceProximityEvent.idl \
|
||||
nsIDOMUserProximityEvent.idl \
|
||||
nsIDOMDeviceOrientationEvent.idl \
|
||||
nsIDOMDeviceMotionEvent.idl \
|
||||
nsIDOMScrollAreaEvent.idl \
|
||||
|
21
dom/interfaces/events/nsIDOMUserProximityEvent.idl
Normal file
21
dom/interfaces/events/nsIDOMUserProximityEvent.idl
Normal file
@ -0,0 +1,21 @@
|
||||
/* 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(e67432b8-ead4-4247-bf6c-f2e426472478)]
|
||||
interface nsIDOMUserProximityEvent : nsIDOMEvent
|
||||
{
|
||||
[noscript] void initUserProximityEvent(in DOMString eventTypeArg,
|
||||
in boolean canBubbleArg,
|
||||
in boolean cancelableArg,
|
||||
in boolean near);
|
||||
|
||||
readonly attribute boolean near;
|
||||
};
|
||||
|
||||
dictionary UserProximityEventInit : EventInit
|
||||
{
|
||||
boolean near;
|
||||
};
|
@ -54,6 +54,8 @@
|
||||
using namespace mozilla;
|
||||
using namespace hal;
|
||||
|
||||
#undef near
|
||||
|
||||
// also see sDefaultSensorHint in mobile/android/base/GeckoAppShell.java
|
||||
#define DEFAULT_SENSOR_POLL 100
|
||||
|
||||
@ -124,6 +126,7 @@ NS_IMPL_ISUPPORTS1(nsDeviceSensors, nsIDeviceSensors)
|
||||
|
||||
nsDeviceSensors::nsDeviceSensors()
|
||||
{
|
||||
mIsUserProximityNear = false;
|
||||
mLastDOMMotionEventTime = TimeStamp::Now();
|
||||
mEnabled = Preferences::GetBool("device.sensors.enabled", true);
|
||||
|
||||
@ -274,14 +277,46 @@ nsDeviceSensors::FireDOMProximityEvent(nsIDOMEventTarget *aTarget,
|
||||
}
|
||||
bool defaultActionEnabled;
|
||||
aTarget->DispatchEvent(event, &defaultActionEnabled);
|
||||
|
||||
// Some proximity sensors only support a binary near or
|
||||
// far measurement. In this case, the sensor should report
|
||||
// its maximum range value in the far state and a lesser
|
||||
// value in the near state.
|
||||
|
||||
bool near = (aValue < aMax);
|
||||
if (mIsUserProximityNear != near) {
|
||||
mIsUserProximityNear = near;
|
||||
FireDOMUserProximityEvent(aTarget, mIsUserProximityNear);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceSensors::FireDOMUserProximityEvent(nsIDOMEventTarget *aTarget, bool aNear)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
NS_NewDOMUserProximityEvent(getter_AddRefs(event), nsnull, nsnull);
|
||||
nsCOMPtr<nsIDOMUserProximityEvent> pe = do_QueryInterface(event);
|
||||
|
||||
pe->InitUserProximityEvent(NS_LITERAL_STRING("userproximity"),
|
||||
true,
|
||||
false,
|
||||
aNear);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
privateEvent = do_QueryInterface(event);
|
||||
if (privateEvent) {
|
||||
privateEvent->SetTrusted(true);
|
||||
}
|
||||
bool defaultActionEnabled;
|
||||
aTarget->DispatchEvent(event, &defaultActionEnabled);
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceSensors::FireDOMOrientationEvent(nsIDOMDocument *domdoc,
|
||||
nsIDOMEventTarget *target,
|
||||
double alpha,
|
||||
double beta,
|
||||
double gamma)
|
||||
nsIDOMEventTarget *target,
|
||||
double alpha,
|
||||
double beta,
|
||||
double gamma)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
bool defaultActionEnabled = true;
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "nsIDOMDeviceLightEvent.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIDOMDeviceProximityEvent.h"
|
||||
#include "nsIDOMUserProximityEvent.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsDOMDeviceMotionEvent.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
@ -84,6 +85,9 @@ private:
|
||||
double aMin,
|
||||
double aMax);
|
||||
|
||||
void FireDOMUserProximityEvent(nsIDOMEventTarget *aTarget,
|
||||
bool aNear);
|
||||
|
||||
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
|
||||
class nsIDOMEventTarget *target,
|
||||
double alpha,
|
||||
@ -104,6 +108,7 @@ private:
|
||||
}
|
||||
|
||||
mozilla::TimeStamp mLastDOMMotionEventTime;
|
||||
bool mIsUserProximityNear;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
|
||||
nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
|
||||
nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
|
||||
|
@ -16,6 +16,7 @@ dictionaries = [
|
||||
[ 'SettingsEventInit', 'nsIDOMSettingsManager.idl' ],
|
||||
[ 'GeoPositionOptions', 'nsIDOMGeoGeolocation.idl' ],
|
||||
[ 'DeviceProximityEventInit', 'nsIDOMDeviceProximityEvent.idl' ],
|
||||
[ 'UserProximityEventInit', 'nsIDOMUserProximityEvent.idl' ],
|
||||
[ 'DeviceLightEventInit', 'nsIDOMDeviceLightEvent.idl' ]
|
||||
]
|
||||
|
||||
|
@ -543,7 +543,8 @@ class nsHashKey;
|
||||
#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_DEVICE_LIGHT (NS_DEVICE_ORIENTATION_START+3)
|
||||
#define NS_USER_PROXIMITY (NS_DEVICE_ORIENTATION_START+3)
|
||||
#define NS_DEVICE_LIGHT (NS_DEVICE_ORIENTATION_START+4)
|
||||
|
||||
#define NS_SHOW_EVENT 5000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user