mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Properly use integers on grid properties, and derive ToComputedValue.
This commit is contained in:
parent
02d24061e7
commit
64ab73eabd
7 changed files with 112 additions and 91 deletions
|
@ -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>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue