From d7e00ba03d0ed8d7382ff7b04103bec8c04c2e5a Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sun, 21 May 2023 23:39:34 +0200 Subject: [PATCH] style: Add some style quirks for legacy ::markers created from list-style-type/list-style-image Specifically: For "bullets", i.e. 'list-style-type:disc|circle|square| disclosure-closed|disclosure-open', we use a built-in font (-moz-bullet-font, which has glyphs for those symbols + space) to retain mostly backwards compatible rendering for those. Authors may override that with an explicit 'font-family' ::marker style though. We also use this font for 'list-style-image' in case it would fallback to one of the above when the image fails to load (so that we get the same width space). When the -moz-bullet-font is used we also set 'font-synthesis' to avoid synthesizing italic/bold for this font. Authors may override this with an explicit ::marker declaration. We also set 'letter-spacing' and 'word-spacing' to the initial value for bullets for web-compat reasons. Again, authors may override this with an explicit ::marker declaration. (This breaks backwards- compat slightly but makes us compatible with Chrome. We used to ignore these for list-style-type: too.) Differential Revision: https://phabricator.services.mozilla.com/D111693 --- components/style/properties/cascade.rs | 28 +++++++++++ .../style/properties/computed_value_flags.rs | 14 +++++- components/style/style_adjuster.rs | 47 +++++++++++++++++++ components/style/values/computed/text.rs | 8 ++++ components/style/values/generics/mod.rs | 15 ++++++ components/style/values/specified/font.rs | 8 ++++ components/style/values/specified/list.rs | 9 ++++ 7 files changed, 128 insertions(+), 1 deletion(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 9c3e6ebd85e..1368cf9c8e7 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -786,6 +786,34 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_PADDING); } + if self + .author_specified + .contains(LonghandId::FontFamily) + { + builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_FONT_FAMILY); + } + + if self + .author_specified + .contains(LonghandId::LetterSpacing) + { + builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_LETTER_SPACING); + } + + if self + .author_specified + .contains(LonghandId::WordSpacing) + { + builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_WORD_SPACING); + } + + if self + .author_specified + .contains(LonghandId::FontSynthesis) + { + builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS); + } + #[cfg(feature = "servo")] { if let Some(font) = builder.get_font_if_mutated() { diff --git a/components/style/properties/computed_value_flags.rs b/components/style/properties/computed_value_flags.rs index cc7d9c94fb9..b3e5fe4f7f9 100644 --- a/components/style/properties/computed_value_flags.rs +++ b/components/style/properties/computed_value_flags.rs @@ -12,7 +12,7 @@ bitflags! { /// If we ever want to add some flags that shouldn't inherit for them, /// we might want to add a function to handle this. #[repr(C)] - pub struct ComputedValueFlags: u16 { + pub struct ComputedValueFlags: u32 { /// Whether the style or any of the ancestors has a text-decoration-line /// property that should get propagated to descendants. /// @@ -89,6 +89,18 @@ bitflags! { /// FIXME(emilio): Try to merge this with BORDER_BACKGROUND, see /// https://github.com/w3c/csswg-drafts/issues/4777 const HAS_AUTHOR_SPECIFIED_PADDING = 1 << 15; + + /// Whether there are author-specified rules for `font-family`. + const HAS_AUTHOR_SPECIFIED_FONT_FAMILY = 1 << 16; + + /// Whether there are author-specified rules for `font-synthesis`. + const HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS = 1 << 17; + + /// Whether there are author-specified rules for `letter-spacing`. + const HAS_AUTHOR_SPECIFIED_LETTER_SPACING = 1 << 18; + + /// Whether there are author-specified rules for `word-spacing`. + const HAS_AUTHOR_SPECIFIED_WORD_SPACING = 1 << 19; } } diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 158be6d5dfb..bfd43da6088 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -818,6 +818,52 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } } + /// A legacy ::marker (i.e. no 'content') without an author-specified 'font-family' + /// and 'list-style-type:disc|circle|square|disclosure-closed|disclosure-open' + /// is assigned 'font-family:-moz-bullet-font'. (This is for