From 73113e28dd518a981ba10bd8accf8fe98bce147d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 6 Mar 2018 00:10:28 +0300 Subject: [PATCH 1/5] Move text-emphasis-style variables out of mako templates --- components/style/properties/gecko.mako.rs | 25 +-- .../longhand/inherited_text.mako.rs | 170 ++---------------- .../shorthand/inherited_text.mako.rs | 2 +- components/style/values/computed/mod.rs | 2 +- components/style/values/computed/text.rs | 15 +- components/style/values/specified/mod.rs | 2 +- components/style/values/specified/text.rs | 136 +++++++++++++- 7 files changed, 175 insertions(+), 177 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 5c3de4a501e..3ce5891bb73 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -4707,14 +4707,14 @@ fn static_assert() { ${impl_simple_type_with_conversion("text_emphasis_position")} - pub fn set_text_emphasis_style(&mut self, v: longhands::text_emphasis_style::computed_value::T) { - use properties::longhands::text_emphasis_style::computed_value::T; - use properties::longhands::text_emphasis_style::{FillMode, ShapeKeyword}; + pub fn set_text_emphasis_style(&mut self, v: values::computed::TextEmphasisStyle) { + use values::computed::TextEmphasisStyle; + use values::specified::text::{FillMode, ShapeKeyword}; self.clear_text_emphasis_style_if_string(); let (te, s) = match v { - T::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""), - T::Keyword(ref keyword) => { + TextEmphasisStyle::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""), + TextEmphasisStyle::Keyword(ref keyword) => { let fill = match keyword.fill { FillMode::Filled => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED, FillMode::Open => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN, @@ -4729,7 +4729,7 @@ fn static_assert() { (shape | fill, keyword.shape.char(keyword.fill)) }, - T::String(ref s) => { + TextEmphasisStyle::String(ref s) => { (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING, &**s) }, }; @@ -4750,16 +4750,17 @@ fn static_assert() { self.copy_text_emphasis_style_from(other) } - pub fn clone_text_emphasis_style(&self) -> longhands::text_emphasis_style::computed_value::T { - use properties::longhands::text_emphasis_style::computed_value::{T, KeywordValue}; - use properties::longhands::text_emphasis_style::{FillMode, ShapeKeyword}; + pub fn clone_text_emphasis_style(&self) -> values::computed::TextEmphasisStyle { + use values::computed::TextEmphasisStyle; + use values::specified::text::{FillMode, ShapeKeyword}; + use values::computed::text::{KeywordValue}; if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8 { - return T::None; + return TextEmphasisStyle::None; } if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING as u8 { - return T::String(self.gecko.mTextEmphasisStyleString.to_string()); + return TextEmphasisStyle::String(self.gecko.mTextEmphasisStyleString.to_string()); } let fill = @@ -4777,7 +4778,7 @@ fn static_assert() { _ => panic!("Unexpected value in style struct for text-emphasis-style property") }; - T::Keyword(KeywordValue { fill, shape }) + TextEmphasisStyle::Keyword(KeywordValue { fill, shape }) } ${impl_non_negative_length('_webkit_text_stroke_width', diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index b25b88cbcad..9e9c27ee72b 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -195,166 +195,16 @@ ${helpers.predefined_type( spec="https://drafts.csswg.org/css-text-decor-3/#text-shadow-property", )} -<%helpers:longhand name="text-emphasis-style" products="gecko" boxed="True" - animation_value_type="discrete" - spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style"> - use computed_values::writing_mode::T as WritingMode; - use unicode_segmentation::UnicodeSegmentation; - - pub mod computed_value { - #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] - #[cfg_attr(feature = "servo", derive(ToComputedValue))] - pub enum T { - Keyword(KeywordValue), - None, - String(String), - } - - #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] - pub struct KeywordValue { - pub fill: super::FillMode, - pub shape: super::ShapeKeyword, - } - } - - #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] - pub enum SpecifiedValue { - Keyword(KeywordValue), - None, - String(String), - } - - #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] - pub enum KeywordValue { - Fill(FillMode), - Shape(ShapeKeyword), - FillAndShape(FillMode, ShapeKeyword), - } - - impl KeywordValue { - fn fill(&self) -> Option { - match *self { - KeywordValue::Fill(fill) | - KeywordValue::FillAndShape(fill, _) => Some(fill), - _ => None, - } - } - - fn shape(&self) -> Option { - match *self { - KeywordValue::Shape(shape) | - KeywordValue::FillAndShape(_, shape) => Some(shape), - _ => None, - } - } - } - - #[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss)] - pub enum FillMode { - Filled, - Open, - } - - #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)] - pub enum ShapeKeyword { - Dot, - Circle, - DoubleCircle, - Triangle, - Sesame, - } - - impl ShapeKeyword { - pub fn char(&self, fill: FillMode) -> &str { - let fill = fill == FillMode::Filled; - match *self { - ShapeKeyword::Dot => if fill { "\u{2022}" } else { "\u{25e6}" }, - ShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, - ShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, - ShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, - ShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, - } - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T::None - } - - #[inline] - pub fn get_initial_specified_value() -> SpecifiedValue { - SpecifiedValue::None - } - - impl ToComputedValue for SpecifiedValue { - type ComputedValue = computed_value::T; - - #[inline] - fn to_computed_value(&self, context: &Context) -> computed_value::T { - match *self { - SpecifiedValue::Keyword(ref keyword) => { - let default_shape = if context.style().get_inheritedbox() - .clone_writing_mode() == WritingMode::HorizontalTb { - ShapeKeyword::Circle - } else { - ShapeKeyword::Sesame - }; - computed_value::T::Keyword(computed_value::KeywordValue { - fill: keyword.fill().unwrap_or(FillMode::Filled), - shape: keyword.shape().unwrap_or(default_shape), - }) - }, - SpecifiedValue::None => computed_value::T::None, - SpecifiedValue::String(ref s) => { - // Passing `true` to iterate over extended grapheme clusters, following - // recommendation at http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries - let string = s.graphemes(true).next().unwrap_or("").to_string(); - computed_value::T::String(string) - } - } - } - #[inline] - fn from_computed_value(computed: &computed_value::T) -> Self { - match *computed { - computed_value::T::Keyword(ref keyword) => - SpecifiedValue::Keyword(KeywordValue::FillAndShape(keyword.fill,keyword.shape)), - computed_value::T::None => SpecifiedValue::None, - computed_value::T::String(ref string) => SpecifiedValue::String(string.clone()) - } - } - } - - pub fn parse<'i, 't>( - _context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - if input.try(|input| input.expect_ident_matching("none")).is_ok() { - return Ok(SpecifiedValue::None); - } - - if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { - // Handle - return Ok(SpecifiedValue::String(s)); - } - - // Handle a pair of keywords - let mut shape = input.try(ShapeKeyword::parse).ok(); - let fill = input.try(FillMode::parse).ok(); - if shape.is_none() { - shape = input.try(ShapeKeyword::parse).ok(); - } - - // At least one of shape or fill must be handled - let keyword_value = match (fill, shape) { - (Some(fill), Some(shape)) => KeywordValue::FillAndShape(fill, shape), - (Some(fill), None) => KeywordValue::Fill(fill), - (None, Some(shape)) => KeywordValue::Shape(shape), - _ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), - }; - Ok(SpecifiedValue::Keyword(keyword_value)) - } - +${helpers.predefined_type( + "text-emphasis-style", + "TextEmphasisStyle", + None, + initial_specified_value="SpecifiedValue::None", + products="gecko", + boxed=True, + animation_value_type="discrete", + spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style", +)} <%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko" spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position"> diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index 95850f5c043..71359384697 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -33,7 +33,7 @@ if color.is_some() || style.is_some() { Ok(expanded! { text_emphasis_color: unwrap_or_initial!(text_emphasis_color, color), - text_emphasis_style: unwrap_or_initial!(text_emphasis_style, style), + text_emphasis_style: unwrap_or_initial!(text_emphasis_style, style), // TODO: what? }) } else { Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 1667f7ec8cf..335a28d647e 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -75,7 +75,7 @@ pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize}; -pub use self::text::{TextAlign, TextOverflow, WordSpacing}; +pub use self::text::{TextAlign, TextOverflow, WordSpacing, TextEmphasisStyle}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 011477ca781..37b38a75b55 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -15,7 +15,7 @@ use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::MozTabSize as GenericMozTabSize; use values::generics::text::Spacing; -use values::specified::text::{TextOverflowSide, TextDecorationLine}; +use values::specified::text::{TextOverflowSide, TextDecorationLine, FillMode, ShapeKeyword}; pub use values::specified::TextAlignKeyword as TextAlign; @@ -151,3 +151,16 @@ impl TextDecorationsInEffect { /// A specified value for the `-moz-tab-size` property. pub type MozTabSize = GenericMozTabSize; + +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] +pub enum TextEmphasisStyle { + Keyword(KeywordValue), + None, + String(String), +} + +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] +pub struct KeywordValue { + pub fill: FillMode, + pub shape: ShapeKeyword, +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 192c22a0a13..2d557b0e87d 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -71,7 +71,7 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; -pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign}; +pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign, TextEmphasisStyle}; pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform}; diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 1c18c833784..1559295eeec 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -11,7 +11,9 @@ use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use values::computed::{Context, ToComputedValue}; use values::computed::text::LineHeight as ComputedLineHeight; +use values::computed::text::TextEmphasisStyle as ComputedTextEmphasisStyle; use values::computed::text::TextOverflow as ComputedTextOverflow; +use values::computed::text::KeywordValue as ComputedKeywordValue; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::MozTabSize as GenericMozTabSize; @@ -19,6 +21,8 @@ use values::generics::text::Spacing; use values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number}; use values::specified::length::{FontRelativeLength, Length, LengthOrPercentage, NoCalcLength}; use values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; +use properties::longhands::writing_mode::computed_value::T as SpecifiedWritingMode; +use unicode_segmentation::UnicodeSegmentation; /// A specified type for the `initial-letter` property. pub type InitialLetter = GenericInitialLetter; @@ -420,7 +424,6 @@ pub enum TextAlign { /// unlike other values. #[cfg(feature = "gecko")] MozCenterOrInherit, - } impl Parse for TextAlign { @@ -515,6 +518,137 @@ impl ToComputedValue for TextAlign { } } +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] +#[cfg_attr(feature = "servo", derive(ToComputedValue))] +pub enum TextEmphasisStyle { + Keyword(KeywordValue), + None, + String(String), +} + +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] +pub enum KeywordValue { + Fill(FillMode), + Shape(ShapeKeyword), + FillAndShape(FillMode, ShapeKeyword), +} + +impl KeywordValue { + fn fill(&self) -> Option { + match *self { + KeywordValue::Fill(fill) | + KeywordValue::FillAndShape(fill, _) => Some(fill), + _ => None, + } + } + + fn shape(&self) -> Option { + match *self { + KeywordValue::Shape(shape) | + KeywordValue::FillAndShape(_, shape) => Some(shape), + _ => None, + } + } +} + +#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss)] +pub enum FillMode { + Filled, + Open, +} + +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)] +pub enum ShapeKeyword { + Dot, + Circle, + DoubleCircle, + Triangle, + Sesame, +} + +impl ShapeKeyword { + pub fn char(&self, fill: FillMode) -> &str { + let fill = fill == FillMode::Filled; + match *self { + ShapeKeyword::Dot => if fill { "\u{2022}" } else { "\u{25e6}" }, + ShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, + ShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, + ShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, + ShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, + } + } +} + +impl ToComputedValue for TextEmphasisStyle { + type ComputedValue = ComputedTextEmphasisStyle; + + #[inline] + fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { + match *self { + TextEmphasisStyle::Keyword(ref keyword) => { + let default_shape = if context.style().get_inheritedbox() + .clone_writing_mode() == SpecifiedWritingMode::HorizontalTb { + ShapeKeyword::Circle + } else { + ShapeKeyword::Sesame + }; + ComputedTextEmphasisStyle::Keyword(ComputedKeywordValue { + fill: keyword.fill().unwrap_or(FillMode::Filled), + shape: keyword.shape().unwrap_or(default_shape), + }) + }, + TextEmphasisStyle::None => ComputedTextEmphasisStyle::None, + TextEmphasisStyle::String(ref s) => { + // Passing `true` to iterate over extended grapheme clusters, following + // recommendation at http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries + let string = s.graphemes(true).next().unwrap_or("").to_string(); + ComputedTextEmphasisStyle::String(string) + } + } + } + #[inline] + fn from_computed_value(computed: &Self::ComputedValue) -> Self { + match *computed { + ComputedTextEmphasisStyle::Keyword(ref keyword) => + TextEmphasisStyle::Keyword(KeywordValue::FillAndShape(keyword.fill, keyword.shape)), + ComputedTextEmphasisStyle::None => TextEmphasisStyle::None, + ComputedTextEmphasisStyle::String(ref string) => TextEmphasisStyle::String(string.clone()) + } + } +} + +impl Parse for TextEmphasisStyle { + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + if input.try(|input| input.expect_ident_matching("none")).is_ok() { + return Ok(TextEmphasisStyle::None); + } + + if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { + // Handle + return Ok(TextEmphasisStyle::String(s)); + } + + // Handle a pair of keywords + let mut shape = input.try(ShapeKeyword::parse).ok(); + let fill = input.try(FillMode::parse).ok(); + if shape.is_none() { + shape = input.try(ShapeKeyword::parse).ok(); + } + + // At least one of shape or fill must be handled + let keyword_value = match (fill, shape) { + (Some(fill), Some(shape)) => KeywordValue::FillAndShape(fill, shape), + (Some(fill), None) => KeywordValue::Fill(fill), + (None, Some(shape)) => KeywordValue::Shape(shape), + _ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), + }; + Ok(TextEmphasisStyle::Keyword(keyword_value)) + } +} + /// A specified value for the `-moz-tab-size` property. pub type MozTabSize = GenericMozTabSize; From 6febdf3751d78f3997f9d0dafe94e8568ccea679 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 9 Mar 2018 00:01:41 +0300 Subject: [PATCH 2/5] Add docs for text-emphasis-property values --- components/style/values/computed/text.rs | 7 +++++++ components/style/values/specified/text.rs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 37b38a75b55..2238a5d6804 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -152,15 +152,22 @@ impl TextDecorationsInEffect { /// A specified value for the `-moz-tab-size` property. pub type MozTabSize = GenericMozTabSize; +/// computed value for the text-emphasis-style property #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] pub enum TextEmphasisStyle { + /// Keyword value for the text-emphasis-style property (`filled` `open`) Keyword(KeywordValue), + /// `none` None, + /// String (will be used only first character) for the text-emphasis-style property String(String), } +/// Keyword value for the text-emphasis-style property #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] pub struct KeywordValue { + /// fill for the text-emphasis-style property pub fill: FillMode, + /// shape for the text-emphasis-style property pub shape: ShapeKeyword, } diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 1559295eeec..23ea5ac4e34 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -518,18 +518,26 @@ impl ToComputedValue for TextAlign { } } +/// Specified value of text-emphasis-style property. #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] #[cfg_attr(feature = "servo", derive(ToComputedValue))] pub enum TextEmphasisStyle { + /// Keyword(KeywordValue), + /// `none` None, + /// String (will be used only first character) for the text-emphasis-style property String(String), } +/// Keyword value for the text-emphasis-style property #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] pub enum KeywordValue { + /// Fill(FillMode), + /// Shape(ShapeKeyword), + /// FillAndShape(FillMode, ShapeKeyword), } @@ -551,22 +559,32 @@ impl KeywordValue { } } +/// Fill mode for the text-emphasis-style property #[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss)] pub enum FillMode { + /// `filled` Filled, + /// `open` Open, } +/// Shape keyword for the text-emphasis-style property #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)] pub enum ShapeKeyword { + /// `dot` Dot, + /// `circle` Circle, + /// `double-circle` DoubleCircle, + /// `triangle` Triangle, + /// `sesame` Sesame, } impl ShapeKeyword { + /// converts fill mode to a unicode char pub fn char(&self, fill: FillMode) -> &str { let fill = fill == FillMode::Filled; match *self { From 47397758773cc42260f2dda7cddd7ddfd9224a20 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 9 Mar 2018 00:27:09 +0300 Subject: [PATCH 3/5] Remove duplicate derive for text emphasis style enum --- components/style/values/specified/text.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 23ea5ac4e34..48236907679 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -520,7 +520,6 @@ impl ToComputedValue for TextAlign { /// Specified value of text-emphasis-style property. #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] -#[cfg_attr(feature = "servo", derive(ToComputedValue))] pub enum TextEmphasisStyle { /// Keyword(KeywordValue), From acdb4df53b966ca05acf86d36c5d807e3027afce Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 9 Mar 2018 01:21:23 +0300 Subject: [PATCH 4/5] Fix test-tidy formatting errors --- components/style/values/specified/text.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 48236907679..31e30ada2f9 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -6,14 +6,16 @@ use cssparser::{Parser, Token}; use parser::{Parse, ParserContext}; +use properties::longhands::writing_mode::computed_value::T as SpecifiedWritingMode; use selectors::parser::SelectorParseErrorKind; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; +use unicode_segmentation::UnicodeSegmentation; use values::computed::{Context, ToComputedValue}; +use values::computed::text::KeywordValue as ComputedKeywordValue; use values::computed::text::LineHeight as ComputedLineHeight; use values::computed::text::TextEmphasisStyle as ComputedTextEmphasisStyle; use values::computed::text::TextOverflow as ComputedTextOverflow; -use values::computed::text::KeywordValue as ComputedKeywordValue; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::MozTabSize as GenericMozTabSize; @@ -21,8 +23,6 @@ use values::generics::text::Spacing; use values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number}; use values::specified::length::{FontRelativeLength, Length, LengthOrPercentage, NoCalcLength}; use values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; -use properties::longhands::writing_mode::computed_value::T as SpecifiedWritingMode; -use unicode_segmentation::UnicodeSegmentation; /// A specified type for the `initial-letter` property. pub type InitialLetter = GenericInitialLetter; @@ -588,10 +588,10 @@ impl ShapeKeyword { let fill = fill == FillMode::Filled; match *self { ShapeKeyword::Dot => if fill { "\u{2022}" } else { "\u{25e6}" }, - ShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, - ShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, - ShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, - ShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, + ShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, + ShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, + ShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, + ShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, } } } From a1dd888c2378f6bb1f0fa35850434305fbda8814 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 9 Mar 2018 20:21:18 +0300 Subject: [PATCH 5/5] Rename entities that belong to text-emphasis-style value. Fix order of imports --- components/style/properties/gecko.mako.rs | 34 ++++----- .../shorthand/inherited_text.mako.rs | 2 +- components/style/values/computed/mod.rs | 2 +- components/style/values/computed/text.rs | 12 ++-- components/style/values/specified/text.rs | 70 +++++++++---------- 5 files changed, 60 insertions(+), 60 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3ce5891bb73..5ec5e6d414f 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -4709,22 +4709,22 @@ fn static_assert() { pub fn set_text_emphasis_style(&mut self, v: values::computed::TextEmphasisStyle) { use values::computed::TextEmphasisStyle; - use values::specified::text::{FillMode, ShapeKeyword}; + use values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; self.clear_text_emphasis_style_if_string(); let (te, s) = match v { TextEmphasisStyle::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""), TextEmphasisStyle::Keyword(ref keyword) => { let fill = match keyword.fill { - FillMode::Filled => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED, - FillMode::Open => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN, + TextEmphasisFillMode::Filled => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED, + TextEmphasisFillMode::Open => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN, }; let shape = match keyword.shape { - ShapeKeyword::Dot => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT, - ShapeKeyword::Circle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE, - ShapeKeyword::DoubleCircle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE, - ShapeKeyword::Triangle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE, - ShapeKeyword::Sesame => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME, + TextEmphasisShapeKeyword::Dot => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT, + TextEmphasisShapeKeyword::Circle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE, + TextEmphasisShapeKeyword::DoubleCircle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE, + TextEmphasisShapeKeyword::Triangle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE, + TextEmphasisShapeKeyword::Sesame => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME, }; (shape | fill, keyword.shape.char(keyword.fill)) @@ -4752,8 +4752,8 @@ fn static_assert() { pub fn clone_text_emphasis_style(&self) -> values::computed::TextEmphasisStyle { use values::computed::TextEmphasisStyle; - use values::specified::text::{FillMode, ShapeKeyword}; - use values::computed::text::{KeywordValue}; + use values::computed::text::TextEmphasisKeywordValue; + use values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8 { return TextEmphasisStyle::None; @@ -4766,19 +4766,19 @@ fn static_assert() { let fill = self.gecko.mTextEmphasisStyle & structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN as u8 == 0; - let fill = if fill { FillMode::Filled } else { FillMode::Open }; + let fill = if fill { TextEmphasisFillMode::Filled } else { TextEmphasisFillMode::Open }; let shape = match self.gecko.mTextEmphasisStyle as u32 & !structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN { - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT => ShapeKeyword::Dot, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE => ShapeKeyword::Circle, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE => ShapeKeyword::DoubleCircle, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE => ShapeKeyword::Triangle, - structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME => ShapeKeyword::Sesame, + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT => TextEmphasisShapeKeyword::Dot, + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE => TextEmphasisShapeKeyword::Circle, + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE => TextEmphasisShapeKeyword::DoubleCircle, + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE => TextEmphasisShapeKeyword::Triangle, + structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME => TextEmphasisShapeKeyword::Sesame, _ => panic!("Unexpected value in style struct for text-emphasis-style property") }; - TextEmphasisStyle::Keyword(KeywordValue { fill, shape }) + TextEmphasisStyle::Keyword(TextEmphasisKeywordValue { fill, shape }) } ${impl_non_negative_length('_webkit_text_stroke_width', diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index 71359384697..95850f5c043 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -33,7 +33,7 @@ if color.is_some() || style.is_some() { Ok(expanded! { text_emphasis_color: unwrap_or_initial!(text_emphasis_color, color), - text_emphasis_style: unwrap_or_initial!(text_emphasis_style, style), // TODO: what? + text_emphasis_style: unwrap_or_initial!(text_emphasis_style, style), }) } else { Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 335a28d647e..a24ebc5073c 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -75,7 +75,7 @@ pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize}; -pub use self::text::{TextAlign, TextOverflow, WordSpacing, TextEmphasisStyle}; +pub use self::text::{TextAlign, TextEmphasisStyle, TextOverflow, WordSpacing}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 2238a5d6804..bbef98ae4bd 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -15,7 +15,7 @@ use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; use values::generics::text::MozTabSize as GenericMozTabSize; use values::generics::text::Spacing; -use values::specified::text::{TextOverflowSide, TextDecorationLine, FillMode, ShapeKeyword}; +use values::specified::text::{TextDecorationLine, TextEmphasisFillMode, TextEmphasisShapeKeyword, TextOverflowSide}; pub use values::specified::TextAlignKeyword as TextAlign; @@ -156,18 +156,18 @@ pub type MozTabSize = GenericMozTabSize; #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] pub enum TextEmphasisStyle { /// Keyword value for the text-emphasis-style property (`filled` `open`) - Keyword(KeywordValue), + Keyword(TextEmphasisKeywordValue), /// `none` None, - /// String (will be used only first character) for the text-emphasis-style property + /// String (will be used only first grapheme cluster) for the text-emphasis-style property String(String), } /// Keyword value for the text-emphasis-style property #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] -pub struct KeywordValue { +pub struct TextEmphasisKeywordValue { /// fill for the text-emphasis-style property - pub fill: FillMode, + pub fill: TextEmphasisFillMode, /// shape for the text-emphasis-style property - pub shape: ShapeKeyword, + pub shape: TextEmphasisShapeKeyword, } diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 31e30ada2f9..fcb15650110 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -12,8 +12,8 @@ use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use unicode_segmentation::UnicodeSegmentation; use values::computed::{Context, ToComputedValue}; -use values::computed::text::KeywordValue as ComputedKeywordValue; use values::computed::text::LineHeight as ComputedLineHeight; +use values::computed::text::TextEmphasisKeywordValue as ComputedTextEmphasisKeywordValue; use values::computed::text::TextEmphasisStyle as ComputedTextEmphasisStyle; use values::computed::text::TextOverflow as ComputedTextOverflow; use values::generics::text::InitialLetter as GenericInitialLetter; @@ -522,37 +522,37 @@ impl ToComputedValue for TextAlign { #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] pub enum TextEmphasisStyle { /// - Keyword(KeywordValue), + Keyword(TextEmphasisKeywordValue), /// `none` None, - /// String (will be used only first character) for the text-emphasis-style property + /// String (will be used only first grapheme cluster) for the text-emphasis-style property String(String), } /// Keyword value for the text-emphasis-style property #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] -pub enum KeywordValue { +pub enum TextEmphasisKeywordValue { /// - Fill(FillMode), + Fill(TextEmphasisFillMode), /// - Shape(ShapeKeyword), + Shape(TextEmphasisShapeKeyword), /// - FillAndShape(FillMode, ShapeKeyword), + FillAndShape(TextEmphasisFillMode, TextEmphasisShapeKeyword), } -impl KeywordValue { - fn fill(&self) -> Option { +impl TextEmphasisKeywordValue { + fn fill(&self) -> Option { match *self { - KeywordValue::Fill(fill) | - KeywordValue::FillAndShape(fill, _) => Some(fill), + TextEmphasisKeywordValue::Fill(fill) | + TextEmphasisKeywordValue::FillAndShape(fill, _) => Some(fill), _ => None, } } - fn shape(&self) -> Option { + fn shape(&self) -> Option { match *self { - KeywordValue::Shape(shape) | - KeywordValue::FillAndShape(_, shape) => Some(shape), + TextEmphasisKeywordValue::Shape(shape) | + TextEmphasisKeywordValue::FillAndShape(_, shape) => Some(shape), _ => None, } } @@ -560,7 +560,7 @@ impl KeywordValue { /// Fill mode for the text-emphasis-style property #[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss)] -pub enum FillMode { +pub enum TextEmphasisFillMode { /// `filled` Filled, /// `open` @@ -569,7 +569,7 @@ pub enum FillMode { /// Shape keyword for the text-emphasis-style property #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)] -pub enum ShapeKeyword { +pub enum TextEmphasisShapeKeyword { /// `dot` Dot, /// `circle` @@ -582,16 +582,16 @@ pub enum ShapeKeyword { Sesame, } -impl ShapeKeyword { +impl TextEmphasisShapeKeyword { /// converts fill mode to a unicode char - pub fn char(&self, fill: FillMode) -> &str { - let fill = fill == FillMode::Filled; + pub fn char(&self, fill: TextEmphasisFillMode) -> &str { + let fill = fill == TextEmphasisFillMode::Filled; match *self { - ShapeKeyword::Dot => if fill { "\u{2022}" } else { "\u{25e6}" }, - ShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, - ShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, - ShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, - ShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, + TextEmphasisShapeKeyword::Dot => if fill { "\u{2022}" } else { "\u{25e6}" }, + TextEmphasisShapeKeyword::Circle => if fill { "\u{25cf}" } else { "\u{25cb}" }, + TextEmphasisShapeKeyword::DoubleCircle => if fill { "\u{25c9}" } else { "\u{25ce}" }, + TextEmphasisShapeKeyword::Triangle => if fill { "\u{25b2}" } else { "\u{25b3}" }, + TextEmphasisShapeKeyword::Sesame => if fill { "\u{fe45}" } else { "\u{fe46}" }, } } } @@ -605,12 +605,12 @@ impl ToComputedValue for TextEmphasisStyle { TextEmphasisStyle::Keyword(ref keyword) => { let default_shape = if context.style().get_inheritedbox() .clone_writing_mode() == SpecifiedWritingMode::HorizontalTb { - ShapeKeyword::Circle + TextEmphasisShapeKeyword::Circle } else { - ShapeKeyword::Sesame + TextEmphasisShapeKeyword::Sesame }; - ComputedTextEmphasisStyle::Keyword(ComputedKeywordValue { - fill: keyword.fill().unwrap_or(FillMode::Filled), + ComputedTextEmphasisStyle::Keyword(ComputedTextEmphasisKeywordValue { + fill: keyword.fill().unwrap_or(TextEmphasisFillMode::Filled), shape: keyword.shape().unwrap_or(default_shape), }) }, @@ -627,7 +627,7 @@ impl ToComputedValue for TextEmphasisStyle { fn from_computed_value(computed: &Self::ComputedValue) -> Self { match *computed { ComputedTextEmphasisStyle::Keyword(ref keyword) => - TextEmphasisStyle::Keyword(KeywordValue::FillAndShape(keyword.fill, keyword.shape)), + TextEmphasisStyle::Keyword(TextEmphasisKeywordValue::FillAndShape(keyword.fill, keyword.shape)), ComputedTextEmphasisStyle::None => TextEmphasisStyle::None, ComputedTextEmphasisStyle::String(ref string) => TextEmphasisStyle::String(string.clone()) } @@ -649,17 +649,17 @@ impl Parse for TextEmphasisStyle { } // Handle a pair of keywords - let mut shape = input.try(ShapeKeyword::parse).ok(); - let fill = input.try(FillMode::parse).ok(); + let mut shape = input.try(TextEmphasisShapeKeyword::parse).ok(); + let fill = input.try(TextEmphasisFillMode::parse).ok(); if shape.is_none() { - shape = input.try(ShapeKeyword::parse).ok(); + shape = input.try(TextEmphasisShapeKeyword::parse).ok(); } // At least one of shape or fill must be handled let keyword_value = match (fill, shape) { - (Some(fill), Some(shape)) => KeywordValue::FillAndShape(fill, shape), - (Some(fill), None) => KeywordValue::Fill(fill), - (None, Some(shape)) => KeywordValue::Shape(shape), + (Some(fill), Some(shape)) => TextEmphasisKeywordValue::FillAndShape(fill, shape), + (Some(fill), None) => TextEmphasisKeywordValue::Fill(fill), + (None, Some(shape)) => TextEmphasisKeywordValue::Shape(shape), _ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), }; Ok(TextEmphasisStyle::Keyword(keyword_value))