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

@ -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,