Add a fast path in the cascade for anonymous boxes.

This commit is contained in:
Simon Sapin 2014-05-14 16:32:05 +01:00
parent 4310f29431
commit ff554ee845
3 changed files with 34 additions and 3 deletions

View file

@ -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),

View file

@ -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:

View file

@ -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;