Bug 1677254 - Make select event from select() uncancelable r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D97068
This commit is contained in:
Kagami Sascha Rosylight 2020-11-15 02:32:22 +00:00
parent 41e5dcf390
commit 0c28c71544
5 changed files with 18 additions and 46 deletions

View File

@ -3010,7 +3010,8 @@ void HTMLInputElement::Select() {
return;
}
if (DispatchSelectEvent(presContext) && fm) {
DispatchSelectEvent(presContext);
if (fm) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
// ensure that the element is actually focused
@ -3021,22 +3022,16 @@ void HTMLInputElement::Select() {
}
}
bool HTMLInputElement::DispatchSelectEvent(nsPresContext* aPresContext) {
nsEventStatus status = nsEventStatus_eIgnore;
void HTMLInputElement::DispatchSelectEvent(nsPresContext* aPresContext) {
// If already handling select event, don't dispatch a second.
if (!mHandlingSelectEvent) {
WidgetEvent event(true, eFormSelect);
mHandlingSelectEvent = true;
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), aPresContext,
&event, nullptr, &status);
&event);
mHandlingSelectEvent = false;
}
// If the DOM event was not canceled (e.g. by a JS event handler
// returning false)
return (status == nsEventStatus_eIgnore);
}
void HTMLInputElement::SelectAll(nsPresContext* aPresContext) {
@ -3735,9 +3730,8 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
nsIFocusManager::FLAG_BYMOVEFOCUS)) {
RefPtr<nsPresContext> presContext =
GetPresContext(eForComposedDoc);
if (DispatchSelectEvent(presContext)) {
SelectAll(presContext);
}
DispatchSelectEvent(presContext);
SelectAll(presContext);
}
}
}

View File

@ -965,9 +965,9 @@ class HTMLInputElement final : public TextControlElement,
virtual void ResultForDialogSubmit(nsAString& aResult) override;
/**
* Dispatch a select event. Returns true if the event was not cancelled.
* Dispatch a select event.
*/
bool DispatchSelectEvent(nsPresContext* aPresContext);
void DispatchSelectEvent(nsPresContext* aPresContext);
void SelectAll(nsPresContext* aPresContext);
bool IsImage() const {

View File

@ -149,23 +149,18 @@ void HTMLTextAreaElement::Select() {
return;
}
nsEventStatus status = nsEventStatus_eIgnore;
WidgetGUIEvent event(true, eFormSelect, nullptr);
// XXXbz HTMLInputElement guards against this reentering; shouldn't we?
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext, &event,
nullptr, &status);
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
&event);
// If the DOM event was not canceled (e.g. by a JS event handler
// returning false)
if (status == nsEventStatus_eIgnore) {
if (fm) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
if (fm) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
// ensure that the element is actually focused
if (this == fm->GetFocusedElement()) {
// Now Select all the text!
SelectAll(presContext);
}
// ensure that the element is actually focused
if (this == fm->GetFocusedElement()) {
// Now Select all the text!
SelectAll(presContext);
}
}
}

View File

@ -1,7 +1,4 @@
[select-event.html]
[textarea: select()]
expected: FAIL
[textarea: select() a second time (must not fire select)]
expected: FAIL
@ -20,9 +17,6 @@
[textarea: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type text: select()]
expected: FAIL
[input type text: select() a second time (must not fire select)]
expected: FAIL
@ -41,9 +35,6 @@
[input type text: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type search: select()]
expected: FAIL
[input type search: select() a second time (must not fire select)]
expected: FAIL
@ -62,9 +53,6 @@
[input type search: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type tel: select()]
expected: FAIL
[input type tel: select() a second time (must not fire select)]
expected: FAIL
@ -83,9 +71,6 @@
[input type tel: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type url: select()]
expected: FAIL
[input type url: select() a second time (must not fire select)]
expected: FAIL
@ -104,9 +89,6 @@
[input type url: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type password: select()]
expected: FAIL
[input type password: select() a second time (must not fire select)]
expected: FAIL

View File

@ -480,7 +480,8 @@ class WidgetEvent : public WidgetEventTime {
break;
default:
if (mMessage == eResize || mMessage == eMozVisualResize ||
mMessage == eMozVisualScroll || mMessage == eEditorInput) {
mMessage == eMozVisualScroll || mMessage == eEditorInput ||
mMessage == eFormSelect) {
mFlags.mCancelable = false;
} else {
mFlags.mCancelable = true;