From 523ec15e9c66b47dcd571f375f0314d59081f608 Mon Sep 17 00:00:00 2001 From: roytam1 Date: Fri, 10 Nov 2023 16:18:39 +0800 Subject: [PATCH] import changes from `dev' branch of rmottola/Arctic-Fox: - Bug 1235830 - Renaming GetInternalNSEvent to WidgetEvent, in nsIDOMEvent r=smaug (cc4346fac9) - Bug 1235899 - Don't allow frame reconstruction to clobber the APZ scroll offset. r=botond (4c4de0dedd) - Bug 1073224 - [1.2] Use SENSOR_ROTATION_VECTOR for DOM DeviceOrientation events on Android. r=vlad (0362a236bc) - Bug 1073224 - [2.1] Accept rotation vector device sensor listeners in tests. r=vlad (de453a3439) - Bug 1205649 - [1.1] Use relative orientation for DOM DeviceOrientation events by default. r=vlad (cf903846b3) - Bug 1205649 - [2.4] Add AbsoluteDeviceOrientation DOM event for compass heading orientation data. r=smaug (fa19ea545f) --- dom/base/PostMessageEvent.cpp | 2 +- dom/base/TextInputProcessor.cpp | 6 +- dom/base/nsContentUtils.cpp | 4 +- dom/base/nsDOMWindowUtils.cpp | 4 +- dom/base/nsDocument.cpp | 4 +- dom/base/nsGkAtomList.h | 11 +- dom/base/nsGlobalWindow.cpp | 8 +- dom/base/nsObjectLoadingContent.cpp | 2 +- dom/events/AsyncEventDispatcher.cpp | 2 +- dom/events/Event.cpp | 2 +- dom/events/Event.h | 4 +- dom/events/EventDispatcher.cpp | 4 +- dom/events/EventListenerManager.cpp | 28 ++++ dom/events/EventNameList.h | 4 + dom/events/IMEStateManager.cpp | 2 +- dom/events/test/test_bug742376.html | 4 +- dom/html/nsTextEditorState.cpp | 2 +- dom/indexedDB/ActorsChild.cpp | 4 +- dom/interfaces/events/nsIDOMEvent.idl | 4 +- dom/ipc/TabParent.cpp | 4 +- dom/media/gmp/GMPService.cpp | 2 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 12 +- dom/system/nsDeviceSensors.cpp | 123 +++++++++++++++--- dom/system/nsDeviceSensors.h | 7 +- dom/webidl/Window.webidl | 1 + dom/workers/ServiceWorkerPrivate.cpp | 4 +- dom/xbl/nsXBLEventHandler.cpp | 2 +- dom/xbl/nsXBLPrototypeHandler.cpp | 2 +- dom/xbl/nsXBLWindowKeyHandler.cpp | 6 +- editor/libeditor/nsEditor.cpp | 6 +- editor/libeditor/nsEditorEventListener.cpp | 6 +- editor/libeditor/nsHTMLEditor.cpp | 4 +- editor/libeditor/nsPlaintextDataTransfer.cpp | 2 +- editor/libeditor/nsPlaintextEditor.cpp | 4 +- .../windowwatcher/nsAutoWindowStateHelper.cpp | 2 +- gfx/layers/apz/util/APZCCallbackHelper.cpp | 4 +- layout/base/AccessibleCaretManager.cpp | 2 +- layout/base/nsDocumentViewer.cpp | 2 +- layout/base/nsLayoutUtils.cpp | 17 ++- layout/base/nsLayoutUtils.h | 9 ++ layout/forms/nsListControlFrame.cpp | 6 +- layout/generic/nsGfxScrollFrame.cpp | 11 +- layout/printing/nsPrintPreviewListener.cpp | 2 +- layout/xul/nsMenuBarFrame.cpp | 2 +- layout/xul/nsMenuBarListener.cpp | 4 +- layout/xul/nsSliderFrame.cpp | 2 +- layout/xul/nsXULPopupManager.cpp | 8 +- .../src/peerconnection/PeerConnectionImpl.cpp | 2 +- widget/EventMessageList.h | 1 + xpcom/system/nsIDeviceSensors.idl | 11 +- 50 files changed, 269 insertions(+), 102 deletions(-) diff --git a/dom/base/PostMessageEvent.cpp b/dom/base/PostMessageEvent.cpp index b33445189c..1551a5c26d 100644 --- a/dom/base/PostMessageEvent.cpp +++ b/dom/base/PostMessageEvent.cpp @@ -131,7 +131,7 @@ PostMessageEvent::Run() presContext = shell->GetPresContext(); event->SetTrusted(mTrustedCaller); - WidgetEvent* internalEvent = event->GetInternalNSEvent(); + WidgetEvent* internalEvent = event->WidgetEventPtr(); nsEventStatus status = nsEventStatus_eIgnore; EventDispatcher::Dispatch(static_cast(mTargetWindow), diff --git a/dom/base/TextInputProcessor.cpp b/dom/base/TextInputProcessor.cpp index 48e9a0b853..44f00ccde1 100644 --- a/dom/base/TextInputProcessor.cpp +++ b/dom/base/TextInputProcessor.cpp @@ -344,7 +344,7 @@ TextInputProcessor::PrepareKeyboardEventForComposition( aKeyboardEvent = aOptionalArgc && aDOMKeyEvent ? - aDOMKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent() : nullptr; + aDOMKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent() : nullptr; if (!aKeyboardEvent || aOptionalArgc < 2) { aKeyFlags = 0; } @@ -769,7 +769,7 @@ TextInputProcessor::Keydown(nsIDOMKeyEvent* aDOMKeyEvent, return NS_ERROR_INVALID_ARG; } WidgetKeyboardEvent* originalKeyEvent = - aDOMKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aDOMKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); if (NS_WARN_IF(!originalKeyEvent)) { return NS_ERROR_INVALID_ARG; } @@ -875,7 +875,7 @@ TextInputProcessor::Keyup(nsIDOMKeyEvent* aDOMKeyEvent, return NS_ERROR_INVALID_ARG; } WidgetKeyboardEvent* originalKeyEvent = - aDOMKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aDOMKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); if (NS_WARN_IF(!originalKeyEvent)) { return NS_ERROR_INVALID_ARG; } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 748070536d..676a3be42e 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3808,7 +3808,7 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, aCancelable, aTrusted, getter_AddRefs(event), getter_AddRefs(target)); NS_ENSURE_SUCCESS(rv, rv); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = aOnlyChromeDispatch; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = aOnlyChromeDispatch; bool dummy; return target->DispatchEvent(event, aDefaultAction ? aDefaultAction : &dummy); @@ -4954,7 +4954,7 @@ nsContentUtils::GetAccelKeyCandidates(nsIDOMKeyEvent* aDOMKeyEvent, return; WidgetKeyboardEvent* nativeKeyEvent = - aDOMKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aDOMKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); if (nativeKeyEvent) { NS_ASSERTION(nativeKeyEvent->mClass == eKeyboardEventClass, "wrong type of native event"); diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 8e0e741ab8..b64b4ebdf7 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1875,7 +1875,7 @@ nsDOMWindowUtils::DispatchDOMEventViaPresShell(nsIDOMNode* aTarget, NS_ENSURE_STATE(aEvent); aEvent->SetTrusted(aTrusted); - WidgetEvent* internalEvent = aEvent->GetInternalNSEvent(); + WidgetEvent* internalEvent = aEvent->WidgetEventPtr(); NS_ENSURE_STATE(internalEvent); nsCOMPtr content = do_QueryInterface(aTarget); NS_ENSURE_STATE(content); @@ -3547,7 +3547,7 @@ nsDOMWindowUtils::DispatchEventToChromeOnly(nsIDOMEventTarget* aTarget, *aRetVal = false; MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome()); NS_ENSURE_STATE(aTarget && aEvent); - aEvent->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + aEvent->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; aTarget->DispatchEvent(aEvent, aRetVal); return NS_OK; } diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index f6f7bd70ad..79db58ec91 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5124,7 +5124,7 @@ nsDocument::DispatchContentLoadedEvents() // the ancestor document if we used the normal event // dispatching code. - WidgetEvent* innerEvent = event->GetInternalNSEvent(); + WidgetEvent* innerEvent = event->WidgetEventPtr(); if (innerEvent) { nsEventStatus status = nsEventStatus_eIgnore; @@ -8139,7 +8139,7 @@ nsIDocument::CreateEvent(const nsAString& aEventType, ErrorResult& rv) const rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } - WidgetEvent* e = ev->GetInternalNSEvent(); + WidgetEvent* e = ev->WidgetEventPtr(); e->mFlags.mBubbles = false; e->mFlags.mCancelable = false; return ev.forget(); diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index 5314447413..18b19a7049 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -104,7 +104,6 @@ GK_ATOM(applet, "applet") GK_ATOM(applyImports, "apply-imports") GK_ATOM(applyTemplates, "apply-templates") GK_ATOM(mozapptype, "mozapptype") -GK_ATOM(apz, "apz") GK_ATOM(archive, "archive") GK_ATOM(area, "area") GK_ATOM(arrow, "arrow") @@ -1919,6 +1918,7 @@ GK_ATOM(onlostpointercapture, "onlostpointercapture") // orientation support GK_ATOM(ondevicemotion, "ondevicemotion") GK_ATOM(ondeviceorientation, "ondeviceorientation") +GK_ATOM(onabsolutedeviceorientation, "onabsolutedeviceorientation") GK_ATOM(ondeviceproximity, "ondeviceproximity") GK_ATOM(onmozorientationchange, "onmozorientationchange") GK_ATOM(onuserproximity, "onuserproximity") @@ -2270,13 +2270,20 @@ GK_ATOM(SendMail, "SendMail") GK_ATOM(ForwardMail, "ForwardMail") GK_ATOM(ReplyToMail, "ReplyToMail") -// Smooth scroll events origins +// Scroll origins (these are used in various scrolling functions in +// nsIScrollableFrame and ScrollFrameHelper). These are divided into two lists +// - origins in the first one have smooth-scrolling prefs associated with them, +// under the "general.smoothScroll..*" pref branch. Origins in the +// second one do not. GK_ATOM(mouseWheel, "mouseWheel") // For discrete wheel events (e.g. not OSX magic mouse) GK_ATOM(pixels, "pixels") GK_ATOM(lines, "lines") GK_ATOM(pages, "pages") GK_ATOM(scrollbars, "scrollbars") GK_ATOM(other, "other") +// Scroll origins without smooth-scrolling prefs +GK_ATOM(apz, "apz") +GK_ATOM(restore, "restore") #ifdef ACCESSIBILITY GK_ATOM(alert, "alert") diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 2b58a5f0ed..e4409591e3 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -6190,7 +6190,7 @@ nsGlobalWindow::DispatchResizeEvent(const CSSIntSize& aSize) } domEvent->SetTrusted(true); - domEvent->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + domEvent->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; nsCOMPtr target = do_QueryInterface(GetOuterWindow()); domEvent->SetTarget(target); @@ -8892,7 +8892,7 @@ nsGlobalWindow::LeaveModalState() RefPtr event = NS_NewDOMEvent(topWin, nullptr, nullptr); event->InitEvent(NS_LITERAL_STRING("endmodalstate"), true, false); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; bool dummy; topWin->DispatchEvent(event, &dummy); } @@ -11656,7 +11656,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, newEvent->SetTrusted(true); if (fireMozStorageChanged) { - WidgetEvent* internalEvent = newEvent->GetInternalNSEvent(); + WidgetEvent* internalEvent = newEvent->WidgetEventPtr(); internalEvent->mFlags.mOnlyChromeDispatch = true; } @@ -13825,7 +13825,7 @@ nsGlobalWindow::BeginWindowMove(Event& aMouseDownEvent, Element* aPanel, } WidgetMouseEvent* mouseEvent = - aMouseDownEvent.GetInternalNSEvent()->AsMouseEvent(); + aMouseDownEvent.WidgetEventPtr()->AsMouseEvent(); if (!mouseEvent || mouseEvent->mClass != eMouseEventClass) { aError.Throw(NS_ERROR_FAILURE); return; diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index c53e46837d..c30760854a 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -354,7 +354,7 @@ nsPluginCrashedEvent::Run() PluginCrashedEvent::Constructor(doc, NS_LITERAL_STRING("PluginCrashed"), init); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; EventDispatcher::DispatchDOMEvent(mContent, nullptr, event, nullptr, nullptr); return NS_OK; diff --git a/dom/events/AsyncEventDispatcher.cpp b/dom/events/AsyncEventDispatcher.cpp index b885fff6c3..c256c9b47b 100644 --- a/dom/events/AsyncEventDispatcher.cpp +++ b/dom/events/AsyncEventDispatcher.cpp @@ -47,7 +47,7 @@ AsyncEventDispatcher::Run() } if (mOnlyChromeDispatch) { MOZ_ASSERT(event->IsTrusted()); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; } bool dummy; mTarget->DispatchEvent(event, &dummy); diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index c2df00d9d8..06a50bf2dc 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -638,7 +638,7 @@ Event::IsDispatchStopped() } NS_IMETHODIMP_(WidgetEvent*) -Event::GetInternalNSEvent() +Event::WidgetEventPtr() { return mEvent; } diff --git a/dom/events/Event.h b/dom/events/Event.h index 572654cd52..2c35536cfc 100644 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -315,10 +315,10 @@ private: NS_IMETHOD GetIsTrusted(bool* aIsTrusted) override { return _to GetIsTrusted(aIsTrusted); } \ NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) override { return _to SetTarget(aTarget); } \ NS_IMETHOD_(bool) IsDispatchStopped(void) override { return _to IsDispatchStopped(); } \ - NS_IMETHOD_(WidgetEvent*) GetInternalNSEvent(void) override { return _to GetInternalNSEvent(); } \ + NS_IMETHOD_(WidgetEvent*) WidgetEventPtr(void) override { return _to WidgetEventPtr(); } \ NS_IMETHOD_(void) SetTrusted(bool aTrusted) override { _to SetTrusted(aTrusted); } \ NS_IMETHOD_(void) SetOwner(EventTarget* aOwner) override { _to SetOwner(aOwner); } \ - NS_IMETHOD_(Event*) InternalDOMEvent() override { return _to InternalDOMEvent(); } \ + NS_IMETHOD_(Event*) InternalDOMEvent() override { return _to InternalDOMEvent(); } #define NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \ NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(Event::) \ diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index b2f829cac0..09e1bb8007 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -509,7 +509,7 @@ EventDispatcher::Dispatch(nsISupports* aTarget, } if (aDOMEvent) { - WidgetEvent* innerEvent = aDOMEvent->GetInternalNSEvent(); + WidgetEvent* innerEvent = aDOMEvent->WidgetEventPtr(); NS_ASSERTION(innerEvent == aEvent, "The inner event of aDOMEvent is not the same as aEvent!"); } @@ -698,7 +698,7 @@ EventDispatcher::DispatchDOMEvent(nsISupports* aTarget, nsEventStatus* aEventStatus) { if (aDOMEvent) { - WidgetEvent* innerEvent = aDOMEvent->GetInternalNSEvent(); + WidgetEvent* innerEvent = aDOMEvent->WidgetEventPtr(); NS_ENSURE_TRUE(innerEvent, NS_ERROR_ILLEGAL_VALUE); bool dontResetTrusted = false; diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 10febe30bd..8b3524367b 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -319,6 +319,8 @@ EventListenerManager::AddEventListenerInternal( } } else if (aTypeAtom == nsGkAtoms::ondeviceorientation) { EnableDevice(eDeviceOrientation); + } else if (aTypeAtom == nsGkAtoms::onabsolutedeviceorientation) { + EnableDevice(eAbsoluteDeviceOrientation); } else if (aTypeAtom == nsGkAtoms::ondeviceproximity || aTypeAtom == nsGkAtoms::onuserproximity) { EnableDevice(eDeviceProximity); } else if (aTypeAtom == nsGkAtoms::ondevicelight) { @@ -431,6 +433,7 @@ EventListenerManager::IsDeviceType(EventMessage aEventMessage) { switch (aEventMessage) { case eDeviceOrientation: + case eAbsoluteDeviceOrientation: case eDeviceMotion: case eDeviceLight: case eDeviceProximity: @@ -455,7 +458,21 @@ EventListenerManager::EnableDevice(EventMessage aEventMessage) switch (aEventMessage) { case eDeviceOrientation: +#ifdef MOZ_WIDGET_ANDROID + // Falls back to SENSOR_ROTATION_VECTOR and SENSOR_ORIENTATION if + // unavailable on device. + window->EnableDeviceSensor(SENSOR_GAME_ROTATION_VECTOR); +#else window->EnableDeviceSensor(SENSOR_ORIENTATION); +#endif + break; + case eAbsoluteDeviceOrientation: +#ifdef MOZ_WIDGET_ANDROID + // Falls back to SENSOR_ORIENTATION if unavailable on device. + window->EnableDeviceSensor(SENSOR_ROTATION_VECTOR); +#else + window->EnableDeviceSensor(SENSOR_ORIENTATION); +#endif break; case eDeviceProximity: case eUserProximity: @@ -490,6 +507,17 @@ EventListenerManager::DisableDevice(EventMessage aEventMessage) switch (aEventMessage) { case eDeviceOrientation: +#ifdef MOZ_WIDGET_ANDROID + // Disable all potential fallback sensors. + window->DisableDeviceSensor(SENSOR_GAME_ROTATION_VECTOR); + window->DisableDeviceSensor(SENSOR_ROTATION_VECTOR); +#endif + window->DisableDeviceSensor(SENSOR_ORIENTATION); + break; + case eAbsoluteDeviceOrientation: +#ifdef MOZ_WIDGET_ANDROID + window->DisableDeviceSensor(SENSOR_ROTATION_VECTOR); +#endif window->DisableDeviceSensor(SENSOR_ORIENTATION); break; case eDeviceMotion: diff --git a/dom/events/EventNameList.h b/dom/events/EventNameList.h index 5f1e5d059d..ce5ee313ff 100644 --- a/dom/events/EventNameList.h +++ b/dom/events/EventNameList.h @@ -551,6 +551,10 @@ WINDOW_ONLY_EVENT(deviceorientation, eDeviceOrientation, EventNameType_None, eBasicEventClass) +WINDOW_ONLY_EVENT(absolutedeviceorientation, + eAbsoluteDeviceOrientation, + EventNameType_None, + eBasicEventClass) WINDOW_ONLY_EVENT(deviceproximity, eDeviceProximity, EventNameType_None, diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 1504298da5..9c95cca99a 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -582,7 +582,7 @@ IMEStateManager::OnMouseButtonEventInEditor(nsPresContext* aPresContext, } WidgetMouseEvent* internalEvent = - aMouseEvent->AsEvent()->GetInternalNSEvent()->AsMouseEvent(); + aMouseEvent->AsEvent()->WidgetEventPtr()->AsMouseEvent(); if (NS_WARN_IF(!internalEvent)) { MOZ_LOG(sISMLog, LogLevel::Debug, ("ISM: IMEStateManager::OnMouseButtonEventInEditor(), " diff --git a/dom/events/test/test_bug742376.html b/dom/events/test/test_bug742376.html index b47f2c2f74..4c3cea7e20 100644 --- a/dom/events/test/test_bug742376.html +++ b/dom/events/test/test_bug742376.html @@ -22,7 +22,9 @@ function hasListeners() { var Ci = SpecialPowers.Ci; var dss = Cc["@mozilla.org/devicesensors;1"].getService(Ci.nsIDeviceSensors); - return dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_ORIENTATION, window); + return dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_ORIENTATION, window) || + dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_ROTATION_VECTOR, window) || + dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_GAME_ROTATION_VECTOR, window); } is(hasListeners(), false, "Must not have listeners before tests start"); diff --git a/dom/html/nsTextEditorState.cpp b/dom/html/nsTextEditorState.cpp index 634bca5e0c..1021da0b44 100644 --- a/dom/html/nsTextEditorState.cpp +++ b/dom/html/nsTextEditorState.cpp @@ -873,7 +873,7 @@ nsTextInputListener::HandleEvent(nsIDOMEvent* aEvent) } WidgetKeyboardEvent* keyEvent = - aEvent->GetInternalNSEvent()->AsKeyboardEvent(); + aEvent->WidgetEventPtr()->AsKeyboardEvent(); if (!keyEvent) { return NS_ERROR_UNEXPECTED; } diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 06994a4539..53a550ccb5 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -743,7 +743,7 @@ DispatchErrorEvent(IDBRequest* aRequest, MOZ_ASSERT(!transaction || transaction->IsOpen() || transaction->IsAborted()); if (transaction && transaction->IsOpen()) { - WidgetEvent* internalEvent = aEvent->GetInternalNSEvent(); + WidgetEvent* internalEvent = aEvent->WidgetEventPtr(); MOZ_ASSERT(internalEvent); if (internalEvent->mFlags.mExceptionHasBeenRisen) { @@ -816,7 +816,7 @@ DispatchSuccessEvent(ResultHelper* aResultHelper, MOZ_ASSERT_IF(transaction, transaction->IsOpen() || transaction->IsAborted()); - WidgetEvent* internalEvent = aEvent->GetInternalNSEvent(); + WidgetEvent* internalEvent = aEvent->WidgetEventPtr(); MOZ_ASSERT(internalEvent); if (transaction && diff --git a/dom/interfaces/events/nsIDOMEvent.idl b/dom/interfaces/events/nsIDOMEvent.idl index 1cd665a07c..786884022c 100644 --- a/dom/interfaces/events/nsIDOMEvent.idl +++ b/dom/interfaces/events/nsIDOMEvent.idl @@ -7,7 +7,7 @@ interface nsIDOMEventTarget; -[ptr] native WidgetEventPtr(mozilla::WidgetEvent); +[ptr] native WidgetEvent(mozilla::WidgetEvent); [ptr] native DOMEventPtr(mozilla::dom::Event); [ptr] native IPCMessagePtr(IPC::Message); [ptr] native ConstIPCMessagePtr(const IPC::Message); @@ -207,7 +207,7 @@ interface nsIDOMEvent : nsISupports [noscript] void duplicatePrivateData(); [noscript] void setTarget(in nsIDOMEventTarget aTarget); [notxpcom] boolean IsDispatchStopped(); - [notxpcom] WidgetEventPtr GetInternalNSEvent(); + [notxpcom] WidgetEvent WidgetEventPtr(); [noscript,notxpcom] void SetTrusted(in boolean aTrusted); [notxpcom] void Serialize(in IPCMessagePtr aMsg, in boolean aSerializeInterfaceType); diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index e171e1f6d2..1b5641a7ab 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -3075,7 +3075,7 @@ TabParent::LayerTreeUpdate(bool aActive) event->InitEvent(NS_LITERAL_STRING("MozLayerTreeCleared"), true, false); } event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; bool dummy; mFrameElement->DispatchEvent(event, &dummy); return true; @@ -3110,7 +3110,7 @@ TabParent::RecvRemotePaintIsReady() RefPtr event = NS_NewDOMEvent(mFrameElement, nullptr, nullptr); event->InitEvent(NS_LITERAL_STRING("MozAfterRemotePaint"), false, false); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; bool dummy; mFrameElement->DispatchEvent(event, &dummy); return true; diff --git a/dom/media/gmp/GMPService.cpp b/dom/media/gmp/GMPService.cpp index a81460fd19..f1bb914907 100644 --- a/dom/media/gmp/GMPService.cpp +++ b/dom/media/gmp/GMPService.cpp @@ -205,7 +205,7 @@ GeckoMediaPluginService::GMPCrashCallback::Run(const nsACString& aPluginName) RefPtr event = dom::PluginCrashedEvent::Constructor(document, NS_LITERAL_STRING("PluginCrashed"), init); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; EventDispatcher::DispatchDOMEvent(parentWindow, nullptr, event, nullptr, nullptr); } diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 56459f52e8..884dd77260 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -1665,7 +1665,7 @@ nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent) } #endif - WidgetEvent* theEvent = aFocusEvent->GetInternalNSEvent(); + WidgetEvent* theEvent = aFocusEvent->WidgetEventPtr(); if (theEvent) { WidgetGUIEvent focusEvent(theEvent->mFlags.mIsTrusted, theEvent->mMessage, nullptr); @@ -1707,7 +1707,7 @@ nsresult nsPluginInstanceOwner::DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent) if (mInstance) { WidgetKeyboardEvent* keyEvent = - aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->WidgetEventPtr()->AsKeyboardEvent(); if (keyEvent && keyEvent->mClass == eKeyboardEventClass) { nsEventStatus rv = ProcessEvent(*keyEvent); if (nsEventStatus_eConsumeNoDefault == rv) { @@ -1742,7 +1742,7 @@ nsPluginInstanceOwner::ProcessMouseDown(nsIDOMEvent* aMouseEvent) } WidgetMouseEvent* mouseEvent = - aMouseEvent->GetInternalNSEvent()->AsMouseEvent(); + aMouseEvent->WidgetEventPtr()->AsMouseEvent(); if (mouseEvent && mouseEvent->mClass == eMouseEventClass) { mLastMouseDownButtonType = mouseEvent->button; nsEventStatus rv = ProcessEvent(*mouseEvent); @@ -1767,7 +1767,7 @@ nsresult nsPluginInstanceOwner::DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent, return NS_OK; WidgetMouseEvent* mouseEvent = - aMouseEvent->GetInternalNSEvent()->AsMouseEvent(); + aMouseEvent->WidgetEventPtr()->AsMouseEvent(); if (mouseEvent && mouseEvent->mClass == eMouseEventClass) { nsEventStatus rv = ProcessEvent(*mouseEvent); if (nsEventStatus_eConsumeNoDefault == rv) { @@ -1882,7 +1882,7 @@ nsPluginInstanceOwner::DispatchCompositionToPlugin(nsIDOMEvent* aEvent) return NS_OK; } WidgetCompositionEvent* compositionEvent = - aEvent->GetInternalNSEvent()->AsCompositionEvent(); + aEvent->WidgetEventPtr()->AsCompositionEvent(); if (NS_WARN_IF(!compositionEvent)) { return NS_ERROR_INVALID_ARG; } @@ -2025,7 +2025,7 @@ nsPluginInstanceOwner::HandleEvent(nsIDOMEvent* aEvent) nsCOMPtr dragEvent(do_QueryInterface(aEvent)); if (dragEvent && mInstance) { - WidgetEvent* ievent = aEvent->GetInternalNSEvent(); + WidgetEvent* ievent = aEvent->WidgetEventPtr(); if (ievent && ievent->mFlags.mIsTrusted && ievent->mMessage != eDragEnter && ievent->mMessage != eDragOver) { aEvent->PreventDefault(); diff --git a/dom/system/nsDeviceSensors.cpp b/dom/system/nsDeviceSensors.cpp index 733e6c13fb..2665fc4abe 100644 --- a/dom/system/nsDeviceSensors.cpp +++ b/dom/system/nsDeviceSensors.cpp @@ -25,6 +25,8 @@ #include "mozilla/dom/DeviceProximityEvent.h" #include "mozilla/dom/UserProximityEvent.h" +#include + using namespace mozilla; using namespace mozilla::dom; using namespace hal; @@ -193,6 +195,67 @@ WindowCannotReceiveSensorEvent (nsPIDOMWindow* aWindow) return false; } +// Holds the device orientation in Euler angle degrees (azimuth, pitch, roll). +struct Orientation +{ + enum OrientationReference + { + kRelative = 0, + kAbsolute + }; + + static Orientation RadToDeg(const Orientation& aOrient) + { + const static double kRadToDeg = 180.0 / M_PI; + return { aOrient.alpha * kRadToDeg, + aOrient.beta * kRadToDeg, + aOrient.gamma * kRadToDeg }; + } + + double alpha; + double beta; + double gamma; +}; + +static Orientation +RotationVectorToOrientation(double aX, double aY, double aZ, double aW) +{ + static const double kFuzzyOne = 1.0 - 1e-6; + static const double kCircleRad = 2.0 * M_PI; + + Orientation orient = { 2.0 * std::atan2(aY, aW), + M_PI_2, + 0.0 }; + + const double sqX = aX * aX; + const double sqY = aY * aY; + const double sqZ = aZ * aZ; + const double sqW = aW * aW; + const double unitLength = sqX + sqY + sqZ + sqW; + const double xwyz = 2.0 * (aX * aW + aY * aZ) / unitLength; + + if (xwyz < -kFuzzyOne) { + orient.alpha *= -1.0; + orient.beta *= -1.0; + } else if (xwyz <= kFuzzyOne) { + const double gammaX = -sqX - sqY + sqZ + sqW; + const double gammaY = 2.0 * (aY * aW - aX * aZ); + const double alphaX = -sqX + sqY - sqZ + sqW; + const double alphaY = 2.0 * (aZ * aW - aX * aY); + const double fac = gammaX > 0 ? 1.0 : -1.0; + + orient.alpha = std::fmod(kCircleRad + std::atan2(fac * alphaY, fac * alphaX), + kCircleRad); + orient.beta = fac * std::asin(xwyz); + orient.gamma = std::atan2(fac * gammaY, fac * gammaX); + if (fac < 0.0) { + orient.beta = fmod(M_PI + orient.beta, M_PI); + } + } + + return Orientation::RadToDeg(orient); +} + void nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) { @@ -203,6 +266,7 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) double x = len > 0 ? values[0] : 0.0; double y = len > 1 ? values[1] : 0.0; double z = len > 2 ? values[2] : 0.0; + double w = len > 3 ? values[3] : 0.0; nsCOMArray windowListeners; for (uint32_t i = 0; i < mWindowListeners[type]->Length(); i++) { @@ -224,15 +288,23 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) nsCOMPtr target = do_QueryInterface(windowListeners[i]); if (type == nsIDeviceSensorData::TYPE_ACCELERATION || type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION || - type == nsIDeviceSensorData::TYPE_GYROSCOPE) + type == nsIDeviceSensorData::TYPE_GYROSCOPE) { FireDOMMotionEvent(domdoc, target, type, x, y, z); - else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) - FireDOMOrientationEvent(target, x, y, z); - else if (type == nsIDeviceSensorData::TYPE_PROXIMITY) + } else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) { + FireDOMOrientationEvent(target, x, y, z, Orientation::kAbsolute); + } else if (type == nsIDeviceSensorData::TYPE_ROTATION_VECTOR) { + const Orientation orient = RotationVectorToOrientation(x, y, z, w); + FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma, + Orientation::kAbsolute); + } else if (type == nsIDeviceSensorData::TYPE_GAME_ROTATION_VECTOR) { + const Orientation orient = RotationVectorToOrientation(x, y, z, w); + FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma, + Orientation::kRelative); + } else if (type == nsIDeviceSensorData::TYPE_PROXIMITY) { FireDOMProximityEvent(target, x, y, z); - else if (type == nsIDeviceSensorData::TYPE_LIGHT) + } else if (type == nsIDeviceSensorData::TYPE_LIGHT) { FireDOMLightEvent(target, x); - + } } } } @@ -310,7 +382,8 @@ void nsDeviceSensors::FireDOMOrientationEvent(EventTarget* aTarget, double aAlpha, double aBeta, - double aGamma) + double aGamma, + bool aIsAbsolute) { DeviceOrientationEventInit init; init.mBubbles = true; @@ -318,19 +391,37 @@ nsDeviceSensors::FireDOMOrientationEvent(EventTarget* aTarget, init.mAlpha.SetValue(aAlpha); init.mBeta.SetValue(aBeta); init.mGamma.SetValue(aGamma); - init.mAbsolute = true; + init.mAbsolute = aIsAbsolute; - RefPtr event = - DeviceOrientationEvent::Constructor(aTarget, - NS_LITERAL_STRING("deviceorientation"), - init); - event->SetTrusted(true); + auto Dispatch = [&](EventTarget* aEventTarget, const nsAString& aType) + { + RefPtr event = + DeviceOrientationEvent::Constructor(aEventTarget, aType, init); + event->SetTrusted(true); + bool dummy; + aEventTarget->DispatchEvent(event, &dummy); + }; - bool dummy; - aTarget->DispatchEvent(event, &dummy); + Dispatch(aTarget, aIsAbsolute ? NS_LITERAL_STRING("absolutedeviceorientation") : + NS_LITERAL_STRING("deviceorientation")); + + // This is used to determine whether relative events have been dispatched + // during the current session, in which case we don't dispatch the additional + // compatibility events. + static bool sIsDispatchingRelativeEvents = false; + sIsDispatchingRelativeEvents = sIsDispatchingRelativeEvents || !aIsAbsolute; + + // Android devices with SENSOR_GAME_ROTATION_VECTOR support dispatch + // relative events for "deviceorientation" by default, while other platforms + // and devices without such support dispatch absolute events by default. + if (aIsAbsolute && !sIsDispatchingRelativeEvents) { + // For absolute events on devices without support for relative events, + // we need to additionally dispatch type "deviceorientation" to keep + // backwards-compatibility. + Dispatch(aTarget, NS_LITERAL_STRING("deviceorientation")); + } } - void nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc, EventTarget* target, diff --git a/dom/system/nsDeviceSensors.h b/dom/system/nsDeviceSensors.h index 660658c3cd..6f7df48d9a 100644 --- a/dom/system/nsDeviceSensors.h +++ b/dom/system/nsDeviceSensors.h @@ -55,9 +55,10 @@ private: bool aNear); void FireDOMOrientationEvent(mozilla::dom::EventTarget* target, - double alpha, - double beta, - double gamma); + double aAlpha, + double aBeta, + double aGamma, + bool aIsAbsolute); void FireDOMMotionEvent(class nsIDOMDocument *domDoc, mozilla::dom::EventTarget* target, diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 4043ddcd00..cb6045f1cb 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -354,6 +354,7 @@ partial interface Window { attribute EventHandler ondevicemotion; attribute EventHandler ondeviceorientation; + attribute EventHandler onabsolutedeviceorientation; attribute EventHandler ondeviceproximity; attribute EventHandler onuserproximity; attribute EventHandler ondevicelight; diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 4827e3176d..21a37aa93b 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -264,7 +264,7 @@ public: MOZ_ASSERT(aWorkerScope); MOZ_ASSERT(aEvent); nsCOMPtr sgo = aWorkerScope; - WidgetEvent* internalEvent = aEvent->GetInternalNSEvent(); + WidgetEvent* internalEvent = aEvent->WidgetEventPtr(); ErrorResult result; result = aWorkerScope->DispatchDOMEvent(nullptr, aEvent, nullptr, nullptr); @@ -1263,7 +1263,7 @@ private: nsCOMPtr runnable; if (event->DefaultPrevented(aCx)) { event->ReportCanceled(); - } else if (event->GetInternalNSEvent()->mFlags.mExceptionHasBeenRisen) { + } else if (event->WidgetEventPtr()->mFlags.mExceptionHasBeenRisen) { // Exception logged via the WorkerPrivate ErrorReporter } else { runnable = new ResumeRequest(mInterceptedChannel); diff --git a/dom/xbl/nsXBLEventHandler.cpp b/dom/xbl/nsXBLEventHandler.cpp index 2522419f8e..064d672e4b 100644 --- a/dom/xbl/nsXBLEventHandler.cpp +++ b/dom/xbl/nsXBLEventHandler.cpp @@ -90,7 +90,7 @@ nsXBLKeyEventHandler::ExecuteMatchedHandlers( uint32_t aCharCode, const IgnoreModifierState& aIgnoreModifierState) { - WidgetEvent* event = aKeyEvent->AsEvent()->GetInternalNSEvent(); + WidgetEvent* event = aKeyEvent->AsEvent()->WidgetEventPtr(); nsCOMPtr target = aKeyEvent->AsEvent()->InternalDOMEvent()->GetCurrentTarget(); bool executed = false; diff --git a/dom/xbl/nsXBLPrototypeHandler.cpp b/dom/xbl/nsXBLPrototypeHandler.cpp index bdd7050369..e469c9745c 100644 --- a/dom/xbl/nsXBLPrototypeHandler.cpp +++ b/dom/xbl/nsXBLPrototypeHandler.cpp @@ -924,7 +924,7 @@ nsXBLPrototypeHandler::ModifiersMatchMask( nsIDOMUIEvent* aEvent, const IgnoreModifierState& aIgnoreModifierState) { - WidgetInputEvent* inputEvent = aEvent->AsEvent()->GetInternalNSEvent()->AsInputEvent(); + WidgetInputEvent* inputEvent = aEvent->AsEvent()->WidgetEventPtr()->AsInputEvent(); NS_ENSURE_TRUE(inputEvent, false); if (mKeyMask & cMetaMask) { diff --git a/dom/xbl/nsXBLWindowKeyHandler.cpp b/dom/xbl/nsXBLWindowKeyHandler.cpp index dda51272e2..388c3d20fd 100644 --- a/dom/xbl/nsXBLWindowKeyHandler.cpp +++ b/dom/xbl/nsXBLWindowKeyHandler.cpp @@ -322,14 +322,14 @@ void nsXBLWindowKeyHandler::HandleEventOnCapture(nsIDOMKeyEvent* aEvent) { WidgetKeyboardEvent* widgetEvent = - aEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); if (widgetEvent->mFlags.mNoCrossProcessBoundaryForwarding) { return; } nsCOMPtr originalTarget = - do_QueryInterface(aEvent->AsEvent()->GetInternalNSEvent()->originalTarget); + do_QueryInterface(aEvent->AsEvent()->WidgetEventPtr()->originalTarget); if (!EventStateManager::IsRemoteTarget(originalTarget)) { return; } @@ -565,7 +565,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute( // retry to look for a shortcut key without the Windows-Logo key press. if (!aIgnoreModifierState.mOS) { WidgetKeyboardEvent* keyEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); if (keyEvent && keyEvent->IsOS()) { IgnoreModifierState ignoreModifierState(aIgnoreModifierState); ignoreModifierState.mOS = true; diff --git a/editor/libeditor/nsEditor.cpp b/editor/libeditor/nsEditor.cpp index 13d3ec4715..14df2ef719 100644 --- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -4629,7 +4629,7 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) // HandleKeyPressEvent()'s switch statement. WidgetKeyboardEvent* nativeKeyEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED); NS_ASSERTION(nativeKeyEvent->mMessage == eKeyPress, "HandleKeyPressEvent gets non-keypress event"); @@ -5066,7 +5066,7 @@ nsEditor::IsAcceptableInputEvent(nsIDOMEvent* aEvent) // If the event is trusted, the event should always cause input. NS_ENSURE_TRUE(aEvent, false); - WidgetEvent* widgetEvent = aEvent->GetInternalNSEvent(); + WidgetEvent* widgetEvent = aEvent->WidgetEventPtr(); if (NS_WARN_IF(!widgetEvent)) { return false; } @@ -5099,7 +5099,7 @@ nsEditor::IsAcceptableInputEvent(nsIDOMEvent* aEvent) case eCompositionCommitAsIs: // Don't allow composition events whose internal event are not // WidgetCompositionEvent. - widgetGUIEvent = aEvent->GetInternalNSEvent()->AsCompositionEvent(); + widgetGUIEvent = aEvent->WidgetEventPtr()->AsCompositionEvent(); needsWidget = true; break; default: diff --git a/editor/libeditor/nsEditorEventListener.cpp b/editor/libeditor/nsEditorEventListener.cpp index f228da1ba9..a13174be53 100644 --- a/editor/libeditor/nsEditorEventListener.cpp +++ b/editor/libeditor/nsEditorEventListener.cpp @@ -357,7 +357,7 @@ nsEditorEventListener::HandleEvent(nsIDOMEvent* aEvent) nsCOMPtr kungFuDeathGrip = mEditor; - WidgetEvent* internalEvent = aEvent->GetInternalNSEvent(); + WidgetEvent* internalEvent = aEvent->WidgetEventPtr(); // Let's handle each event with the message of the internal event of the // coming event. If the DOM event was created with improper interface, @@ -641,7 +641,7 @@ nsEditorEventListener::KeyPress(nsIDOMKeyEvent* aKeyEvent) // Now, ask the native key bindings to handle the event. WidgetKeyboardEvent* keyEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); MOZ_ASSERT(keyEvent, "DOM key event's internal event must be WidgetKeyboardEvent"); nsIWidget* widget = keyEvent->widget; @@ -1047,7 +1047,7 @@ nsEditorEventListener::HandleStartComposition(nsIDOMEvent* aCompositionEvent) return NS_OK; } WidgetCompositionEvent* compositionStart = - aCompositionEvent->GetInternalNSEvent()->AsCompositionEvent(); + aCompositionEvent->WidgetEventPtr()->AsCompositionEvent(); return mEditor->BeginIMEComposition(compositionStart); } diff --git a/editor/libeditor/nsHTMLEditor.cpp b/editor/libeditor/nsHTMLEditor.cpp index a6fd8a38e9..640f855474 100644 --- a/editor/libeditor/nsHTMLEditor.cpp +++ b/editor/libeditor/nsHTMLEditor.cpp @@ -619,7 +619,7 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) } WidgetKeyboardEvent* nativeKeyEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED); NS_ASSERTION(nativeKeyEvent->mMessage == eKeyPress, "HandleKeyPressEvent gets non-keypress event"); @@ -5209,7 +5209,7 @@ nsHTMLEditor::IsAcceptableInputEvent(nsIDOMEvent* aEvent) // While there is composition, all composition events in its top level window // are always fired on the composing editor. Therefore, if this editor has // composition, the composition events should be handled in this editor. - if (mComposition && aEvent->GetInternalNSEvent()->AsCompositionEvent()) { + if (mComposition && aEvent->WidgetEventPtr()->AsCompositionEvent()) { return true; } diff --git a/editor/libeditor/nsPlaintextDataTransfer.cpp b/editor/libeditor/nsPlaintextDataTransfer.cpp index b3856ac2a3..9b0e0b8785 100644 --- a/editor/libeditor/nsPlaintextDataTransfer.cpp +++ b/editor/libeditor/nsPlaintextDataTransfer.cpp @@ -184,7 +184,7 @@ nsresult nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) } if (nsContentUtils::CheckForSubFrameDrop(dragSession, - aDropEvent->GetInternalNSEvent()->AsDragEvent())) { + aDropEvent->WidgetEventPtr()->AsDragEvent())) { // Don't allow drags from subframe documents with different origins than // the drop destination. if (srcdomdoc && !IsSafeToInsertData(srcdomdoc)) diff --git a/editor/libeditor/nsPlaintextEditor.cpp b/editor/libeditor/nsPlaintextEditor.cpp index 0edf24f3fc..65c37f037d 100644 --- a/editor/libeditor/nsPlaintextEditor.cpp +++ b/editor/libeditor/nsPlaintextEditor.cpp @@ -362,7 +362,7 @@ nsPlaintextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) } WidgetKeyboardEvent* nativeKeyEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED); NS_ASSERTION(nativeKeyEvent->mMessage == eKeyPress, "HandleKeyPressEvent gets non-keypress event"); @@ -848,7 +848,7 @@ nsPlaintextEditor::UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent) MOZ_ASSERT(aDOMTextEvent, "aDOMTextEvent must not be nullptr"); WidgetCompositionEvent* compositionChangeEvent = - aDOMTextEvent->GetInternalNSEvent()->AsCompositionEvent(); + aDOMTextEvent->WidgetEventPtr()->AsCompositionEvent(); NS_ENSURE_TRUE(compositionChangeEvent, NS_ERROR_INVALID_ARG); MOZ_ASSERT(compositionChangeEvent->mMessage == eCompositionChange, "The internal event should be eCompositionChange"); diff --git a/embedding/components/windowwatcher/nsAutoWindowStateHelper.cpp b/embedding/components/windowwatcher/nsAutoWindowStateHelper.cpp index 2f81b26a1b..ced5e2df76 100644 --- a/embedding/components/windowwatcher/nsAutoWindowStateHelper.cpp +++ b/embedding/components/windowwatcher/nsAutoWindowStateHelper.cpp @@ -63,7 +63,7 @@ nsAutoWindowStateHelper::DispatchEventToChrome(const char* aEventName) } event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; nsCOMPtr target = do_QueryInterface(mWindow); bool defaultActionEnabled; diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index b21b165949..7ca71298a3 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -94,11 +94,11 @@ ScrollFrameTo(nsIScrollableFrame* aFrame, const CSSPoint& aPoint, bool& aSuccess // If the scrollable frame is currently in the middle of an async or smooth // scroll then we don't want to interrupt it (see bug 961280). - // Also if the scrollable frame got a scroll request from something other than us + // Also if the scrollable frame got a scroll request from a higher priority origin // since the last layers update, then we don't want to push our scroll request // because we'll clobber that one, which is bad. bool scrollInProgress = aFrame->IsProcessingAsyncScroll() - || (aFrame->LastScrollOrigin() && aFrame->LastScrollOrigin() != nsGkAtoms::apz) + || nsLayoutUtils::CanScrollOriginClobberApz(aFrame->LastScrollOrigin()) || aFrame->LastSmoothScrollOrigin(); if (!scrollInProgress) { aFrame->ScrollToCSSPixelsApproximate(targetScrollPosition, nsGkAtoms::apz); diff --git a/layout/base/AccessibleCaretManager.cpp b/layout/base/AccessibleCaretManager.cpp index 771d8705f3..fa0504b10f 100644 --- a/layout/base/AccessibleCaretManager.cpp +++ b/layout/base/AccessibleCaretManager.cpp @@ -1175,7 +1175,7 @@ AccessibleCaretManager::DispatchCaretStateChangedEvent(CaretChangedReason aReaso CaretStateChangedEvent::Constructor(doc, NS_LITERAL_STRING("mozcaretstatechanged"), init); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; AC_LOG("%s: reason %d, collapsed %d, caretVisible %d", __FUNCTION__, init.mReason, init.mCollapsed, init.mCaretVisible); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 57d6d02e91..3d92c882e1 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -1176,7 +1176,7 @@ nsDocumentViewer::PermitUnloadInternal(bool aCallerClosesWindow, // the event being dispatched. if (!sIsBeforeUnloadDisabled && *aShouldPrompt && dialogsAreEnabled && mDocument && (!sBeforeUnloadRequiresInteraction || mDocument->UserHasInteracted()) && - (event->GetInternalNSEvent()->mFlags.mDefaultPrevented || + (event->WidgetEventPtr()->mFlags.mDefaultPrevented || !text.IsEmpty())) { // Ask the user if it's ok to unload the current page diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index b037b25373..2d069d16ac 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -2002,7 +2002,7 @@ nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame { if (!aDOMEvent) return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE); - WidgetEvent* event = aDOMEvent->GetInternalNSEvent(); + WidgetEvent* event = aDOMEvent->WidgetEventPtr(); if (!event) return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE); return GetEventCoordinatesRelativeTo(event, aFrame); @@ -8594,6 +8594,14 @@ nsLayoutUtils::SetScrollPositionClampingScrollPortSize(nsIPresShell* aPresShell, MaybeReflowForInflationScreenSizeChange(presContext); } +/* static */ bool +nsLayoutUtils::CanScrollOriginClobberApz(nsIAtom* aScrollOrigin) +{ + return aScrollOrigin != nullptr + && aScrollOrigin != nsGkAtoms::apz + && aScrollOrigin != nsGkAtoms::restore; +} + /* static */ FrameMetrics nsLayoutUtils::ComputeFrameMetrics(nsIFrame* aForFrame, nsIFrame* aScrollFrame, @@ -8650,11 +8658,10 @@ nsLayoutUtils::ComputeFrameMetrics(nsIFrame* aForFrame, nsPoint smoothScrollPosition = scrollableFrame->LastScrollDestination(); metrics.SetSmoothScrollOffset(CSSPoint::FromAppUnits(smoothScrollPosition)); - // If the frame was scrolled since the last layers update, and by - // something other than the APZ code, we want to tell the APZ to update + // If the frame was scrolled since the last layers update, and by something + // that is higher priority than APZ, we want to tell the APZ to update // its scroll offset. - nsIAtom* lastScrollOrigin = scrollableFrame->LastScrollOrigin(); - if (lastScrollOrigin && lastScrollOrigin != nsGkAtoms::apz) { + if (CanScrollOriginClobberApz(scrollableFrame->LastScrollOrigin())) { metrics.SetScrollOffsetUpdated(scrollableFrame->CurrentScrollGeneration()); } nsIAtom* lastSmoothScrollOrigin = scrollableFrame->LastSmoothScrollOrigin(); diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index fb236243f8..99f0c9b6e8 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2771,6 +2771,15 @@ public: static void SetScrollPositionClampingScrollPortSize(nsIPresShell* aPresShell, CSSSize aSize); + /** + * Returns true if the given scroll origin is "higher priority" than APZ. + * In general any content programmatic scrolls (e.g. scrollTo calls) are + * higher priority, and take precedence over APZ scrolling. This function + * returns true for those, and returns false for other origins like APZ + * itself, or scroll position updates from the history restore code. + */ + static bool CanScrollOriginClobberApz(nsIAtom* aScrollOrigin); + static FrameMetrics ComputeFrameMetrics(nsIFrame* aForFrame, nsIFrame* aScrollFrame, nsIContent* aContent, diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index a32ebff643..d0dfcb1332 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -1638,7 +1638,7 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent) // So we cheat here by either setting or unsetting the clcikCount in the native event // so the right thing happens for the onclick event WidgetMouseEvent* mouseEvent = - aMouseEvent->GetInternalNSEvent()->AsMouseEvent(); + aMouseEvent->WidgetEventPtr()->AsMouseEvent(); int32_t selectedIndex; if (NS_SUCCEEDED(GetIndexFromDOMEvent(aMouseEvent, selectedIndex))) { @@ -2126,7 +2126,7 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent) // XXXmats in onkeydown. That seems sub-optimal though. const WidgetKeyboardEvent* keyEvent = - aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->WidgetEventPtr()->AsKeyboardEvent(); MOZ_ASSERT(keyEvent, "DOM event must have WidgetKeyboardEvent for its internal event"); @@ -2279,7 +2279,7 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) AutoIncrementalSearchResetter incrementalSearchResetter; const WidgetKeyboardEvent* keyEvent = - aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->WidgetEventPtr()->AsKeyboardEvent(); MOZ_ASSERT(keyEvent, "DOM event must have WidgetKeyboardEvent for its internal event"); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index f4eb2a5bc7..779eac62a0 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1726,9 +1726,15 @@ private: void ScrollFrameHelper::AsyncScroll::InitPreferences(TimeStamp aTime, nsIAtom *aOrigin) { - if (!aOrigin){ + if (!aOrigin || aOrigin == nsGkAtoms::restore) { + // We don't have special prefs for "restore", just treat it as "other". + // "restore" scrolls are (for now) always instant anyway so unless something + // changes we should never have aOrigin == nsGkAtoms::restore here. aOrigin = nsGkAtoms::other; } + // Likewise we should never get APZ-triggered scrolls here, and if that changes + // something is likely broken somewhere. + MOZ_ASSERT(aOrigin != nsGkAtoms::apz); // Read preferences only on first iteration or for a different event origin. if (!mIsFirstIteration && aOrigin == mOrigin) { @@ -3793,7 +3799,8 @@ ScrollFrameHelper::ScrollToRestoredPosition() scrollToPos.x = mScrollPort.x - (mScrollPort.XMost() - scrollToPos.x - mScrolledFrame->GetRect().width); nsWeakFrame weakFrame(mOuter); - ScrollTo(scrollToPos, nsIScrollableFrame::INSTANT); + ScrollToWithOrigin(scrollToPos, nsIScrollableFrame::INSTANT, + nsGkAtoms::restore, nullptr); if (!weakFrame.IsAlive()) { return; } diff --git a/layout/printing/nsPrintPreviewListener.cpp b/layout/printing/nsPrintPreviewListener.cpp index 738b3d3231..6a028a9e84 100644 --- a/layout/printing/nsPrintPreviewListener.cpp +++ b/layout/printing/nsPrintPreviewListener.cpp @@ -112,7 +112,7 @@ static eEventAction GetActionForEvent(nsIDOMEvent* aEvent) { WidgetKeyboardEvent* keyEvent = - aEvent->GetInternalNSEvent()->AsKeyboardEvent(); + aEvent->WidgetEventPtr()->AsKeyboardEvent(); if (!keyEvent) { return eEventAction_Suppress; } diff --git a/layout/xul/nsMenuBarFrame.cpp b/layout/xul/nsMenuBarFrame.cpp index 05bee79e19..c45c2315e3 100644 --- a/layout/xul/nsMenuBarFrame.cpp +++ b/layout/xul/nsMenuBarFrame.cpp @@ -168,7 +168,7 @@ nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent) AutoTArray accessKeys; WidgetKeyboardEvent* nativeKeyEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent(); if (nativeKeyEvent) nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, accessKeys); if (accessKeys.IsEmpty() && charCode) diff --git a/layout/xul/nsMenuBarListener.cpp b/layout/xul/nsMenuBarListener.cpp index 9ee4b6c80a..f21db2bde0 100644 --- a/layout/xul/nsMenuBarListener.cpp +++ b/layout/xul/nsMenuBarListener.cpp @@ -198,7 +198,7 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent) bool hasAccessKeyCandidates = charCode != 0; if (!hasAccessKeyCandidates) { WidgetKeyboardEvent* nativeKeyEvent = - aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent(); + aKeyEvent->WidgetEventPtr()->AsKeyboardEvent(); if (nativeKeyEvent) { AutoTArray keys; nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, keys); @@ -273,7 +273,7 @@ Modifiers nsMenuBarListener::GetModifiersForAccessKey(nsIDOMKeyEvent* aKeyEvent) { WidgetInputEvent* inputEvent = - aKeyEvent->AsEvent()->GetInternalNSEvent()->AsInputEvent(); + aKeyEvent->AsEvent()->WidgetEventPtr()->AsInputEvent(); MOZ_ASSERT(inputEvent); static const Modifiers kPossibleModifiersForAccessKey = diff --git a/layout/xul/nsSliderFrame.cpp b/layout/xul/nsSliderFrame.cpp index f173770fb8..cb7a6e9e04 100644 --- a/layout/xul/nsSliderFrame.cpp +++ b/layout/xul/nsSliderFrame.cpp @@ -968,7 +968,7 @@ nsSliderFrame::StartDrag(nsIDOMEvent* aEvent) nsGkAtoms::_true, eCaseMatters)) return NS_OK; - WidgetGUIEvent* event = aEvent->GetInternalNSEvent()->AsGUIEvent(); + WidgetGUIEvent* event = aEvent->WidgetEventPtr()->AsGUIEvent(); if (!ShouldScrollForEvent(event)) { return NS_OK; diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp index cc0bdfa257..cf2fa32c6d 100644 --- a/layout/xul/nsXULPopupManager.cpp +++ b/layout/xul/nsXULPopupManager.cpp @@ -582,7 +582,7 @@ nsXULPopupManager::InitTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup, // get the event coordinates relative to the root frame of the document // containing the popup. NS_ASSERTION(aPopup, "Expected a popup node"); - WidgetEvent* event = aEvent->GetInternalNSEvent(); + WidgetEvent* event = aEvent->WidgetEventPtr(); if (event) { WidgetInputEvent* inputEvent = event->AsInputEvent(); if (inputEvent) { @@ -2008,7 +2008,7 @@ nsXULPopupManager::HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent, { // On Windows, don't check shortcuts when the accelerator key is down. #ifdef XP_WIN - WidgetInputEvent* evt = aKeyEvent->AsEvent()->GetInternalNSEvent()->AsInputEvent(); + WidgetInputEvent* evt = aKeyEvent->AsEvent()->WidgetEventPtr()->AsInputEvent(); if (evt && evt->IsAccel()) { return false; } @@ -2024,7 +2024,7 @@ nsXULPopupManager::HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent, if (result) { aFrame->ChangeMenuItem(result, false, true); if (action) { - WidgetGUIEvent* evt = aKeyEvent->AsEvent()->GetInternalNSEvent()->AsGUIEvent(); + WidgetGUIEvent* evt = aKeyEvent->AsEvent()->WidgetEventPtr()->AsGUIEvent(); nsMenuFrame* menuToOpen = result->Enter(evt); if (menuToOpen) { nsCOMPtr content = menuToOpen->GetContent(); @@ -2271,7 +2271,7 @@ nsXULPopupManager::HandleKeyboardEventWithKeyCode( // Enter method will return a menu if one needs to be opened as a result. nsMenuFrame* menuToOpen = nullptr; WidgetGUIEvent* GUIEvent = aKeyEvent->AsEvent()-> - GetInternalNSEvent()->AsGUIEvent(); + WidgetEventPtr()->AsGUIEvent(); if (aTopVisibleMenuItem) { menuToOpen = aTopVisibleMenuItem->Frame()->Enter(GUIEvent); diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp index 417c76c674..9792b3d96f 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ -2520,7 +2520,7 @@ PeerConnectionImpl::PluginCrash(uint32_t aPluginID, PluginCrashedEvent::Constructor(doc, NS_LITERAL_STRING("PluginCrashed"), init); event->SetTrusted(true); - event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; EventDispatcher::DispatchDOMEvent(mWindow, nullptr, event, nullptr, nullptr); #endif diff --git a/widget/EventMessageList.h b/widget/EventMessageList.h index 5b1be3e729..4099f3bfc3 100644 --- a/widget/EventMessageList.h +++ b/widget/EventMessageList.h @@ -338,6 +338,7 @@ NS_EVENT_MESSAGE(eOpen) // Device motion and orientation NS_EVENT_MESSAGE(eDeviceOrientation) +NS_EVENT_MESSAGE(eAbsoluteDeviceOrientation) NS_EVENT_MESSAGE(eDeviceMotion) NS_EVENT_MESSAGE(eDeviceProximity) NS_EVENT_MESSAGE(eUserProximity) diff --git a/xpcom/system/nsIDeviceSensors.idl b/xpcom/system/nsIDeviceSensors.idl index f6ad25d151..dcb67cb925 100644 --- a/xpcom/system/nsIDeviceSensors.idl +++ b/xpcom/system/nsIDeviceSensors.idl @@ -6,16 +6,25 @@ interface nsIDOMWindow; -[scriptable, uuid(1B406E32-CF42-471E-A470-6FD600BF4C7B)] +[scriptable, uuid(0462247e-fe8c-4aa5-b675-3752547e485f)] interface nsIDeviceSensorData : nsISupports { // Keep in sync with hal/HalSensor.h + + // 1. TYPE_ORIENTATION: absolute device orientation, not spec-conform and + // deprecated on Android. + // 2. TYPE_ROTATION_VECTOR: absolute device orientation affected by drift. + // 3. TYPE_GAME_ROTATION_VECTOR: relative device orientation less affected by drift. + // Preferred fallback priorities on Android are [3, 2, 1] for the general case + // and [2, 1] if absolute orientation (compass heading) is required. 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_LIGHT = 5; + const unsigned long TYPE_ROTATION_VECTOR = 6; + const unsigned long TYPE_GAME_ROTATION_VECTOR = 7; readonly attribute unsigned long type;