stylo: Replace FontComputationData with typedef

This commit is contained in:
Manish Goregaokar 2017-09-11 14:26:31 -07:00 committed by Manish Goregaokar
parent 6318969269
commit 2db5fbbe56
3 changed files with 40 additions and 56 deletions

View file

@ -53,7 +53,7 @@ use logical_geometry::WritingMode;
use media_queries::Device; use media_queries::Device;
use properties::animated_properties::TransitionProperty; use properties::animated_properties::TransitionProperty;
use properties::computed_value_flags::ComputedValueFlags; use properties::computed_value_flags::ComputedValueFlags;
use properties::{longhands, FontComputationData, Importance, LonghandId}; use properties::{default_font_size_keyword, longhands, FontComputationData, Importance, LonghandId};
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId}; use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
use rule_tree::StrongRuleNode; use rule_tree::StrongRuleNode;
use selector_parser::PseudoElement; use selector_parser::PseudoElement;
@ -85,7 +85,7 @@ impl ComputedValues {
pseudo: Option<<&PseudoElement>, pseudo: Option<<&PseudoElement>,
custom_properties: Option<Arc<CustomPropertiesMap>>, custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode, writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>, font_size_keyword: FontComputationData,
flags: ComputedValueFlags, flags: ComputedValueFlags,
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
@ -114,7 +114,7 @@ impl ComputedValues {
ComputedValuesInner::new( ComputedValuesInner::new(
/* custom_properties = */ None, /* custom_properties = */ None,
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious /* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
FontComputationData::default_font_size_keyword(), default_font_size_keyword(),
ComputedValueFlags::empty(), ComputedValueFlags::empty(),
/* rules = */ None, /* rules = */ None,
/* visited_style = */ None, /* visited_style = */ None,
@ -188,7 +188,7 @@ type ParentStyleContextInfo<'a> = Option< &'a ComputedValues>;
impl ComputedValuesInner { impl ComputedValuesInner {
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>, pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode, writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>, font_size_keyword: FontComputationData,
flags: ComputedValueFlags, flags: ComputedValueFlags,
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
@ -199,7 +199,7 @@ impl ComputedValuesInner {
ComputedValuesInner { ComputedValuesInner {
custom_properties: custom_properties, custom_properties: custom_properties,
writing_mode: writing_mode, writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword), font_computation_data: font_size_keyword,
rules: rules, rules: rules,
visited_style: visited_style.map(|x| Arc::into_raw_offset(x)), visited_style: visited_style.map(|x| Arc::into_raw_offset(x)),
flags: flags, flags: flags,

View file

@ -980,8 +980,9 @@ ${helpers.single_keyword_system("font-variant-caps",
// recomputed from the base size for the keyword and the relative size. // recomputed from the base size for the keyword and the relative size.
// //
// See bug 1355707 // See bug 1355707
if let Some((kw, fraction, old_abs)) = context.builder.inherited_font_computation_data().font_size_keyword { if let Some((kw, fraction, old_abs)) = *context.builder.inherited_font_computation_data() {
context.builder.font_size_keyword = Some((kw, fraction * ratio, abs + old_abs.0.scale_by(ratio).into())); context.builder.font_size_keyword =
Some((kw, fraction * ratio, abs + old_abs.0.scale_by(ratio).into()));
} else { } else {
context.builder.font_size_keyword = None; context.builder.font_size_keyword = None;
} }
@ -1037,7 +1038,7 @@ ${helpers.single_keyword_system("font-variant-caps",
let mut font = context.builder.take_font(); let mut font = context.builder.take_font();
let used_kw = { let used_kw = {
let parent_font = context.builder.get_parent_font(); let parent_font = context.builder.get_parent_font();
parent_kw = context.builder.inherited_font_computation_data().font_size_keyword; parent_kw = *context.builder.inherited_font_computation_data();
font.inherit_font_size_from(parent_font, kw_inherited_size, device) font.inherit_font_size_from(parent_font, kw_inherited_size, device)
}; };

View file

@ -11,7 +11,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" /> <%namespace name="helpers" file="/helpers.mako.rs" />
use app_units::Au; use app_units::Au;
#[cfg(feature = "servo")] use app_units::Au;
use servo_arc::{Arc, UniqueArc}; use servo_arc::{Arc, UniqueArc};
use smallbitvec::SmallBitVec; use smallbitvec::SmallBitVec;
use std::borrow::Cow; use std::borrow::Cow;
@ -95,8 +94,7 @@ pub trait MaybeBoxed<Out> {
/// This is where we store extra font data while /// This is where we store extra font data while
/// while computing font sizes. /// while computing font sizes.
#[derive(Clone, Debug)] ///
pub struct FontComputationData {
/// font-size keyword values (and font-size-relative values applied /// font-size keyword values (and font-size-relative values applied
/// to keyword values) need to preserve their identity as originating /// to keyword values) need to preserve their identity as originating
/// from keywords and relative font sizes. We store this information /// from keywords and relative font sizes. We store this information
@ -112,29 +110,13 @@ pub struct FontComputationData {
/// When this is Some, we compute font sizes by computing the keyword against /// When this is Some, we compute font sizes by computing the keyword against
/// the generic font, and then multiplying it by the ratio (as well as adding any /// the generic font, and then multiplying it by the ratio (as well as adding any
/// absolute offset from calcs) /// absolute offset from calcs)
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)> pub type FontComputationData = Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>;
}
/// Default value for FontComputationData
impl FontComputationData { pub fn default_font_size_keyword() -> FontComputationData {
/// Assigns values for variables in struct FontComputationData
pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>) -> Self {
FontComputationData {
font_size_keyword: font_size_keyword
}
}
/// Assigns default values for variables in struct FontComputationData
pub fn default_font_size_keyword() -> Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)> {
Some((Default::default(), 1., Au(0).into())) Some((Default::default(), 1., Au(0).into()))
} }
/// Gets a FontComputationData with the default values.
pub fn default_values() -> Self {
Self::new(Self::default_font_size_keyword())
}
}
impl<T> MaybeBoxed<T> for T { impl<T> MaybeBoxed<T> for T {
#[inline] #[inline]
fn maybe_boxed(self) -> T { self } fn maybe_boxed(self) -> T { self }
@ -2009,7 +1991,7 @@ impl ComputedValues {
_: Option<<&PseudoElement>, _: Option<<&PseudoElement>,
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>, custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode, writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>, font_size_keyword: FontComputationData,
flags: ComputedValueFlags, flags: ComputedValueFlags,
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
@ -2042,7 +2024,7 @@ impl ComputedValuesInner {
pub fn new( pub fn new(
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>, custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode, writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>, font_size_keyword: FontComputationData,
flags: ComputedValueFlags, flags: ComputedValueFlags,
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
@ -2053,7 +2035,7 @@ impl ComputedValuesInner {
ComputedValuesInner { ComputedValuesInner {
custom_properties: custom_properties, custom_properties: custom_properties,
writing_mode: writing_mode, writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword), font_computation_data: font_size_keyword,
rules: rules, rules: rules,
visited_style: visited_style, visited_style: visited_style,
flags: flags, flags: flags,
@ -2566,7 +2548,7 @@ pub struct StyleBuilder<'a> {
/// TODO(emilio): Make private. /// TODO(emilio): Make private.
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, NonNegativeAu)>, pub font_size_keyword: FontComputationData,
/// Flags for the computed value. /// Flags for the computed value.
pub flags: ComputedValueFlags, 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
@ -2589,7 +2571,7 @@ impl<'a> StyleBuilder<'a> {
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>, custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode, writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>, font_size_keyword: FontComputationData,
flags: ComputedValueFlags, flags: ComputedValueFlags,
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
) -> Self { ) -> Self {
@ -2659,7 +2641,7 @@ impl<'a> StyleBuilder<'a> {
rules: None, // FIXME(emilio): Dubious... rules: None, // FIXME(emilio): Dubious...
custom_properties: style_to_derive_from.custom_properties(), custom_properties: style_to_derive_from.custom_properties(),
writing_mode: style_to_derive_from.writing_mode, writing_mode: style_to_derive_from.writing_mode,
font_size_keyword: style_to_derive_from.font_computation_data.font_size_keyword, font_size_keyword: style_to_derive_from.font_computation_data,
flags: style_to_derive_from.flags, flags: style_to_derive_from.flags,
visited_style: style_to_derive_from.clone_visited_style(), visited_style: style_to_derive_from.clone_visited_style(),
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
@ -2759,7 +2741,7 @@ impl<'a> StyleBuilder<'a> {
/* rules = */ None, /* rules = */ None,
parent.custom_properties(), parent.custom_properties(),
parent.writing_mode, parent.writing_mode,
parent.font_computation_data.font_size_keyword, parent.font_computation_data,
parent.flags, parent.flags,
parent.clone_visited_style() parent.clone_visited_style()
) )
@ -2914,7 +2896,8 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
mod lazy_static_module { mod lazy_static_module {
use logical_geometry::WritingMode; use logical_geometry::WritingMode;
use servo_arc::Arc; use servo_arc::Arc;
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData}; use super::{ComputedValues, ComputedValuesInner, longhands, style_structs};
use super::default_font_size_keyword;
use super::computed_value_flags::ComputedValueFlags; use super::computed_value_flags::ComputedValueFlags;
/// The initial values for all style structs as defined by the specification. /// The initial values for all style structs as defined by the specification.
@ -2933,7 +2916,7 @@ mod lazy_static_module {
% endfor % endfor
custom_properties: None, custom_properties: None,
writing_mode: WritingMode::empty(), writing_mode: WritingMode::empty(),
font_computation_data: FontComputationData::default_values(), font_computation_data: default_font_size_keyword(),
rules: None, rules: None,
visited_style: None, visited_style: None,
flags: ComputedValueFlags::empty(), flags: ComputedValueFlags::empty(),
@ -3154,7 +3137,7 @@ where
Some(rules.clone()), Some(rules.clone()),
custom_properties, custom_properties,
WritingMode::empty(), WritingMode::empty(),
inherited_style.font_computation_data.font_size_keyword, inherited_style.font_computation_data,
ComputedValueFlags::empty(), ComputedValueFlags::empty(),
visited_style, visited_style,
), ),