diff options
author | Josh Matthews <josh@joshmatthews.net> | 2014-09-04 16:21:50 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2014-09-18 15:07:11 -0400 |
commit | fae7ce3c1dbcbf90460c3fba683c162b6c742cc7 (patch) | |
tree | a606e8ca9c5cd1c204eeeb7800ac8ee3d67b1a54 /components/script/dom | |
parent | fa57fe890b20200d1b69ef0a8baf6b313183b237 (diff) | |
download | servo-fae7ce3c1dbcbf90460c3fba683c162b6c742cc7.tar.gz servo-fae7ce3c1dbcbf90460c3fba683c162b6c742cc7.zip |
Retrieve some basic layout properties for nodes to make the box model somewhat useful.
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/attr.rs | 5 | ||||
-rw-r--r-- | components/script/dom/element.rs | 15 | ||||
-rw-r--r-- | components/script/dom/node.rs | 16 |
3 files changed, 22 insertions, 14 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index ebad173edda..61f520821a1 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -2,7 +2,6 @@ * 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 devtools_traits::AttrInfo; use dom::bindings::codegen::Bindings::AttrBinding; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::InheritTypes::NodeCast; @@ -14,6 +13,8 @@ use dom::element::{Element, AttributeHandlers}; use dom::node::Node; use dom::window::Window; use dom::virtualmethods::vtable_for; + +use devtools_traits::AttrInfo; use servo_util::atom::Atom; use servo_util::namespace; use servo_util::namespace::Namespace; @@ -189,7 +190,7 @@ impl<'a> AttrHelpers for JSRef<'a, Attr> { fn summarize(&self) -> AttrInfo { AttrInfo { - namespace: self.GetNamespaceURI().unwrap_or("".to_string()), + namespace: self.namespace.to_str().to_string(), name: self.Name(), value: self.Value(), } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 953036788f4..ab61fc47136 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -10,6 +10,7 @@ use dom::namednodemap::NamedNodeMap; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::ElementBinding; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; +use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast}; use dom::bindings::js::{JS, JSRef, Temporary, TemporaryPushable}; use dom::bindings::js::{OptionalSettable, OptionalRootable, Root}; @@ -30,6 +31,7 @@ use dom::nodelist::NodeList; use dom::virtualmethods::{VirtualMethods, vtable_for}; use layout_interface::ContentChangedDocumentDamage; use layout_interface::MatchSelectorsDocumentDamage; +use devtools_traits::AttrInfo; use style::{matches, parse_selector_list_from_str}; use style; use servo_util::atom::Atom; @@ -239,6 +241,7 @@ pub trait ElementHelpers { fn html_element_in_html_document(&self) -> bool; fn get_local_name<'a>(&'a self) -> &'a Atom; fn get_namespace<'a>(&'a self) -> &'a Namespace; + fn summarize(&self) -> Vec<AttrInfo>; } impl<'a> ElementHelpers for JSRef<'a, Element> { @@ -254,6 +257,18 @@ impl<'a> ElementHelpers for JSRef<'a, Element> { fn get_namespace<'a>(&'a self) -> &'a Namespace { &self.deref().namespace } + + fn summarize(&self) -> Vec<AttrInfo> { + let attrs = self.Attributes().root(); + let mut i = 0; + let mut summarized = vec!(); + while i < attrs.Length() { + let attr = attrs.Item(i).unwrap().root(); + summarized.push(attr.summarize()); + i += 1; + } + summarized + } } pub trait AttributeHandlers { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index e58f0e888a6..04d2686df18 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -4,7 +4,6 @@ //! The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements. -use devtools_traits::NodeInfo; use dom::attr::{Attr, AttrHelpers}; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; @@ -48,6 +47,7 @@ use geom::rect::Rect; use html::hubbub_html_parser::build_element_from_tag; use layout_interface::{ContentBoxResponse, ContentBoxesResponse, LayoutRPC, LayoutChan, ReapLayoutDataMsg, TrustedNodeAddress, UntrustedNodeAddress}; +use devtools_traits::NodeInfo; use servo_util::geometry::Au; use servo_util::str::{DOMString, null_str_as_empty}; use style::{parse_selector_list_from_str, matches}; @@ -702,7 +702,7 @@ impl<'m, 'n> NodeHelpers<'m, 'n> for JSRef<'n, Node> { } fn summarize(&self) -> NodeInfo { - if self.unique_id.borrow().as_slice() == "" { + if self.unique_id.borrow().is_empty() { let mut unique_id = self.unique_id.borrow_mut(); *unique_id = uuid::Uuid::new_v4().to_simple_str(); } @@ -710,7 +710,7 @@ impl<'m, 'n> NodeHelpers<'m, 'n> for JSRef<'n, Node> { NodeInfo { uniqueId: self.unique_id.borrow().clone(), baseURI: self.GetBaseURI().unwrap_or("".to_string()), - parent: self.GetParentNode().root().map(|node| node.unique_id.borrow().clone()).unwrap_or("".to_string()), + parent: self.GetParentNode().root().map(|node| node.get_unique_id()).unwrap_or("".to_string()), nodeType: self.NodeType() as uint, namespaceURI: "".to_string(), //FIXME nodeName: self.NodeName(), @@ -722,16 +722,8 @@ impl<'m, 'n> NodeHelpers<'m, 'n> for JSRef<'n, Node> { systemId: "".to_string(), attrs: if self.is_element() { - let mut summarized = vec!(); let elem: &JSRef<Element> = ElementCast::to_ref(self).unwrap(); - let attrs = elem.Attributes().root(); - let mut i = 0; - while i < attrs.Length() { - let attr = attrs.Item(i).unwrap().root(); - summarized.push(attr.summarize()); - i += 1; - } - summarized + elem.summarize() } else { vec!() }, |