mirror of
https://github.com/servo/servo.git
synced 2025-06-19 14:48:59 +01:00
Auto merge of #20252 - NeverHappened:extract_text_emphasis_style, r=upsuper
Extract text emphasis style <!-- Please describe your changes on the following line: --> Extracted the text-emphasis-style property out of the inherited_text.mako.rs. This is a part of #19015 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] `./mach cargo-geckolib check` does not report any errors - [X] These changes fix #19940 (github issue number if applicable). <!-- Either: --> - [X] These changes do not require tests because it's a refactoring <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20252) <!-- Reviewable:end -->
This commit is contained in:
commit
aa8fb3a204
6 changed files with 211 additions and 189 deletions
|
@ -4707,29 +4707,29 @@ fn static_assert() {
|
||||||
|
|
||||||
${impl_simple_type_with_conversion("text_emphasis_position")}
|
${impl_simple_type_with_conversion("text_emphasis_position")}
|
||||||
|
|
||||||
pub fn set_text_emphasis_style(&mut self, v: longhands::text_emphasis_style::computed_value::T) {
|
pub fn set_text_emphasis_style(&mut self, v: values::computed::TextEmphasisStyle) {
|
||||||
use properties::longhands::text_emphasis_style::computed_value::T;
|
use values::computed::TextEmphasisStyle;
|
||||||
use properties::longhands::text_emphasis_style::{FillMode, ShapeKeyword};
|
use values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
|
||||||
|
|
||||||
self.clear_text_emphasis_style_if_string();
|
self.clear_text_emphasis_style_if_string();
|
||||||
let (te, s) = match v {
|
let (te, s) = match v {
|
||||||
T::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""),
|
TextEmphasisStyle::None => (structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE, ""),
|
||||||
T::Keyword(ref keyword) => {
|
TextEmphasisStyle::Keyword(ref keyword) => {
|
||||||
let fill = match keyword.fill {
|
let fill = match keyword.fill {
|
||||||
FillMode::Filled => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED,
|
TextEmphasisFillMode::Filled => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED,
|
||||||
FillMode::Open => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN,
|
TextEmphasisFillMode::Open => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN,
|
||||||
};
|
};
|
||||||
let shape = match keyword.shape {
|
let shape = match keyword.shape {
|
||||||
ShapeKeyword::Dot => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT,
|
TextEmphasisShapeKeyword::Dot => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOT,
|
||||||
ShapeKeyword::Circle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE,
|
TextEmphasisShapeKeyword::Circle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE,
|
||||||
ShapeKeyword::DoubleCircle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE,
|
TextEmphasisShapeKeyword::DoubleCircle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE,
|
||||||
ShapeKeyword::Triangle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE,
|
TextEmphasisShapeKeyword::Triangle => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE,
|
||||||
ShapeKeyword::Sesame => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME,
|
TextEmphasisShapeKeyword::Sesame => structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
(shape | fill, keyword.shape.char(keyword.fill))
|
(shape | fill, keyword.shape.char(keyword.fill))
|
||||||
},
|
},
|
||||||
T::String(ref s) => {
|
TextEmphasisStyle::String(ref s) => {
|
||||||
(structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING, &**s)
|
(structs::NS_STYLE_TEXT_EMPHASIS_STYLE_STRING, &**s)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -4750,34 +4750,35 @@ fn static_assert() {
|
||||||
self.copy_text_emphasis_style_from(other)
|
self.copy_text_emphasis_style_from(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_text_emphasis_style(&self) -> longhands::text_emphasis_style::computed_value::T {
|
pub fn clone_text_emphasis_style(&self) -> values::computed::TextEmphasisStyle {
|
||||||
use properties::longhands::text_emphasis_style::computed_value::{T, KeywordValue};
|
use values::computed::TextEmphasisStyle;
|
||||||
use properties::longhands::text_emphasis_style::{FillMode, ShapeKeyword};
|
use values::computed::text::TextEmphasisKeywordValue;
|
||||||
|
use values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
|
||||||
|
|
||||||
if self.gecko.mTextEmphasisStyle == structs::NS_STYLE_TEXT_EMPHASIS_STYLE_NONE as u8 {
|
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 {
|
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 =
|
let fill =
|
||||||
self.gecko.mTextEmphasisStyle & structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN as u8 == 0;
|
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 =
|
let shape =
|
||||||
match self.gecko.mTextEmphasisStyle as u32 & !structs::NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN {
|
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_DOT => TextEmphasisShapeKeyword::Dot,
|
||||||
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE => ShapeKeyword::Circle,
|
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_CIRCLE => TextEmphasisShapeKeyword::Circle,
|
||||||
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE => ShapeKeyword::DoubleCircle,
|
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_DOUBLE_CIRCLE => TextEmphasisShapeKeyword::DoubleCircle,
|
||||||
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE => ShapeKeyword::Triangle,
|
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_TRIANGLE => TextEmphasisShapeKeyword::Triangle,
|
||||||
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME => ShapeKeyword::Sesame,
|
structs::NS_STYLE_TEXT_EMPHASIS_STYLE_SESAME => TextEmphasisShapeKeyword::Sesame,
|
||||||
_ => panic!("Unexpected value in style struct for text-emphasis-style property")
|
_ => panic!("Unexpected value in style struct for text-emphasis-style property")
|
||||||
};
|
};
|
||||||
|
|
||||||
T::Keyword(KeywordValue { fill, shape })
|
TextEmphasisStyle::Keyword(TextEmphasisKeywordValue { fill, shape })
|
||||||
}
|
}
|
||||||
|
|
||||||
${impl_non_negative_length('_webkit_text_stroke_width',
|
${impl_non_negative_length('_webkit_text_stroke_width',
|
||||||
|
|
|
@ -195,166 +195,16 @@ ${helpers.predefined_type(
|
||||||
spec="https://drafts.csswg.org/css-text-decor-3/#text-shadow-property",
|
spec="https://drafts.csswg.org/css-text-decor-3/#text-shadow-property",
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<%helpers:longhand name="text-emphasis-style" products="gecko" boxed="True"
|
${helpers.predefined_type(
|
||||||
animation_value_type="discrete"
|
"text-emphasis-style",
|
||||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style">
|
"TextEmphasisStyle",
|
||||||
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,
|
None,
|
||||||
String(String),
|
initial_specified_value="SpecifiedValue::None",
|
||||||
}
|
products="gecko",
|
||||||
|
boxed=True,
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
animation_value_type="discrete",
|
||||||
pub struct KeywordValue {
|
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style",
|
||||||
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<FillMode> {
|
|
||||||
match *self {
|
|
||||||
KeywordValue::Fill(fill) |
|
|
||||||
KeywordValue::FillAndShape(fill, _) => Some(fill),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn shape(&self) -> Option<ShapeKeyword> {
|
|
||||||
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<SpecifiedValue, ParseError<'i>> {
|
|
||||||
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 <string>
|
|
||||||
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:longhand>
|
|
||||||
|
|
||||||
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
|
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
|
||||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
|
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||||
pub use self::svg::MozContextProperties;
|
pub use self::svg::MozContextProperties;
|
||||||
pub use self::table::XSpan;
|
pub use self::table::XSpan;
|
||||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize};
|
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize};
|
||||||
pub use self::text::{TextAlign, TextOverflow, WordSpacing};
|
pub use self::text::{TextAlign, TextEmphasisStyle, TextOverflow, WordSpacing};
|
||||||
pub use self::time::Time;
|
pub use self::time::Time;
|
||||||
pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation};
|
pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation};
|
||||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||||
|
|
|
@ -15,7 +15,7 @@ use values::generics::text::InitialLetter as GenericInitialLetter;
|
||||||
use values::generics::text::LineHeight as GenericLineHeight;
|
use values::generics::text::LineHeight as GenericLineHeight;
|
||||||
use values::generics::text::MozTabSize as GenericMozTabSize;
|
use values::generics::text::MozTabSize as GenericMozTabSize;
|
||||||
use values::generics::text::Spacing;
|
use values::generics::text::Spacing;
|
||||||
use values::specified::text::{TextOverflowSide, TextDecorationLine};
|
use values::specified::text::{TextDecorationLine, TextEmphasisFillMode, TextEmphasisShapeKeyword, TextOverflowSide};
|
||||||
|
|
||||||
pub use values::specified::TextAlignKeyword as TextAlign;
|
pub use values::specified::TextAlignKeyword as TextAlign;
|
||||||
|
|
||||||
|
@ -151,3 +151,23 @@ impl TextDecorationsInEffect {
|
||||||
|
|
||||||
/// A specified value for the `-moz-tab-size` property.
|
/// A specified value for the `-moz-tab-size` property.
|
||||||
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
||||||
|
|
||||||
|
/// 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(TextEmphasisKeywordValue),
|
||||||
|
/// `none`
|
||||||
|
None,
|
||||||
|
/// 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 TextEmphasisKeywordValue {
|
||||||
|
/// fill for the text-emphasis-style property
|
||||||
|
pub fill: TextEmphasisFillMode,
|
||||||
|
/// shape for the text-emphasis-style property
|
||||||
|
pub shape: TextEmphasisShapeKeyword,
|
||||||
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||||
pub use self::svg::MozContextProperties;
|
pub use self::svg::MozContextProperties;
|
||||||
pub use self::table::XSpan;
|
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::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||||
pub use self::time::Time;
|
pub use self::time::Time;
|
||||||
pub use self::transform::{Rotate, Scale, TimingFunction, Transform};
|
pub use self::transform::{Rotate, Scale, TimingFunction, Transform};
|
||||||
|
|
|
@ -6,11 +6,15 @@
|
||||||
|
|
||||||
use cssparser::{Parser, Token};
|
use cssparser::{Parser, Token};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
|
use properties::longhands::writing_mode::computed_value::T as SpecifiedWritingMode;
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::computed::{Context, ToComputedValue};
|
||||||
use values::computed::text::LineHeight as ComputedLineHeight;
|
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::computed::text::TextOverflow as ComputedTextOverflow;
|
||||||
use values::generics::text::InitialLetter as GenericInitialLetter;
|
use values::generics::text::InitialLetter as GenericInitialLetter;
|
||||||
use values::generics::text::LineHeight as GenericLineHeight;
|
use values::generics::text::LineHeight as GenericLineHeight;
|
||||||
|
@ -420,7 +424,6 @@ pub enum TextAlign {
|
||||||
/// unlike other values.
|
/// unlike other values.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
MozCenterOrInherit,
|
MozCenterOrInherit,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for TextAlign {
|
impl Parse for TextAlign {
|
||||||
|
@ -515,6 +518,154 @@ impl ToComputedValue for TextAlign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specified value of text-emphasis-style property.
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
pub enum TextEmphasisStyle {
|
||||||
|
/// <fill> <shape>
|
||||||
|
Keyword(TextEmphasisKeywordValue),
|
||||||
|
/// `none`
|
||||||
|
None,
|
||||||
|
/// 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 TextEmphasisKeywordValue {
|
||||||
|
/// <fill>
|
||||||
|
Fill(TextEmphasisFillMode),
|
||||||
|
/// <shape>
|
||||||
|
Shape(TextEmphasisShapeKeyword),
|
||||||
|
/// <fill> <shape>
|
||||||
|
FillAndShape(TextEmphasisFillMode, TextEmphasisShapeKeyword),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextEmphasisKeywordValue {
|
||||||
|
fn fill(&self) -> Option<TextEmphasisFillMode> {
|
||||||
|
match *self {
|
||||||
|
TextEmphasisKeywordValue::Fill(fill) |
|
||||||
|
TextEmphasisKeywordValue::FillAndShape(fill, _) => Some(fill),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shape(&self) -> Option<TextEmphasisShapeKeyword> {
|
||||||
|
match *self {
|
||||||
|
TextEmphasisKeywordValue::Shape(shape) |
|
||||||
|
TextEmphasisKeywordValue::FillAndShape(_, shape) => Some(shape),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fill mode for the text-emphasis-style property
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss)]
|
||||||
|
pub enum TextEmphasisFillMode {
|
||||||
|
/// `filled`
|
||||||
|
Filled,
|
||||||
|
/// `open`
|
||||||
|
Open,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shape keyword for the text-emphasis-style property
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
|
||||||
|
pub enum TextEmphasisShapeKeyword {
|
||||||
|
/// `dot`
|
||||||
|
Dot,
|
||||||
|
/// `circle`
|
||||||
|
Circle,
|
||||||
|
/// `double-circle`
|
||||||
|
DoubleCircle,
|
||||||
|
/// `triangle`
|
||||||
|
Triangle,
|
||||||
|
/// `sesame`
|
||||||
|
Sesame,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextEmphasisShapeKeyword {
|
||||||
|
/// converts fill mode to a unicode char
|
||||||
|
pub fn char(&self, fill: TextEmphasisFillMode) -> &str {
|
||||||
|
let fill = fill == TextEmphasisFillMode::Filled;
|
||||||
|
match *self {
|
||||||
|
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}" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
TextEmphasisShapeKeyword::Circle
|
||||||
|
} else {
|
||||||
|
TextEmphasisShapeKeyword::Sesame
|
||||||
|
};
|
||||||
|
ComputedTextEmphasisStyle::Keyword(ComputedTextEmphasisKeywordValue {
|
||||||
|
fill: keyword.fill().unwrap_or(TextEmphasisFillMode::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(TextEmphasisKeywordValue::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<Self, ParseError<'i>> {
|
||||||
|
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 <string>
|
||||||
|
return Ok(TextEmphasisStyle::String(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle a pair of keywords
|
||||||
|
let mut shape = input.try(TextEmphasisShapeKeyword::parse).ok();
|
||||||
|
let fill = input.try(TextEmphasisFillMode::parse).ok();
|
||||||
|
if shape.is_none() {
|
||||||
|
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)) => 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A specified value for the `-moz-tab-size` property.
|
/// A specified value for the `-moz-tab-size` property.
|
||||||
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue