mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -206,93 +206,15 @@ ${helpers.predefined_type(
|
|||
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">
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
|
||||
#[derive(ToComputedValue, ToCss)]
|
||||
pub enum HorizontalWritingModeValue {
|
||||
Over,
|
||||
Under,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
|
||||
#[derive(ToComputedValue, ToCss)]
|
||||
pub enum VerticalWritingModeValue {
|
||||
Right,
|
||||
Left,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub struct SpecifiedValue(pub HorizontalWritingModeValue, pub VerticalWritingModeValue);
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = super::SpecifiedValue;
|
||||
}
|
||||
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
SpecifiedValue(HorizontalWritingModeValue::Over, VerticalWritingModeValue::Right)
|
||||
}
|
||||
|
||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
if let Ok(horizontal) = input.try(|input| HorizontalWritingModeValue::parse(input)) {
|
||||
let vertical = VerticalWritingModeValue::parse(input)?;
|
||||
Ok(SpecifiedValue(horizontal, vertical))
|
||||
} else {
|
||||
let vertical = VerticalWritingModeValue::parse(input)?;
|
||||
let horizontal = HorizontalWritingModeValue::parse(input)?;
|
||||
Ok(SpecifiedValue(horizontal, vertical))
|
||||
}
|
||||
}
|
||||
|
||||
% if product == "gecko":
|
||||
impl SpecifiedValue {
|
||||
pub fn from_gecko_keyword(kw: u32) -> Self {
|
||||
use gecko_bindings::structs;
|
||||
|
||||
let vert = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT != 0 {
|
||||
VerticalWritingModeValue::Right
|
||||
} else {
|
||||
debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT != 0);
|
||||
VerticalWritingModeValue::Left
|
||||
};
|
||||
let horiz = if kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER != 0 {
|
||||
HorizontalWritingModeValue::Over
|
||||
} else {
|
||||
debug_assert!(kw & structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER != 0);
|
||||
HorizontalWritingModeValue::Under
|
||||
};
|
||||
SpecifiedValue(horiz, vert)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u8> for SpecifiedValue {
|
||||
fn from(bits: u8) -> SpecifiedValue {
|
||||
SpecifiedValue::from_gecko_keyword(bits as u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SpecifiedValue> for u8 {
|
||||
fn from(v: SpecifiedValue) -> u8 {
|
||||
use gecko_bindings::structs;
|
||||
|
||||
let mut result = match v.0 {
|
||||
HorizontalWritingModeValue::Over => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER,
|
||||
HorizontalWritingModeValue::Under => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER,
|
||||
};
|
||||
match v.1 {
|
||||
VerticalWritingModeValue::Right => {
|
||||
result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT;
|
||||
}
|
||||
VerticalWritingModeValue::Left => {
|
||||
result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT;
|
||||
}
|
||||
};
|
||||
result as u8
|
||||
}
|
||||
}
|
||||
% endif
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type(
|
||||
"text-emphasis-position",
|
||||
"TextEmphasisPosition",
|
||||
"computed::TextEmphasisPosition::over_right()",
|
||||
initial_specified_value="specified::TextEmphasisPosition::over_right()",
|
||||
products="gecko",
|
||||
animation_value_type="discrete",
|
||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position",
|
||||
)}
|
||||
|
||||
${helpers.predefined_type(
|
||||
"text-emphasis-color",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue