diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2023-03-26 18:34:04 +0800 |
---|---|---|
committer | FranklinDM <franklindm@no-reply.palemoon.org> | 2023-04-08 00:20:48 +0000 |
commit | 78e4526d55adc049eacc6031fafd66fbe9a7e315 (patch) | |
tree | 4ed5780064051bd9b8c0d4be5d1bebfcb65d0f44 /dom/base | |
parent | c01fd8ec19ea7f170cf56241ce2ee803f4e2adc2 (diff) | |
download | uxp-78e4526d55adc049eacc6031fafd66fbe9a7e315.tar.gz |
Issue #595 - Implement window.event
This MSIE extension is still technically part of the standard*, although its use is discouraged. This API will also likely never go away based on some comments at this issue on MDN content**.
Note that this uses a different approach for getting the inner window.
* https://dom.spec.whatwg.org/#interface-window-extensions
** https://github.com/mdn/content/issues/21848
Spec PR: https://github.com/whatwg/dom/pull/407
Spec discussion: https://github.com/whatwg/dom/issues/334
Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=218415
Diffstat (limited to 'dom/base')
-rw-r--r-- | dom/base/FragmentOrElement.cpp | 4 | ||||
-rw-r--r-- | dom/base/nsGlobalWindow.cpp | 13 | ||||
-rw-r--r-- | dom/base/nsGlobalWindow.h | 1 | ||||
-rw-r--r-- | dom/base/nsPIDOMWindow.h | 15 |
4 files changed, 32 insertions, 1 deletions
diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 412031f98a..ccfe960cb7 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -820,6 +820,10 @@ nsIContent::GetEventTargetParent(EventChainPreVisitor& aVisitor) aVisitor.mCanHandle = true; aVisitor.mMayHaveListenerManager = HasListenerManager(); + if (IsInShadowTree()) { + aVisitor.mItemInShadowTree = true; + } + // Don't propagate mouseover and mouseout events when mouse is moving // inside chrome access only content. bool isAnonForEvents = IsRootOfChromeAccessOnlySubtree(); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index c6b35a9bf0..01023f3a2d 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -907,7 +907,8 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow) mOuterWindow(aOuterWindow), // Make sure no actual window ends up with mWindowID == 0 mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false), - mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false) + mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false), + mEvent(nullptr) {} template<class T> @@ -5244,6 +5245,16 @@ nsGlobalWindow::SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener, } void +nsGlobalWindow::GetEvent(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval) +{ + if (mEvent) { + Unused << nsContentUtils::WrapNative(aCx, mEvent, aRetval); + } else { + aRetval.setUndefined(); + } +} + +void nsGlobalWindow::GetStatusOuter(nsAString& aStatus) { MOZ_RELEASE_ASSERT(IsOuterWindow()); diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index e42835a0b2..e593890af0 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -845,6 +845,7 @@ public: already_AddRefed<nsPIDOMWindowOuter> GetOpener() override; void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener, mozilla::ErrorResult& aError); + void GetEvent(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval); already_AddRefed<nsPIDOMWindowOuter> GetParentOuter(); already_AddRefed<nsPIDOMWindowOuter> GetParent(mozilla::ErrorResult& aError); already_AddRefed<nsPIDOMWindowOuter> GetParent() override; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 21eb4cff7f..ffebf6570d 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -194,6 +194,10 @@ protected: // we have what it takes to do so. void MaybeCreateDoc(); + // The event dispatch code sets and unsets this while keeping + // the event object alive. + nsIDOMEvent* mEvent; + public: inline bool IsLoadingOrRunningTimeout() const; @@ -789,6 +793,17 @@ public: return mInnerObjectsFreed; } + // Sets the event for window.event. Does NOT take ownership, so + // the caller is responsible for clearing the event before the + // event gets deallocated. Pass nullptr to set window.event to + // undefined. Returns the previous value. + nsIDOMEvent* SetEvent(nsIDOMEvent* aEvent) + { + nsIDOMEvent* old = mEvent; + mEvent = aEvent; + return old; + } + /** * Check whether this window is a secure context. */ |