Allow event dispatch on disabled form controls.

master
Fedor 2020-06-21 00:21:29 +03:00 committed by Fedor
parent e2b2bd0a7c
commit 2f4f7d8270
14 changed files with 35 additions and 26 deletions

View File

@ -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;
}

View File

@ -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::GetEventTargetParent(EventChainPreVisitor& aVisitor)
{
aVisitor.mCanHandle = false;
if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) {
if (IsDisabledForEvents(aVisitor.mEvent)) {
return NS_OK;
}

View File

@ -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;

View File

@ -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::GetEventTargetParent(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;
}

View File

@ -55,7 +55,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; }

View File

@ -3712,9 +3712,9 @@ HTMLInputElement::NeedToInitializeEditorForEvent(
}
bool
HTMLInputElement::IsDisabledForEvents(EventMessage aMessage)
HTMLInputElement::IsDisabledForEvents(WidgetEvent* aEvent)
{
return IsElementDisabledForEvents(aMessage, GetPrimaryFrame());
return IsElementDisabledForEvents(aEvent, GetPrimaryFrame());
}
nsresult
@ -3722,7 +3722,7 @@ HTMLInputElement::GetEventTargetParent(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;
}

View File

@ -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;

View File

@ -1419,21 +1419,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::GetEventTargetParent(EventChainPreVisitor& aVisitor)
{
aVisitor.mCanHandle = false;
if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) {
if (IsDisabledForEvents(aVisitor.mEvent)) {
return NS_OK;
}

View File

@ -294,7 +294,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;

View File

@ -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::GetEventTargetParent(EventChainPreVisitor& aVisitor)
{
aVisitor.mCanHandle = false;
if (IsDisabledForEvents(aVisitor.mEvent->mMessage)) {
if (IsDisabledForEvents(aVisitor.mEvent)) {
return NS_OK;
}

View File

@ -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;

View File

@ -2285,10 +2285,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:
@ -2454,8 +2461,9 @@ nsGenericHTMLFormElement::IsLabelable() const
void
nsGenericHTMLElement::Click()
{
if (HandlingClick())
if (IsDisabled() || HandlingClick()) {
return;
}
// Strong in case the event kills it
nsCOMPtr<nsIDocument> doc = GetComposedDoc();

View File

@ -1307,7 +1307,7 @@ protected:
void* aData);
// Returns true if the event should not be handled from GetEventTargetParent
bool IsElementDisabledForEvents(mozilla::EventMessage aMessage,
bool IsElementDisabledForEvents(mozilla::WidgetEvent* aEvent,
nsIFrame* aFrame);
// The focusability state of this form control. eUnfocusable means that it

View File

@ -207,7 +207,7 @@ public:
*/
inline bool AllowDraggableChildren() const;
virtual bool IsDisabledForEvents(mozilla::EventMessage aMessage)
virtual bool IsDisabledForEvents(mozilla::WidgetEvent* aEvent)
{
return false;
}