… rather than the start location of the current construct. This likely places the error just *after* of the unexpected token whereas before would be best, but that’s likely a much bigger change. See https://bugzilla.mozilla.org/show_bug.cgi?id=1378861 Source-Repo: https://github.com/servo/servo Source-Revision: c79a54dbd9d3a590f5fd8191b8e57a0b9d1d0fdb
44 lines
1.8 KiB
Rust
44 lines
1.8 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
//! Specified types for CSS values related to backgrounds.
|
|
|
|
use cssparser::Parser;
|
|
use parser::{Parse, ParserContext};
|
|
use selectors::parser::SelectorParseErrorKind;
|
|
use style_traits::ParseError;
|
|
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
|
use values::specified::length::LengthOrPercentageOrAuto;
|
|
|
|
/// A specified value for the `background-size` property.
|
|
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
|
|
|
impl Parse for BackgroundSize {
|
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
|
if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) {
|
|
let height = input
|
|
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
|
|
.unwrap_or(LengthOrPercentageOrAuto::Auto);
|
|
return Ok(GenericBackgroundSize::Explicit { width, height });
|
|
}
|
|
let location = input.current_source_location();
|
|
let ident = input.expect_ident()?;
|
|
(match_ignore_ascii_case! { &ident,
|
|
"cover" => Ok(GenericBackgroundSize::Cover),
|
|
"contain" => Ok(GenericBackgroundSize::Contain),
|
|
_ => Err(()),
|
|
}).map_err(|()| location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
|
}
|
|
}
|
|
|
|
impl BackgroundSize {
|
|
/// Returns `auto auto`.
|
|
pub fn auto() -> Self {
|
|
GenericBackgroundSize::Explicit {
|
|
width: LengthOrPercentageOrAuto::Auto,
|
|
height: LengthOrPercentageOrAuto::Auto,
|
|
}
|
|
}
|
|
}
|