style: Rework -x-text-zoom to allow disabling text zoom and min-font-size separately

And use it instead of explicit document checks. This centralizes where
we check for it.

IsChromeDoc is relatively cheap, but this bug wants to also check for
PDF.js which is a bit more expensive.

No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D176940
This commit is contained in:
Emilio Cobos Álvarez 2023-05-03 15:02:40 +00:00 committed by Martin Robinson
parent a6b97563c3
commit a27f477c7d
10 changed files with 46 additions and 65 deletions

View file

@ -1596,10 +1596,9 @@ impl<'le> TElement for GeckoElement<'le> {
V: Push<ApplicableDeclarationBlock>,
{
use crate::properties::longhands::_x_lang::SpecifiedValue as SpecifiedLang;
use crate::properties::longhands::_x_text_zoom::SpecifiedValue as SpecifiedZoom;
use crate::properties::longhands::color::SpecifiedValue as SpecifiedColor;
use crate::stylesheets::layer_rule::LayerOrder;
use crate::values::specified::color::Color;
use crate::values::specified::{color::Color, font::XTextScale};
lazy_static! {
static ref TABLE_COLOR_RULE: ApplicableDeclarationBlock = {
let global_style_data = &*GLOBAL_STYLE_DATA;
@ -1627,10 +1626,10 @@ impl<'le> TElement for GeckoElement<'le> {
LayerOrder::root(),
)
};
static ref SVG_TEXT_DISABLE_ZOOM_RULE: ApplicableDeclarationBlock = {
static ref SVG_TEXT_DISABLE_SCALE_RULE: ApplicableDeclarationBlock = {
let global_style_data = &*GLOBAL_STYLE_DATA;
let pdb = PropertyDeclarationBlock::with_one(
PropertyDeclaration::XTextZoom(SpecifiedZoom(false)),
PropertyDeclaration::XTextScale(XTextScale::None),
Importance::Normal,
);
let arc = Arc::new_leaked(global_style_data.shared_lock.wrap(pdb));
@ -1653,7 +1652,7 @@ impl<'le> TElement for GeckoElement<'le> {
}
if ns == structs::kNameSpaceID_SVG as i32 {
if self.local_name().as_ptr() == atom!("text").as_ptr() {
hints.push(SVG_TEXT_DISABLE_ZOOM_RULE.clone());
hints.push(SVG_TEXT_DISABLE_SCALE_RULE.clone());
}
}
let declarations =

View file

@ -1028,28 +1028,31 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
builder.mutate_font().gecko_mut().mFont.size = min_font_size;
}
/// <svg:text> is not affected by text zoom, and it uses a preshint
/// to disable it. We fix up the struct when this happens by
/// unzooming its contained font values, which will have been zoomed
/// in the parent.
/// <svg:text> is not affected by text zoom, and it uses a preshint to disable it. We fix up
/// the struct when this happens by unzooming its contained font values, which will have been
/// zoomed in the parent.
///
/// FIXME(emilio): Also, why doing this _before_ handling font-size? That
/// sounds wrong.
/// FIXME(emilio): Why doing this _before_ handling font-size? That sounds wrong.
#[cfg(feature = "gecko")]
fn unzoom_fonts_if_needed(&mut self) {
if !self.seen.contains(LonghandId::XTextZoom) {
if !self.seen.contains(LonghandId::XTextScale) {
return;
}
let builder = &mut self.context.builder;
let parent_zoom = builder.get_parent_font().gecko().mAllowZoomAndMinSize;
let zoom = builder.get_font().gecko().mAllowZoomAndMinSize;
if zoom == parent_zoom {
let parent_text_scale = builder.get_parent_font().clone__x_text_scale();
let text_scale = builder.get_font().clone__x_text_scale();
if parent_text_scale == text_scale {
return;
}
debug_assert_ne!(
parent_text_scale.text_zoom_enabled(),
text_scale.text_zoom_enabled(),
"There's only one value that disables it"
);
debug_assert!(
!zoom,
!text_scale.text_zoom_enabled(),
"We only ever disable text zoom (in svg:text), never enable it"
);
let device = builder.device;
@ -1140,7 +1143,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
}
let mut min = parent_font.mScriptMinSize;
if font.mAllowZoomAndMinSize {
if font.mXTextScale.text_zoom_enabled() {
min = builder.device.zoom_text(min);
}

View file

@ -503,7 +503,7 @@ class Longhand(Property):
"UserSelect",
"WordBreak",
"XSpan",
"XTextZoom",
"XTextScale",
"ZIndex",
}
if self.name == "overflow-y":

View file

@ -841,8 +841,7 @@ fn static_assert() {
font-variant-alternates font-variant-east-asian
font-variant-ligatures font-variant-numeric
font-language-override font-feature-settings
font-variation-settings -moz-min-font-size-ratio
-x-text-zoom""" %>
font-variation-settings -moz-min-font-size-ratio""" %>
<%self:impl_trait style_struct_name="Font"
skip_longhands="${skip_font_longhands}">
@ -943,27 +942,8 @@ fn static_assert() {
})
}
#[allow(non_snake_case)]
pub fn set__x_text_zoom(&mut self, v: longhands::_x_text_zoom::computed_value::T) {
self.gecko.mAllowZoomAndMinSize = v.0;
}
#[allow(non_snake_case)]
pub fn copy__x_text_zoom_from(&mut self, other: &Self) {
self.gecko.mAllowZoomAndMinSize = other.gecko.mAllowZoomAndMinSize;
}
#[allow(non_snake_case)]
pub fn reset__x_text_zoom(&mut self, other: &Self) {
self.copy__x_text_zoom_from(other)
}
#[allow(non_snake_case)]
pub fn clone__x_text_zoom(&self) -> longhands::_x_text_zoom::computed_value::T {
longhands::_x_text_zoom::computed_value::T(self.gecko.mAllowZoomAndMinSize)
}
<% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %>
${impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride")}
${impl_simple_type_with_conversion("font_variant_ligatures", "mFont.variantLigatures")}
${impl_simple_type_with_conversion("font_variant_east_asian", "mFont.variantEastAsian")}
${impl_simple_type_with_conversion("font_variant_numeric", "mFont.variantNumeric")}

View file

@ -331,9 +331,9 @@ ${helpers.predefined_type(
)}
${helpers.predefined_type(
"-x-text-zoom",
"XTextZoom",
"computed::XTextZoom(true)",
"-x-text-scale",
"XTextScale",
"computed::XTextScale::All",
engines="gecko",
animation_value_type="none",
enabled_in="",

View file

@ -915,9 +915,7 @@ CASCADE_GROUPS = {
# Cascade::fixup_font_stuff.
"fonts_and_color": [
# Needed to properly compute the zoomed font-size.
# FIXME(emilio): This could probably just be a cascade flag
# like IN_SVG_SUBTREE or such, and we could nuke this property.
"-x-text-zoom",
"-x-text-scale",
# Needed to do font-size computation in a language-dependent way.
"-x-lang",
# Needed for ruby to respect language-dependent min-font-size

View file

@ -30,7 +30,7 @@ pub use crate::values::specified::font::{FontPalette, FontSynthesis};
pub use crate::values::specified::font::MozScriptSizeMultiplier;
pub use crate::values::specified::font::{
FontVariantAlternates, FontVariantEastAsian, FontVariantLigatures, FontVariantNumeric, XLang,
XTextZoom,
XTextScale,
};
pub use crate::values::specified::Integer as SpecifiedInteger;
pub use crate::values::specified::Number as SpecifiedNumber;

View file

@ -71,7 +71,7 @@ pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumer
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis};
pub use self::font::{FontVariantAlternates, FontWeight};
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextScale};
pub use self::image::{Gradient, Image, ImageRendering, LineDirection, MozImageRect};
pub use self::length::{CSSPixelLength, NonNegativeLength};
pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber};
@ -390,10 +390,7 @@ impl<'a> Context<'a> {
/// Apply text-zoom if enabled.
#[cfg(feature = "gecko")]
pub fn maybe_zoom_text(&self, size: CSSPixelLength) -> CSSPixelLength {
// We disable zoom for <svg:text> by unsetting the
// -x-text-zoom property, which leads to a false value
// in mAllowZoomAndMinSize
if self.style().get_font().gecko.mAllowZoomAndMinSize {
if self.style().get_font().clone__x_text_scale().text_zoom_enabled() {
self.device().zoom_text(size)
} else {
size

View file

@ -1936,6 +1936,7 @@ impl MetricsOverride {
Copy,
Debug,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
@ -1943,19 +1944,22 @@ impl MetricsOverride {
ToResolvedValue,
ToShmem,
)]
/// text-zoom. Enable if true, disable if false
pub struct XTextZoom(#[css(skip)] pub bool);
#[repr(u8)]
/// How to do font-size scaling.
pub enum XTextScale {
/// Both min-font-size and text zoom are enabled.
All,
/// Text-only zoom is enabled, but min-font-size is not honored.
ZoomOnly,
/// Neither of them is enabled.
None,
}
impl Parse for XTextZoom {
fn parse<'i, 't>(
_: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<XTextZoom, ParseError<'i>> {
debug_assert!(
false,
"Should be set directly by presentation attributes only."
);
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
impl XTextScale {
/// Returns whether text zoom is enabled.
#[inline]
pub fn text_zoom_enabled(self) -> bool {
self != Self::None
}
}

View file

@ -58,7 +58,7 @@ pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumer
pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis};
pub use self::font::{FontVariantAlternates, FontWeight};
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextScale};
pub use self::image::{EndingShape as GradientEndingShape, Gradient};
pub use self::image::{Image, ImageRendering, MozImageRect};
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};