--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -48,17 +48,17 @@ use gecko_bindings::sugar::ns_style_coor
use gecko::values::convert_nscolor_to_rgba;
use gecko::values::convert_rgba_to_nscolor;
use gecko::values::GeckoStyleCoordConvertible;
use gecko::values::round_border_to_device_pixels;
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;
use servo_arc::{Arc, RawOffsetArc};
use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr};
use values::{self, Auto, CustomIdent, Either, KeyframesName, None_};
use values::computed::{NonNegativeAu, ToComputedValue, Percentage};
@@ -80,17 +80,17 @@ pub struct ComputedValues(::gecko_bindin
impl ComputedValues {
pub fn new(
device: &Device,
parent: Option<<&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>>,
% for style_struct in data.style_structs:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Arc<Self> {
ComputedValuesInner::new(
@@ -109,17 +109,17 @@ impl ComputedValues {
pseudo.map(|p| p.pseudo_info())
)
}
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
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,
% for style_struct in data.style_structs:
style_structs::${style_struct.name}::default(pres_context),
% endfor
).to_outer(pres_context, None, None)
}
@@ -183,28 +183,28 @@ impl Clone for ComputedValuesInner {
}
type PseudoInfo = (*mut structs::nsIAtom, structs::CSSPseudoElementType);
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>>,
% for style_struct in data.style_structs:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Self {
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,
% for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}),
% endfor
}
}
--- a/servo/components/style/properties/longhand/font.mako.rs
+++ b/servo/components/style/properties/longhand/font.mako.rs
@@ -975,17 +975,17 @@ macro_rules! impl_gecko_keyword_conversi
context.builder.font_size_keyword = Some((kw, fraction, offset));
} else if let Some((ratio, abs)) = specified_value.as_font_ratio(context) {
// In case a font-size-relative value was applied to a keyword
// value, we must preserve this fact in case the generic font family
// changes. relative values (em and %) applied to keywords must be
// 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 {
+ 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;
}
} else {
context.builder.font_size_keyword = None;
}
@@ -1032,17 +1032,17 @@ macro_rules! impl_gecko_keyword_conversi
let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio, offset)| {
context.maybe_zoom_text(SpecifiedValue::Keyword(kw, ratio, offset).to_computed_value(context))
});
let parent_kw;
let device = context.builder.device;
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)
};
context.builder.put_font(font);
context.builder.font_size_keyword =
if used_kw { parent_kw } else { None };
}
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -89,54 +89,37 @@ pub mod declaration_block;
pub trait MaybeBoxed<Out> {
/// Convert
fn maybe_boxed(self) -> 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()))
- }
-
- /// Gets a FontComputationData with the default values.
- pub fn default_values() -> Self {
- Self::new(Self::default_font_size_keyword())
- }
+///
+/// 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)>;
+
+/// Default value for FontComputationData
+pub fn default_font_size_keyword() -> FontComputationData {
+ Some((Default::default(), 1., Au(0).into()))
}
impl<T> MaybeBoxed<T> for T {
#[inline]
fn maybe_boxed(self) -> T { self }
}
impl<T> MaybeBoxed<Box<T>> for T {
@@ -2002,17 +1985,17 @@ pub struct ComputedValues {
impl ComputedValues {
/// Create a new refcounted `ComputedValues`
pub fn new(
_: &Device,
_: Option<<&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>>,
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Arc<Self> {
Arc::new(Self {
@@ -2035,28 +2018,28 @@ impl ComputedValues {
}
#[cfg(feature = "servo")]
impl ComputedValuesInner {
/// Construct a `ComputedValuesInner` instance.
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>>,
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Self {
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,
% for style_struct in data.active_style_structs():
${style_struct.ident}: ${style_struct.ident},
% endfor
}
}
@@ -2559,17 +2542,17 @@ pub struct StyleBuilder<'a> {
/// The pseudo-element this style will represent.
pseudo: Option<<&'a PseudoElement>,
/// The writing mode flags.
///
/// 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
/// for this element. A element's "relevant link" is the element being
/// matched if it is a link or the nearest ancestor link.
visited_style: Option<Arc<ComputedValues>>,
% for style_struct in data.active_style_structs():
${style_struct.ident}: StyleStructRef<'a, style_structs::${style_struct.name}>,
@@ -2582,17 +2565,17 @@ impl<'a> StyleBuilder<'a> {
device: &'a Device,
parent_style: Option<<&'a ComputedValues>,
parent_style_ignoring_first_line: Option<<&'a ComputedValues>,
pseudo: Option<<&'a PseudoElement>,
cascade_flags: CascadeFlags,
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 {
debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some());
#[cfg(feature = "gecko")]
debug_assert!(parent_style.is_none() ||
ptr::eq(parent_style.unwrap(),
parent_style_ignoring_first_line.unwrap()) ||
@@ -2652,17 +2635,17 @@ impl<'a> StyleBuilder<'a> {
inherited_style,
// None of our callers pass in ::first-line parent styles.
inherited_style_ignoring_first_line: inherited_style,
reset_style,
pseudo,
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():
${style_struct.ident}: StyleStructRef::Borrowed(
style_to_derive_from.${style_struct.name_lower}_arc()
),
% endfor
}
@@ -2752,17 +2735,17 @@ impl<'a> StyleBuilder<'a> {
device,
Some(parent),
Some(parent),
pseudo,
CascadeFlags::empty(),
/* 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()
)
}
/// Returns whether we have a visited style.
pub fn has_visited_style(&self) -> bool {
self.visited_style.is_some()
@@ -3146,17 +3129,17 @@ where
device,
parent_style,
parent_style_ignoring_first_line,
pseudo,
flags,
Some(rules.clone()),
custom_properties,
WritingMode::empty(),
- inherited_style.font_computation_data.font_size_keyword,
+ inherited_style.font_computation_data,
ComputedValueFlags::empty(),
visited_style,
),
font_metrics_provider: font_metrics_provider,
cached_system_font: None,
in_media_query: false,
quirks_mode: quirks_mode,
for_smil_animation: false,