Move HAS_TEXT_DECORATION_LINES setting into StyleAdjuster.

This commit is contained in:
Xidorn Quan 2017-07-14 10:33:55 +10:00
parent 86799d4d6e
commit fcf37b19fd
4 changed files with 17 additions and 37 deletions

View file

@ -4,8 +4,6 @@
//! Misc information about a given computed style. //! Misc information about a given computed style.
use properties::{ComputedValues, StyleBuilder};
bitflags! { bitflags! {
/// Misc information about a given computed style. /// Misc information about a given computed style.
/// ///
@ -22,29 +20,3 @@ bitflags! {
const HAS_TEXT_DECORATION_LINES = 1 << 0, const HAS_TEXT_DECORATION_LINES = 1 << 0,
} }
} }
impl ComputedValueFlags {
/// Get the computed value flags for the initial style.
pub fn initial() -> Self {
Self::empty()
}
/// Compute the flags for this style, given the parent style.
pub fn compute(
this_style: &StyleBuilder,
parent_style: &ComputedValues,
) -> Self {
let mut ret = Self::empty();
// FIXME(emilio): This feels like it wants to look at the
// layout_parent_style, but the way it works in Gecko means it's not
// needed (we'd recascade a bit more when it changes, but that's fine),
// and this way it simplifies the code for text styles and similar.
if parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) ||
!this_style.get_text().clone_text_decoration_line().is_empty() {
ret.insert(HAS_TEXT_DECORATION_LINES);
}
ret
}
}

View file

@ -125,7 +125,7 @@ impl ComputedValues {
custom_properties: None, custom_properties: None,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
font_computation_data: FontComputationData::default_values(), font_computation_data: FontComputationData::default_values(),
flags: ComputedValueFlags::initial(), flags: ComputedValueFlags::empty(),
rules: None, rules: None,
visited_style: None, visited_style: None,
% for style_struct in data.style_structs: % for style_struct in data.style_structs:

View file

@ -2384,8 +2384,6 @@ impl<'a, T: 'a> Deref for StyleStructRef<'a, T> {
/// actually cloning them, until we either build the style, or mutate the /// actually cloning them, until we either build the style, or mutate the
/// inherited value. /// inherited value.
pub struct StyleBuilder<'a> { pub struct StyleBuilder<'a> {
/// The style we're inheriting from.
inherited_style: &'a ComputedValues,
/// The rule node representing the ordered list of rules matched for this /// The rule node representing the ordered list of rules matched for this
/// node. /// node.
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
@ -2396,6 +2394,8 @@ pub struct StyleBuilder<'a> {
pub writing_mode: WritingMode, pub writing_mode: WritingMode,
/// The keyword behind the current font-size property, if any. /// The keyword behind the current font-size property, if any.
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>, pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
/// Flags for the computed value.
pub flags: ComputedValueFlags,
/// The element's style if visited, only computed if there's a relevant link /// The element's style if visited, only computed if there's a relevant link
/// for this element. A element's "relevant link" is the element being /// for this element. A element's "relevant link" is the element being
/// matched if it is a link or the nearest ancestor link. /// matched if it is a link or the nearest ancestor link.
@ -2418,7 +2418,6 @@ impl<'a> StyleBuilder<'a> {
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
) -> Self { ) -> Self {
StyleBuilder { StyleBuilder {
inherited_style,
rules, rules,
custom_properties, custom_properties,
writing_mode, writing_mode,
@ -2518,11 +2517,10 @@ impl<'a> StyleBuilder<'a> {
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance. /// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
pub fn build(self) -> ComputedValues { pub fn build(self) -> ComputedValues {
let flags = ComputedValueFlags::compute(&self, &self.inherited_style);
ComputedValues::new(self.custom_properties, ComputedValues::new(self.custom_properties,
self.writing_mode, self.writing_mode,
self.font_size_keyword, self.font_size_keyword,
flags, self.flags,
self.rules, self.rules,
self.visited_style, self.visited_style,
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
@ -2567,7 +2565,7 @@ mod lazy_static_module {
% endfor % endfor
custom_properties: None, custom_properties: None,
writing_mode: WritingMode::empty(), writing_mode: WritingMode::empty(),
flags: ComputedValueFlags::initial(), flags: ComputedValueFlags::empty(),
font_computation_data: FontComputationData::default_values(), font_computation_data: FontComputationData::default_values(),
rules: None, rules: None,
visited_style: None, visited_style: None,

View file

@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! A struct to encapsulate all the style fixups a computed style needs in order //! A struct to encapsulate all the style fixups and flags propagations
//! for it to adhere to the CSS spec. //! a computed style needs in order for it to adhere to the CSS spec.
use app_units::Au; use app_units::Au;
use properties::{self, CascadeFlags, ComputedValues}; use properties::{self, CascadeFlags, ComputedValues};
@ -312,6 +312,15 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
self.style.mutate_inheritedtext().set_text_align(text_align::start); self.style.mutate_inheritedtext().set_text_align(text_align::start);
} }
/// Set the HAS_TEXT_DECORATION_LINES flag based on parent style.
fn adjust_for_text_decoration_lines(&mut self, layout_parent_style: &ComputedValues) {
use properties::computed_value_flags::HAS_TEXT_DECORATION_LINES;
if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) ||
!self.style.get_text().clone_text_decoration_line().is_empty() {
self.style.flags.insert(HAS_TEXT_DECORATION_LINES);
}
}
/// Adjusts the style to account for various fixups that don't fit naturally /// Adjusts the style to account for various fixups that don't fit naturally
/// into the cascade. /// into the cascade.
/// ///
@ -341,5 +350,6 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
self.adjust_for_border_width(); self.adjust_for_border_width();
self.adjust_for_outline(); self.adjust_for_outline();
self.adjust_for_writing_mode(layout_parent_style); self.adjust_for_writing_mode(layout_parent_style);
self.adjust_for_text_decoration_lines(layout_parent_style);
} }
} }