mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
stylo: Handle text-zoom for font-size
This commit is contained in:
parent
de5f6f19bd
commit
16d46eaf7a
5 changed files with 52 additions and 15 deletions
|
@ -186,6 +186,11 @@ impl Device {
|
|||
pub fn default_background_color(&self) -> RGBA {
|
||||
convert_nscolor_to_rgba(self.pres_context().mBackgroundColor)
|
||||
}
|
||||
|
||||
/// Applies text zoom to a font-size or line-height value (see nsStyleFont::ZoomText).
|
||||
pub fn zoom_text(&self, size: Au) -> Au {
|
||||
size.scale_by(self.pres_context().mEffectiveTextZoom)
|
||||
}
|
||||
}
|
||||
|
||||
/// A expression for gecko contains a reference to the media feature, the value
|
||||
|
|
|
@ -2231,9 +2231,6 @@ fn static_assert() {
|
|||
)
|
||||
}
|
||||
|
||||
// FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the
|
||||
// actual computed size, and the other of which (mFont.size) is the 'display
|
||||
// size' which takes font zooming into account. We don't handle font zooming yet.
|
||||
pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) {
|
||||
self.gecko.mSize = v.0;
|
||||
self.gecko.mScriptUnconstrainedSize = v.0;
|
||||
|
|
|
@ -830,17 +830,17 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
value.to_computed_value(base_size.resolve(context))
|
||||
}
|
||||
SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
|
||||
l.to_computed_value(context)
|
||||
context.maybe_zoom_text(l.to_computed_value(context))
|
||||
}
|
||||
SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => {
|
||||
base_size.resolve(context).scale_by(pc.0)
|
||||
}
|
||||
SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => {
|
||||
let calc = calc.to_computed_value(context);
|
||||
let calc = calc.to_computed_value_zoomed(context);
|
||||
calc.to_used_value(Some(base_size.resolve(context))).unwrap()
|
||||
}
|
||||
SpecifiedValue::Keyword(ref key, fraction) => {
|
||||
key.to_computed_value(context).scale_by(fraction)
|
||||
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction))
|
||||
}
|
||||
SpecifiedValue::Smaller => {
|
||||
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
|
||||
|
@ -960,7 +960,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
context.builder.get_font().gecko().mGenericID !=
|
||||
context.builder.get_parent_font().gecko().mGenericID {
|
||||
if let Some((kw, ratio)) = context.builder.font_size_keyword {
|
||||
computed = kw.to_computed_value(context).scale_by(ratio);
|
||||
computed = context.maybe_zoom_text(kw.to_computed_value(context).scale_by(ratio));
|
||||
}
|
||||
}
|
||||
% endif
|
||||
|
@ -990,7 +990,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
// changes using the font_size_keyword. We also need to do this to
|
||||
// handle mathml scriptlevel changes
|
||||
let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio)| {
|
||||
SpecifiedValue::Keyword(kw, ratio).to_computed_value(context)
|
||||
context.maybe_zoom_text(SpecifiedValue::Keyword(kw, ratio).to_computed_value(context))
|
||||
});
|
||||
let parent_kw;
|
||||
let device = context.builder.device;
|
||||
|
@ -1015,8 +1015,10 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
pub fn cascade_initial_font_size(context: &mut Context) {
|
||||
// font-size's default ("medium") does not always
|
||||
// compute to the same value and depends on the font
|
||||
let computed = longhands::font_size::get_initial_specified_value()
|
||||
.to_computed_value(context);
|
||||
let computed = context.maybe_zoom_text(
|
||||
longhands::font_size::get_initial_specified_value()
|
||||
.to_computed_value(context)
|
||||
);
|
||||
context.builder.mutate_font().set_font_size(computed);
|
||||
% if product == "gecko":
|
||||
let device = context.builder.device;
|
||||
|
|
|
@ -228,14 +228,14 @@ impl ToCss for CalcLengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::CalcLengthOrPercentage {
|
||||
type ComputedValue = CalcLengthOrPercentage;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||
impl specified::CalcLengthOrPercentage {
|
||||
/// Compute the value, zooming any absolute units by the zoom function.
|
||||
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F) -> CalcLengthOrPercentage
|
||||
where F: Fn(Au) -> Au {
|
||||
let mut length = Au(0);
|
||||
|
||||
if let Some(absolute) = self.absolute {
|
||||
length += absolute;
|
||||
length += zoom_fn(absolute);
|
||||
}
|
||||
|
||||
for val in &[self.vw.map(ViewportPercentageLength::Vw),
|
||||
|
@ -263,6 +263,19 @@ impl ToComputedValue for specified::CalcLengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
/// Compute font-size or line-height taking into account text-zoom if necessary.
|
||||
pub fn to_computed_value_zoomed(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::CalcLengthOrPercentage {
|
||||
type ComputedValue = CalcLengthOrPercentage;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||
self.to_computed_value_with_zoom(context, |abs| abs)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &CalcLengthOrPercentage) -> Self {
|
||||
specified::CalcLengthOrPercentage {
|
||||
|
|
|
@ -132,6 +132,26 @@ impl<'a> Context<'a> {
|
|||
pub fn style(&self) -> &StyleBuilder {
|
||||
&self.builder
|
||||
}
|
||||
|
||||
|
||||
/// Apply text-zoom if enabled
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn maybe_zoom_text(&self, size: Au) -> Au {
|
||||
// We disable zoom for <svg:text> by unsetting the
|
||||
// -x-text-zoom property, which leads to a false value
|
||||
// in mAllowZoom
|
||||
if self.style().get_font().gecko.mAllowZoom {
|
||||
self.device().zoom_text(size)
|
||||
} else {
|
||||
size
|
||||
}
|
||||
}
|
||||
|
||||
/// (Servo doesn't do text-zoom)
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn maybe_zoom_text(&self, size: Au) -> Au {
|
||||
size
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over a slice of computed values
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue