mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
Thread ParseError return values through CSS parsing.
This commit is contained in:
parent
58e39bfffa
commit
27ae1ef2e7
121 changed files with 2133 additions and 1505 deletions
|
@ -13,9 +13,10 @@ use media_queries::MediaType;
|
|||
use parser::ParserContext;
|
||||
use properties::{ComputedValues, StyleBuilder};
|
||||
use properties::longhands::font_size;
|
||||
use selectors::parser::SelectorParseError;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
|
||||
use style_traits::{CSSPixel, ToCss};
|
||||
use style_traits::{CSSPixel, ToCss, ParseError};
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use values::computed::{self, ToComputedValue};
|
||||
use values::specified;
|
||||
|
@ -151,7 +152,8 @@ impl Expression {
|
|||
/// ```
|
||||
///
|
||||
/// Only supports width and width ranges for now.
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
try!(input.expect_parenthesis_block());
|
||||
input.parse_nested_block(|input| {
|
||||
let name = try!(input.expect_ident());
|
||||
|
@ -167,7 +169,7 @@ impl Expression {
|
|||
"width" => {
|
||||
ExpressionKind::Width(Range::Eq(try!(specified::Length::parse_non_negative(context, input))))
|
||||
},
|
||||
_ => return Err(())
|
||||
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use restyle_hints::ElementSnapshot;
|
|||
use selector_parser::{AttrValue as SelectorAttrValue, ElementExt, PseudoElementCascadeType, SelectorParser};
|
||||
use selectors::Element;
|
||||
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint};
|
||||
use selectors::parser::SelectorMethods;
|
||||
use selectors::parser::{SelectorMethods, SelectorParseError};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
|
@ -24,6 +24,7 @@ use std::fmt;
|
|||
use std::fmt::Debug;
|
||||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use style_traits::{ParseError, StyleParseError};
|
||||
|
||||
/// A pseudo-element, both public and private.
|
||||
///
|
||||
|
@ -300,10 +301,12 @@ impl ::selectors::SelectorImpl for SelectorImpl {
|
|||
type BorrowedNamespaceUrl = Namespace;
|
||||
}
|
||||
|
||||
impl<'a> ::selectors::Parser for SelectorParser<'a> {
|
||||
impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
||||
type Impl = SelectorImpl;
|
||||
type Error = StyleParseError<'i>;
|
||||
|
||||
fn parse_non_ts_pseudo_class(&self, name: Cow<str>) -> Result<NonTSPseudoClass, ()> {
|
||||
fn parse_non_ts_pseudo_class(&self, name: Cow<'i, str>)
|
||||
-> Result<NonTSPseudoClass, ParseError<'i>> {
|
||||
use self::NonTSPseudoClass::*;
|
||||
let pseudo_class = match_ignore_ascii_case! { &name,
|
||||
"active" => Active,
|
||||
|
@ -323,20 +326,21 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
|
|||
"visited" => Visited,
|
||||
"-servo-nonzero-border" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(());
|
||||
return Err(SelectorParseError::UnexpectedIdent(
|
||||
"-servo-nonzero-border".into()).into());
|
||||
}
|
||||
ServoNonZeroBorder
|
||||
},
|
||||
_ => return Err(())
|
||||
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into()),
|
||||
};
|
||||
|
||||
Ok(pseudo_class)
|
||||
}
|
||||
|
||||
fn parse_non_ts_functional_pseudo_class(&self,
|
||||
name: Cow<str>,
|
||||
parser: &mut CssParser)
|
||||
-> Result<NonTSPseudoClass, ()> {
|
||||
fn parse_non_ts_functional_pseudo_class<'t>(&self,
|
||||
name: Cow<'i, str>,
|
||||
parser: &mut CssParser<'i, 't>)
|
||||
-> Result<NonTSPseudoClass, ParseError<'i>> {
|
||||
use self::NonTSPseudoClass::*;
|
||||
let pseudo_class = match_ignore_ascii_case!{ &name,
|
||||
"lang" => {
|
||||
|
@ -344,18 +348,17 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
|
|||
}
|
||||
"-servo-case-sensitive-type-attr" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(());
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into());
|
||||
}
|
||||
ServoCaseSensitiveTypeAttr(Atom::from(parser.expect_ident()?))
|
||||
}
|
||||
_ => return Err(())
|
||||
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
};
|
||||
|
||||
Ok(pseudo_class)
|
||||
}
|
||||
|
||||
fn parse_pseudo_element(&self, name: Cow<str>)
|
||||
-> Result<PseudoElement, ()> {
|
||||
fn parse_pseudo_element(&self, name: Cow<'i, str>) -> Result<PseudoElement, ParseError<'i>> {
|
||||
use self::PseudoElement::*;
|
||||
let pseudo_element = match_ignore_ascii_case! { &name,
|
||||
"before" => Before,
|
||||
|
@ -363,77 +366,78 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
|
|||
"selection" => Selection,
|
||||
"-servo-details-summary" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
DetailsSummary
|
||||
},
|
||||
"-servo-details-content" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
DetailsContent
|
||||
},
|
||||
"-servo-text" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoText
|
||||
},
|
||||
"-servo-input-text" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoInputText
|
||||
},
|
||||
"-servo-table-wrapper" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoTableWrapper
|
||||
},
|
||||
"-servo-anonymous-table-wrapper" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoAnonymousTableWrapper
|
||||
},
|
||||
"-servo-anonymous-table" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoAnonymousTable
|
||||
},
|
||||
"-servo-anonymous-table-row" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoAnonymousTableRow
|
||||
},
|
||||
"-servo-anonymous-table-cell" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoAnonymousTableCell
|
||||
},
|
||||
"-servo-anonymous-block" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoAnonymousBlock
|
||||
},
|
||||
"-servo-inline-block-wrapper" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoInlineBlockWrapper
|
||||
},
|
||||
"-servo-input-absolute" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
}
|
||||
ServoInlineAbsolute
|
||||
},
|
||||
_ => return Err(())
|
||||
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
|
||||
|
||||
};
|
||||
|
||||
Ok(pseudo_element)
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::fmt::{self, Write};
|
|||
// nonzero optimization is important in keeping the size of SpecifiedUrl below
|
||||
// the threshold.
|
||||
use std::sync::Arc;
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{ToCss, ParseError};
|
||||
|
||||
/// A specified url() value for servo.
|
||||
///
|
||||
|
@ -43,7 +43,7 @@ impl SpecifiedUrl {
|
|||
/// gecko version.
|
||||
pub fn parse_from_string<'a>(url: Cow<'a, str>,
|
||||
context: &ParserContext)
|
||||
-> Result<Self, ()> {
|
||||
-> Result<Self, ParseError<'a>> {
|
||||
let serialization = Arc::new(url.into_owned());
|
||||
let resolved = context.url_data.join(&serialization).ok();
|
||||
Ok(SpecifiedUrl {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue