Auto merge of #18022 - emilio:text-zoom-woes, r=Manishearth

style: Only zoom absolute lengths.

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

<!-- 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/18022)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-09 11:58:12 -05:00 committed by GitHub
commit 1457f99909
3 changed files with 31 additions and 14 deletions

View file

@ -844,8 +844,11 @@ ${helpers.single_keyword_system("font-variant-caps",
} }
/// Compute it against a given base font size /// Compute it against a given base font size
pub fn to_computed_value_against(&self, context: &Context, base_size: FontBaseSize) pub fn to_computed_value_against(
-> NonNegativeAu { &self,
context: &Context,
base_size: FontBaseSize,
) -> NonNegativeAu {
use values::specified::length::FontRelativeLength; use values::specified::length::FontRelativeLength;
match *self { match *self {
SpecifiedValue::Length(LengthOrPercentage::Length( SpecifiedValue::Length(LengthOrPercentage::Length(
@ -856,9 +859,13 @@ ${helpers.single_keyword_system("font-variant-caps",
NoCalcLength::ServoCharacterWidth(value))) => { NoCalcLength::ServoCharacterWidth(value))) => {
value.to_computed_value(base_size.resolve(context)).into() 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()) 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)) => { SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => {
base_size.resolve(context).scale_by(pc.0).into() base_size.resolve(context).scale_by(pc.0).into()
} }

View file

@ -135,8 +135,7 @@ impl<'a> Context<'a> {
&self.builder &self.builder
} }
/// Apply text-zoom if enabled.
/// Apply text-zoom if enabled
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu { pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu {
// We disable zoom for <svg:text> by unsetting the // We disable zoom for <svg:text> by unsetting the

View file

@ -84,6 +84,7 @@ impl ToComputedValue for LineHeight {
#[inline] #[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
use values::specified::length::FontBaseSize;
match *self { match *self {
GenericLineHeight::Normal => { GenericLineHeight::Normal => {
GenericLineHeight::Normal GenericLineHeight::Normal
@ -97,23 +98,33 @@ impl ToComputedValue for LineHeight {
}, },
GenericLineHeight::Length(ref non_negative_lop) => { GenericLineHeight::Length(ref non_negative_lop) => {
let result = match non_negative_lop.0 { 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) => { LengthOrPercentage::Length(ref length) => {
context.maybe_zoom_text(length.to_computed_value(context).into()) length.to_computed_value(context).into()
}, },
LengthOrPercentage::Percentage(ref p) => { LengthOrPercentage::Percentage(ref p) => {
let font_relative_length = FontRelativeLength::Em(p.0)
Length::NoCalc(NoCalcLength::FontRelative(FontRelativeLength::Em(p.0))); .to_computed_value(
font_relative_length.to_computed_value(context).into() context,
FontBaseSize::CurrentStyle,
).into()
} }
LengthOrPercentage::Calc(ref calc) => { LengthOrPercentage::Calc(ref calc) => {
let computed_calc = calc.to_computed_value_zoomed(context); let computed_calc = calc.to_computed_value_zoomed(context);
let font_relative_length = 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(); let absolute_length = computed_calc.unclamped_length();
computed_calc.clamping_mode.clamp( computed_calc
absolute_length + font_relative_length.to_computed_value(context) .clamping_mode
).into() .clamp(absolute_length + font_relative_length)
.into()
} }
}; };
GenericLineHeight::Length(result) GenericLineHeight::Length(result)