diff --git a/components/layout/query.rs b/components/layout/query.rs index 4fe98c05969..bd6088a1e05 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -54,7 +54,7 @@ pub struct LayoutThreadData { pub stylist: Arc, /// A queued response for the union of the content boxes of a node. - pub content_box_response: Rect, + pub content_box_response: Option>, /// A queued response for the content boxes of a node. pub content_boxes_response: Vec>, @@ -384,15 +384,12 @@ impl FragmentBorderBoxIterator for MarginRetrievingFragmentBorderBoxIterator { } pub fn process_content_box_request( - requested_node: N, layout_root: &mut Flow) -> Rect { + requested_node: N, layout_root: &mut Flow) -> Option> { // FIXME(pcwalton): This has not been updated to handle the stacking context relative // stuff. So the position is wrong in most cases. let mut iterator = UnioningFragmentBorderBoxIterator::new(requested_node.opaque()); sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator); - match iterator.rect { - Some(rect) => rect, - None => Rect::zero() - } + iterator.rect } pub fn process_content_boxes_request(requested_node: N, layout_root: &mut Flow) diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 6dc72bc86c3..c641a23dcd0 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -464,7 +464,7 @@ impl LayoutThread { constellation_chan: constellation_chan, display_list: None, stylist: stylist, - content_box_response: Rect::zero(), + content_box_response: None, content_boxes_response: Vec::new(), client_rect_response: Rect::zero(), hit_test_response: (None, false), @@ -1012,7 +1012,7 @@ impl LayoutThread { debug!("layout: No root node: bailing"); match data.query_type { ReflowQueryType::ContentBoxQuery(_) => { - rw_data.content_box_response = Rect::zero(); + rw_data.content_box_response = None; }, ReflowQueryType::ContentBoxesQuery(_) => { rw_data.content_boxes_response = Vec::new(); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 8902a0545ab..940f98fc8fd 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -524,8 +524,12 @@ impl Node { TrustedNodeAddress(&*self as *const Node as *const libc::c_void) } + /// Returns the rendered bounding content box if the element is rendered, + /// and none otherwise. pub fn bounding_content_box(&self) -> Rect { - window_from_node(self).content_box_query(self.to_trusted_node_address()) + window_from_node(self) + .content_box_query(self.to_trusted_node_address()) + .unwrap_or_else(Rect::zero) } pub fn content_boxes(&self) -> Vec> { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d0a87168ab7..9bc4586dc38 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1216,11 +1216,11 @@ impl Window { &*self.layout_rpc } - pub fn content_box_query(&self, content_box_request: TrustedNodeAddress) -> Rect { + pub fn content_box_query(&self, content_box_request: TrustedNodeAddress) -> Option> { if !self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxQuery(content_box_request), ReflowReason::Query) { - return Rect::zero(); + return None; } let ContentBoxResponse(rect) = self.layout_rpc.content_box(); rect diff --git a/components/script_layout_interface/rpc.rs b/components/script_layout_interface/rpc.rs index 7b559078291..2fb75f6b959 100644 --- a/components/script_layout_interface/rpc.rs +++ b/components/script_layout_interface/rpc.rs @@ -43,7 +43,7 @@ pub trait LayoutRPC { fn text_index(&self) -> TextIndexResponse; } -pub struct ContentBoxResponse(pub Rect); +pub struct ContentBoxResponse(pub Option>); pub struct ContentBoxesResponse(pub Vec>);