auto merge of #2210 : saneyuki/servo/query, r=jdm

- see #356
- To decrease the conversion code, `JS<Node>` -> `Node`, I added API methods to `NodeHelpers`.
- I added APIs to `Page` not `Document` because I had thought that their APIs returns the hitted nodes address in the "page".
This commit is contained in:
bors-servo 2014-04-24 09:52:11 -04:00
commit 6d89e67194
4 changed files with 87 additions and 55 deletions

View file

@ -20,8 +20,7 @@ use dom::htmlcollection::HTMLCollection;
use dom::htmlserializer::serialize;
use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator, document_from_node};
use dom::virtualmethods::{VirtualMethods, vtable_for};
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse, ContentChangedDocumentDamage};
use layout_interface::ContentChangedDocumentDamage;
use layout_interface::MatchSelectorsDocumentDamage;
use style;
use servo_util::namespace;
@ -605,9 +604,7 @@ impl Element {
let doc = self.node.owner_doc();
let win = &doc.get().window;
let node: JS<Node> = NodeCast::from(abstract_self);
let (chan, port) = channel();
let addr = node.to_trusted_node_address();
let ContentBoxesResponse(rects) = win.get().page().query_layout(ContentBoxesQuery(addr, chan), port);
let rects = node.get_content_boxes();
let rects = rects.map(|r| {
ClientRect::new(
win,
@ -625,9 +622,7 @@ impl Element {
let doc = self.node.owner_doc();
let win = &doc.get().window;
let node: JS<Node> = NodeCast::from(abstract_self);
let (chan, port) = channel();
let addr = node.to_trusted_node_address();
let ContentBoxResponse(rect) = win.get().page().query_layout(ContentBoxQuery(addr, chan), port);
let rect = node.get_bounding_content_box();
ClientRect::new(
win,
rect.origin.y,

View file

@ -16,7 +16,6 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId, NodeHelpers, window_from_node};
use dom::virtualmethods::VirtualMethods;
use servo_util::geometry::to_px;
use layout_interface::{ContentBoxQuery, ContentBoxResponse};
use servo_net::image_cache_task;
use servo_util::url::parse_url;
use servo_util::str::DOMString;
@ -131,11 +130,7 @@ impl HTMLImageElement {
pub fn Width(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
let node: JS<Node> = NodeCast::from(abstract_self);
let window = window_from_node(&node);
let page = window.get().page();
let (chan, port) = channel();
let addr = node.to_trusted_node_address();
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
let rect = node.get_bounding_content_box();
to_px(rect.size.width) as u32
}
@ -145,13 +140,8 @@ impl HTMLImageElement {
}
pub fn Height(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
let node = &self.htmlelement.element.node;
let doc = node.owner_doc();
let page = doc.get().window.get().page();
let (chan, port) = channel();
let this_node: JS<Node> = NodeCast::from(abstract_self);
let addr = this_node.to_trusted_node_address();
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
let node: JS<Node> = NodeCast::from(abstract_self);
let rect = node.get_bounding_content_box();
to_px(rect.size.height) as u32
}

View file

@ -26,9 +26,11 @@ use dom::processinginstruction::ProcessingInstruction;
use dom::text::Text;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use dom::window::Window;
use geom::rect::Rect;
use html::hubbub_html_parser::build_element_from_tag;
use layout_interface::{LayoutChan, ReapLayoutDataMsg, UntrustedNodeAddress};
use layout_interface::TrustedNodeAddress;
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery, ContentBoxesResponse,
LayoutChan, ReapLayoutDataMsg, TrustedNodeAddress, UntrustedNodeAddress};
use servo_util::geometry::Au;
use servo_util::str::{DOMString, null_str_as_empty};
use js::jsapi::{JSContext, JSObject, JSRuntime};
@ -283,6 +285,9 @@ pub trait NodeHelpers {
fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) -> Self;
fn to_trusted_node_address(&self) -> TrustedNodeAddress;
fn get_bounding_content_box(&self) -> Rect<Au>;
fn get_content_boxes(&self) -> ~[Rect<Au>];
}
impl NodeHelpers for JS<Node> {
@ -565,6 +570,24 @@ impl NodeHelpers for JS<Node> {
fn to_trusted_node_address(&self) -> TrustedNodeAddress {
TrustedNodeAddress(self.get() as *Node as *libc::c_void)
}
fn get_bounding_content_box(&self) -> Rect<Au> {
let window = window_from_node(self);
let page = window.get().page();
let (chan, port) = channel();
let addr = self.to_trusted_node_address();
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
rect
}
fn get_content_boxes(&self) -> ~[Rect<Au>] {
let window = window_from_node(self);
let page = window.get().page();
let (chan, port) = channel();
let addr = self.to_trusted_node_address();
let ContentBoxesResponse(rects) = page.query_layout(ContentBoxesQuery(addr, chan), port);
rects
}
}
//