diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2023-01-02 02:29:30 +0000 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-11-04 08:17:09 +0100 |
commit | 18b9e1b615c583ccce13552102ab517a77005f39 (patch) | |
tree | 1a54fa8deec29ae5f5ce0bb0d95b7cb0206acd13 /components | |
parent | d30400d3ea6c057f112c6b502415e96bf55ce0ce (diff) | |
download | servo-18b9e1b615c583ccce13552102ab517a77005f39.tar.gz servo-18b9e1b615c583ccce13552102ab517a77005f39.zip |
style: Use used, rather than computed font-size for font-metric dependent units
Differential Revision: https://phabricator.services.mozilla.com/D165737
Diffstat (limited to 'components')
-rw-r--r-- | components/style/matching.rs | 2 | ||||
-rw-r--r-- | components/style/properties/cascade.rs | 2 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 15 | ||||
-rw-r--r-- | components/style/properties/longhands/font.mako.rs | 4 | ||||
-rw-r--r-- | components/style/rule_cache.rs | 2 | ||||
-rw-r--r-- | components/style/values/computed/font.rs | 29 | ||||
-rw-r--r-- | components/style/values/computed/length.rs | 2 | ||||
-rw-r--r-- | components/style/values/computed/mod.rs | 2 | ||||
-rw-r--r-- | components/style/values/specified/font.rs | 12 | ||||
-rw-r--r-- | components/style/values/specified/length.rs | 31 | ||||
-rw-r--r-- | components/style/values/specified/text.rs | 2 |
11 files changed, 64 insertions, 39 deletions
diff --git a/components/style/matching.rs b/components/style/matching.rs index a22dba26808..fa757693e5b 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -924,7 +924,7 @@ pub trait MatchMethods: TElement { if is_root { let device = context.shared.stylist.device(); debug_assert!(self.owner_doc_matches_for_testing(device)); - device.set_root_font_size(new_font_size.size().into()); + device.set_root_font_size(new_font_size.computed_size().into()); if device.used_root_font_size() { // If the root font-size changed since last time, and something // in the document did use rem units, ensure we recascade the diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index dfd063ba8a5..ce8973f4939 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -983,7 +983,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { }, }; - if font.gecko().mScriptUnconstrainedSize == new_size.size { + if font.gecko().mScriptUnconstrainedSize == new_size.computed_size { return; } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 03301cc07d2..05f2d3223bd 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -863,6 +863,8 @@ fn static_assert() { self.gecko.mScriptUnconstrainedSize = other.gecko.mScriptUnconstrainedSize; self.gecko.mSize = other.gecko.mScriptUnconstrainedSize; + // NOTE: Intentionally not copying from mFont.size. The cascade process + // recomputes the used size as needed. self.gecko.mFont.size = other.gecko.mSize; self.gecko.mFontSizeKeyword = other.gecko.mFontSizeKeyword; @@ -876,12 +878,14 @@ fn static_assert() { } pub fn set_font_size(&mut self, v: FontSize) { - let size = v.size; - self.gecko.mScriptUnconstrainedSize = size; + let computed_size = v.computed_size; + self.gecko.mScriptUnconstrainedSize = computed_size; // These two may be changed from Cascade::fixup_font_stuff. - self.gecko.mSize = size; - self.gecko.mFont.size = size; + self.gecko.mSize = computed_size; + // NOTE: Intentionally not copying from used_size. The cascade process + // recomputes the used size as needed. + self.gecko.mFont.size = computed_size; self.gecko.mFontSizeKeyword = v.keyword_info.kw; self.gecko.mFontSizeFactor = v.keyword_info.factor; @@ -892,7 +896,8 @@ fn static_assert() { use crate::values::specified::font::KeywordInfo; FontSize { - size: self.gecko.mSize, + computed_size: self.gecko.mSize, + used_size: self.gecko.mFont.size, keyword_info: KeywordInfo { kw: self.gecko.mFontSizeKeyword, factor: self.gecko.mFontSizeFactor, diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs index 67e8db666ef..e987a42b652 100644 --- a/components/style/properties/longhands/font.mako.rs +++ b/components/style/properties/longhands/font.mako.rs @@ -382,10 +382,12 @@ pub mod system_font { ); &mut *system.as_mut_ptr() }; + let size = NonNegative(cx.maybe_zoom_text(system.size.0)); let ret = ComputedSystemFont { font_family: system.family.clone(), font_size: FontSize { - size: NonNegative(cx.maybe_zoom_text(system.size.0)), + computed_size: size, + used_size: size, keyword_info: KeywordInfo::none() }, font_weight: system.weight, diff --git a/components/style/rule_cache.rs b/components/style/rule_cache.rs index 24039fb94f7..604a92b724a 100644 --- a/components/style/rule_cache.rs +++ b/components/style/rule_cache.rs @@ -53,7 +53,7 @@ impl RuleCacheConditions { } if let Some(fs) = self.font_size { - if style.get_font().clone_font_size().size != fs { + if style.get_font().clone_font_size().computed_size != fs { return false; } } diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 43f12a2f6cb..8fe54445d05 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -226,8 +226,13 @@ impl FontWeight { #[cfg_attr(feature = "servo", derive(Serialize, Deserialize))] /// The computed value of font-size pub struct FontSize { - /// The size. - pub size: NonNegativeLength, + /// The computed size, that we use to compute ems etc. This accounts for + /// e.g., text-zoom. + pub computed_size: NonNegativeLength, + /// The actual used size. This is the computed font size, potentially + /// constrained by other factors like minimum font-size settings and so on. + #[css(skip)] + pub used_size: NonNegativeLength, /// If derived from a keyword, the keyword and additional transformations applied to it #[css(skip)] pub keyword_info: KeywordInfo, @@ -236,15 +241,22 @@ pub struct FontSize { impl FontSize { /// The actual computed font size. #[inline] - pub fn size(&self) -> Length { - self.size.0 + pub fn computed_size(&self) -> Length { + self.computed_size.0 + } + + /// The actual used font size. + #[inline] + pub fn used_size(&self) -> Length { + self.used_size.0 } #[inline] /// Get default value of font size. pub fn medium() -> Self { Self { - size: NonNegative(Length::new(specified::FONT_MEDIUM_PX)), + computed_size: NonNegative(Length::new(specified::FONT_MEDIUM_PX)), + used_size: NonNegative(Length::new(specified::FONT_MEDIUM_PX)), keyword_info: KeywordInfo::medium(), } } @@ -255,13 +267,14 @@ impl ToAnimatedValue for FontSize { #[inline] fn to_animated_value(self) -> Self::AnimatedValue { - self.size.0 + self.computed_size.0 } #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { FontSize { - size: NonNegative(animated.clamp_to_non_negative()), + computed_size: NonNegative(animated.clamp_to_non_negative()), + used_size: NonNegative(animated.clamp_to_non_negative()), keyword_info: KeywordInfo::none(), } } @@ -839,7 +852,7 @@ impl ToComputedValue for specified::MozScriptMinSize { match self.0 { NoCalcLength::FontRelative(value) => value.to_computed_value(cx, base_size), NoCalcLength::ServoCharacterWidth(value) => { - value.to_computed_value(base_size.resolve(cx)) + value.to_computed_value(base_size.resolve(cx).computed_size()) }, ref l => l.to_computed_value(cx), } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 29bed80d926..4f68e1c4593 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -58,7 +58,7 @@ impl specified::NoCalcLength { length.to_computed_value(context) }, specified::NoCalcLength::ServoCharacterWidth(length) => { - length.to_computed_value(context.style().get_font().clone_font_size().size()) + length.to_computed_value(context.style().get_font().clone_font_size().computed_size()) }, } } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index de5c1e5a374..dac4c4f2467 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -327,7 +327,7 @@ impl<'a> Context<'a> { FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS, FontBaseSize::InheritedStyle => ComputedValueFlags::DEPENDS_ON_INHERITED_FONT_METRICS, }); - let size = base_size.resolve(self); + let size = base_size.resolve(self).used_size(); let style = self.style(); let (wm, font) = match base_size { diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index d2e47bf7dfc..f61f1c5abaa 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -907,11 +907,11 @@ impl FontSize { // If the parent font was keyword-derived, this is too. // Tack the % onto the factor info = compose_keyword(pc.0); - (base_size.resolve(context) * pc.0).normalized() + (base_size.resolve(context).computed_size() * pc.0).normalized() }, FontSize::Length(LengthPercentage::Calc(ref calc)) => { let calc = calc.to_computed_value_zoomed(context, base_size); - calc.resolve(base_size.resolve(context)) + calc.resolve(base_size.resolve(context).computed_size()) }, FontSize::Keyword(i) => { // As a specified keyword, this is keyword derived @@ -940,13 +940,13 @@ impl FontSize { .as_ref() .unwrap() .font_size - .size - .0 + .computed_size() } }, }; computed::FontSize { - size: NonNegative(size), + computed_size: NonNegative(size), + used_size: NonNegative(size), keyword_info: info, } } @@ -963,7 +963,7 @@ impl ToComputedValue for FontSize { #[inline] fn from_computed_value(computed: &computed::FontSize) -> Self { FontSize::Length(LengthPercentage::Length( - ToComputedValue::from_computed_value(&computed.size.0), + ToComputedValue::from_computed_value(&computed.computed_size()), )) } } diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index ea96ef7426e..2d0a031953f 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -77,12 +77,10 @@ pub enum FontBaseSize { impl FontBaseSize { /// Calculate the actual size for a given context - pub fn resolve(&self, context: &Context) -> computed::Length { + pub fn resolve(&self, context: &Context) -> computed::FontSize { match *self { - FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size().size(), - FontBaseSize::InheritedStyle => { - context.style().get_parent_font().clone_font_size().size() - }, + FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size(), + FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size(), } } } @@ -167,11 +165,11 @@ impl FontRelativeLength { context .rule_cache_conditions .borrow_mut() - .set_font_size_dependency(reference_font_size.into()); + .set_font_size_dependency(reference_font_size.computed_size); } } - (reference_font_size, length) + (reference_font_size.computed_size(), length) }, FontRelativeLength::Ex(length) => { // The x-height is an intrinsically horizontal metric. @@ -184,7 +182,9 @@ impl FontRelativeLength { // determine the x-height, a value of 0.5em must be // assumed. // - reference_font_size * 0.5 + // (But note we use 0.5em of the used, not computed + // font-size) + reference_font_size.used_size() * 0.5 }); (reference_size, length) }, @@ -212,11 +212,13 @@ impl FontRelativeLength { // writing-mode is vertical-rl or vertical-lr and // text-orientation is upright). // + // Same caveat about computed vs. used font-size applies + // above. let wm = context.style().writing_mode; if wm.is_vertical() && wm.is_upright() { - reference_font_size + reference_font_size.used_size() } else { - reference_font_size * 0.5 + reference_font_size.used_size() * 0.5 } }); (reference_size, length) @@ -228,7 +230,8 @@ impl FontRelativeLength { // https://drafts.csswg.org/css-values/#cap // // In the cases where it is impossible or impractical to - // determine the cap-height, the font’s ascent must be used. + // determine the cap-height, the font’s ascent must be + // used. // metrics.ascent }); @@ -247,7 +250,9 @@ impl FontRelativeLength { // determine the ideographic advance measure, it must be // assumed to be 1em. // - reference_font_size + // Same caveat about computed vs. used as for other + // metric-dependent units. + reference_font_size.used_size() }); (reference_size, length) }, @@ -259,7 +264,7 @@ impl FontRelativeLength { // value. // let reference_size = if context.builder.is_root_element || context.in_media_query { - reference_font_size + reference_font_size.computed_size() } else { context.device().root_font_size() }; diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 5f21c774372..b782780c955 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -123,7 +123,7 @@ impl ToComputedValue for LineHeight { LengthPercentage::Calc(ref calc) => { let computed_calc = calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle); - let base = context.style().get_font().clone_font_size().size(); + let base = context.style().get_font().clone_font_size().computed_size(); computed_calc.resolve(base) }, }; |