Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make transforms generic #18750

Merged
merged 21 commits into from Nov 2, 2017
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
337d48a
Add generic struct for transform
Manishearth Oct 3, 2017
dcefcc3
Add ToComputedValue and ToCss impls
Manishearth Oct 3, 2017
d6525e0
Add specified and computed variants of Transform/TransformOperation
Manishearth Oct 3, 2017
5449898
Add parsing support for transform
Manishearth Oct 3, 2017
5031d14
Use a generic Matrix3D type
Manishearth Oct 3, 2017
2de3464
Add ToAnimatedZero implementation
Manishearth Oct 3, 2017
5ce2966
Add utilities for converting Transform to euclid types
Manishearth Oct 4, 2017
6631594
Replace old transform code with new generic code
Manishearth Oct 4, 2017
079b25d
Share transform function lists between set_transform and clone_transform
Manishearth Oct 4, 2017
fc29de8
Add support for more functions in Gecko glue
Manishearth Oct 6, 2017
e20c508
Add support for 2D matrices in Gecko glue
Manishearth Oct 30, 2017
e156952
Add support for transform functions with an optional final argument i…
Manishearth Oct 30, 2017
aba00be
Add more operations to animation
Manishearth Oct 30, 2017
f699b8c
Handle animating 2D matrices
Manishearth Oct 31, 2017
9c9a181
Allow cross interpolation between differing translate/scale functions
Manishearth Oct 31, 2017
ca02785
Handle case of empty transform lists
Manishearth Oct 31, 2017
5098948
Handle distance calculation of new variants
Manishearth Oct 31, 2017
6415294
Fix unit tests
Manishearth Oct 31, 2017
1c12e0e
Rustfmt the new files
Manishearth Nov 1, 2017
123bc1d
Update test expectations
Manishearth Nov 2, 2017
cb9645c
Comments and minor fixes
Manishearth Nov 2, 2017
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Handle distance calculation of new variants

  • Loading branch information
