diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 9ef7b45722a..25947a01c99 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -885,7 +885,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub(crate) fn fire_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_event(&self, name: Atom, can_gc: CanGc) -> bool { self.fire_event_with_params( name, EventBubbles::DoesNotBubble, @@ -896,7 +896,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub(crate) fn fire_bubbling_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_bubbling_event(&self, name: Atom, can_gc: CanGc) -> bool { self.fire_event_with_params( name, EventBubbles::Bubbles, @@ -907,7 +907,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub(crate) fn fire_cancelable_event(&self, name: Atom, can_gc: CanGc) -> DomRoot { + pub(crate) fn fire_cancelable_event(&self, name: Atom, can_gc: CanGc) -> bool { self.fire_event_with_params( name, EventBubbles::DoesNotBubble, @@ -918,11 +918,7 @@ impl EventTarget { } // https://dom.spec.whatwg.org/#concept-event-fire - pub(crate) fn fire_bubbling_cancelable_event( - &self, - name: Atom, - can_gc: CanGc, - ) -> DomRoot { + pub(crate) fn fire_bubbling_cancelable_event(&self, name: Atom, can_gc: CanGc) -> bool { self.fire_event_with_params( name, EventBubbles::Bubbles, @@ -940,11 +936,10 @@ impl EventTarget { cancelable: EventCancelable, composed: EventComposed, can_gc: CanGc, - ) -> DomRoot { + ) -> bool { let event = Event::new(&self.global(), name, bubbles, cancelable, can_gc); event.set_composed(composed.into()); - event.fire(self, can_gc); - event + event.fire(self, can_gc) } /// diff --git a/components/script/dom/html/htmlformelement.rs b/components/script/dom/html/htmlformelement.rs index ac6876392d5..82980ea9047 100644 --- a/components/script/dom/html/htmlformelement.rs +++ b/components/script/dom/html/htmlformelement.rs @@ -1148,7 +1148,7 @@ impl HTMLFormElement { } }) .collect::>>(); - // Step 4 + // Step 4: If invalid controls is empty, then return a positive result. if invalid_controls.is_empty() { return Ok(()); } @@ -1156,10 +1156,13 @@ impl HTMLFormElement { let unhandled_invalid_controls = invalid_controls .into_iter() .filter_map(|field| { - let event = field + // Step 6.1: Let notCanceled be the result of firing an event named invalid at + // field, with the cancelable attribute initialized to true. + let not_canceled = field .upcast::() .fire_cancelable_event(atom!("invalid"), can_gc); - if !event.DefaultPrevented() { + // Step 6.2: If notCanceled is true, then add field to unhandled invalid controls. + if not_canceled { return Some(field); } None @@ -1302,6 +1305,7 @@ impl HTMLFormElement { Some(form_data.datums()) } + /// pub(crate) fn reset(&self, _reset_method_flag: ResetFrom, can_gc: CanGc) { // https://html.spec.whatwg.org/multipage/#locked-for-reset if self.marked_for_reset.get() { @@ -1310,10 +1314,13 @@ impl HTMLFormElement { self.marked_for_reset.set(true); } - let event = self + // https://html.spec.whatwg.org/multipage/#concept-form-reset + // Let reset be the result of firing an event named reset at form, + // with the bubbles and cancelable attributes initialized to true. + let reset = self .upcast::() .fire_bubbling_cancelable_event(atom!("reset"), can_gc); - if event.DefaultPrevented() { + if !reset { return; } diff --git a/components/script/dom/validation.rs b/components/script/dom/validation.rs index c17d8ef0a9a..3128fc1c7e7 100755 --- a/components/script/dom/validation.rs +++ b/components/script/dom/validation.rs @@ -1,7 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods; use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use crate::dom::bindings::codegen::Bindings::HTMLOrSVGElementBinding::FocusOptions; use crate::dom::bindings::inheritance::Castable; @@ -62,14 +61,15 @@ pub(crate) trait Validatable { return true; } - // Step 1.1. - let event = self + // Step 1.1: Let report be the result of firing an event named invalid at element, + // with the cancelable attribute initialized to true. + let report = self .as_element() .upcast::() .fire_cancelable_event(atom!("invalid"), can_gc); // Step 1.2. - if !event.DefaultPrevented() { + if report { let flags = self.validity_state().invalid_flags(); println!( "Validation error: {}",