Skip to content

Commit

Permalink
add support for mask_position_parse/serial
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmiywj committed Feb 4, 2017
1 parent 725b805 commit eb115e0
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 182 deletions.
117 changes: 25 additions & 92 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1683,72 +1683,56 @@ fn static_assert() {
}
</%self:simple_image_array_property>

% if shorthand != "background":
pub fn copy_${shorthand}_position_from(&mut self, other: &Self) {
% for orientation in [("x", "Horizontal"), ("y", "Vertical")]:
pub fn copy_${shorthand}_position_${orientation[0]}_from(&mut self, other: &Self) {
use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;

self.gecko.${image_layers_field}.mPositionXCount
= cmp::min(1, other.gecko.${image_layers_field}.mPositionXCount);
self.gecko.${image_layers_field}.mPositionYCount
= cmp::min(1, other.gecko.${image_layers_field}.mPositionYCount);
self.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count
= cmp::min(1, other.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count);
self.gecko.${image_layers_field}.mLayers.mFirstElement.mPosition =
other.gecko.${image_layers_field}.mLayers.mFirstElement.mPosition;
unsafe {
Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
other.gecko.${image_layers_field}.mLayers.len(),
LayerType::${shorthand.title()});
}
for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
.zip(other.gecko.${image_layers_field}.mLayers.iter())
.take(other.gecko.${image_layers_field}.mPositionXCount as usize) {
layer.mPosition.mXPosition
= other.mPosition.mXPosition;
LayerType::${shorthand.capitalize()});
}

for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
.zip(other.gecko.${image_layers_field}.mLayers.iter())
.take(other.gecko.${image_layers_field}.mPositionYCount as usize) {
layer.mPosition.mYPosition
= other.mPosition.mYPosition;
.zip(other.gecko.${image_layers_field}.mLayers.iter()) {
layer.mPosition.m${orientation[0].upper()}Position
= other.mPosition.m${orientation[0].upper()}Position;
}
self.gecko.${image_layers_field}.mPositionXCount
= other.gecko.${image_layers_field}.mPositionXCount;
self.gecko.${image_layers_field}.mPositionYCount
= other.gecko.${image_layers_field}.mPositionYCount;
self.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count
= other.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count;
}

pub fn clone_${shorthand}_position(&self)
-> longhands::${shorthand}_position::computed_value::T {
use values::computed::position::Position;
longhands::${shorthand}_position::computed_value::T(
pub fn clone_${shorthand}_position_${orientation[0]}(&self)
-> longhands::${shorthand}_position_${orientation[0]}::computed_value::T {
use values::computed::position::${orientation[1]}Position;
longhands::${shorthand}_position_${orientation[0]}::computed_value::T(
self.gecko.${image_layers_field}.mLayers.iter()
.take(self.gecko.${image_layers_field}.mPositionXCount as usize)
.take(self.gecko.${image_layers_field}.mPositionYCount as usize)
.map(|position| Position {
horizontal: position.mPosition.mXPosition.into(),
vertical: position.mPosition.mYPosition.into(),
})
.take(self.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count as usize)
.map(|position| ${orientation[1]}Position(position.mPosition.m${orientation[0].upper()}Position.into()))
.collect()
)
}

pub fn set_${shorthand}_position(&mut self,
v: longhands::${shorthand}_position::computed_value::T) {
pub fn set_${shorthand}_position_${orientation[0]}(&mut self,
v: longhands::${shorthand}_position_${orientation[0]}::computed_value::T) {
use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;

unsafe {
Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, v.0.len(),
LayerType::${shorthand.title()});
Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, v.0.len(),
LayerType::${shorthand.capitalize()});
}

self.gecko.${image_layers_field}.mPositionXCount = v.0.len() as u32;
self.gecko.${image_layers_field}.mPositionYCount = v.0.len() as u32;
self.gecko.${image_layers_field}.mPosition${orientation[0].upper()}Count = v.0.len() as u32;
for (servo, geckolayer) in v.0.into_iter().zip(self.gecko.${image_layers_field}
.mLayers.iter_mut()) {
geckolayer.mPosition.mXPosition = servo.horizontal.into();
geckolayer.mPosition.mYPosition = servo.vertical.into();
geckolayer.mPosition.m${orientation[0].upper()}Position = servo.0.into();
}
}
% endif
% endfor

<%self:simple_image_array_property name="size" shorthand="${shorthand}" field_name="mSize">
use gecko_bindings::structs::nsStyleImageLayers_Size_Dimension;
Expand Down Expand Up @@ -1938,56 +1922,6 @@ fn static_assert() {
T::luminosity => structs::NS_STYLE_BLEND_LUMINOSITY as u8,
}
</%self:simple_image_array_property>

% for orientation in [("x", "Horizontal"), ("y", "Vertical")]:
pub fn copy_background_position_${orientation[0]}_from(&mut self, other: &Self) {
use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;

self.gecko.mImage.mPosition${orientation[0].upper()}Count
= cmp::min(1, other.gecko.mImage.mPosition${orientation[0].upper()}Count);
self.gecko.mImage.mLayers.mFirstElement.mPosition =
other.gecko.mImage.mLayers.mFirstElement.mPosition;
unsafe {
Gecko_EnsureImageLayersLength(&mut self.gecko.mImage,
other.gecko.mImage.mLayers.len(),
LayerType::Background);
}
for (layer, other) in self.gecko.mImage.mLayers.iter_mut()
.zip(other.gecko.mImage.mLayers.iter()) {
layer.mPosition.m${orientation[0].upper()}Position
= other.mPosition.m${orientation[0].upper()}Position;
}
self.gecko.mImage.mPosition${orientation[0].upper()}Count
= other.gecko.mImage.mPosition${orientation[0].upper()}Count;
}

pub fn clone_background_position_${orientation[0]}(&self)
-> longhands::background_position_${orientation[0]}::computed_value::T {
use values::computed::position::${orientation[1]}Position;
longhands::background_position_${orientation[0]}::computed_value::T(
self.gecko.mImage.mLayers.iter()
.take(self.gecko.mImage.mPosition${orientation[0].upper()}Count as usize)
.map(|position| ${orientation[1]}Position(position.mPosition.m${orientation[0].upper()}Position.into()))
.collect()
)
}

pub fn set_background_position_${orientation[0]}(&mut self,
v: longhands::background_position_${orientation[0]}::computed_value::T) {
use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;

unsafe {
Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, v.0.len(),
LayerType::Background);
}

self.gecko.mImage.mPosition${orientation[0].upper()}Count = v.0.len() as u32;
for (servo, geckolayer) in v.0.into_iter().zip(self.gecko.mImage
.mLayers.iter_mut()) {
geckolayer.mPosition.m${orientation[0].upper()}Position = servo.0.into();
}
}
% endfor
</%self:impl_trait>