Manishearth committed Nov 2, 2017
commit 5098948c0d809082b2e20f7b3433a992ee600d09
@@ -18,8 +18,6 @@ use properties::longhands::font_weight::computed_value::T as FontWeight;
use properties::longhands::font_stretch::computed_value::T as FontStretch;
#[cfg(feature = "gecko")]
use properties::longhands::font_variation_settings::computed_value::T as FontVariationSettings;
use properties::longhands::transform::computed_value::ComputedOperation as ComputedTransformOperation;
use properties::longhands::transform::computed_value::T as ComputedTransform;
use properties::longhands::visibility::computed_value::T as Visibility;
#[cfg(feature = "gecko")]
use properties::PropertyId;
@@ -45,6 +43,8 @@ use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage
use values::computed::length::NonNegativeLengthOrPercentage;
use values::computed::ToComputedValue;
use values::computed::transform::{DirectionVector, Matrix, Matrix3D};
use values::computed::transform::TransformOperation as ComputedTransformOperation;
use values::computed::transform::Transform as ComputedTransform;
use values::generics::transform::{Transform, TransformOperation};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
#[cfg(feature = "gecko")] use values::generics::FontSettings as GenericFontSettings;
@@ -1226,11 +1226,11 @@ impl Animate for ComputedTransformOperation {
fd_matrix.animate(&td_matrix, procedure)?,
))
},
(ref f, ref t) if f.is_translate() && t.is_translate() => {
f.to_translate_3d().animate(&t.to_translate_3d(), procedure)
_ if self.is_translate() && other.is_translate() => {
self.to_translate_3d().animate(&other.to_translate_3d(), procedure)
}
(ref f, ref t) if f.is_scale() && t.is_scale() => {
f.to_scale_3d().animate(&t.to_scale_3d(), procedure)
_ if self.is_scale() && other.is_scale() => {
self.to_scale_3d().animate(&other.to_scale_3d(), procedure)
}
_ => Err(()),
}
@@ -2334,13 +2334,36 @@ impl Animate for ComputedTransform {
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1318591#c0.
impl ComputeSquaredDistance for ComputedTransformOperation {
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
// For translate, We don't want to require doing layout in order to calculate the result, so
// drop the percentage part. However, dropping percentage makes us impossible to
// compute the distance for the percentage-percentage case, but Gecko uses the
// same formula, so it's fine for now.
// Note: We use pixel value to compute the distance for translate, so we have to
// convert Au into px.
let extract_pixel_length = |lop: &LengthOrPercentage| {
match *lop {
LengthOrPercentage::Length(px) => px.px(),
LengthOrPercentage::Percentage(_) => 0.,
LengthOrPercentage::Calc(calc) => calc.length().px(),
}
};
match (self, other) {
(
&TransformOperation::Matrix3D(ref this),
&TransformOperation::Matrix3D(ref other),
) => {
this.compute_squared_distance(other)
},
(
&TransformOperation::Matrix(ref this),
&TransformOperation::Matrix(ref other),
) => {
let this: Matrix3D = (*this).into();
let other: Matrix3D = (*other).into();
this.compute_squared_distance(&other)
},


(
&TransformOperation::Skew(ref fx, ref fy),
&TransformOperation::Skew(ref tx, ref ty),
@@ -2350,24 +2373,19 @@ impl ComputeSquaredDistance for ComputedTransformOperation {
fy.compute_squared_distance(&ty)?,
)
},
(
&TransformOperation::SkewX(ref f),
&TransformOperation::SkewX(ref t),
) | (
&TransformOperation::SkewY(ref f),
&TransformOperation::SkewY(ref t),
) => {
f.compute_squared_distance(&t)
},
(
&TransformOperation::Translate3D(ref fx, ref fy, ref fz),
&TransformOperation::Translate3D(ref tx, ref ty, ref tz),
) => {
// We don't want to require doing layout in order to calculate the result, so
// drop the percentage part. However, dropping percentage makes us impossible to
// compute the distance for the percentage-percentage case, but Gecko uses the
// same formula, so it's fine for now.
// Note: We use pixel value to compute the distance for translate, so we have to
// convert Au into px.
let extract_pixel_length = |lop: &LengthOrPercentage| {
match *lop {
LengthOrPercentage::Length(px) => px.px(),
LengthOrPercentage::Percentage(_) => 0.,
LengthOrPercentage::Calc(calc) => calc.length().px(),
}
};

let fx = extract_pixel_length(&fx);
let fy = extract_pixel_length(&fy);
let tx = extract_pixel_length(&tx);
@@ -2407,6 +2425,24 @@ impl ComputeSquaredDistance for ComputedTransformOperation {
q1.compute_squared_distance(&q2)
}
}
(
&TransformOperation::RotateX(fa),
&TransformOperation::RotateX(ta),
) |
(
&TransformOperation::RotateY(fa),
&TransformOperation::RotateY(ta),
) |
(
&TransformOperation::RotateZ(fa),
&TransformOperation::RotateZ(ta),
) |
(
&TransformOperation::Rotate(fa),
&TransformOperation::Rotate(ta),
) => {
fa.compute_squared_distance(&ta)
}
(
&TransformOperation::Perspective(ref fd),
&TransformOperation::Perspective(ref td),
@@ -2435,6 +2471,12 @@ impl ComputeSquaredDistance for ComputedTransformOperation {
}
p_matrix.compute_squared_distance(&m)
}
_ if self.is_translate() && other.is_translate() => {

This comment has been minimized.

@emilio

emilio Nov 2, 2017

Member

Again, links, comments.

self.to_translate_3d().compute_squared_distance(&other.to_translate_3d())
}
_ if self.is_scale() && other.is_scale() => {
self.to_scale_3d().compute_squared_distance(&other.to_scale_3d())
}
_ => Err(()),
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.