diff options
author | Martin Robinson <mrobinson@igalia.com> | 2020-02-19 09:46:09 +0100 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2020-02-21 17:07:09 +0100 |
commit | 80b29380f144e4693a45487a966d7044cd0f5b6f (patch) | |
tree | b4a2262cdc7a049a1832e1e1821e2e4bcae7b88c /components/style/values/generics/transform.rs | |
parent | 9a760cfc02e619084690cc1cab77a3406ae822e9 (diff) | |
download | servo-80b29380f144e4693a45487a966d7044cd0f5b6f.tar.gz servo-80b29380f144e4693a45487a966d7044cd0f5b6f.zip |
Add layout_2020 support for transformations
Diffstat (limited to 'components/style/values/generics/transform.rs')
-rw-r--r-- | components/style/values/generics/transform.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 26e54ab8df4..b77bba40b82 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -11,7 +11,6 @@ use crate::values::specified::length::Length as SpecifiedLength; use crate::values::specified::length::LengthPercentage as SpecifiedLengthPercentage; use crate::values::{computed, CSSFloat}; use crate::Zero; -use app_units::Au; use euclid; use euclid::default::{Rect, Transform3D}; use std::fmt::{self, Write}; @@ -329,7 +328,7 @@ where /// Convert a length type into the absolute lengths. pub trait ToAbsoluteLength { /// Returns the absolute length as pixel value. - fn to_pixel_length(&self, containing_len: Option<Au>) -> Result<CSSFloat, ()>; + fn to_pixel_length(&self, containing_len: Option<ComputedLength>) -> Result<CSSFloat, ()>; } impl ToAbsoluteLength for SpecifiedLength { @@ -337,7 +336,7 @@ impl ToAbsoluteLength for SpecifiedLength { // parsing a transform list of DOMMatrix because we want to return a DOM Exception // if there is relative length. #[inline] - fn to_pixel_length(&self, _containing_len: Option<Au>) -> Result<CSSFloat, ()> { + fn to_pixel_length(&self, _containing_len: Option<ComputedLength>) -> Result<CSSFloat, ()> { match *self { SpecifiedLength::NoCalc(len) => len.to_computed_pixel_length_without_context(), SpecifiedLength::Calc(ref calc) => calc.to_computed_pixel_length_without_context(), @@ -350,7 +349,7 @@ impl ToAbsoluteLength for SpecifiedLengthPercentage { // parsing a transform list of DOMMatrix because we want to return a DOM Exception // if there is relative length. #[inline] - fn to_pixel_length(&self, _containing_len: Option<Au>) -> Result<CSSFloat, ()> { + fn to_pixel_length(&self, _containing_len: Option<ComputedLength>) -> Result<CSSFloat, ()> { use self::SpecifiedLengthPercentage::*; match *self { Length(len) => len.to_computed_pixel_length_without_context(), @@ -362,16 +361,16 @@ impl ToAbsoluteLength for SpecifiedLengthPercentage { impl ToAbsoluteLength for ComputedLength { #[inline] - fn to_pixel_length(&self, _containing_len: Option<Au>) -> Result<CSSFloat, ()> { + fn to_pixel_length(&self, _containing_len: Option<ComputedLength>) -> Result<CSSFloat, ()> { Ok(self.px()) } } impl ToAbsoluteLength for ComputedLengthPercentage { #[inline] - fn to_pixel_length(&self, containing_len: Option<Au>) -> Result<CSSFloat, ()> { + fn to_pixel_length(&self, containing_len: Option<ComputedLength>) -> Result<CSSFloat, ()> { match containing_len { - Some(relative_len) => Ok(self.to_pixel_length(relative_len).px()), + Some(relative_len) => Ok(self.resolve(relative_len).px()), // If we don't have reference box, we cannot resolve the used value, // so only retrieve the length part. This will be used for computing // distance without any layout info. @@ -388,7 +387,10 @@ pub trait ToMatrix { fn is_3d(&self) -> bool; /// Return the equivalent 3d matrix. - fn to_3d_matrix(&self, reference_box: Option<&Rect<Au>>) -> Result<Transform3D<f64>, ()>; + fn to_3d_matrix( + &self, + reference_box: Option<&Rect<ComputedLength>>, + ) -> Result<Transform3D<f64>, ()>; } /// A little helper to deal with both specified and computed angles. @@ -434,7 +436,10 @@ where /// However, for specified TransformOperation, we will return Err(()) if there is any relative /// lengths because the only caller, DOMMatrix, doesn't accept relative lengths. #[inline] - fn to_3d_matrix(&self, reference_box: Option<&Rect<Au>>) -> Result<Transform3D<f64>, ()> { + fn to_3d_matrix( + &self, + reference_box: Option<&Rect<ComputedLength>>, + ) -> Result<Transform3D<f64>, ()> { use self::TransformOperation::*; use std::f64; @@ -537,7 +542,7 @@ impl<T: ToMatrix> Transform<T> { #[cfg_attr(rustfmt, rustfmt_skip)] pub fn to_transform_3d_matrix( &self, - reference_box: Option<&Rect<Au>> + reference_box: Option<&Rect<ComputedLength>> ) -> Result<(Transform3D<CSSFloat>, bool), ()> { let cast_3d_transform = |m: Transform3D<f64>| -> Transform3D<CSSFloat> { use std::{f32, f64}; @@ -557,7 +562,7 @@ impl<T: ToMatrix> Transform<T> { /// Same as Transform::to_transform_3d_matrix but a f64 version. pub fn to_transform_3d_matrix_f64( &self, - reference_box: Option<&Rect<Au>>, + reference_box: Option<&Rect<ComputedLength>>, ) -> Result<(Transform3D<f64>, bool), ()> { // We intentionally use Transform3D<f64> during computation to avoid error propagation // because using f32 to compute triangle functions (e.g. in create_rotation()) is not |