Skip to content

Commit

Permalink
layout: Expose whether the element was rendered in content_box_query …
Browse files Browse the repository at this point in the history
…to script.

But don't change the API yet.
  • Loading branch information
emilio committed Jan 17, 2017
1 parent 8159dac commit 485fe87
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
9 changes: 3 additions & 6 deletions components/layout/query.rs
Expand Up @@ -54,7 +54,7 @@ pub struct LayoutThreadData {
pub stylist: Arc<Stylist>,

/// A queued response for the union of the content boxes of a node.
pub content_box_response: Rect<Au>,
pub content_box_response: Option<Rect<Au>>,

/// A queued response for the content boxes of a node.
pub content_boxes_response: Vec<Rect<Au>>,
Expand Down Expand Up @@ -384,15 +384,12 @@ impl FragmentBorderBoxIterator for MarginRetrievingFragmentBorderBoxIterator {
}

pub fn process_content_box_request<N: LayoutNode>(
requested_node: N, layout_root: &mut Flow) -> Rect<Au> {
requested_node: N, layout_root: &mut Flow) -> Option<Rect<Au>> {
// 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<N: LayoutNode>(requested_node: N, layout_root: &mut Flow)
Expand Down
4 changes: 2 additions & 2 deletions components/layout_thread/lib.rs
Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion components/script/dom/node.rs
Expand Up @@ -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<Au> {
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<Rect<Au>> {
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/window.rs
Expand Up @@ -1216,11 +1216,11 @@ impl Window {
&*self.layout_rpc
}

pub fn content_box_query(&self, content_box_request: TrustedNodeAddress) -> Rect<Au> {
pub fn content_box_query(&self, content_box_request: TrustedNodeAddress) -> Option<Rect<Au>> {
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
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/rpc.rs
Expand Up @@ -43,7 +43,7 @@ pub trait LayoutRPC {
fn text_index(&self) -> TextIndexResponse;
}

pub struct ContentBoxResponse(pub Rect<Au>);
pub struct ContentBoxResponse(pub Option<Rect<Au>>);

pub struct ContentBoxesResponse(pub Vec<Rect<Au>>);

Expand Down

0 comments on commit 485fe87

Please sign in to comment.