From a7bc62dcfe5495c8b53532c1b585af07171b4403 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 26 Jun 2018 13:53:12 +0200 Subject: Issue #12 Part 2: Stop using nsIDOMEvent in IsAcceptableInputEvent. --- widget/BasicEvents.h | 6 ++++++ widget/WidgetEventImpl.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'widget') diff --git a/widget/BasicEvents.h b/widget/BasicEvents.h index a6228f179..f24d7ca8a 100644 --- a/widget/BasicEvents.h +++ b/widget/BasicEvents.h @@ -407,10 +407,16 @@ public: nsString mSpecifiedEventTypeString; // Event targets, needed by DOM Events + // Note that when you need event target for DOM event, you should use + // Get*DOMEventTarget() instead of accessing these members directly. nsCOMPtr mTarget; nsCOMPtr mCurrentTarget; nsCOMPtr mOriginalTarget; + dom::EventTarget* GetDOMEventTarget() const; + dom::EventTarget* GetCurrentDOMEventTarget() const; + dom::EventTarget* GetOriginalDOMEventTarget() const; + void AssignEventData(const WidgetEvent& aEvent, bool aCopyTargets) { // mClass should be initialized with the constructor. diff --git a/widget/WidgetEventImpl.cpp b/widget/WidgetEventImpl.cpp index 7dd292cb0..59c80672b 100644 --- a/widget/WidgetEventImpl.cpp +++ b/widget/WidgetEventImpl.cpp @@ -12,6 +12,7 @@ #include "mozilla/Preferences.h" #include "mozilla/TextEvents.h" #include "mozilla/TouchEvents.h" +#include "nsIDOMEventTarget.h" #include "nsPrintfCString.h" namespace mozilla { @@ -410,6 +411,39 @@ WidgetEvent::IsAllowedToDispatchDOMEvent() const } } +/****************************************************************************** + * mozilla::WidgetEvent + * + * Misc methods. + ******************************************************************************/ + +static dom::EventTarget* +GetTargetForDOMEvent(nsIDOMEventTarget* aTarget) +{ + return aTarget ? aTarget->GetTargetForDOMEvent() : nullptr; +} + +dom::EventTarget* +WidgetEvent::GetDOMEventTarget() const +{ + return GetTargetForDOMEvent(mTarget); +} + +dom::EventTarget* +WidgetEvent::GetCurrentDOMEventTarget() const +{ + return GetTargetForDOMEvent(mCurrentTarget); +} + +dom::EventTarget* +WidgetEvent::GetOriginalDOMEventTarget() const +{ + if (mOriginalTarget) { + return GetTargetForDOMEvent(mOriginalTarget); + } + return GetDOMEventTarget(); +} + /****************************************************************************** * mozilla::WidgetInputEvent ******************************************************************************/ -- cgit v1.2.3 From 783b60aae187d75c8c1924eceec8c4c56aa40c5e Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 26 Jun 2018 14:07:51 +0200 Subject: Issue #12 Part 5: WidgetEvent shouldn't mark event as consumed if it's not cancelable. Currently, EventListenerManager calls WidgetEvent::PreventDefault() when the status is nsEventStatus_eConsumeNoDefault. That causes an unexpected state of events. To solve this, WidgetEvent should do nothing when it's not cancelable but PreventDefault() is called. --- widget/BasicEvents.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'widget') diff --git a/widget/BasicEvents.h b/widget/BasicEvents.h index f24d7ca8a..960cb67c6 100644 --- a/widget/BasicEvents.h +++ b/widget/BasicEvents.h @@ -161,6 +161,9 @@ public: } inline void PreventDefault(bool aCalledByDefaultHandler = true) { + if (!mCancelable) { + return; + } mDefaultPrevented = true; // Note that even if preventDefault() has already been called by chrome, // a call of preventDefault() by content needs to overwrite @@ -175,6 +178,9 @@ public: // This should be used only before dispatching events into the DOM tree. inline void PreventDefaultBeforeDispatch() { + if (!mCancelable) { + return; + } mDefaultPrevented = true; } inline bool DefaultPrevented() const -- cgit v1.2.3