RadioNodeList now reflects changes to the parent, but has room for performance optimization

This commit is contained in:
Patrick Shaughnessy 2020-01-05 12:58:28 -05:00
parent 6b79a8f042
commit d59aed606d
6 changed files with 167 additions and 67 deletions

View file

@ -6,16 +6,17 @@ use crate::dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollecti
use crate::dom::bindings::codegen::Bindings::HTMLFormControlsCollectionBinding;
use crate::dom::bindings::codegen::Bindings::HTMLFormControlsCollectionBinding::HTMLFormControlsCollectionMethods;
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::str::DOMString;
use crate::dom::element::Element;
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::node::Node;
use crate::dom::radionodelist::RadioNodeList;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use std::iter;
#[dom_struct]
pub struct HTMLFormControlsCollection {
@ -24,17 +25,17 @@ pub struct HTMLFormControlsCollection {
impl HTMLFormControlsCollection {
fn new_inherited(
root: &Node,
root: &HTMLFormElement,
filter: Box<dyn CollectionFilter + 'static>,
) -> HTMLFormControlsCollection {
HTMLFormControlsCollection {
collection: HTMLCollection::new_inherited(root, filter),
collection: HTMLCollection::new_inherited(root.upcast::<Node>(), filter),
}
}
pub fn new(
window: &Window,
root: &Node,
root: &HTMLFormElement,
filter: Box<dyn CollectionFilter + 'static>,
) -> DomRoot<HTMLFormControlsCollection> {
reflect_dom_object(
@ -76,12 +77,16 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
Some(RadioNodeListOrElement::Element(elem))
} else {
// Step 4-5
let once = iter::once(DomRoot::upcast::<Node>(elem));
let list = once.chain(peekable.map(DomRoot::upcast));
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_simple_list(window, list),
RadioNodeList::new_controls_except_image_inputs(window, form, name),
))
}
// Step 3