diff --git a/.gitignore b/.gitignore index 68bfa091d929..35e4be025362 100644 --- a/.gitignore +++ b/.gitignore @@ -131,6 +131,9 @@ mobile/android/gradle/.gradle # Rust/Cargo output from running `cargo` directly /target/ +/servo/ports/geckolib/target/ +/dom/base/rust/target/ +/servo/components/style/target/ # Ignore mozharness execution files testing/mozharness/.tox/ diff --git a/.hgignore b/.hgignore index 83fab97aba8f..94c6bde51657 100644 --- a/.hgignore +++ b/.hgignore @@ -147,6 +147,9 @@ _OPT\.OBJ/ # Rust/Cargo output from running `cargo` directly ^target/ +^servo/ports/geckolib/target/ +^dom/base/rust/target/ +^servo/components/style/target/ # Ignore mozharness execution files ^testing/mozharness/.tox/ @@ -258,4 +261,4 @@ toolkit/components/certviewer/content/package-lock.json ^tools/esmify/jscodeshift ^tools/esmify/jscodeshift.cmd ^tools/esmify/jscodeshift.ps1 -^tools/esmify/package-lock.json +^tools/esmify/package-lock.json \ No newline at end of file diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index ce218aa3b616..c99c5b59b7cb 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -1188,13 +1188,13 @@ static inline void MapLangAttributeInto(const nsMappedAttributes* aAttributes, const nsAtom* lang = langValue->GetAtomValue(); if (nsStyleUtil::MatchesLanguagePrefix(lang, u"zh")) { aDecls.SetKeywordValue(eCSSProperty_text_emphasis_position, - NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH); + StyleTextEmphasisPosition::DEFAULT_ZH.bits); } else if (nsStyleUtil::MatchesLanguagePrefix(lang, u"ja") || nsStyleUtil::MatchesLanguagePrefix(lang, u"mn")) { // This branch is currently no part of the spec. // See bug 1040668 comment 69 and comment 75. aDecls.SetKeywordValue(eCSSProperty_text_emphasis_position, - NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT); + StyleTextEmphasisPosition::DEFAULT.bits); } } } diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 259bbf2d7823..8a565b6f63bd 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -566,6 +566,7 @@ cbindgen-types = [ { gecko = "StyleGenericTrackList", servo = "crate::values::generics::grid::TrackList" }, { gecko = "StyleGenericGridTemplateComponent", servo = "crate::values::generics::grid::GridTemplateComponent" }, { gecko = "StyleTextEmphasisStyle", servo = "crate::values::computed::text::TextEmphasisStyle" }, + { gecko = "StyleTextEmphasisPosition", servo = "crate::values::computed::TextEmphasisPosition" }, { gecko = "StyleVariantAlternatesList", servo = "crate::values::specified::font::VariantAlternatesList" }, { gecko = "StyleSVGPaintOrder", servo = "crate::values::specified::svg::SVGPaintOrder" }, { gecko = "StyleClipRectOrAuto", servo = "crate::values::computed::ClipRectOrAuto" }, diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index fc18dad6d6cd..59cbd0e7903e 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -682,17 +682,6 @@ enum class StyleTextAnchor : uint8_t { End, }; -// text-emphasis-position -#define NS_STYLE_TEXT_EMPHASIS_POSITION_OVER (1 << 0) -#define NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER (1 << 1) -#define NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT (1 << 2) -#define NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT (1 << 3) -#define NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT \ - (NS_STYLE_TEXT_EMPHASIS_POSITION_OVER | NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT) -#define NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH \ - (NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER | \ - NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT) - // text-rendering enum class StyleTextRendering : uint8_t { Auto, diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 968c54f2d863..ac2a3268a2f4 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -2965,8 +2965,8 @@ nsStyleText::nsStyleText(const Document& aDocument) RefPtr language = aDocument.GetContentLanguageAsAtomForStyle(); mTextEmphasisPosition = language && nsStyleUtil::MatchesLanguagePrefix(language, u"zh") - ? NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH - : NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT; + ? StyleTextEmphasisPosition::DEFAULT_ZH + : StyleTextEmphasisPosition::DEFAULT; } nsStyleText::nsStyleText(const nsStyleText& aSource) @@ -3092,17 +3092,16 @@ nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aNewData) const { } LogicalSide nsStyleText::TextEmphasisSide(WritingMode aWM) const { - MOZ_ASSERT( - (!(mTextEmphasisPosition & NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT) != - !(mTextEmphasisPosition & NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT)) && - (!(mTextEmphasisPosition & NS_STYLE_TEXT_EMPHASIS_POSITION_OVER) != - !(mTextEmphasisPosition & NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER))); + MOZ_ASSERT((!(mTextEmphasisPosition & StyleTextEmphasisPosition::LEFT) != + !(mTextEmphasisPosition & StyleTextEmphasisPosition::RIGHT)) && + (!(mTextEmphasisPosition & StyleTextEmphasisPosition::OVER) != + !(mTextEmphasisPosition & StyleTextEmphasisPosition::UNDER))); mozilla::Side side = aWM.IsVertical() - ? (mTextEmphasisPosition & NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT + ? (mTextEmphasisPosition & StyleTextEmphasisPosition::LEFT ? eSideLeft : eSideRight) - : (mTextEmphasisPosition & NS_STYLE_TEXT_EMPHASIS_POSITION_OVER + : (mTextEmphasisPosition & StyleTextEmphasisPosition::OVER ? eSideTop : eSideBottom); LogicalSide result = aWM.LogicalSideForPhysicalSide(side); diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index e6dcafbd98f0..37ef4640ab81 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -949,7 +949,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText { mozilla::StyleTextSizeAdjust mTextSizeAdjust; uint8_t mTextCombineUpright; // NS_STYLE_TEXT_COMBINE_UPRIGHT_* mozilla::StyleMozControlCharacterVisibility mMozControlCharacterVisibility; - uint8_t mTextEmphasisPosition; // NS_STYLE_TEXT_EMPHASIS_POSITION_* + mozilla::StyleTextEmphasisPosition mTextEmphasisPosition; mozilla::StyleTextRendering mTextRendering; mozilla::StyleColor mTextEmphasisColor; mozilla::StyleColor mWebkitTextFillColor; diff --git a/servo/components/style/properties/longhands/inherited_text.mako.rs b/servo/components/style/properties/longhands/inherited_text.mako.rs index 5f98dc15dc5f..c1d6ca513b98 100644 --- a/servo/components/style/properties/longhands/inherited_text.mako.rs +++ b/servo/components/style/properties/longhands/inherited_text.mako.rs @@ -220,9 +220,9 @@ ${helpers.predefined_type( ${helpers.predefined_type( "text-emphasis-position", "TextEmphasisPosition", - "computed::TextEmphasisPosition::over_right()", + "computed::TextEmphasisPosition::DEFAULT", engines="gecko", - initial_specified_value="specified::TextEmphasisPosition::over_right()", + initial_specified_value="specified::TextEmphasisPosition::DEFAULT", animation_value_type="discrete", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position", )} diff --git a/servo/components/style/values/specified/text.rs b/servo/components/style/values/specified/text.rs index c436bc15d9d8..24d00e80af6a 100644 --- a/servo/components/style/values/specified/text.rs +++ b/servo/components/style/values/specified/text.rs @@ -772,146 +772,32 @@ impl Parse for TextEmphasisStyle { } } -/// The allowed horizontal values for the `text-emphasis-position` property. -#[derive( - Clone, - Copy, - Debug, - Eq, - MallocSizeOf, - Parse, - PartialEq, - SpecifiedValueInfo, - ToComputedValue, - ToCss, - ToResolvedValue, - ToShmem, -)] -pub enum TextEmphasisHorizontalWritingModeValue { - /// Draw marks over the text in horizontal writing mode. - Over, - /// Draw marks under the text in horizontal writing mode. - Under, +bitflags! { + #[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem, Parse, ToCss)] + #[repr(C)] + #[css(bitflags(mixed="over,under,left,right", validate_mixed="Self::is_valid"))] + /// Values for text-emphasis-position: + /// + pub struct TextEmphasisPosition: u8 { + /// Draws marks to the right of the text in vertical writing mode. + const OVER = 1 << 0; + /// Draw marks under the text in horizontal writing mode. + const UNDER = 1 << 1; + /// Draw marks to the left of the text in vertical writing mode. + 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; + } } -/// The allowed vertical values for the `text-emphasis-position` property. -#[derive( - Clone, - Copy, - Debug, - Eq, - MallocSizeOf, - Parse, - PartialEq, - SpecifiedValueInfo, - ToComputedValue, - ToCss, - ToResolvedValue, - ToShmem, -)] -pub enum TextEmphasisVerticalWritingModeValue { - /// Draws marks to the right of the text in vertical writing mode. - Right, - /// Draw marks to the left of the text in vertical writing mode. - Left, -} - -/// Specified value of `text-emphasis-position` property. -#[derive( - Clone, - Copy, - Debug, - MallocSizeOf, - PartialEq, - SpecifiedValueInfo, - ToComputedValue, - ToCss, - ToResolvedValue, - ToShmem, -)] -pub struct TextEmphasisPosition( - pub TextEmphasisHorizontalWritingModeValue, - pub TextEmphasisVerticalWritingModeValue, -); - impl TextEmphasisPosition { - #[inline] - /// Returns the initial value of `text-emphasis-position` - pub fn over_right() -> Self { - TextEmphasisPosition( - TextEmphasisHorizontalWritingModeValue::Over, - TextEmphasisVerticalWritingModeValue::Right, - ) - } - - #[cfg(feature = "gecko")] - /// Converts an enumerated value coming from Gecko to a `TextEmphasisPosition`. - pub fn from_gecko_keyword(kw: u32) -> Self { - use crate::gecko_bindings::structs; - - let vert = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT != 0 { - TextEmphasisVerticalWritingModeValue::Right - } else { - debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT != 0); - TextEmphasisVerticalWritingModeValue::Left - }; - let horiz = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER != 0 { - TextEmphasisHorizontalWritingModeValue::Over - } else { - debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER != 0); - TextEmphasisHorizontalWritingModeValue::Under - }; - TextEmphasisPosition(horiz, vert) - } -} - -impl Parse for TextEmphasisPosition { - fn parse<'i, 't>( - _context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - if let Ok(horizontal) = - input.try_parse(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) - { - let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; - Ok(TextEmphasisPosition(horizontal, vertical)) - } else { - let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; - let horizontal = TextEmphasisHorizontalWritingModeValue::parse(input)?; - Ok(TextEmphasisPosition(horizontal, vertical)) - } - } -} - -#[cfg(feature = "gecko")] -impl From for TextEmphasisPosition { - fn from(bits: u8) -> Self { - TextEmphasisPosition::from_gecko_keyword(bits as u32) - } -} - -#[cfg(feature = "gecko")] -impl From for u8 { - fn from(v: TextEmphasisPosition) -> u8 { - use crate::gecko_bindings::structs; - - let mut result = match v.0 { - TextEmphasisHorizontalWritingModeValue::Over => { - structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER - }, - TextEmphasisHorizontalWritingModeValue::Under => { - structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER - }, - }; - match v.1 { - TextEmphasisVerticalWritingModeValue::Right => { - result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT; - }, - TextEmphasisVerticalWritingModeValue::Left => { - result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT; - }, - }; - result as u8 + fn is_valid(self) -> bool { + return self.intersects(Self::LEFT) != self.intersects(Self::RIGHT) && + self.intersects(Self::OVER) != self.intersects(Self::UNDER); } } diff --git a/servo/components/style_derive/to_css.rs b/servo/components/style_derive/to_css.rs index e0f66da3773d..031b583b7944 100644 --- a/servo/components/style_derive/to_css.rs +++ b/servo/components/style_derive/to_css.rs @@ -322,24 +322,29 @@ fn derive_single_field_expr( } #[derive(Default, FromMeta)] +#[darling(default)] pub struct CssBitflagAttrs { /// Flags that can only go on their own, comma-separated. - pub single: String, + pub single: Option, /// Flags that can go mixed with each other, comma-separated. - pub mixed: String, + pub mixed: Option, /// Extra validation of the resulting mixed flags. - #[darling(default)] pub validate_mixed: Option, /// Whether there are overlapping bits we need to take care of when /// serializing. - #[darling(default)] pub overlapping_bits: bool, } impl CssBitflagAttrs { /// Returns a vector of (rust_name, css_name) of a given flag list. - fn names(s: &str) -> Vec<(String, String)> { - s.split(',').map(|css_name| (cg::to_scream_case(css_name), css_name.to_owned())).collect() + fn names(s: &Option) -> Vec<(String, String)> { + let s = match s { + Some(s) => s, + None => return vec![], + }; + s.split(',') + .map(|css_name| (cg::to_scream_case(css_name), css_name.to_owned())) + .collect() } pub fn single_flags(&self) -> Vec<(String, String)> { diff --git a/servo/ports/geckolib/cbindgen.toml b/servo/ports/geckolib/cbindgen.toml index 3e2c218c0ffb..81529aa39293 100644 --- a/servo/ports/geckolib/cbindgen.toml +++ b/servo/ports/geckolib/cbindgen.toml @@ -207,6 +207,7 @@ include = [ "SVGPaintKind", "GridTemplateComponent", "TextEmphasisStyle", + "TextEmphasisPosition", "VariantAlternatesList", "PaintOrder", "SVGPaintOrder", diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 72859c59c447..903341702a6b 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -5089,7 +5089,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue( use style::values::generics::box_::{VerticalAlign, VerticalAlignKeyword}; use style::values::generics::font::FontStyle; use style::values::specified::{ - table::CaptionSide, BorderStyle, Clear, Display, Float, TextAlign, + table::CaptionSide, BorderStyle, Clear, Display, Float, TextAlign, TextEmphasisPosition }; fn get_from_computed(value: u32) -> T @@ -5111,7 +5111,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue( Clear => get_from_computed::(value), VerticalAlign => VerticalAlign::Keyword(VerticalAlignKeyword::from_u32(value).unwrap()), TextAlign => get_from_computed::(value), - TextEmphasisPosition => longhands::text_emphasis_position::SpecifiedValue::from_gecko_keyword(value), + TextEmphasisPosition => TextEmphasisPosition::from_bits_truncate(value as u8), FontSize => { // We rely on Gecko passing in font-size values (0...7) here. longhands::font_size::SpecifiedValue::from_html_size(value as u8)