mirror of
https://github.com/servo/servo.git
synced 2025-06-18 22:34:30 +01:00
Auto merge of #7219 - vectorijk:issue#7042, r=Ms2ger
remove unused static collection type in htmlcollection.rs ref #7042 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7219) <!-- Reviewable:end -->
This commit is contained in:
commit
71ae18bae4
1 changed files with 25 additions and 42 deletions
|
@ -24,28 +24,25 @@ pub trait CollectionFilter : JSTraceable {
|
||||||
|
|
||||||
#[derive(JSTraceable)]
|
#[derive(JSTraceable)]
|
||||||
#[must_root]
|
#[must_root]
|
||||||
pub enum CollectionTypeId {
|
pub struct Collection(JS<Node>, Box<CollectionFilter + 'static>);
|
||||||
Static(Vec<JS<Element>>),
|
|
||||||
Live(JS<Node>, Box<CollectionFilter + 'static>)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
#[derive(HeapSizeOf)]
|
#[derive(HeapSizeOf)]
|
||||||
pub struct HTMLCollection {
|
pub struct HTMLCollection {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
#[ignore_heap_size_of = "Contains a trait object; can't measure due to #6870"]
|
#[ignore_heap_size_of = "Contains a trait object; can't measure due to #6870"]
|
||||||
collection: CollectionTypeId,
|
collection: Collection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLCollection {
|
impl HTMLCollection {
|
||||||
fn new_inherited(collection: CollectionTypeId) -> HTMLCollection {
|
fn new_inherited(collection: Collection) -> HTMLCollection {
|
||||||
HTMLCollection {
|
HTMLCollection {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
collection: collection,
|
collection: collection,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &Window, collection: CollectionTypeId) -> Root<HTMLCollection> {
|
pub fn new(window: &Window, collection: Collection) -> Root<HTMLCollection> {
|
||||||
reflect_dom_object(box HTMLCollection::new_inherited(collection),
|
reflect_dom_object(box HTMLCollection::new_inherited(collection),
|
||||||
GlobalRef::Window(window), HTMLCollectionBinding::Wrap)
|
GlobalRef::Window(window), HTMLCollectionBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +51,7 @@ impl HTMLCollection {
|
||||||
impl HTMLCollection {
|
impl HTMLCollection {
|
||||||
pub fn create(window: &Window, root: &Node,
|
pub fn create(window: &Window, root: &Node,
|
||||||
filter: Box<CollectionFilter + 'static>) -> Root<HTMLCollection> {
|
filter: Box<CollectionFilter + 'static>) -> Root<HTMLCollection> {
|
||||||
HTMLCollection::new(window, CollectionTypeId::Live(JS::from_ref(root), filter))
|
HTMLCollection::new(window, Collection(JS::from_ref(root), filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_elements(window: &Window, root: &Node,
|
fn all_elements(window: &Window, root: &Node,
|
||||||
|
@ -179,34 +176,28 @@ impl HTMLCollection {
|
||||||
|
|
||||||
impl<'a> HTMLCollectionMethods for &'a HTMLCollection {
|
impl<'a> HTMLCollectionMethods for &'a HTMLCollection {
|
||||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-length
|
// https://dom.spec.whatwg.org/#dom-htmlcollection-length
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
fn Length(self) -> u32 {
|
fn Length(self) -> u32 {
|
||||||
match self.collection {
|
let Collection(ref root, ref filter) = self.collection;
|
||||||
CollectionTypeId::Static(ref elems) => elems.len() as u32,
|
let root = root.root();
|
||||||
CollectionTypeId::Live(ref root, ref filter) => {
|
HTMLCollection::traverse(root.r())
|
||||||
let root = root.root();
|
.filter(|element| filter.filter(element.r(), root.r()))
|
||||||
HTMLCollection::traverse(root.r())
|
.count() as u32
|
||||||
.filter(|element| filter.filter(element.r(), root.r()))
|
|
||||||
.count() as u32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
fn Item(self, index: u32) -> Option<Root<Element>> {
|
fn Item(self, index: u32) -> Option<Root<Element>> {
|
||||||
let index = index as usize;
|
let index = index as usize;
|
||||||
match self.collection {
|
let Collection(ref root, ref filter) = self.collection;
|
||||||
CollectionTypeId::Static(ref elems) => elems
|
let root = root.root();
|
||||||
.get(index).map(|t| t.root()),
|
HTMLCollection::traverse(root.r())
|
||||||
CollectionTypeId::Live(ref root, ref filter) => {
|
.filter(|element| filter.filter(element.r(), root.r()))
|
||||||
let root = root.root();
|
.nth(index)
|
||||||
HTMLCollection::traverse(root.r())
|
|
||||||
.filter(|element| filter.filter(element.r(), root.r()))
|
|
||||||
.nth(index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
// https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
fn NamedItem(self, key: DOMString) -> Option<Root<Element>> {
|
fn NamedItem(self, key: DOMString) -> Option<Root<Element>> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if key.is_empty() {
|
if key.is_empty() {
|
||||||
|
@ -214,21 +205,13 @@ impl<'a> HTMLCollectionMethods for &'a HTMLCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
match self.collection {
|
let Collection(ref root, ref filter) = self.collection;
|
||||||
CollectionTypeId::Static(ref elems) => elems.iter()
|
let root = root.root();
|
||||||
.map(|elem| elem.root())
|
HTMLCollection::traverse(root.r())
|
||||||
.find(|elem| {
|
.filter(|element| filter.filter(element.r(), root.r()))
|
||||||
elem.r().get_string_attribute(&atom!("name")) == key ||
|
.find(|elem| {
|
||||||
elem.r().get_string_attribute(&atom!("id")) == key }),
|
elem.r().get_string_attribute(&atom!("name")) == key ||
|
||||||
CollectionTypeId::Live(ref root, ref filter) => {
|
elem.r().get_string_attribute(&atom!("id")) == key})
|
||||||
let root = root.root();
|
|
||||||
HTMLCollection::traverse(root.r())
|
|
||||||
.filter(|element| filter.filter(element.r(), root.r()))
|
|
||||||
.find(|elem| {
|
|
||||||
elem.r().get_string_attribute(&atom!("name")) == key ||
|
|
||||||
elem.r().get_string_attribute(&atom!("id")) == key })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue