mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use canvas_traits::{CanvasGradientStop, FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle};
|
||||
use cssparser::{Parser, RGBA};
|
||||
use cssparser::{Parser, ParserInput, RGBA};
|
||||
use cssparser::Color as CSSColor;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::CanvasGradientBinding;
|
||||
|
@ -53,7 +53,8 @@ impl CanvasGradientMethods for CanvasGradient {
|
|||
return Err(Error::IndexSize);
|
||||
}
|
||||
|
||||
let mut parser = Parser::new(&color);
|
||||
let mut input = ParserInput::new(&color);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let color = CSSColor::parse(&mut parser);
|
||||
let color = if parser.is_exhausted() {
|
||||
match color {
|
||||
|
|
|
@ -6,7 +6,7 @@ use canvas_traits::{Canvas2dMsg, CanvasCommonMsg, CanvasMsg};
|
|||
use canvas_traits::{CompositionOrBlending, FillOrStrokeStyle, FillRule};
|
||||
use canvas_traits::{LineCapStyle, LineJoinStyle, LinearGradientStyle};
|
||||
use canvas_traits::{RadialGradientStyle, RepetitionStyle, byte_swap_and_premultiply};
|
||||
use cssparser::{Parser, RGBA};
|
||||
use cssparser::{Parser, ParserInput, RGBA};
|
||||
use cssparser::Color as CSSColor;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
|
||||
|
@ -463,7 +463,8 @@ impl CanvasRenderingContext2D {
|
|||
}
|
||||
|
||||
fn parse_color(&self, string: &str) -> Result<RGBA, ()> {
|
||||
let mut parser = Parser::new(&string);
|
||||
let mut input = ParserInput::new(string);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let color = CSSColor::parse(&mut parser);
|
||||
if parser.is_exhausted() {
|
||||
match color {
|
||||
|
@ -1314,7 +1315,8 @@ impl Drop for CanvasRenderingContext2D {
|
|||
}
|
||||
|
||||
pub fn parse_color(string: &str) -> Result<RGBA, ()> {
|
||||
let mut parser = Parser::new(&string);
|
||||
let mut input = ParserInput::new(string);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
match CSSColor::parse(&mut parser) {
|
||||
Ok(CSSColor::RGBA(rgba)) => {
|
||||
if parser.is_exhausted() {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::{Parser, serialize_identifier};
|
||||
use cssparser::{Parser, ParserInput, serialize_identifier};
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::reflector::Reflector;
|
||||
|
@ -39,7 +39,8 @@ impl CSS {
|
|||
|
||||
/// https://drafts.csswg.org/css-conditional/#dom-css-supports
|
||||
pub fn Supports_(win: &Window, condition: DOMString) -> bool {
|
||||
let mut input = Parser::new(&condition);
|
||||
let mut input = ParserInput::new(&condition);
|
||||
let mut input = Parser::new(&mut input);
|
||||
let cond = parse_condition_or_declaration(&mut input);
|
||||
if let Ok(cond) = cond {
|
||||
let url = win.Document().url();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding;
|
||||
use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding::CSSKeyframesRuleMethods;
|
||||
use dom::bindings::error::ErrorResult;
|
||||
|
@ -58,7 +58,8 @@ impl CSSKeyframesRule {
|
|||
|
||||
/// Given a keyframe selector, finds the index of the first corresponding rule if any
|
||||
fn find_rule(&self, selector: &str) -> Option<usize> {
|
||||
let mut input = Parser::new(selector);
|
||||
let mut input = ParserInput::new(selector);
|
||||
let mut input = Parser::new(&mut input);
|
||||
if let Ok(sel) = KeyframeSelector::parse(&mut input) {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
// This finds the *last* element matching a selector
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use dom::bindings::codegen::Bindings::CSSMediaRuleBinding;
|
||||
use dom::bindings::codegen::Bindings::CSSMediaRuleBinding::CSSMediaRuleMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
|
@ -69,7 +69,8 @@ impl CSSMediaRule {
|
|||
|
||||
/// https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface
|
||||
pub fn set_condition_text(&self, text: DOMString) {
|
||||
let mut input = Parser::new(&text);
|
||||
let mut input = ParserInput::new(&text);
|
||||
let mut input = Parser::new(&mut input);
|
||||
let global = self.global();
|
||||
let win = global.as_window();
|
||||
let url = win.get_url();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use dom::bindings::codegen::Bindings::CSSSupportsRuleBinding;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
use dom::bindings::js::Root;
|
||||
|
@ -55,7 +55,8 @@ impl CSSSupportsRule {
|
|||
|
||||
/// https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
|
||||
pub fn set_condition_text(&self, text: DOMString) {
|
||||
let mut input = Parser::new(&text);
|
||||
let mut input = ParserInput::new(&text);
|
||||
let mut input = Parser::new(&mut input);
|
||||
let cond = SupportsCondition::parse(&mut input);
|
||||
if let Ok(cond) = cond {
|
||||
let global = self.global();
|
||||
|
|
|
@ -2061,7 +2061,7 @@ impl ElementMethods for Element {
|
|||
// https://dom.spec.whatwg.org/#dom-element-matches
|
||||
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
Err(()) => Err(Error::Syntax),
|
||||
Err(_) => Err(Error::Syntax),
|
||||
Ok(selectors) => {
|
||||
let mut ctx = MatchingContext::new(MatchingMode::Normal, None);
|
||||
Ok(matches_selector_list(&selectors, &Root::from_ref(self), &mut ctx))
|
||||
|
@ -2077,7 +2077,7 @@ impl ElementMethods for Element {
|
|||
// https://dom.spec.whatwg.org/#dom-element-closest
|
||||
fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
Err(()) => Err(Error::Syntax),
|
||||
Err(_) => Err(Error::Syntax),
|
||||
Ok(selectors) => {
|
||||
let root = self.upcast::<Node>();
|
||||
for element in root.inclusive_ancestors() {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::Parser as CssParser;
|
||||
use cssparser::{Parser as CssParser, ParserInput};
|
||||
use dom::attr::Attr;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListBinding::DOMTokenListMethods;
|
||||
|
@ -278,7 +278,8 @@ impl HTMLLinkElement {
|
|||
None => "",
|
||||
};
|
||||
|
||||
let mut css_parser = CssParser::new(&mq_str);
|
||||
let mut input = ParserInput::new(&mq_str);
|
||||
let mut css_parser = CssParser::new(&mut input);
|
||||
let win = document.window();
|
||||
let doc_url = document.url();
|
||||
let context = CssParserContext::new_for_cssom(&doc_url, win.css_error_reporter(), Some(CssRuleType::Media),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::Parser as CssParser;
|
||||
use cssparser::{Parser as CssParser, ParserInput};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::HTMLStyleElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLStyleElementBinding::HTMLStyleElementMethods;
|
||||
|
@ -91,8 +91,9 @@ impl HTMLStyleElement {
|
|||
PARSING_MODE_DEFAULT,
|
||||
doc.quirks_mode());
|
||||
let shared_lock = node.owner_doc().style_shared_lock().clone();
|
||||
let mut input = ParserInput::new(&mq_str);
|
||||
let mq = Arc::new(shared_lock.wrap(
|
||||
parse_media_query_list(&context, &mut CssParser::new(&mq_str))));
|
||||
parse_media_query_list(&context, &mut CssParser::new(&mut input))));
|
||||
let loader = StylesheetLoader::for_element(self.upcast());
|
||||
let sheet = Stylesheet::from_str(&data, win.get_url(), Origin::Author, mq,
|
||||
shared_lock, Some(&loader),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use dom::bindings::codegen::Bindings::MediaListBinding;
|
||||
use dom::bindings::codegen::Bindings::MediaListBinding::MediaListMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
|
@ -71,7 +71,8 @@ impl MediaListMethods for MediaList {
|
|||
return;
|
||||
}
|
||||
// Step 3
|
||||
let mut parser = Parser::new(&value);
|
||||
let mut input = ParserInput::new(&value);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let global = self.global();
|
||||
let win = global.as_window();
|
||||
let url = win.get_url();
|
||||
|
@ -107,7 +108,8 @@ impl MediaListMethods for MediaList {
|
|||
// https://drafts.csswg.org/cssom/#dom-medialist-appendmedium
|
||||
fn AppendMedium(&self, medium: DOMString) {
|
||||
// Step 1
|
||||
let mut parser = Parser::new(&medium);
|
||||
let mut input = ParserInput::new(&medium);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let global = self.global();
|
||||
let win = global.as_window();
|
||||
let url = win.get_url();
|
||||
|
@ -135,7 +137,8 @@ impl MediaListMethods for MediaList {
|
|||
// https://drafts.csswg.org/cssom/#dom-medialist-deletemedium
|
||||
fn DeleteMedium(&self, medium: DOMString) {
|
||||
// Step 1
|
||||
let mut parser = Parser::new(&medium);
|
||||
let mut input = ParserInput::new(&medium);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let global = self.global();
|
||||
let win = global.as_window();
|
||||
let url = win.get_url();
|
||||
|
|
|
@ -717,7 +717,7 @@ impl Node {
|
|||
// Step 1.
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
// Step 2.
|
||||
Err(()) => Err(Error::Syntax),
|
||||
Err(_) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
Ok(selectors) => {
|
||||
let mut ctx = MatchingContext::new(MatchingMode::Normal, None);
|
||||
|
@ -737,7 +737,7 @@ impl Node {
|
|||
// Step 1.
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
// Step 2.
|
||||
Err(()) => Err(Error::Syntax),
|
||||
Err(_) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
Ok(selectors) => {
|
||||
let mut descendants = self.traverse_preorder();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use app_units::Au;
|
||||
use base64;
|
||||
use bluetooth_traits::BluetoothRequest;
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||
|
@ -1003,7 +1003,8 @@ impl WindowMethods for Window {
|
|||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-window-matchmedia
|
||||
fn MatchMedia(&self, query: DOMString) -> Root<MediaQueryList> {
|
||||
let mut parser = Parser::new(&query);
|
||||
let mut input = ParserInput::new(&query);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let url = self.get_url();
|
||||
let quirks_mode = self.Document().quirks_mode();
|
||||
let context = CssParserContext::new_for_cssom(&url, self.css_error_reporter(), Some(CssRuleType::Media),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue