From 6cf0eb11157bab3776c92d603021cba2b068c591 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 11 Feb 2014 12:11:28 -0400 Subject: [PATCH 1/8] Bumped HTMLCollection interface to latest Spec: http://dom.spec.whatwg.org/#interface-htmlcollection This is a sub-task for #1662. --- src/components/script/dom/htmlcollection.rs | 48 ++++++++++++++----- .../script/dom/webidls/HTMLCollection.webidl | 3 +- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index ff2cfa7b5a1..bb4cffc227e 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -5,15 +5,10 @@ use dom::bindings::codegen::HTMLCollectionBinding; use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; -use dom::bindings::error::Fallible; use dom::element::Element; use dom::window::Window; use servo_util::str::DOMString; -use js::jsapi::{JSObject, JSContext}; - -use std::ptr; - #[deriving(Encodable)] pub struct HTMLCollection { elements: ~[JS], @@ -34,11 +29,15 @@ impl HTMLCollection { reflect_dom_object(~HTMLCollection::new_inherited(window.clone(), elements), window, HTMLCollectionBinding::Wrap) } - +} + +impl HTMLCollection { + // http://dom.spec.whatwg.org/#dom-htmlcollection-length pub fn Length(&self) -> u32 { self.elements.len() as u32 } + // http://dom.spec.whatwg.org/#dom-htmlcollection-item pub fn Item(&self, index: u32) -> Option> { if index < self.Length() { Some(self.elements[index].clone()) @@ -47,17 +46,40 @@ impl HTMLCollection { } } - pub fn NamedItem(&self, _cx: *JSContext, _name: DOMString) -> Fallible<*JSObject> { - Ok(ptr::null()) - } + // http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem + pub fn NamedItem(&self, key: DOMString) -> Option> { + // Step 1. + if key.is_empty() { + return None; + } + // Step 2. + self.elements.iter().find(|elem| { + let elem = elem.get(); + elem.get_string_attribute("name") == key || elem.get_string_attribute("id") == key + }).map(|maybe_elem| maybe_elem.clone()) + } +} + +impl HTMLCollection { pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option> { - *found = true; - self.Item(index) + let maybe_elem = self.Item(index); + *found = maybe_elem.is_some(); + maybe_elem } - pub fn NamedGetter(&self, _cx: *JSContext, _name: Option, _found: &mut bool) -> Fallible<*JSObject> { - Ok(ptr::null()) + pub fn NamedGetter(&self, maybe_name: Option, found: &mut bool) -> Option> { + match maybe_name { + Some(name) => { + let maybe_elem = self.NamedItem(name); + *found = maybe_elem.is_some(); + maybe_elem + }, + None => { + *found = false; + None + } + } } } diff --git a/src/components/script/dom/webidls/HTMLCollection.webidl b/src/components/script/dom/webidls/HTMLCollection.webidl index 2c1fc60e04a..7389e776834 100644 --- a/src/components/script/dom/webidls/HTMLCollection.webidl +++ b/src/components/script/dom/webidls/HTMLCollection.webidl @@ -10,6 +10,5 @@ interface HTMLCollection { readonly attribute unsigned long length; getter Element? item(unsigned long index); - [Throws] - getter object? namedItem(DOMString name); // only returns Element + getter Element? namedItem(DOMString name); }; From c768097adc6366dd60319aeaccc4f7e2f883e9f6 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 11 Feb 2014 13:39:57 -0400 Subject: [PATCH 2/8] Added HTMLCollection::create This is a sub-task for #1662. --- src/components/script/dom/htmlcollection.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index bb4cffc227e..3f176f4bc31 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -2,10 +2,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::bindings::codegen::InheritTypes::{ElementCast}; use dom::bindings::codegen::HTMLCollectionBinding; use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; +use dom::node::{Node, NodeHelpers}; use dom::window::Window; use servo_util::str::DOMString; @@ -31,6 +33,21 @@ impl HTMLCollection { } } +impl HTMLCollection { + pub fn create(window: &JS, root: &JS, predicate: |elem: &JS| -> bool) -> JS { + let mut elements = ~[]; + for child in root.traverse_preorder() { + if child.is_element() { + let elem: JS = ElementCast::to(&child); + if predicate(&elem) { + elements.push(elem); + } + } + } + HTMLCollection::new(window, elements) + } +} + impl HTMLCollection { // http://dom.spec.whatwg.org/#dom-htmlcollection-length pub fn Length(&self) -> u32 { From d22dbb53ca4bbbf3867d87f9d80059473bd48880 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 27 Feb 2014 13:14:02 -0400 Subject: [PATCH 3/8] Implemented {Document,Element}.getElementsByTagName --- src/components/script/dom/bindings/codegen/Bindings.conf | 2 ++ src/components/script/dom/document.rs | 4 ++-- src/components/script/dom/element.rs | 7 +++---- src/components/script/dom/htmlcollection.rs | 4 ++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 3420e40a4dd..36dbf48a6e8 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -32,6 +32,7 @@ DOMInterfaces = { 'createElement', 'createProcessingInstruction', 'createTextNode', + 'getElementsByTagName', 'title', ], }, @@ -43,6 +44,7 @@ DOMInterfaces = { 'attributes', 'getBoundingClientRect', 'getClientRects', + 'getElementsByTagName', 'id', 'innerHTML', 'outerHTML', diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 2a81d08f4a5..9190e36b0dd 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -212,8 +212,8 @@ impl Document { } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - pub fn GetElementsByTagName(&self, tag: DOMString) -> JS { - self.createHTMLCollection(|elem| elem.get().tag_name == tag) + pub fn GetElementsByTagName(&self, abstract_self: &JS, tag_name: DOMString) -> JS { + HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), tag_name) } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 4ff7872aa80..108d9aed19e 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -503,11 +503,10 @@ impl Element { self.GetAttributeNS(namespace, local_name).is_some() } - // http://dom.spec.whatwg.org/#dom-element-getelementsbytagname - pub fn GetElementsByTagName(&self, _localname: DOMString) -> JS { - // FIXME: stub - https://github.com/mozilla/servo/issues/1660 + pub fn GetElementsByTagName(&self, abstract_self: &JS, localname: DOMString) -> JS { let doc = self.node.owner_doc(); - HTMLCollection::new(&doc.get().window, ~[]) + let doc = doc.get(); + HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname) } // http://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 3f176f4bc31..b2a8ca0aa02 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -46,6 +46,10 @@ impl HTMLCollection { } HTMLCollection::new(window, elements) } + + pub fn by_tag_name(window: &JS, root: &JS, tag_name: DOMString) -> JS { + HTMLCollection::create(window, root, |elem| elem.get().tag_name == tag_name) + } } impl HTMLCollection { From e1499b610ed5e3d73b055652589098cce9c0c9dd Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 27 Feb 2014 13:18:03 -0400 Subject: [PATCH 4/8] Implemented {Document,Element}.getElementsByTagNameNS --- .../script/dom/bindings/codegen/Bindings.conf | 2 ++ src/components/script/dom/document.rs | 11 ++++++++++- src/components/script/dom/element.rs | 12 ++++++++---- src/components/script/dom/htmlcollection.rs | 5 +++++ src/components/script/dom/webidls/Document.webidl | 1 + src/components/script/dom/webidls/Element.webidl | 1 - 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 36dbf48a6e8..ffa19b30198 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -33,6 +33,7 @@ DOMInterfaces = { 'createProcessingInstruction', 'createTextNode', 'getElementsByTagName', + 'getElementsByTagNameNS', 'title', ], }, @@ -45,6 +46,7 @@ DOMInterfaces = { 'getBoundingClientRect', 'getClientRects', 'getElementsByTagName', + 'getElementsByTagNameNS', 'id', 'innerHTML', 'outerHTML', diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 9190e36b0dd..fba0d4b506f 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -35,7 +35,7 @@ use dom::window::Window; use html::hubbub_html_parser::build_element_from_tag; use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks}; use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage}; -use servo_util::namespace::Null; +use servo_util::namespace::{Namespace, Null}; use servo_util::str::DOMString; use extra::url::{Url, from_str}; @@ -216,6 +216,15 @@ impl Document { HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), tag_name) } + // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens + pub fn GetElementsByTagNameNS(&self, abstract_self: &JS, maybe_ns: Option, tag_name: DOMString) -> JS { + let namespace = match maybe_ns { + Some(namespace) => Namespace::from_str(namespace), + None => Null + }; + HTMLCollection::by_tag_name_ns(&self.window, &NodeCast::from(abstract_self), tag_name, namespace) + } + // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid pub fn GetElementById(&self, id: DOMString) -> Option> { // TODO: "in tree order, within the context object's tree" diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 108d9aed19e..a004126cc6d 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -509,11 +509,15 @@ impl Element { HTMLCollection::by_tag_name(&doc.window, &NodeCast::from(abstract_self), localname) } - // http://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens - pub fn GetElementsByTagNameNS(&self, _namespace: Option, _localname: DOMString) -> Fallible> { - // FIXME: stub - https://github.com/mozilla/servo/issues/1660 + pub fn GetElementsByTagNameNS(&self, abstract_self: &JS, maybe_ns: Option, + localname: DOMString) -> JS { let doc = self.node.owner_doc(); - Ok(HTMLCollection::new(&doc.get().window, ~[])) + let doc = doc.get(); + let namespace = match maybe_ns { + Some(namespace) => Namespace::from_str(namespace), + None => Null + }; + HTMLCollection::by_tag_name_ns(&doc.window, &NodeCast::from(abstract_self), localname, namespace) } // http://dom.spec.whatwg.org/#dom-element-getelementsbyclassname diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index b2a8ca0aa02..4d18e9734f4 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -9,6 +9,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::{Node, NodeHelpers}; use dom::window::Window; +use servo_util::namespace::Namespace; use servo_util::str::DOMString; #[deriving(Encodable)] @@ -50,6 +51,10 @@ impl HTMLCollection { pub fn by_tag_name(window: &JS, root: &JS, tag_name: DOMString) -> JS { HTMLCollection::create(window, root, |elem| elem.get().tag_name == tag_name) } + + pub fn by_tag_name_ns(window: &JS, root: &JS, tag_name: DOMString, namespace: Namespace) -> JS { + HTMLCollection::create(window, root, |elem| elem.get().namespace == namespace && elem.get().tag_name == tag_name) + } } impl HTMLCollection { diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index 11e92a0930e..9dc92b1520f 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -21,6 +21,7 @@ interface Document : Node { readonly attribute DocumentType? doctype; readonly attribute Element? documentElement; HTMLCollection getElementsByTagName(DOMString localName); + HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); Element? getElementById(DOMString elementId); [Creator, Throws] diff --git a/src/components/script/dom/webidls/Element.webidl b/src/components/script/dom/webidls/Element.webidl index 6c393f00067..e26c9415d4a 100644 --- a/src/components/script/dom/webidls/Element.webidl +++ b/src/components/script/dom/webidls/Element.webidl @@ -51,7 +51,6 @@ interface Element : Node { boolean hasAttributeNS(DOMString? namespace, DOMString localName); HTMLCollection getElementsByTagName(DOMString localName); - [Throws] HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); HTMLCollection getElementsByClassName(DOMString classNames); }; From d010861b757304466827b290be7805b6a1d3ce31 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 27 Feb 2014 13:18:29 -0400 Subject: [PATCH 5/8] Implemented {Document,Element}.getElementsByClassName --- .../script/dom/bindings/codegen/Bindings.conf | 2 ++ src/components/script/dom/document.rs | 5 +++++ src/components/script/dom/element.rs | 14 ++++++++++---- src/components/script/dom/htmlcollection.rs | 6 ++++++ src/components/script/dom/webidls/Document.webidl | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index ffa19b30198..7cff64d5ade 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -32,6 +32,7 @@ DOMInterfaces = { 'createElement', 'createProcessingInstruction', 'createTextNode', + 'getElementsByClassName', 'getElementsByTagName', 'getElementsByTagNameNS', 'title', @@ -45,6 +46,7 @@ DOMInterfaces = { 'attributes', 'getBoundingClientRect', 'getClientRects', + 'getElementsByClassName', 'getElementsByTagName', 'getElementsByTagNameNS', 'id', diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index fba0d4b506f..95de6ab2fac 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -225,6 +225,11 @@ impl Document { HTMLCollection::by_tag_name_ns(&self.window, &NodeCast::from(abstract_self), tag_name, namespace) } + // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname + pub fn GetElementsByClassName(&self, abstract_self: &JS, classes: DOMString) -> JS { + HTMLCollection::by_class_name(&self.window, &NodeCast::from(abstract_self), classes) + } + // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid pub fn GetElementById(&self, id: DOMString) -> Option> { // TODO: "in tree order, within the context object's tree" diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index a004126cc6d..95e4e7f9af9 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -370,6 +370,13 @@ impl Element { _ => false } } + + pub fn has_class(&self, name: &str) -> bool { + // FIXME: https://github.com/mozilla/servo/issues/1840 + let class_names = self.get_string_attribute("class"); + let mut classes = class_names.split(' '); + classes.any(|class| name == class) + } } // http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes @@ -520,11 +527,10 @@ impl Element { HTMLCollection::by_tag_name_ns(&doc.window, &NodeCast::from(abstract_self), localname, namespace) } - // http://dom.spec.whatwg.org/#dom-element-getelementsbyclassname - pub fn GetElementsByClassName(&self, _names: DOMString) -> JS { - // FIXME: stub - https://github.com/mozilla/servo/issues/1660 + pub fn GetElementsByClassName(&self, abstract_self: &JS, classes: DOMString) -> JS { let doc = self.node.owner_doc(); - HTMLCollection::new(&doc.get().window, ~[]) + let doc = doc.get(); + HTMLCollection::by_class_name(&doc.window, &NodeCast::from(abstract_self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 4d18e9734f4..96e04d46d3b 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -55,6 +55,12 @@ impl HTMLCollection { pub fn by_tag_name_ns(window: &JS, root: &JS, tag_name: DOMString, namespace: Namespace) -> JS { HTMLCollection::create(window, root, |elem| elem.get().namespace == namespace && elem.get().tag_name == tag_name) } + + pub fn by_class_name(window: &JS, root: &JS, classes: DOMString) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1840 + let classes: ~[&str] = classes.split(' ').collect(); + HTMLCollection::create(window, root, |elem| classes.iter().all(|class| elem.get().has_class(*class))) + } } impl HTMLCollection { diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index 9dc92b1520f..98df0b2aef9 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -22,6 +22,7 @@ interface Document : Node { readonly attribute Element? documentElement; HTMLCollection getElementsByTagName(DOMString localName); HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); + HTMLCollection getElementsByClassName(DOMString classNames); Element? getElementById(DOMString elementId); [Creator, Throws] From 38ba71ceb1ad828455f9ad8f6e07e584595ace64 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 27 Feb 2014 13:43:55 -0400 Subject: [PATCH 6/8] Replaced Document::createHTMLDocument in favor of HTMLCollection helpers --- .../script/dom/bindings/codegen/Bindings.conf | 8 +++ src/components/script/dom/document.rs | 57 ++++++++----------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 7cff64d5ade..369d08bfdf0 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -26,15 +26,23 @@ DOMInterfaces = { 'Console': {}, 'Document': { 'needsAbstract': [ + 'anchors', + 'applets', 'body', 'createComment', 'createDocumentFragment', 'createElement', 'createProcessingInstruction', 'createTextNode', + 'embeds', + 'forms', 'getElementsByClassName', 'getElementsByTagName', 'getElementsByTagNameNS', + 'images', + 'links', + 'plugins', + 'scripts', 'title', ], }, diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 95de6ab2fac..07660e30e88 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -431,43 +431,49 @@ impl Document { }) } - pub fn Images(&self) -> JS { - self.createHTMLCollection(|elem| "img" == elem.get().tag_name) + pub fn Images(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"img") } - pub fn Embeds(&self) -> JS { - self.createHTMLCollection(|elem| "embed" == elem.get().tag_name) + pub fn Embeds(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"embed") } - pub fn Plugins(&self) -> JS { - self.Embeds() + pub fn Plugins(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + self.Embeds(abstract_self) } - pub fn Links(&self) -> JS { - self.createHTMLCollection(|elem| { + pub fn Links(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), |elem| { ("a" == elem.get().tag_name || "area" == elem.get().tag_name) && elem.get().get_attribute(Null, "href").is_some() }) } - pub fn Forms(&self) -> JS { - self.createHTMLCollection(|elem| "form" == elem.get().tag_name) + pub fn Forms(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"form") } - pub fn Scripts(&self) -> JS { - self.createHTMLCollection(|elem| "script" == elem.get().tag_name) + pub fn Scripts(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"script") } - pub fn Anchors(&self) -> JS { - self.createHTMLCollection(|elem| { - "a" == elem.get().tag_name && - elem.get().get_attribute(Null, "name").is_some() + pub fn Anchors(&self, abstract_self: &JS) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1847 + HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), |elem| { + "a" == elem.get().tag_name && elem.get().get_attribute(Null, "name").is_some() }) } - pub fn Applets(&self) -> JS { + pub fn Applets(&self, abstract_self: &JS) -> JS { // FIXME: This should be return OBJECT elements containing applets. - self.createHTMLCollection(|elem| "applet" == elem.get().tag_name) + HTMLCollection::by_tag_name(&self.window, &NodeCast::from(abstract_self), ~"applet") } pub fn create_collection(&self, callback: |elem: &JS| -> Option>) -> ~[JS] { @@ -487,21 +493,6 @@ impl Document { nodes } - pub fn createHTMLCollection(&self, callback: |elem: &JS| -> bool) -> JS { - HTMLCollection::new(&self.window, self.create_collection(|node| { - if !node.is_element() { - return None; - } - - let element: JS = ElementCast::to(node); - if !callback(&element) { - return None; - } - - Some(element) - })) - } - pub fn createNodeList(&self, callback: |node: &JS| -> bool) -> JS { NodeList::new_simple_list(&self.window, self.create_collection(|node| { if !callback(node) { From 4b809bf9e6bf47822cb2826529826cfe1e8cb138 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 11 Feb 2014 12:12:34 -0400 Subject: [PATCH 7/8] Added FIXME stub comments This is a sub-task for #1662. --- src/components/script/dom/htmldatalistelement.rs | 1 + src/components/script/dom/htmlfieldsetelement.rs | 1 + src/components/script/dom/htmlformelement.rs | 1 + src/components/script/dom/htmlmapelement.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index 6cd888029c2..ef3f91f1702 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -42,6 +42,7 @@ impl HTMLDataListElement { impl HTMLDataListElement { pub fn Options(&self) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1842 let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); HTMLCollection::new(&doc.window, ~[]) diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index cdfc6eab402..4dec639d041 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -69,6 +69,7 @@ impl HTMLFieldSetElement { } pub fn Elements(&self) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1843 let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); HTMLCollection::new(&doc.window, ~[]) diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index 03d2ee8eeb1..a1ca7d5dc2f 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -115,6 +115,7 @@ impl HTMLFormElement { } pub fn Elements(&self) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1844 let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); HTMLCollection::new(&doc.window, ~[]) diff --git a/src/components/script/dom/htmlmapelement.rs b/src/components/script/dom/htmlmapelement.rs index 41516e9a5d2..d343073a278 100644 --- a/src/components/script/dom/htmlmapelement.rs +++ b/src/components/script/dom/htmlmapelement.rs @@ -51,6 +51,7 @@ impl HTMLMapElement { } pub fn Areas(&self) -> JS { + // FIXME: https://github.com/mozilla/servo/issues/1845 let doc = self.htmlelement.element.node.owner_doc(); let doc = doc.get(); HTMLCollection::new(&doc.window, ~[]) From 782c079697ddf7444ceb1a5822735283a8e3296f Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 27 Feb 2014 13:18:39 -0400 Subject: [PATCH 8/8] Added HTMLCollection content test --- .../html/content/test_htmlcollection.html | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/test/html/content/test_htmlcollection.html diff --git a/src/test/html/content/test_htmlcollection.html b/src/test/html/content/test_htmlcollection.html new file mode 100644 index 00000000000..e024a331e80 --- /dev/null +++ b/src/test/html/content/test_htmlcollection.html @@ -0,0 +1,127 @@ + + + + + + + +
+
+
+
+
+

+

+

+

+ +