mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Defined new trait ParseErrorReporter and added error_reporter member to ParserContext
This commit is contained in:
parent
8efc954531
commit
996e9e06b2
24 changed files with 194 additions and 69 deletions
|
@ -16,10 +16,12 @@ use std::cell::Cell;
|
|||
use std::iter::Iterator;
|
||||
use std::slice;
|
||||
use string_cache::{Atom, Namespace};
|
||||
use style_traits::ParseErrorReporter;
|
||||
use url::Url;
|
||||
use util::mem::HeapSizeOf;
|
||||
use viewport::ViewportRule;
|
||||
|
||||
|
||||
/// Each style rule has an origin, which determines where it enters the cascade.
|
||||
///
|
||||
/// http://dev.w3.org/csswg/css-cascade/#cascading-origins
|
||||
|
@ -80,31 +82,33 @@ pub struct StyleRule {
|
|||
impl Stylesheet {
|
||||
pub fn from_bytes_iter<I: Iterator<Item=Vec<u8>>>(
|
||||
input: I, base_url: Url, protocol_encoding_label: Option<&str>,
|
||||
environment_encoding: Option<EncodingRef>, origin: Origin) -> Stylesheet {
|
||||
environment_encoding: Option<EncodingRef>, origin: Origin,
|
||||
error_reporter: Box<ParseErrorReporter + Send>) -> Stylesheet {
|
||||
let mut bytes = vec![];
|
||||
// TODO: incremental decoding and tokenization/parsing
|
||||
for chunk in input {
|
||||
bytes.push_all(&chunk)
|
||||
}
|
||||
Stylesheet::from_bytes(&bytes, base_url, protocol_encoding_label,
|
||||
environment_encoding, origin)
|
||||
environment_encoding, origin, error_reporter)
|
||||
}
|
||||
|
||||
pub fn from_bytes(bytes: &[u8],
|
||||
base_url: Url,
|
||||
protocol_encoding_label: Option<&str>,
|
||||
environment_encoding: Option<EncodingRef>,
|
||||
origin: Origin)
|
||||
origin: Origin, error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> Stylesheet {
|
||||
// TODO: bytes.as_slice could be bytes.container_as_bytes()
|
||||
let (string, _) = decode_stylesheet_bytes(
|
||||
bytes, protocol_encoding_label, environment_encoding);
|
||||
Stylesheet::from_str(&string, base_url, origin)
|
||||
Stylesheet::from_str(&string, base_url, origin, error_reporter)
|
||||
}
|
||||
|
||||
pub fn from_str(css: &str, base_url: Url, origin: Origin) -> Stylesheet {
|
||||
pub fn from_str(css: &str, base_url: Url, origin: Origin,
|
||||
error_reporter: Box<ParseErrorReporter + Send>) -> Stylesheet {
|
||||
let rule_parser = TopLevelRuleParser {
|
||||
context: ParserContext::new(origin, &base_url),
|
||||
context: ParserContext::new(origin, &base_url, error_reporter),
|
||||
state: Cell::new(State::Start),
|
||||
};
|
||||
let mut input = Parser::new(css);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue