mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
style: Use used, rather than computed font-size for font-metric dependent units
Differential Revision: https://phabricator.services.mozilla.com/D165737
This commit is contained in:
parent
d30400d3ea
commit
18b9e1b615
11 changed files with 64 additions and 39 deletions
|
@ -924,7 +924,7 @@ pub trait MatchMethods: TElement {
|
||||||
if is_root {
|
if is_root {
|
||||||
let device = context.shared.stylist.device();
|
let device = context.shared.stylist.device();
|
||||||
debug_assert!(self.owner_doc_matches_for_testing(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 device.used_root_font_size() {
|
||||||
// If the root font-size changed since last time, and something
|
// If the root font-size changed since last time, and something
|
||||||
// in the document did use rem units, ensure we recascade the
|
// in the document did use rem units, ensure we recascade the
|
||||||
|
|
|
@ -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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -863,6 +863,8 @@ fn static_assert() {
|
||||||
self.gecko.mScriptUnconstrainedSize = other.gecko.mScriptUnconstrainedSize;
|
self.gecko.mScriptUnconstrainedSize = other.gecko.mScriptUnconstrainedSize;
|
||||||
|
|
||||||
self.gecko.mSize = 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.mFont.size = other.gecko.mSize;
|
||||||
self.gecko.mFontSizeKeyword = other.gecko.mFontSizeKeyword;
|
self.gecko.mFontSizeKeyword = other.gecko.mFontSizeKeyword;
|
||||||
|
|
||||||
|
@ -876,12 +878,14 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_font_size(&mut self, v: FontSize) {
|
pub fn set_font_size(&mut self, v: FontSize) {
|
||||||
let size = v.size;
|
let computed_size = v.computed_size;
|
||||||
self.gecko.mScriptUnconstrainedSize = size;
|
self.gecko.mScriptUnconstrainedSize = computed_size;
|
||||||
|
|
||||||
// These two may be changed from Cascade::fixup_font_stuff.
|
// These two may be changed from Cascade::fixup_font_stuff.
|
||||||
self.gecko.mSize = size;
|
self.gecko.mSize = computed_size;
|
||||||
self.gecko.mFont.size = 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.mFontSizeKeyword = v.keyword_info.kw;
|
||||||
self.gecko.mFontSizeFactor = v.keyword_info.factor;
|
self.gecko.mFontSizeFactor = v.keyword_info.factor;
|
||||||
|
@ -892,7 +896,8 @@ fn static_assert() {
|
||||||
use crate::values::specified::font::KeywordInfo;
|
use crate::values::specified::font::KeywordInfo;
|
||||||
|
|
||||||
FontSize {
|
FontSize {
|
||||||
size: self.gecko.mSize,
|
computed_size: self.gecko.mSize,
|
||||||
|
used_size: self.gecko.mFont.size,
|
||||||
keyword_info: KeywordInfo {
|
keyword_info: KeywordInfo {
|
||||||
kw: self.gecko.mFontSizeKeyword,
|
kw: self.gecko.mFontSizeKeyword,
|
||||||
factor: self.gecko.mFontSizeFactor,
|
factor: self.gecko.mFontSizeFactor,
|
||||||
|
|
|
@ -382,10 +382,12 @@ pub mod system_font {
|
||||||
);
|
);
|
||||||
&mut *system.as_mut_ptr()
|
&mut *system.as_mut_ptr()
|
||||||
};
|
};
|
||||||
|
let size = NonNegative(cx.maybe_zoom_text(system.size.0));
|
||||||
let ret = ComputedSystemFont {
|
let ret = ComputedSystemFont {
|
||||||
font_family: system.family.clone(),
|
font_family: system.family.clone(),
|
||||||
font_size: FontSize {
|
font_size: FontSize {
|
||||||
size: NonNegative(cx.maybe_zoom_text(system.size.0)),
|
computed_size: size,
|
||||||
|
used_size: size,
|
||||||
keyword_info: KeywordInfo::none()
|
keyword_info: KeywordInfo::none()
|
||||||
},
|
},
|
||||||
font_weight: system.weight,
|
font_weight: system.weight,
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl RuleCacheConditions {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(fs) = self.font_size {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,8 +226,13 @@ impl FontWeight {
|
||||||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||||
/// The computed value of font-size
|
/// The computed value of font-size
|
||||||
pub struct FontSize {
|
pub struct FontSize {
|
||||||
/// The size.
|
/// The computed size, that we use to compute ems etc. This accounts for
|
||||||
pub size: NonNegativeLength,
|
/// 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
|
/// If derived from a keyword, the keyword and additional transformations applied to it
|
||||||
#[css(skip)]
|
#[css(skip)]
|
||||||
pub keyword_info: KeywordInfo,
|
pub keyword_info: KeywordInfo,
|
||||||
|
@ -236,15 +241,22 @@ pub struct FontSize {
|
||||||
impl FontSize {
|
impl FontSize {
|
||||||
/// The actual computed font size.
|
/// The actual computed font size.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn size(&self) -> Length {
|
pub fn computed_size(&self) -> Length {
|
||||||
self.size.0
|
self.computed_size.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The actual used font size.
|
||||||
|
#[inline]
|
||||||
|
pub fn used_size(&self) -> Length {
|
||||||
|
self.used_size.0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Get default value of font size.
|
/// Get default value of font size.
|
||||||
pub fn medium() -> Self {
|
pub fn medium() -> Self {
|
||||||
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(),
|
keyword_info: KeywordInfo::medium(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,13 +267,14 @@ impl ToAnimatedValue for FontSize {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||||
self.size.0
|
self.computed_size.0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||||
FontSize {
|
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(),
|
keyword_info: KeywordInfo::none(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -839,7 +852,7 @@ impl ToComputedValue for specified::MozScriptMinSize {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
NoCalcLength::FontRelative(value) => value.to_computed_value(cx, base_size),
|
NoCalcLength::FontRelative(value) => value.to_computed_value(cx, base_size),
|
||||||
NoCalcLength::ServoCharacterWidth(value) => {
|
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),
|
ref l => l.to_computed_value(cx),
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl specified::NoCalcLength {
|
||||||
length.to_computed_value(context)
|
length.to_computed_value(context)
|
||||||
},
|
},
|
||||||
specified::NoCalcLength::ServoCharacterWidth(length) => {
|
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())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,7 +327,7 @@ impl<'a> Context<'a> {
|
||||||
FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS,
|
FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS,
|
||||||
FontBaseSize::InheritedStyle => ComputedValueFlags::DEPENDS_ON_INHERITED_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 style = self.style();
|
||||||
|
|
||||||
let (wm, font) = match base_size {
|
let (wm, font) = match base_size {
|
||||||
|
|
|
@ -907,11 +907,11 @@ impl FontSize {
|
||||||
// If the parent font was keyword-derived, this is too.
|
// If the parent font was keyword-derived, this is too.
|
||||||
// Tack the % onto the factor
|
// Tack the % onto the factor
|
||||||
info = compose_keyword(pc.0);
|
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)) => {
|
FontSize::Length(LengthPercentage::Calc(ref calc)) => {
|
||||||
let calc = calc.to_computed_value_zoomed(context, base_size);
|
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) => {
|
FontSize::Keyword(i) => {
|
||||||
// As a specified keyword, this is keyword derived
|
// As a specified keyword, this is keyword derived
|
||||||
|
@ -940,13 +940,13 @@ impl FontSize {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.font_size
|
.font_size
|
||||||
.size
|
.computed_size()
|
||||||
.0
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
computed::FontSize {
|
computed::FontSize {
|
||||||
size: NonNegative(size),
|
computed_size: NonNegative(size),
|
||||||
|
used_size: NonNegative(size),
|
||||||
keyword_info: info,
|
keyword_info: info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -963,7 +963,7 @@ impl ToComputedValue for FontSize {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &computed::FontSize) -> Self {
|
fn from_computed_value(computed: &computed::FontSize) -> Self {
|
||||||
FontSize::Length(LengthPercentage::Length(
|
FontSize::Length(LengthPercentage::Length(
|
||||||
ToComputedValue::from_computed_value(&computed.size.0),
|
ToComputedValue::from_computed_value(&computed.computed_size()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,12 +77,10 @@ pub enum FontBaseSize {
|
||||||
|
|
||||||
impl FontBaseSize {
|
impl FontBaseSize {
|
||||||
/// Calculate the actual size for a given context
|
/// 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 {
|
match *self {
|
||||||
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size().size(),
|
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size(),
|
||||||
FontBaseSize::InheritedStyle => {
|
FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size(),
|
||||||
context.style().get_parent_font().clone_font_size().size()
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,11 +165,11 @@ impl FontRelativeLength {
|
||||||
context
|
context
|
||||||
.rule_cache_conditions
|
.rule_cache_conditions
|
||||||
.borrow_mut()
|
.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) => {
|
FontRelativeLength::Ex(length) => {
|
||||||
// The x-height is an intrinsically horizontal metric.
|
// 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
|
// determine the x-height, a value of 0.5em must be
|
||||||
// assumed.
|
// 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)
|
(reference_size, length)
|
||||||
},
|
},
|
||||||
|
@ -212,11 +212,13 @@ impl FontRelativeLength {
|
||||||
// writing-mode is vertical-rl or vertical-lr and
|
// writing-mode is vertical-rl or vertical-lr and
|
||||||
// text-orientation is upright).
|
// text-orientation is upright).
|
||||||
//
|
//
|
||||||
|
// Same caveat about computed vs. used font-size applies
|
||||||
|
// above.
|
||||||
let wm = context.style().writing_mode;
|
let wm = context.style().writing_mode;
|
||||||
if wm.is_vertical() && wm.is_upright() {
|
if wm.is_vertical() && wm.is_upright() {
|
||||||
reference_font_size
|
reference_font_size.used_size()
|
||||||
} else {
|
} else {
|
||||||
reference_font_size * 0.5
|
reference_font_size.used_size() * 0.5
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
(reference_size, length)
|
(reference_size, length)
|
||||||
|
@ -228,7 +230,8 @@ impl FontRelativeLength {
|
||||||
// https://drafts.csswg.org/css-values/#cap
|
// https://drafts.csswg.org/css-values/#cap
|
||||||
//
|
//
|
||||||
// In the cases where it is impossible or impractical to
|
// 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
|
metrics.ascent
|
||||||
});
|
});
|
||||||
|
@ -247,7 +250,9 @@ impl FontRelativeLength {
|
||||||
// determine the ideographic advance measure, it must be
|
// determine the ideographic advance measure, it must be
|
||||||
// assumed to be 1em.
|
// 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)
|
(reference_size, length)
|
||||||
},
|
},
|
||||||
|
@ -259,7 +264,7 @@ impl FontRelativeLength {
|
||||||
// value.
|
// value.
|
||||||
//
|
//
|
||||||
let reference_size = if context.builder.is_root_element || context.in_media_query {
|
let reference_size = if context.builder.is_root_element || context.in_media_query {
|
||||||
reference_font_size
|
reference_font_size.computed_size()
|
||||||
} else {
|
} else {
|
||||||
context.device().root_font_size()
|
context.device().root_font_size()
|
||||||
};
|
};
|
||||||
|
|
|
@ -123,7 +123,7 @@ impl ToComputedValue for LineHeight {
|
||||||
LengthPercentage::Calc(ref calc) => {
|
LengthPercentage::Calc(ref calc) => {
|
||||||
let computed_calc =
|
let computed_calc =
|
||||||
calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle);
|
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)
|
computed_calc.resolve(base)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue