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/script_task.rs | |
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/script_task.rs')
-rw-r--r-- | components/script/script_task.rs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs index e49350a1942..1dd63abeadd 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -6,7 +6,9 @@ //! and layout tasks. use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; -use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast}; +use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; +use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; +use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast, ElementCast}; use dom::bindings::conversions; use dom::bindings::conversions::{FromJSValConvertible, Empty}; use dom::bindings::global::Window; @@ -36,7 +38,7 @@ use page::{Page, IterablePage, Frame}; use devtools_traits; use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, NewGlobal, NodeInfo, GetRootNode}; use devtools_traits::{DevtoolScriptControlMsg, EvaluateJS, EvaluateJSReply, GetDocumentElement}; -use devtools_traits::{GetChildren}; +use devtools_traits::{GetChildren, GetLayout}; use script_traits::{CompositorEvent, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent}; use script_traits::{MouseMoveEvent, MouseUpEvent, ConstellationControlMsg, ScriptTaskFactory}; use script_traits::{ResizeMsg, AttachLayoutMsg, LoadMsg, SendEventMsg, ResizeInactiveMsg}; @@ -506,6 +508,7 @@ impl ScriptTask { FromDevtools(GetRootNode(id, reply)) => self.handle_get_root_node(id, reply), FromDevtools(GetDocumentElement(id, reply)) => self.handle_get_document_element(id, reply), FromDevtools(GetChildren(id, node_id, reply)) => self.handle_get_children(id, node_id, reply), + FromDevtools(GetLayout(id, node_id, reply)) => self.handle_get_layout(id, node_id, reply), } } @@ -554,28 +557,34 @@ impl ScriptTask { reply.send(node.summarize()); } - fn handle_get_children(&self, pipeline: PipelineId, node_id: String, reply: Sender<Vec<NodeInfo>>) { + fn find_node_by_unique_id(&self, pipeline: PipelineId, node_id: String) -> Temporary<Node> { let page = get_page(&*self.page.borrow(), pipeline); let frame = page.frame(); let document = frame.get_ref().document.root(); let node: &JSRef<Node> = NodeCast::from_ref(&*document); - let mut children = vec!(); - let mut found_parent = false; for candidate in node.traverse_preorder() { if candidate.get_unique_id().as_slice() == node_id.as_slice() { - found_parent = true; - for kid in candidate.children() { - children.push(kid.summarize()); - } - break; + return Temporary::from_rooted(&candidate); } } - assert!(found_parent); + fail!("couldn't find node with unique id {:s}", node_id) + } + + fn handle_get_children(&self, pipeline: PipelineId, node_id: String, reply: Sender<Vec<NodeInfo>>) { + let parent = self.find_node_by_unique_id(pipeline, node_id).root(); + let children = parent.children().map(|child| child.summarize()).collect(); reply.send(children); } + fn handle_get_layout(&self, pipeline: PipelineId, node_id: String, reply: Sender<(f32, f32)>) { + let node = self.find_node_by_unique_id(pipeline, node_id).root(); + let elem: &JSRef<Element> = ElementCast::to_ref(&*node).expect("should be getting layout of element"); + let rect = elem.GetBoundingClientRect().root(); + reply.send((rect.Width(), rect.Height())); + } + fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) { debug!("Script: new layout: {:?}", new_layout_info); let NewLayoutInfo { |