diff options
author | tanishka <109246904+taniishkaaa@users.noreply.github.com> | 2024-10-20 13:35:11 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-20 08:05:11 +0000 |
commit | a57b6a3f79314910543024c951d365e55efa154e (patch) | |
tree | 1a9ec5c4989abe059b638701fc39da1467505485 /components/script | |
parent | d0d02cd56cb646da1f2193e57561b78d5e4b6bdf (diff) | |
download | servo-a57b6a3f79314910543024c951d365e55efa154e.tar.gz servo-a57b6a3f79314910543024c951d365e55efa154e.zip |
CanGc fixes through focusevent.rs & hashchangeevent.rs (#33921)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
Diffstat (limited to 'components/script')
20 files changed, 140 insertions, 69 deletions
diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 9a423cd8ace..d53fe81b955 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -101,6 +101,10 @@ DOMInterfaces = { 'canGc': ['SetInnerHTML', 'SetOuterHTML', 'InsertAdjacentHTML', 'GetClientRects', 'GetBoundingClientRect'], }, +'ElementInternals': { + 'canGc': ['ReportValidity'], +}, + 'EventSource': { 'weakReferenceable': True, }, @@ -135,8 +139,24 @@ DOMInterfaces = { 'inRealms': ['PlayEffect', 'Reset'] }, +'HTMLButtonElement': { + 'canGc': ['ReportValidity'], +}, + +'HTMLElement': { + 'canGc': ['Focus', 'Blur'], +}, + +'HTMLFieldSetElement': { + 'canGc': ['ReportValidity'], +}, + 'HTMLFormElement': { - 'canGc': ['RequestSubmit'], + 'canGc': ['RequestSubmit', 'ReportValidity'], +}, + +'HTMLInputElement': { + 'canGc': ['ReportValidity'], }, 'HTMLMediaElement': { @@ -144,14 +164,30 @@ DOMInterfaces = { 'inRealms': ['Play'], }, +'HTMLObjectElement': { + 'canGc': ['ReportValidity'], +}, + +'HTMLOutputElement': { + 'canGc': ['ReportValidity'], +}, + 'HTMLCanvasElement': { 'canGc': ['CaptureStream', 'GetContext'], }, +'HTMLSelectElement': { + 'canGc': ['ReportValidity'], +}, + 'HTMLTemplateElement': { 'canGc': ['Content'], }, +'HTMLTextAreaElement': { + 'canGc': ['ReportValidity'], +}, + 'MediaDevices': { 'canGc': ['GetUserMedia'], 'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'], diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 044d4f5bfb2..a7d10dc825e 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1112,20 +1112,26 @@ impl Document { } /// <https://html.spec.whatwg.org/multipage/#focus-fixup-rule> - pub(crate) fn perform_focus_fixup_rule(&self, not_focusable: &Element) { + pub(crate) fn perform_focus_fixup_rule(&self, not_focusable: &Element, can_gc: CanGc) { if Some(not_focusable) != self.focused.get().as_deref() { return; } self.request_focus( self.GetBody().as_ref().map(|e| e.upcast()), FocusType::Element, + can_gc, ) } /// Request that the given element receive focus once the current transaction is complete. /// If None is passed, then whatever element is currently focused will no longer be focused /// once the transaction is complete. - pub(crate) fn request_focus(&self, elem: Option<&Element>, focus_type: FocusType) { + pub(crate) fn request_focus( + &self, + elem: Option<&Element>, + focus_type: FocusType, + can_gc: CanGc, + ) { let implicit_transaction = matches!( *self.focus_transaction.borrow(), FocusTransaction::NotInTransaction @@ -1138,13 +1144,13 @@ impl Document { FocusTransaction::InTransaction(elem.map(Dom::from_ref)); } if implicit_transaction { - self.commit_focus_transaction(focus_type); + self.commit_focus_transaction(focus_type, can_gc); } } /// Reassign the focus context to the element that last requested focus during this /// transaction, or none if no elements requested it. - fn commit_focus_transaction(&self, focus_type: FocusType) { + fn commit_focus_transaction(&self, focus_type: FocusType, can_gc: CanGc) { let possibly_focused = match *self.focus_transaction.borrow() { FocusTransaction::NotInTransaction => unreachable!(), FocusTransaction::InTransaction(ref elem) => { @@ -1159,7 +1165,7 @@ impl Document { let node = elem.upcast::<Node>(); elem.set_focus_state(false); // FIXME: pass appropriate relatedTarget - self.fire_focus_event(FocusEventType::Blur, node, None); + self.fire_focus_event(FocusEventType::Blur, node, None, can_gc); // Notify the embedder to hide the input method. if elem.input_method_type().is_some() { @@ -1173,7 +1179,7 @@ impl Document { elem.set_focus_state(true); let node = elem.upcast::<Node>(); // FIXME: pass appropriate relatedTarget - self.fire_focus_event(FocusEventType::Focus, node, None); + self.fire_focus_event(FocusEventType::Focus, node, None, can_gc); // Update the focus state for all elements in the focus chain. // https://html.spec.whatwg.org/multipage/#focus-chain if focus_type == FocusType::Element { @@ -1299,6 +1305,7 @@ impl Document { node_address: Option<UntrustedNodeAddress>, point_in_node: Option<Point2D<f32>>, pressed_mouse_buttons: u16, + can_gc: CanGc, ) { let mouse_event_type_string = match mouse_event_type { MouseEventType::Click => "click".to_owned(), @@ -1328,7 +1335,7 @@ impl Document { } self.begin_focus_transaction(); - self.request_focus(Some(&*el), FocusType::Element); + self.request_focus(Some(&*el), FocusType::Element, can_gc); } // https://w3c.github.io/uievents/#event-type-click @@ -1390,7 +1397,7 @@ impl Document { } if let MouseEventType::Click = mouse_event_type { - self.commit_focus_transaction(FocusType::Element); + self.commit_focus_transaction(FocusType::Element, can_gc); self.maybe_fire_dblclick(client_point, node, pressed_mouse_buttons); } } @@ -1901,10 +1908,11 @@ impl Document { } } - pub fn ime_dismissed(&self) { + pub fn ime_dismissed(&self, can_gc: CanGc) { self.request_focus( self.GetBody().as_ref().map(|e| e.upcast()), FocusType::Element, + can_gc, ) } @@ -2850,6 +2858,7 @@ impl Document { focus_event_type: FocusEventType, node: &Node, related_target: Option<&EventTarget>, + can_gc: CanGc, ) { let (event_name, does_bubble) = match focus_event_type { FocusEventType::Focus => (DOMString::from("focus"), EventBubbles::DoesNotBubble), @@ -2863,6 +2872,7 @@ impl Document { Some(&self.window), 0i32, related_target, + can_gc, ); let event = event.upcast::<Event>(); event.set_trusted(true); @@ -4680,6 +4690,7 @@ impl DocumentMethods for Document { ))), "hashchangeevent" => Ok(DomRoot::upcast(HashChangeEvent::new_uninitialized( &self.window, + can_gc, ))), "keyboardevent" => Ok(DomRoot::upcast(KeyboardEvent::new_uninitialized( &self.window, diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 78cf0960b00..1a429b540b5 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -2002,7 +2002,7 @@ impl Element { } } - pub(crate) fn update_sequentially_focusable_status(&self) { + pub(crate) fn update_sequentially_focusable_status(&self, can_gc: CanGc) { let node = self.upcast::<Node>(); let is_sequentially_focusable = self.is_sequentially_focusable(); node.set_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE, is_sequentially_focusable); @@ -2010,7 +2010,7 @@ impl Element { // https://html.spec.whatwg.org/multipage/#focus-fixup-rule if !is_sequentially_focusable { let document = document_from_node(self); - document.perform_focus_fixup_rule(self); + document.perform_focus_fixup_rule(self, can_gc); } } @@ -3327,7 +3327,7 @@ impl VirtualMethods for Element { let doc = node.owner_doc(); match attr.local_name() { &local_name!("tabindex") | &local_name!("draggable") | &local_name!("hidden") => { - self.update_sequentially_focusable_status() + self.update_sequentially_focusable_status(CanGc::note()) }, &local_name!("style") => { // Modifying the `style` attribute might change style. @@ -3493,7 +3493,7 @@ impl VirtualMethods for Element { return; } - self.update_sequentially_focusable_status(); + self.update_sequentially_focusable_status(CanGc::note()); if let Some(ref id) = *self.id_attribute.borrow() { if let Some(shadow_root) = self.upcast::<Node>().containing_shadow_root() { @@ -3526,7 +3526,7 @@ impl VirtualMethods for Element { return; } - self.update_sequentially_focusable_status(); + self.update_sequentially_focusable_status(CanGc::note()); let doc = document_from_node(self); diff --git a/components/script/dom/elementinternals.rs b/components/script/dom/elementinternals.rs index 3956b1cccc8..e0ccef06b29 100644 --- a/components/script/dom/elementinternals.rs +++ b/components/script/dom/elementinternals.rs @@ -25,6 +25,7 @@ use crate::dom::node::{window_from_node, Node}; use crate::dom::nodelist::NodeList; use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable}; use crate::dom::validitystate::{ValidationFlags, ValidityState}; +use crate::script_runtime::CanGc; #[derive(Clone, JSTraceable, MallocSizeOf)] enum SubmissionValue { @@ -324,11 +325,11 @@ impl ElementInternalsMethods for ElementInternals { } /// <https://html.spec.whatwg.org/multipage#dom-elementinternals-reportvalidity> - fn ReportValidity(&self) -> Fallible<bool> { + fn ReportValidity(&self, can_gc: CanGc) -> Fallible<bool> { if !self.is_target_form_associated() { return Err(Error::NotSupported); } - Ok(self.report_validity()) + Ok(self.report_validity(can_gc)) } } diff --git a/components/script/dom/focusevent.rs b/components/script/dom/focusevent.rs index d847f8a5492..d8a73b91fa1 100644 --- a/components/script/dom/focusevent.rs +++ b/components/script/dom/focusevent.rs @@ -55,6 +55,7 @@ impl FocusEvent { view: Option<&Window>, detail: i32, related_target: Option<&EventTarget>, + can_gc: CanGc, ) -> DomRoot<FocusEvent> { Self::new_with_proto( window, @@ -65,7 +66,7 @@ impl FocusEvent { view, detail, related_target, - CanGc::note(), + can_gc, ) } diff --git a/components/script/dom/hashchangeevent.rs b/components/script/dom/hashchangeevent.rs index 7f4f2bebfee..e39ede9870b 100644 --- a/components/script/dom/hashchangeevent.rs +++ b/components/script/dom/hashchangeevent.rs @@ -35,19 +35,20 @@ impl HashChangeEvent { } } - pub fn new_uninitialized(window: &Window) -> DomRoot<HashChangeEvent> { - Self::new_uninitialized_with_proto(window, None) + pub fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot<HashChangeEvent> { + Self::new_uninitialized_with_proto(window, None, can_gc) } fn new_uninitialized_with_proto( window: &Window, proto: Option<HandleObject>, + can_gc: CanGc, ) -> DomRoot<HashChangeEvent> { reflect_dom_object_with_proto( Box::new(HashChangeEvent::new_inherited(String::new(), String::new())), window, proto, - CanGc::note(), + can_gc, ) } @@ -58,16 +59,10 @@ impl HashChangeEvent { cancelable: bool, old_url: String, new_url: String, + can_gc: CanGc, ) -> DomRoot<HashChangeEvent> { Self::new_with_proto( - window, - None, - type_, - bubbles, - cancelable, - old_url, - new_url, - CanGc::note(), + window, None, type_, bubbles, cancelable, old_url, new_url, can_gc, ) } diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b9d0a3231cb..1e3430d94f7 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -152,6 +152,7 @@ impl History { false, old_url.into_string(), url.into_string(), + can_gc, ); event .upcast::<Event>() diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index f0b18725338..2a25174cba5 100755 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -175,8 +175,8 @@ impl HTMLButtonElementMethods for HTMLButtonElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage @@ -245,7 +245,7 @@ impl VirtualMethods for HTMLButtonElement { el.check_ancestors_disabled_state_for_form_control(); }, } - el.update_sequentially_focusable_status(); + el.update_sequentially_focusable_status(CanGc::note()); self.validity_state() .perform_validation_and_update(ValidationFlags::all()); }, diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 84807a3cbcb..b4e407c5b2b 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -51,6 +51,7 @@ use crate::dom::node::{ }; use crate::dom::text::Text; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; use crate::script_thread::ScriptThread; #[dom_struct] @@ -399,22 +400,22 @@ impl HTMLElementMethods for HTMLElement { } // https://html.spec.whatwg.org/multipage/#dom-focus - fn Focus(&self) { + fn Focus(&self, can_gc: CanGc) { // TODO: Mark the element as locked for focus and run the focusing steps. // https://html.spec.whatwg.org/multipage/#focusing-steps let document = document_from_node(self); - document.request_focus(Some(self.upcast()), FocusType::Element); + document.request_focus(Some(self.upcast()), FocusType::Element, can_gc); } // https://html.spec.whatwg.org/multipage/#dom-blur - fn Blur(&self) { + fn Blur(&self, can_gc: CanGc) { // TODO: Run the unfocusing steps. if !self.as_element().focus_state() { return; } // https://html.spec.whatwg.org/multipage/#unfocusing-steps let document = document_from_node(self); - document.request_focus(None, FocusType::Element); + document.request_focus(None, FocusType::Element, can_gc); } // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent @@ -1077,7 +1078,7 @@ impl VirtualMethods for HTMLElement { super_type.bind_to_tree(context); } let element = self.as_element(); - element.update_sequentially_focusable_status(); + element.update_sequentially_focusable_status(CanGc::note()); // Binding to a tree can disable a form control if one of the new // ancestors is a fieldset. diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 29f66982192..6e390a1794a 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -25,6 +25,7 @@ use crate::dom::node::{window_from_node, Node, ShadowIncluding}; use crate::dom::validation::Validatable; use crate::dom::validitystate::ValidityState; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; use crate::script_thread::ScriptThread; #[dom_struct] @@ -131,8 +132,8 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage @@ -219,7 +220,7 @@ impl VirtualMethods for HTMLFieldSetElement { ); } } - element.update_sequentially_focusable_status(); + element.update_sequentially_focusable_status(CanGc::note()); } } else { for field in fields { @@ -240,10 +241,10 @@ impl VirtualMethods for HTMLFieldSetElement { ); } } - element.update_sequentially_focusable_status(); + element.update_sequentially_focusable_status(CanGc::note()); } } - element.update_sequentially_focusable_status(); + element.update_sequentially_focusable_status(CanGc::note()); }, local_name!("form") => { self.form_attribute_mutated(mutation); diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index db8c69f80b0..d118b2599e5 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -634,8 +634,8 @@ impl HTMLFormElementMethods for HTMLFormElement { } /// <https://html.spec.whatwg.org/multipage/#dom-form-reportvalidity> - fn ReportValidity(&self) -> bool { - self.interactive_validation().is_ok() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.interactive_validation(can_gc).is_ok() } } @@ -733,7 +733,7 @@ impl HTMLFormElement { // Step 6.2 self.firing_submission_events.set(true); // Step 6.3 - if !submitter.no_validate(self) && self.interactive_validation().is_err() { + if !submitter.no_validate(self) && self.interactive_validation(can_gc).is_err() { self.firing_submission_events.set(false); return; } @@ -1029,7 +1029,7 @@ impl HTMLFormElement { /// Interactively validate the constraints of form elements /// <https://html.spec.whatwg.org/multipage/#interactively-validate-the-constraints> - fn interactive_validation(&self) -> Result<(), ()> { + fn interactive_validation(&self, can_gc: CanGc) -> Result<(), ()> { // Step 1-2 let unhandled_invalid_controls = match self.static_validation() { Ok(()) => return Ok(()), @@ -1045,7 +1045,7 @@ impl HTMLFormElement { } if first { if let Some(html_elem) = elem.downcast::<HTMLElement>() { - html_elem.Focus(); + html_elem.Focus(can_gc); first = false; } } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index d2ff2590a2d..867bca5eab7 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -1591,8 +1591,8 @@ impl HTMLInputElementMethods for HTMLInputElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage @@ -2267,7 +2267,7 @@ impl VirtualMethods for HTMLInputElement { el.set_read_write_state(read_write); } - el.update_sequentially_focusable_status(); + el.update_sequentially_focusable_status(CanGc::note()); }, local_name!("checked") if !self.checked_changed.get() => { let checked_state = match mutation { diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index 25794aca176..0518bdbab2c 100755 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -24,6 +24,7 @@ use crate::dom::node::{window_from_node, Node}; use crate::dom::validation::Validatable; use crate::dom::validitystate::ValidityState; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; #[dom_struct] pub struct HTMLObjectElement { @@ -114,8 +115,8 @@ impl HTMLObjectElementMethods for HTMLObjectElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage diff --git a/components/script/dom/htmloutputelement.rs b/components/script/dom/htmloutputelement.rs index 405a13eb9e3..667b0bdedfa 100644 --- a/components/script/dom/htmloutputelement.rs +++ b/components/script/dom/htmloutputelement.rs @@ -21,6 +21,7 @@ use crate::dom::nodelist::NodeList; use crate::dom::validation::Validatable; use crate::dom::validitystate::ValidityState; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; #[dom_struct] pub struct HTMLOutputElement { @@ -136,8 +137,8 @@ impl HTMLOutputElementMethods for HTMLOutputElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index aa5e6f8f469..7c53abfd17b 100755 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -39,6 +39,7 @@ use crate::dom::nodelist::NodeList; use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable}; use crate::dom::validitystate::{ValidationFlags, ValidityState}; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; #[derive(JSTraceable, MallocSizeOf)] struct OptionsFilter; @@ -395,8 +396,8 @@ impl HTMLSelectElementMethods for HTMLSelectElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index a6cfde252e5..dc1158775ba 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -42,6 +42,7 @@ use crate::dom::textcontrol::{TextControlElement, TextControlSelection}; use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable}; use crate::dom::validitystate::{ValidationFlags, ValidityState}; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; use crate::textinput::{ Direction, KeyReaction, Lines, SelectionDirection, TextInput, UTF16CodeUnits, UTF8Bytes, }; @@ -428,8 +429,8 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { } // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity - fn ReportValidity(&self) -> bool { - self.report_validity() + fn ReportValidity(&self, can_gc: CanGc) -> bool { + self.report_validity(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage @@ -484,7 +485,7 @@ impl VirtualMethods for HTMLTextAreaElement { } }, } - el.update_sequentially_focusable_status(); + el.update_sequentially_focusable_status(CanGc::note()); }, local_name!("maxlength") => match *attr.value() { AttrValue::Int(_, value) => { diff --git a/components/script/dom/validation.rs b/components/script/dom/validation.rs index dadef038600..24987bb2b31 100755 --- a/components/script/dom/validation.rs +++ b/components/script/dom/validation.rs @@ -12,6 +12,7 @@ use crate::dom::htmldatalistelement::HTMLDataListElement; use crate::dom::htmlelement::HTMLElement; use crate::dom::node::Node; use crate::dom::validitystate::{ValidationFlags, ValidityState}; +use crate::script_runtime::CanGc; /// Trait for elements with constraint validation support pub trait Validatable { @@ -46,7 +47,7 @@ pub trait Validatable { } /// <https://html.spec.whatwg.org/multipage/#report-validity-steps> - fn report_validity(&self) -> bool { + fn report_validity(&self, can_gc: CanGc) -> bool { // Step 1. if !self.is_instance_validatable() { return true; @@ -70,7 +71,7 @@ pub trait Validatable { validation_message_for_flags(&self.validity_state(), flags) ); if let Some(html_elem) = self.as_element().downcast::<HTMLElement>() { - html_elem.Focus(); + html_elem.Focus(can_gc); } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 66e31567f20..55ea17fd718 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -2262,7 +2262,8 @@ impl Window { false, false, old_url, - new_url); + new_url, + CanGc::note()); event.upcast::<Event>().fire(this.upcast::<EventTarget>()); }); // FIXME(nox): Why are errors silenced here? diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index ea6148325b9..6dada855c57 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1581,6 +1581,7 @@ impl ScriptThread { node_address, point_in_node, pressed_mouse_buttons, + can_gc, ); }, @@ -1628,7 +1629,7 @@ impl ScriptThread { }, CompositorEvent::IMEDismissedEvent => { - document.ime_dismissed(); + document.ime_dismissed(can_gc); }, CompositorEvent::CompositionEvent(composition_event) => { @@ -2381,7 +2382,7 @@ impl ScriptThread { self.handle_remove_history_states(pipeline_id, history_states) }, ConstellationControlMsg::FocusIFrame(parent_pipeline_id, frame_id) => { - self.handle_focus_iframe_msg(parent_pipeline_id, frame_id) + self.handle_focus_iframe_msg(parent_pipeline_id, frame_id, can_gc) }, ConstellationControlMsg::WebDriverScriptCommand(pipeline_id, msg) => { self.handle_webdriver_msg(pipeline_id, msg, can_gc) @@ -2782,10 +2783,22 @@ impl ScriptThread { ) }, WebDriverScriptCommand::FocusElement(element_id, reply) => { - webdriver_handlers::handle_focus_element(&documents, pipeline_id, element_id, reply) + webdriver_handlers::handle_focus_element( + &documents, + pipeline_id, + element_id, + reply, + can_gc, + ) }, WebDriverScriptCommand::ElementClick(element_id, reply) => { - webdriver_handlers::handle_element_click(&documents, pipeline_id, element_id, reply) + webdriver_handlers::handle_element_click( + &documents, + pipeline_id, + element_id, + reply, + can_gc, + ) }, WebDriverScriptCommand::GetActiveElement(reply) => { webdriver_handlers::handle_get_active_element(&documents, pipeline_id, reply) @@ -3027,6 +3040,7 @@ impl ScriptThread { &self, parent_pipeline_id: PipelineId, browsing_context_id: BrowsingContextId, + can_gc: CanGc, ) { let doc = self .documents @@ -3036,7 +3050,7 @@ impl ScriptThread { let frame_element = doc.find_iframe(browsing_context_id); if let Some(ref frame_element) = frame_element { - doc.request_focus(Some(frame_element.upcast()), FocusType::Parent); + doc.request_focus(Some(frame_element.upcast()), FocusType::Parent, can_gc); } } @@ -3914,6 +3928,7 @@ impl ScriptThread { node_address: Option<UntrustedNodeAddress>, point_in_node: Option<Point2D<f32>>, pressed_mouse_buttons: u16, + can_gc: CanGc, ) { let Some(document) = self.documents.borrow().find_document(pipeline_id) else { warn!("Message sent to closed pipeline {pipeline_id}."); @@ -3927,6 +3942,7 @@ impl ScriptThread { node_address, point_in_node, pressed_mouse_buttons, + can_gc, ) } } diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index cbe74aa1263..489e071908c 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -677,6 +677,7 @@ pub fn handle_focus_element( pipeline: PipelineId, element_id: String, reply: IpcSender<Result<(), ErrorStatus>>, + can_gc: CanGc, ) { reply .send( @@ -684,7 +685,7 @@ pub fn handle_focus_element( match node.downcast::<HTMLElement>() { Some(element) => { // Need a way to find if this actually succeeded - element.Focus(); + element.Focus(can_gc); Ok(()) }, None => Err(ErrorStatus::UnknownError), @@ -1072,6 +1073,7 @@ pub fn handle_element_click( pipeline: PipelineId, element_id: String, reply: IpcSender<Result<Option<String>, ErrorStatus>>, + can_gc: CanGc, ) { reply .send( @@ -1122,7 +1124,7 @@ pub fn handle_element_click( // Step 8.5 match parent_node.downcast::<HTMLElement>() { - Some(html_element) => html_element.Focus(), + Some(html_element) => html_element.Focus(can_gc), None => return Err(ErrorStatus::UnknownError), } |