diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index a88db8bf03e..69ad8440148 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% from data import Method, to_rust_ident %> +<% from data import Keyword, Method, to_rust_ident %> <% data.new_style_struct("Box", inherited=False, @@ -126,8 +126,12 @@ ${helpers.single_keyword("clear", "none left right both", gecko_ffi_name="mBreak use cssparser::ToCss; use std::fmt; - <% vertical_align_keywords = ( - "baseline sub super top text-top middle bottom text-bottom".split()) %> + <% vertical_align = data.longhands_by_name["vertical-align"] %> + <% vertical_align.keyword = Keyword("vertical-align", + "baseline sub super top text-top middle bottom text-bottom", + extra_gecko_values="middle-with-baseline") %> + <% vertical_align_keywords = vertical_align.keyword.values_for(product) %> + #[allow(non_camel_case_types)] #[derive(Debug, Clone, PartialEq, Copy, HeapSizeOf)] pub enum SpecifiedValue { diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 5ef6f45d568..904181b264d 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -29,7 +29,8 @@ use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; use style::properties::longhands; use style::properties::make_cascade_vec; use style::properties::style_struct_traits::*; -use values::{ToGeckoStyleCoord, convert_rgba_to_nscolor, convert_nscolor_to_rgba}; +use values::{StyleCoordHelpers, ToGeckoStyleCoord, convert_nscolor_to_rgba}; +use values::{convert_rgba_to_nscolor, debug_assert_unit_is_safe_to_copy}; use values::round_border_to_device_pixels; #[derive(Clone)] @@ -285,9 +286,7 @@ def set_gecko_property(ffi_name, expr): &mut self.gecko.${union_ffi_name}); } fn copy_${ident}_from(&mut self, other: &Self) { - use gecko_bindings::structs::nsStyleUnit::eStyleUnit_Calc; - debug_assert!(self.gecko.${unit_ffi_name} != eStyleUnit_Calc, - "stylo: Can't yet handle refcounted Calc"); + debug_assert_unit_is_safe_to_copy(self.gecko.${unit_ffi_name}); self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name}; self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name}; } @@ -305,10 +304,8 @@ def set_gecko_property(ffi_name, expr): &mut self.gecko.${y_union_ffi_name}); } fn copy_${ident}_from(&mut self, other: &Self) { - use gecko_bindings::structs::nsStyleUnit::eStyleUnit_Calc; - debug_assert!(self.gecko.${x_unit_ffi_name} != eStyleUnit_Calc && - self.gecko.${y_unit_ffi_name} != eStyleUnit_Calc, - "stylo: Can't yet handle refcounted Calc"); + debug_assert_unit_is_safe_to_copy(self.gecko.${x_unit_ffi_name}); + debug_assert_unit_is_safe_to_copy(self.gecko.${y_unit_ffi_name}); self.gecko.${x_unit_ffi_name} = other.gecko.${x_unit_ffi_name}; self.gecko.${x_union_ffi_name} = other.gecko.${x_union_ffi_name}; self.gecko.${y_unit_ffi_name} = other.gecko.${y_unit_ffi_name}; @@ -552,20 +549,14 @@ fn static_assert() { % endfor fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) { - use gecko_bindings::structs::nsStyleUnit; use style::properties::longhands::z_index::computed_value::T; match v { - T::Auto => { - self.gecko.mZIndex.mUnit = nsStyleUnit::eStyleUnit_Auto; - unsafe { *self.gecko.mZIndex.mValue.mInt.as_mut() = 0; } - } - T::Number(n) => { - self.gecko.mZIndex.mUnit = nsStyleUnit::eStyleUnit_Integer; - unsafe { *self.gecko.mZIndex.mValue.mInt.as_mut() = n; } - } + T::Auto => self.gecko.mZIndex.set_auto(), + T::Number(n) => self.gecko.mZIndex.set_int(n), } } fn copy_z_index_from(&mut self, other: &Self) { + debug_assert_unit_is_safe_to_copy(self.gecko.mZIndex.mUnit); self.gecko.mZIndex.mUnit = other.gecko.mZIndex.mUnit; self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue; } @@ -632,7 +623,7 @@ fn static_assert() { -<%self:impl_trait style_struct_name="Box" skip_longhands="display overflow-y"> +<%self:impl_trait style_struct_name="Box" skip_longhands="display overflow-y vertical-align"> // We manually-implement the |display| property until we get general // infrastructure for preffing certain values. @@ -666,6 +657,24 @@ fn static_assert() { } } + fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) { + <% keyword = data.longhands_by_name["vertical-align"].keyword %> + use style::properties::longhands::vertical_align::computed_value::T; + // FIXME: Align binary representations and ditch |match| for cast + static_asserts + match v { + % for value in keyword.values_for('gecko'): + T::${to_rust_ident(value)} => + self.gecko.mVerticalAlign.set_int(structs::${keyword.gecko_constant(value)} as i32), + % endfor + T::LengthOrPercentage(v) => self.gecko.mVerticalAlign.set(v), + } + } + fn copy_vertical_align_from(&mut self, other: &Self) { + debug_assert_unit_is_safe_to_copy(self.gecko.mVerticalAlign.mUnit); + self.gecko.mVerticalAlign.mUnit = other.gecko.mVerticalAlign.mUnit; + self.gecko.mVerticalAlign.mValue = other.gecko.mVerticalAlign.mValue; + } + <%self:impl_trait style_struct_name="Background" skip_longhands="background-color" skip_additionals="*"> diff --git a/ports/geckolib/values.rs b/ports/geckolib/values.rs index 069fb9bc9b6..7a313315f1f 100644 --- a/ports/geckolib/values.rs +++ b/ports/geckolib/values.rs @@ -4,10 +4,44 @@ use app_units::Au; use cssparser::RGBA; -use gecko_bindings::structs::{nsStyleUnion, nsStyleUnit}; +use gecko_bindings::structs::{nsStyleCoord, nsStyleUnion, nsStyleUnit}; use std::cmp::max; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; +pub trait StyleCoordHelpers { + fn set(&mut self, val: T); + fn set_auto(&mut self); + fn set_coord(&mut self, val: Au); + fn set_int(&mut self, val: i32); + fn set_percent(&mut self, val: f32); +} + +impl StyleCoordHelpers for nsStyleCoord { + fn set(&mut self, val: T) { + val.to_gecko_style_coord(&mut self.mUnit, &mut self.mValue); + } + + fn set_auto(&mut self) { + self.mUnit = nsStyleUnit::eStyleUnit_Auto; + unsafe { *self.mValue.mInt.as_mut() = 0; } + } + + fn set_coord(&mut self, val: Au) { + self.mUnit = nsStyleUnit::eStyleUnit_Coord; + unsafe { *self.mValue.mInt.as_mut() = val.0; } + } + + fn set_percent(&mut self, val: f32) { + self.mUnit = nsStyleUnit::eStyleUnit_Percent; + unsafe { *self.mValue.mFloat.as_mut() = val; } + } + + fn set_int(&mut self, val: i32) { + self.mUnit = nsStyleUnit::eStyleUnit_Integer; + unsafe { *self.mValue.mInt.as_mut() = val; } + } +} + pub trait ToGeckoStyleCoord { fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion); } @@ -95,3 +129,7 @@ pub fn round_border_to_device_pixels(width: Au, au_per_device_px: Au) -> Au { max(au_per_device_px, Au(width.0 / au_per_device_px.0 * au_per_device_px.0)) } } + +pub fn debug_assert_unit_is_safe_to_copy(unit: nsStyleUnit) { + debug_assert!(unit != nsStyleUnit::eStyleUnit_Calc, "stylo: Can't yet handle refcounted Calc"); +}