servo: Merge #20124 - Replace LengthOrNone by a specific type for the perspective property (from servo:perspective); r=emilio

Source-Repo: https://github.com/servo/servo
Source-Revision: 6df0dc5b2710a6ba856de7c064a6631a8d63efc5

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 832da1d4deab01047fb65ef99f476b922bbf1b7b
This commit is contained in:
Anthony Ramine 2018-02-26 16:35:32 -05:00
Родитель dbae7d4792
Коммит c65e310932
12 изменённых файлов: 113 добавлений и 68 удалений

Просмотреть файл

@ -59,10 +59,9 @@ use style::properties::ComputedValues;
use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace;
use style::values::{self, Either};
use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::counters::ContentItem;
use style::values::generics::box_::VerticalAlign;
use style::values::generics::box_::{Perspective, VerticalAlign};
use style::values::generics::transform;
use text;
use text::TextRunScanner;
@ -2477,7 +2476,7 @@ impl Fragment {
pub fn has_filter_transform_or_perspective(&self) -> bool {
!self.style().get_box().transform.0.is_empty() ||
!self.style().get_effects().filter.0.is_empty() ||
self.style().get_box().perspective != Either::Second(values::None_)
self.style().get_box().perspective != Perspective::None
}
/// Returns true if this fragment establishes a new stacking context and false otherwise.
@ -2899,7 +2898,7 @@ impl Fragment {
/// Returns the 4D matrix representing this fragment's perspective.
pub fn perspective_matrix(&self, stacking_relative_border_box: &Rect<Au>) -> Option<LayoutTransform> {
match self.style().get_box().perspective {
Either::First(length) => {
Perspective::Length(length) => {
let perspective_origin = self.style().get_box().perspective_origin;
let perspective_origin =
Point2D::new(
@ -2923,7 +2922,7 @@ impl Fragment {
Some(pre_transform.pre_mul(&perspective_matrix).pre_mul(&post_transform))
}
Either::Second(values::None_) => {
Perspective::None => {
None
}
}

Просмотреть файл

@ -24,6 +24,7 @@ use values::computed::{NonNegativeLength, NonNegativeLengthOrPercentage, NonNega
use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use values::generics::{CounterStyleOrNone, NonNegative};
use values::generics::basic_shape::ShapeRadius;
use values::generics::box_::Perspective;
use values::generics::gecko::ScrollSnapPoint;
use values::generics::grid::{TrackBreadth, TrackKeyword};
@ -422,6 +423,27 @@ impl GeckoStyleCoordConvertible for ScrollSnapPoint<LengthOrPercentage> {
}
}
impl<L> GeckoStyleCoordConvertible for Perspective<L>
where
L: GeckoStyleCoordConvertible,
{
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self {
Perspective::None => coord.set_value(CoordDataValue::None),
Perspective::Length(ref l) => l.to_gecko_style_coord(coord),
};
}
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
use gecko_bindings::structs::root::nsStyleUnit;
if coord.unit() == nsStyleUnit::eStyleUnit_None {
return Some(Perspective::None);
}
Some(Perspective::Length(L::from_gecko_style_coord(coord)?))
}
}
/// Convert a given RGBA value to `nscolor`.
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
((rgba.alpha as u32) << 24) |

Просмотреть файл

@ -1447,18 +1447,18 @@ impl Clone for ${style_struct.gecko_struct_name} {
# Types used with predefined_type()-defined properties that we can auto-generate.
predefined_types = {
"Color": impl_color,
"GreaterThanOrEqualToOneNumber": impl_simple,
"Integer": impl_simple,
"length::LengthOrAuto": impl_style_coord,
"length::LengthOrNormal": impl_style_coord,
"length::NonNegativeLengthOrAuto": impl_style_coord,
"length::NonNegativeLengthOrNormal": impl_style_coord,
"GreaterThanOrEqualToOneNumber": impl_simple,
"Length": impl_absolute_length,
"Position": impl_position,
"LengthOrNormal": impl_style_coord,
"LengthOrPercentage": impl_style_coord,
"LengthOrPercentageOrAuto": impl_style_coord,
"LengthOrPercentageOrNone": impl_style_coord,
"LengthOrNone": impl_style_coord,
"LengthOrNormal": impl_style_coord,
"MaxLength": impl_style_coord,
"MozLength": impl_style_coord,
"MozScriptMinSize": impl_absolute_length,
@ -1466,9 +1466,9 @@ impl Clone for ${style_struct.gecko_struct_name} {
"NonNegativeLengthOrPercentage": impl_style_coord,
"NonNegativeNumber": impl_simple,
"Number": impl_simple,
"Integer": impl_simple,
"Opacity": impl_simple,
"Color": impl_color,
"Perspective": impl_style_coord,
"Position": impl_position,
"RGBAColor": impl_rgba_color,
"SVGLength": impl_svg_length,
"SVGOpacity": impl_svg_opacity,
@ -4795,10 +4795,10 @@ fn static_assert() {
use values::Either;
match v {
Either::Second(non_negative_number) => {
Either::First(non_negative_number) => {
self.gecko.mTabSize.set_value(CoordDataValue::Factor(non_negative_number.0));
}
Either::First(non_negative_length) => {
Either::Second(non_negative_length) => {
self.gecko.mTabSize.set(non_negative_length);
}
}
@ -4809,8 +4809,8 @@ fn static_assert() {
use values::Either;
match self.gecko.mTabSize.as_value() {
CoordDataValue::Coord(coord) => Either::First(Au(coord).into()),
CoordDataValue::Factor(number) => Either::Second(From::from(number)),
CoordDataValue::Coord(coord) => Either::Second(Au(coord).into()),
CoordDataValue::Factor(number) => Either::First(From::from(number)),
_ => unreachable!(),
}
}

Просмотреть файл

@ -507,17 +507,17 @@ ${helpers.single_keyword("resize",
flags="APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete")}
${helpers.predefined_type("perspective",
"LengthOrNone",
"Either::Second(None_)",
"parse_non_negative_length",
gecko_ffi_name="mChildPerspective",
spec="https://drafts.csswg.org/css-transforms/#perspective",
extra_prefixes="moz webkit",
flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
animation_value_type="ComputedValue",
servo_restyle_damage = "reflow_out_of_flow")}
${helpers.predefined_type(
"perspective",
"Perspective",
"computed::Perspective::none()",
gecko_ffi_name="mChildPerspective",
spec="https://drafts.csswg.org/css-transforms/#perspective",
extra_prefixes="moz webkit",
flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
animation_value_type="AnimatedPerspective",
servo_restyle_damage = "reflow_out_of_flow",
)}
${helpers.predefined_type("perspective-origin",
"position::Position",

Просмотреть файл

@ -488,7 +488,7 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"-moz-tab-size", "length::NonNegativeLengthOrNumber",
"::values::Either::Second(From::from(8.0))",
"::values::Either::First(From::from(8.0))",
products="gecko", animation_value_type="::values::computed::length::NonNegativeLengthOrNumber",
spec="https://drafts.csswg.org/css-text-3/#tab-size-property")}

Просмотреть файл

@ -5,8 +5,9 @@
//! Computed types for box properties.
use values::computed::Number;
use values::computed::length::LengthOrPercentage;
use values::computed::length::{LengthOrPercentage, NonNegativeLength};
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use values::generics::box_::Perspective as GenericPerspective;
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
pub use values::specified::box_::{AnimationName, Display, OverflowClipBox, Contain};
@ -25,3 +26,6 @@ impl AnimationIterationCount {
GenericAnimationIterationCount::Number(1.0)
}
}
/// A computed value for the `perspective` property.
pub type Perspective = GenericPerspective<NonNegativeLength>;

Просмотреть файл

@ -13,7 +13,7 @@ use std::ops::{Add, Neg};
use style_traits::{CssWriter, ToCss};
use style_traits::values::specified::AllowedNumericType;
use super::{Number, ToComputedValue, Context, Percentage};
use values::{Auto, CSSFloat, Either, None_, Normal, specified};
use values::{Auto, CSSFloat, Either, Normal, specified};
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::computed::NonNegativeNumber;
use values::distance::{ComputeSquaredDistance, SquaredDistance};
@ -792,9 +792,6 @@ impl From<Au> for CSSPixelLength {
/// An alias of computed `<length>` value.
pub type Length = CSSPixelLength;
/// Either a computed `<length>` or the `none` keyword.
pub type LengthOrNone = Either<Length, None_>;
/// Either a computed `<length>` or the `auto` keyword.
pub type LengthOrAuto = Either<Length, Auto>;
@ -902,7 +899,7 @@ pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>;
pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
/// Either a computed NonNegativeLength or a NonNegativeNumber value.
pub type NonNegativeLengthOrNumber = Either<NonNegativeLength, NonNegativeNumber>;
pub type NonNegativeLengthOrNumber = Either<NonNegativeNumber, NonNegativeLength>;
/// A type for possible values for min- and max- flavors of width, height,
/// block-size, and inline-size.

Просмотреть файл

@ -47,8 +47,9 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
@ -61,7 +62,7 @@ pub use self::gecko::ScrollSnapPoint;
pub use self::rect::LengthOrNumberRect;
pub use super::{Auto, Either, None_};
pub use super::specified::{BorderStyle, TextDecorationLine};
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage};
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength, NonNegativeLengthOrPercentage};
pub use self::list::{ListStyleImage, Quotes};

Просмотреть файл

@ -55,3 +55,21 @@ pub enum AnimationIterationCount<Number> {
/// The `infinite` keyword.
Infinite,
}
/// A generic value for the `perspective` property.
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
pub enum Perspective<NonNegativeLength> {
/// A non-negative length.
Length(NonNegativeLength),
/// The keyword `none`.
None,
}
impl<L> Perspective<L> {
/// Returns `none`.
#[inline]
pub fn none() -> Self {
Perspective::None
}
}

Просмотреть файл

@ -13,9 +13,10 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use values::CustomIdent;
use values::KeyframesName;
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use values::generics::box_::Perspective as GenericPerspective;
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
use values::specified::{AllowQuirks, Number};
use values::specified::length::LengthOrPercentage;
use values::specified::length::{LengthOrPercentage, NonNegativeLength};
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
@ -588,3 +589,18 @@ impl Parse for Contain {
}
}
}
/// A specified value for the `perspective` property.
pub type Perspective = GenericPerspective<NonNegativeLength>;
impl Parse for Perspective {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<Self, ParseError<'i>> {
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(GenericPerspective::None);
}
Ok(GenericPerspective::Length(NonNegativeLength::parse(context, input)?))
}
}

Просмотреть файл

@ -17,7 +17,7 @@ use std::ops::{Add, Mul};
use style_traits::{ParseError, StyleParseErrorKind};
use style_traits::values::specified::AllowedNumericType;
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
use values::{Auto, CSSFloat, Either, None_, Normal};
use values::{Auto, CSSFloat, Either, Normal};
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
use values::generics::NonNegative;
use values::specified::NonNegativeNumber;
@ -640,21 +640,19 @@ impl Length {
}
}
impl<T: Parse> Either<Length, T> {
/// Parse a non-negative length
#[inline]
pub fn parse_non_negative_length<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
if let Ok(v) = input.try(|input| T::parse(context, input)) {
return Ok(Either::Second(v));
}
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First)
}
}
/// A wrapper of Length, whose value must be >= 0.
pub type NonNegativeLength = NonNegative<Length>;
impl Parse for NonNegativeLength {
#[inline]
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Ok(NonNegative(Length::parse_non_negative(context, input)?))
}
}
impl From<NoCalcLength> for NonNegativeLength {
#[inline]
fn from(len: NoCalcLength) -> Self {
@ -669,17 +667,6 @@ impl From<Length> for NonNegativeLength {
}
}
impl<T: Parse> Parse for Either<NonNegativeLength, T> {
#[inline]
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if let Ok(v) = input.try(|input| T::parse(context, input)) {
return Ok(Either::Second(v));
}
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No)
.map(NonNegative::<Length>).map(Either::First)
}
}
impl NonNegativeLength {
/// Returns a `zero` length.
#[inline]
@ -701,7 +688,10 @@ pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>;
/// Either a NonNegativeLength or a NonNegativeNumber value.
pub type NonNegativeLengthOrNumber = Either<NonNegativeLength, NonNegativeNumber>;
///
/// The order is important, because `0` must be parsed as the number `0` and not
/// the length `0px`.
pub type NonNegativeLengthOrNumber = Either<NonNegativeNumber, NonNegativeLength>;
/// A length or a percentage value.
#[allow(missing_docs)]
@ -1072,9 +1062,6 @@ impl NonNegativeLengthOrPercentage {
}
}
/// Either a `<length>` or the `none` keyword.
pub type LengthOrNone = Either<Length, None_>;
/// Either a `<length>` or the `normal` keyword.
pub type LengthOrNormal = Either<Length, Normal>;

Просмотреть файл

@ -39,8 +39,9 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
@ -51,7 +52,7 @@ pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
pub use self::inherited_box::ImageOrientation;
pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
pub use self::length::{FontRelativeLength, Length, LengthOrNone, LengthOrNumber};
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{NoCalcLength, ViewportPercentageLength};