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]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
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 {
|
match *self {
|
||||||
specified::NoCalcLength::Absolute(length) => length.to_computed_value(context),
|
specified::NoCalcLength::Absolute(length) => length.to_computed_value(context),
|
||||||
specified::NoCalcLength::FontRelative(length) => {
|
specified::NoCalcLength::FontRelative(length) => {
|
||||||
length.to_computed_value(context, FontBaseSize::CurrentStyle)
|
length.to_computed_value(context, base_size)
|
||||||
},
|
},
|
||||||
specified::NoCalcLength::ViewportPercentage(length) => {
|
specified::NoCalcLength::ViewportPercentage(length) => {
|
||||||
context
|
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 {
|
impl ToComputedValue for specified::Length {
|
||||||
|
|
|
@ -730,14 +730,16 @@ impl specified::CalcLengthPercentage {
|
||||||
F: Fn(Length) -> Length,
|
F: Fn(Length) -> Length,
|
||||||
{
|
{
|
||||||
use crate::values::specified::calc::Leaf;
|
use crate::values::specified::calc::Leaf;
|
||||||
use crate::values::specified::length::NoCalcLength;
|
|
||||||
|
|
||||||
let node = self.node.map_leaves(|leaf| match *leaf {
|
let node = self.node.map_leaves(|leaf| match *leaf {
|
||||||
Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)),
|
Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)),
|
||||||
Leaf::Length(l) => CalcLengthPercentageLeaf::Length(match l {
|
Leaf::Length(l) => CalcLengthPercentageLeaf::Length({
|
||||||
NoCalcLength::Absolute(ref abs) => zoom_fn(abs.to_computed_value(context)),
|
let result = l.to_computed_value_with_base_size(context, base_size);
|
||||||
NoCalcLength::FontRelative(ref fr) => fr.to_computed_value(context, base_size),
|
if l.should_zoom_text() {
|
||||||
other => other.to_computed_value(context),
|
zoom_fn(result)
|
||||||
|
} else {
|
||||||
|
result
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
Leaf::Number(..) | Leaf::Angle(..) | Leaf::Time(..) => {
|
Leaf::Number(..) | Leaf::Angle(..) | Leaf::Time(..) => {
|
||||||
unreachable!("Shouldn't have parsed")
|
unreachable!("Shouldn't have parsed")
|
||||||
|
@ -755,7 +757,7 @@ impl specified::CalcLengthPercentage {
|
||||||
) -> LengthPercentage {
|
) -> LengthPercentage {
|
||||||
self.to_computed_value_with_zoom(
|
self.to_computed_value_with_zoom(
|
||||||
context,
|
context,
|
||||||
|abs| context.maybe_zoom_text(abs.into()),
|
|abs| context.maybe_zoom_text(abs),
|
||||||
base_size,
|
base_size,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -916,21 +916,21 @@ impl FontSize {
|
||||||
};
|
};
|
||||||
let mut info = KeywordInfo::none();
|
let mut info = KeywordInfo::none();
|
||||||
let size = match *self {
|
let size = match *self {
|
||||||
FontSize::Length(LengthPercentage::Length(NoCalcLength::FontRelative(value))) => {
|
FontSize::Length(LengthPercentage::Length(ref l)) => {
|
||||||
if let FontRelativeLength::Em(em) = value {
|
if let NoCalcLength::FontRelative(ref value) = *l {
|
||||||
// If the parent font was keyword-derived, this is too.
|
if let FontRelativeLength::Em(em) = *value {
|
||||||
// Tack the em unit onto the factor
|
// If the parent font was keyword-derived, this is
|
||||||
info = compose_keyword(em);
|
// 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)) => {
|
FontSize::Length(LengthPercentage::Percentage(pc)) => {
|
||||||
// If the parent font was keyword-derived, this is too.
|
// If the parent font was keyword-derived, this is too.
|
||||||
// Tack the % onto the factor
|
// 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.
|
/// Parse a given absolute or relative dimension.
|
||||||
pub fn parse_dimension(
|
pub fn parse_dimension(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue