Skip to content
Permalink
Browse files

stylo: Replace FontComputationData with typedef

  • Loading branch information
Manishearth committed Sep 12, 2017
1 parent 6318969 commit 2db5fbbe56d0a1fe4329faf385a0c075fd850551
@@ -53,7 +53,7 @@ use logical_geometry::WritingMode;
use media_queries::Device;
use properties::animated_properties::TransitionProperty;
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 rule_tree::StrongRuleNode;
use selector_parser::PseudoElement;
@@ -85,7 +85,7 @@ impl ComputedValues {
pseudo: Option<<&PseudoElement>,
custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>,
font_size_keyword: FontComputationData,
flags: ComputedValueFlags,
rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>,
@@ -114,7 +114,7 @@ impl ComputedValues {
ComputedValuesInner::new(
/* custom_properties = */ None,
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
FontComputationData::default_font_size_keyword(),
default_font_size_keyword(),
ComputedValueFlags::empty(),
/* rules = */ None,
/* visited_style = */ None,
@@ -188,7 +188,7 @@ type ParentStyleContextInfo<'a> = Option< &'a ComputedValues>;
impl ComputedValuesInner {
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>,
font_size_keyword: FontComputationData,
flags: ComputedValueFlags,
rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>,
@@ -199,7 +199,7 @@ impl ComputedValuesInner {
ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
font_computation_data: font_size_keyword,
rules: rules,
visited_style: visited_style.map(|x| Arc::into_raw_offset(x)),
flags: flags,
@@ -980,8 +980,9 @@ ${helpers.single_keyword_system("font-variant-caps",
// recomputed from the base size for the keyword and the relative size.
//
// See bug 1355707
if let Some((kw, fraction, old_abs)) = context.builder.inherited_font_computation_data().font_size_keyword {
context.builder.font_size_keyword = Some((kw, fraction * ratio, abs + old_abs.0.scale_by(ratio).into()));
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()));
} else {
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 used_kw = {
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)
};
@@ -11,7 +11,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />

use app_units::Au;
#[cfg(feature = "servo")] use app_units::Au;
use servo_arc::{Arc, UniqueArc};
use smallbitvec::SmallBitVec;
use std::borrow::Cow;
@@ -95,44 +94,27 @@ pub trait MaybeBoxed<Out> {

/// This is where we store extra font data while
/// while computing font sizes.
#[derive(Clone, Debug)]
pub struct FontComputationData {
/// font-size keyword values (and font-size-relative values applied
/// to keyword values) need to preserve their identity as originating
/// from keywords and relative font sizes. We store this information
/// out of band in the ComputedValues. When None, the font size on the
/// current struct was computed from a value that was not a keyword
/// or a chain of font-size-relative values applying to successive parents
/// terminated by a keyword. When Some, this means the font-size was derived
/// from a keyword value or a keyword value on some ancestor with only
/// font-size-relative keywords and regular inheritance in between. The
/// integer stores the final ratio of the chain of font size relative values.
/// and is 1 when there was just a keyword and no relative values.
///
/// 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
/// absolute offset from calcs)
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>
}


impl 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()))
}
///
/// font-size keyword values (and font-size-relative values applied
/// to keyword values) need to preserve their identity as originating
/// from keywords and relative font sizes. We store this information
/// out of band in the ComputedValues. When None, the font size on the
/// current struct was computed from a value that was not a keyword
/// or a chain of font-size-relative values applying to successive parents
/// terminated by a keyword. When Some, this means the font-size was derived
/// from a keyword value or a keyword value on some ancestor with only
/// font-size-relative keywords and regular inheritance in between. The
/// integer stores the final ratio of the chain of font size relative values.
/// and is 1 when there was just a keyword and no relative values.
///
/// 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
/// absolute offset from calcs)
pub type FontComputationData = Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>;

/// Gets a FontComputationData with the default values.
pub fn default_values() -> Self {
Self::new(Self::default_font_size_keyword())
}
/// Default value for FontComputationData
pub fn default_font_size_keyword() -> FontComputationData {
Some((Default::default(), 1., Au(0).into()))
}

impl<T> MaybeBoxed<T> for T {
@@ -2009,7 +1991,7 @@ impl ComputedValues {
_: Option<<&PseudoElement>,
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>,
font_size_keyword: FontComputationData,
flags: ComputedValueFlags,
rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>,
@@ -2042,7 +2024,7 @@ impl ComputedValuesInner {
pub fn new(
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>,
font_size_keyword: FontComputationData,
flags: ComputedValueFlags,
rules: Option<StrongRuleNode>,
visited_style: Option<Arc<ComputedValues>>,
@@ -2053,7 +2035,7 @@ impl ComputedValuesInner {
ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
font_computation_data: font_size_keyword,
rules: rules,
visited_style: visited_style,
flags: flags,
@@ -2566,7 +2548,7 @@ pub struct StyleBuilder<'a> {
/// TODO(emilio): Make private.
pub writing_mode: WritingMode,
/// 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.
pub flags: ComputedValueFlags,
/// 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>,
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>,
font_size_keyword: FontComputationData,
flags: ComputedValueFlags,
visited_style: Option<Arc<ComputedValues>>,
) -> Self {
@@ -2659,7 +2641,7 @@ impl<'a> StyleBuilder<'a> {
rules: None, // FIXME(emilio): Dubious...
custom_properties: style_to_derive_from.custom_properties(),
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,
visited_style: style_to_derive_from.clone_visited_style(),
% for style_struct in data.active_style_structs():
@@ -2759,7 +2741,7 @@ impl<'a> StyleBuilder<'a> {
/* rules = */ None,
parent.custom_properties(),
parent.writing_mode,
parent.font_computation_data.font_size_keyword,
parent.font_computation_data,
parent.flags,
parent.clone_visited_style()
)
@@ -2914,7 +2896,8 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
mod lazy_static_module {
use logical_geometry::WritingMode;
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;

/// The initial values for all style structs as defined by the specification.
@@ -2933,7 +2916,7 @@ mod lazy_static_module {
% endfor
custom_properties: None,
writing_mode: WritingMode::empty(),
font_computation_data: FontComputationData::default_values(),
font_computation_data: default_font_size_keyword(),
rules: None,
visited_style: None,
flags: ComputedValueFlags::empty(),
@@ -3154,7 +3137,7 @@ where
Some(rules.clone()),
custom_properties,
WritingMode::empty(),
inherited_style.font_computation_data.font_size_keyword,
inherited_style.font_computation_data,
ComputedValueFlags::empty(),
visited_style,
),

0 comments on commit 2db5fbb

Please sign in to comment.
You can’t perform that action at this time.