diff options
author | athenian200 <athenian200@outlook.com> | 2020-05-21 01:31:48 -0500 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-05-23 16:12:59 +0200 |
commit | 5e98d0d0966f1b10406ed23afc9f6e1521d04f51 (patch) | |
tree | ed44abb0edc3aa974e7bb933da244409c985ced5 | |
parent | 2f31509c7054b2810213f962f1f38e5ce1f44023 (diff) | |
download | uxp-5e98d0d0966f1b10406ed23afc9f6e1521d04f51.tar.gz |
Issue mcp-graveyard/UXP#1557 - Allow event dispatch on disabled form controls. (uplift)
-rw-r--r-- | dom/base/nsDOMWindowUtils.cpp | 3 | ||||
-rw-r--r-- | dom/html/HTMLButtonElement.cpp | 6 | ||||
-rw-r--r-- | dom/html/HTMLButtonElement.h | 2 | ||||
-rw-r--r-- | dom/html/HTMLFieldSetElement.cpp | 6 | ||||
-rw-r--r-- | dom/html/HTMLFieldSetElement.h | 2 | ||||
-rw-r--r-- | dom/html/HTMLInputElement.cpp | 6 | ||||
-rw-r--r-- | dom/html/HTMLInputElement.h | 2 | ||||
-rw-r--r-- | dom/html/HTMLSelectElement.cpp | 6 | ||||
-rw-r--r-- | dom/html/HTMLSelectElement.h | 2 | ||||
-rw-r--r-- | dom/html/HTMLTextAreaElement.cpp | 6 | ||||
-rw-r--r-- | dom/html/HTMLTextAreaElement.h | 2 | ||||
-rw-r--r-- | dom/html/nsGenericHTMLElement.cpp | 14 | ||||
-rw-r--r-- | dom/html/nsGenericHTMLElement.h | 2 | ||||
-rw-r--r-- | dom/html/nsIFormControl.h | 2 |
14 files changed, 35 insertions, 26 deletions
diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 2ab5937ace..adb407a043 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3577,7 +3577,8 @@ nsDOMWindowUtils::IsNodeDisabledForEvents(nsIDOMNode* aNode, bool* aRetVal) while (node) { if (node->IsNodeOfType(nsINode::eHTML_FORM_CONTROL)) { nsCOMPtr<nsIFormControl> fc = do_QueryInterface(node); - if (fc && fc->IsDisabledForEvents(eVoidEvent)) { + WidgetEvent event(true, eVoidEvent); + if (fc && fc->IsDisabledForEvents(&event)) { *aRetVal = true; break; } diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp index 435aa9f7fd..609eb7a66d 100644 --- a/dom/html/HTMLButtonElement.cpp +++ b/dom/html/HTMLButtonElement.cpp @@ -199,18 +199,18 @@ HTMLButtonElement::ParseAttribute(int32_t aNamespaceID, } bool -HTMLButtonElement::IsDisabledForEvents(EventMessage aMessage) +HTMLButtonElement::IsDisabledForEvents(WidgetEvent* aEvent) { nsIFormControlFrame* formControlFrame = GetFormControlFrame(false); nsIFrame* formFrame = do_QueryFrame(formControlFrame); - return IsElementDisabledForEvents(aMessage, formFrame); + return IsElementDisabledForEvents(aEvent, formFrame); } nsresult HTMLButtonElement::PreHandleEvent(EventChainPreVisitor& aVisitor) { aVisitor.mCanHandle = false; - if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) { + if (IsDisabledForEvents(aVisitor.mEvent)) { return NS_OK; } diff --git a/dom/html/HTMLButtonElement.h b/dom/html/HTMLButtonElement.h index ecd9e03d73..d15d11b6de 100644 --- a/dom/html/HTMLButtonElement.h +++ b/dom/html/HTMLButtonElement.h @@ -52,7 +52,7 @@ public: NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SaveState() override; bool RestoreState(nsPresState* aState) override; - virtual bool IsDisabledForEvents(EventMessage aMessage) override; + virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/HTMLFieldSetElement.cpp b/dom/html/HTMLFieldSetElement.cpp index d72fd1061a..788d887912 100644 --- a/dom/html/HTMLFieldSetElement.cpp +++ b/dom/html/HTMLFieldSetElement.cpp @@ -63,9 +63,9 @@ NS_IMPL_STRING_ATTR(HTMLFieldSetElement, Name, name) NS_IMPL_NSICONSTRAINTVALIDATION(HTMLFieldSetElement) bool -HTMLFieldSetElement::IsDisabledForEvents(EventMessage aMessage) +HTMLFieldSetElement::IsDisabledForEvents(WidgetEvent* aEvent) { - return IsElementDisabledForEvents(aMessage, nullptr); + return IsElementDisabledForEvents(aEvent, nullptr); } // nsIContent @@ -74,7 +74,7 @@ HTMLFieldSetElement::PreHandleEvent(EventChainPreVisitor& aVisitor) { // Do not process any DOM events if the element is disabled. aVisitor.mCanHandle = false; - if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) { + if (IsDisabledForEvents(aVisitor.mEvent)) { return NS_OK; } diff --git a/dom/html/HTMLFieldSetElement.h b/dom/html/HTMLFieldSetElement.h index 96fff4582b..4a4ab71e42 100644 --- a/dom/html/HTMLFieldSetElement.h +++ b/dom/html/HTMLFieldSetElement.h @@ -52,7 +52,7 @@ public: NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_FIELDSET; } NS_IMETHOD Reset() override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; - virtual bool IsDisabledForEvents(EventMessage aMessage) override; + virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override; virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; const nsIContent* GetFirstLegend() const { return mFirstLegend; } diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 0b879bb9b4..7a07994f74 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -3732,9 +3732,9 @@ HTMLInputElement::NeedToInitializeEditorForEvent( } bool -HTMLInputElement::IsDisabledForEvents(EventMessage aMessage) +HTMLInputElement::IsDisabledForEvents(WidgetEvent* aEvent) { - return IsElementDisabledForEvents(aMessage, GetPrimaryFrame()); + return IsElementDisabledForEvents(aEvent, GetPrimaryFrame()); } nsresult @@ -3742,7 +3742,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor) { // Do not process any DOM events if the element is disabled aVisitor.mCanHandle = false; - if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) { + if (IsDisabledForEvents(aVisitor.mEvent)) { return NS_OK; } diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 98a5904437..a000aa21d4 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -169,7 +169,7 @@ public: NS_IMETHOD SaveState() override; virtual bool RestoreState(nsPresState* aState) override; virtual bool AllowDrop() override; - virtual bool IsDisabledForEvents(EventMessage aMessage) override; + virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index 9ba0a1efe9..e1bc0ca620 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -1431,21 +1431,21 @@ HTMLSelectElement::GetAttributeMappingFunction() const } bool -HTMLSelectElement::IsDisabledForEvents(EventMessage aMessage) +HTMLSelectElement::IsDisabledForEvents(WidgetEvent* aEvent) { nsIFormControlFrame* formControlFrame = GetFormControlFrame(false); nsIFrame* formFrame = nullptr; if (formControlFrame) { formFrame = do_QueryFrame(formControlFrame); } - return IsElementDisabledForEvents(aMessage, formFrame); + return IsElementDisabledForEvents(aEvent, formFrame); } nsresult HTMLSelectElement::PreHandleEvent(EventChainPreVisitor& aVisitor) { aVisitor.mCanHandle = false; - if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) { + if (IsDisabledForEvents(aVisitor.mEvent)) { return NS_OK; } diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h index dc1075cd7d..b9041c8854 100644 --- a/dom/html/HTMLSelectElement.h +++ b/dom/html/HTMLSelectElement.h @@ -293,7 +293,7 @@ public: NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SaveState() override; virtual bool RestoreState(nsPresState* aState) override; - virtual bool IsDisabledForEvents(EventMessage aMessage) override; + virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp index 42bc02435e..4c40c16f3f 100644 --- a/dom/html/HTMLTextAreaElement.cpp +++ b/dom/html/HTMLTextAreaElement.cpp @@ -498,18 +498,18 @@ HTMLTextAreaElement::GetAttributeMappingFunction() const } bool -HTMLTextAreaElement::IsDisabledForEvents(EventMessage aMessage) +HTMLTextAreaElement::IsDisabledForEvents(WidgetEvent* aEvent) { nsIFormControlFrame* formControlFrame = GetFormControlFrame(false); nsIFrame* formFrame = do_QueryFrame(formControlFrame); - return IsElementDisabledForEvents(aMessage, formFrame); + return IsElementDisabledForEvents(aEvent, formFrame); } nsresult HTMLTextAreaElement::PreHandleEvent(EventChainPreVisitor& aVisitor) { aVisitor.mCanHandle = false; - if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) { + if (IsDisabledForEvents(aVisitor.mEvent)) { return NS_OK; } diff --git a/dom/html/HTMLTextAreaElement.h b/dom/html/HTMLTextAreaElement.h index 0390828182..90fb680c50 100644 --- a/dom/html/HTMLTextAreaElement.h +++ b/dom/html/HTMLTextAreaElement.h @@ -77,7 +77,7 @@ public: NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SaveState() override; virtual bool RestoreState(nsPresState* aState) override; - virtual bool IsDisabledForEvents(EventMessage aMessage) override; + virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 2f890325ad..1e2f1c1860 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -2286,10 +2286,17 @@ nsGenericHTMLFormElement::FormIdUpdated(Element* aOldElement, } bool -nsGenericHTMLFormElement::IsElementDisabledForEvents(EventMessage aMessage, +nsGenericHTMLFormElement::IsElementDisabledForEvents(WidgetEvent* aEvent, nsIFrame* aFrame) { - switch (aMessage) { + MOZ_ASSERT(aEvent); + + // Allow dispatch of CustomEvent and untrusted Events. + if (!aEvent->IsTrusted()) { + return false; + } + + switch (aEvent->mMessage) { case eMouseMove: case eMouseOver: case eMouseOut: @@ -2455,8 +2462,9 @@ nsGenericHTMLFormElement::IsLabelable() const void nsGenericHTMLElement::Click() { - if (HandlingClick()) + if (IsDisabled() || HandlingClick()) { return; + } // Strong in case the event kills it nsCOMPtr<nsIDocument> doc = GetComposedDoc(); diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 72039f2661..23fabc4e88 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -1308,7 +1308,7 @@ protected: void* aData); // Returns true if the event should not be handled from PreHandleEvent - bool IsElementDisabledForEvents(mozilla::EventMessage aMessage, + bool IsElementDisabledForEvents(mozilla::WidgetEvent* aEvent, nsIFrame* aFrame); // The focusability state of this form control. eUnfocusable means that it diff --git a/dom/html/nsIFormControl.h b/dom/html/nsIFormControl.h index 34380bc679..22f1d08b3a 100644 --- a/dom/html/nsIFormControl.h +++ b/dom/html/nsIFormControl.h @@ -207,7 +207,7 @@ public: */ inline bool AllowDraggableChildren() const; - virtual bool IsDisabledForEvents(mozilla::EventMessage aMessage) + virtual bool IsDisabledForEvents(mozilla::WidgetEvent* aEvent) { return false; } |