aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2014-09-19 09:15:03 -0400
committerJosh Matthews <josh@joshmatthews.net>2014-09-19 09:15:03 -0400
commitb82c0dced08ccda8c3c7f35643c3891bc45b058c (patch)
tree4b392e6e26e6d2d4433875cbb51c90237e351f70 /components/script/dom
parent2652d223f50d53ee5a8a07ff4a3d6a25b510d1f1 (diff)
parentfae7ce3c1dbcbf90460c3fba683c162b6c742cc7 (diff)
downloadservo-b82c0dced08ccda8c3c7f35643c3891bc45b058c.tar.gz
servo-b82c0dced08ccda8c3c7f35643c3891bc45b058c.zip
Merge pull request #3172 from jdm/devtools
Dump initial prototype of devtools server into the build. Expect lies if...
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/attr.rs11
-rw-r--r--components/script/dom/element.rs15
-rw-r--r--components/script/dom/node.rs55
3 files changed, 80 insertions, 1 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index be419eb2a61..61f520821a1 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -13,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;
@@ -149,6 +151,7 @@ pub trait AttrHelpers {
fn set_value(&self, set_type: AttrSettingType, value: AttrValue);
fn value<'a>(&'a self) -> Ref<'a, AttrValue>;
fn local_name<'a>(&'a self) -> &'a Atom;
+ fn summarize(&self) -> AttrInfo;
}
impl<'a> AttrHelpers for JSRef<'a, Attr> {
@@ -184,6 +187,14 @@ impl<'a> AttrHelpers for JSRef<'a, Attr> {
fn local_name<'a>(&'a self) -> &'a Atom {
&self.local_name
}
+
+ fn summarize(&self) -> AttrInfo {
+ AttrInfo {
+ namespace: self.namespace.to_str().to_string(),
+ name: self.Name(),
+ value: self.Value(),
+ }
+ }
}
pub trait AttrHelpersForLayout {
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 e72e95052a6..608fdcad118 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -9,7 +9,9 @@ use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
+use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods};
+use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
use dom::bindings::codegen::InheritTypes::{CommentCast, DocumentCast, DocumentTypeCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast, ElementDerived};
@@ -36,7 +38,7 @@ use dom::element::{HTMLInputElementTypeId, HTMLSelectElementTypeId};
use dom::element::{HTMLTextAreaElementTypeId, HTMLOptGroupElementTypeId};
use dom::element::{HTMLOptionElementTypeId, HTMLFieldSetElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
-use dom::nodelist::{NodeList};
+use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
use dom::text::Text;
use dom::virtualmethods::{VirtualMethods, vtable_for};
@@ -45,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};
@@ -59,6 +62,7 @@ use std::mem;
use style;
use style::ComputedValues;
use sync::Arc;
+use uuid;
use serialize::{Encoder, Encodable};
@@ -105,6 +109,8 @@ pub struct Node {
/// Must be sent back to the layout task to be destroyed when this
/// node is finalized.
pub layout_data: LayoutDataRef,
+
+ unique_id: RefCell<String>,
}
impl<S: Encoder<E>, E> Encodable<S, E> for LayoutDataRef {
@@ -419,6 +425,9 @@ pub trait NodeHelpers<'m, 'n> {
fn query_selector_all(&self, selectors: DOMString) -> Fallible<Temporary<NodeList>>;
fn remove_self(&self);
+
+ fn get_unique_id(&self) -> String;
+ fn summarize(&self) -> NodeInfo;
}
impl<'m, 'n> NodeHelpers<'m, 'n> for JSRef<'n, Node> {
@@ -687,6 +696,48 @@ impl<'m, 'n> NodeHelpers<'m, 'n> for JSRef<'n, Node> {
None => ()
}
}
+
+ fn get_unique_id(&self) -> String {
+ self.unique_id.borrow().clone()
+ }
+
+ fn summarize(&self) -> NodeInfo {
+ 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();
+ }
+
+ NodeInfo {
+ uniqueId: self.unique_id.borrow().clone(),
+ baseURI: self.GetBaseURI().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(),
+ numChildren: self.ChildNodes().root().Length() as uint,
+
+ //FIXME doctype nodes only
+ name: "".to_string(),
+ publicId: "".to_string(),
+ systemId: "".to_string(),
+
+ attrs: if self.is_element() {
+ let elem: &JSRef<Element> = ElementCast::to_ref(self).unwrap();
+ elem.summarize()
+ } else {
+ vec!()
+ },
+
+ isDocumentElement:
+ self.owner_doc().root()
+ .GetDocumentElement()
+ .map(|elem| NodeCast::from_ref(&*elem.root()) == self)
+ .unwrap_or(false),
+
+ shortValue: self.GetNodeValue().unwrap_or("".to_string()), //FIXME: truncate
+ incompleteValue: false, //FIXME: reflect truncation
+ }
+ }
}
/// If the given untrusted node address represents a valid DOM node in the given runtime,
@@ -991,6 +1042,8 @@ impl Node {
flags: Traceable::new(RefCell::new(NodeFlags::new(type_id))),
layout_data: LayoutDataRef::new(),
+
+ unique_id: RefCell::new("".to_string()),
}
}