|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | + <%page args="data, helpers" /> |
| 6 | + |
| 7 | +<% data.new_style_struct("Box", inherited=False, gecko_ffi_name="nsStyleDisplay", |
| 8 | + additional_methods=[data.new_method("clone_display", |
| 9 | + "longhands::display::computed_value::T"), |
| 10 | + data.new_method("clone_position", |
| 11 | + "longhands::position::computed_value::T"), |
| 12 | + data.new_method("is_floated", "bool"), |
| 13 | + data.new_method("overflow_x_is_visible", "bool"), |
| 14 | + data.new_method("overflow_y_is_visible", "bool"), |
| 15 | + data.new_method("transition_count", "usize")]) %> |
| 16 | + |
| 17 | +// TODO(SimonSapin): don't parse `inline-table`, since we don't support it |
| 18 | +<%helpers:longhand name="display" custom_cascade="${product == 'servo'}"> |
| 19 | + <% |
| 20 | + values = """inline block inline-block |
| 21 | + table inline-table table-row-group table-header-group table-footer-group |
| 22 | + table-row table-column-group table-column table-cell table-caption |
| 23 | + list-item flex |
| 24 | + none |
| 25 | + """.split() |
| 26 | + experimental_values = set("flex".split()) |
| 27 | + %> |
| 28 | + pub use self::computed_value::T as SpecifiedValue; |
| 29 | + use values::computed::{Context, ComputedValueAsSpecified}; |
| 30 | + |
| 31 | + pub mod computed_value { |
| 32 | + #[allow(non_camel_case_types)] |
| 33 | + #[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug, HeapSizeOf)] |
| 34 | + #[derive(Deserialize, Serialize)] |
| 35 | + pub enum T { |
| 36 | + % for value in values: |
| 37 | + ${data.to_rust_ident(value)}, |
| 38 | + % endfor |
| 39 | + } |
| 40 | + |
| 41 | + impl ::cssparser::ToCss for T { |
| 42 | + fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result |
| 43 | + where W: ::std::fmt::Write { |
| 44 | + match *self { |
| 45 | + % for value in values: |
| 46 | + T::${data.to_rust_ident(value)} => dest.write_str("${value}"), |
| 47 | + % endfor |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + #[inline] pub fn get_initial_value() -> computed_value::T { |
| 53 | + computed_value::T::${data.to_rust_ident(values[0])} |
| 54 | + } |
| 55 | + pub fn parse(_context: &ParserContext, input: &mut Parser) |
| 56 | + -> Result<SpecifiedValue, ()> { |
| 57 | + match_ignore_ascii_case! { try!(input.expect_ident()), |
| 58 | + % for value in values: |
| 59 | + "${value}" => { |
| 60 | + % if value in experimental_values: |
| 61 | + if !::util::prefs::get_pref("layout.${value}.enabled") |
| 62 | + .as_boolean().unwrap_or(false) { |
| 63 | + return Err(()) |
| 64 | + } |
| 65 | + % endif |
| 66 | + Ok(computed_value::T::${data.to_rust_ident(value)}) |
| 67 | + }, |
| 68 | + % endfor |
| 69 | + _ => Err(()) |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + impl ComputedValueAsSpecified for SpecifiedValue {} |
| 74 | + |
| 75 | + % if product == "servo": |
| 76 | + fn cascade_property_custom<C: ComputedValues>( |
| 77 | + _declaration: &PropertyDeclaration, |
| 78 | + _inherited_style: &C, |
| 79 | + context: &mut computed::Context<C>, |
| 80 | + _seen: &mut PropertyBitField, |
| 81 | + _cacheable: &mut bool, |
| 82 | + _error_reporter: &mut StdBox<ParseErrorReporter + Send>) { |
| 83 | + longhands::_servo_display_for_hypothetical_box::derive_from_display(context); |
| 84 | + longhands::_servo_text_decorations_in_effect::derive_from_display(context); |
| 85 | + } |
| 86 | + % endif |
| 87 | + |
| 88 | +</%helpers:longhand> |
| 89 | + |
| 90 | +${helpers.single_keyword("position", "static absolute relative fixed", extra_gecko_values="sticky")} |
| 91 | + |
| 92 | +<%helpers:single_keyword_computed name="float" values="none left right" gecko_ffi_name="mFloats"> |
| 93 | + impl ToComputedValue for SpecifiedValue { |
| 94 | + type ComputedValue = computed_value::T; |
| 95 | + |
| 96 | + #[inline] |
| 97 | + fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { |
| 98 | + let positioned = matches!(context.style().get_box().clone_position(), |
| 99 | + longhands::position::SpecifiedValue::absolute | |
| 100 | + longhands::position::SpecifiedValue::fixed); |
| 101 | + if positioned { |
| 102 | + SpecifiedValue::none |
| 103 | + } else { |
| 104 | + *self |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | +</%helpers:single_keyword_computed> |
| 110 | + |
| 111 | +${helpers.single_keyword("clear", "none left right both", gecko_ffi_name="mBreakType")} |
| 112 | + |
| 113 | +<%helpers:longhand name="-servo-display-for-hypothetical-box" derived_from="display" products="servo"> |
| 114 | + pub use super::display::{SpecifiedValue, get_initial_value}; |
| 115 | + pub use super::display::{parse}; |
| 116 | + |
| 117 | + pub mod computed_value { |
| 118 | + pub type T = super::SpecifiedValue; |
| 119 | + } |
| 120 | + |
| 121 | + #[inline] |
| 122 | + pub fn derive_from_display<Cx: TContext>(context: &mut Cx) { |
| 123 | + let d = context.style().get_box().clone_display(); |
| 124 | + context.mutate_style().mutate_box().set__servo_display_for_hypothetical_box(d); |
| 125 | + } |
| 126 | + |
| 127 | +</%helpers:longhand> |
0 commit comments