mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
style: Use Rust types from transform-origin / perspective-origin.
Differential Revision: https://phabricator.services.mozilla.com/D20382
This commit is contained in:
parent
74d7d5bc42
commit
71daec59eb
4 changed files with 11 additions and 86 deletions
|
@ -91,6 +91,7 @@ include = [
|
||||||
"NonNegativeLengthOrNumberRect",
|
"NonNegativeLengthOrNumberRect",
|
||||||
"Perspective",
|
"Perspective",
|
||||||
"ZIndex",
|
"ZIndex",
|
||||||
|
"TransformOrigin",
|
||||||
]
|
]
|
||||||
item_types = ["enums", "structs", "typedefs"]
|
item_types = ["enums", "structs", "typedefs"]
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ item_types = ["enums", "structs", "typedefs"]
|
||||||
// Defined in nsStyleCoord.h
|
// Defined in nsStyleCoord.h
|
||||||
static constexpr inline StyleLengthPercentage Zero();
|
static constexpr inline StyleLengthPercentage Zero();
|
||||||
static inline StyleLengthPercentage FromAppUnits(nscoord);
|
static inline StyleLengthPercentage FromAppUnits(nscoord);
|
||||||
|
static inline StyleLengthPercentage FromPixels(CSSCoord);
|
||||||
static inline StyleLengthPercentage FromPercentage(float);
|
static inline StyleLengthPercentage FromPercentage(float);
|
||||||
inline CSSCoord LengthInCSSPixels() const;
|
inline CSSCoord LengthInCSSPixels() const;
|
||||||
inline float Percentage() const;
|
inline float Percentage() const;
|
||||||
|
|
|
@ -1188,55 +1188,6 @@ pub fn clone_transform_from_list(
|
||||||
}
|
}
|
||||||
</%def>
|
</%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. 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 let Some(third) = self.gecko.${gecko_ffi_name}.get_mut(2) {
|
|
||||||
third.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 let (Some(self_third), Some(other_third)) =
|
|
||||||
(self.gecko.${gecko_ffi_name}.get_mut(2), other.gecko.${gecko_ffi_name}.get(2))
|
|
||||||
{
|
|
||||||
self_third.copy_from(other_third)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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 crate::values::computed::{Length, LengthPercentage, TransformOrigin};
|
|
||||||
TransformOrigin {
|
|
||||||
horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0])
|
|
||||||
.expect("clone for LengthPercentage failed"),
|
|
||||||
vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1])
|
|
||||||
.expect("clone for LengthPercentage failed"),
|
|
||||||
depth: if let Some(third) = self.gecko.${gecko_ffi_name}.get(2) {
|
|
||||||
Length::from_gecko_style_coord(third)
|
|
||||||
.expect("clone for Length failed")
|
|
||||||
} else {
|
|
||||||
Length::new(0.)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%def>
|
|
||||||
|
|
||||||
<%def name="impl_logical(name, **kwargs)">
|
<%def name="impl_logical(name, **kwargs)">
|
||||||
${helpers.logical_setter(name)}
|
${helpers.logical_setter(name)}
|
||||||
</%def>
|
</%def>
|
||||||
|
@ -1385,7 +1336,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||||
"SVGPaint": impl_svg_paint,
|
"SVGPaint": impl_svg_paint,
|
||||||
"SVGWidth": impl_svg_length,
|
"SVGWidth": impl_svg_length,
|
||||||
"Transform": impl_transform,
|
"Transform": impl_transform,
|
||||||
"TransformOrigin": impl_transform_origin,
|
"TransformOrigin": impl_simple,
|
||||||
"UserSelect": impl_simple,
|
"UserSelect": impl_simple,
|
||||||
"url::UrlOrNone": impl_css_url,
|
"url::UrlOrNone": impl_css_url,
|
||||||
"ZIndex": impl_simple,
|
"ZIndex": impl_simple,
|
||||||
|
@ -2913,10 +2864,8 @@ fn static_assert() {
|
||||||
clear transition-duration transition-delay
|
clear transition-duration transition-delay
|
||||||
transition-timing-function transition-property
|
transition-timing-function transition-property
|
||||||
rotate scroll-snap-points-x scroll-snap-points-y
|
rotate scroll-snap-points-x scroll-snap-points-y
|
||||||
scroll-snap-coordinate
|
scroll-snap-coordinate -moz-binding will-change
|
||||||
perspective-origin -moz-binding will-change
|
offset-path shape-outside contain touch-action
|
||||||
offset-path perspective-origin -moz-binding
|
|
||||||
will-change shape-outside contain touch-action
|
|
||||||
translate scale""" %>
|
translate scale""" %>
|
||||||
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -3268,31 +3217,6 @@ fn static_assert() {
|
||||||
|
|
||||||
${impl_animation_timing_function()}
|
${impl_animation_timing_function()}
|
||||||
|
|
||||||
pub fn set_perspective_origin(&mut self, v: longhands::perspective_origin::computed_value::T) {
|
|
||||||
self.gecko.mPerspectiveOrigin[0].set(v.horizontal);
|
|
||||||
self.gecko.mPerspectiveOrigin[1].set(v.vertical);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_perspective_origin_from(&mut self, other: &Self) {
|
|
||||||
self.gecko.mPerspectiveOrigin[0].copy_from(&other.gecko.mPerspectiveOrigin[0]);
|
|
||||||
self.gecko.mPerspectiveOrigin[1].copy_from(&other.gecko.mPerspectiveOrigin[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset_perspective_origin(&mut self, other: &Self) {
|
|
||||||
self.copy_perspective_origin_from(other)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clone_perspective_origin(&self) -> longhands::perspective_origin::computed_value::T {
|
|
||||||
use crate::properties::longhands::perspective_origin::computed_value::T;
|
|
||||||
use crate::values::computed::LengthPercentage;
|
|
||||||
T {
|
|
||||||
horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[0])
|
|
||||||
.expect("Expected length or percentage for horizontal value of perspective-origin"),
|
|
||||||
vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[1])
|
|
||||||
.expect("Expected length or percentage for vertical value of perspective-origin"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
${impl_individual_transform('rotate', 'Rotate', 'mSpecifiedRotate')}
|
${impl_individual_transform('rotate', 'Rotate', 'mSpecifiedRotate')}
|
||||||
${impl_individual_transform('translate', 'Translate', 'mSpecifiedTranslate')}
|
${impl_individual_transform('translate', 'Translate', 'mSpecifiedTranslate')}
|
||||||
${impl_individual_transform('scale', 'Scale', 'mSpecifiedScale')}
|
${impl_individual_transform('scale', 'Scale', 'mSpecifiedScale')}
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub type TransformOperation =
|
||||||
pub type Transform = generic::Transform<TransformOperation>;
|
pub type Transform = generic::Transform<TransformOperation>;
|
||||||
|
|
||||||
/// The computed value of a CSS `<transform-origin>`
|
/// The computed value of a CSS `<transform-origin>`
|
||||||
pub type TransformOrigin = generic::TransformOrigin<LengthPercentage, LengthPercentage, Length>;
|
pub type TransformOrigin = generic::GenericTransformOrigin<LengthPercentage, LengthPercentage, Length>;
|
||||||
|
|
||||||
/// A vector to represent the direction vector (rotate axis) for Rotate3D.
|
/// A vector to represent the direction vector (rotate axis) for Rotate3D.
|
||||||
pub type DirectionVector = Vector3D<CSSFloat>;
|
pub type DirectionVector = Vector3D<CSSFloat>;
|
||||||
|
|
|
@ -83,7 +83,8 @@ impl<T: Into<f64>> From<Matrix3D<T>> for Transform3D<f64> {
|
||||||
ToComputedValue,
|
ToComputedValue,
|
||||||
ToCss,
|
ToCss,
|
||||||
)]
|
)]
|
||||||
pub struct TransformOrigin<H, V, Depth> {
|
#[repr(C)]
|
||||||
|
pub struct GenericTransformOrigin<H, V, Depth> {
|
||||||
/// The horizontal origin.
|
/// The horizontal origin.
|
||||||
pub horizontal: H,
|
pub horizontal: H,
|
||||||
/// The vertical origin.
|
/// The vertical origin.
|
||||||
|
@ -92,14 +93,12 @@ pub struct TransformOrigin<H, V, Depth> {
|
||||||
pub depth: Depth,
|
pub depth: Depth,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use self::GenericTransformOrigin as TransformOrigin;
|
||||||
|
|
||||||
impl<H, V, D> TransformOrigin<H, V, D> {
|
impl<H, V, D> TransformOrigin<H, V, D> {
|
||||||
/// Returns a new transform origin.
|
/// Returns a new transform origin.
|
||||||
pub fn new(horizontal: H, vertical: V, depth: D) -> Self {
|
pub fn new(horizontal: H, vertical: V, depth: D) -> Self {
|
||||||
Self {
|
Self { horizontal, vertical, depth }
|
||||||
horizontal: horizontal,
|
|
||||||
vertical: vertical,
|
|
||||||
depth: depth,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue