mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
RadioNodeList now reflects changes to the parent, but has room for performance optimization
This commit is contained in:
parent
6b79a8f042
commit
d59aed606d
6 changed files with 167 additions and 67 deletions
|
@ -8,11 +8,12 @@ use crate::dom::bindings::codegen::Bindings::RadioNodeListBinding;
|
|||
use crate::dom::bindings::codegen::Bindings::RadioNodeListBinding::RadioNodeListMethods;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::htmlformelement::HTMLFormElement;
|
||||
use crate::dom::htmlinputelement::{HTMLInputElement, InputType};
|
||||
use crate::dom::node::Node;
|
||||
use crate::dom::nodelist::{NodeList, NodeListType};
|
||||
use crate::dom::nodelist::{NodeList, NodeListType, RadioList, RadioListMode};
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
|
@ -38,18 +39,33 @@ impl RadioNodeList {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn new_simple_list<T>(window: &Window, iter: T) -> DomRoot<RadioNodeList>
|
||||
where
|
||||
T: Iterator<Item = DomRoot<Node>>,
|
||||
{
|
||||
pub fn new_controls_except_image_inputs(
|
||||
window: &Window,
|
||||
form: &HTMLFormElement,
|
||||
name: DOMString,
|
||||
) -> DomRoot<RadioNodeList> {
|
||||
RadioNodeList::new(
|
||||
window,
|
||||
NodeListType::Simple(iter.map(|r| Dom::from_ref(&*r)).collect()),
|
||||
NodeListType::Radio(RadioList::new(
|
||||
form,
|
||||
RadioListMode::ControlsExceptImageInputs,
|
||||
name,
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
// FIXME: This shouldn't need to be implemented here since NodeList (the parent of
|
||||
// RadioNodeList) implements Length
|
||||
pub fn new_images(
|
||||
window: &Window,
|
||||
form: &HTMLFormElement,
|
||||
name: DOMString,
|
||||
) -> DomRoot<RadioNodeList> {
|
||||
RadioNodeList::new(
|
||||
window,
|
||||
NodeListType::Radio(RadioList::new(form, RadioListMode::Images, name)),
|
||||
)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nodelist-length
|
||||
// https://github.com/servo/servo/issues/5875
|
||||
pub fn Length(&self) -> u32 {
|
||||
self.node_list.Length()
|
||||
|
@ -60,7 +76,6 @@ impl RadioNodeListMethods for RadioNodeList {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-radionodelist-value
|
||||
fn Value(&self) -> DOMString {
|
||||
self.upcast::<NodeList>()
|
||||
.as_simple_list()
|
||||
.iter()
|
||||
.filter_map(|node| {
|
||||
// Step 1
|
||||
|
@ -85,7 +100,7 @@ impl RadioNodeListMethods for RadioNodeList {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-radionodelist-value
|
||||
fn SetValue(&self, value: DOMString) {
|
||||
for node in self.upcast::<NodeList>().as_simple_list().iter() {
|
||||
for node in self.upcast::<NodeList>().iter() {
|
||||
// Step 1
|
||||
if let Some(input) = node.downcast::<HTMLInputElement>() {
|
||||
match input.input_type() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue