aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/htmldocument.rs
diff options
context:
space:
mode:
authorYoungsoo Son <ysoo.son@samsung.com>2013-08-01 11:56:17 +0900
committerYoungsoo Son <ysoo.son@samsung.com>2013-08-01 11:56:17 +0900
commit8032b17e364eee08eb7f2f643afa3904048ea857 (patch)
treefbbc61646943a6371707bc44795244c95b4d3c4e /src/components/script/dom/htmldocument.rs
parent7911ae56954cc0ff03f77ff901233a411a30f1e7 (diff)
downloadservo-8032b17e364eee08eb7f2f643afa3904048ea857.tar.gz
servo-8032b17e364eee08eb7f2f643afa3904048ea857.zip
This implements the DOM tree accessors that return a HTMLCollection
Diffstat (limited to 'src/components/script/dom/htmldocument.rs')
-rw-r--r--src/components/script/dom/htmldocument.rs54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs
index b44a1b400d8..b45e56910f8 100644
--- a/src/components/script/dom/htmldocument.rs
+++ b/src/components/script/dom/htmldocument.rs
@@ -12,6 +12,8 @@ use dom::window::Window;
use js::jsapi::{JSObject, JSContext};
+use servo_util::tree::TreeUtils;
+
use std::libc;
use std::ptr;
@@ -64,33 +66,27 @@ impl HTMLDocument {
}
pub fn Images(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"img")
}
pub fn Embeds(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"embed")
}
pub fn Plugins(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.Embeds()
}
pub fn Links(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"link")
}
pub fn Forms(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"form")
}
pub fn Scripts(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"script")
}
pub fn Close(&self, _rv: &mut ErrorResult) {
@@ -163,13 +159,11 @@ impl HTMLDocument {
}
pub fn Anchors(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"a")
}
pub fn Applets(&self) -> @mut HTMLCollection {
- let (scope, cx) = self.get_scope_and_cx();
- HTMLCollection::new(~[], cx, scope)
+ self.createHTMLCollection(~"applet")
}
pub fn Clear(&self) {
@@ -178,6 +172,33 @@ impl HTMLDocument {
pub fn GetAll(&self, _cx: *JSContext, _rv: &mut ErrorResult) -> *libc::c_void {
ptr::null()
}
+
+ fn createHTMLCollection(&self, elem_name: ~str) -> @mut HTMLCollection {
+ let (scope, cx) = self.get_scope_and_cx();
+ let mut elements = ~[];
+ let _ = for self.parent.root.traverse_preorder |child| {
+ if child.is_element() {
+ do child.with_imm_element |elem| {
+ match elem_name {
+ ~"link" => {
+ if elem.tag_name == ~"a" || elem.tag_name == ~"area" {
+ match elem.get_attr("href") {
+ Some(_val) => elements.push(child),
+ None() => ()
+ }
+ }
+ }
+ _ => {
+ if elem.tag_name == elem_name {
+ elements.push(child);
+ }
+ }
+ }
+ }
+ }
+ };
+ HTMLCollection::new(elements, cx, scope)
+ }
}
impl CacheableWrapper for HTMLDocument {
@@ -196,3 +217,4 @@ impl BindingObject for HTMLDocument {
self.parent.GetParentObject(cx)
}
}
+