diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml new file mode 100644 index 00000000000..ff4fe642a90 --- /dev/null +++ b/components/style/cbindgen.toml @@ -0,0 +1,26 @@ +header = """/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */""" +autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen. + * To generate this file: + * 1. Get the latest cbindgen using `cargo install --force cbindgen` + * a. Alternatively, you can clone `https://github.com/eqrion/cbindgen` and use a tagged release + * 2. Run `rustup run nightly cbindgen toolkit/library/rust/ --lockfile Cargo.lock --crate style -o layout/style/ServoStyleConsts.h` + */""" +include_version = true +braces = "SameLine" +line_length = 80 +tab_width = 2 +language = "C++" +namespaces = ["mozilla"] + +[struct] +derive_eq = true + +[enum] +derive_helper_methods = true + +[export] +prefix = "Style" +include = ["StyleDisplay"] +item_types = ["enums"] diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index c91ef4d4476..62a4eb86819 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -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)"> + #[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)} diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index cec7c8ccc33..de53bb20262 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -41,29 +41,42 @@ fn moz_box_display_values_enabled(context: &ParserContext) -> bool { } } +/// Defines an element’s display type, which consists of +/// the two basic qualities of how an element generates boxes +/// +/// +/// +/// NOTE(emilio): Order is important in Gecko! +/// +/// If you change it, make sure to take a look at the +/// FrameConstructionDataByDisplay stuff (both the XUL and non-XUL version), and +/// ensure it's still correct! +/// +/// Also, when you change this from Gecko you may need to regenerate the +/// C++-side bindings (see components/style/cbindgen.toml). #[allow(missing_docs)] #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] -/// Defines an element’s display type, which consists of -/// the two basic qualities of how an element generates boxes -/// +#[repr(u8)] pub enum Display { - Inline, + None = 0, Block, + #[cfg(feature = "gecko")] + FlowRoot, + Inline, InlineBlock, + ListItem, Table, InlineTable, TableRowGroup, + TableColumn, + TableColumnGroup, TableHeaderGroup, TableFooterGroup, TableRow, - TableColumnGroup, - TableColumn, TableCell, TableCaption, - ListItem, - None, #[parse(aliases = "-webkit-flex")] Flex, #[parse(aliases = "-webkit-inline-flex")] @@ -85,8 +98,6 @@ pub enum Display { #[cfg(feature = "gecko")] Contents, #[cfg(feature = "gecko")] - FlowRoot, - #[cfg(feature = "gecko")] WebkitBox, #[cfg(feature = "gecko")] WebkitInlineBox, @@ -119,10 +130,10 @@ pub enum Display { MozDeck, #[cfg(feature = "gecko")] #[parse(condition = "moz_display_values_enabled")] - MozPopup, + MozGroupbox, #[cfg(feature = "gecko")] #[parse(condition = "moz_display_values_enabled")] - MozGroupbox, + MozPopup, } impl Display {