mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Use cbindgen for border-image-width.
Differential Revision: https://phabricator.services.mozilla.com/D32032
This commit is contained in:
parent
af8e8e6a34
commit
44926adde7
5 changed files with 9 additions and 82 deletions
|
@ -718,23 +718,6 @@ def set_gecko_property(ffi_name, expr):
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_style_sides(ident)">
|
||||
<% gecko_ffi_name = "m" + to_camel_case(ident) %>
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
v.to_gecko_rect(&mut self.gecko.${gecko_ffi_name});
|
||||
}
|
||||
|
||||
<%self:copy_sides_style_coord ident="${ident}"></%self:copy_sides_style_coord>
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||
longhands::${ident}::computed_value::T::from_gecko_rect(&self.gecko.${gecko_ffi_name})
|
||||
.expect("clone for ${ident} failed")
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="copy_sides_style_coord(ident)">
|
||||
<% gecko_ffi_name = "m" + to_camel_case(ident) %>
|
||||
#[allow(non_snake_case)]
|
||||
|
@ -989,7 +972,7 @@ fn static_assert() {
|
|||
|
||||
<%self:impl_trait style_struct_name="Border"
|
||||
skip_longhands="${skip_border_longhands} border-image-source
|
||||
border-image-repeat border-image-width">
|
||||
border-image-repeat">
|
||||
% for side in SIDES:
|
||||
pub fn set_border_${side.ident}_style(&mut self, v: BorderStyle) {
|
||||
self.gecko.mBorderStyle[${side.index}] = v;
|
||||
|
@ -1128,8 +1111,6 @@ fn static_assert() {
|
|||
% endfor
|
||||
longhands::border_image_repeat::computed_value::T(servo_h, servo_v)
|
||||
}
|
||||
|
||||
<% impl_style_sides("border_image_width") %>
|
||||
</%self:impl_trait>
|
||||
|
||||
<% skip_scroll_margin_longhands = " ".join(["scroll-margin-%s" % x.ident for x in SIDES]) %>
|
||||
|
|
|
@ -159,60 +159,3 @@ ${helpers.predefined_type(
|
|||
flags="APPLIES_TO_FIRST_LETTER",
|
||||
boxed=True,
|
||||
)}
|
||||
|
||||
// FIXME(emilio): Why does this live here? ;_;
|
||||
#[cfg(feature = "gecko")]
|
||||
impl crate::values::computed::BorderImageWidth {
|
||||
pub fn to_gecko_rect(&self, sides: &mut crate::gecko_bindings::structs::nsStyleSides) {
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataMut, CoordDataValue};
|
||||
use crate::gecko::values::GeckoStyleCoordConvertible;
|
||||
use crate::values::generics::border::BorderImageSideWidth;
|
||||
|
||||
% for i in range(0, 4):
|
||||
match self.${i} {
|
||||
BorderImageSideWidth::Auto => {
|
||||
sides.data_at_mut(${i}).set_value(CoordDataValue::Auto)
|
||||
},
|
||||
BorderImageSideWidth::Length(l) => {
|
||||
l.to_gecko_style_coord(&mut sides.data_at_mut(${i}))
|
||||
},
|
||||
BorderImageSideWidth::Number(n) => {
|
||||
sides.data_at_mut(${i}).set_value(CoordDataValue::Factor(n.0))
|
||||
},
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
|
||||
pub fn from_gecko_rect(
|
||||
sides: &crate::gecko_bindings::structs::nsStyleSides,
|
||||
) -> Option<crate::values::computed::BorderImageWidth> {
|
||||
use crate::gecko_bindings::structs::nsStyleUnit::{eStyleUnit_Factor, eStyleUnit_Auto};
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::CoordData;
|
||||
use crate::gecko::values::GeckoStyleCoordConvertible;
|
||||
use crate::values::computed::{LengthPercentage, Number};
|
||||
use crate::values::generics::border::BorderImageSideWidth;
|
||||
use crate::values::generics::NonNegative;
|
||||
|
||||
Some(
|
||||
crate::values::computed::BorderImageWidth::new(
|
||||
% for i in range(0, 4):
|
||||
match sides.data_at(${i}).unit() {
|
||||
eStyleUnit_Auto => {
|
||||
BorderImageSideWidth::Auto
|
||||
},
|
||||
eStyleUnit_Factor => {
|
||||
BorderImageSideWidth::Number(
|
||||
NonNegative(Number::from_gecko_style_coord(&sides.data_at(${i}))
|
||||
.expect("sides[${i}] could not convert to Number")))
|
||||
},
|
||||
_ => {
|
||||
BorderImageSideWidth::Length(
|
||||
NonNegative(LengthPercentage::from_gecko_style_coord(&sides.data_at(${i}))
|
||||
.expect("sides[${i}] could not convert to LengthPercentage")))
|
||||
},
|
||||
},
|
||||
% endfor
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use crate::values::computed::length::{NonNegativeLength, NonNegativeLengthPercentage};
|
||||
use crate::values::computed::{NonNegativeNumber, NonNegativeNumberOrPercentage};
|
||||
use crate::values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||
use crate::values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
|
||||
use crate::values::generics::border::GenericBorderImageSideWidth;
|
||||
use crate::values::generics::border::BorderImageSlice as GenericBorderImageSlice;
|
||||
use crate::values::generics::border::BorderRadius as GenericBorderRadius;
|
||||
use crate::values::generics::border::BorderSpacing as GenericBorderSpacing;
|
||||
|
|
|
@ -23,15 +23,18 @@ use style_traits::{CssWriter, ToCss};
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum BorderImageSideWidth<LengthPercentage, Number> {
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericBorderImageSideWidth<LP, N> {
|
||||
/// `<length-or-percentage>`
|
||||
Length(LengthPercentage),
|
||||
LengthPercentage(LP),
|
||||
/// `<number>`
|
||||
Number(Number),
|
||||
Number(N),
|
||||
/// `auto`
|
||||
Auto,
|
||||
}
|
||||
|
||||
pub use self::GenericBorderImageSideWidth as BorderImageSideWidth;
|
||||
|
||||
/// A generic value for the `border-image-slice` property.
|
||||
#[derive(
|
||||
Clone,
|
||||
|
|
|
@ -183,7 +183,7 @@ impl Parse for BorderImageSideWidth {
|
|||
}
|
||||
|
||||
if let Ok(len) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
return Ok(GenericBorderImageSideWidth::Length(len));
|
||||
return Ok(GenericBorderImageSideWidth::LengthPercentage(len));
|
||||
}
|
||||
|
||||
let num = NonNegativeNumber::parse(context, input)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue