style: Make all keywords CamelCase for consistency.

This prevents confusion and paves the ground for derive(Parse) of them.
This commit is contained in:
Emilio Cobos Álvarez 2017-12-05 22:13:50 +01:00
parent 37cd870a9e
commit af879523ea
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
60 changed files with 921 additions and 836 deletions

View file

@ -5,7 +5,7 @@
// `data` comes from components/style/properties.mako.rs; see build.rs for more details.
<%!
from data import to_rust_ident, to_camel_case, to_camel_case_lower
from data import to_camel_case, to_camel_case_lower
from data import Keyword
%>
<%namespace name="helpers" file="/helpers.mako.rs" />
@ -258,7 +258,7 @@ impl ComputedValuesInner {
#[inline]
pub fn is_display_contents(&self) -> bool {
self.get_box().clone_display() == longhands::display::computed_value::T::contents
self.get_box().clone_display() == longhands::display::computed_value::T::Contents
}
/// Returns true if the value of the `content` property would make a
@ -404,7 +404,7 @@ def set_gecko_property(ffi_name, expr):
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
let result = match v {
% for value in keyword.values_for('gecko'):
Keyword::${to_rust_ident(value)} =>
Keyword::${to_camel_case(value)} =>
structs::${keyword.gecko_constant(value)} ${keyword.maybe_cast(cast_type)},
% endfor
};
@ -437,7 +437,7 @@ def set_gecko_property(ffi_name, expr):
match ${get_gecko_property(gecko_ffi_name)} as ${cast_type} {
% for value in keyword.values_for('gecko'):
${keyword.casted_constant_name(value, cast_type)} => Keyword::${to_rust_ident(value)},
${keyword.casted_constant_name(value, cast_type)} => Keyword::${to_camel_case(value)},
% endfor
% if keyword.gecko_inexhaustive:
x => panic!("Found unexpected value in style struct for ${ident} property: {:?}", x),
@ -446,7 +446,7 @@ def set_gecko_property(ffi_name, expr):
% else:
match ${get_gecko_property(gecko_ffi_name)} {
% for value in keyword.values_for('gecko'):
structs::${keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)},
structs::${keyword.gecko_constant(value)} => Keyword::${to_camel_case(value)},
% endfor
% if keyword.gecko_inexhaustive:
x => panic!("Found unexpected value in style struct for ${ident} property: {:?}", x),
@ -2348,7 +2348,7 @@ fn static_assert() {
// cast + static_asserts
let result = match v {
% for value in border_style_keyword.values_for('gecko'):
Either::Second(border_style::T::${to_rust_ident(value)}) =>
Either::Second(border_style::T::${to_camel_case(value)}) =>
structs::${border_style_keyword.gecko_constant(value)} ${border_style_keyword.maybe_cast("u8")},
% endfor
Either::First(Auto) =>
@ -2377,7 +2377,9 @@ fn static_assert() {
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match ${get_gecko_property("mOutlineStyle")} ${border_style_keyword.maybe_cast("u32")} {
% for value in border_style_keyword.values_for('gecko'):
structs::${border_style_keyword.gecko_constant(value)} => Either::Second(border_style::T::${value}),
structs::${border_style_keyword.gecko_constant(value)} => {
Either::Second(border_style::T::${to_camel_case(value)})
},
% endfor
structs::${border_style_keyword.gecko_constant('auto')} => Either::First(Auto),
% if border_style_keyword.gecko_inexhaustive:
@ -3065,7 +3067,7 @@ fn static_assert() {
for (gecko, servo) in self.gecko.mAnimations.iter_mut().zip(v.cycle()) {
let result = match servo {
% for value in keyword.gecko_values():
Keyword::${to_rust_ident(value)} =>
Keyword::${to_camel_case(value)} =>
structs::${keyword.gecko_constant(value)} ${keyword.maybe_cast(cast_type)},
% endfor
};
@ -3078,7 +3080,7 @@ fn static_assert() {
use properties::longhands::animation_${ident}::single_value::computed_value::T as Keyword;
match self.gecko.mAnimations[index].m${gecko_ffi_name} ${keyword.maybe_cast("u32")} {
% for value in keyword.gecko_values():
structs::${keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)},
structs::${keyword.gecko_constant(value)} => Keyword::${to_camel_case(value)},
% endfor
x => panic!("Found unexpected value for animation-${ident}: {:?}", x),
}
@ -3121,7 +3123,7 @@ fn static_assert() {
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
let result = match v {
% for value in display_keyword.values_for('gecko'):
Keyword::${to_rust_ident(value)} =>
Keyword::${to_camel_case(value)} =>
structs::${display_keyword.gecko_constant(value)},
% endfor
};
@ -3138,7 +3140,7 @@ fn static_assert() {
use properties::longhands::display::computed_value::T as Keyword;
let result = match v {
% for value in display_keyword.values_for('gecko'):
Keyword::${to_rust_ident(value)} =>
Keyword::${to_camel_case(value)} =>
structs::${display_keyword.gecko_constant(value)},
% endfor
};
@ -3162,7 +3164,7 @@ fn static_assert() {
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
self.gecko.mOverflowY = match v {
% for value in overflow_x.keyword.values_for('gecko'):
BaseType::${to_rust_ident(value)} => structs::${overflow_x.keyword.gecko_constant(value)} as u8,
BaseType::${to_camel_case(value)} => structs::${overflow_x.keyword.gecko_constant(value)} as u8,
% endfor
};
}
@ -3172,7 +3174,7 @@ fn static_assert() {
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match self.gecko.mOverflowY as u32 {
% for value in overflow_x.keyword.values_for('gecko'):
structs::${overflow_x.keyword.gecko_constant(value)} => BaseType::${to_rust_ident(value)},
structs::${overflow_x.keyword.gecko_constant(value)} => BaseType::${to_camel_case(value)},
% endfor
x => panic!("Found unexpected value in style struct for overflow_y property: {}", x),
}
@ -3228,11 +3230,11 @@ fn static_assert() {
use computed_values::page_break_${kind}::T;
let result = match v {
T::auto => false,
T::always => true,
T::avoid => false,
T::left => true,
T::right => true
T::Auto => false,
T::Always => true,
T::Avoid => false,
T::Left => true,
T::Right => true
};
self.gecko.mBreak${kind.title()} = result;
}
@ -3244,10 +3246,7 @@ fn static_assert() {
pub fn clone_page_break_${kind}(&self) -> longhands::page_break_${kind}::computed_value::T {
use computed_values::page_break_${kind}::T;
match self.gecko.mBreak${kind.title()} {
true => T::always,
false => T::auto,
}
if self.gecko.mBreak${kind.title()} { T::Always } else { T::Auto }
}
% endfor
@ -3776,7 +3775,7 @@ fn static_assert() {
geckolayer.${field_name} = {
match servo {
% for value in keyword.values_for("gecko"):
Keyword::${to_rust_ident(value)} =>
Keyword::${to_camel_case(value)} =>
structs::${keyword.gecko_constant(value)} ${keyword.maybe_cast('u8')},
% endfor
}
@ -3805,7 +3804,7 @@ fn static_assert() {
% else:
structs::${keyword.gecko_constant(value)}
% endif
=> Keyword::${to_rust_ident(value)},
=> Keyword::${to_camel_case(value)},
% endfor
x => panic!("Found unexpected value in style struct for ${ident} property: {:?}", x),
}

View file

@ -441,7 +441,7 @@
use style_traits::ParseError;
define_css_keyword_enum! { T:
% for value in keyword.values_for(product):
"${value}" => ${to_rust_ident(value)},
"${value}" => ${to_camel_case(value)},
% endfor
}
@ -486,11 +486,11 @@
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::${to_rust_ident(values.split()[0])}
computed_value::T::${to_camel_case(values.split()[0])}
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Keyword(computed_value::T::${to_rust_ident(values.split()[0])})
SpecifiedValue::Keyword(computed_value::T::${to_camel_case(values.split()[0])})
}
impl SpecifiedValue {
@ -510,6 +510,8 @@
<%def name="single_keyword(name, values, vector=False, **kwargs)">
<%call expr="single_keyword_computed(name, values, vector, **kwargs)">
// FIXME(emilio): WTF is this even trying to do? Those are no-ops,
// should be derived instead!
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
@ -517,7 +519,7 @@
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
% for value in data.longhands_by_name[name].keyword.values_for(product):
SpecifiedValue::${to_rust_ident(value)} => computed_value::T::${to_rust_ident(value)},
SpecifiedValue::${to_camel_case(value)} => computed_value::T::${to_camel_case(value)},
% endfor
}
}
@ -525,7 +527,7 @@
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
% for value in data.longhands_by_name[name].keyword.values_for(product):
computed_value::T::${to_rust_ident(value)} => SpecifiedValue::${to_rust_ident(value)},
computed_value::T::${to_camel_case(value)} => SpecifiedValue::${to_camel_case(value)},
% endfor
}
}
@ -554,7 +556,7 @@
% endfor
match kw ${maybe_cast} {
% for value in values:
${to_rust_ident(value).upper()} => ${type}::${to_rust_ident(value)},
${to_rust_ident(value).upper()} => ${type}::${to_camel_case(value)},
% endfor
x => panic!("Found unexpected value in style struct for ${keyword.name} property: {:?}", x),
}
@ -616,12 +618,12 @@
define_css_keyword_enum! { SpecifiedValue:
values {
% for value in keyword.values_for(product) + (extra_specified or "").split():
"${value}" => ${to_rust_ident(value)},
"${value}" => ${to_camel_case(value)},
% endfor
}
aliases {
% for alias, value in keyword.aliases_for(product).iteritems():
"${alias}" => ${to_rust_ident(value)},
"${alias}" => ${to_camel_case(value)},
% endfor
}
}
@ -631,17 +633,17 @@
pub mod computed_value {
define_css_keyword_enum! { T:
% for value in data.longhands_by_name[name].keyword.values_for(product):
"${value}" => ${to_rust_ident(value)},
"${value}" => ${to_camel_case(value)},
% endfor
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::${to_rust_ident(values.split()[0])}
computed_value::T::${to_camel_case(values.split()[0])}
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::${to_rust_ident(values.split()[0])}
SpecifiedValue::${to_camel_case(values.split()[0])}
}
#[inline]
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)

View file

@ -658,10 +658,10 @@ impl Animate for Visibility {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
let (this_weight, other_weight) = procedure.weights();
match (*self, *other) {
(Visibility::visible, _) => {
(Visibility::Visible, _) => {
Ok(if this_weight > 0.0 { *self } else { *other })
},
(_, Visibility::visible) => {
(_, Visibility::Visible) => {
Ok(if other_weight > 0.0 { *other } else { *self })
},
_ => Err(()),
@ -763,7 +763,7 @@ impl Animate for FontStretch {
{
let from = f64::from(*self);
let to = f64::from(*other);
let normal = f64::from(FontStretch::normal);
let normal = f64::from(FontStretch::Normal);
let (this_weight, other_weight) = procedure.weights();
let result = (from - normal) * this_weight + (to - normal) * other_weight + normal;
Ok(result.into())
@ -788,15 +788,15 @@ impl From<FontStretch> for f64 {
fn from(stretch: FontStretch) -> f64 {
use self::FontStretch::*;
match stretch {
ultra_condensed => 1.0,
extra_condensed => 2.0,
condensed => 3.0,
semi_condensed => 4.0,
normal => 5.0,
semi_expanded => 6.0,
expanded => 7.0,
extra_expanded => 8.0,
ultra_expanded => 9.0,
UltraCondensed => 1.0,
ExtraCondensed => 2.0,
Condensed => 3.0,
SemiCondensed => 4.0,
Normal => 5.0,
SemiExpanded => 6.0,
Expanded => 7.0,
ExtraExpanded => 8.0,
UltraExpanded => 9.0,
}
}
}
@ -806,8 +806,8 @@ impl Into<FontStretch> for f64 {
use properties::longhands::font_stretch::computed_value::T::*;
let index = (self + 0.5).floor().min(9.0).max(1.0);
static FONT_STRETCH_ENUM_MAP: [FontStretch; 9] =
[ ultra_condensed, extra_condensed, condensed, semi_condensed, normal,
semi_expanded, expanded, extra_expanded, ultra_expanded ];
[ UltraCondensed, ExtraCondensed, Condensed, SemiCondensed, Normal,
SemiExpanded, Expanded, ExtraExpanded, UltraExpanded ];
FONT_STRETCH_ENUM_MAP[(index - 1.0) as usize]
}
}

View file

@ -33,7 +33,7 @@
)}
${helpers.predefined_type("border-%s-style" % side_name, "BorderStyle",
"specified::BorderStyle::none",
"specified::BorderStyle::None",
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"),
spec=maybe_logical_spec(side, "style"),
flags="APPLIES_TO_FIRST_LETTER",

View file

@ -37,19 +37,20 @@
pub mod computed_value {
pub use super::SpecifiedValue as T;
use super::SpecifiedValue as Display;
impl T {
impl Display {
/// Returns whether this "display" value is the display of a flex or
/// grid container.
///
/// This is used to implement various style fixups.
pub fn is_item_container(&self) -> bool {
matches!(*self,
T::flex
| T::inline_flex
Display::Flex
| Display::InlineFlex
% if product == "gecko":
| T::grid
| T::inline_grid
| Display::Grid
| Display::InlineGrid
% endif
)
}
@ -59,11 +60,11 @@
/// line as itself.
pub fn is_line_participant(&self) -> bool {
matches!(*self,
T::inline
Display::Inline
% if product == "gecko":
| T::contents
| T::ruby
| T::ruby_base_container
| Display::Contents
| Display::Ruby
| Display::RubyBaseContainer
% endif
)
}
@ -84,8 +85,8 @@
#[cfg(feature = "gecko")]
{
match (_old_display, _new_display) {
(T::_webkit_box, T::_moz_box) |
(T::_webkit_inline_box, T::_moz_inline_box) => {
(Display::WebkitBox, Display::MozBox) |
(Display::WebkitInlineBox, Display::MozInlineBox) => {
return true;
}
_ => {},
@ -99,14 +100,20 @@
/// ruby.
#[cfg(feature = "gecko")]
pub fn is_ruby_type(&self) -> bool {
matches!(*self, T::ruby | T::ruby_base | T::ruby_text |
T::ruby_base_container | T::ruby_text_container)
matches!(*self,
Display::Ruby |
Display::RubyBase |
Display::RubyText |
Display::RubyBaseContainer |
Display::RubyTextContainer)
}
/// Returns whether this "display" value is a ruby level container.
#[cfg(feature = "gecko")]
pub fn is_ruby_level_container(&self) -> bool {
matches!(*self, T::ruby_base_container | T::ruby_text_container)
matches!(*self,
Display::RubyBaseContainer |
Display::RubyTextContainer)
}
/// Convert this display into an equivalent block display.
@ -115,28 +122,36 @@
pub fn equivalent_block_display(&self, _is_root_element: bool) -> Self {
match *self {
// Values that have a corresponding block-outside version.
T::inline_table => T::table,
T::inline_flex => T::flex,
Display::InlineTable => Display::Table,
Display::InlineFlex => Display::Flex,
% if product == "gecko":
T::inline_grid => T::grid,
T::_webkit_inline_box => T::_webkit_box,
Display::InlineGrid => Display::Grid,
Display::WebkitInlineBox => Display::WebkitBox,
% endif
// Special handling for contents and list-item on the root
// element for Gecko.
% if product == "gecko":
T::contents | T::list_item if _is_root_element => T::block,
Display::Contents | Display::ListItem if _is_root_element => Display::Block,
% endif
// These are not changed by blockification.
T::none | T::block | T::flex | T::list_item | T::table => *self,
Display::None |
Display::Block |
Display::Flex |
Display::ListItem |
Display::Table => *self,
% if product == "gecko":
T::contents | T::flow_root | T::grid | T::_webkit_box => *self,
Display::Contents |
Display::FlowRoot |
Display::Grid |
Display::WebkitBox => *self,
% endif
// Everything else becomes block.
_ => T::block,
_ => Display::Block,
}
}
@ -148,35 +163,38 @@
#[cfg(feature = "gecko")]
pub fn inlinify(&self) -> Self {
match *self {
T::block | T::flow_root => T::inline_block,
T::table => T::inline_table,
T::flex => T::inline_flex,
T::grid => T::inline_grid,
T::_moz_box => T::_moz_inline_box,
T::_moz_stack => T::_moz_inline_stack,
T::_webkit_box => T::_webkit_inline_box,
Display::Block |
Display::FlowRoot => Display::InlineBlock,
Display::Table => Display::InlineTable,
Display::Flex => Display::InlineFlex,
Display::Grid => Display::InlineGrid,
Display::MozBox => Display::MozInlineBox,
Display::MozStack => Display::MozInlineStack,
Display::WebkitBox => Display::WebkitInlineBox,
other => other,
}
}
}
}
// FIXME(emilio): Why does this reinvent the wheel, again?
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub enum SpecifiedValue {
% for value in values:
${to_rust_ident(value)},
${to_camel_case(value)},
% endfor
}
// TODO(emilio): derive.
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
where W: ::std::fmt::Write,
{
match *self {
% for value in values:
SpecifiedValue::${to_rust_ident(value)} => dest.write_str("${value}"),
SpecifiedValue::${to_camel_case(value)} => dest.write_str("${value}"),
% endfor
}
}
@ -185,7 +203,7 @@
/// The initial display value.
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::${to_rust_ident(values[0])}
computed_value::T::${to_camel_case(values[0])}
}
/// Parse a display value.
@ -194,12 +212,12 @@
try_match_ident_ignore_ascii_case! { input,
% for value in values:
"${value}" => {
Ok(computed_value::T::${to_rust_ident(value)})
Ok(computed_value::T::${to_camel_case(value)})
},
% endfor
% for value in webkit_prefixed_values:
"-webkit-${value}" => {
Ok(computed_value::T::${to_rust_ident(value)})
Ok(computed_value::T::${to_camel_case(value)})
},
% endfor
}
@ -250,25 +268,25 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
let ltr = context.style().writing_mode.is_bidi_ltr();
// https://drafts.csswg.org/css-logical-props/#float-clear
match *self {
SpecifiedValue::inline_start => {
SpecifiedValue::InlineStart => {
context.rule_cache_conditions.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
if ltr {
computed_value::T::left
computed_value::T::Left
} else {
computed_value::T::right
computed_value::T::Right
}
}
SpecifiedValue::inline_end => {
SpecifiedValue::InlineEnd => {
context.rule_cache_conditions.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
if ltr {
computed_value::T::right
computed_value::T::Right
} else {
computed_value::T::left
computed_value::T::Left
}
}
% for value in "none left right".split():
% for value in "None Left Right".split():
SpecifiedValue::${value} => computed_value::T::${value},
% endfor
}
@ -276,7 +294,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
#[inline]
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
match *computed {
% for value in "none left right".split():
% for value in "None Left Right".split():
computed_value::T::${value} => SpecifiedValue::${value},
% endfor
}
@ -302,25 +320,25 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
let ltr = context.style().writing_mode.is_bidi_ltr();
// https://drafts.csswg.org/css-logical-props/#float-clear
match *self {
SpecifiedValue::inline_start => {
SpecifiedValue::InlineStart => {
context.rule_cache_conditions.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
if ltr {
computed_value::T::left
computed_value::T::Left
} else {
computed_value::T::right
computed_value::T::Right
}
}
SpecifiedValue::inline_end => {
SpecifiedValue::InlineEnd => {
context.rule_cache_conditions.borrow_mut()
.set_writing_mode_dependency(context.builder.writing_mode);
if ltr {
computed_value::T::right
computed_value::T::Right
} else {
computed_value::T::left
computed_value::T::Left
}
}
% for value in "none left right both".split():
% for value in "None Left Right Both".split():
SpecifiedValue::${value} => computed_value::T::${value},
% endfor
}
@ -328,7 +346,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky",
#[inline]
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
match *computed {
% for value in "none left right both".split():
% for value in "None Left Right Both".split():
computed_value::T::${value} => SpecifiedValue::${value},
% endfor
}
@ -377,7 +395,7 @@ ${helpers.single_keyword("-servo-overflow-clip-box", "padding-box content-box",
${helpers.predefined_type(
"overflow-clip-box-" + direction,
"OverflowClipBox",
"computed::OverflowClipBox::padding_box",
"computed::OverflowClipBox::PaddingBox",
products="gecko",
enabled_in="ua",
needs_context=False,

View file

@ -136,7 +136,7 @@
input.try(|input| {
input.expect_comma()?;
list_style_type::parse(context, input)
}).unwrap_or(list_style_type::computed_value::T::decimal)
}).unwrap_or(list_style_type::computed_value::T::Decimal)
}
#[cfg(feature = "gecko")]

View file

@ -76,13 +76,13 @@ ${helpers.single_keyword("word-break",
#[inline]
fn to_computed_value(&self, _: &Context) -> computed_value::T {
match *self {
% for value in "auto none inter_word".split():
% for value in "Auto None InterWord".split():
SpecifiedValue::${value} => computed_value::T::${value},
% endfor
% if product == "gecko":
SpecifiedValue::inter_character => computed_value::T::inter_character,
SpecifiedValue::InterCharacter => computed_value::T::InterCharacter,
// https://drafts.csswg.org/css-text-3/#valdef-text-justify-distribute
SpecifiedValue::distribute => computed_value::T::inter_character,
SpecifiedValue::Distribute => computed_value::T::InterCharacter,
% endif
}
}
@ -90,11 +90,11 @@ ${helpers.single_keyword("word-break",
#[inline]
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
match *computed {
% for value in "auto none inter_word".split():
% for value in "Auto None InterWord".split():
computed_value::T::${value} => SpecifiedValue::${value},
% endfor
% if product == "gecko":
computed_value::T::inter_character => SpecifiedValue::inter_character,
computed_value::T::InterCharacter => SpecifiedValue::InterCharacter,
% endif
}
}
@ -109,18 +109,25 @@ ${helpers.single_keyword("text-align-last",
spec="https://drafts.csswg.org/css-text/#propdef-text-align-last")}
// TODO make this a shorthand and implement text-align-last/text-align-all
//
// FIXME(emilio): This can't really be that complicated.
<%helpers:longhand name="text-align" animation_value_type="discrete"
flags="APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-text/#propdef-text-align">
pub use self::computed_value::TextAlign;
pub mod computed_value {
pub use self::TextAlign as T;
macro_rules! define_text_align {
( $( $name: ident ( $string: expr ) => $discriminant: expr, )+ ) => {
define_css_keyword_enum! { T:
define_css_keyword_enum! { TextAlign:
$(
$string => $name,
)+
}
impl T {
impl TextAlign {
pub fn to_u32(self) -> u32 {
match self {
$(
@ -139,22 +146,23 @@ ${helpers.single_keyword("text-align-last",
}
}
}
// FIXME(emilio): Why reinventing the world?
define_text_align! {
start("start") => 0,
end("end") => 1,
left("left") => 2,
right("right") => 3,
center("center") => 4,
justify("justify") => 5,
Start("start") => 0,
End("end") => 1,
Left("left") => 2,
Right("right") => 3,
Center("center") => 4,
Justify("justify") => 5,
% if product == "servo":
servo_center("-servo-center") => 6,
servo_left("-servo-left") => 7,
servo_right("-servo-right") => 8,
ServoCenter("-servo-center") => 6,
ServoLeft("-servo-left") => 7,
ServoRight("-servo-right") => 8,
% else:
_moz_center("-moz-center") => 6,
_moz_left("-moz-left") => 7,
_moz_right("-moz-right") => 8,
char("char") => 10,
MozCenter("-moz-center") => 6,
MozLeft("-moz-left") => 7,
MozRight("-moz-right") => 8,
Char("char") => 10,
% endif
}
@ -164,8 +172,8 @@ ${helpers.single_keyword("text-align-last",
gecko_strip_moz_prefix=False), type="T")}
}
#[inline] pub fn get_initial_value() -> computed_value::T {
computed_value::T::start
#[inline] pub fn get_initial_value() -> TextAlign {
TextAlign::Start
}
@ -176,14 +184,14 @@ ${helpers.single_keyword("text-align-last",
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum SpecifiedValue {
Keyword(computed_value::T),
Keyword(TextAlign),
MatchParent,
MozCenterOrInherit,
}
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
// MozCenterOrInherit cannot be parsed, only set directly on th elements
if let Ok(key) = input.try(computed_value::T::parse) {
if let Ok(key) = input.try(TextAlign::parse) {
Ok(SpecifiedValue::Keyword(key))
} else {
input.expect_ident_matching("match-parent")?;
@ -211,10 +219,10 @@ ${helpers.single_keyword("text-align-last",
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
type ComputedValue = TextAlign;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
fn to_computed_value(&self, context: &Context) -> TextAlign {
match *self {
SpecifiedValue::Keyword(key) => key,
SpecifiedValue::MatchParent => {
@ -230,17 +238,17 @@ ${helpers.single_keyword("text-align-last",
let parent = context.builder.get_parent_inheritedtext().clone_text_align();
let ltr = context.builder.inherited_writing_mode().is_bidi_ltr();
match (parent, ltr) {
(computed_value::T::start, true) => computed_value::T::left,
(computed_value::T::start, false) => computed_value::T::right,
(computed_value::T::end, true) => computed_value::T::right,
(computed_value::T::end, false) => computed_value::T::left,
(TextAlign::Start, true) => TextAlign::Left,
(TextAlign::Start, false) => TextAlign::Right,
(TextAlign::End, true) => TextAlign::Right,
(TextAlign::End, false) => TextAlign::Left,
_ => parent
}
}
SpecifiedValue::MozCenterOrInherit => {
let parent = context.builder.get_parent_inheritedtext().clone_text_align();
if parent == computed_value::T::start {
computed_value::T::center
if parent == TextAlign::Start {
TextAlign::Center
} else {
parent
}
@ -314,8 +322,8 @@ ${helpers.predefined_type("word-spacing",
// Start with no declarations if this is an atomic inline-level box; otherwise, start with the
// declarations in effect and add in the text decorations that this block specifies.
let mut result = match context.style().get_box().clone_display() {
super::display::computed_value::T::inline_block |
super::display::computed_value::T::inline_table => get_initial_value(),
super::display::computed_value::T::InlineBlock |
super::display::computed_value::T::InlineTable => get_initial_value(),
_ => context.builder.get_parent_inheritedtext().clone__servo_text_decorations_in_effect()
};
@ -354,31 +362,31 @@ ${helpers.predefined_type("word-spacing",
impl SpecifiedValue {
pub fn allow_wrap(&self) -> bool {
match *self {
SpecifiedValue::nowrap |
SpecifiedValue::pre => false,
SpecifiedValue::normal |
SpecifiedValue::pre_wrap |
SpecifiedValue::pre_line => true,
SpecifiedValue::Nowrap |
SpecifiedValue::Pre => false,
SpecifiedValue::Normal |
SpecifiedValue::PreWrap |
SpecifiedValue::PreLine => true,
}
}
pub fn preserve_newlines(&self) -> bool {
match *self {
SpecifiedValue::normal |
SpecifiedValue::nowrap => false,
SpecifiedValue::pre |
SpecifiedValue::pre_wrap |
SpecifiedValue::pre_line => true,
SpecifiedValue::Normal |
SpecifiedValue::Nowrap => false,
SpecifiedValue::Pre |
SpecifiedValue::PreWrap |
SpecifiedValue::PreLine => true,
}
}
pub fn preserve_spaces(&self) -> bool {
match *self {
SpecifiedValue::normal |
SpecifiedValue::nowrap |
SpecifiedValue::pre_line => false,
SpecifiedValue::pre |
SpecifiedValue::pre_wrap => true,
SpecifiedValue::Normal |
SpecifiedValue::Nowrap |
SpecifiedValue::PreLine => false,
SpecifiedValue::Pre |
SpecifiedValue::PreWrap => true,
}
}
}
@ -399,7 +407,7 @@ ${helpers.predefined_type(
<%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 writing_mode;
use computed_values::writing_mode::T as WritingMode;
use std::fmt;
use style_traits::ToCss;
use unicode_segmentation::UnicodeSegmentation;
@ -519,7 +527,7 @@ ${helpers.predefined_type(
match *self {
SpecifiedValue::Keyword(ref keyword) => {
let default_shape = if context.style().get_inheritedbox()
.clone_writing_mode() == writing_mode::horizontal_tb {
.clone_writing_mode() == WritingMode::HorizontalTb {
ShapeKeyword::Circle
} else {
ShapeKeyword::Sesame

View file

@ -38,12 +38,12 @@ ${helpers.predefined_type(
#[inline]
pub fn get_initial_value() -> computed_value::T {
Either::Second(BorderStyle::none)
Either::Second(BorderStyle::None)
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
Either::Second(BorderStyle::none)
Either::Second(BorderStyle::None)
}
pub mod computed_value {
@ -54,7 +54,7 @@ ${helpers.predefined_type(
-> Result<SpecifiedValue, ParseError<'i>> {
SpecifiedValue::parse(context, input)
.and_then(|result| {
if let Either::Second(BorderStyle::hidden) = result {
if let Either::Second(BorderStyle::Hidden) = result {
// The outline-style property accepts the same values as
// border-style, except that 'hidden' is not a legal outline
// style.

View file

@ -2396,24 +2396,24 @@ impl ComputedValuesInner {
/// Return true if the effects force the transform style to be Flat
pub fn overrides_transform_style(&self) -> bool {
use computed_values::mix_blend_mode;
use computed_values::mix_blend_mode::T as MixBlendMode;
let effects = self.get_effects();
// TODO(gw): Add clip-path, isolation, mask-image, mask-border-source when supported.
effects.opacity < 1.0 ||
!effects.filter.0.is_empty() ||
!effects.clip.is_auto() ||
effects.mix_blend_mode != mix_blend_mode::T::normal
effects.mix_blend_mode != MixBlendMode::Normal
}
/// <https://drafts.csswg.org/css-transforms/#grouping-property-values>
pub fn get_used_transform_style(&self) -> computed_values::transform_style::T {
use computed_values::transform_style;
use computed_values::transform_style::T as TransformStyle;
let box_ = self.get_box();
if self.overrides_transform_style() {
transform_style::T::flat
TransformStyle::Flat
} else {
// Return the computed value if not overridden by the above exceptions
box_.transform_style
@ -2913,15 +2913,15 @@ impl<'a> StyleBuilder<'a> {
/// Returns whether this computed style represents a floated object.
pub fn floated(&self) -> bool {
self.get_box().clone_float() != longhands::float::computed_value::T::none
self.get_box().clone_float() != longhands::float::computed_value::T::None
}
/// Returns whether this computed style represents an out of flow-positioned
/// object.
pub fn out_of_flow_positioned(&self) -> bool {
use properties::longhands::position::computed_value::T as position;
use properties::longhands::position::computed_value::T as Position;
matches!(self.get_box().clone_position(),
position::absolute | position::fixed)
Position::Absolute | Position::Fixed)
}
/// Whether this style has a top-layer style. That's implemented in Gecko
@ -2934,7 +2934,7 @@ impl<'a> StyleBuilder<'a> {
#[cfg(feature = "gecko")]
pub fn in_top_layer(&self) -> bool {
matches!(self.get_box().clone__moz_top_layer(),
longhands::_moz_top_layer::computed_value::T::top)
longhands::_moz_top_layer::computed_value::T::Top)
}
/// Clears the "have any reset structs been modified" flag.

View file

@ -18,16 +18,17 @@
use values::specified::{Color, Position, PositionComponent};
use parser::Parse;
// FIXME(emilio): Should be the same type!
impl From<background_origin::single_value::SpecifiedValue> for background_clip::single_value::SpecifiedValue {
fn from(origin: background_origin::single_value::SpecifiedValue) ->
background_clip::single_value::SpecifiedValue {
match origin {
background_origin::single_value::SpecifiedValue::content_box =>
background_clip::single_value::SpecifiedValue::content_box,
background_origin::single_value::SpecifiedValue::padding_box =>
background_clip::single_value::SpecifiedValue::padding_box,
background_origin::single_value::SpecifiedValue::border_box =>
background_clip::single_value::SpecifiedValue::border_box,
background_origin::single_value::SpecifiedValue::ContentBox =>
background_clip::single_value::SpecifiedValue::ContentBox,
background_origin::single_value::SpecifiedValue::PaddingBox =>
background_clip::single_value::SpecifiedValue::PaddingBox,
background_origin::single_value::SpecifiedValue::BorderBox =>
background_clip::single_value::SpecifiedValue::BorderBox,
}
}
}
@ -177,7 +178,7 @@
size.to_css(dest)?;
}
if *origin != Origin::padding_box || *clip != Clip::border_box {
if *origin != Origin::PaddingBox || *clip != Clip::BorderBox {
dest.write_str(" ")?;
origin.to_css(dest)?;
if *clip != From::from(*origin) {

View file

@ -80,7 +80,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
}
if any {
Ok((color.unwrap_or_else(|| Color::currentcolor()),
style.unwrap_or(BorderStyle::none),
style.unwrap_or(BorderStyle::None),
width.unwrap_or(BorderSideWidth::Medium)))
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))

View file

@ -18,20 +18,20 @@
try_match_ident_ignore_ascii_case! { input,
"-moz-scrollbars-horizontal" => {
Ok(expanded! {
overflow_x: SpecifiedValue::scroll,
overflow_y: SpecifiedValue::hidden,
overflow_x: SpecifiedValue::Scroll,
overflow_y: SpecifiedValue::Hidden,
})
}
"-moz-scrollbars-vertical" => {
Ok(expanded! {
overflow_x: SpecifiedValue::hidden,
overflow_y: SpecifiedValue::scroll,
overflow_x: SpecifiedValue::Hidden,
overflow_y: SpecifiedValue::Scroll,
})
}
"-moz-scrollbars-none" => {
Ok(expanded! {
overflow_x: SpecifiedValue::hidden,
overflow_y: SpecifiedValue::hidden,
overflow_x: SpecifiedValue::Hidden,
overflow_y: SpecifiedValue::Hidden,
})
}
}

View file

@ -60,7 +60,7 @@
fn list_style_type_none() -> list_style_type::SpecifiedValue {
% if product == "servo":
list_style_type::SpecifiedValue::none
list_style_type::SpecifiedValue::None
% else:
use values::generics::CounterStyleOrNone;
list_style_type::SpecifiedValue::CounterStyle(CounterStyleOrNone::None)

View file

@ -14,22 +14,23 @@
use values::specified::{Position, PositionComponent};
use parser::Parse;
// FIXME(emilio): These two mask types should be the same!
impl From<mask_origin::single_value::SpecifiedValue> for mask_clip::single_value::SpecifiedValue {
fn from(origin: mask_origin::single_value::SpecifiedValue) -> mask_clip::single_value::SpecifiedValue {
match origin {
mask_origin::single_value::SpecifiedValue::content_box =>
mask_clip::single_value::SpecifiedValue::content_box,
mask_origin::single_value::SpecifiedValue::padding_box =>
mask_clip::single_value::SpecifiedValue::padding_box,
mask_origin::single_value::SpecifiedValue::border_box =>
mask_clip::single_value::SpecifiedValue::border_box,
mask_origin::single_value::SpecifiedValue::ContentBox =>
mask_clip::single_value::SpecifiedValue::ContentBox,
mask_origin::single_value::SpecifiedValue::PaddingBox =>
mask_clip::single_value::SpecifiedValue::PaddingBox ,
mask_origin::single_value::SpecifiedValue::BorderBox =>
mask_clip::single_value::SpecifiedValue::BorderBox,
% if product == "gecko":
mask_origin::single_value::SpecifiedValue::fill_box =>
mask_clip::single_value::SpecifiedValue::fill_box,
mask_origin::single_value::SpecifiedValue::stroke_box =>
mask_clip::single_value::SpecifiedValue::stroke_box,
mask_origin::single_value::SpecifiedValue::view_box =>
mask_clip::single_value::SpecifiedValue::view_box,
mask_origin::single_value::SpecifiedValue::FillBox =>
mask_clip::single_value::SpecifiedValue::FillBox ,
mask_origin::single_value::SpecifiedValue::StrokeBox =>
mask_clip::single_value::SpecifiedValue::StrokeBox,
mask_origin::single_value::SpecifiedValue::ViewBox=>
mask_clip::single_value::SpecifiedValue::ViewBox,
% endif
}
}
@ -160,7 +161,7 @@
dest.write_str(" ")?;
repeat.to_css(dest)?;
if *origin != Origin::border_box || *clip != Clip::border_box {
if *origin != Origin::BorderBox || *clip != Clip::BorderBox {
dest.write_str(" ")?;
origin.to_css(dest)?;
if *clip != From::from(*origin) {

View file

@ -66,7 +66,7 @@
self.text_decoration_line.to_css(dest)?;
% if product == "gecko":
if self.text_decoration_style != &text_decoration_style::SpecifiedValue::solid {
if *self.text_decoration_style != text_decoration_style::SpecifiedValue::Solid {
dest.write_str(" ")?;
self.text_decoration_style.to_css(dest)?;
}