Auto merge of #11001 - heycam:alnp, r=bholley

Support most remaining length/percentage/none/auto-taking properties in geckolib

This is on top of #10999 so no need to review 8ae820b.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11001)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-05 00:44:57 -07:00
commit 319f520e4d
2 changed files with 61 additions and 18 deletions

View file

@ -267,7 +267,7 @@ def set_gecko_property(ffi_name, expr):
% endif
</%def>
<%def name="impl_style_coord(ident, unit_ffi_name, union_ffi_name)">
<%def name="impl_split_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});
@ -281,6 +281,10 @@ def set_gecko_property(ffi_name, expr):
}
</%def>
<%def name="impl_style_coord(ident, gecko_ffi_name)">
<%call expr="impl_split_style_coord(ident, '%s.mUnit' % gecko_ffi_name, '%s.mValue' % gecko_ffi_name)"></%call>
</%def>
<%def name="impl_style_struct(style_struct)">
impl ${style_struct.gecko_struct_name} {
#[allow(dead_code, unused_variables)]
@ -354,14 +358,19 @@ impl Debug for ${style_struct.gecko_ffi_name} {
# These are booleans.
force_stub += ["page-break-after", "page-break-before"]
simple_types = ["Number", "Opacity"]
# Types used with predefined_type()-defined properties that we can auto-generate.
predefined_types = {
"LengthOrPercentage": impl_style_coord,
"LengthOrPercentageOrAuto": impl_style_coord,
"LengthOrPercentageOrNone": impl_style_coord,
"Number": impl_simple,
"Opacity": impl_simple,
}
keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub]
simple_longhands = [x for x in longhands
if x.predefined_type in simple_types and not x.name in force_stub]
autogenerated_longhands = keyword_longhands + simple_longhands
stub_longhands = [x for x in longhands if x not in autogenerated_longhands]
predefined_longhands = [x for x in longhands
if x.predefined_type in predefined_types and not x.name in force_stub]
stub_longhands = [x for x in longhands if x not in keyword_longhands + predefined_longhands]
%>
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
/*
@ -372,12 +381,13 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
/*
* Auto-Generated Methods.
*/
% for longhand in keyword_longhands:
<%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"></%call>
% endfor
% for longhand in simple_longhands:
<%call expr="impl_simple(longhand.ident, longhand.gecko_ffi_name)"></%call>
% endfor
<%
for longhand in keyword_longhands:
impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)
for longhand in predefined_longhands:
impl_fn = predefined_types[longhand.predefined_type]
impl_fn(longhand.ident, longhand.gecko_ffi_name)
%>
/*
* Stubs.
@ -461,8 +471,9 @@ fn static_assert() {
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) %>
<% impl_split_style_coord("margin_%s" % side.ident,
"mMargin.mUnits[%s]" % side.index,
"mMargin.mValues[%s]" % side.index) %>
% endfor
</%self:impl_trait>
@ -471,8 +482,20 @@ fn static_assert() {
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) %>
<% impl_split_style_coord("padding_%s" % side.ident,
"mPadding.mUnits[%s]" % side.index,
"mPadding.mValues[%s]" % side.index) %>
% endfor
</%self:impl_trait>
<% skip_position_longhands = " ".join(x.ident for x in SIDES) %>
<%self:impl_trait style_struct_name="Position"
skip_longhands="${skip_position_longhands}">
% for side in SIDES:
<% impl_split_style_coord("%s" % side.ident,
"mOffset.mUnits[%s]" % side.index,
"mOffset.mValues[%s]" % side.index) %>
% endfor
</%self:impl_trait>

View file

@ -4,7 +4,7 @@
use cssparser::RGBA;
use gecko_style_structs::{nsStyleUnion, nsStyleUnit};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
pub trait ToGeckoStyleCoord {
fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion);
@ -46,6 +46,26 @@ impl ToGeckoStyleCoord for LengthOrPercentageOrAuto {
}
}
impl ToGeckoStyleCoord for LengthOrPercentageOrNone {
fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) {
match *self {
LengthOrPercentageOrNone::Length(au) => {
*unit = nsStyleUnit::eStyleUnit_Coord;
unsafe { *union.mInt.as_mut() = au.0; }
},
LengthOrPercentageOrNone::Percentage(p) => {
*unit = nsStyleUnit::eStyleUnit_Percent;
unsafe { *union.mFloat.as_mut() = p; }
},
LengthOrPercentageOrNone::None => {
*unit = nsStyleUnit::eStyleUnit_None;
unsafe { *union.mInt.as_mut() = 0; }
},
LengthOrPercentageOrNone::Calc(_) => unimplemented!(),
};
}
}
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
(((rgba.alpha * 255.0).round() as u32) << 24) |
(((rgba.blue * 255.0).round() as u32) << 16) |