mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Simplify computed::LengthOrPercentage and friends.
This is a first step to share LengthOrPercentage representation between Rust and Gecko. We need to preserve whether the value came from a calc() expression, for now at least, since we do different things depending on whether we're calc or not right now. See https://github.com/w3c/csswg-drafts/issues/3482 and dependent bugs for example. That means that the gecko conversion code needs to handle calc() in a bit of an awkward way until I change it to not be needed (patches for that incoming in the next few weeks I hope). I need to add a hack to exclude other things from the PartialEq implementation because the new conversion code is less lossy than the old one, and we relied on the lousiness in AnimationValue comparison (in order to start transitions and such, in [1] for example). I expect to remove that manual PartialEq implementation as soon as I'm done with the conversion. The less lossy conversion does fix a few serialization bugs for animation values though, like not loosing 0% values in calc() when interpolating lengths and percentages, see the two modified tests: * property-types.js * test_animation_properties.html Differential Revision: https://phabricator.services.mozilla.com/D15793
This commit is contained in:
parent
bffe2a699e
commit
ca503b4908
22 changed files with 338 additions and 644 deletions
|
@ -1167,17 +1167,6 @@ impl Animate for ComputedTransformOperation {
|
|||
// 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)
|
||||
|
@ -1199,10 +1188,16 @@ impl ComputeSquaredDistance for ComputedTransformOperation {
|
|||
&TransformOperation::Translate3D(ref fx, ref fy, ref fz),
|
||||
&TransformOperation::Translate3D(ref tx, ref ty, ref tz),
|
||||
) => {
|
||||
let fx = extract_pixel_length(&fx);
|
||||
let fy = extract_pixel_length(&fy);
|
||||
let tx = extract_pixel_length(&tx);
|
||||
let ty = extract_pixel_length(&ty);
|
||||
// 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.
|
||||
let fx = fx.length_component().px();
|
||||
let fy = fy.length_component().px();
|
||||
let tx = tx.length_component().px();
|
||||
let ty = ty.length_component().px();
|
||||
|
||||
Ok(fx.compute_squared_distance(&tx)? +
|
||||
fy.compute_squared_distance(&ty)? +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue