diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index 5a2a468d319..4b26a186c02 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -42,6 +42,7 @@ mod gecko_style_structs; pub mod glue; mod selector_impl; mod traversal; +mod values; mod wrapper; // Generated from the properties.mako.rs template by build.rs diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 7dd8f34013f..f18659c0ea0 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -28,6 +28,8 @@ use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; use style::properties::longhands; use style::properties::make_cascade_vec; use style::properties::style_struct_traits::*; +use gecko_style_structs::{nsStyleUnion, nsStyleUnit}; +use values::ToGeckoStyleCoord; #[derive(Clone)] pub struct GeckoComputedValues { @@ -196,6 +198,20 @@ def set_gecko_property(ffi_name, expr): % endif +<%def name="impl_style_coord(ident, unit_ffi_name, union_ffi_name)"> + fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { + v.to_gecko_style_coord(&mut self.gecko.${unit_ffi_name}, + &mut self.gecko.${union_ffi_name}); + } + fn copy_${ident}_from(&mut self, other: &Self) { + use gecko_style_structs::nsStyleUnit::eStyleUnit_Calc; + assert!(self.gecko.${unit_ffi_name} != eStyleUnit_Calc, + "stylo: Can't yet handle refcounted Calc"); + self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name}; + self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name}; + } + + <%def name="impl_style_struct(style_struct)"> impl ${style_struct.gecko_struct_name} { #[allow(dead_code, unused_variables)] @@ -340,12 +356,7 @@ fn static_assert() { <% border_style_keyword = Keyword("border-style", "none solid double dotted dashed hidden groove ridge inset outset") %> -<% -skip_border_longhands = "" -for side in SIDES: - skip_border_longhands += "border-{0}-style border-{0}-width ".format(side.ident) -%> - +<% skip_border_longhands = " ".join(["border-{0}-style border-{0}-width ".format(x.ident) for x in SIDES]) %> <%self:impl_trait style_struct_name="Border" skip_longhands="${skip_border_longhands}" skip_additionals="*"> @@ -362,6 +373,26 @@ for side in SIDES: % endfor +<% skip_margin_longhands = " ".join(["margin-%s" % x.ident for x in SIDES]) %> +<%self:impl_trait style_struct_name="Margin" + skip_longhands="${skip_margin_longhands}"> + + % for side in SIDES: + <% impl_style_coord("margin_%s" % side.ident, + "mMargin.mUnits[%s]" % side.index, "mMargin.mValues[%s]" % side.index) %> + % endfor + + +<% skip_padding_longhands = " ".join(["padding-%s" % x.ident for x in SIDES]) %> +<%self:impl_trait style_struct_name="Padding" + skip_longhands="${skip_padding_longhands}"> + + % for side in SIDES: + <% impl_style_coord("padding_%s" % side.ident, + "mPadding.mUnits[%s]" % side.index, "mPadding.mValues[%s]" % side.index) %> + % endfor + + <%self:impl_trait style_struct_name="Outline" skip_longhands="outline-style" skip_additionals="*"> diff --git a/ports/geckolib/values.rs b/ports/geckolib/values.rs new file mode 100644 index 00000000000..6d195519aeb --- /dev/null +++ b/ports/geckolib/values.rs @@ -0,0 +1,46 @@ +/* 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/. */ + +use gecko_style_structs::{nsStyleUnion, nsStyleUnit}; +use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; + +pub trait ToGeckoStyleCoord { + fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion); +} + +impl ToGeckoStyleCoord for LengthOrPercentage { + fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) { + match *self { + LengthOrPercentage::Length(au) => { + *unit = nsStyleUnit::eStyleUnit_Coord; + unsafe { *union.mInt.as_mut() = au.0; } + }, + LengthOrPercentage::Percentage(p) => { + *unit = nsStyleUnit::eStyleUnit_Percent; + unsafe { *union.mFloat.as_mut() = p; } + }, + LengthOrPercentage::Calc(_) => unimplemented!(), + }; + } +} + +impl ToGeckoStyleCoord for LengthOrPercentageOrAuto { + fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) { + match *self { + LengthOrPercentageOrAuto::Length(au) => { + *unit = nsStyleUnit::eStyleUnit_Coord; + unsafe { *union.mInt.as_mut() = au.0; } + }, + LengthOrPercentageOrAuto::Percentage(p) => { + *unit = nsStyleUnit::eStyleUnit_Percent; + unsafe { *union.mFloat.as_mut() = p; } + }, + LengthOrPercentageOrAuto::Auto => { + *unit = nsStyleUnit::eStyleUnit_Auto; + unsafe { *union.mInt.as_mut() = 0; } + }, + LengthOrPercentageOrAuto::Calc(_) => unimplemented!(), + }; + } +}