Skip to content

Commit

Permalink
style: Only zoom absolute lengths.
Browse files Browse the repository at this point in the history
As silly as it may seem to specify font-sizes using viewport units, we weren't
handling zoom for them correctly either.

Bug: 1388588
Reviewed-by: Manishearth
MozReview-Commit-ID: 3Q6phYAu5CE
  • Loading branch information
emilio committed Aug 9, 2017
1 parent 77cb537 commit 7d813d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
13 changes: 10 additions & 3 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -844,8 +844,11 @@ ${helpers.single_keyword_system("font-variant-caps",
}

/// Compute it against a given base font size
pub fn to_computed_value_against(&self, context: &Context, base_size: FontBaseSize)
-> NonNegativeAu {
pub fn to_computed_value_against(
&self,
context: &Context,
base_size: FontBaseSize,
) -> NonNegativeAu {
use values::specified::length::FontRelativeLength;
match *self {
SpecifiedValue::Length(LengthOrPercentage::Length(
Expand All @@ -856,9 +859,13 @@ ${helpers.single_keyword_system("font-variant-caps",
NoCalcLength::ServoCharacterWidth(value))) => {
value.to_computed_value(base_size.resolve(context)).into()
}
SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
SpecifiedValue::Length(LengthOrPercentage::Length(
NoCalcLength::Absolute(ref l))) => {
context.maybe_zoom_text(l.to_computed_value(context).into())
}
SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
l.to_computed_value(context).into()
}
SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => {
base_size.resolve(context).scale_by(pc.0).into()
}
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/computed/mod.rs
Expand Up @@ -135,8 +135,7 @@ impl<'a> Context<'a> {
&self.builder
}


/// Apply text-zoom if enabled
/// Apply text-zoom if enabled.
#[cfg(feature = "gecko")]
pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu {
// We disable zoom for <svg:text> by unsetting the
Expand Down
29 changes: 20 additions & 9 deletions components/style/values/specified/text.rs
Expand Up @@ -84,6 +84,7 @@ impl ToComputedValue for LineHeight {

#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
use values::specified::length::FontBaseSize;
match *self {
GenericLineHeight::Normal => {
GenericLineHeight::Normal
Expand All @@ -97,23 +98,33 @@ impl ToComputedValue for LineHeight {
},
GenericLineHeight::Length(ref non_negative_lop) => {
let result = match non_negative_lop.0 {
LengthOrPercentage::Length(NoCalcLength::Absolute(ref abs)) => {
context.maybe_zoom_text(abs.to_computed_value(context).into())
}
LengthOrPercentage::Length(ref length) => {
context.maybe_zoom_text(length.to_computed_value(context).into())
length.to_computed_value(context).into()
},
LengthOrPercentage::Percentage(ref p) => {
let font_relative_length =
Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0)));
font_relative_length.to_computed_value(context).into()
FontRelativeLength::Em(p.0)
.to_computed_value(
context,
FontBaseSize::CurrentStyle,
).into()
}
LengthOrPercentage::Calc(ref calc) => {
let computed_calc = calc.to_computed_value_zoomed(context);
let font_relative_length =
Length::NoCalc(NoCalcLength::FontRelative(
FontRelativeLength::Em(computed_calc.percentage())));
FontRelativeLength::Em(computed_calc.percentage())
.to_computed_value(
context,
FontBaseSize::CurrentStyle,
);

let absolute_length = computed_calc.unclamped_length();
computed_calc.clamping_mode.clamp(
absolute_length + font_relative_length.to_computed_value(context)
).into()
computed_calc
.clamping_mode
.clamp(absolute_length + font_relative_length)
.into()
}
};
GenericLineHeight::Length(result)
Expand Down

0 comments on commit 7d813d8

Please sign in to comment.