Auto merge of #8205 - Ms2ger:query, r=jdm

Return the result from query functions.

This reduces some unnecessarily tight coupling, makes it clearer what these functions do, and may help avoid bugs where we would return from such a function without updating the relevant field.

It is also a precondition for some future experimentation I'm thinking of doing with this querying design.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8205)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-26 09:00:30 -05:00
commit 3a254b7e20
2 changed files with 44 additions and 47 deletions

View file

@ -877,25 +877,24 @@ impl LayoutTask {
traversal); traversal);
} }
fn process_node_geometry_request<'a>(&'a self, fn process_node_geometry_request(&self,
requested_node: TrustedNodeAddress, requested_node: TrustedNodeAddress,
layout_root: &mut FlowRef, layout_root: &mut FlowRef)
rw_data: &mut RWGuard<'a>) { -> Rect<i32> {
let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node); let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node);
let mut iterator = FragmentLocatingFragmentIterator::new(requested_node); let mut iterator = FragmentLocatingFragmentIterator::new(requested_node);
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator); sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator);
rw_data.client_rect_response = iterator.client_rect; iterator.client_rect
} }
// Compute the resolved value of property for a given (pseudo)element. /// Return the resolved value of property for a given (pseudo)element.
// Stores the result in rw_data.resolved_style_response. /// https://drafts.csswg.org/cssom/#resolved-value
// https://drafts.csswg.org/cssom/#resolved-value fn process_resolved_style_request(&self,
fn process_resolved_style_request<'a>(&'a self, requested_node: TrustedNodeAddress,
requested_node: TrustedNodeAddress, pseudo: &Option<PseudoElement>,
pseudo: &Option<PseudoElement>, property: &Atom,
property: &Atom, layout_root: &mut FlowRef)
layout_root: &mut FlowRef, -> Option<String> {
rw_data: &mut RWGuard<'a>) {
// FIXME: Isolate this transmutation into a "bridge" module. // FIXME: Isolate this transmutation into a "bridge" module.
// FIXME(rust#16366): The following line had to be moved because of a // FIXME(rust#16366): The following line had to be moved because of a
// rustc bug. It should be in the next unsafe block. // rustc bug. It should be in the next unsafe block.
@ -918,8 +917,7 @@ impl LayoutTask {
// The pseudo doesn't exist, return nothing. Chrome seems to query // The pseudo doesn't exist, return nothing. Chrome seems to query
// the element itself in this case, Firefox uses the resolved value. // the element itself in this case, Firefox uses the resolved value.
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=29006 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=29006
rw_data.resolved_style_response = None; return None;
return;
} }
Some(layout_node) => layout_node Some(layout_node) => layout_node
}; };
@ -970,7 +968,7 @@ impl LayoutTask {
style.writing_mode); style.writing_mode);
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root,
&mut iterator); &mut iterator);
rw_data.resolved_style_response = iterator.result.map(|r| r.to_css_string()); iterator.result.map(|r| r.to_css_string())
}, },
atom!("bottom") | atom!("top") | atom!("right") | atom!("bottom") | atom!("top") | atom!("right") |
@ -1003,20 +1001,19 @@ impl LayoutTask {
position); position);
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root,
&mut iterator); &mut iterator);
rw_data.resolved_style_response = iterator.result.map(|r| r.to_css_string()); iterator.result.map(|r| r.to_css_string())
}, },
// FIXME: implement used value computation for line-height // FIXME: implement used value computation for line-height
ref property => { ref property => {
rw_data.resolved_style_response = style.computed_value_to_string(property.as_slice()).ok()
style.computed_value_to_string(property.as_slice()).ok();
} }
}; }
} }
fn process_offset_parent_query<'a>(&'a self, fn process_offset_parent_query(&self,
requested_node: TrustedNodeAddress, requested_node: TrustedNodeAddress,
layout_root: &mut FlowRef, layout_root: &mut FlowRef)
rw_data: &mut RWGuard<'a>) { -> OffsetParentResponse {
let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node); let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node);
let mut iterator = ParentOffsetBorderBoxIterator::new(requested_node); let mut iterator = ParentOffsetBorderBoxIterator::new(requested_node);
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator); sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator);
@ -1026,13 +1023,13 @@ impl LayoutTask {
let parent = iterator.parent_nodes[parent_info_index].as_ref().unwrap(); let parent = iterator.parent_nodes[parent_info_index].as_ref().unwrap();
let origin = iterator.node_border_box.origin - parent.border_box.origin; let origin = iterator.node_border_box.origin - parent.border_box.origin;
let size = iterator.node_border_box.size; let size = iterator.node_border_box.size;
rw_data.offset_parent_response = OffsetParentResponse { OffsetParentResponse {
node_address: Some(parent.node_address.to_untrusted_node_address()), node_address: Some(parent.node_address.to_untrusted_node_address()),
rect: Rect::new(origin, size), rect: Rect::new(origin, size),
}; }
} }
None => { None => {
rw_data.offset_parent_response = OffsetParentResponse::empty(); OffsetParentResponse::empty()
} }
} }
} }
@ -1231,20 +1228,20 @@ impl LayoutTask {
if let Some(mut root_flow) = rw_data.layout_root() { if let Some(mut root_flow) = rw_data.layout_root() {
match data.query_type { match data.query_type {
ReflowQueryType::ContentBoxQuery(node) => ReflowQueryType::ContentBoxQuery(node) =>
process_content_box_request(node, &mut root_flow, &mut rw_data), rw_data.content_box_response = process_content_box_request(node, &mut root_flow),
ReflowQueryType::ContentBoxesQuery(node) => ReflowQueryType::ContentBoxesQuery(node) =>
process_content_boxes_request(node, &mut root_flow, &mut rw_data), rw_data.content_boxes_response = process_content_boxes_request(node, &mut root_flow),
ReflowQueryType::NodeGeometryQuery(node) => ReflowQueryType::NodeGeometryQuery(node) =>
self.process_node_geometry_request(node, &mut root_flow, &mut rw_data), rw_data.client_rect_response = self.process_node_geometry_request(node, &mut root_flow),
ReflowQueryType::ResolvedStyleQuery(node, ref pseudo, ref property) => { ReflowQueryType::ResolvedStyleQuery(node, ref pseudo, ref property) => {
self.process_resolved_style_request(node, rw_data.resolved_style_response =
pseudo, self.process_resolved_style_request(node,
property, pseudo,
&mut root_flow, property,
&mut rw_data) &mut root_flow)
} }
ReflowQueryType::OffsetParentQuery(node) => ReflowQueryType::OffsetParentQuery(node) =>
self.process_offset_parent_query(node, &mut root_flow, &mut rw_data), rw_data.offset_parent_response = self.process_offset_parent_query(node, &mut root_flow),
ReflowQueryType::NoQuery => {} ReflowQueryType::NoQuery => {}
} }
} }

View file

@ -10,7 +10,7 @@ use euclid::rect::Rect;
use flow_ref::FlowRef; use flow_ref::FlowRef;
use fragment::{Fragment, FragmentBorderBoxIterator}; use fragment::{Fragment, FragmentBorderBoxIterator};
use gfx::display_list::{DisplayItemMetadata, OpaqueNode}; use gfx::display_list::{DisplayItemMetadata, OpaqueNode};
use layout_task::{LayoutTaskData, RWGuard}; use layout_task::LayoutTaskData;
use msg::constellation_msg::ConstellationChan; use msg::constellation_msg::ConstellationChan;
use msg::constellation_msg::Msg as ConstellationMsg; use msg::constellation_msg::Msg as ConstellationMsg;
use opaque_node::OpaqueNodeMethods; use opaque_node::OpaqueNodeMethods;
@ -281,27 +281,27 @@ impl FragmentBorderBoxIterator for MarginRetrievingFragmentBorderBoxIterator {
} }
} }
pub fn process_content_box_request<'a>(requested_node: TrustedNodeAddress, pub fn process_content_box_request(requested_node: TrustedNodeAddress,
layout_root: &mut FlowRef, layout_root: &mut FlowRef)
rw_data: &mut RWGuard<'a>) { -> Rect<Au> {
// FIXME(pcwalton): This has not been updated to handle the stacking context relative // FIXME(pcwalton): This has not been updated to handle the stacking context relative
// stuff. So the position is wrong in most cases. // stuff. So the position is wrong in most cases.
let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node); let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node);
let mut iterator = UnioningFragmentBorderBoxIterator::new(requested_node); let mut iterator = UnioningFragmentBorderBoxIterator::new(requested_node);
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator); sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator);
rw_data.content_box_response = match iterator.rect { match iterator.rect {
Some(rect) => rect, Some(rect) => rect,
None => Rect::zero() None => Rect::zero()
}; }
} }
pub fn process_content_boxes_request<'a>(requested_node: TrustedNodeAddress, pub fn process_content_boxes_request(requested_node: TrustedNodeAddress,
layout_root: &mut FlowRef, layout_root: &mut FlowRef)
rw_data: &mut RWGuard<'a>) { -> Vec<Rect<Au>> {
// FIXME(pcwalton): This has not been updated to handle the stacking context relative // FIXME(pcwalton): This has not been updated to handle the stacking context relative
// stuff. So the position is wrong in most cases. // stuff. So the position is wrong in most cases.
let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node); let requested_node: OpaqueNode = OpaqueNodeMethods::from_script_node(requested_node);
let mut iterator = CollectingFragmentBorderBoxIterator::new(requested_node); let mut iterator = CollectingFragmentBorderBoxIterator::new(requested_node);
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator); sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator);
rw_data.content_boxes_response = iterator.rects; iterator.rects
} }