aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-01-29 15:24:42 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-01-30 13:09:01 -0800
commit0e20ec02c58dbd744c22ee4c998b8cc5c48153fd (patch)
treec3cba47414a235c76b8fd159f07066a1e3b93482 /src
parent6c2e48f04d83cb0491138d8cc8a5c81ebc160cc6 (diff)
downloadservo-0e20ec02c58dbd744c22ee4c998b8cc5c48153fd.tar.gz
servo-0e20ec02c58dbd744c22ee4c998b8cc5c48153fd.zip
layout: Make box building thread safe by pushing down styles into
non-element children during the cascade. Fetching them from the parent isn't thread-safe. Adds a test for anonymous block box inheritance.
Diffstat (limited to 'src')
-rw-r--r--src/components/main/css/matching.rs4
-rw-r--r--src/components/main/layout/box_.rs29
-rw-r--r--src/components/main/layout/parallel.rs16
-rw-r--r--src/test/ref/anon_block_inherit_a.html13
-rw-r--r--src/test/ref/anon_block_inherit_b.html13
-rw-r--r--src/test/ref/basic.list1
6 files changed, 37 insertions, 39 deletions
diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs
index 7860623d2c5..ec82ee17c0f 100644
--- a/src/components/main/css/matching.rs
+++ b/src/components/main/css/matching.rs
@@ -139,9 +139,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
}
for kid in self.children() {
- if kid.is_element() {
- kid.cascade_subtree(Some(*self));
- }
+ kid.cascade_subtree(Some(*self));
}
}
}
diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs
index 3203d90301b..048918eee28 100644
--- a/src/components/main/layout/box_.rs
+++ b/src/components/main/layout/box_.rs
@@ -298,36 +298,9 @@ pub struct InlineParentInfo {
impl Box {
/// Constructs a new `Box` instance.
pub fn new(node: LayoutNode, specific: SpecificBoxInfo) -> Box {
- // Find the nearest ancestor element and take its style. (It should be either that node or
- // its immediate parent.)
- // CSS 2.1 § 9.2.1.1,9.2.2.1 This is for non-inherited properties on anonymous boxes
- // example:
- //
- // <div style="border: solid">
- // <p>Foo</p>
- // Bar
- // <p>Baz</p>
- // </div>
- //
- // An anonymous block box is generated around `Bar`, but it shouldn't inherit the border.
-
- let node_style = if node.is_element() {
- node.style().clone()
- } else {
- let mut nearest_ancestor_element = node;
- while !nearest_ancestor_element.is_element() {
- nearest_ancestor_element =
- nearest_ancestor_element.parent_node().expect("no nearest element?!");
- }
-
- // Anonymous box: inheriting from the ancestor with no specified declarations.
- Arc::new(cascade(&[Arc::new(~[])],
- Some(nearest_ancestor_element.style().get())))
- };
-
Box {
node: OpaqueNode::from_layout_node(&node),
- style: node_style,
+ style: node.style().clone(),
position: RefCell::new(Au::zero_rect()),
border: RefCell::new(Zero::zero()),
padding: RefCell::new(Zero::zero()),
diff --git a/src/components/main/layout/parallel.rs b/src/components/main/layout/parallel.rs
index 859a3839333..d7127f0c50a 100644
--- a/src/components/main/layout/parallel.rs
+++ b/src/components/main/layout/parallel.rs
@@ -134,16 +134,16 @@ fn match_and_cascade_node(unsafe_layout_node: UnsafeLayoutNode,
// Perform the CSS selector matching.
let stylist: &Stylist = cast::transmute(layout_context.stylist);
node.match_node(stylist);
-
- // Perform the CSS cascade.
- let parent_opt = if OpaqueNode::from_layout_node(&node) == layout_context.reflow_root {
- None
- } else {
- node.parent_node()
- };
- node.cascade_node(parent_opt);
}
+ // Perform the CSS cascade.
+ let parent_opt = if OpaqueNode::from_layout_node(&node) == layout_context.reflow_root {
+ None
+ } else {
+ node.parent_node()
+ };
+ node.cascade_node(parent_opt);
+
// Enqueue kids.
let mut child_count = 0;
for kid in node.children() {
diff --git a/src/test/ref/anon_block_inherit_a.html b/src/test/ref/anon_block_inherit_a.html
new file mode 100644
index 00000000000..855b51e5009
--- /dev/null
+++ b/src/test/ref/anon_block_inherit_a.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>hi</title>
+</head>
+<body>
+<div style="border: solid">
+<p>Foo</p>
+Bar
+<p>Baz</p>
+</div>
+</body>
+</html>
diff --git a/src/test/ref/anon_block_inherit_b.html b/src/test/ref/anon_block_inherit_b.html
new file mode 100644
index 00000000000..db245b4b21f
--- /dev/null
+++ b/src/test/ref/anon_block_inherit_b.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>hi</title>
+</head>
+<body>
+<div style="border: solid">
+<p>Foo</p>
+<div>Bar</div>
+<p>Baz</p>
+</div>
+</body>
+</html>
diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list
index 7cc05c829e6..74601f3fe0e 100644
--- a/src/test/ref/basic.list
+++ b/src/test/ref/basic.list
@@ -25,3 +25,4 @@
== img_size_a.html img_size_b.html
== upper_id_attr.html upper_id_attr_ref.html
# inline_border_a.html inline_border_b.html
+== anon_block_inherit_a.html anon_block_inherit_b.html