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:
Emilio Cobos Álvarez 2019-01-06 23:01:00 +01:00
parent bffe2a699e
commit ca503b4908
22 changed files with 338 additions and 644 deletions

View file

@ -18,7 +18,7 @@ use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard
use crate::str::CssStringWriter;
use crate::stylesheets::{Origin, StylesheetInDocument};
use crate::values::computed::{Context, ToComputedValue};
use crate::values::specified::{LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength};
use crate::values::specified::{self, LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength};
use app_units::Au;
use cssparser::CowRcStr;
use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
@ -157,7 +157,9 @@ impl FromMeta for ViewportLength {
fn from_meta(value: &str) -> Option<ViewportLength> {
macro_rules! specified {
($value:expr) => {
ViewportLength::Specified(LengthOrPercentageOrAuto::Length($value))
ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(
specified::LengthOrPercentage::Length($value)
))
};
}
@ -752,16 +754,10 @@ impl MaybeNew for ViewportConstraints {
if let Some($value) = $value {
match *$value {
ViewportLength::Specified(ref length) => match *length {
LengthOrPercentageOrAuto::Length(ref value) => {
Some(Au::from(value.to_computed_value(&context)))
},
LengthOrPercentageOrAuto::Percentage(value) => {
Some(initial_viewport.$dimension.scale_by(value.0))
},
LengthOrPercentageOrAuto::Auto => None,
LengthOrPercentageOrAuto::Calc(ref calc) => calc
LengthOrPercentageOrAuto::LengthOrPercentage(ref lop) => Some(lop
.to_computed_value(&context)
.to_used_value(Some(initial_viewport.$dimension)),
.to_used_value(initial_viewport.$dimension)),
},
ViewportLength::ExtendToZoom => {
// $extend_to will be 'None' if 'extend-to-zoom' is 'auto'