servo: Merge #18429 - style: Remove a few uses of ComputedValueAsSpecified (from emilio:cvas-die); r=nox

Source-Repo: https://github.com/servo/servo
Source-Revision: 7fc2c435513feadf1dc666e7873095884dfd6d84

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 2d5c5e40214492fa277b7a30ae4cf73371ae96e5
This commit is contained in:
Emilio Cobos Álvarez 2017-09-11 04:31:10 -05:00
Родитель f38299c32f
Коммит b517d24b00
21 изменённых файлов: 231 добавлений и 237 удалений

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

@ -18,7 +18,7 @@ use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordData
use std::f32::consts::PI;
use stylesheets::{Origin, RulesMutateError};
use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image};
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, Percentage};
use values::computed::{Integer, LengthOrPercentage, LengthOrPercentageOrAuto, Percentage};
use values::generics::box_::VerticalAlign;
use values::generics::grid::{TrackListValue, TrackSize};
use values::generics::image::{CompatMode, Image as GenericImage, GradientItem};
@ -896,7 +896,7 @@ impl TrackSize<LengthOrPercentage> {
}
}
impl TrackListValue<LengthOrPercentage> {
impl TrackListValue<LengthOrPercentage, Integer> {
/// Return TrackSize from given two nsStyleCoord
pub fn from_gecko_style_coords<T: CoordData>(gecko_min: &T, gecko_max: &T) -> Self {
TrackListValue::TrackSize(TrackSize::from_gecko_style_coords(gecko_min, gecko_max))

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

@ -4,6 +4,22 @@
//! Various macro helpers.
macro_rules! trivial_to_computed_value {
($name: ident) => {
impl $crate::values::computed::ToComputedValue for $name {
type ComputedValue = $name;
fn to_computed_value(&self, _: &$crate::values::computed::Context) -> Self {
self.clone()
}
fn from_computed_value(other: &Self) -> Self {
other.clone()
}
}
}
}
/// A macro to parse an identifier, or return an `UnexpectedIndent` error
/// otherwise.
///
@ -35,10 +51,10 @@ macro_rules! define_numbered_css_keyword_enum {
}
impl $crate::parser::Parse for $name {
#[allow(missing_docs)]
fn parse<'i, 't>(_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>)
-> Result<$name, ::style_traits::ParseError<'i>> {
fn parse<'i, 't>(
_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>,
) -> Result<$name, ::style_traits::ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
$( $css => Ok($name::$variant), )+
}
@ -47,7 +63,8 @@ macro_rules! define_numbered_css_keyword_enum {
impl ::style_traits::values::ToCss for $name {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
where W: ::std::fmt::Write,
where
W: ::std::fmt::Write,
{
match *self {
$( $name::$variant => dest.write_str($css) ),+
@ -57,7 +74,7 @@ macro_rules! define_numbered_css_keyword_enum {
}
}
/// A macro for implementing `ComputedValueAsSpecified`, and `Parse` traits for
/// A macro for implementing `ToComputedValue`, and `Parse` traits for
/// the enums defined using `define_css_keyword_enum` macro.
///
/// NOTE: We should either move `Parse` trait to `style_traits`
@ -67,14 +84,15 @@ macro_rules! add_impls_for_keyword_enum {
($name:ident) => {
impl $crate::parser::Parse for $name {
#[inline]
fn parse<'i, 't>(_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>)
-> Result<Self, ::style_traits::ParseError<'i>> {
fn parse<'i, 't>(
_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>,
) -> Result<Self, ::style_traits::ParseError<'i>> {
$name::parse(input)
}
}
impl $crate::values::computed::ComputedValueAsSpecified for $name {}
trivial_to_computed_value!($name);
};
}
@ -83,7 +101,7 @@ macro_rules! define_keyword_type {
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, PartialEq)]
#[derive(ToAnimatedZero, ToCss)]
#[derive(ToAnimatedZero, ToComputedValue, ToCss)]
pub struct $name;
impl fmt::Debug for $name {
@ -93,14 +111,14 @@ macro_rules! define_keyword_type {
}
impl $crate::parser::Parse for $name {
fn parse<'i, 't>(_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>)
-> Result<$name, ::style_traits::ParseError<'i>> {
fn parse<'i, 't>(
_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>
) -> Result<$name, ::style_traits::ParseError<'i>> {
input.expect_ident_matching($css).map(|_| $name).map_err(|e| e.into())
}
}
impl $crate::values::computed::ComputedValueAsSpecified for $name {}
impl $crate::values::animated::AnimatedValueAsComputed for $name {}
};
}

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

@ -1700,7 +1700,7 @@ fn static_assert() {
if let Some(integer) = v.line_num {
// clamping the integer between a range
self.gecko.${value.gecko}.mInteger = cmp::max(nsStyleGridLine_kMinLine,
cmp::min(integer.value(), nsStyleGridLine_kMaxLine));
cmp::min(integer, nsStyleGridLine_kMaxLine));
}
}
@ -1717,7 +1717,6 @@ fn static_assert() {
pub fn clone_${value.name}(&self) -> longhands::${value.name}::computed_value::T {
use gecko_bindings::structs::{nsStyleGridLine_kMinLine, nsStyleGridLine_kMaxLine};
use string_cache::Atom;
use values::specified::Integer;
longhands::${value.name}::computed_value::T {
is_span: self.gecko.${value.gecko}.mHasSpan,
@ -1735,7 +1734,7 @@ fn static_assert() {
} else {
debug_assert!(nsStyleGridLine_kMinLine <= self.gecko.${value.gecko}.mInteger);
debug_assert!(self.gecko.${value.gecko}.mInteger <= nsStyleGridLine_kMaxLine);
Some(Integer::new(self.gecko.${value.gecko}.mInteger))
Some(self.gecko.${value.gecko}.mInteger)
},
}
}

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

@ -500,32 +500,26 @@
<%def name="single_keyword(name, values, vector=False, **kwargs)">
<%call expr="single_keyword_computed(name, values, vector, **kwargs)">
% if not "extra_specified" in kwargs and ("aliases" in kwargs or (("extra_%s_aliases" % product) in kwargs)):
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
% for value in data.longhands_by_name[name].keyword.values_for(product):
SpecifiedValue::${to_rust_ident(value)} => computed_value::T::${to_rust_ident(value)},
% endfor
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
% for value in data.longhands_by_name[name].keyword.values_for(product):
computed_value::T::${to_rust_ident(value)} => SpecifiedValue::${to_rust_ident(value)},
% endfor
}
#[inline]
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
% for value in data.longhands_by_name[name].keyword.values_for(product):
SpecifiedValue::${to_rust_ident(value)} => computed_value::T::${to_rust_ident(value)},
% endfor
}
}
% else:
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
% endif
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
% for value in data.longhands_by_name[name].keyword.values_for(product):
computed_value::T::${to_rust_ident(value)} => SpecifiedValue::${to_rust_ident(value)},
% endfor
}
}
}
</%call>
</%def>

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

