commit 268969d4a8096d6572447e0b03893ea7146797a2
parent 51e7067f2ffc7465465df75edd064f41882a69fd
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date: Wed, 17 Dec 2025 05:01:35 +0000
Bug 2003978 - screen.addEventListenr("mozorientation") should show deprecated warning. r=masayuki
Follow up bug 2003169. Although I added a deprecated warning for legacy
`mozOrientation` event by it, I should follow up `addEventListener`
too.
Differential Revision: https://phabricator.services.mozilla.com/D276575
Diffstat:
5 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/dom/base/nsScreen.h b/dom/base/nsScreen.h
@@ -84,6 +84,8 @@ class nsScreen : public mozilla::DOMEventTargetHelper {
return mScreenOrientation.get();
}
+ bool IsScreen() const override { return true; }
+
protected:
nsDeviceContext* GetDeviceContext() const;
mozilla::CSSIntRect GetRect();
@@ -101,4 +103,26 @@ class nsScreen : public mozilla::DOMEventTargetHelper {
RefPtr<mozilla::dom::ScreenOrientation> mScreenOrientation;
};
+namespace mozilla::dom {
+
+inline nsScreen* EventTarget::GetAsScreen() {
+ return IsScreen() ? AsScreen() : nullptr;
+}
+
+inline const nsScreen* EventTarget::GetAsScreen() const {
+ return IsScreen() ? AsScreen() : nullptr;
+}
+
+inline nsScreen* EventTarget::AsScreen() {
+ MOZ_DIAGNOSTIC_ASSERT(IsScreen());
+ return static_cast<nsScreen*>(this);
+}
+
+inline const nsScreen* EventTarget::AsScreen() const {
+ MOZ_DIAGNOSTIC_ASSERT(IsScreen());
+ return static_cast<const nsScreen*>(this);
+}
+
+} // namespace mozilla::dom
+
#endif /* nsScreen_h___ */
diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp
@@ -62,6 +62,7 @@
#include "nsPIWindowRoot.h"
#include "nsPrintfCString.h"
#include "nsSandboxFlags.h"
+#include "nsScreen.h"
#include "xpcpublic.h"
namespace mozilla {
@@ -464,6 +465,16 @@ void EventListenerManager::AddEventListenerInternal(
case eFormRadioStateChange:
nsContentUtils::SetMayHaveFormRadioStateChangeListeners();
break;
+ case eMozOrientationChange:
+ if (nsScreen* screen = mTarget->GetAsScreen()) {
+ if (nsPIDOMWindowOuter* outer = screen->GetOuter()) {
+ if (Document* doc = outer->GetExtantDoc()) {
+ doc->WarnOnceAbout(
+ DeprecatedOperations::eMozorientationchangeDeprecated);
+ }
+ }
+ }
+ break;
default:
// XXX Use NS_ASSERTION here to print resolvedEventMessage since
// MOZ_ASSERT can take only string literal, not pointer to
@@ -553,6 +564,10 @@ void EventListenerManager::AddEventListenerInternal(
nsPrintfCString("resolvedEventMessage=%s",
ToChar(resolvedEventMessage))
.get());
+ NS_ASSERTION(aTypeAtom != nsGkAtoms::onmozorientationchange,
+ nsPrintfCString("resolvedEventMessage=%s",
+ ToChar(resolvedEventMessage))
+ .get());
break;
}
}
diff --git a/dom/events/EventNameList.h b/dom/events/EventNameList.h
@@ -542,6 +542,9 @@ NON_IDL_EVENT(complete, eAudioComplete, EventNameType_None, eBasicEventClass)
EVENT(scrollend, eScrollend, EventNameType_All, eBasicEventClass)
+EVENT(mozorientationchange, eMozOrientationChange, EventNameType_All,
+ eBasicEventClass)
+
#ifdef DEFINED_FORWARDED_EVENT
# undef DEFINED_FORWARDED_EVENT
# undef FORWARDED_EVENT
diff --git a/dom/events/EventTarget.h b/dom/events/EventTarget.h
@@ -18,6 +18,7 @@ class nsINode;
class nsPIDOMWindowInner;
class nsPIDOMWindowOuter;
class nsPIWindowRoot;
+class nsScreen;
namespace mozilla {
@@ -144,6 +145,12 @@ class EventTarget : public nsISupports, public nsWrapperCache {
inline Navigation* AsNavigation();
inline const Navigation* AsNavigation() const;
+ virtual bool IsScreen() const { return false; }
+ inline nsScreen* GetAsScreen();
+ inline const nsScreen* GetAsScreen() const;
+ inline nsScreen* AsScreen();
+ inline const nsScreen* AsScreen() const;
+
virtual bool IsInnerWindow() const { return false; }
virtual bool IsOuterWindow() const { return false; }
virtual bool IsRootWindow() const { return false; }
diff --git a/widget/EventMessageList.h b/widget/EventMessageList.h
@@ -504,6 +504,9 @@ NS_EVENT_MESSAGE(eWaitingForKey)
NS_EVENT_MESSAGE(eScrollend)
+// Legacy orientatipon events.
+NS_EVENT_MESSAGE(eMozOrientationChange)
+
#ifdef UNDEF_NS_EVENT_MESSAGE_FIRST_LAST
# undef UNDEF_NS_EVENT_MESSAGE_FIRST_LAST
# undef NS_EVENT_MESSAGE_FIRST_LAST