Auto merge of #15115 - Wafflespeanut:lop, r=emilio

Introduce the `NoCalcLength`

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

I began this for making the `CalcLengthOrPercentage` represent `LengthOrPercentage` (instead of the enum we already have), but only later did I realize that it will make `LengthOrPercentageOrFoo` types fatty (which is the problem we're trying to avoid - #15061) and so, I dropped that attempt. Along the way, I introduced an internal type for `Length`, for representing all its non-calc variants (which are `Copy`). We could still have this type for the `LengthOrPercentageOrFoo` types which don't really need  `Length` since they already have their own variants for calc.

r? @Manishearth @emilio @SimonSapin or anyone interested

---
<!-- 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

<!-- 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/15115)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-28 14:08:38 -08:00 committed by GitHub
commit cd0a6b98f4
19 changed files with 305 additions and 230 deletions

View file

@ -1328,7 +1328,7 @@ ${helpers.single_keyword("animation-fill-mode",
result.push(SpecifiedOperation::Translate(TranslateKind::Translate,
tx,
ty,
specified::Length::Absolute(Au(0))));
specified::Length::zero()));
Ok(())
}))
},
@ -1339,7 +1339,7 @@ ${helpers.single_keyword("animation-fill-mode",
TranslateKind::TranslateX,
tx,
specified::LengthOrPercentage::zero(),
specified::Length::Absolute(Au(0))));
specified::Length::zero()));
Ok(())
}))
},
@ -1350,7 +1350,7 @@ ${helpers.single_keyword("animation-fill-mode",
TranslateKind::TranslateY,
specified::LengthOrPercentage::zero(),
ty,
specified::Length::Absolute(Au(0))));
specified::Length::zero()));
Ok(())
}))
},
@ -1761,7 +1761,7 @@ ${helpers.single_keyword("transform-style",
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::specified::{Length, LengthOrPercentage, Percentage};
use values::specified::{NoCalcLength, LengthOrPercentage, Percentage};
pub mod computed_value {
use properties::animated_properties::Interpolate;
@ -1799,7 +1799,7 @@ ${helpers.single_keyword("transform-style",
pub struct SpecifiedValue {
horizontal: LengthOrPercentage,
vertical: LengthOrPercentage,
depth: Length,
depth: NoCalcLength,
}
impl ToCss for computed_value::T {
@ -1836,7 +1836,7 @@ ${helpers.single_keyword("transform-style",
Ok(SpecifiedValue {
horizontal: result.horizontal.unwrap_or(LengthOrPercentage::Percentage(Percentage(0.5))),
vertical: result.vertical.unwrap_or(LengthOrPercentage::Percentage(Percentage(0.5))),
depth: result.depth.unwrap_or(Length::Absolute(Au(0))),
depth: result.depth.unwrap_or(NoCalcLength::zero()),
})
}

View file

@ -280,10 +280,10 @@ ${helpers.predefined_type("opacity",
left = try!(parse_argument(context, input));
}
Ok(SpecifiedValue(Some(SpecifiedClipRect {
top: top.unwrap_or(Length::Absolute(Au(0))),
top: top.unwrap_or(Length::zero()),
right: right,
bottom: bottom,
left: left.unwrap_or(Length::Absolute(Au(0))),
left: left.unwrap_or(Length::zero()),
})))
})
}
@ -613,7 +613,7 @@ ${helpers.predefined_type("opacity",
pub struct OriginParseResult {
pub horizontal: Option<specified::LengthOrPercentage>,
pub vertical: Option<specified::LengthOrPercentage>,
pub depth: Option<specified::Length>
pub depth: Option<specified::NoCalcLength>
}
pub fn parse_origin(context: &ParserContext, input: &mut Parser) -> Result<OriginParseResult,()> {

View file

@ -329,7 +329,7 @@ ${helpers.single_keyword("font-variant-caps",
use std::fmt;
use style_traits::ToCss;
use values::{FONT_MEDIUM_PX, HasViewportPercentage};
use values::specified::{LengthOrPercentage, Length, Percentage};
use values::specified::{LengthOrPercentage, Length, NoCalcLength, Percentage};
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
@ -363,10 +363,10 @@ ${helpers.single_keyword("font-variant-caps",
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
match self.0 {
LengthOrPercentage::Length(Length::FontRelative(value)) => {
LengthOrPercentage::Length(NoCalcLength::FontRelative(value)) => {
value.to_computed_value(context, /* use inherited */ true)
}
LengthOrPercentage::Length(Length::ServoCharacterWidth(value)) => {
LengthOrPercentage::Length(NoCalcLength::ServoCharacterWidth(value)) => {
value.to_computed_value(context.inherited_style().get_font().clone_font_size())
}
LengthOrPercentage::Length(ref l) => {
@ -397,11 +397,10 @@ ${helpers.single_keyword("font-variant-caps",
input.try(specified::LengthOrPercentage::parse_non_negative)
.or_else(|()| {
let ident = try!(input.expect_ident());
specified::Length::from_str(&ident as &str)
.ok_or(())
.map(specified::LengthOrPercentage::Length)
})
.map(SpecifiedValue)
NoCalcLength::from_str(&ident as &str)
.ok_or(())
.map(specified::LengthOrPercentage::Length)
}).map(SpecifiedValue)
}
</%helpers:longhand>

View file

@ -113,13 +113,14 @@
specified::LengthOrPercentage::Length(ref value) =>
computed_value::T::Length(value.to_computed_value(context)),
specified::LengthOrPercentage::Percentage(specified::Percentage(value)) => {
let fr = specified::Length::FontRelative(specified::FontRelativeLength::Em(value));
let fr = specified::Length::NoCalc(specified::NoCalcLength::FontRelative(
specified::FontRelativeLength::Em(value)));
computed_value::T::Length(fr.to_computed_value(context))
},
specified::LengthOrPercentage::Calc(ref calc) => {
let calc = calc.to_computed_value(context);
let fr = specified::FontRelativeLength::Em(calc.percentage());
let fr = specified::Length::FontRelative(fr);
let fr = specified::Length::NoCalc(specified::NoCalcLength::FontRelative(fr));
computed_value::T::Length(calc.length() + fr.to_computed_value(context))
}
}
@ -681,9 +682,7 @@ ${helpers.single_keyword("text-align-last",
fn parse_one_text_shadow(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedTextShadow,()> {
use app_units::Au;
let mut lengths = [specified::Length::Absolute(Au(0)),
specified::Length::Absolute(Au(0)),
specified::Length::Absolute(Au(0))];
let mut lengths = [specified::Length::zero(), specified::Length::zero(), specified::Length::zero()];
let mut lengths_parsed = false;
let mut color = None;

View file

@ -74,7 +74,6 @@
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
use values::specified::{BorderWidth, Length};
use app_units::Au;
let mut color = None;
let mut width = None;
@ -99,7 +98,7 @@
Ok(Longhands {
_webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor,
authored: None })),
_webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))),
_webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::zero()))),
})
} else {
Err(())

View file

@ -57,8 +57,7 @@
<%helpers:shorthand name="flex" sub_properties="flex-grow flex-shrink flex-basis" extra_prefixes="webkit"
spec="https://drafts.csswg.org/css-flexbox/#flex-property">
use parser::Parse;
use app_units::Au;
use values::specified::{Number, Length, LengthOrPercentageOrAutoOrContent};
use values::specified::{Number, NoCalcLength, LengthOrPercentageOrAutoOrContent};
pub fn parse_flexibility(input: &mut Parser)
-> Result<(Number, Option<Number>),()> {
@ -102,7 +101,7 @@
Ok(Longhands {
flex_grow: grow.or(Some(Number(1.0))),
flex_shrink: shrink.or(Some(Number(1.0))),
flex_basis: basis.or(Some(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0)))))
flex_basis: basis.or(Some(LengthOrPercentageOrAutoOrContent::Length(NoCalcLength::zero())))
})
}