<%self:impl_trait style_struct_name="List"
Expand Down Expand Up @@ -2471,7 +2405,7 @@ fn static_assert() {
</%self:impl_trait>

<% skip_svg_longhands = """
mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position mask-size mask-image
mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-position-y mask-size mask-image
clip-path
"""
%>
Expand Down Expand Up @@ -2633,7 +2567,6 @@ clip-path
}
}
}

</%self:impl_trait>

<%self:impl_trait style_struct_name="Color"
Expand Down
77 changes: 32 additions & 45 deletions components/style/properties/longhand/svg.mako.rs
Expand Up @@ -103,59 +103,46 @@ ${helpers.single_keyword("mask-repeat",
animatable=False,
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat")}

<%helpers:vector_longhand name="mask-position" products="gecko" animatable="True" extra_prefixes="webkit"
<%helpers:vector_longhand name="mask-position-x" products="gecko" animatable="True" extra_prefixes="webkit"
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-position">
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::specified::position::Position;

pub mod computed_value {
use values::computed::position::Position;
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
use properties::longhands::mask_position::computed_value::T as MaskPosition;

pub type T = Position;

impl RepeatableListInterpolate for MaskPosition {}

impl Interpolate for MaskPosition {
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
Ok(MaskPosition(try!(self.0.interpolate(&other.0, progress))))
}
pub use properties::longhands::background_position_x::single_value::get_initial_value;
pub use properties::longhands::background_position_x::single_value::get_initial_position_value;
pub use properties::longhands::background_position_x::single_value::get_initial_specified_value;
pub use properties::longhands::background_position_x::single_value::parse;
pub use properties::longhands::background_position_x::single_value::SpecifiedValue;
pub use properties::longhands::background_position_x::single_value::computed_value;
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
use properties::longhands::mask_position_x::computed_value::T as MaskPositionX;

impl Interpolate for MaskPositionX {
#[inline]
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
Ok(MaskPositionX(try!(self.0.interpolate(&other.0, progress))))
}
}

pub type SpecifiedValue = Position;
impl RepeatableListInterpolate for MaskPositionX {}
</%helpers:vector_longhand>

#[inline]
pub fn get_initial_value() -> computed_value::T {
use values::computed::position::Position;
Position {
horizontal: computed::LengthOrPercentage::Percentage(0.0),
vertical: computed::LengthOrPercentage::Percentage(0.0),
}
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
use values::specified::Percentage;
use values::specified::position::{HorizontalPosition, VerticalPosition};
Position {
horizontal: HorizontalPosition {
keyword: None,
position: Some(specified::LengthOrPercentage::Percentage(Percentage(0.0))),
},
vertical: VerticalPosition {
keyword: None,
position: Some(specified::LengthOrPercentage::Percentage(Percentage(0.0))),
},
<%helpers:vector_longhand name="mask-position-y" products="gecko" animatable="True" extra_prefixes="webkit"
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-position">
pub use properties::longhands::background_position_y::single_value::get_initial_value;
pub use properties::longhands::background_position_y::single_value::get_initial_position_value;
pub use properties::longhands::background_position_y::single_value::get_initial_specified_value;
pub use properties::longhands::background_position_y::single_value::parse;
pub use properties::longhands::background_position_y::single_value::SpecifiedValue;
pub use properties::longhands::background_position_y::single_value::computed_value;
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
use properties::longhands::mask_position_y::computed_value::T as MaskPositionY;

impl Interpolate for MaskPositionY {
#[inline]
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
Ok(MaskPositionY(try!(self.0.interpolate(&other.0, progress))))
}
}

pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
Position::parse(context, input)
}
impl RepeatableListInterpolate for MaskPositionY {}
</%helpers:vector_longhand>

${helpers.single_keyword("mask-clip",
Expand Down

0 comments on commit eb115e0

Please sign in to comment.