Skip to content
Permalink
Browse files

Allow retrieving width/height for non-positioned elements

  • Loading branch information
dzbarsky committed Nov 4, 2015
1 parent ca56ebb commit d95ca55f2642e9d3433d649c9b6c86c29f45887a
Showing with 54 additions and 157 deletions.
  1. +42 −29 components/layout/layout_task.rs
  2. +4 −3 components/layout/query.rs
  3. +0 −3 tests/wpt/metadata-css/cssom-1_dev/html/computed-style-001.htm.ini
  4. +0 −5 ...etadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.decimal.html.ini
  5. +0 −5 ...wpt/metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.em.html.ini
  6. +0 −5 ...pt/metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.exp.html.ini
  7. +0 −5 ...pt/metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.hex.html.ini
  8. +0 −5 .../metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.octal.html.ini
  9. +0 −5 ...etadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.percent.html.ini
  10. +0 −5 ...t/metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.plus.html.ini
  11. +0 −5 .../metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.space.html.ini
  12. +0 −5 ...ta/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.trailingjunk.html.ini
  13. +0 −5 ...data/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.whitespace.html.ini
  14. +0 −5 ...t/metadata/html/semantics/embedded-content/the-canvas-element/size.attributes.parse.zero.html.ini
  15. +0 −5 .../html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.decimal.html.ini
  16. +0 −5 ...adata/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.em.html.ini
  17. +0 −5 ...data/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.exp.html.ini
  18. +0 −5 ...data/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.hex.html.ini
  19. +0 −5 ...ta/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.octal.html.ini
  20. +0 −5 .../html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.percent.html.ini
  21. +0 −5 ...ata/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.plus.html.ini
  22. +0 −5 ...ta/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.space.html.ini
  23. +0 −5 .../semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.trailingjunk.html.ini
  24. +0 −5 ...ml/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.whitespace.html.ini
  25. +0 −5 ...ata/html/semantics/embedded-content/the-canvas-element/size.attributes.setAttribute.zero.html.ini
  26. +0 −9 tests/wpt/mozilla/meta/mozilla/calc.html.ini
  27. +5 −0 tests/wpt/mozilla/meta/mozilla/getComputedStyle.html.ini
  28. +3 −3 tests/wpt/mozilla/tests/mozilla/getComputedStyle.html
@@ -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()
@@ -221,13 +221,14 @@ impl PositionRetrievingFragmentBorderBoxIterator {
}

impl FragmentBorderBoxIterator for PositionRetrievingFragmentBorderBoxIterator {
fn process(&mut self, _: &Fragment, _: i32, border_box: &Rect<Au>) {
fn process(&mut self, fragment: &Fragment, _: i32, border_box: &Rect<Au>) {
let border_padding = fragment.border_padding.to_physical(fragment.style.writing_mode);
self.result =
Some(match self.property {
PositionProperty::Left => self.position.x,
PositionProperty::Top => self.position.y,
PositionProperty::Width => border_box.size.width,
PositionProperty::Height => border_box.size.height,
PositionProperty::Width => border_box.size.width - border_padding.horizontal(),
PositionProperty::Height => border_box.size.height - border_padding.vertical(),
// TODO: the following 2 calculations are completely wrong.
// They should return the difference between the parent's and this
// fragment's border boxes.
@@ -3,6 +3,3 @@
[read_only]
expected: FAIL

[relative_property_values]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,11 +1,5 @@
[calc.html]
type: testharness
[calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)]
expected: FAIL

[calc(0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)]
expected: FAIL

[calc for column-width]
expected: FAIL

@@ -15,6 +9,3 @@
[calc for column-count]
expected: FAIL

[calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)]
expected: FAIL

@@ -0,0 +1,5 @@
[getComputedStyle.html]
type: testharness
[getComputedStyle work for elements not in a document]
expected: FAIL

@@ -24,7 +24,7 @@
assert_equals(cs.getPropertyValue("top"), "auto");
assert_equals(cs.getPropertyValue("bottom"), "auto");
assert_equals(cs.getPropertyValue("width"), "50px");
assert_equals(cs.getPropertyValue("height"), "auto");
assert_equals(cs.getPropertyValue("height"), "0px");
assert_equals(cs.getPropertyValue("color"), "rgb(0, 0, 0)");
}, "Element's resolved values");

@@ -43,8 +43,8 @@
test(function() {
var div = document.createElement("div");
div.id = "foo";
assert_equals(getComputedStyle(div).getPropertyValue("width"), "");
}, "Blank style for elements not in a document");
assert_equals(getComputedStyle(div).getPropertyValue("width"), "50px");
}, "getComputedStyle work for elements not in a document");

</script>
</body>

0 comments on commit d95ca55

Please sign in to comment.
You can’t perform that action at this time.