mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Implement -webkit-gradient() (fixes #16542)
This commit is contained in:
parent
9e6f9db127
commit
ea4e7299d4
4 changed files with 285 additions and 16 deletions
|
@ -658,7 +658,7 @@ impl ToCss for Number {
|
|||
|
||||
/// <number-percentage>
|
||||
/// Accepts only non-negative numbers.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum NumberOrPercentage {
|
||||
|
@ -668,13 +668,27 @@ pub enum NumberOrPercentage {
|
|||
|
||||
no_viewport_percentage!(NumberOrPercentage);
|
||||
|
||||
impl Parse for NumberOrPercentage {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if let Ok(per) = input.try(Percentage::parse_non_negative) {
|
||||
impl NumberOrPercentage {
|
||||
fn parse_with_clamping_mode(context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
type_: AllowedNumericType)
|
||||
-> Result<Self, ()> {
|
||||
if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(i, type_)) {
|
||||
return Ok(NumberOrPercentage::Percentage(per));
|
||||
}
|
||||
|
||||
Number::parse_non_negative(context, input).map(NumberOrPercentage::Number)
|
||||
parse_number_with_clamping_mode(context, input, type_).map(NumberOrPercentage::Number)
|
||||
}
|
||||
|
||||
/// Parse a non-negative number or percentage.
|
||||
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_with_clamping_mode(context, input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for NumberOrPercentage {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_with_clamping_mode(context, input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue