Skip to content

Commit

Permalink
Add general impl in gecko_properties for TransformOrigin value and ad…
Browse files Browse the repository at this point in the history
…d -moz-window-transform-origin.
  • Loading branch information
upsuper committed Nov 12, 2017
1 parent dfbf632 commit 79ea639
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 30 deletions.
81 changes: 51 additions & 30 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1324,6 +1324,55 @@ pub fn clone_transform_from_list(
}
</%def>

<%def name="impl_transform_origin(ident, gecko_ffi_name)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: values::computed::TransformOrigin) {
self.gecko.${gecko_ffi_name}[0].set(v.horizontal);
self.gecko.${gecko_ffi_name}[1].set(v.vertical);
// transform-origin supports the third value for depth, while
// -moz-window-transform-origin doesn't. The following code is
// for handling this difference. Rust (incorrectly) generates
// an unsuppressible warning, but we know it's safe here.
// See rust-lang/rust#45850. Also if we can have more knowledge
// about the type here, we may want to check that the length is
// exactly either 2 or 3 in compile time.
if self.gecko.${gecko_ffi_name}.len() == 3 {
self.gecko.${gecko_ffi_name}[2].set(v.depth);
}
}

#[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name}[0].copy_from(&other.gecko.${gecko_ffi_name}[0]);
self.gecko.${gecko_ffi_name}[1].copy_from(&other.gecko.${gecko_ffi_name}[1]);
if self.gecko.${gecko_ffi_name}.len() == 3 {
self.gecko.${gecko_ffi_name}[2].copy_from(&other.gecko.${gecko_ffi_name}[2]);
}
}

#[allow(non_snake_case)]
pub fn reset_${ident}(&mut self, other: &Self) {
self.copy_${ident}_from(other)
}

#[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> values::computed::TransformOrigin {
use values::computed::{Length, LengthOrPercentage, TransformOrigin};
TransformOrigin {
horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0])
.expect("clone for LengthOrPercentage failed"),
vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1])
.expect("clone for LengthOrPercentage failed"),
depth: if self.gecko.${gecko_ffi_name}.len() == 3 {
Length::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[2])
.expect("clone for Length failed")
} else {
Length::new(0.)
},
}
}
</%def>

<%def name="impl_logical(name, **kwargs)">
${helpers.logical_setter(name)}
</%def>
Expand Down Expand Up @@ -1477,6 +1526,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
"SVGPaint": impl_svg_paint,
"SVGWidth": impl_svg_length,
"Transform": impl_transform,
"TransformOrigin": impl_transform_origin,
"UrlOrNone": impl_css_url,
}

Expand Down Expand Up @@ -3047,7 +3097,7 @@ fn static_assert() {
page-break-before page-break-after
scroll-snap-points-x scroll-snap-points-y
scroll-snap-type-x scroll-snap-type-y scroll-snap-coordinate
perspective-origin transform-origin -moz-binding will-change
perspective-origin -moz-binding will-change
shape-outside contain touch-action""" %>
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">

Expand Down Expand Up @@ -3460,35 +3510,6 @@ fn static_assert() {
}
}

pub fn set_transform_origin(&mut self, v: longhands::transform_origin::computed_value::T) {
self.gecko.mTransformOrigin[0].set(v.horizontal);
self.gecko.mTransformOrigin[1].set(v.vertical);
self.gecko.mTransformOrigin[2].set(v.depth);
}

pub fn copy_transform_origin_from(&mut self, other: &Self) {
self.gecko.mTransformOrigin[0].copy_from(&other.gecko.mTransformOrigin[0]);
self.gecko.mTransformOrigin[1].copy_from(&other.gecko.mTransformOrigin[1]);
self.gecko.mTransformOrigin[2].copy_from(&other.gecko.mTransformOrigin[2]);
}

pub fn reset_transform_origin(&mut self, other: &Self) {
self.copy_transform_origin_from(other)
}

pub fn clone_transform_origin(&self) -> longhands::transform_origin::computed_value::T {
use properties::longhands::transform_origin::computed_value::T;
use values::computed::{Length, LengthOrPercentage};
T {
horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mTransformOrigin[0])
.expect("clone for LengthOrPercentage failed"),
vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mTransformOrigin[1])
.expect("clone for LengthOrPercentage failed"),
depth: Length::from_gecko_style_coord(&self.gecko.mTransformOrigin[2])
.expect("clone for Length failed"),
}
}

pub fn set_will_change(&mut self, v: longhands::will_change::computed_value::T) {
use gecko_bindings::bindings::{Gecko_AppendWillChange, Gecko_ClearWillChange};
use gecko_bindings::structs::NS_STYLE_WILL_CHANGE_OPACITY;
Expand Down
1 change: 1 addition & 0 deletions components/style/properties/longhand/box.mako.rs
Expand Up @@ -684,6 +684,7 @@ ${helpers.predefined_type("transform-origin",
"computed::TransformOrigin::initial_value()",
animation_value_type="ComputedValue",
extra_prefixes="moz webkit",
gecko_ffi_name="mTransformOrigin",
boxed=True,
spec="https://drafts.csswg.org/css-transforms/#transform-origin-property")}

Expand Down
10 changes: 10 additions & 0 deletions components/style/properties/longhand/ui.mako.rs
Expand Up @@ -53,6 +53,16 @@ ${helpers.predefined_type("-moz-window-transform", "Transform",
internal=True,
spec="None (Nonstandard internal property)")}

${helpers.predefined_type("-moz-window-transform-origin",
"TransformOrigin",
"computed::TransformOrigin::initial_value()",
animation_value_type="ComputedValue",
gecko_ffi_name="mWindowTransformOrigin",
products="gecko",
boxed=True,
internal=True,
spec="None (Nonstandard internal property)")}

<%helpers:longhand name="-moz-force-broken-image-icon"
products="gecko"
animation_value_type="discrete"
Expand Down

0 comments on commit 79ea639

Please sign in to comment.