@ -46,7 +46,7 @@ use values::animated::effects::Filter as AnimatedFilter;
use values::animated::effects::FilterList as AnimatedFilterList;
use values::animated::effects::TextShadowList as AnimatedTextShadowList;
use values::computed::{Angle, BorderCornerRadius, CalcLengthOrPercentage};
use values::computed::{ClipRect, Context, ComputedUrl, ComputedValueAsSpecified};
use values::computed::{ClipRect, Context, ComputedUrl};
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, MaxLength, NonNegativeAu};
use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage};
@ -203,7 +203,7 @@ pub fn nscsspropertyid_is_animatable(property: nsCSSPropertyID) -> bool {
// NB: This needs to be here because it needs all the longhands generated
// beforehand.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss, ToComputedValue)]
pub enum TransitionProperty {
/// All, any transitionable property changing should generate a transition.
All,
@ -218,9 +218,6 @@ pub enum TransitionProperty {
Unsupported(CustomIdent)
}
impl ComputedValueAsSpecified for TransitionProperty {}
impl TransitionProperty {
/// Iterates over each longhand property.
pub fn each<F: FnMut(&TransitionProperty) -> ()>(mut cb: F) {

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

@ -34,7 +34,6 @@
-moz-grid-group -moz-grid-line -moz-stack -moz-inline-stack -moz-deck
-moz-popup -moz-groupbox""".split()
%>
use values::computed::ComputedValueAsSpecified;
use style_traits::ToCss;
pub mod computed_value {
@ -137,7 +136,7 @@
}
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub enum SpecifiedValue {
% for value in values:
@ -180,8 +179,6 @@
}
}
impl ComputedValueAsSpecified for SpecifiedValue {}
% if product == "servo":
fn cascade_property_custom(_declaration: &PropertyDeclaration,
context: &mut computed::Context) {
@ -403,14 +400,13 @@ ${helpers.predefined_type("transition-delay",
use Atom;
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
use values::KeyframesName;
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue(pub Option<KeyframesName>);
@ -448,8 +444,10 @@ ${helpers.predefined_type("transition-delay",
}
impl Parse for SpecifiedValue {
fn parse<'i, 't>(context: &ParserContext, input: &mut ::cssparser::Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut ::cssparser::Parser<'i, 't>
) -> Result<Self, ParseError<'i>> {
if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) {
Ok(SpecifiedValue(Some(name)))
} else {
@ -458,12 +456,13 @@ ${helpers.predefined_type("transition-delay",
}
}
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue,ParseError<'i>> {
pub fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<SpecifiedValue,ParseError<'i>> {
SpecifiedValue::parse(context, input)
}
impl ComputedValueAsSpecified for SpecifiedValue {}
</%helpers:vector_longhand>
${helpers.predefined_type("animation-duration",
@ -496,15 +495,13 @@ ${helpers.predefined_type("animation-timing-function",
extra_prefixes="moz webkit"
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
allowed_in_keyframe_block="False">
use values::computed::ComputedValueAsSpecified;
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
// https://drafts.csswg.org/css-animations/#animation-iteration-count
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
#[derive(Clone, Debug, PartialEq, ToCss, ToComputedValue)]
pub enum SpecifiedValue {
Number(f32),
Infinite,
@ -538,12 +535,12 @@ ${helpers.predefined_type("animation-timing-function",
}
#[inline]
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
pub fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<SpecifiedValue, ParseError<'i>> {
SpecifiedValue::parse(context, input)
}
impl ComputedValueAsSpecified for SpecifiedValue {}
</%helpers:vector_longhand>
<% animation_direction_custom_consts = { "alternate-reverse": "Alternate_reverse" } %>
@ -1626,15 +1623,13 @@ ${helpers.predefined_type("transform-origin",
spec="https://drafts.csswg.org/css-contain/#contain-property">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
pub type T = super::SpecifiedValue;
}
bitflags! {
#[derive(ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub flags SpecifiedValue: u8 {
const LAYOUT = 0x01,
@ -1770,15 +1765,12 @@ ${helpers.single_keyword("-moz-orient",
use std::fmt;
use style_traits::ToCss;
use values::CustomIdent;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
Auto,
@ -1843,9 +1835,6 @@ ${helpers.predefined_type(
use gecko_bindings::structs;
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
pub use super::SpecifiedValue as T;
@ -1853,6 +1842,7 @@ ${helpers.predefined_type(
bitflags! {
/// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants.
#[derive(ToComputedValue)]
pub flags SpecifiedValue: u8 {
const TOUCH_ACTION_NONE = structs::NS_STYLE_TOUCH_ACTION_NONE as u8,
const TOUCH_ACTION_AUTO = structs::NS_STYLE_TOUCH_ACTION_AUTO as u8,

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

@ -1175,15 +1175,12 @@ ${helpers.single_keyword_system("font-variant-caps",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-synthesis">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue {
pub weight: bool,
@ -2186,11 +2183,8 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
<%helpers:longhand name="-x-lang" products="gecko" animation_value_type="none" internal="True"
spec="Internal (not web-exposed)">
use values::computed::ComputedValueAsSpecified;
pub use self::computed_value::T as SpecifiedValue;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
use Atom;
use std::fmt;
@ -2202,7 +2196,7 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Atom);
}
@ -2393,11 +2387,8 @@ ${helpers.single_keyword("-moz-math-variant",
<%helpers:longhand name="-x-text-zoom" products="gecko" animation_value_type="none" internal="True"
spec="Internal (not web-exposed)">
use values::computed::ComputedValueAsSpecified;
pub use self::computed_value::T as SpecifiedValue;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
use std::fmt;
use style_traits::ToCss;
@ -2408,7 +2399,7 @@ ${helpers.single_keyword("-moz-math-variant",
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// text-zoom. Enable if true, disable if false
pub struct T(pub bool);

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

@ -268,10 +268,6 @@ ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
spec="Nonstandard (Internal-only)"
allow_empty="True">
use values::CustomIdent;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue { }
pub type SpecifiedValue = CustomIdent;

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

@ -255,9 +255,8 @@ ${helpers.single_keyword("text-align-last",
}
}
% else:
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub use self::computed_value::T as SpecifiedValue;
add_impls_for_keyword_enum!(SpecifiedValue);
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
computed_value::T::parse(input)
@ -287,9 +286,6 @@ ${helpers.predefined_type("word-spacing",
use cssparser::RGBA;
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
@ -299,6 +295,8 @@ ${helpers.predefined_type("word-spacing",
pub line_through: Option<RGBA>,
}
trivial_to_computed_value!(SpecifiedValue);
pub mod computed_value {
pub type T = super::SpecifiedValue;
}
@ -374,9 +372,7 @@ ${helpers.predefined_type("word-spacing",
// !important.
flags="APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-text/#propdef-white-space">
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
trivial_to_computed_value!(SpecifiedValue);
% if product != "gecko":
impl SpecifiedValue {
pub fn allow_wrap(&self) -> bool {
@ -433,8 +429,8 @@ ${helpers.predefined_type(
pub mod computed_value {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, ToComputedValue))]
pub enum T {
Keyword(KeywordValue),
None,
@ -449,8 +445,8 @@ ${helpers.predefined_type(
}
}
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
Keyword(KeywordValue),
None,
@ -614,26 +610,25 @@ ${helpers.predefined_type(
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
use values::computed::ComputedValueAsSpecified;
use style_traits::ToCss;
define_css_keyword_enum!(HorizontalWritingModeValue:
"over" => Over,
"under" => Under);
add_impls_for_keyword_enum!(VerticalWritingModeValue);
define_css_keyword_enum!(VerticalWritingModeValue:
"right" => Right,
"left" => Left);
add_impls_for_keyword_enum!(HorizontalWritingModeValue);
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)]
pub struct SpecifiedValue(pub HorizontalWritingModeValue, pub VerticalWritingModeValue);
pub mod computed_value {
pub type T = super::SpecifiedValue;
}
impl ComputedValueAsSpecified for SpecifiedValue {}
pub fn get_initial_value() -> computed_value::T {
SpecifiedValue(HorizontalWritingModeValue::Over, VerticalWritingModeValue::Right)
}

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

@ -291,19 +291,18 @@ ${helpers.predefined_type("object-position",
animation_value_type="discrete">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
pub type SpecifiedValue = computed_value::T;
pub mod computed_value {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum AutoFlow {
Row,
Column,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T {
pub autoflow: AutoFlow,
@ -311,8 +310,6 @@ ${helpers.predefined_type("object-position",
}
}
impl ComputedValueAsSpecified for SpecifiedValue {}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(match self.autoflow {
@ -421,7 +418,6 @@ ${helpers.predefined_type("object-position",
use std::ops::Range;
use str::HTML_SPACE_CHARACTERS;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
pub mod computed_value {
pub use super::SpecifiedValue as T;
@ -453,11 +449,13 @@ ${helpers.predefined_type("object-position",
pub columns: Range<u32>,
}
impl ComputedValueAsSpecified for TemplateAreas {}
trivial_to_computed_value!(TemplateAreas);
impl Parse for TemplateAreas {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let mut strings = vec![];
while let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().into())) {
strings.push(string);

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

@ -14,15 +14,12 @@ ${helpers.single_keyword("table-layout", "auto fixed",
spec="Internal-only (for `<col span>` pres attr)"
animation_value_type="none"
internal="True">
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
pub type SpecifiedValue = computed_value::T;
pub mod computed_value {
use std::fmt;
use style_traits::ToCss;
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub i32);
@ -39,8 +36,10 @@ ${helpers.single_keyword("table-layout", "auto fixed",
}
// never parse it, only set via presentation attribute
fn parse<'i, 't>(_: &ParserContext, _: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
fn parse<'i, 't>(
_: &ParserContext,
_: &mut Parser<'i, 't>,
) -> Result<SpecifiedValue, ParseError<'i>> {
Err(StyleParseError::UnspecifiedError.into())
}
</%helpers:longhand>

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

@ -147,7 +147,7 @@
let end = if input.try(|i| i.expect_delim('/')).is_ok() {
GridLine::parse(context, input)?
} else {
let mut line = GridLine::default();
let mut line = GridLine::auto();
if start.line_num.is_none() && !start.is_span {
line.ident = start.ident.clone(); // ident from start value should be taken
}
@ -182,7 +182,7 @@
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
fn line_with_ident_from(other: &GridLine) -> GridLine {
let mut this = GridLine::default();
let mut this = GridLine::auto();
if other.line_num.is_none() && !other.is_span {
this.ident = other.ident.clone();
}

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

@ -8,7 +8,7 @@
use std::fmt;
use style_traits::ToCss;
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
use values::computed::{Context, ToComputedValue};
use values::specified;
pub use super::specified::{AlignItems, AlignJustifyContent, AlignJustifySelf};
@ -69,7 +69,3 @@ impl ToComputedValue for specified::JustifyItems {
computed.specified
}
}
impl ComputedValueAsSpecified for AlignItems {}
impl ComputedValueAsSpecified for AlignJustifyContent {}
impl ComputedValueAsSpecified for AlignJustifySelf {}

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

@ -21,9 +21,9 @@ use std::sync::Arc;
use style_traits::ToCss;
use super::{CSSFloat, CSSInteger};
use super::generics::{GreaterThanOrEqualToOne, NonNegative};
use super::generics::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList};
use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
use super::generics::grid::TrackList as GenericTrackList;
use super::specified;
pub use app_units::Au;
@ -44,7 +44,6 @@ pub use self::gecko::ScrollSnapPoint;
pub use self::rect::LengthOrNumberRect;
pub use super::{Auto, Either, None_};
pub use super::specified::BorderStyle;
pub use super::generics::grid::GridLine;
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::NonNegativeLengthOrPercentage;
@ -333,11 +332,13 @@ impl<T> ToComputedValue for T
}
}
impl ComputedValueAsSpecified for Atom {}
impl ComputedValueAsSpecified for bool {}
impl ComputedValueAsSpecified for f32 {}
impl ComputedValueAsSpecified for specified::BorderStyle {}
trivial_to_computed_value!(Atom);
trivial_to_computed_value!(u8);
trivial_to_computed_value!(u16);
trivial_to_computed_value!(bool);
trivial_to_computed_value!(i32);
trivial_to_computed_value!(f32);
trivial_to_computed_value!(BorderStyle);
/// A `<number>` value.
pub type Number = CSSFloat;
@ -501,10 +502,13 @@ pub type TrackSize = GenericTrackSize<LengthOrPercentage>;
/// The computed value of a grid `<track-list>`
/// (could also be `<auto-track-list>` or `<explicit-track-list>`)
pub type TrackList = GenericTrackList<LengthOrPercentage>;
pub type TrackList = GenericTrackList<LengthOrPercentage, Integer>;
/// The computed value of a `<grid-line>`.
pub type GridLine = GenericGridLine<Integer>;
/// `<grid-template-rows> | <grid-template-columns>`
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthOrPercentage>;
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthOrPercentage, Integer>;
impl ClipRectOrAuto {
/// Return an auto (default for clip-rect and image-region) value

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

@ -8,7 +8,6 @@
use std::fmt;
use style_traits::ToCss;
use values::animated::{Animate, Procedure, ToAnimatedZero};
use values::computed::ComputedValueAsSpecified;
use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::border::BorderRadius;
use values::generics::position::Position;
@ -20,14 +19,13 @@ pub type ClippingShape<BasicShape, Url> = ShapeSource<BasicShape, GeometryBox, U
/// https://drafts.fxtf.org/css-masking-1/#typedef-geometry-box
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)]
pub enum GeometryBox {
FillBox,
StrokeBox,
ViewBox,
ShapeBox(ShapeBox),
}
impl ComputedValueAsSpecified for GeometryBox {}
/// A float area shape, for `shape-outside`.
pub type FloatAreaShape<BasicShape, Url> = ShapeSource<BasicShape, ShapeBox, Url>;

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

@ -10,16 +10,16 @@ use parser::{Parse, ParserContext};
use std::{fmt, mem, usize};
use style_traits::{ToCss, ParseError, StyleParseError};
use values::{CSSFloat, CustomIdent, serialize_dimension};
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
use values::specified::Integer;
use values::computed::{Context, ToComputedValue};
use values::specified;
use values::specified::grid::parse_line_names;
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// A `<grid-line>` type.
///
/// https://drafts.csswg.org/css-grid/#typedef-grid-row-start-grid-line
pub struct GridLine {
pub struct GridLine<Integer> {
/// Flag to check whether it's a `span` keyword.
pub is_span: bool,
/// A custom identifier for named lines.
@ -30,24 +30,26 @@ pub struct GridLine {
pub line_num: Option<Integer>,
}
impl GridLine {
impl<Integer> GridLine<Integer> {
/// The `auto` value.
pub fn auto() -> Self {
Self {
is_span: false,
line_num: None,
ident: None,
}
}
/// Check whether this `<grid-line>` represents an `auto` value.
pub fn is_auto(&self) -> bool {
self.ident.is_none() && self.line_num.is_none() && !self.is_span
}
}
impl Default for GridLine {
fn default() -> Self {
GridLine {
is_span: false,
ident: None,
line_num: None,
}
}
}
impl ToCss for GridLine {
impl<Integer> ToCss for GridLine<Integer>
where
Integer: ToCss,
{
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.is_auto() {
return dest.write_str("auto")
@ -57,9 +59,9 @@ impl ToCss for GridLine {
dest.write_str("span")?;
}
if let Some(i) = self.line_num {
if let Some(ref i) = self.line_num {
dest.write_str(" ")?;
i.value().to_css(dest)?;
i.to_css(dest)?;
}
if let Some(ref s) = self.ident {
@ -71,9 +73,9 @@ impl ToCss for GridLine {
}
}
impl Parse for GridLine {
impl Parse for GridLine<specified::Integer> {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let mut grid_line = Default::default();
let mut grid_line = Self::auto();
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(grid_line)
}
@ -95,7 +97,8 @@ impl Parse for GridLine {
}
grid_line.is_span = true;
} else if let Ok(i) = input.try(|i| Integer::parse(context, i)) {
} else if let Ok(i) = input.try(|i| specified::Integer::parse(context, i)) {
// FIXME(emilio): Probably shouldn't reject if it's calc()...
if i.value() == 0 || val_before_span || grid_line.line_num.is_some() {
return Err(StyleParseError::UnspecifiedError.into())
}
@ -129,14 +132,12 @@ impl Parse for GridLine {
}
}
impl ComputedValueAsSpecified for GridLine {}
define_css_keyword_enum!{ TrackKeyword:
"auto" => Auto,
"max-content" => MaxContent,
"min-content" => MinContent
}
impl ComputedValueAsSpecified for TrackKeyword {}
add_impls_for_keyword_enum!(TrackKeyword);
/// A track breadth for explicit grid track sizing. It's generic solely to
/// avoid re-implementing it for the computed type.
@ -316,9 +317,15 @@ impl<L: ToComputedValue> ToComputedValue for TrackSize<L> {
/// Helper function for serializing identifiers with a prefix and suffix, used
/// for serializing <line-names> (in grid).
pub fn concat_serialize_idents<W>(prefix: &str, suffix: &str,
slice: &[CustomIdent], sep: &str, dest: &mut W) -> fmt::Result
where W: fmt::Write
pub fn concat_serialize_idents<W>(
prefix: &str,
suffix: &str,
slice: &[CustomIdent],
sep: &str,
dest: &mut W,
) -> fmt::Result
where
W: fmt::Write
{
if let Some((ref first, rest)) = slice.split_first() {
dest.write_str(prefix)?;
@ -338,8 +345,8 @@ pub fn concat_serialize_idents<W>(prefix: &str, suffix: &str,
///
/// https://drafts.csswg.org/css-grid/#typedef-track-repeat
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
pub enum RepeatCount {
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)]
pub enum RepeatCount<Integer> {
/// A positive integer. This is allowed only for `<track-repeat>` and `<fixed-repeat>`
Number(Integer),
/// An `<auto-fill>` keyword allowed only for `<auto-repeat>`
@ -348,19 +355,15 @@ pub enum RepeatCount {
AutoFit,
}
impl Parse for RepeatCount {
impl Parse for RepeatCount<specified::Integer> {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
// Maximum number of repeat is 10000. The greater numbers should be clamped.
const MAX_LINE: i32 = 10000;
if let Ok(mut i) = input.try(|i| Integer::parse(context, i)) {
if i.value() > 0 {
if i.value() > MAX_LINE {
i = Integer::new(MAX_LINE);
}
Ok(RepeatCount::Number(i))
} else {
Err(StyleParseError::UnspecifiedError.into())
if let Ok(mut i) = input.try(|i| specified::Integer::parse_positive(context, i)) {
if i.value() > MAX_LINE {
i = specified::Integer::new(MAX_LINE);
}
Ok(RepeatCount::Number(i))
} else {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
"auto-fill" => Ok(RepeatCount::AutoFill),
@ -370,17 +373,15 @@ impl Parse for RepeatCount {
}
}
impl ComputedValueAsSpecified for RepeatCount {}
/// The structure containing `<line-names>` and `<track-size>` values.
///
/// It can also hold `repeat()` function parameters, which expands into the respective
/// values in its computed form.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
pub struct TrackRepeat<L> {
pub struct TrackRepeat<L, I> {
/// The number of times for the value to be repeated (could also be `auto-fit` or `auto-fill`)
pub count: RepeatCount,
pub count: RepeatCount<I>,
/// `<line-names>` accompanying `<track_size>` values.
///
/// If there's no `<line-names>`, then it's represented by an empty vector.
@ -392,7 +393,7 @@ pub struct TrackRepeat<L> {
pub track_sizes: Vec<TrackSize<L>>,
}
impl<L: ToCss> ToCss for TrackRepeat<L> {
impl<L: ToCss, I: ToCss> ToCss for TrackRepeat<L, I> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str("repeat(")?;
self.count.to_css(dest)?;
@ -418,7 +419,7 @@ impl<L: ToCss> ToCss for TrackRepeat<L> {
Ok(())
}
}
impl<L: Clone> TrackRepeat<L> {
impl<L: Clone> TrackRepeat<L, specified::Integer> {
/// If the repeat count is numeric, then expand the values and merge accordingly.
pub fn expand(&self) -> Self {
if let RepeatCount::Number(num) = self.count {
@ -460,17 +461,17 @@ impl<L: Clone> TrackRepeat<L> {
/// Track list values. Can be <track-size> or <track-repeat>
#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum TrackListValue<T> {
pub enum TrackListValue<LengthOrPercentage, Integer> {
/// A <track-size> value.
TrackSize(TrackSize<T>),
TrackSize(TrackSize<LengthOrPercentage>),
/// A <track-repeat> value.
TrackRepeat(TrackRepeat<T>),
TrackRepeat(TrackRepeat<LengthOrPercentage, Integer>),
}
/// The type of a `<track-list>` as determined during parsing.
///
/// https://drafts.csswg.org/css-grid/#typedef-track-list
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum TrackListType {
/// [`<auto-track-list>`](https://drafts.csswg.org/css-grid/#typedef-auto-track-list)
@ -490,21 +491,19 @@ pub enum TrackListType {
Explicit,
}
impl ComputedValueAsSpecified for TrackListType {}
/// A grid `<track-list>` type.
///
/// https://drafts.csswg.org/css-grid/#typedef-track-list
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq)]
pub struct TrackList<T> {
pub struct TrackList<LengthOrPercentage, Integer> {
/// The type of this `<track-list>` (auto, explicit or general).
///
/// In order to avoid parsing the same value multiple times, this does a single traversal
/// and arrives at the type of value it has parsed (or bails out gracefully with an error).
pub list_type: TrackListType,
/// A vector of `<track-size> | <track-repeat>` values.
pub values: Vec<TrackListValue<T>>,
pub values: Vec<TrackListValue<LengthOrPercentage, Integer>>,
/// `<line-names>` accompanying `<track-size> | <track-repeat>` values.
///
/// If there's no `<line-names>`, then it's represented by an empty vector.
@ -512,10 +511,10 @@ pub struct TrackList<T> {
/// length is always one value more than that of the `<track-size>`.
pub line_names: Box<[Box<[CustomIdent]>]>,
/// `<auto-repeat>` value. There can only be one `<auto-repeat>` in a TrackList.
pub auto_repeat: Option<TrackRepeat<T>>,
pub auto_repeat: Option<TrackRepeat<LengthOrPercentage, Integer>>,
}
impl<T: ToCss> ToCss for TrackList<T> {
impl<L: ToCss, I: ToCss> ToCss for TrackList<L, I> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let auto_idx = match self.list_type {
TrackListType::Auto(i) => i as usize,
@ -572,6 +571,8 @@ pub struct LineNameList {
pub fill_idx: Option<u32>,
}
trivial_to_computed_value!(LineNameList);
impl Parse for LineNameList {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
input.expect_ident_matching("subgrid")?;
@ -654,23 +655,21 @@ impl ToCss for LineNameList {
}
}
impl ComputedValueAsSpecified for LineNameList {}
/// Variants for `<grid-template-rows> | <grid-template-columns>`
/// Subgrid deferred to Level 2 spec due to lack of implementation.
/// But it's implemented in gecko, so we have to as well.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)]
pub enum GridTemplateComponent<L> {
pub enum GridTemplateComponent<L, I> {
/// `none` value.
None,
/// The grid `<track-list>`
TrackList(TrackList<L>),
TrackList(TrackList<L, I>),
/// A `subgrid <line-name-list>?`
Subgrid(LineNameList),
}
impl<L> GridTemplateComponent<L> {
impl<L, I> GridTemplateComponent<L, I> {
/// Returns length of the <track-list>s <track-size>
pub fn track_list_len(&self) -> usize {
match *self {

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

@ -8,10 +8,10 @@
use Atom;
use cssparser::serialize_identifier;
use custom_properties::SpecifiedValue;
use custom_properties;
use std::fmt;
use style_traits::ToCss;
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
use values::computed::{Context, ToComputedValue};
/// An [image].
///
@ -153,7 +153,7 @@ define_css_keyword_enum!(ShapeExtent:
"contain" => Contain,
"cover" => Cover
);
impl ComputedValueAsSpecified for ShapeExtent {}
add_impls_for_keyword_enum!(ShapeExtent);
/// A gradient item.
/// https://drafts.csswg.org/css-images-4/#color-stop-syntax
@ -186,10 +186,10 @@ pub struct PaintWorklet {
pub name: Atom,
/// The arguments for the worklet.
/// TODO: store a parsed representation of the arguments.
pub arguments: Vec<SpecifiedValue>,
pub arguments: Vec<custom_properties::SpecifiedValue>,
}
impl ComputedValueAsSpecified for PaintWorklet {}
trivial_to_computed_value!(PaintWorklet);
impl ToCss for PaintWorklet {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {

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

@ -98,7 +98,7 @@ impl<A: Parse, B: Parse> Parse for Either<A, B> {
}
/// https://drafts.csswg.org/css-values-4/#custom-idents
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct CustomIdent(pub Atom);
@ -127,7 +127,7 @@ impl ToCss for CustomIdent {
}
/// https://drafts.csswg.org/css-animations/#typedef-keyframes-name
#[derive(Clone, Debug)]
#[derive(Clone, Debug, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum KeyframesName {
/// <custom-ident>

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

@ -18,6 +18,7 @@ bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
///
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
#[derive(ToComputedValue)]
pub flags AlignFlags: u8 {
// Enumeration stored in the lower 5 bits:
/// 'auto'
@ -113,7 +114,7 @@ const ALIGN_ALL_SHIFT: u32 = structs::NS_STYLE_ALIGN_ALL_SHIFT;
///
/// The 16-bit field stores the primary value in its lower 8 bits, and the optional fallback value
/// in its upper 8 bits. This matches the representation of these properties in Gecko.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct AlignJustifyContent(u16);
@ -205,7 +206,7 @@ impl Parse for AlignJustifyContent {
/// Value of the `align-self` or `justify-self` property.
///
/// https://drafts.csswg.org/css-align/#self-alignment
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
pub struct AlignJustifySelf(pub AlignFlags);
impl AlignJustifySelf {
@ -242,7 +243,7 @@ impl Parse for AlignJustifySelf {
/// Value of the `align-items` property
///
/// https://drafts.csswg.org/css-align/#self-alignment
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
pub struct AlignItems(pub AlignFlags);
impl AlignItems {

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

@ -14,7 +14,7 @@ use values::{CSSFloat, CustomIdent};
use values::computed::{self, Context, ToComputedValue};
use values::generics::grid::{GridTemplateComponent, RepeatCount, TrackBreadth, TrackKeyword, TrackRepeat};
use values::generics::grid::{LineNameList, TrackSize, TrackList, TrackListType, TrackListValue};
use values::specified::LengthOrPercentage;
use values::specified::{LengthOrPercentage, Integer};
/// Parse a single flexible length.
pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CSSFloat, ParseError<'i>> {
@ -97,9 +97,11 @@ enum RepeatType {
Fixed,
}
impl TrackRepeat<LengthOrPercentage> {
fn parse_with_repeat_type<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(TrackRepeat<LengthOrPercentage>, RepeatType), ParseError<'i>> {
impl TrackRepeat<LengthOrPercentage, Integer> {
fn parse_with_repeat_type<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<(Self, RepeatType), ParseError<'i>> {
input.try(|i| i.expect_function_matching("repeat").map_err(|e| e.into())).and_then(|_| {
input.parse_nested_block(|input| {
let count = RepeatCount::parse(context, input)?;
@ -165,7 +167,7 @@ impl TrackRepeat<LengthOrPercentage> {
}
}
impl Parse for TrackList<LengthOrPercentage> {
impl Parse for TrackList<LengthOrPercentage, Integer> {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let mut current_names = vec![];
let mut names = vec![];
@ -248,8 +250,8 @@ impl Parse for TrackList<LengthOrPercentage> {
}
}
impl ToComputedValue for TrackList<LengthOrPercentage> {
type ComputedValue = TrackList<computed::LengthOrPercentage>;
impl ToComputedValue for TrackList<LengthOrPercentage, Integer> {
type ComputedValue = TrackList<computed::LengthOrPercentage, computed::Integer>;
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
@ -321,7 +323,7 @@ impl ToComputedValue for TrackList<LengthOrPercentage> {
}
}
impl Parse for GridTemplateComponent<LengthOrPercentage> {
impl Parse for GridTemplateComponent<LengthOrPercentage, Integer> {
// FIXME: Derive Parse (probably with None_)
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() {
@ -332,10 +334,12 @@ impl Parse for GridTemplateComponent<LengthOrPercentage> {
}
}
impl GridTemplateComponent<LengthOrPercentage> {
impl GridTemplateComponent<LengthOrPercentage, Integer> {
/// Parses a `GridTemplateComponent<LengthOrPercentage>` except `none` keyword.
pub fn parse_without_none<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
pub fn parse_without_none<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(t) = input.try(|i| TrackList::parse(context, i)) {
return Ok(GridTemplateComponent::TrackList(t))
}

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

@ -19,8 +19,8 @@ use style_traits::values::specified::AllowedNumericType;
use super::{Auto, CSSFloat, CSSInteger, Either, None_};
use super::computed::{Context, ToComputedValue};
use super::generics::{GreaterThanOrEqualToOne, NonNegative};
use super::generics::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
use super::generics::grid::TrackList as GenericTrackList;
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList};
use values::computed::ComputedValueAsSpecified;
use values::specified::calc::CalcNode;
@ -52,7 +52,6 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDash
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, WordSpacing};
pub use self::time::Time;
pub use self::transform::{TimingFunction, TransformOrigin};
pub use super::generics::grid::GridLine;
pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
#[cfg(feature = "gecko")]
@ -356,9 +355,11 @@ impl ToComputedValue for Opacity {
}
}
/// An specified `<integer>`, optionally coming from a `calc()` expression.
///
/// https://drafts.csswg.org/css-values/#integers
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
pub struct Integer {
value: CSSInteger,
was_calc: bool,
@ -387,7 +388,6 @@ impl Integer {
}
}
impl Parse for Integer {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
parse_integer(context, input)
@ -395,25 +395,37 @@ impl Parse for Integer {
}
impl Integer {
#[allow(missing_docs)]
pub fn parse_with_minimum<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>, min: i32)
-> Result<Integer, ParseError<'i>> {
/// Parse an integer value which is at least `min`.
pub fn parse_with_minimum<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
min: i32
) -> Result<Integer, ParseError<'i>> {
match parse_integer(context, input) {
// FIXME(emilio): The spec asks us to avoid rejecting it at parse
// time except until computed value time.
//
// It's not totally clear it's worth it though, and no other browser
// does this.
Ok(value) if value.value() >= min => Ok(value),
Ok(_value) => Err(StyleParseError::UnspecifiedError.into()),
Err(e) => Err(e),
}
}
#[allow(missing_docs)]
pub fn parse_non_negative<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Integer, ParseError<'i>> {
/// Parse a non-negative integer.
pub fn parse_non_negative<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Integer, ParseError<'i>> {
Integer::parse_with_minimum(context, input, 0)
}
#[allow(missing_docs)]
pub fn parse_positive<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Integer, ParseError<'i>> {
/// Parse a positive integer (>= 1).
pub fn parse_positive<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<Integer, ParseError<'i>> {
Integer::parse_with_minimum(context, input, 1)
}
}
@ -484,10 +496,13 @@ pub type TrackSize = GenericTrackSize<LengthOrPercentage>;
/// The specified value of a grid `<track-list>`
/// (could also be `<auto-track-list>` or `<explicit-track-list>`)
pub type TrackList = GenericTrackList<LengthOrPercentage>;
pub type TrackList = GenericTrackList<LengthOrPercentage, Integer>;
/// The specified value of a `<grid-line>`.
pub type GridLine = GenericGridLine<Integer>;
/// `<grid-template-rows> | <grid-template-columns>`
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthOrPercentage>;
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthOrPercentage, Integer>;
/// <length> | <percentage> | <number>
pub type LengthOrPercentageOrNumber = Either<Number, LengthOrPercentage>;