mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Run rustfmt on selectors, servo_arc, and style.
This was generated with: ./mach cargo fmt --package selectors && ./mach cargo fmt --package servo_arc && ./mach cargo fmt --package style Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
parent
f7ae1a37e3
commit
c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions
|
@ -15,7 +15,7 @@ use std::cmp;
|
|||
use std::ops::{Add, Mul};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
||||
use super::{AllowQuirks, Number, Percentage, ToComputedValue};
|
||||
use values::{Auto, CSSFloat, Either, Normal};
|
||||
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
|
||||
use values::generics::NonNegative;
|
||||
|
@ -62,7 +62,7 @@ pub enum FontRelativeLength {
|
|||
Ch(CSSFloat),
|
||||
/// A "rem" value: https://drafts.csswg.org/css-values/#rem
|
||||
#[css(dimension)]
|
||||
Rem(CSSFloat)
|
||||
Rem(CSSFloat),
|
||||
}
|
||||
|
||||
/// A source to resolve font-relative units against
|
||||
|
@ -88,8 +88,9 @@ impl FontBaseSize {
|
|||
match *self {
|
||||
FontBaseSize::Custom(size) => size,
|
||||
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size().size(),
|
||||
FontBaseSize::InheritedStyleButStripEmUnits |
|
||||
FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size().size(),
|
||||
FontBaseSize::InheritedStyleButStripEmUnits | FontBaseSize::InheritedStyle => {
|
||||
context.style().get_parent_font().clone_font_size().size()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +100,9 @@ impl FontRelativeLength {
|
|||
pub fn to_computed_value(&self, context: &Context, base_size: FontBaseSize) -> CSSPixelLength {
|
||||
use std::f32;
|
||||
let (reference_size, length) = self.reference_font_size_and_length(context, base_size);
|
||||
let pixel = (length * reference_size.to_f32_px()).min(f32::MAX).max(f32::MIN);
|
||||
let pixel = (length * reference_size.to_f32_px())
|
||||
.min(f32::MAX)
|
||||
.max(f32::MIN);
|
||||
CSSPixelLength::new(pixel)
|
||||
}
|
||||
|
||||
|
@ -133,10 +136,10 @@ impl FontRelativeLength {
|
|||
FontRelativeLength::Em(length) => {
|
||||
if context.for_non_inherited_property.is_some() {
|
||||
if base_size == FontBaseSize::CurrentStyle {
|
||||
context.rule_cache_conditions.borrow_mut()
|
||||
.set_font_size_dependency(
|
||||
reference_font_size.into()
|
||||
);
|
||||
context
|
||||
.rule_cache_conditions
|
||||
.borrow_mut()
|
||||
.set_font_size_dependency(reference_font_size.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,18 +154,14 @@ impl FontRelativeLength {
|
|||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
let reference_size = match query_font_metrics(context, reference_font_size) {
|
||||
FontMetricsQueryResult::Available(metrics) => {
|
||||
metrics.x_height
|
||||
},
|
||||
FontMetricsQueryResult::Available(metrics) => metrics.x_height,
|
||||
// https://drafts.csswg.org/css-values/#ex
|
||||
//
|
||||
// In the cases where it is impossible or impractical to
|
||||
// determine the x-height, a value of 0.5em must be
|
||||
// assumed.
|
||||
//
|
||||
FontMetricsQueryResult::NotAvailable => {
|
||||
reference_font_size.scale_by(0.5)
|
||||
},
|
||||
FontMetricsQueryResult::NotAvailable => reference_font_size.scale_by(0.5),
|
||||
};
|
||||
(reference_size, length)
|
||||
},
|
||||
|
@ -171,9 +170,7 @@ impl FontRelativeLength {
|
|||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
let reference_size = match query_font_metrics(context, reference_font_size) {
|
||||
FontMetricsQueryResult::Available(metrics) => {
|
||||
metrics.zero_advance_measure
|
||||
},
|
||||
FontMetricsQueryResult::Available(metrics) => metrics.zero_advance_measure,
|
||||
// https://drafts.csswg.org/css-values/#ch
|
||||
//
|
||||
// In the cases where it is impossible or impractical to
|
||||
|
@ -190,10 +187,10 @@ impl FontRelativeLength {
|
|||
} else {
|
||||
reference_font_size.scale_by(0.5)
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
(reference_size, length)
|
||||
}
|
||||
},
|
||||
FontRelativeLength::Rem(length) => {
|
||||
// https://drafts.csswg.org/css-values/#rem:
|
||||
//
|
||||
|
@ -207,7 +204,7 @@ impl FontRelativeLength {
|
|||
context.device().root_font_size()
|
||||
};
|
||||
(reference_size, length)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,21 +225,21 @@ pub enum ViewportPercentageLength {
|
|||
Vmin(CSSFloat),
|
||||
/// <https://drafts.csswg.org/css-values/#vmax>
|
||||
#[css(dimension)]
|
||||
Vmax(CSSFloat)
|
||||
Vmax(CSSFloat),
|
||||
}
|
||||
|
||||
impl ViewportPercentageLength {
|
||||
/// Computes the given viewport-relative length for the given viewport size.
|
||||
pub fn to_computed_value(&self, viewport_size: Size2D<Au>) -> CSSPixelLength {
|
||||
let (factor, length) = match *self {
|
||||
ViewportPercentageLength::Vw(length) =>
|
||||
(length, viewport_size.width),
|
||||
ViewportPercentageLength::Vh(length) =>
|
||||
(length, viewport_size.height),
|
||||
ViewportPercentageLength::Vmin(length) =>
|
||||
(length, cmp::min(viewport_size.width, viewport_size.height)),
|
||||
ViewportPercentageLength::Vmax(length) =>
|
||||
(length, cmp::max(viewport_size.width, viewport_size.height)),
|
||||
ViewportPercentageLength::Vw(length) => (length, viewport_size.width),
|
||||
ViewportPercentageLength::Vh(length) => (length, viewport_size.height),
|
||||
ViewportPercentageLength::Vmin(length) => {
|
||||
(length, cmp::min(viewport_size.width, viewport_size.height))
|
||||
},
|
||||
ViewportPercentageLength::Vmax(length) => {
|
||||
(length, cmp::max(viewport_size.width, viewport_size.height))
|
||||
},
|
||||
};
|
||||
|
||||
// FIXME: Bug 1396535, we need to fix the extremely small viewport length for transform.
|
||||
|
@ -300,13 +297,13 @@ pub enum AbsoluteLength {
|
|||
impl AbsoluteLength {
|
||||
fn is_zero(&self) -> bool {
|
||||
match *self {
|
||||
AbsoluteLength::Px(v)
|
||||
| AbsoluteLength::In(v)
|
||||
| AbsoluteLength::Cm(v)
|
||||
| AbsoluteLength::Mm(v)
|
||||
| AbsoluteLength::Q(v)
|
||||
| AbsoluteLength::Pt(v)
|
||||
| AbsoluteLength::Pc(v) => v == 0.,
|
||||
AbsoluteLength::Px(v) |
|
||||
AbsoluteLength::In(v) |
|
||||
AbsoluteLength::Cm(v) |
|
||||
AbsoluteLength::Mm(v) |
|
||||
AbsoluteLength::Q(v) |
|
||||
AbsoluteLength::Pt(v) |
|
||||
AbsoluteLength::Pc(v) => v == 0.,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +474,7 @@ impl NoCalcLength {
|
|||
pub fn is_zero(&self) -> bool {
|
||||
match *self {
|
||||
NoCalcLength::Absolute(length) => length.is_zero(),
|
||||
_ => false
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,25 +574,31 @@ impl Length {
|
|||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) =>
|
||||
{
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(Length::NoCalc)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode) {
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
return Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value))))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
ref token => return Err(location.new_unexpected_token_error(token.clone()))
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
return Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(
|
||||
value,
|
||||
))));
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
ref token => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
}
|
||||
input.parse_nested_block(|input| {
|
||||
CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc)))
|
||||
CalcNode::parse_length(context, input, num_context)
|
||||
.map(|calc| Length::Calc(Box::new(calc)))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -615,7 +618,12 @@ impl Length {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(
|
||||
context,
|
||||
input,
|
||||
AllowedNumericType::NonNegative,
|
||||
allow_quirks,
|
||||
)
|
||||
}
|
||||
|
||||
/// Get an absolute length from a px value.
|
||||
|
@ -626,7 +634,10 @@ impl Length {
|
|||
}
|
||||
|
||||
impl Parse for Length {
|
||||
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>> {
|
||||
Self::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
@ -717,7 +728,7 @@ impl From<Percentage> for LengthOrPercentage {
|
|||
if pc.is_calc() {
|
||||
LengthOrPercentage::Calc(Box::new(CalcLengthOrPercentage {
|
||||
percentage: Some(computed::Percentage(pc.get())),
|
||||
.. Default::default()
|
||||
..Default::default()
|
||||
}))
|
||||
} else {
|
||||
LengthOrPercentage::Percentage(computed::Percentage(pc.get()))
|
||||
|
@ -750,31 +761,37 @@ impl LengthOrPercentage {
|
|||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) =>
|
||||
{
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(LengthOrPercentage::Length)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentage::Percentage(computed::Percentage(unit_value)))
|
||||
}
|
||||
},
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(LengthOrPercentage::Percentage(computed::Percentage(
|
||||
unit_value,
|
||||
)))
|
||||
},
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode) {
|
||||
return Err(location.new_unexpected_token_error(token.clone()))
|
||||
if value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(location.new_unexpected_token_error(token.clone()));
|
||||
} else {
|
||||
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)))
|
||||
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)));
|
||||
}
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone()))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
let calc = input
|
||||
.parse_nested_block(|i| CalcNode::parse_length_or_percentage(context, i, num_context))?;
|
||||
Ok(LengthOrPercentage::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
|
@ -794,13 +811,21 @@ impl LengthOrPercentage {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<LengthOrPercentage, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(
|
||||
context,
|
||||
input,
|
||||
AllowedNumericType::NonNegative,
|
||||
allow_quirks,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentage {
|
||||
#[inline]
|
||||
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>> {
|
||||
Self::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
@ -809,9 +834,11 @@ impl LengthOrPercentage {
|
|||
/// Parses a length or a percentage, allowing the unitless length quirk.
|
||||
/// <https://quirks.spec.whatwg.org/#the-unitless-length-quirk>
|
||||
#[inline]
|
||||
pub fn parse_quirky<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ParseError<'i>> {
|
||||
pub fn parse_quirky<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
|
||||
}
|
||||
}
|
||||
|
@ -852,35 +879,41 @@ impl LengthOrPercentageOrAuto {
|
|||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) =>
|
||||
{
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(LengthOrPercentageOrAuto::Length)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentageOrAuto::Percentage(computed::Percentage(unit_value)))
|
||||
}
|
||||
},
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(LengthOrPercentageOrAuto::Percentage(computed::Percentage(
|
||||
unit_value,
|
||||
)))
|
||||
},
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode) {
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
if value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
return Ok(LengthOrPercentageOrAuto::Length(
|
||||
NoCalcLength::Absolute(AbsoluteLength::Px(value))
|
||||
))
|
||||
}
|
||||
return Ok(LengthOrPercentageOrAuto::Length(NoCalcLength::Absolute(
|
||||
AbsoluteLength::Px(value),
|
||||
)));
|
||||
},
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
|
||||
return Ok(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone()))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
let calc = input
|
||||
.parse_nested_block(|i| CalcNode::parse_length_or_percentage(context, i, num_context))?;
|
||||
Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
|
@ -900,7 +933,12 @@ impl LengthOrPercentageOrAuto {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(
|
||||
context,
|
||||
input,
|
||||
AllowedNumericType::NonNegative,
|
||||
allow_quirks,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the `auto` value.
|
||||
|
@ -932,7 +970,10 @@ impl LengthOrPercentageOrAuto {
|
|||
|
||||
impl Parse for LengthOrPercentageOrAuto {
|
||||
#[inline]
|
||||
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>> {
|
||||
Self::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
@ -962,8 +1003,14 @@ impl NonNegativeLengthOrPercentageOrAuto {
|
|||
|
||||
impl Parse for NonNegativeLengthOrPercentageOrAuto {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
Ok(NonNegative(LengthOrPercentageOrAuto::parse_non_negative(context, input)?))
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(NonNegative(LengthOrPercentageOrAuto::parse_non_negative(
|
||||
context,
|
||||
input,
|
||||
)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -989,34 +1036,41 @@ impl LengthOrPercentageOrNone {
|
|||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) =>
|
||||
{
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(LengthOrPercentageOrNone::Length)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentageOrNone::Percentage(computed::Percentage(unit_value)))
|
||||
}
|
||||
},
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(LengthOrPercentageOrNone::Percentage(computed::Percentage(
|
||||
unit_value,
|
||||
)))
|
||||
},
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode) {
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
return Ok(LengthOrPercentageOrNone::Length(
|
||||
NoCalcLength::Absolute(AbsoluteLength::Px(value))
|
||||
))
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
return Ok(LengthOrPercentageOrNone::Length(NoCalcLength::Absolute(
|
||||
AbsoluteLength::Px(value),
|
||||
)));
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => {
|
||||
return Ok(LengthOrPercentageOrNone::None)
|
||||
}
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone()))
|
||||
},
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
let calc = input
|
||||
.parse_nested_block(|i| CalcNode::parse_length_or_percentage(context, i, num_context))?;
|
||||
Ok(LengthOrPercentageOrNone::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
|
@ -1036,13 +1090,21 @@ impl LengthOrPercentageOrNone {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
|
||||
Self::parse_internal(
|
||||
context,
|
||||
input,
|
||||
AllowedNumericType::NonNegative,
|
||||
allow_quirks,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for LengthOrPercentageOrNone {
|
||||
#[inline]
|
||||
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>> {
|
||||
Self::parse_internal(context, input, AllowedNumericType::All, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
@ -1065,8 +1127,12 @@ impl From<NoCalcLength> for NonNegativeLengthOrPercentage {
|
|||
|
||||
impl Parse for NonNegativeLengthOrPercentage {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
LengthOrPercentage::parse_non_negative(context, input).map(NonNegative::<LengthOrPercentage>)
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
LengthOrPercentage::parse_non_negative(context, input)
|
||||
.map(NonNegative::<LengthOrPercentage>)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1109,7 +1175,7 @@ impl LengthOrNumber {
|
|||
// LengthOrNumber, we want "0" to be parsed as a plain Number rather
|
||||
// than a Length (0px); this matches the behaviour of all major browsers
|
||||
if let Ok(v) = input.try(|i| Number::parse_non_negative(context, i)) {
|
||||
return Ok(Either::Second(v))
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
|
||||
Length::parse_non_negative(context, input).map(Either::First)
|
||||
|
@ -1136,7 +1202,10 @@ pub enum MozLength {
|
|||
}
|
||||
|
||||
impl Parse for MozLength {
|
||||
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>> {
|
||||
MozLength::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
@ -1163,11 +1232,8 @@ impl MozLength {
|
|||
return Ok(MozLength::ExtremumLength(l));
|
||||
}
|
||||
|
||||
let length = LengthOrPercentageOrAuto::parse_non_negative_quirky(
|
||||
context,
|
||||
input,
|
||||
allow_quirks,
|
||||
)?;
|
||||
let length =
|
||||
LengthOrPercentageOrAuto::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(MozLength::LengthOrPercentageOrAuto(length))
|
||||
}
|
||||
|
||||
|
@ -1193,7 +1259,10 @@ pub enum MaxLength {
|
|||
}
|
||||
|
||||
impl Parse for MaxLength {
|
||||
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>> {
|
||||
MaxLength::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
@ -1220,11 +1289,8 @@ impl MaxLength {
|
|||
return Ok(MaxLength::ExtremumLength(l));
|
||||
}
|
||||
|
||||
let length = LengthOrPercentageOrNone::parse_non_negative_quirky(
|
||||
context,
|
||||
input,
|
||||
allow_quirks,
|
||||
)?;
|
||||
let length =
|
||||
LengthOrPercentageOrNone::parse_non_negative_quirky(context, input, allow_quirks)?;
|
||||
Ok(MaxLength::LengthOrPercentageOrNone(length))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue