mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Refactor text-emphasis-position
to use ${helpers.predefined_type(..)}
This commit is contained in:
parent
f7a495afa7
commit
8d5a2a9aeb
5 changed files with 113 additions and 89 deletions
|
@ -71,7 +71,8 @@ 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, TextEmphasisStyle};
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign};
|
||||
pub use self::text::{TextEmphasisStyle, TextEmphasisPosition};
|
||||
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||
pub use self::time::Time;
|
||||
pub use self::transform::{Rotate, Scale, TimingFunction, Transform};
|
||||
|
|
|
@ -666,6 +666,106 @@ impl Parse for TextEmphasisStyle {
|
|||
}
|
||||
}
|
||||
|
||||
/// The allowed horizontal values for the `text-emphasis-position` property.
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
|
||||
#[derive(ToComputedValue, ToCss)]
|
||||
pub enum TextEmphasisHorizontalWritingModeValue {
|
||||
/// Draw marks over the text in horizontal writing mode.
|
||||
Over,
|
||||
/// Draw marks under the text in horizontal writing mode.
|
||||
Under,
|
||||
}
|
||||
|
||||
/// The allowed vertical values for the `text-emphasis-position` property.
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
|
||||
#[derive(ToComputedValue, ToCss)]
|
||||
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, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
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 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<Self, ParseError<'i>> {
|
||||
if let Ok(horizontal) = input.try(|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<u8> for TextEmphasisPosition {
|
||||
fn from(bits: u8) -> Self {
|
||||
TextEmphasisPosition::from_gecko_keyword(bits as u32)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<TextEmphasisPosition> for u8 {
|
||||
fn from(v: TextEmphasisPosition) -> u8 {
|
||||
use 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
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `-moz-tab-size` property.
|
||||
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue