From 8eb39aafd4335bea1594a7db689d0d0fb1776797 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Mon, 6 Jan 2014 17:18:50 +0900 Subject: [PATCH 1/5] fix for anonymous block boxes --- src/components/main/layout/box.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 145bb95b0394..e3649f899072 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -27,8 +27,8 @@ use std::cast; use std::cell::Cell; use std::cmp::ApproxEq; use std::num::Zero; -use style::{ComputedValues, TElement, TNode}; -use style::computed_values::{LengthOrPercentage, overflow}; +use style::{ComputedValues, TElement, TNode, cascade}; +use style::computed_values::{LengthOrPercentage, overflow, display}; use style::computed_values::{border_style, clear, font_family, line_height}; use style::computed_values::{text_align, text_decoration, vertical_align, visibility}; @@ -228,8 +228,7 @@ impl Box { 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.) - // - // FIXME(pcwalton): This is incorrect for non-inherited properties on anonymous boxes. For + // CSS 2.1 § 9.2.1.1 This is for non-inherited properties on anonymous block boxes // example: // //
@@ -239,14 +238,27 @@ impl Box { //
// // An anonymous block box is generated around `Bar`, but it shouldn't inherit the border. - let mut nearest_ancestor_element = node; - while !nearest_ancestor_element.is_element() { - nearest_ancestor_element = node.parent_node().expect("no nearest element?!"); - } + + 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?!"); + } + + if nearest_ancestor_element.style().get().Box.display == display::block { + Arc::new(cascade(&[Arc::new(~[])], + Some(nearest_ancestor_element.style().get()))) + } else { + nearest_ancestor_element.style().clone() + } + }; Box { node: OpaqueNode::from_layout_node(&node), - style: (*nearest_ancestor_element.style()).clone(), + style: node_style, position: Slot::init(Au::zero_rect()), border: Slot::init(Zero::zero()), padding: Slot::init(Zero::zero()), From cfd44e408230cb46ef3ed2c5e9a9092c16819a21 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Mon, 6 Jan 2014 19:08:08 +0900 Subject: [PATCH 2/5] remove block exception --- src/components/main/layout/box.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index e3649f899072..d38494dab72e 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -248,12 +248,8 @@ impl Box { nearest_ancestor_element.parent_node().expect("no nearest element?!"); } - if nearest_ancestor_element.style().get().Box.display == display::block { - Arc::new(cascade(&[Arc::new(~[])], - Some(nearest_ancestor_element.style().get()))) - } else { - nearest_ancestor_element.style().clone() - } + Arc::new(cascade(&[Arc::new(~[])], + Some(nearest_ancestor_element.style().get()))) }; Box { From c538a90a14d2df251b69c26c03d50c4f49b80d8f Mon Sep 17 00:00:00 2001 From: patrick kim Date: Mon, 6 Jan 2014 19:10:24 +0900 Subject: [PATCH 3/5] remove unused import --- src/components/main/layout/box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index d38494dab72e..aad51d8d7593 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -28,7 +28,7 @@ use std::cell::Cell; use std::cmp::ApproxEq; use std::num::Zero; use style::{ComputedValues, TElement, TNode, cascade}; -use style::computed_values::{LengthOrPercentage, overflow, display}; +use style::computed_values::{LengthOrPercentage, overflow}; use style::computed_values::{border_style, clear, font_family, line_height}; use style::computed_values::{text_align, text_decoration, vertical_align, visibility}; From 454374276f5d583d413f403e56b70ff4af816614 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Mon, 6 Jan 2014 19:17:09 +0900 Subject: [PATCH 4/5] add comment --- src/components/main/layout/box.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index aad51d8d7593..54c233fe03ae 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -248,6 +248,7 @@ impl Box { 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()))) }; From 9b100241fd2c09645645bac084c6b15014977a6f Mon Sep 17 00:00:00 2001 From: patrick kim Date: Mon, 6 Jan 2014 19:30:24 +0900 Subject: [PATCH 5/5] fix comment --- src/components/main/layout/box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 54c233fe03ae..d1ed277a95b8 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -228,7 +228,7 @@ impl Box { 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 This is for non-inherited properties on anonymous block boxes + // CSS 2.1 § 9.2.1.1,9.2.2.1 This is for non-inherited properties on anonymous boxes // example: // //