Rename AllowedNumericType to AllowedLengthType

This commit is contained in:
Anthony Ramine 2017-04-12 11:39:19 +02:00
parent 5f6c27bb94
commit 12d46e7d01
3 changed files with 36 additions and 36 deletions

View file

@ -15,7 +15,7 @@ use std::{cmp, fmt, mem};
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::ops::Mul; use std::ops::Mul;
use style_traits::ToCss; use style_traits::ToCss;
use style_traits::values::specified::AllowedNumericType; use style_traits::values::specified::AllowedLengthType;
use stylesheets::CssRuleType; use stylesheets::CssRuleType;
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time, ToComputedValue}; use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time, ToComputedValue};
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal}; use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal};
@ -458,7 +458,7 @@ pub enum Length {
/// A calc expression. /// A calc expression.
/// ///
/// https://drafts.csswg.org/css-values/#calc-notation /// https://drafts.csswg.org/css-values/#calc-notation
Calc(Box<CalcLengthOrPercentage>, AllowedNumericType), Calc(Box<CalcLengthOrPercentage>, AllowedLengthType),
} }
impl From<NoCalcLength> for Length { impl From<NoCalcLength> for Length {
@ -539,7 +539,7 @@ impl Length {
} }
#[inline] #[inline]
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType)
-> Result<Length, ()> { -> Result<Length, ()> {
match try!(input.next()) { match try!(input.next()) {
Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
@ -556,7 +556,7 @@ impl Length {
/// Parse a non-negative length /// Parse a non-negative length
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> {
Self::parse_internal(context, input, AllowedNumericType::NonNegative) Self::parse_internal(context, input, AllowedLengthType::NonNegative)
} }
/// Get an absolute length from a px value. /// Get an absolute length from a px value.
@ -576,7 +576,7 @@ impl Length {
impl Parse for Length { impl Parse for Length {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedNumericType::All) Self::parse_internal(context, input, AllowedLengthType::All)
} }
} }
@ -598,7 +598,7 @@ impl Either<Length, Normal> {
if input.try(|input| Normal::parse(context, input)).is_ok() { if input.try(|input| Normal::parse(context, input)).is_ok() {
return Ok(Either::Second(Normal)); return Ok(Either::Second(Normal));
} }
Length::parse_internal(context, input, AllowedNumericType::NonNegative).map(Either::First) Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First)
} }
} }
@ -609,7 +609,7 @@ impl Either<Length, Auto> {
if input.try(|input| Auto::parse(context, input)).is_ok() { if input.try(|input| Auto::parse(context, input)).is_ok() {
return Ok(Either::Second(Auto)); return Ok(Either::Second(Auto));
} }
Length::parse_internal(context, input, AllowedNumericType::NonNegative).map(Either::First) Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First)
} }
} }
@ -836,7 +836,7 @@ impl CalcLengthOrPercentage {
fn parse_length(context: &ParserContext, fn parse_length(context: &ParserContext,
input: &mut Parser, input: &mut Parser,
num_context: AllowedNumericType) -> Result<Length, ()> { num_context: AllowedLengthType) -> Result<Length, ()> {
CalcLengthOrPercentage::parse(context, input, CalcUnit::Length).map(|calc| { CalcLengthOrPercentage::parse(context, input, CalcUnit::Length).map(|calc| {
Length::Calc(Box::new(calc), num_context) Length::Calc(Box::new(calc), num_context)
}) })
@ -1061,7 +1061,7 @@ impl ToCss for Percentage {
} }
impl Percentage { impl Percentage {
fn parse_internal(input: &mut Parser, context: AllowedNumericType) -> Result<Self, ()> { fn parse_internal(input: &mut Parser, context: AllowedLengthType) -> Result<Self, ()> {
match try!(input.next()) { match try!(input.next()) {
Token::Percentage(ref value) if context.is_ok(value.unit_value) => { Token::Percentage(ref value) if context.is_ok(value.unit_value) => {
Ok(Percentage(value.unit_value)) Ok(Percentage(value.unit_value))
@ -1072,14 +1072,14 @@ impl Percentage {
/// Parses a percentage token, but rejects it if it's negative. /// Parses a percentage token, but rejects it if it's negative.
pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> { pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(input, AllowedNumericType::NonNegative) Self::parse_internal(input, AllowedLengthType::NonNegative)
} }
} }
impl Parse for Percentage { impl Parse for Percentage {
#[inline] #[inline]
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(input, AllowedNumericType::All) Self::parse_internal(input, AllowedLengthType::All)
} }
} }
@ -1145,7 +1145,7 @@ impl LengthOrPercentage {
LengthOrPercentage::Length(NoCalcLength::zero()) LengthOrPercentage::Length(NoCalcLength::zero())
} }
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType)
-> Result<LengthOrPercentage, ()> -> Result<LengthOrPercentage, ()>
{ {
match try!(input.next()) { match try!(input.next()) {
@ -1168,14 +1168,14 @@ impl LengthOrPercentage {
/// Parse a non-negative length. /// Parse a non-negative length.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> {
Self::parse_internal(context, input, AllowedNumericType::NonNegative) Self::parse_internal(context, input, AllowedLengthType::NonNegative)
} }
/// Parse a length, treating dimensionless numbers as pixels /// Parse a length, treating dimensionless numbers as pixels
/// ///
/// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value /// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value
pub fn parse_numbers_are_pixels(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> { pub fn parse_numbers_are_pixels(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> {
if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedNumericType::All)) { if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedLengthType::All)) {
return Ok(lop) return Ok(lop)
} }
@ -1191,7 +1191,7 @@ impl LengthOrPercentage {
pub fn parse_numbers_are_pixels_non_negative(context: &ParserContext, pub fn parse_numbers_are_pixels_non_negative(context: &ParserContext,
input: &mut Parser) input: &mut Parser)
-> Result<LengthOrPercentage, ()> { -> Result<LengthOrPercentage, ()> {
if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedNumericType::NonNegative)) { if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedLengthType::NonNegative)) {
return Ok(lop) return Ok(lop)
} }
@ -1217,7 +1217,7 @@ impl LengthOrPercentage {
impl Parse for LengthOrPercentage { impl Parse for LengthOrPercentage {
#[inline] #[inline]
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedNumericType::All) Self::parse_internal(context, input, AllowedLengthType::All)
} }
} }
@ -1270,7 +1270,7 @@ impl ToCss for LengthOrPercentageOrAuto {
} }
impl LengthOrPercentageOrAuto { impl LengthOrPercentageOrAuto {
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType)
-> Result<Self, ()> { -> Result<Self, ()> {
match try!(input.next()) { match try!(input.next()) {
Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
@ -1294,7 +1294,7 @@ impl LengthOrPercentageOrAuto {
/// Parse a non-negative length, percentage, or auto. /// Parse a non-negative length, percentage, or auto.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> {
Self::parse_internal(context, input, AllowedNumericType::NonNegative) Self::parse_internal(context, input, AllowedLengthType::NonNegative)
} }
/// Returns the `auto` value. /// Returns the `auto` value.
@ -1311,7 +1311,7 @@ impl LengthOrPercentageOrAuto {
impl Parse for LengthOrPercentageOrAuto { impl Parse for LengthOrPercentageOrAuto {
#[inline] #[inline]
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedNumericType::All) Self::parse_internal(context, input, AllowedLengthType::All)
} }
} }
@ -1348,7 +1348,7 @@ impl ToCss for LengthOrPercentageOrNone {
} }
} }
impl LengthOrPercentageOrNone { impl LengthOrPercentageOrNone {
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType)
-> Result<LengthOrPercentageOrNone, ()> -> Result<LengthOrPercentageOrNone, ()>
{ {
match try!(input.next()) { match try!(input.next()) {
@ -1372,14 +1372,14 @@ impl LengthOrPercentageOrNone {
/// Parse a non-negative LengthOrPercentageOrNone. /// Parse a non-negative LengthOrPercentageOrNone.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedNumericType::NonNegative) Self::parse_internal(context, input, AllowedLengthType::NonNegative)
} }
} }
impl Parse for LengthOrPercentageOrNone { impl Parse for LengthOrPercentageOrNone {
#[inline] #[inline]
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedNumericType::All) Self::parse_internal(context, input, AllowedLengthType::All)
} }
} }
@ -1414,7 +1414,7 @@ pub enum LengthOrPercentageOrAutoOrContent {
impl LengthOrPercentageOrAutoOrContent { impl LengthOrPercentageOrAutoOrContent {
/// Parse a non-negative LengthOrPercentageOrAutoOrContent. /// Parse a non-negative LengthOrPercentageOrAutoOrContent.
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let num_context = AllowedNumericType::NonNegative; let num_context = AllowedLengthType::NonNegative;
match try!(input.next()) { match try!(input.next()) {
Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
NoCalcLength::parse_dimension(context, value.value, unit) NoCalcLength::parse_dimension(context, value.value, unit)

View file

@ -151,24 +151,24 @@ macro_rules! __define_css_keyword_enum__actual {
pub mod specified { pub mod specified {
use app_units::Au; use app_units::Au;
/// Whether to allow negative values or not. /// Whether to allow negative lengths or not.
#[repr(u8)] #[repr(u8)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AllowedNumericType { pub enum AllowedLengthType {
/// Allow all kind of numeric values. /// Allow all kind of lengths.
All, All,
/// Allow only non-negative values. /// Allow only non-negative lengths.
NonNegative NonNegative
} }
impl AllowedNumericType { impl AllowedLengthType {
/// Whether value is valid for this allowed numeric type. /// Whether value is valid for this allowed length type.
#[inline] #[inline]
pub fn is_ok(&self, value: f32) -> bool { pub fn is_ok(&self, value: f32) -> bool {
match *self { match *self {
AllowedNumericType::All => true, AllowedLengthType::All => true,
AllowedNumericType::NonNegative => value >= 0., AllowedLengthType::NonNegative => value >= 0.,
} }
} }
@ -177,8 +177,8 @@ pub mod specified {
pub fn clamp(&self, val: Au) -> Au { pub fn clamp(&self, val: Au) -> Au {
use std::cmp; use std::cmp;
match *self { match *self {
AllowedNumericType::All => val, AllowedLengthType::All => val,
AllowedNumericType::NonNegative => cmp::max(Au(0), val), AllowedLengthType::NonNegative => cmp::max(Au(0), val),
} }
} }
} }

View file

@ -9,7 +9,7 @@ use cssparser::{Parser, ToCss};
use euclid::size::TypedSize2D; use euclid::size::TypedSize2D;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::fmt; use std::fmt;
use values::specified::AllowedNumericType; use values::specified::AllowedLengthType;
define_css_keyword_enum!(UserZoom: define_css_keyword_enum!(UserZoom:
"zoom" => Zoom, "zoom" => Zoom,
@ -95,9 +95,9 @@ impl Zoom {
use cssparser::Token; use cssparser::Token;
match try!(input.next()) { match try!(input.next()) {
Token::Percentage(ref value) if AllowedNumericType::NonNegative.is_ok(value.unit_value) => Token::Percentage(ref value) if AllowedLengthType::NonNegative.is_ok(value.unit_value) =>
Ok(Zoom::Percentage(value.unit_value)), Ok(Zoom::Percentage(value.unit_value)),
Token::Number(ref value) if AllowedNumericType::NonNegative.is_ok(value.value) => Token::Number(ref value) if AllowedLengthType::NonNegative.is_ok(value.value) =>
Ok(Zoom::Number(value.value)), Ok(Zoom::Number(value.value)),
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") =>
Ok(Zoom::Auto), Ok(Zoom::Auto),