Implement Margin and Padding.

Note: We still need to handle the cached value stuff. I'll do that shortly.
This commit is contained in:
Bobby Holley 2016-04-29 18:25:49 -07:00
parent 9aab775e7c
commit 0982e6f237
3 changed files with 84 additions and 6 deletions

View file

@ -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

View file

@ -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>
<%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>
<%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
</%self:impl_trait>
<% 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
</%self:impl_trait>
<% 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>
<%self:impl_trait style_struct_name="Outline"
skip_longhands="outline-style"
skip_additionals="*">

46
ports/geckolib/values.rs Normal file
View file

@ -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!(),
};
}
}