mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Update cssparser to 0.18
https://github.com/servo/rust-cssparser/pull/171
This commit is contained in:
parent
30d6d6024b
commit
eb98ae6e04
64 changed files with 541 additions and 512 deletions
|
@ -240,11 +240,11 @@ impl Resolution {
|
|||
}
|
||||
|
||||
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let (value, unit) = match input.next()? {
|
||||
Token::Dimension { value, unit, .. } => {
|
||||
let (value, unit) = match *input.next()? {
|
||||
Token::Dimension { value, ref unit, .. } => {
|
||||
(value, unit)
|
||||
},
|
||||
t => return Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
};
|
||||
|
||||
if value <= 0. {
|
||||
|
@ -256,7 +256,7 @@ impl Resolution {
|
|||
"dppx" => Ok(Resolution::Dppx(value)),
|
||||
"dpcm" => Ok(Resolution::Dpcm(value)),
|
||||
_ => Err(())
|
||||
}).map_err(|()| StyleParseError::UnexpectedDimension(unit).into())
|
||||
}).map_err(|()| StyleParseError::UnexpectedDimension(unit.clone()).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,47 +474,55 @@ impl Expression {
|
|||
-> Result<Self, ParseError<'i>> {
|
||||
input.expect_parenthesis_block()?;
|
||||
input.parse_nested_block(|input| {
|
||||
let ident = input.expect_ident()?;
|
||||
// FIXME: remove extra indented block when lifetimes are non-lexical
|
||||
let feature;
|
||||
let range;
|
||||
{
|
||||
let ident = input.expect_ident()?;
|
||||
|
||||
let mut flags = 0;
|
||||
let result = {
|
||||
let mut feature_name = &*ident;
|
||||
let mut flags = 0;
|
||||
let result = {
|
||||
let mut feature_name = &**ident;
|
||||
|
||||
// TODO(emilio): this is under a pref in Gecko.
|
||||
if starts_with_ignore_ascii_case(feature_name, "-webkit-") {
|
||||
feature_name = &feature_name[8..];
|
||||
flags |= nsMediaFeature_RequirementFlags::eHasWebkitPrefix as u8;
|
||||
}
|
||||
// TODO(emilio): this is under a pref in Gecko.
|
||||
if starts_with_ignore_ascii_case(feature_name, "-webkit-") {
|
||||
feature_name = &feature_name[8..];
|
||||
flags |= nsMediaFeature_RequirementFlags::eHasWebkitPrefix as u8;
|
||||
}
|
||||
|
||||
let range = if starts_with_ignore_ascii_case(feature_name, "min-") {
|
||||
feature_name = &feature_name[4..];
|
||||
nsMediaExpression_Range::eMin
|
||||
} else if starts_with_ignore_ascii_case(feature_name, "max-") {
|
||||
feature_name = &feature_name[4..];
|
||||
nsMediaExpression_Range::eMax
|
||||
} else {
|
||||
nsMediaExpression_Range::eEqual
|
||||
let range = if starts_with_ignore_ascii_case(feature_name, "min-") {
|
||||
feature_name = &feature_name[4..];
|
||||
nsMediaExpression_Range::eMin
|
||||
} else if starts_with_ignore_ascii_case(feature_name, "max-") {
|
||||
feature_name = &feature_name[4..];
|
||||
nsMediaExpression_Range::eMax
|
||||
} else {
|
||||
nsMediaExpression_Range::eEqual
|
||||
};
|
||||
|
||||
let atom = Atom::from(feature_name);
|
||||
match find_feature(|f| atom.as_ptr() == unsafe { *f.mName }) {
|
||||
Some(f) => Ok((f, range)),
|
||||
None => Err(()),
|
||||
}
|
||||
};
|
||||
|
||||
let atom = Atom::from(feature_name);
|
||||
match find_feature(|f| atom.as_ptr() == unsafe { *f.mName }) {
|
||||
Some(f) => Ok((f, range)),
|
||||
None => Err(()),
|
||||
match result {
|
||||
Ok((f, r)) => {
|
||||
feature = f;
|
||||
range = r;
|
||||
}
|
||||
Err(()) => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
|
||||
}
|
||||
};
|
||||
|
||||
let (feature, range) = match result {
|
||||
Ok((feature, range)) => (feature, range),
|
||||
Err(()) => return Err(SelectorParseError::UnexpectedIdent(ident).into()),
|
||||
};
|
||||
if (feature.mReqFlags & !flags) != 0 {
|
||||
return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into());
|
||||
}
|
||||
|
||||
if (feature.mReqFlags & !flags) != 0 {
|
||||
return Err(SelectorParseError::UnexpectedIdent(ident).into());
|
||||
}
|
||||
|
||||
if range != nsMediaExpression_Range::eEqual &&
|
||||
feature.mRangeType != nsMediaFeature_RangeType::eMinMaxAllowed {
|
||||
return Err(SelectorParseError::UnexpectedIdent(ident).into());
|
||||
if range != nsMediaExpression_Range::eEqual &&
|
||||
feature.mRangeType != nsMediaFeature_RangeType::eMinMaxAllowed {
|
||||
return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into());
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no colon, this is a media query of the form
|
||||
|
@ -590,7 +598,7 @@ impl Expression {
|
|||
MediaExpressionValue::Enumerated(value)
|
||||
}
|
||||
nsMediaFeature_ValueType::eIdent => {
|
||||
MediaExpressionValue::Ident(input.expect_ident()?.into_owned())
|
||||
MediaExpressionValue::Ident(input.expect_ident()?.as_ref().to_owned())
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! Gecko-specific bits for selector-parsing.
|
||||
|
||||
use cssparser::{BasicParseError, Parser, ToCss, Token, CompactCowStr};
|
||||
use cssparser::{BasicParseError, Parser, ToCss, Token, CowRcStr};
|
||||
use element_state::ElementState;
|
||||
use gecko_bindings::structs::CSSPseudoClassType;
|
||||
use selector_parser::{SelectorParser, PseudoElementCascadeType};
|
||||
|
@ -267,12 +267,12 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
type Impl = SelectorImpl;
|
||||
type Error = StyleParseError<'i>;
|
||||
|
||||
fn is_pseudo_element_allows_single_colon(name: &CompactCowStr<'i>) -> bool {
|
||||
fn is_pseudo_element_allows_single_colon(name: &CowRcStr<'i>) -> bool {
|
||||
::selectors::parser::is_css2_pseudo_element(name) ||
|
||||
name.starts_with("-moz-tree-") // tree pseudo-elements
|
||||
}
|
||||
|
||||
fn parse_non_ts_pseudo_class(&self, name: CompactCowStr<'i>)
|
||||
fn parse_non_ts_pseudo_class(&self, name: CowRcStr<'i>)
|
||||
-> Result<NonTSPseudoClass, ParseError<'i>> {
|
||||
macro_rules! pseudo_class_parse {
|
||||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||
|
@ -294,7 +294,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
}
|
||||
|
||||
fn parse_non_ts_functional_pseudo_class<'t>(&self,
|
||||
name: CompactCowStr<'i>,
|
||||
name: CowRcStr<'i>,
|
||||
parser: &mut Parser<'i, 't>)
|
||||
-> Result<NonTSPseudoClass, ParseError<'i>> {
|
||||
macro_rules! pseudo_class_string_parse {
|
||||
|
@ -338,12 +338,12 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_pseudo_element(&self, name: CompactCowStr<'i>) -> Result<PseudoElement, ParseError<'i>> {
|
||||
fn parse_pseudo_element(&self, name: CowRcStr<'i>) -> Result<PseudoElement, ParseError<'i>> {
|
||||
PseudoElement::from_slice(&name, self.in_user_agent_stylesheet())
|
||||
.ok_or(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
|
||||
fn parse_functional_pseudo_element<'t>(&self, name: CompactCowStr<'i>,
|
||||
fn parse_functional_pseudo_element<'t>(&self, name: CowRcStr<'i>,
|
||||
parser: &mut Parser<'i, 't>)
|
||||
-> Result<PseudoElement, ParseError<'i>> {
|
||||
if name.starts_with("-moz-tree-") {
|
||||
|
@ -352,9 +352,9 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
let mut args = Vec::new();
|
||||
loop {
|
||||
match parser.next() {
|
||||
Ok(Token::Ident(ident)) => args.push(ident.into_owned()),
|
||||
Ok(Token::Comma) => {},
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
Ok(&Token::Ident(ref ident)) => args.push(ident.as_ref().to_owned()),
|
||||
Ok(&Token::Comma) => {},
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
Err(BasicParseError::EndOfInput) => break,
|
||||
_ => unreachable!("Parser::next() shouldn't return any other error"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue