diff options
author | Patrick Shaughnessy <pshaughn@comcast.net> | 2020-02-10 14:35:48 -0500 |
---|---|---|
committer | Patrick Shaughnessy <pshaughn@comcast.net> | 2020-02-10 14:35:48 -0500 |
commit | 0eeb075ecd68f79281d99721efe78709c63486e1 (patch) | |
tree | 38a2bb42f675c33c9df24126b56c2c255f320571 /components/script/dom/htmlformcontrolscollection.rs | |
parent | 5bcd0d8dd0c5f6cb56c1d3d67771d986ec54f68a (diff) | |
download | servo-0eeb075ecd68f79281d99721efe78709c63486e1.tar.gz servo-0eeb075ecd68f79281d99721efe78709c63486e1.zip |
rooted at the form's root, not rooted at the form
Diffstat (limited to 'components/script/dom/htmlformcontrolscollection.rs')
-rw-r--r-- | components/script/dom/htmlformcontrolscollection.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/components/script/dom/htmlformcontrolscollection.rs b/components/script/dom/htmlformcontrolscollection.rs index 1cf969a2fdd..410244c52c1 100644 --- a/components/script/dom/htmlformcontrolscollection.rs +++ b/components/script/dom/htmlformcontrolscollection.rs @@ -5,10 +5,11 @@ use crate::dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods; use crate::dom::bindings::codegen::Bindings::HTMLFormControlsCollectionBinding; use crate::dom::bindings::codegen::Bindings::HTMLFormControlsCollectionBinding::HTMLFormControlsCollectionMethods; +use crate::dom::bindings::codegen::Bindings::NodeBinding::{GetRootNodeOptions, NodeMethods}; use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; -use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::element::Element; use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection}; @@ -21,25 +22,30 @@ use dom_struct::dom_struct; #[dom_struct] pub struct HTMLFormControlsCollection { collection: HTMLCollection, + form: Dom<HTMLFormElement>, } impl HTMLFormControlsCollection { fn new_inherited( - root: &HTMLFormElement, + form: &HTMLFormElement, filter: Box<dyn CollectionFilter + 'static>, ) -> HTMLFormControlsCollection { + let root_of_form = form + .upcast::<Node>() + .GetRootNode(&GetRootNodeOptions::empty()); HTMLFormControlsCollection { - collection: HTMLCollection::new_inherited(root.upcast::<Node>(), filter), + collection: HTMLCollection::new_inherited(&*root_of_form, filter), + form: Dom::from_ref(form), } } pub fn new( window: &Window, - root: &HTMLFormElement, + form: &HTMLFormElement, filter: Box<dyn CollectionFilter + 'static>, ) -> DomRoot<HTMLFormControlsCollection> { reflect_dom_object( - Box::new(HTMLFormControlsCollection::new_inherited(root, filter)), + Box::new(HTMLFormControlsCollection::new_inherited(form, filter)), window, HTMLFormControlsCollectionBinding::Wrap, ) @@ -80,14 +86,11 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection { // Step 4-5 let global = self.global(); let window = global.as_window(); - // okay to unwrap: root's type was checked in the constructor - let collection_root = self.collection.root_node(); - let form = collection_root.downcast::<HTMLFormElement>().unwrap(); // There is only one way to get an HTMLCollection, // specifically HTMLFormElement::Elements(), // and the collection filter excludes image inputs. Some(RadioNodeListOrElement::RadioNodeList( - RadioNodeList::new_controls_except_image_inputs(window, form, name), + RadioNodeList::new_controls_except_image_inputs(window, &*self.form, name), )) } // Step 3 |