style: Generate StyleDisplay using cbindgen.

We use the same setup WR uses, which is checking-in the files.

But I think it's much better than keeping the two things in sync manually :)

When you add a new value, you need to add it to the rust source, then run the
command, but since it doesn't need to build the style crate (it uses the Rust
AST, doesn't build) there's no problem.

Differential Revision: https://phabricator.services.mozilla.com/D2354
This commit is contained in:
Emilio Cobos Álvarez 2018-07-25 13:15:21 +02:00
parent c63a9a37a9
commit 798d45f38d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 63 additions and 44 deletions

View file

@ -3031,57 +3031,39 @@ fn static_assert() {
shape-outside contain touch-action translate
scale""" %>
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
// We manually-implement the |display| property until we get general
// infrastructure for preffing certain values.
<% display_keyword = Keyword("display", "inline block inline-block table inline-table table-row-group " +
"table-header-group table-footer-group table-row table-column-group " +
"table-column table-cell table-caption list-item flex none " +
"inline-flex grid inline-grid ruby ruby-base ruby-base-container " +
"ruby-text ruby-text-container contents flow-root -webkit-box " +
"-webkit-inline-box -moz-box -moz-inline-box -moz-grid -moz-inline-grid " +
"-moz-grid-group -moz-grid-line -moz-stack -moz-inline-stack -moz-deck " +
"-moz-popup -moz-groupbox",
gecko_enum_prefix="StyleDisplay",
gecko_strip_moz_prefix=False) %>
fn match_display_keyword(
v: longhands::display::computed_value::T
) -> structs::root::mozilla::StyleDisplay {
use properties::longhands::display::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match v {
% for value in display_keyword.values_for('gecko'):
Keyword::${to_camel_case(value)} =>
structs::${display_keyword.gecko_constant(value)},
% endfor
}
}
#[inline]
pub fn set_display(&mut self, v: longhands::display::computed_value::T) {
let result = Self::match_display_keyword(v);
self.gecko.mDisplay = result;
self.gecko.mOriginalDisplay = result;
// unsafe: cbindgen ensures the representation is the same.
self.gecko.mDisplay = unsafe { transmute(v) };
self.gecko.mOriginalDisplay = unsafe { transmute(v) };
}
#[inline]
pub fn copy_display_from(&mut self, other: &Self) {
self.gecko.mDisplay = other.gecko.mDisplay;
self.gecko.mOriginalDisplay = other.gecko.mDisplay;
}
#[inline]
pub fn reset_display(&mut self, other: &Self) {
self.copy_display_from(other)
}
#[inline]
pub fn set_adjusted_display(
&mut self,
v: longhands::display::computed_value::T,
_is_item_or_root: bool
) {
self.gecko.mDisplay = Self::match_display_keyword(v);
// unsafe: cbindgen ensures the representation is the same.
self.gecko.mDisplay = unsafe { transmute(v) };
}
<%call expr="impl_keyword_clone('display', 'mDisplay', display_keyword)"></%call>
#[inline]
pub fn clone_display(&self) -> longhands::display::computed_value::T {
// unsafe: cbindgen ensures the representation is the same.
unsafe { transmute(self.gecko.mDisplay) }
}
<% float_keyword = Keyword("float", "Left Right None", gecko_enum_prefix="StyleFloat") %>
${impl_keyword('float', 'mFloat', float_keyword)}