Implement -webkit-gradient() (fixes #16542)

This commit is contained in:
Anthony Ramine 2017-05-13 16:46:58 +02:00
parent 9e6f9db127
commit ea4e7299d4
4 changed files with 285 additions and 16 deletions

View file

@ -15,7 +15,7 @@ use std::{cmp, fmt, mem};
use std::ascii::AsciiExt;
use std::ops::Mul;
use style_traits::ToCss;
use style_traits::values::specified::AllowedLengthType;
use style_traits::values::specified::{AllowedLengthType, AllowedNumericType};
use stylesheets::CssRuleType;
use super::{AllowQuirks, Number, ToComputedValue};
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal};
@ -729,7 +729,10 @@ impl ToCss for Percentage {
}
impl Percentage {
fn parse_internal(input: &mut Parser, context: AllowedLengthType) -> Result<Self, ()> {
/// Parse a specific kind of percentage.
pub fn parse_with_clamping_mode(input: &mut Parser,
context: AllowedNumericType)
-> Result<Self, ()> {
match try!(input.next()) {
Token::Percentage(ref value) if context.is_ok(value.unit_value) => {
Ok(Percentage(value.unit_value))
@ -740,14 +743,14 @@ impl Percentage {
/// Parses a percentage token, but rejects it if it's negative.
pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(input, AllowedLengthType::NonNegative)
Self::parse_with_clamping_mode(input, AllowedNumericType::NonNegative)
}
}
impl Parse for Percentage {
#[inline]
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(input, AllowedLengthType::All)
Self::parse_with_clamping_mode(input, AllowedNumericType::All)
}
}