Auto merge of #14049 - Wafflespeanut:lon, r=SimonSapin

Add a generic type for sharing some CSS types

<!-- Please describe your changes on the following line: -->

This would be useful for types such as `T(pub Option<U>)` or any type that's a mixture of two types (like `LengthOrFoo` for example). Well, it's a bit ugly, especially because we have to address the types as `Either::First` and `Either::Second` everywhere, but I don't have a brighter idea 😄

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

r? @SimonSapin (cc @Manishearth @emilio)

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14049)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-09 08:15:16 -06:00 committed by GitHub
commit 35f328d717
11 changed files with 125 additions and 117 deletions

View file

@ -178,7 +178,7 @@
use parser::{ParserContext, ParserContextExtraData};
use properties::{CSSWideKeyword, DeclaredValue, Shorthand};
% endif
#[allow(unused_imports)]
use values::{Auto, Either, None_, Normal};
use cascade_info::CascadeInfo;
use error_reporting::ParseErrorReporter;
use parser::Parse;

View file

@ -22,6 +22,7 @@ use std::cmp;
use std::fmt;
use style_traits::ToCss;
use super::ComputedValues;
use values::Either;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, LengthOrNone};
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage};
@ -682,8 +683,8 @@ impl Interpolate for BoxShadow {
impl Interpolate for LengthOrNone {
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
match (*self, *other) {
(LengthOrNone::Length(ref len), LengthOrNone::Length(ref other)) =>
len.interpolate(&other, progress).map(LengthOrNone::Length),
(Either::First(ref length), Either::First(ref other)) =>
length.interpolate(&other, progress).map(Either::First),
_ => Err(()),
}
}

View file

@ -1395,7 +1395,7 @@ ${helpers.single_keyword("transform-style",
${helpers.predefined_type("perspective",
"LengthOrNone",
"computed::LengthOrNone::None",
"Either::Second(None_)",
products="servo",
animatable=True)}

View file

@ -30,6 +30,7 @@ use logical_geometry::WritingMode;
use parser::{ParserContext, ParserContextExtraData};
use style_traits::ToCss;
use stylesheets::Origin;
#[cfg(feature = "servo")] use values::Either;
use values::{HasViewportPercentage, computed};
use cascade_info::CascadeInfo;
use rule_tree::StrongRuleNode;
@ -1249,7 +1250,7 @@ impl ComputedValues {
if effects.transform.0.is_some() {
return transform_style::T::flat;
}
if effects.perspective != computed::LengthOrNone::None {
if let Either::First(ref _length) = effects.perspective {
return transform_style::T::flat;
}
}