diff options
author | David Zbarsky <dzbarsky@gmail.com> | 2015-10-25 23:54:44 -0700 |
---|---|---|
committer | David Zbarsky <dzbarsky@gmail.com> | 2015-11-03 20:13:09 -0800 |
commit | d95ca55f2642e9d3433d649c9b6c86c29f45887a (patch) | |
tree | 51bd22cebaf3bc79b030f47fea9ecdb6ee96d19f /components/layout/layout_task.rs | |
parent | ca56ebbb09f3c258d10e7a7fa276d42fe258d893 (diff) | |
download | servo-d95ca55f2642e9d3433d649c9b6c86c29f45887a.tar.gz servo-d95ca55f2642e9d3433d649c9b6c86c29f45887a.zip |
Allow retrieving width/height for non-positioned elements
Diffstat (limited to 'components/layout/layout_task.rs')
-rw-r--r-- | components/layout/layout_task.rs | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 42dcddb57a4..c86ecdedaff 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -931,6 +931,40 @@ impl LayoutTask { // There are probably other quirks. let applies = true; + fn used_value_for_position_property(layout_node: ThreadSafeLayoutNode, + layout_root: &mut FlowRef, + requested_node: TrustedNodeAddress, + property: &Atom) -> Option<String> { + let layout_data = layout_node.borrow_layout_data(); + let position = layout_data.as_ref().map(|layout_data| { + match layout_data.data.flow_construction_result { + ConstructionResult::Flow(ref flow_ref, _) => + flow::base(flow_ref.deref()).stacking_relative_position, + // TODO(dzbarsky) search parents until we find node with a flow ref. + // https://github.com/servo/servo/issues/8307 + _ => ZERO_POINT + } + }).unwrap_or(ZERO_POINT); + let property = match *property { + atom!("bottom") => PositionProperty::Bottom, + atom!("top") => PositionProperty::Top, + atom!("left") => PositionProperty::Left, + atom!("right") => PositionProperty::Right, + atom!("width") => PositionProperty::Width, + atom!("height") => PositionProperty::Height, + _ => unreachable!() + }; + let requested_node: OpaqueNode = + OpaqueNodeMethods::from_script_node(requested_node); + let mut iterator = + PositionRetrievingFragmentBorderBoxIterator::new(requested_node, + property, + position); + sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, + &mut iterator); + iterator.result.map(|r| r.to_css_string()) + } + // TODO: we will return neither the computed nor used value for margin and padding. // Firefox returns blank strings for the computed value of shorthands, // so this should be web-compatible. @@ -964,37 +998,16 @@ impl LayoutTask { }, atom!("bottom") | atom!("top") | atom!("right") | - atom!("left") | atom!("width") | atom!("height") + atom!("left") if applies && positioned && style.get_box().display != display::computed_value::T::none => { - let layout_data = layout_node.borrow_layout_data(); - let position = layout_data.as_ref().map(|layout_data| { - match layout_data.data.flow_construction_result { - ConstructionResult::Flow(ref flow_ref, _) => - flow::base(flow_ref.deref()).stacking_relative_position, - // TODO search parents until we find node with a flow ref. - _ => ZERO_POINT - } - }).unwrap_or(ZERO_POINT); - let property = match *property { - atom!("bottom") => PositionProperty::Bottom, - atom!("top") => PositionProperty::Top, - atom!("left") => PositionProperty::Left, - atom!("right") => PositionProperty::Right, - atom!("width") => PositionProperty::Width, - atom!("height") => PositionProperty::Height, - _ => unreachable!() - }; - let requested_node: OpaqueNode = - OpaqueNodeMethods::from_script_node(requested_node); - let mut iterator = - PositionRetrievingFragmentBorderBoxIterator::new(requested_node, - property, - position); - sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, - &mut iterator); - iterator.result.map(|r| r.to_css_string()) - }, + used_value_for_position_property(layout_node, layout_root, requested_node, property) + } + atom!("width") | atom!("height") + if applies && style.get_box().display != + display::computed_value::T::none => { + used_value_for_position_property(layout_node, layout_root, requested_node, property) + } // FIXME: implement used value computation for line-height ref property => { style.computed_value_to_string(property.as_slice()).ok() |