mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Move special cases of CSS 'display' the property to computed value, per spec.
This commit is contained in:
parent
90431a1907
commit
5c59699e4c
2 changed files with 49 additions and 36 deletions
|
@ -379,38 +379,21 @@ impl LayoutTreeBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn box_generator_for_node<'a>(&mut self,
|
||||
node: AbstractNode<LayoutView>,
|
||||
grandparent_generator: Option<&mut BoxGenerator<'a>>,
|
||||
parent_generator: &mut BoxGenerator<'a>,
|
||||
mut sibling_generator: Option<&mut BoxGenerator<'a>>)
|
||||
-> BoxGenResult<'a> {
|
||||
let display = if node.is_element() {
|
||||
let display = node.style().Box.display;
|
||||
if node.is_root() {
|
||||
match display {
|
||||
display::none => return NoGenerator,
|
||||
display::inline => display::block,
|
||||
display::list_item => display::block,
|
||||
v => v
|
||||
}
|
||||
} else {
|
||||
match display {
|
||||
display::none => return NoGenerator,
|
||||
display::list_item => display::block,
|
||||
v => v
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match node.type_id() {
|
||||
ElementNodeTypeId(_) => display::inline,
|
||||
TextNodeTypeId => display::inline,
|
||||
DoctypeNodeTypeId |
|
||||
DocumentFragmentNodeTypeId |
|
||||
CommentNodeTypeId => return NoGenerator,
|
||||
}
|
||||
let display = match node.type_id() {
|
||||
ElementNodeTypeId(_) => match node.style().Box.display {
|
||||
display::none => return NoGenerator,
|
||||
display => display,
|
||||
},
|
||||
TextNodeTypeId => display::inline,
|
||||
DoctypeNodeTypeId |
|
||||
DocumentFragmentNodeTypeId |
|
||||
CommentNodeTypeId => return NoGenerator,
|
||||
};
|
||||
|
||||
// FIXME(pcwalton): Unsafe.
|
||||
|
@ -448,8 +431,8 @@ impl LayoutTreeBuilder {
|
|||
// afterward.
|
||||
(display::block, _, Some(InlineFlowClass)) if is_float.is_some() => {
|
||||
let float_type = FloatFlowType(is_float.unwrap());
|
||||
let float_generator = self.create_child_generator(node,
|
||||
sibling_generator.unwrap(),
|
||||
let float_generator = self.create_child_generator(node,
|
||||
sibling_generator.unwrap(),
|
||||
float_type);
|
||||
return Mixed(float_generator, ~SiblingGenerator);
|
||||
}
|
||||
|
|
|
@ -101,10 +101,9 @@ pub mod longhands {
|
|||
</%self:longhand>
|
||||
</%def>
|
||||
|
||||
<%def name="single_keyword(name, values, inherited=False)">
|
||||
<%def name="single_keyword_computed(name, values, inherited=False)">
|
||||
<%self:single_component_value name="${name}" inherited="${inherited}">
|
||||
// The computed value is the same as the specified value.
|
||||
pub use to_computed_value = super::computed_as_specified;
|
||||
${caller.body()}
|
||||
pub mod computed_value {
|
||||
#[deriving(Eq, Clone)]
|
||||
pub enum T {
|
||||
|
@ -130,6 +129,13 @@ pub mod longhands {
|
|||
</%self:single_component_value>
|
||||
</%def>
|
||||
|
||||
<%def name="single_keyword(name, values, inherited=False)">
|
||||
<%self:single_keyword_computed name="${name}" values="${values}" inherited="${inherited}">
|
||||
// The computed value is the same as the specified value.
|
||||
pub use to_computed_value = super::computed_as_specified;
|
||||
</%self:single_keyword_computed>
|
||||
</%def>
|
||||
|
||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse', inherited=False)">
|
||||
<%self:single_component_value name="${name}" inherited="${inherited}">
|
||||
pub use to_computed_value = super::super::common_types::computed::compute_${type};
|
||||
|
@ -217,11 +223,35 @@ pub mod longhands {
|
|||
${new_style_struct("Box")}
|
||||
|
||||
// TODO: don't parse values we don't support
|
||||
${single_keyword("display",
|
||||
"inline block list-item inline-block none "
|
||||
)}
|
||||
// "table inline-table table-row-group table-header-group table-footer-group "
|
||||
// "table-row table-column-group table-column table-cell table-caption"
|
||||
<%self:single_keyword_computed name="display"
|
||||
values="inline block inline-block none">
|
||||
// list-item
|
||||
// table inline-table table-row-group table-header-group table-footer-group
|
||||
// table-row table-column-group table-column table-cell table-caption
|
||||
pub fn to_computed_value(value: SpecifiedValue, context: &computed::Context)
|
||||
-> computed_value::T {
|
||||
// if context.is_root_element && value == list_item {
|
||||
// return block
|
||||
// }
|
||||
let positioned = match context.position {
|
||||
position::absolute | position::fixed => true,
|
||||
_ => false
|
||||
};
|
||||
if positioned || context.float != float::none || context.is_root_element {
|
||||
match value {
|
||||
// inline_table => table,
|
||||
inline | inline_block
|
||||
// | table_row_group | table_column | table_column_group
|
||||
// | table_header_group | table_footer_group | table_row
|
||||
// | table_cell | table_caption
|
||||
=> block,
|
||||
_ => value,
|
||||
}
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
</%self:single_keyword_computed>
|
||||
|
||||
${single_keyword("position", "static absolute relative fixed")}
|
||||
${single_keyword("float", "none left right")}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue