mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
style: Convert text-emphasis-position #defines to enum classes
Differential Revision: https://phabricator.services.mozilla.com/D155557
This commit is contained in:
parent
6cfdd989d5
commit
1a9198a5ef
3 changed files with 36 additions and 145 deletions
|
@ -221,9 +221,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",
|
||||
)}
|
||||
|
|
|
@ -771,146 +771,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:
|
||||
/// <https://drafts.csswg.org/css-text-decor/#text-emphasis-position-property>
|
||||
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<Self, ParseError<'i>> {
|
||||
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<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 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -328,24 +328,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<String>,
|
||||
/// Flags that can go mixed with each other, comma-separated.
|
||||
pub mixed: String,
|
||||
pub mixed: Option<String>,
|
||||
/// Extra validation of the resulting mixed flags.
|
||||
#[darling(default)]
|
||||
pub validate_mixed: Option<Path>,
|
||||
/// 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<String>) -> 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)> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue