mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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:
parent
82d7f2154d
commit
5de65d9f2c
4 changed files with 47 additions and 25 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -916,21 +916,21 @@ impl FontSize {
|
|||
};
|
||||
let mut info = KeywordInfo::none();
|
||||
let size = match *self {
|
||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::FontRelative(value))) => {
|
||||
if let FontRelativeLength::Em(em) = value {
|
||||
// If the parent font was keyword-derived, this is too.
|
||||
// Tack the em unit onto the factor
|
||||
info = compose_keyword(em);
|
||||
FontSize::Length(LengthPercentage::Length(ref l)) => {
|
||||
if let NoCalcLength::FontRelative(ref value) = *l {
|
||||
if let FontRelativeLength::Em(em) = *value {
|
||||
// If the parent font was keyword-derived, this is
|
||||
// too. Tack the em unit onto the factor
|
||||
info = compose_keyword(em);
|
||||
}
|
||||
}
|
||||
let result = l.to_computed_value_with_base_size(context, base_size);
|
||||
if l.should_zoom_text() {
|
||||
context.maybe_zoom_text(result)
|
||||
} else {
|
||||
result
|
||||
}
|
||||
value.to_computed_value(context, base_size)
|
||||
},
|
||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::ServoCharacterWidth(
|
||||
value,
|
||||
))) => value.to_computed_value(base_size.resolve(context)),
|
||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::Absolute(ref l))) => {
|
||||
context.maybe_zoom_text(l.to_computed_value(context))
|
||||
},
|
||||
FontSize::Length(LengthPercentage::Length(ref l)) => l.to_computed_value(context),
|
||||
FontSize::Length(LengthPercentage::Percentage(pc)) => {
|
||||
// If the parent font was keyword-derived, this is too.
|
||||
// Tack the % onto the factor
|
||||
|
|
|
@ -790,6 +790,19 @@ impl NoCalcLength {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether text-only zoom should be applied to this length.
|
||||
///
|
||||
/// Generally, font-dependent/relative units don't get text-only-zoomed,
|
||||
/// because the font they're relative to should be zoomed already.
|
||||
pub fn should_zoom_text(&self) -> bool {
|
||||
match *self {
|
||||
Self::Absolute(..) |
|
||||
Self::ViewportPercentage(..) => true,
|
||||
Self::ServoCharacterWidth(..) |
|
||||
Self::FontRelative(..) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a given absolute or relative dimension.
|
||||
pub fn parse_dimension(
|
||||
context: &ParserContext,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue