mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Implement Margin and Padding.
Note: We still need to handle the cached value stuff. I'll do that shortly.
This commit is contained in:
parent
9aab775e7c
commit
0982e6f237
3 changed files with 84 additions and 6 deletions
|
@ -42,6 +42,7 @@ mod gecko_style_structs;
|
||||||
pub mod glue;
|
pub mod glue;
|
||||||
mod selector_impl;
|
mod selector_impl;
|
||||||
mod traversal;
|
mod traversal;
|
||||||
|
mod values;
|
||||||
mod wrapper;
|
mod wrapper;
|
||||||
|
|
||||||
// Generated from the properties.mako.rs template by build.rs
|
// Generated from the properties.mako.rs template by build.rs
|
||||||
|
|
|
@ -28,6 +28,8 @@ use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues};
|
||||||
use style::properties::longhands;
|
use style::properties::longhands;
|
||||||
use style::properties::make_cascade_vec;
|
use style::properties::make_cascade_vec;
|
||||||
use style::properties::style_struct_traits::*;
|
use style::properties::style_struct_traits::*;
|
||||||
|
use gecko_style_structs::{nsStyleUnion, nsStyleUnit};
|
||||||
|
use values::ToGeckoStyleCoord;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GeckoComputedValues {
|
pub struct GeckoComputedValues {
|
||||||
|
@ -196,6 +198,20 @@ def set_gecko_property(ffi_name, expr):
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%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)">
|
<%def name="impl_style_struct(style_struct)">
|
||||||
impl ${style_struct.gecko_struct_name} {
|
impl ${style_struct.gecko_struct_name} {
|
||||||
#[allow(dead_code, unused_variables)]
|
#[allow(dead_code, unused_variables)]
|
||||||
|
@ -340,12 +356,7 @@ fn static_assert() {
|
||||||
<% border_style_keyword = Keyword("border-style",
|
<% border_style_keyword = Keyword("border-style",
|
||||||
"none solid double dotted dashed hidden groove ridge inset outset") %>
|
"none solid double dotted dashed hidden groove ridge inset outset") %>
|
||||||
|
|
||||||
<%
|
<% skip_border_longhands = " ".join(["border-{0}-style border-{0}-width ".format(x.ident) for x in SIDES]) %>
|
||||||
skip_border_longhands = ""
|
|
||||||
for side in SIDES:
|
|
||||||
skip_border_longhands += "border-{0}-style border-{0}-width ".format(side.ident)
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Border"
|
<%self:impl_trait style_struct_name="Border"
|
||||||
skip_longhands="${skip_border_longhands}"
|
skip_longhands="${skip_border_longhands}"
|
||||||
skip_additionals="*">
|
skip_additionals="*">
|
||||||
|
@ -362,6 +373,26 @@ for side in SIDES:
|
||||||
% endfor
|
% endfor
|
||||||
</%self:impl_trait>
|
</%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"
|
<%self:impl_trait style_struct_name="Outline"
|
||||||
skip_longhands="outline-style"
|
skip_longhands="outline-style"
|
||||||
skip_additionals="*">
|
skip_additionals="*">
|
||||||
|
|
46
ports/geckolib/values.rs
Normal file
46
ports/geckolib/values.rs
Normal 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!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue