aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/document.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2013-08-08 23:00:38 -0700
committerbors-servo <release+servo@mozilla.com>2013-08-08 23:00:38 -0700
commit73e7b6519b64160c802acd5175c01aacfd0daba6 (patch)
tree8385c805ed1bd616fa8568ab7a5ff295005496c5 /src/components/script/dom/document.rs
parent1da9f340825fa75e0c76c26a62662a9def641a32 (diff)
parent133cf9caf1f1ca808520ffa2c1c2a02b463c9df8 (diff)
downloadservo-73e7b6519b64160c802acd5175c01aacfd0daba6.tar.gz
servo-73e7b6519b64160c802acd5175c01aacfd0daba6.zip
auto merge of #705 : sonwow/servo/collection, r=jdm
Simplify some APIs that returns HTMLCollection in `dom::Document`. In order to do this, `dom::htmldocument::createHTMLCollection` is moved to `dom::document::createHTMLCollection`.
Diffstat (limited to 'src/components/script/dom/document.rs')
-rw-r--r--src/components/script/dom/document.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index e338eee5dae..af7b5c7ff23 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -5,7 +5,8 @@
use dom::bindings::codegen::DocumentBinding;
use dom::bindings::utils::{DOMString, WrapperCache, ErrorResult, null_string, str};
use dom::bindings::utils::{BindingObject, CacheableWrapper, rust_box, DerivedWrapper};
-use dom::element::{HTMLHtmlElement, HTMLTitleElement, HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId};
+use dom::element::{Element, HTMLHtmlElement, HTMLTitleElement};
+use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId};
use dom::event::Event;
use dom::htmlcollection::HTMLCollection;
use dom::htmldocument::HTMLDocument;
@@ -216,19 +217,7 @@ impl Document {
}
pub fn GetElementsByTagName(&self, tag: &DOMString) -> @mut HTMLCollection {
- let mut elements = ~[];
- let tag = tag.to_str();
- let _ = for self.root.traverse_preorder |child| {
- if child.is_element() {
- do child.with_imm_element |elem| {
- if elem.tag_name == tag {
- elements.push(child);
- }
- }
- }
- };
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(elements, cx, scope)
+ self.createHTMLCollection(|elem| eq_slice(elem.tag_name, tag.to_str()))
}
pub fn GetElementsByTagNameNS(&self, _ns: &DOMString, _tag: &DOMString) -> @mut HTMLCollection {
@@ -431,14 +420,17 @@ impl Document {
}
pub fn GetElementsByName(&self, name: &DOMString) -> @mut HTMLCollection {
+ self.createHTMLCollection(|elem|
+ elem.get_attr("name").is_some() && eq_slice(elem.get_attr("name").unwrap(), name.to_str()))
+ }
+
+ pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection {
let mut elements = ~[];
- let name = name.to_str();
let _ = for self.root.traverse_preorder |child| {
if child.is_element() {
do child.with_imm_element |elem| {
- match elem.get_attr("name") {
- Some(val) => if eq_slice(val, name) { elements.push(child) },
- None() => ()
+ if callback(elem) {
+ elements.push(child);
}
}
}