diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 22d1e2fe0e8..c185c276e97 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -44,7 +44,7 @@ use std::from_str::FromStr; use std::iter::AdditiveIterator; use std::mem; use std::num::Zero; -use style::{ComputedValues, TElement, TNode, cascade}; +use style::{ComputedValues, TElement, TNode, cascade_anonymous}; use style::computed_values::{LengthOrPercentageOrAuto, overflow, LPA_Auto, background_attachment}; use style::computed_values::{background_repeat, border_style, clear, position, text_align}; use style::computed_values::{text_decoration, vertical_align, visibility, white_space}; @@ -343,7 +343,7 @@ impl Box { // // Anonymous table boxes, TableRowBox and TableCellBox, are generated around `Foo`, but it shouldn't inherit the border. - let (node_style, _) = cascade(&[], false, Some(&**node.style()), None); + let node_style = cascade_anonymous(&**node.style()); Box { node: OpaqueNodeMethods::from_thread_safe_layout_node(node), style: Arc::new(node_style), diff --git a/src/components/style/properties.rs.mako b/src/components/style/properties.rs.mako index 682a8d025be..08d4c3f3968 100644 --- a/src/components/style/properties.rs.mako +++ b/src/components/style/properties.rs.mako @@ -1911,6 +1911,36 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], } +/// Equivalent to `cascade()` with an empty `applicable_declarations` +/// Performs the CSS cascade for an anonymous box. +/// +/// * `parent_style`: Computed style of the element this anonymous box inherits from. +pub fn cascade_anonymous(parent_style: &ComputedValues) -> ComputedValues { + let initial_values = &*INITIAL_VALUES; + let mut result = ComputedValues { + % for style_struct in STYLE_STRUCTS: + ${style_struct.name}: + % if style_struct.inherited: + parent_style + % else: + initial_values + % endif + .${style_struct.name}.clone(), + % endfor + shareable: false, + }; + { + let border = result.Border.get_mut(); + % for side in ["top", "right", "bottom", "left"]: + // Like calling to_computed_value, which wouldn't type check. + border.border_${side}_width = Au(0); + % endfor + } + // None of the teaks on 'display' apply here. + result +} + + // Only re-export the types for computed values. pub mod computed_values { % for property in LONGHANDS: diff --git a/src/components/style/style.rs b/src/components/style/style.rs index 47d34dae930..a2f7bea6e4e 100644 --- a/src/components/style/style.rs +++ b/src/components/style/style.rs @@ -33,7 +33,8 @@ extern crate servo_util = "util"; pub use stylesheets::{Stylesheet, CSSRule, StyleRule}; pub use selector_matching::{Stylist, StylesheetOrigin, UserAgentOrigin, AuthorOrigin, UserOrigin}; pub use selector_matching::{MatchedProperty}; -pub use properties::{cascade, PropertyDeclaration, ComputedValues, computed_values, style_structs}; +pub use properties::{cascade, cascade_anonymous}; +pub use properties::{PropertyDeclaration, ComputedValues, computed_values, style_structs}; pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes pub use properties::{CSSFloat, DeclaredValue, PropertyDeclarationParseResult}; pub use properties::longhands;