mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #18335 - Manishearth:stylo-calc-anim, r=birtles
stylo: Compute font-size calcs against appropriate base size r=birtles https://bugzilla.mozilla.org/show_bug.cgi?id=1394302 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18335) <!-- Reviewable:end -->
This commit is contained in:
commit
60daf54352
4 changed files with 10 additions and 7 deletions
|
@ -859,7 +859,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
base_size.resolve(context).scale_by(pc.0).into()
|
||||
}
|
||||
SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => {
|
||||
let calc = calc.to_computed_value_zoomed(context);
|
||||
let calc = calc.to_computed_value_zoomed(context, base_size);
|
||||
calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
|
||||
}
|
||||
SpecifiedValue::Keyword(ref key, fraction) => {
|
||||
|
|
|
@ -217,7 +217,8 @@ impl ToCss for CalcLengthOrPercentage {
|
|||
|
||||
impl specified::CalcLengthOrPercentage {
|
||||
/// Compute the value, zooming any absolute units by the zoom function.
|
||||
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F) -> CalcLengthOrPercentage
|
||||
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F,
|
||||
base_size: FontBaseSize) -> CalcLengthOrPercentage
|
||||
where F: Fn(Au) -> Au {
|
||||
let mut length = Au(0);
|
||||
|
||||
|
@ -239,7 +240,7 @@ impl specified::CalcLengthOrPercentage {
|
|||
self.ex.map(FontRelativeLength::Ex),
|
||||
self.rem.map(FontRelativeLength::Rem)] {
|
||||
if let Some(val) = *val {
|
||||
length += val.to_computed_value(context, FontBaseSize::CurrentStyle);
|
||||
length += val.to_computed_value(context, base_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,8 +252,8 @@ impl specified::CalcLengthOrPercentage {
|
|||
}
|
||||
|
||||
/// Compute font-size or line-height taking into account text-zoom if necessary.
|
||||
pub fn to_computed_value_zoomed(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0)
|
||||
pub fn to_computed_value_zoomed(&self, context: &Context, base_size: FontBaseSize) -> CalcLengthOrPercentage {
|
||||
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0, base_size)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,7 +261,8 @@ impl ToComputedValue for specified::CalcLengthOrPercentage {
|
|||
type ComputedValue = CalcLengthOrPercentage;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||
self.to_computed_value_with_zoom(context, |abs| abs)
|
||||
// normal properties don't zoom, and compute em units against the current style's font-size
|
||||
self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -80,6 +80,7 @@ impl ToCss for FontRelativeLength {
|
|||
}
|
||||
|
||||
/// A source to resolve font-relative units against
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum FontBaseSize {
|
||||
/// Use the font-size of the current element
|
||||
CurrentStyle,
|
||||
|
|
|
@ -112,7 +112,7 @@ impl ToComputedValue for LineHeight {
|
|||
).into()
|
||||
}
|
||||
LengthOrPercentage::Calc(ref calc) => {
|
||||
let computed_calc = calc.to_computed_value_zoomed(context);
|
||||
let computed_calc = calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle);
|
||||
let font_relative_length =
|
||||
FontRelativeLength::Em(computed_calc.percentage())
|
||||
.to_computed_value(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue