From 4dd841a0366cef8bb08a796df51045e8737af209 Mon Sep 17 00:00:00 2001 From: Anurag Kalia Date: Mon, 17 Oct 2022 09:28:44 +0000 Subject: [PATCH] style: Make vertical writing mode (left/right) in text-emphasis-position optional Differential Revision: https://phabricator.services.mozilla.com/D158399 --- .../longhands/inherited_text.mako.rs | 4 ++-- components/style/values/specified/box.rs | 2 +- components/style/values/specified/text.rs | 20 +++++++++++-------- components/style_derive/parse.rs | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 627822994bc..541d102a1de 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -221,9 +221,9 @@ ${helpers.predefined_type( ${helpers.predefined_type( "text-emphasis-position", "TextEmphasisPosition", - "computed::TextEmphasisPosition::DEFAULT", + "computed::TextEmphasisPosition::OVER", engines="gecko", - initial_specified_value="specified::TextEmphasisPosition::DEFAULT", + initial_specified_value="specified::TextEmphasisPosition::OVER", animation_value_type="discrete", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position", )} diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index c0e2756c54e..0faf01bc778 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -2242,7 +2242,7 @@ bitflags! { impl ScrollbarGutter { #[inline] - fn has_stable(self) -> bool { + fn has_stable(&self) -> bool { self.intersects(Self::STABLE) } } diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 02711ba61e9..5f21c774372 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -774,7 +774,7 @@ impl Parse for TextEmphasisStyle { bitflags! { #[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem, Parse, ToCss)] #[repr(C)] - #[css(bitflags(mixed="over,under,left,right", validate_mixed="Self::is_valid"))] + #[css(bitflags(mixed="over,under,left,right", validate_mixed="Self::validate_and_simplify"))] /// Values for text-emphasis-position: /// pub struct TextEmphasisPosition: u8 { @@ -786,17 +786,21 @@ bitflags! { const LEFT = 1 << 2; /// Draws marks to the right of the text in vertical writing mode. const RIGHT = 1 << 3; - /// Returns the initial value of `text-emphasis-position` - const DEFAULT = Self::OVER.bits | Self::RIGHT.bits; - /// Non-standard behavior: Intelligent default for zh locale - const DEFAULT_ZH = Self::UNDER.bits | Self::RIGHT.bits; } } impl TextEmphasisPosition { - fn is_valid(self) -> bool { - return self.intersects(Self::LEFT) != self.intersects(Self::RIGHT) && - self.intersects(Self::OVER) != self.intersects(Self::UNDER); + fn validate_and_simplify(&mut self) -> bool { + if self.intersects(Self::OVER) == self.intersects(Self::UNDER) { + return false; + } + + if self.intersects(Self::LEFT) { + return !self.intersects(Self::RIGHT); + } + + self.remove(Self::RIGHT); // Right is the default + true } } diff --git a/components/style_derive/parse.rs b/components/style_derive/parse.rs index 54982c3dec1..d73e1993c89 100644 --- a/components/style_derive/parse.rs +++ b/components/style_derive/parse.rs @@ -47,7 +47,7 @@ fn parse_bitflags(bitflags: &CssBitflagAttrs) -> TokenStream { let mut validate_condition = quote! { !result.is_empty() }; if let Some(ref function) = bitflags.validate_mixed { validate_condition.append_all(quote! { - && #function(result) + && #function(&mut result) }); }