style: Make viewport-relative units zoomable via "zoom text only"

They're not font relative, so it we probably want them to be zoomed.

Differential Revision: https://phabricator.services.mozilla.com/D148796
This commit is contained in:
Emilio Cobos Álvarez 2022-06-14 08:38:11 +00:00 committed by Martin Robinson
parent 82d7f2154d
commit 5de65d9f2c
4 changed files with 47 additions and 25 deletions

View file

@ -31,10 +31,22 @@ impl ToComputedValue for specified::NoCalcLength {
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
self.to_computed_value_with_base_size(context, FontBaseSize::CurrentStyle)
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
specified::NoCalcLength::Absolute(AbsoluteLength::Px(computed.px()))
}
}
impl specified::NoCalcLength {
/// Computes a length with a given font-relative base size.
pub fn to_computed_value_with_base_size(&self, context: &Context, base_size: FontBaseSize) -> Length {
match *self {
specified::NoCalcLength::Absolute(length) => length.to_computed_value(context),
specified::NoCalcLength::FontRelative(length) => {
length.to_computed_value(context, FontBaseSize::CurrentStyle)
length.to_computed_value(context, base_size)
},
specified::NoCalcLength::ViewportPercentage(length) => {
context
@ -47,11 +59,6 @@ impl ToComputedValue for specified::NoCalcLength {
},
}
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
specified::NoCalcLength::Absolute(AbsoluteLength::Px(computed.px()))
}
}
impl ToComputedValue for specified::Length {

View file

@ -730,14 +730,16 @@ impl specified::CalcLengthPercentage {
F: Fn(Length) -> Length,
{
use crate::values::specified::calc::Leaf;
use crate::values::specified::length::NoCalcLength;
let node = self.node.map_leaves(|leaf| match *leaf {
Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)),
Leaf::Length(l) => CalcLengthPercentageLeaf::Length(match l {
NoCalcLength::Absolute(ref abs) => zoom_fn(abs.to_computed_value(context)),
NoCalcLength::FontRelative(ref fr) => fr.to_computed_value(context, base_size),
other => other.to_computed_value(context),
Leaf::Length(l) => CalcLengthPercentageLeaf::Length({
let result = l.to_computed_value_with_base_size(context, base_size);
if l.should_zoom_text() {
zoom_fn(result)
} else {
result
}
}),
Leaf::Number(..) | Leaf::Angle(..) | Leaf::Time(..) => {
unreachable!("Shouldn't have parsed")
@ -755,7 +757,7 @@ impl specified::CalcLengthPercentage {
) -> LengthPercentage {
self.to_computed_value_with_zoom(
context,
|abs| context.maybe_zoom_text(abs.into()),
|abs| context.maybe_zoom_text(abs),
base_size,
)
}