From 4574cd8ea61b56b1fb553b5e4fe765888d419945 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 10 Apr 2017 09:24:32 +0800 Subject: [PATCH 1/5] Pull rule_type into ParserContext Absorb `rule_type` into the `ParserContext` so that it's easier to pass down to deeper levels of the parser. MozReview-Commit-ID: DjBNytLxGKX --- components/script/dom/css.rs | 5 ++-- components/script/dom/cssmediarule.rs | 5 +++- components/script/dom/csssupportsrule.rs | 4 +-- components/style/keyframes.rs | 10 ++++--- components/style/parser.rs | 28 ++++++++++++++++--- .../style/properties/declaration_block.rs | 15 ++++------ .../style/properties/properties.mako.rs | 5 ++-- components/style/stylesheets.rs | 11 +++++--- components/style/supports.rs | 3 +- ports/geckolib/glue.rs | 8 +++--- tests/unit/style/parsing/animation.rs | 2 +- tests/unit/style/parsing/background.rs | 12 ++++---- tests/unit/style/parsing/basic_shape.rs | 2 +- tests/unit/style/parsing/border.rs | 20 ++++++------- tests/unit/style/parsing/box_.rs | 2 +- tests/unit/style/parsing/column.rs | 6 ++-- tests/unit/style/parsing/containment.rs | 2 +- tests/unit/style/parsing/effects.rs | 4 +-- tests/unit/style/parsing/font.rs | 6 ++-- tests/unit/style/parsing/image.rs | 2 +- tests/unit/style/parsing/inherited_box.rs | 2 +- tests/unit/style/parsing/inherited_text.rs | 8 +++--- tests/unit/style/parsing/length.rs | 2 +- tests/unit/style/parsing/mask.rs | 14 +++++----- tests/unit/style/parsing/mod.rs | 10 +++---- tests/unit/style/parsing/outline.rs | 4 +-- tests/unit/style/parsing/position.rs | 2 +- tests/unit/style/parsing/selectors.rs | 2 +- tests/unit/style/parsing/text.rs | 2 +- tests/unit/style/parsing/text_overflow.rs | 2 +- .../parsing/transition_timing_function.rs | 2 +- tests/unit/style/parsing/ui.rs | 4 +-- tests/unit/style/properties/background.rs | 4 +-- tests/unit/style/properties/serialization.rs | 8 +++--- tests/unit/style/viewport.rs | 4 +-- 35 files changed, 125 insertions(+), 97 deletions(-) diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index 92c15a10067..adc542bd3a4 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -10,6 +10,7 @@ use dom::bindings::str::DOMString; use dom::window::Window; use dom_struct::dom_struct; use style::parser::ParserContext; +use style::stylesheets::CssRuleType; use style::supports::{Declaration, parse_condition_or_declaration}; #[dom_struct] @@ -29,7 +30,7 @@ impl CSS { pub fn Supports(win: &Window, property: DOMString, value: DOMString) -> bool { let decl = Declaration { prop: property.into(), val: value.into() }; let url = win.Document().url(); - let context = ParserContext::new_for_cssom(&url, win.css_error_reporter()); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports)); decl.eval(&context) } @@ -39,7 +40,7 @@ impl CSS { let cond = parse_condition_or_declaration(&mut input); if let Ok(cond) = cond { let url = win.Document().url(); - let context = ParserContext::new_for_cssom(&url, win.css_error_reporter()); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports)); cond.eval(&context) } else { false diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index 2a07471679e..c6bb86bc287 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -17,7 +17,7 @@ use dom_struct::dom_struct; use std::sync::Arc; use style::media_queries::parse_media_query_list; use style::shared_lock::{Locked, ToCssWithGuard}; -use style::stylesheets::MediaRule; +use style::stylesheets::{CssRuleType, MediaRule}; use style_traits::ToCss; #[dom_struct] @@ -68,6 +68,9 @@ 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 win = self.global().as_window(); + let url = win.Document().url(); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media)); let new_medialist = parse_media_query_list(&mut input); let mut guard = self.cssconditionrule.shared_lock().write(); diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index 7ba3a24d038..bad93e621b5 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -16,7 +16,7 @@ use dom_struct::dom_struct; use std::sync::Arc; use style::parser::ParserContext; use style::shared_lock::{Locked, ToCssWithGuard}; -use style::stylesheets::SupportsRule; +use style::stylesheets::{CssRuleType, SupportsRule}; use style::supports::SupportsCondition; use style_traits::ToCss; @@ -61,7 +61,7 @@ impl CSSSupportsRule { let global = self.global(); let win = global.as_window(); let url = win.Document().url(); - let context = ParserContext::new_for_cssom(&url, win.css_error_reporter()); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports)); let enabled = cond.eval(&context); let mut guard = self.cssconditionrule.shared_lock().write(); let rule = self.supportsrule.write_with(&mut guard); diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index 7d01a40fdf3..c12856dd108 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -128,7 +128,8 @@ impl Keyframe { let error_reporter = MemoryHoleReporter; let context = ParserContext::new(parent_stylesheet.origin, &parent_stylesheet.url_data, - &error_reporter); + &error_reporter, + Some(CssRuleType::Keyframe)); let mut input = Parser::new(css); let mut rule_parser = KeyframeListParser { @@ -364,8 +365,9 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> { fn parse_block(&mut self, prelude: Self::Prelude, input: &mut Parser) -> Result { + let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Keyframe)); let parser = KeyframeDeclarationParser { - context: self.context, + context: &context, }; let mut iter = DeclarationListParser::new(input, parser); let mut block = PropertyDeclarationBlock::new(); @@ -376,7 +378,7 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> { let pos = range.start; let message = format!("Unsupported keyframe property declaration: '{}'", iter.input.slice(range)); - log_css_error(iter.input, pos, &*message, self.context); + log_css_error(iter.input, pos, &*message, &context); } } // `parse_important` is not called here, `!important` is not allowed in keyframe blocks. @@ -403,7 +405,7 @@ impl<'a, 'b> DeclarationParser for KeyframeDeclarationParser<'a, 'b> { fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result { let id = try!(PropertyId::parse(name.into())); - match ParsedDeclaration::parse(id, self.context, input, true, CssRuleType::Keyframe) { + match ParsedDeclaration::parse(id, self.context, input, true) { Ok(parsed) => { // In case there is still unparsed text in the declaration, we should roll back. if !input.is_exhausted() { diff --git a/components/style/parser.rs b/components/style/parser.rs index 024d71de936..2f8c3bbffa7 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -9,7 +9,7 @@ use cssparser::{Parser, SourcePosition, UnicodeRange}; use error_reporting::ParseErrorReporter; use style_traits::OneOrMoreCommaSeparated; -use stylesheets::{Origin, UrlExtraData}; +use stylesheets::{CssRuleType, Origin, UrlExtraData}; /// The data that the parser needs from outside in order to parse a stylesheet. pub struct ParserContext<'a> { @@ -20,26 +20,46 @@ pub struct ParserContext<'a> { pub url_data: &'a UrlExtraData, /// An error reporter to report syntax errors. pub error_reporter: &'a ParseErrorReporter, + /// The current rule type, if any. + pub rule_type: Option, } impl<'a> ParserContext<'a> { /// Create a parser context. pub fn new(stylesheet_origin: Origin, url_data: &'a UrlExtraData, - error_reporter: &'a ParseErrorReporter) + error_reporter: &'a ParseErrorReporter, + rule_type: Option) -> ParserContext<'a> { ParserContext { stylesheet_origin: stylesheet_origin, url_data: url_data, error_reporter: error_reporter, + rule_type: rule_type, } } /// Create a parser context for on-the-fly parsing in CSSOM pub fn new_for_cssom(url_data: &'a UrlExtraData, - error_reporter: &'a ParseErrorReporter) + error_reporter: &'a ParseErrorReporter, + rule_type: Option) -> ParserContext<'a> { - Self::new(Origin::Author, url_data, error_reporter) + Self::new(Origin::Author, url_data, error_reporter, rule_type) + } + + /// Create a parser context based on a previous context, but with a modified rule type. + pub fn new_with_rule_type(context: &'a ParserContext, + rule_type: Option) + -> ParserContext<'a> { + Self::new(context.stylesheet_origin, + context.url_data, + context.error_reporter, + rule_type) + } + + /// Get the rule type, which assumes that one is available. + pub fn rule_type(&self) -> CssRuleType { + self.rule_type.expect("Rule type expected, but none was found.") } } diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index c9c0e3d9ad3..bd23f73748f 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -612,8 +612,8 @@ pub fn parse_style_attribute(input: &str, url_data: &UrlExtraData, error_reporter: &ParseErrorReporter) -> PropertyDeclarationBlock { - let context = ParserContext::new(Origin::Author, url_data, error_reporter); - parse_property_declaration_list(&context, &mut Parser::new(input), CssRuleType::Style) + let context = ParserContext::new(Origin::Author, url_data, error_reporter, Some(CssRuleType::Style)); + parse_property_declaration_list(&context, &mut Parser::new(input)) } /// Parse a given property declaration. Can result in multiple @@ -626,9 +626,9 @@ pub fn parse_one_declaration(id: PropertyId, url_data: &UrlExtraData, error_reporter: &ParseErrorReporter) -> Result { - let context = ParserContext::new(Origin::Author, url_data, error_reporter); + let context = ParserContext::new(Origin::Author, url_data, error_reporter, Some(CssRuleType::Style)); Parser::new(input).parse_entirely(|parser| { - ParsedDeclaration::parse(id, &context, parser, false, CssRuleType::Style) + ParsedDeclaration::parse(id, &context, parser, false) .map_err(|_| ()) }) } @@ -636,7 +636,6 @@ pub fn parse_one_declaration(id: PropertyId, /// A struct to parse property declarations. struct PropertyDeclarationParser<'a, 'b: 'a> { context: &'a ParserContext<'b>, - rule_type: CssRuleType, } @@ -654,7 +653,7 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> { -> Result<(ParsedDeclaration, Importance), ()> { let id = try!(PropertyId::parse(name.into())); let parsed = input.parse_until_before(Delimiter::Bang, |input| { - ParsedDeclaration::parse(id, self.context, input, false, self.rule_type) + ParsedDeclaration::parse(id, self.context, input, false) .map_err(|_| ()) })?; let importance = match input.try(parse_important) { @@ -673,13 +672,11 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> { /// Parse a list of property declarations and return a property declaration /// block. pub fn parse_property_declaration_list(context: &ParserContext, - input: &mut Parser, - rule_type: CssRuleType) + input: &mut Parser) -> PropertyDeclarationBlock { let mut block = PropertyDeclarationBlock::new(); let parser = PropertyDeclarationParser { context: context, - rule_type: rule_type, }; let mut iter = DeclarationListParser::new(input, parser); while let Some(declaration) = iter.next() { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 28bfc925cb7..db9eaa9651f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -330,7 +330,7 @@ impl PropertyDeclarationIdSet { // // FIXME(pcwalton): Cloning the error reporter is slow! But so are custom // properties, so whatever... - let context = ParserContext::new(Origin::Author, url_data, error_reporter); + let context = ParserContext::new(Origin::Author, url_data, error_reporter, None); Parser::new(&css).parse_entirely(|input| { match from_shorthand { None => { @@ -977,8 +977,9 @@ impl ParsedDeclaration { /// to Importance::Normal. Parsing Importance values is the job of PropertyDeclarationParser, /// we only set them here so that we don't have to reallocate pub fn parse(id: PropertyId, context: &ParserContext, input: &mut Parser, - in_keyframe_block: bool, rule_type: CssRuleType) + in_keyframe_block: bool) -> Result { + let rule_type = context.rule_type(); debug_assert!(rule_type == CssRuleType::Keyframe || rule_type == CssRuleType::Page || rule_type == CssRuleType::Style, diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index a85a8a6a307..694806c8ef1 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -387,7 +387,8 @@ impl CssRule { let mut namespaces = parent_stylesheet.namespaces.write(); let context = ParserContext::new(parent_stylesheet.origin, &parent_stylesheet.url_data, - &error_reporter); + &error_reporter, + None); let mut input = Parser::new(css); // nested rules are in the body state @@ -658,7 +659,7 @@ impl Stylesheet { namespaces: namespaces, shared_lock: shared_lock, loader: stylesheet_loader, - context: ParserContext::new(origin, url_data, error_reporter), + context: ParserContext::new(origin, url_data, error_reporter, None), state: Cell::new(State::Start), }; @@ -1115,7 +1116,8 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { })))) } AtRulePrelude::Page => { - let declarations = parse_property_declaration_list(self.context, input, CssRuleType::Page); + let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Page)); + let declarations = parse_property_declaration_list(&context, input); Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule( Arc::new(self.shared_lock.wrap(declarations)) ))))) @@ -1138,7 +1140,8 @@ impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> { fn parse_block(&mut self, prelude: SelectorList, input: &mut Parser) -> Result { - let declarations = parse_property_declaration_list(self.context, input, CssRuleType::Style); + let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Style)); + let declarations = parse_property_declaration_list(&context, input); Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule { selectors: prelude, block: Arc::new(self.shared_lock.wrap(declarations)) diff --git a/components/style/supports.rs b/components/style/supports.rs index aae9d989916..37926c2fc9e 100644 --- a/components/style/supports.rs +++ b/components/style/supports.rs @@ -212,7 +212,8 @@ impl Declaration { return false }; let mut input = Parser::new(&self.val); - let res = ParsedDeclaration::parse(id, cx, &mut input, /* in_keyframe */ false, CssRuleType::Style); + let context = ParserContext::new_with_rule_type(cx, Some(CssRuleType::Style)); + let res = ParsedDeclaration::parse(id, &context, &mut input, /* in_keyframe */ false); let _ = input.try(parse_important); res.is_ok() && input.is_exhausted() } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9999dbff74d..438bd79369d 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -950,9 +950,9 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; let reporter = StdoutErrorReporter; - let context = ParserContext::new(Origin::Author, url_data, &reporter); + let context = ParserContext::new(Origin::Author, url_data, &reporter, Some(CssRuleType::Style)); - match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false, CssRuleType::Style) { + match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) { Ok(parsed) => { let global_style_data = &*GLOBAL_STYLE_DATA; let mut block = PropertyDeclarationBlock::new(); @@ -972,7 +972,7 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString, let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; let reporter = StdoutErrorReporter; - let context = ParserContext::new(Origin::Author, url_data, &reporter); + let context = ParserContext::new(Origin::Author, url_data, &reporter, Some(CssRuleType::Style)); let easing = unsafe { (*easing).to_string() }; match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) { Ok(parsed_easing) => { @@ -1511,7 +1511,7 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool { if let Ok(cond) = cond { let url_data = unsafe { dummy_url_data() }; let reporter = StdoutErrorReporter; - let context = ParserContext::new_for_cssom(url_data, &reporter); + let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Style)); cond.eval(&context) } else { false diff --git a/tests/unit/style/parsing/animation.rs b/tests/unit/style/parsing/animation.rs index bf9f3b3e2ee..0cb0bc62a03 100644 --- a/tests/unit/style/parsing/animation.rs +++ b/tests/unit/style/parsing/animation.rs @@ -9,7 +9,7 @@ use servo_atoms::Atom; use style::parser::{Parse, ParserContext}; use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount; use style::properties::longhands::animation_name; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/background.rs b/tests/unit/style/parsing/background.rs index 084c2e10201..d2fea3944c7 100644 --- a/tests/unit/style/parsing/background.rs +++ b/tests/unit/style/parsing/background.rs @@ -10,13 +10,13 @@ use style::properties::longhands::{background_attachment, background_clip, backg use style::properties::longhands::{background_origin, background_position_x, background_position_y, background_repeat}; use style::properties::longhands::background_size; use style::properties::shorthands::background; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; #[test] fn background_shorthand_should_parse_all_available_properties_when_specified() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("url(\"http://servo/test.png\") top center / 200px 200px repeat-x fixed padding-box \ content-box red"); let result = background::parse_value(&context, &mut parser).unwrap(); @@ -36,7 +36,7 @@ fn background_shorthand_should_parse_all_available_properties_when_specified() { fn background_shorthand_should_parse_when_some_fields_set() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("14px 40px repeat-y"); let result = background::parse_value(&context, &mut parser).unwrap(); @@ -67,7 +67,7 @@ fn background_shorthand_should_parse_when_some_fields_set() { fn background_shorthand_should_parse_comma_separated_declarations() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("url(\"http://servo/test.png\") top left no-repeat, url(\"http://servo/test.png\") \ center / 100% 100% no-repeat, white"); let result = background::parse_value(&context, &mut parser).unwrap(); @@ -89,7 +89,7 @@ fn background_shorthand_should_parse_comma_separated_declarations() { fn background_shorthand_should_parse_position_and_size_correctly() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("7px 4px"); let result = background::parse_value(&context, &mut parser).unwrap(); @@ -114,7 +114,7 @@ fn background_shorthand_should_parse_position_and_size_correctly() { fn background_shorthand_should_parse_origin_and_clip_correctly() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("padding-box content-box"); let result = background::parse_value(&context, &mut parser).unwrap(); diff --git a/tests/unit/style/parsing/basic_shape.rs b/tests/unit/style/parsing/basic_shape.rs index dcb269c9397..0923499aed9 100644 --- a/tests/unit/style/parsing/basic_shape.rs +++ b/tests/unit/style/parsing/basic_shape.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::{Parse, ParserContext}; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style::values::specified::basic_shape::*; use style_traits::ToCss; diff --git a/tests/unit/style/parsing/border.rs b/tests/unit/style/parsing/border.rs index 94a4d8f6ff3..e89d33b2b0f 100644 --- a/tests/unit/style/parsing/border.rs +++ b/tests/unit/style/parsing/border.rs @@ -9,14 +9,14 @@ use style::parser::{ParserContext, Parse}; use style::properties::longhands::{border_image_outset, border_image_repeat, border_image_slice}; use style::properties::longhands::{border_image_source, border_image_width}; use style::properties::shorthands::border_image; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] fn border_image_shorthand_should_parse_when_all_properties_specified() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px \ round stretch"); let result = border_image::parse_value(&context, &mut parser).unwrap(); @@ -33,7 +33,7 @@ fn border_image_shorthand_should_parse_when_all_properties_specified() { fn border_image_shorthand_should_parse_without_width() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch"); let result = border_image::parse_value(&context, &mut parser).unwrap(); @@ -49,7 +49,7 @@ fn border_image_shorthand_should_parse_without_width() { fn border_image_shorthand_should_parse_without_outset() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round"); let result = border_image::parse_value(&context, &mut parser).unwrap(); @@ -65,7 +65,7 @@ fn border_image_shorthand_should_parse_without_outset() { fn border_image_shorthand_should_parse_without_width_or_outset() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill round"); let result = border_image::parse_value(&context, &mut parser).unwrap(); @@ -81,7 +81,7 @@ fn border_image_shorthand_should_parse_without_width_or_outset() { fn border_image_shorthand_should_parse_with_just_source() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("linear-gradient(red, blue)"); let result = border_image::parse_value(&context, &mut parser).unwrap(); @@ -97,7 +97,7 @@ fn border_image_shorthand_should_parse_with_just_source() { fn border_image_outset_should_error_on_negative_length() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("-1em"); let result = border_image_outset::parse(&context, &mut parser); assert_eq!(result, Err(())); @@ -107,7 +107,7 @@ fn border_image_outset_should_error_on_negative_length() { fn border_image_outset_should_error_on_negative_number() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("-15"); let result = border_image_outset::parse(&context, &mut parser); assert_eq!(result, Err(())); @@ -117,7 +117,7 @@ fn border_image_outset_should_error_on_negative_number() { fn border_image_outset_should_return_number_on_plain_zero() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("0"); let result = border_image_outset::parse(&context, &mut parser); assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0")); @@ -127,7 +127,7 @@ fn border_image_outset_should_return_number_on_plain_zero() { fn border_image_outset_should_return_length_on_length_zero() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("0em"); let result = border_image_outset::parse(&context, &mut parser); assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0em")); diff --git a/tests/unit/style/parsing/box_.rs b/tests/unit/style/parsing/box_.rs index e6b73a3b246..0f7925391a7 100644 --- a/tests/unit/style/parsing/box_.rs +++ b/tests/unit/style/parsing/box_.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/column.rs b/tests/unit/style/parsing/column.rs index f8aff1e04b7..cc8c8532db7 100644 --- a/tests/unit/style/parsing/column.rs +++ b/tests/unit/style/parsing/column.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use servo_url::ServoUrl; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] @@ -20,7 +20,7 @@ fn test_column_width() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut negative = Parser::new("-6px"); assert!(column_width::parse(&context, &mut negative).is_err()); @@ -37,7 +37,7 @@ fn test_column_gap() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut negative = Parser::new("-6px"); assert!(column_gap::parse(&context, &mut negative).is_err()); diff --git a/tests/unit/style/parsing/containment.rs b/tests/unit/style/parsing/containment.rs index de697cb8441..d5a7bea9723 100644 --- a/tests/unit/style/parsing/containment.rs +++ b/tests/unit/style/parsing/containment.rs @@ -5,7 +5,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; #[test] fn contain_longhand_should_parse_correctly() { diff --git a/tests/unit/style/parsing/effects.rs b/tests/unit/style/parsing/effects.rs index 2b8ef18c2e5..aa53c3c209e 100644 --- a/tests/unit/style/parsing/effects.rs +++ b/tests/unit/style/parsing/effects.rs @@ -8,7 +8,7 @@ use parsing::parse; use servo_url::ServoUrl; use style::parser::ParserContext; use style::properties::longhands::{self, perspective_origin, transform_origin}; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] @@ -39,7 +39,7 @@ fn test_clip() { fn test_longhands_parse_origin() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("1px some-rubbish"); let parsed = longhands::parse_origin(&context, &mut parser); diff --git a/tests/unit/style/parsing/font.rs b/tests/unit/style/parsing/font.rs index 6d44e1f532f..19aa0f12172 100644 --- a/tests/unit/style/parsing/font.rs +++ b/tests/unit/style/parsing/font.rs @@ -9,7 +9,7 @@ use style::parser::ParserContext; use style::properties::longhands::{font_feature_settings, font_weight}; use style::properties::longhands::font_feature_settings::computed_value; use style::properties::longhands::font_feature_settings::computed_value::FeatureTagValue; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] @@ -54,7 +54,7 @@ fn font_feature_settings_should_parse_properly() { fn font_feature_settings_should_throw_on_bad_input() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut empty = Parser::new(""); assert!(font_feature_settings::parse(&context, &mut empty).is_err()); @@ -105,7 +105,7 @@ fn font_weight_keyword_should_preserve_keyword() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("normal"); let result = font_weight::parse(&context, &mut parser); assert_eq!(result.unwrap(), SpecifiedValue::Normal); diff --git a/tests/unit/style/parsing/image.rs b/tests/unit/style/parsing/image.rs index 68ccec16a5f..4859abf41df 100644 --- a/tests/unit/style/parsing/image.rs +++ b/tests/unit/style/parsing/image.rs @@ -10,7 +10,7 @@ use style::font_metrics::ServoMetricsProvider; use style::media_queries::{Device, MediaType}; use style::parser::ParserContext; use style::properties::ComputedValues; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style::values::computed; use style::values::computed::{Angle, Context, ToComputedValue}; use style::values::specified; diff --git a/tests/unit/style/parsing/inherited_box.rs b/tests/unit/style/parsing/inherited_box.rs index 749641c79cf..8eb0cd8d48d 100644 --- a/tests/unit/style/parsing/inherited_box.rs +++ b/tests/unit/style/parsing/inherited_box.rs @@ -5,7 +5,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; #[test] fn image_orientation_longhand_should_parse_properly() { diff --git a/tests/unit/style/parsing/inherited_text.rs b/tests/unit/style/parsing/inherited_text.rs index b0d474b6024..ce25252b25d 100644 --- a/tests/unit/style/parsing/inherited_text.rs +++ b/tests/unit/style/parsing/inherited_text.rs @@ -5,7 +5,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; #[test] fn negative_letter_spacing_should_parse_properly() { @@ -112,7 +112,7 @@ fn webkit_text_stroke_shorthand_should_parse_properly() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("thin red"); let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap(); @@ -134,7 +134,7 @@ fn line_height_should_return_number_on_plain_zero() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("0"); let result = line_height::parse(&context, &mut parser); assert_eq!(result.unwrap(), parse_longhand!(line_height, "0")); @@ -148,7 +148,7 @@ fn line_height_should_return_length_on_length_zero() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("0px"); let result = line_height::parse(&context, &mut parser); assert_eq!(result.unwrap(), parse_longhand!(line_height, "0px")); diff --git a/tests/unit/style/parsing/length.rs b/tests/unit/style/parsing/length.rs index 39407441aaf..bc94ab5ba91 100644 --- a/tests/unit/style/parsing/length.rs +++ b/tests/unit/style/parsing/length.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::{Parse, ParserContext}; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style::values::specified::length::Length; use style_traits::ToCss; diff --git a/tests/unit/style/parsing/mask.rs b/tests/unit/style/parsing/mask.rs index 15f498c4c73..b3f3912d7c9 100644 --- a/tests/unit/style/parsing/mask.rs +++ b/tests/unit/style/parsing/mask.rs @@ -9,13 +9,13 @@ use style::parser::ParserContext; use style::properties::longhands::{mask_clip, mask_composite, mask_image, mask_mode}; use style::properties::longhands::{mask_origin, mask_position_x, mask_position_y, mask_repeat, mask_size}; use style::properties::shorthands::mask; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; #[test] fn mask_shorthand_should_parse_all_available_properties_when_specified() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px \ repeat-x padding-box border-box subtract"); let result = mask::parse_value(&context, &mut parser).unwrap(); @@ -35,7 +35,7 @@ fn mask_shorthand_should_parse_all_available_properties_when_specified() { fn mask_shorthand_should_parse_when_some_fields_set() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("14px 40px repeat-y"); let result = mask::parse_value(&context, &mut parser).unwrap(); @@ -65,7 +65,7 @@ fn mask_shorthand_should_parse_when_some_fields_set() { fn mask_shorthand_should_parse_position_and_size_correctly() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("7px 4px"); let result = mask::parse_value(&context, &mut parser).unwrap(); @@ -90,7 +90,7 @@ fn mask_shorthand_should_parse_position_and_size_correctly() { fn mask_shorthand_should_parse_origin_and_clip_correctly() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("padding-box content-box"); let result = mask::parse_value(&context, &mut parser).unwrap(); @@ -114,7 +114,7 @@ fn mask_shorthand_should_parse_origin_and_clip_correctly() { fn mask_shorthand_should_parse_mode_everywhere() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new("luminance 7px 4px repeat-x padding-box"); assert!(mask::parse_value(&context, &mut parser).is_ok()); @@ -155,7 +155,7 @@ fn mask_repeat_should_parse_longhand_correctly() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); // repeat-x is not available in longhand form. let mut parser = Parser::new("repeat-x no-repeat"); diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index cb5181fc6cc..b6da9a138d6 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -7,12 +7,12 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; fn parse Result>(f: F, s: &str) -> Result { let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new(s); f(&context, &mut parser) } @@ -26,7 +26,7 @@ macro_rules! assert_roundtrip_with_context { ($fun:expr,$input:expr, $output:expr) => { let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new($input); let parsed = $fun(&context, &mut parser) .expect(&format!("Failed to parse {}", $input)); @@ -64,7 +64,7 @@ macro_rules! assert_parser_exhausted { ($name:ident, $string:expr, $should_exhausted:expr) => {{ let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new($string); let parsed = $name::parse(&context, &mut parser); assert_eq!(parsed.is_ok(), true); @@ -76,7 +76,7 @@ macro_rules! parse_longhand { ($name:ident, $s:expr) => {{ let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); $name::parse(&context, &mut Parser::new($s)).unwrap() }}; } diff --git a/tests/unit/style/parsing/outline.rs b/tests/unit/style/parsing/outline.rs index 3603ccda1db..787d4172055 100644 --- a/tests/unit/style/parsing/outline.rs +++ b/tests/unit/style/parsing/outline.rs @@ -5,7 +5,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] @@ -29,7 +29,7 @@ fn test_outline_style() { let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new(r#"hidden"#); let parsed = outline_style::parse(&context, &mut parser); assert!(parsed.is_err()); diff --git a/tests/unit/style/parsing/position.rs b/tests/unit/style/parsing/position.rs index 8c56b323e67..04da426ded8 100644 --- a/tests/unit/style/parsing/position.rs +++ b/tests/unit/style/parsing/position.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::{Parse, ParserContext}; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style::values::specified::position::*; use style_traits::ToCss; diff --git a/tests/unit/style/parsing/selectors.rs b/tests/unit/style/parsing/selectors.rs index 3654360b07c..24ccc11d546 100644 --- a/tests/unit/style/parsing/selectors.rs +++ b/tests/unit/style/parsing/selectors.rs @@ -7,7 +7,7 @@ use media_queries::CSSErrorReporterTest; use selectors::parser::SelectorList; use style::parser::ParserContext; use style::selector_parser::{SelectorImpl, SelectorParser}; -use style::stylesheets::{Origin, Namespaces}; +use style::stylesheets::{CssRuleType, Origin, Namespaces}; fn parse(_context: &ParserContext, input: &mut Parser) -> Result, ()> { let mut ns = Namespaces::default(); diff --git a/tests/unit/style/parsing/text.rs b/tests/unit/style/parsing/text.rs index d1646c0b887..298d8255e7f 100644 --- a/tests/unit/style/parsing/text.rs +++ b/tests/unit/style/parsing/text.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/text_overflow.rs b/tests/unit/style/parsing/text_overflow.rs index fd2b6b91cab..0e57e733477 100644 --- a/tests/unit/style/parsing/text_overflow.rs +++ b/tests/unit/style/parsing/text_overflow.rs @@ -5,7 +5,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/transition_timing_function.rs b/tests/unit/style/parsing/transition_timing_function.rs index fe24b2453c3..5b27ab75188 100644 --- a/tests/unit/style/parsing/transition_timing_function.rs +++ b/tests/unit/style/parsing/transition_timing_function.rs @@ -7,7 +7,7 @@ use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::ParserContext; use style::properties::longhands::transition_timing_function; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/ui.rs b/tests/unit/style/parsing/ui.rs index 10342947ea5..07a1b0a5d4b 100644 --- a/tests/unit/style/parsing/ui.rs +++ b/tests/unit/style/parsing/ui.rs @@ -6,7 +6,7 @@ use cssparser::{Color, Parser, RGBA}; use media_queries::CSSErrorReporterTest; use servo_url::ServoUrl; use style::parser::ParserContext; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; use style::values::{Auto, Either}; use style::values::specified::CSSColor; use style_traits::ToCss; @@ -28,7 +28,7 @@ fn test_moz_user_select() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut negative = Parser::new("potato"); assert!(_moz_user_select::parse(&context, &mut negative).is_err()); diff --git a/tests/unit/style/properties/background.rs b/tests/unit/style/properties/background.rs index 4640845ae85..c83286c10c8 100644 --- a/tests/unit/style/properties/background.rs +++ b/tests/unit/style/properties/background.rs @@ -6,13 +6,13 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use style::parser::ParserContext; use style::properties::longhands::background_size; -use style::stylesheets::Origin; +use style::stylesheets::{CssRuleType, Origin}; #[test] fn background_size_should_reject_negative_values() { let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let parse_result = background_size::parse(&context, &mut Parser::new("-40% -40%")); diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 1dc93fc7656..04dffa1aa5a 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -21,9 +21,9 @@ use stylesheets::block_from; fn parse_declaration_block(css_properties: &str) -> PropertyDeclarationBlock { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new(css_properties); - parse_property_declaration_list(&context, &mut parser, CssRuleType::Style) + parse_property_declaration_list(&context, &mut parser) } #[test] @@ -976,7 +976,7 @@ mod shorthand_serialization { let mut s = String::new(); let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let parsed = transform::parse(&context, &mut Parser::new("none")).unwrap(); let try_serialize = parsed.to_css(&mut s); @@ -1040,7 +1040,7 @@ mod shorthand_serialization { let mut s = String::new(); let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let parsed = quotes::parse(&context, &mut Parser::new("none")).unwrap(); let try_serialize = parsed.to_css(&mut s); diff --git a/tests/unit/style/viewport.rs b/tests/unit/style/viewport.rs index dc15436af5e..252aa266478 100644 --- a/tests/unit/style/viewport.rs +++ b/tests/unit/style/viewport.rs @@ -10,7 +10,7 @@ use servo_url::ServoUrl; use style::media_queries::{Device, MediaType}; use style::parser::{Parse, ParserContext}; use style::shared_lock::SharedRwLock; -use style::stylesheets::{Stylesheet, Origin}; +use style::stylesheets::{CssRuleType, Stylesheet, Origin}; use style::values::specified::LengthOrPercentageOrAuto::{self, Auto}; use style::values::specified::NoCalcLength::{self, ViewportPercentage}; use style::values::specified::ViewportPercentageLength::Vw; @@ -290,7 +290,7 @@ fn multiple_stylesheets_cascading() { fn constrain_viewport() { let url = ServoUrl::parse("http://localhost").unwrap(); let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter); + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Viewport)); macro_rules! from_css { ($css:expr) => { From 997015a4f7a22aa134e8b9f76ea8e4fe4c9685bf Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 10 Apr 2017 13:31:22 +0800 Subject: [PATCH 2/5] Set rule_type in context when descending into any rule Before, we only passed `rule_type` in specific cases where it was needed. Now that it's in `ParserContext`, it seems good to set it at each rule boundary, in case we start to depend on the value in new places. MozReview-Commit-ID: 7ZGD7NGZLR4 --- components/style/stylesheets.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 694806c8ef1..f9bfe30fd38 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -1012,8 +1012,15 @@ struct NestedRuleParser<'a, 'b: 'a> { } impl<'a, 'b> NestedRuleParser<'a, 'b> { - fn parse_nested_rules(&self, input: &mut Parser) -> Arc> { - let mut iter = RuleListParser::new_for_nested_rule(input, self.clone()); + fn parse_nested_rules(&self, input: &mut Parser, rule_type: CssRuleType) -> Arc> { + let context = ParserContext::new_with_rule_type(self.context, Some(rule_type)); + let nested_parser = NestedRuleParser { + stylesheet_origin: self.stylesheet_origin, + shared_lock: self.shared_lock, + context: &context, + namespaces: self.namespaces, + }; + let mut iter = RuleListParser::new_for_nested_rule(input, nested_parser); let mut rules = Vec::new(); while let Some(result) = iter.next() { match result { @@ -1088,31 +1095,34 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result { match prelude { AtRulePrelude::FontFace => { + let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::FontFace)); Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap( - parse_font_face_block(self.context, input).into())))) + parse_font_face_block(&context, input).into())))) } AtRulePrelude::Media(media_queries) => { Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule { media_queries: media_queries, - rules: self.parse_nested_rules(input), + rules: self.parse_nested_rules(input, CssRuleType::Media), })))) } AtRulePrelude::Supports(cond) => { let enabled = cond.eval(self.context); Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule { condition: cond, - rules: self.parse_nested_rules(input), + rules: self.parse_nested_rules(input, CssRuleType::Supports), enabled: enabled, })))) } AtRulePrelude::Viewport => { + let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Viewport)); Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap( - try!(ViewportRule::parse(self.context, input)))))) + try!(ViewportRule::parse(&context, input)))))) } AtRulePrelude::Keyframes(name) => { + let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Keyframes)); Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule { name: name, - keyframes: parse_keyframe_list(&self.context, input, self.shared_lock), + keyframes: parse_keyframe_list(&context, input, self.shared_lock), })))) } AtRulePrelude::Page => { From 1ae1d370f23d5b74902a1f7dc87421e516b5ac2e Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 10 Apr 2017 15:36:49 +0800 Subject: [PATCH 3/5] Check context to test keyframe rule_type Now that the `context` contains the `rule_type`, we can remove the `in_keyframe` arg and check the `rule_type` to achieve the same thing. MozReview-Commit-ID: oXrFBPuKMz --- components/style/keyframes.rs | 2 +- components/style/properties/declaration_block.rs | 4 ++-- components/style/properties/properties.mako.rs | 7 +++---- components/style/supports.rs | 2 +- ports/geckolib/glue.rs | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index c12856dd108..cc8a9229b85 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -405,7 +405,7 @@ impl<'a, 'b> DeclarationParser for KeyframeDeclarationParser<'a, 'b> { fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result { let id = try!(PropertyId::parse(name.into())); - match ParsedDeclaration::parse(id, self.context, input, true) { + match ParsedDeclaration::parse(id, self.context, input) { Ok(parsed) => { // In case there is still unparsed text in the declaration, we should roll back. if !input.is_exhausted() { diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index bd23f73748f..fd0704b8971 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -628,7 +628,7 @@ pub fn parse_one_declaration(id: PropertyId, -> Result { let context = ParserContext::new(Origin::Author, url_data, error_reporter, Some(CssRuleType::Style)); Parser::new(input).parse_entirely(|parser| { - ParsedDeclaration::parse(id, &context, parser, false) + ParsedDeclaration::parse(id, &context, parser) .map_err(|_| ()) }) } @@ -653,7 +653,7 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> { -> Result<(ParsedDeclaration, Importance), ()> { let id = try!(PropertyId::parse(name.into())); let parsed = input.parse_until_before(Delimiter::Bang, |input| { - ParsedDeclaration::parse(id, self.context, input, false) + ParsedDeclaration::parse(id, self.context, input) .map_err(|_| ()) })?; let importance = match input.try(parse_important) { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index db9eaa9651f..d4957461fc2 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -976,8 +976,7 @@ impl ParsedDeclaration { /// This will not actually parse Importance values, and will always set things /// to Importance::Normal. Parsing Importance values is the job of PropertyDeclarationParser, /// we only set them here so that we don't have to reallocate - pub fn parse(id: PropertyId, context: &ParserContext, input: &mut Parser, - in_keyframe_block: bool) + pub fn parse(id: PropertyId, context: &ParserContext, input: &mut Parser) -> Result { let rule_type = context.rule_type(); debug_assert!(rule_type == CssRuleType::Keyframe || @@ -1000,7 +999,7 @@ impl ParsedDeclaration { LonghandId::${property.camel_case} => { % if not property.derived_from: % if not property.allowed_in_keyframe_block: - if in_keyframe_block { + if rule_type == CssRuleType::Keyframe { return Err(PropertyDeclarationParseError::AnimationPropertyInKeyframeBlock) } % endif @@ -1033,7 +1032,7 @@ impl ParsedDeclaration { % for shorthand in data.shorthands: ShorthandId::${shorthand.camel_case} => { % if not shorthand.allowed_in_keyframe_block: - if in_keyframe_block { + if rule_type == CssRuleType::Keyframe { return Err(PropertyDeclarationParseError::AnimationPropertyInKeyframeBlock) } % endif diff --git a/components/style/supports.rs b/components/style/supports.rs index 37926c2fc9e..932b8bc2880 100644 --- a/components/style/supports.rs +++ b/components/style/supports.rs @@ -213,7 +213,7 @@ impl Declaration { }; let mut input = Parser::new(&self.val); let context = ParserContext::new_with_rule_type(cx, Some(CssRuleType::Style)); - let res = ParsedDeclaration::parse(id, &context, &mut input, /* in_keyframe */ false); + let res = ParsedDeclaration::parse(id, &context, &mut input); let _ = input.try(parse_important); res.is_ok() && input.is_exhausted() } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 438bd79369d..f4867e2b292 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -952,7 +952,7 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const let reporter = StdoutErrorReporter; let context = ParserContext::new(Origin::Author, url_data, &reporter, Some(CssRuleType::Style)); - match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) { + match ParsedDeclaration::parse(id, &context, &mut Parser::new(value)) { Ok(parsed) => { let global_style_data = &*GLOBAL_STYLE_DATA; let mut block = PropertyDeclarationBlock::new(); From 1a31b87c22adbd2b7a7350500e089fad3fa49453 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 11 Apr 2017 16:00:37 +0800 Subject: [PATCH 4/5] Pass ParserContext down to lengths To make it possible to check the rule type when parsing lengths, we need to pass the `ParserContext` down through many layers to the place where length units are parsed. This change leaves it unused, so it's only to prepare for the next change. MozReview-Commit-ID: 70YwtcCxnWw --- components/script/dom/cssmediarule.rs | 8 +- components/script/dom/htmllinkelement.rs | 12 +- components/script/dom/htmlstyleelement.rs | 12 +- components/script/dom/medialist.rs | 22 ++- components/script/dom/window.rs | 6 +- components/style/gecko/media_queries.rs | 5 +- components/style/media_queries.rs | 21 ++- .../properties/longhand/background.mako.rs | 6 +- .../style/properties/longhand/border.mako.rs | 6 +- .../style/properties/longhand/box.mako.rs | 44 ++--- .../properties/longhand/counters.mako.rs | 14 +- .../style/properties/longhand/effects.mako.rs | 2 +- .../style/properties/longhand/font.mako.rs | 8 +- .../properties/longhand/inherited_svg.mako.rs | 3 - .../longhand/inherited_table.mako.rs | 6 +- .../longhand/inherited_text.mako.rs | 6 +- .../style/properties/longhand/outline.mako.rs | 4 +- .../style/properties/longhand/padding.mako.rs | 1 - .../properties/longhand/position.mako.rs | 6 - .../style/properties/longhand/text.mako.rs | 2 +- .../style/properties/longhand/xul.mako.rs | 2 - .../properties/shorthand/position.mako.rs | 8 +- components/style/servo/media_queries.rs | 9 +- components/style/stylesheets.rs | 4 +- .../style/values/specified/basic_shape.rs | 20 +- components/style/values/specified/grid.rs | 6 +- components/style/values/specified/length.rs | 177 ++++++++++-------- components/style/values/specified/mod.rs | 86 ++++----- components/style/viewport.rs | 24 +-- ports/geckolib/glue.rs | 17 +- tests/unit/style/value.rs | 8 +- 31 files changed, 304 insertions(+), 251 deletions(-) diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index c6bb86bc287..a151ee81cec 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -16,6 +16,7 @@ use dom::window::Window; use dom_struct::dom_struct; use std::sync::Arc; use style::media_queries::parse_media_query_list; +use style::parser::ParserContext; use style::shared_lock::{Locked, ToCssWithGuard}; use style::stylesheets::{CssRuleType, MediaRule}; use style_traits::ToCss; @@ -68,10 +69,11 @@ 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 win = self.global().as_window(); - let url = win.Document().url(); + let global = self.global(); + let win = global.as_window(); + let url = win.get_url(); let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media)); - let new_medialist = parse_media_query_list(&mut input); + let new_medialist = parse_media_query_list(&context, &mut input); let mut guard = self.cssconditionrule.shared_lock().write(); // Clone an Arc because we canโ€™t borrow `guard` twice at the same time. diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index d29a94a11f0..d22a24d2e17 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -32,8 +32,9 @@ use std::default::Default; use std::sync::Arc; use style::attr::AttrValue; use style::media_queries::parse_media_query_list; +use style::parser::ParserContext as CssParserContext; use style::str::HTML_SPACE_CHARACTERS; -use style::stylesheets::Stylesheet; +use style::stylesheets::{CssRuleType, Stylesheet}; use stylesheet_loader::{StylesheetLoader, StylesheetContextSource, StylesheetOwner}; unsafe_no_jsmanaged_fields!(Stylesheet); @@ -255,7 +256,7 @@ impl HTMLLinkElement { } // Step 2. - let url = match document.base_url().join(href) { + let link_url = match document.base_url().join(href) { Ok(url) => url, Err(e) => { debug!("Parsing url {} failed: {}", href, e); @@ -276,7 +277,10 @@ impl HTMLLinkElement { }; let mut css_parser = CssParser::new(&mq_str); - let media = parse_media_query_list(&mut css_parser); + let win = document.window(); + let doc_url = document.url(); + let context = CssParserContext::new_for_cssom(&doc_url, win.css_error_reporter(), Some(CssRuleType::Media)); + let media = parse_media_query_list(&context, &mut css_parser); let im_attribute = element.get_attribute(&ns!(), &local_name!("integrity")); let integrity_val = im_attribute.r().map(|a| a.value()); @@ -292,7 +296,7 @@ impl HTMLLinkElement { let loader = StylesheetLoader::for_element(self.upcast()); loader.load(StylesheetContextSource::LinkElement { media: Some(media), - }, url, cors_setting, integrity_metadata.to_owned()); + }, link_url, cors_setting, integrity_metadata.to_owned()); } fn handle_favicon_url(&self, rel: &str, href: &str, sizes: &Option) { diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index c3ef5767f2b..fa0cdc92eab 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -25,7 +25,8 @@ use script_layout_interface::message::Msg; use std::cell::Cell; use std::sync::Arc; use style::media_queries::parse_media_query_list; -use style::stylesheets::{Stylesheet, Origin}; +use style::parser::ParserContext as CssParserContext; +use style::stylesheets::{CssRuleType, Stylesheet, Origin}; use stylesheet_loader::{StylesheetLoader, StylesheetOwner}; #[dom_struct] @@ -73,7 +74,6 @@ impl HTMLStyleElement { assert!(node.is_in_doc()); let win = window_from_node(node); - let url = win.get_url(); let mq_attribute = element.get_attribute(&ns!(), &local_name!("media")); let mq_str = match mq_attribute { @@ -82,10 +82,14 @@ impl HTMLStyleElement { }; let data = node.GetTextContent().expect("Element.textContent must be a string"); - let mq = parse_media_query_list(&mut CssParser::new(&mq_str)); + let url = win.get_url(); + let context = CssParserContext::new_for_cssom(&url, + win.css_error_reporter(), + Some(CssRuleType::Media)); + let mq = parse_media_query_list(&context, &mut CssParser::new(&mq_str)); let shared_lock = node.owner_doc().style_shared_lock().clone(); let loader = StylesheetLoader::for_element(self.upcast()); - let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq, + let sheet = Stylesheet::from_str(&data, win.get_url(), Origin::Author, mq, shared_lock, Some(&loader), win.css_error_reporter()); diff --git a/components/script/dom/medialist.rs b/components/script/dom/medialist.rs index b403200983e..54604fbd443 100644 --- a/components/script/dom/medialist.rs +++ b/components/script/dom/medialist.rs @@ -7,7 +7,7 @@ use cssparser::Parser; use dom::bindings::codegen::Bindings::MediaListBinding; use dom::bindings::codegen::Bindings::MediaListBinding::MediaListMethods; use dom::bindings::js::{JS, Root}; -use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; use dom::cssstylesheet::CSSStyleSheet; use dom::window::Window; @@ -15,7 +15,9 @@ use dom_struct::dom_struct; use std::sync::Arc; use style::media_queries::{MediaQuery, parse_media_query_list}; use style::media_queries::MediaList as StyleMediaList; +use style::parser::ParserContext; use style::shared_lock::{SharedRwLock, Locked}; +use style::stylesheets::CssRuleType; use style_traits::ToCss; #[dom_struct] @@ -70,7 +72,11 @@ impl MediaListMethods for MediaList { } // Step 3 let mut parser = Parser::new(&value); - *media_queries = parse_media_query_list(&mut parser); + let global = self.global(); + let win = global.as_window(); + let url = win.get_url(); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media)); + *media_queries = parse_media_query_list(&context, &mut parser); } // https://drafts.csswg.org/cssom/#dom-medialist-length @@ -99,7 +105,11 @@ impl MediaListMethods for MediaList { fn AppendMedium(&self, medium: DOMString) { // Step 1 let mut parser = Parser::new(&medium); - let m = MediaQuery::parse(&mut parser); + let global = self.global(); + let win = global.as_window(); + let url = win.get_url(); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media)); + let m = MediaQuery::parse(&context, &mut parser); // Step 2 if let Err(_) = m { return; @@ -120,7 +130,11 @@ impl MediaListMethods for MediaList { fn DeleteMedium(&self, medium: DOMString) { // Step 1 let mut parser = Parser::new(&medium); - let m = MediaQuery::parse(&mut parser); + let global = self.global(); + let win = global.as_window(); + let url = win.get_url(); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media)); + let m = MediaQuery::parse(&context, &mut parser); // Step 2 if let Err(_) = m { return; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 6a264c86d6b..94cebd6975f 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -103,10 +103,12 @@ use std::sync::mpsc::TryRecvError::{Disconnected, Empty}; use style::context::ReflowGoal; use style::error_reporting::ParseErrorReporter; use style::media_queries; +use style::parser::ParserContext as CssParserContext; use style::properties::PropertyId; use style::properties::longhands::overflow_x; use style::selector_parser::PseudoElement; use style::str::HTML_SPACE_CHARACTERS; +use style::stylesheets::CssRuleType; use task_source::dom_manipulation::DOMManipulationTaskSource; use task_source::file_reading::FileReadingTaskSource; use task_source::history_traversal::HistoryTraversalTaskSource; @@ -963,7 +965,9 @@ impl WindowMethods for Window { // https://drafts.csswg.org/cssom-view/#dom-window-matchmedia fn MatchMedia(&self, query: DOMString) -> Root { let mut parser = Parser::new(&query); - let media_query_list = media_queries::parse_media_query_list(&mut parser); + let url = self.get_url(); + let context = CssParserContext::new_for_cssom(&url, self.css_error_reporter(), Some(CssRuleType::Media)); + let media_query_list = media_queries::parse_media_query_list(&context, &mut parser); let document = self.Document(); let mql = MediaQueryList::new(&document, media_query_list); self.media_query_lists.push(&*mql); diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index d6c5a9286bd..b422d45a327 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -14,6 +14,7 @@ use gecko_bindings::structs::{nsMediaExpression_Range, nsMediaFeature}; use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType, nsMediaFeature_RequirementFlags}; use gecko_bindings::structs::RawGeckoPresContextOwned; use media_queries::MediaType; +use parser::ParserContext; use properties::ComputedValues; use std::ascii::AsciiExt; use std::fmt::{self, Write}; @@ -366,7 +367,7 @@ impl Expression { /// ``` /// (media-feature: media-value) /// ``` - pub fn parse(input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { try!(input.expect_parenthesis_block()); input.parse_nested_block(|input| { let ident = try!(input.expect_ident()); @@ -421,7 +422,7 @@ impl Expression { let value = match feature.mValueType { nsMediaFeature_ValueType::eLength => { MediaExpressionValue::Length( - specified::Length::parse_non_negative(input)?) + specified::Length::parse_non_negative(context, input)?) }, nsMediaFeature_ValueType::eInteger => { let i = input.expect_integer()?; diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index 8a50282682b..d92dd324f99 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -8,6 +8,7 @@ use Atom; use cssparser::{Delimiter, Parser, Token}; +use parser::ParserContext; use serialize_comma_separated_list; use std::ascii::AsciiExt; use std::fmt; @@ -23,7 +24,7 @@ pub use gecko::media_queries::{Device, Expression}; #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct MediaList { /// The list of media queries. - pub media_queries: Vec + pub media_queries: Vec, } impl ToCss for MediaList { @@ -206,7 +207,7 @@ impl MediaQuery { /// Parse a media query given css input. /// /// Returns an error if any of the expressions is unknown. - pub fn parse(input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { let mut expressions = vec![]; let qualifier = if input.try(|input| input.expect_ident_matching("only")).is_ok() { @@ -226,7 +227,7 @@ impl MediaQuery { } // Without a media type, require at least one expression. - expressions.push(try!(Expression::parse(input))); + expressions.push(try!(Expression::parse(context, input))); MediaQueryType::All } @@ -237,7 +238,7 @@ impl MediaQuery { if input.try(|input| input.expect_ident_matching("and")).is_err() { return Ok(MediaQuery::new(qualifier, media_type, expressions)) } - expressions.push(try!(Expression::parse(input))) + expressions.push(try!(Expression::parse(context, input))) } } } @@ -248,14 +249,14 @@ impl MediaQuery { /// media query list is only filled with the equivalent of "not all", see: /// /// https://drafts.csswg.org/mediaqueries/#error-handling -pub fn parse_media_query_list(input: &mut Parser) -> MediaList { +pub fn parse_media_query_list(context: &ParserContext, input: &mut Parser) -> MediaList { if input.is_exhausted() { return Default::default() } let mut media_queries = vec![]; loop { - match input.parse_until_before(Delimiter::Comma, MediaQuery::parse) { + match input.parse_until_before(Delimiter::Comma, |i| MediaQuery::parse(context, i)) { Ok(mq) => { media_queries.push(mq); }, @@ -307,9 +308,9 @@ impl MediaList { /// https://drafts.csswg.org/cssom/#dom-medialist-appendmedium /// /// Returns true if added, false if fail to parse the medium string. - pub fn append_medium(&mut self, new_medium: &str) -> bool { + pub fn append_medium(&mut self, context: &ParserContext, new_medium: &str) -> bool { let mut parser = Parser::new(new_medium); - let new_query = match MediaQuery::parse(&mut parser) { + let new_query = match MediaQuery::parse(&context, &mut parser) { Ok(query) => query, Err(_) => { return false; } }; @@ -325,9 +326,9 @@ impl MediaList { /// https://drafts.csswg.org/cssom/#dom-medialist-deletemedium /// /// Returns true if found and deleted, false otherwise. - pub fn delete_medium(&mut self, old_medium: &str) -> bool { + pub fn delete_medium(&mut self, context: &ParserContext, old_medium: &str) -> bool { let mut parser = Parser::new(old_medium); - let old_query = match MediaQuery::parse(&mut parser) { + let old_query = match MediaQuery::parse(context, &mut parser) { Ok(query) => query, Err(_) => { return false; } }; diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index 8739ca7a356..1b33d7dd0be 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -482,7 +482,7 @@ ${helpers.single_keyword("background-origin", }) } - pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { if input.try(|input| input.expect_ident_matching("cover")).is_ok() { return Ok(SpecifiedValue::Cover); } @@ -492,12 +492,12 @@ ${helpers.single_keyword("background-origin", } let width = - try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input)); + try!(specified::LengthOrPercentageOrAuto::parse_non_negative(context, input)); let height = if input.is_exhausted() { specified::LengthOrPercentageOrAuto::Auto } else { - try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input)) + try!(specified::LengthOrPercentageOrAuto::parse_non_negative(context, input)) }; Ok(SpecifiedValue::Explicit(ExplicitSize { diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 8a468cb5fa7..7dadb540ebb 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -525,16 +525,16 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box", } impl Parse for SingleSpecifiedValue { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { if input.try(|input| input.expect_ident_matching("auto")).is_ok() { return Ok(SingleSpecifiedValue::Auto); } - if let Ok(len) = input.try(|input| LengthOrPercentage::parse_non_negative(input)) { + if let Ok(len) = input.try(|input| LengthOrPercentage::parse_non_negative(context, input)) { return Ok(SingleSpecifiedValue::LengthOrPercentage(len)); } - let num = try!(Number::parse_non_negative(input)); + let num = try!(Number::parse_non_negative(context, input)); Ok(SingleSpecifiedValue::Number(num)) } } diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index ffa8c5ebddf..34cdc44a57c 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -558,20 +558,20 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", } impl Parse for SpecifiedValue { - fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result { + fn parse(context: &ParserContext, input: &mut ::cssparser::Parser) -> Result { if let Ok(function_name) = input.try(|input| input.expect_function()) { return match_ignore_ascii_case! { &function_name, "cubic-bezier" => { let (mut p1x, mut p1y, mut p2x, mut p2y) = (Number::new(0.0), Number::new(0.0), Number::new(0.0), Number::new(0.0)); try!(input.parse_nested_block(|input| { - p1x = try!(specified::parse_number(input)); + p1x = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - p1y = try!(specified::parse_number(input)); + p1y = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - p2x = try!(specified::parse_number(input)); + p2x = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - p2y = try!(specified::parse_number(input)); + p2y = try!(specified::parse_number(context, input)); Ok(()) })); if p1x.value < 0.0 || p1x.value > 1.0 || @@ -585,7 +585,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", "steps" => { let (mut step_count, mut start_end) = (specified::Integer::new(0), StartEnd::End); try!(input.parse_nested_block(|input| { - step_count = try!(specified::parse_integer(input)); + step_count = try!(specified::parse_integer(context, input)); if step_count.value() < 1 { return Err(()) } @@ -1057,12 +1057,12 @@ ${helpers.single_keyword("animation-fill-mode", } } - pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { if input.try(|input| input.expect_ident_matching("none")).is_ok() { Ok(SpecifiedValue::None) } else if input.try(|input| input.expect_function_matching("repeat")).is_ok() { input.parse_nested_block(|input| { - LengthOrPercentage::parse_non_negative(input).map(SpecifiedValue::Repeat) + LengthOrPercentage::parse_non_negative(context, input).map(SpecifiedValue::Repeat) }) } else { Err(()) @@ -1349,7 +1349,7 @@ ${helpers.predefined_type("scroll-snap-coordinate", "matrix" => { try!(input.parse_nested_block(|input| { let values = try!(input.parse_comma_separated(|input| { - specified::parse_number(input) + specified::parse_number(context, input) })); if values.len() != 6 { return Err(()) @@ -1367,7 +1367,7 @@ ${helpers.predefined_type("scroll-snap-coordinate", }, "matrix3d" => { try!(input.parse_nested_block(|input| { - let values = try!(input.parse_comma_separated(specified::parse_number)); + let values = try!(input.parse_comma_separated(|i| specified::parse_number(context, i))); if values.len() != 16 { return Err(()) } @@ -1426,9 +1426,9 @@ ${helpers.predefined_type("scroll-snap-coordinate", }, "scale" => { try!(input.parse_nested_block(|input| { - let sx = try!(specified::parse_number(input)); + let sx = try!(specified::parse_number(context, input)); if input.try(|input| input.expect_comma()).is_ok() { - let sy = try!(specified::parse_number(input)); + let sy = try!(specified::parse_number(context, input)); result.push(SpecifiedOperation::Scale(sx, Some(sy))); } else { result.push(SpecifiedOperation::Scale(sx, None)); @@ -1438,32 +1438,32 @@ ${helpers.predefined_type("scroll-snap-coordinate", }, "scalex" => { try!(input.parse_nested_block(|input| { - let sx = try!(specified::parse_number(input)); + let sx = try!(specified::parse_number(context, input)); result.push(SpecifiedOperation::ScaleX(sx)); Ok(()) })) }, "scaley" => { try!(input.parse_nested_block(|input| { - let sy = try!(specified::parse_number(input)); + let sy = try!(specified::parse_number(context, input)); result.push(SpecifiedOperation::ScaleY(sy)); Ok(()) })) }, "scalez" => { try!(input.parse_nested_block(|input| { - let sz = try!(specified::parse_number(input)); + let sz = try!(specified::parse_number(context, input)); result.push(SpecifiedOperation::ScaleZ(sz)); Ok(()) })) }, "scale3d" => { try!(input.parse_nested_block(|input| { - let sx = try!(specified::parse_number(input)); + let sx = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - let sy = try!(specified::parse_number(input)); + let sy = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - let sz = try!(specified::parse_number(input)); + let sz = try!(specified::parse_number(context, input)); result.push(SpecifiedOperation::Scale3D(sx, sy, sz)); Ok(()) })) @@ -1498,11 +1498,11 @@ ${helpers.predefined_type("scroll-snap-coordinate", }, "rotate3d" => { try!(input.parse_nested_block(|input| { - let ax = try!(specified::parse_number(input)); + let ax = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - let ay = try!(specified::parse_number(input)); + let ay = try!(specified::parse_number(context, input)); try!(input.expect_comma()); - let az = try!(specified::parse_number(input)); + let az = try!(specified::parse_number(context, input)); try!(input.expect_comma()); let theta = try!(specified::Angle::parse_with_unitless(context,input)); // TODO(gw): Check the axis can be normalized!! @@ -1538,7 +1538,7 @@ ${helpers.predefined_type("scroll-snap-coordinate", }, "perspective" => { try!(input.parse_nested_block(|input| { - let d = try!(specified::Length::parse_non_negative(input)); + let d = try!(specified::Length::parse_non_negative(context, input)); result.push(SpecifiedOperation::Perspective(d)); Ok(()) })) diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhand/counters.mako.rs index bcea2f00a82..f9a5aacd3a0 100644 --- a/components/style/properties/longhand/counters.mako.rs +++ b/components/style/properties/longhand/counters.mako.rs @@ -330,11 +330,11 @@ } } - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { - parse_common(1, input) + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { + parse_common(context, 1, input) } - pub fn parse_common(default_value: i32, input: &mut Parser) -> Result { + pub fn parse_common(context: &ParserContext, default_value: i32, input: &mut Parser) -> Result { if input.try(|input| input.expect_ident_matching("none")).is_ok() { return Ok(SpecifiedValue(Vec::new())) } @@ -349,8 +349,8 @@ if content::counter_name_is_illegal(&counter_name) { return Err(()) } - let counter_delta = - input.try(|input| specified::parse_integer(input)).unwrap_or(specified::Integer::new(default_value)); + let counter_delta = input.try(|input| specified::parse_integer(context, input)) + .unwrap_or(specified::Integer::new(default_value)); counters.push((counter_name, counter_delta)) } @@ -367,7 +367,7 @@ pub use super::counter_increment::{SpecifiedValue, computed_value, get_initial_value}; use super::counter_increment::parse_common; - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { - parse_common(0, input) + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { + parse_common(context, 0, input) } diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index 1392475f09c..0b56cb38e67 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -339,7 +339,7 @@ ${helpers.predefined_type("clip", if let Ok(function_name) = input.try(|input| input.expect_function()) { filters.push(try!(input.parse_nested_block(|input| { match_ignore_ascii_case! { &function_name, - "blur" => specified::Length::parse_non_negative(input).map(SpecifiedFilter::Blur), + "blur" => specified::Length::parse_non_negative(context, input).map(SpecifiedFilter::Blur), "brightness" => parse_factor(input).map(SpecifiedFilter::Brightness), "contrast" => parse_factor(input).map(SpecifiedFilter::Contrast), "grayscale" => parse_factor(input).map(SpecifiedFilter::Grayscale), diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 64c83d418c5..7628cb2de96 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -659,8 +659,8 @@ ${helpers.single_keyword("font-variant-caps", } } /// | | | - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { - if let Ok(lop) = input.try(specified::LengthOrPercentage::parse_non_negative) { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { + if let Ok(lop) = input.try(|i| specified::LengthOrPercentage::parse_non_negative(context, i)) { return Ok(SpecifiedValue::Length(lop)) } @@ -766,14 +766,14 @@ ${helpers.single_keyword("font-variant-caps", } /// none | - pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { use values::specified::Number; if input.try(|input| input.expect_ident_matching("none")).is_ok() { return Ok(SpecifiedValue::None); } - Ok(SpecifiedValue::Number(try!(Number::parse_non_negative(input)))) + Ok(SpecifiedValue::Number(try!(Number::parse_non_negative(context, input)))) } diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index 2d051590b62..dabe915cd86 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -71,7 +71,6 @@ ${helpers.predefined_type( "parse_numbers_are_pixels_non_negative", products="gecko", animation_type="normal", - needs_context=False, spec="https://www.w3.org/TR/SVG2/painting.html#StrokeWidth")} ${helpers.single_keyword("stroke-linecap", "butt round square", @@ -84,7 +83,6 @@ ${helpers.single_keyword("stroke-linejoin", "miter round bevel", ${helpers.predefined_type("stroke-miterlimit", "Number", "4.0", "parse_at_least_one", products="gecko", - needs_context=False, animation_type="none", spec="https://www.w3.org/TR/SVG11/painting.html#StrokeMiterlimitProperty")} @@ -108,7 +106,6 @@ ${helpers.predefined_type( "parse_numbers_are_pixels", products="gecko", animation_type="normal", - needs_context=False, spec="https://www.w3.org/TR/SVG2/painting.html#StrokeDashing")} // Section 14 - Clipping, Masking and Compositing diff --git a/components/style/properties/longhand/inherited_table.mako.rs b/components/style/properties/longhand/inherited_table.mako.rs index b72482ce1fc..c202d0abe62 100644 --- a/components/style/properties/longhand/inherited_table.mako.rs +++ b/components/style/properties/longhand/inherited_table.mako.rs @@ -114,14 +114,14 @@ ${helpers.single_keyword("caption-side", "top bottom", } } - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { let mut first = None; let mut second = None; - match specified::Length::parse_non_negative(input) { + match specified::Length::parse_non_negative(context, input) { Err(()) => (), Ok(length) => { first = Some(length); - if let Ok(len) = input.try(|input| specified::Length::parse_non_negative(input)) { + if let Ok(len) = input.try(|input| specified::Length::parse_non_negative(context, input)) { second = Some(len); } } diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 07054fbbd56..709cb2b4a32 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -45,18 +45,18 @@ } } /// normal | | | - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { use cssparser::Token; use std::ascii::AsciiExt; // We try to parse as a Number first because, for 'line-height', we want // "0" to be parsed as a plain Number rather than a Length (0px); this // matches the behaviour of all major browsers - if let Ok(number) = input.try(specified::Number::parse_non_negative) { + if let Ok(number) = input.try(|i| specified::Number::parse_non_negative(context, i)) { return Ok(SpecifiedValue::Number(number)) } - if let Ok(lop) = input.try(specified::LengthOrPercentage::parse_non_negative) { + if let Ok(lop) = input.try(|i| specified::LengthOrPercentage::parse_non_negative(context, i)) { return Ok(SpecifiedValue::LengthOrPercentage(lop)) } diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index 5fba4d67345..810e3ed41c1 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -77,8 +77,8 @@ ${helpers.predefined_type("outline-color", "CSSColor", "computed::CSSColor::Curr } } - pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - specified::parse_border_width(input).map(SpecifiedValue) + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { + specified::parse_border_width(context, input).map(SpecifiedValue) } impl HasViewportPercentage for SpecifiedValue { diff --git a/components/style/properties/longhand/padding.mako.rs b/components/style/properties/longhand/padding.mako.rs index 75786ab1bd9..6f2596088ff 100644 --- a/components/style/properties/longhand/padding.mako.rs +++ b/components/style/properties/longhand/padding.mako.rs @@ -16,7 +16,6 @@ "computed::LengthOrPercentage::Length(Au(0))", "parse_non_negative", alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"), - needs_context=False, animation_type="normal", logical = side[1], spec = spec)} diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index 6b0551fcc1a..ed41a227de8 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -95,14 +95,12 @@ ${helpers.predefined_type("flex-grow", "Number", "0.0", "parse_non_negative", spec="https://drafts.csswg.org/css-flexbox/#flex-grow-property", extra_prefixes="webkit", - needs_context=False, animation_type="normal")} ${helpers.predefined_type("flex-shrink", "Number", "1.0", "parse_non_negative", spec="https://drafts.csswg.org/css-flexbox/#flex-shrink-property", extra_prefixes="webkit", - needs_context=False, animation_type="normal")} // https://drafts.csswg.org/css-align/#align-self-property @@ -142,7 +140,6 @@ ${helpers.predefined_type("flex-basis", "computed::LengthOrPercentageOrAuto::Auto" if product == "gecko" else "computed::LengthOrPercentageOrAutoOrContent::Auto", "parse_non_negative", - needs_context=False, spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", extra_prefixes="webkit", animation_type="normal" if product == "gecko" else "none")} @@ -158,7 +155,6 @@ ${helpers.predefined_type("flex-basis", "LengthOrPercentageOrAuto", "computed::LengthOrPercentageOrAuto::Auto", "parse_non_negative", - needs_context=False, spec=spec % size, animation_type="normal", logical = logical)} % if product == "gecko": @@ -255,14 +251,12 @@ ${helpers.predefined_type("flex-basis", "LengthOrPercentage", "computed::LengthOrPercentage::Length(Au(0))", "parse_non_negative", - needs_context=False, spec=spec % ("min-%s" % size), animation_type="normal", logical = logical)} ${helpers.predefined_type("max-%s" % size, "LengthOrPercentageOrNone", "computed::LengthOrPercentageOrNone::None", "parse_non_negative", - needs_context=False, spec=spec % ("min-%s" % size), animation_type="normal", logical = logical)} % endif diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 170b2476311..1cfc2803786 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -288,7 +288,7 @@ ${helpers.predefined_type( return Ok(SpecifiedValue::Normal); } - let size = try!(Number::parse_at_least_one(input)); + let size = try!(Number::parse_at_least_one(context, input)); match input.try(|input| Integer::parse(context, input)) { Ok(number) => { diff --git a/components/style/properties/longhand/xul.mako.rs b/components/style/properties/longhand/xul.mako.rs index 2fd7c9a6e16..f37809dadc8 100644 --- a/components/style/properties/longhand/xul.mako.rs +++ b/components/style/properties/longhand/xul.mako.rs @@ -25,7 +25,6 @@ ${helpers.single_keyword("-moz-box-direction", "normal reverse", ${helpers.predefined_type("-moz-box-flex", "Number", "0.0", "parse_non_negative", products="gecko", gecko_ffi_name="mBoxFlex", - needs_context=False, animation_type="none", alias="-webkit-box-flex", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/box-flex)")} @@ -52,7 +51,6 @@ ${helpers.single_keyword("-moz-stack-sizing", "stretch-to-fit ignore", ${helpers.predefined_type("-moz-box-ordinal-group", "Integer", "0", parse_method="parse_non_negative", - needs_context=False, products="gecko", alias="-webkit-box-ordinal-group", gecko_ffi_name="mBoxOrdinal", diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 3d4009d750f..12581a3dff7 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -50,10 +50,10 @@ spec="https://drafts.csswg.org/css-flexbox/#flex-property"> use values::specified::Number; - fn parse_flexibility(input: &mut Parser) + fn parse_flexibility(context: &ParserContext, input: &mut Parser) -> Result<(Number, Option),()> { - let grow = try!(Number::parse_non_negative(input)); - let shrink = input.try(Number::parse_non_negative).ok(); + let grow = try!(Number::parse_non_negative(context, input)); + let shrink = input.try(|i| Number::parse_non_negative(context, i)).ok(); Ok((grow, shrink)) } @@ -71,7 +71,7 @@ } loop { if grow.is_none() { - if let Ok((flex_grow, flex_shrink)) = input.try(parse_flexibility) { + if let Ok((flex_grow, flex_shrink)) = input.try(|i| parse_flexibility(context, i)) { grow = Some(flex_grow); shrink = flex_shrink; continue diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index 24dd050fb2b..c2ff1cb828d 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -9,6 +9,7 @@ use cssparser::Parser; use euclid::{Size2D, TypedSize2D}; use font_metrics::ServoMetricsProvider; use media_queries::MediaType; +use parser::ParserContext; use properties::ComputedValues; use std::fmt; use style_traits::{CSSPixel, ToCss}; @@ -104,7 +105,7 @@ impl Expression { /// ``` /// /// Only supports width and width ranges for now. - pub fn parse(input: &mut Parser) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { try!(input.expect_parenthesis_block()); input.parse_nested_block(|input| { let name = try!(input.expect_ident()); @@ -112,13 +113,13 @@ impl Expression { // TODO: Handle other media features Ok(Expression(match_ignore_ascii_case! { &name, "min-width" => { - ExpressionKind::Width(Range::Min(try!(specified::Length::parse_non_negative(input)))) + ExpressionKind::Width(Range::Min(try!(specified::Length::parse_non_negative(context, input)))) }, "max-width" => { - ExpressionKind::Width(Range::Max(try!(specified::Length::parse_non_negative(input)))) + ExpressionKind::Width(Range::Max(try!(specified::Length::parse_non_negative(context, input)))) }, "width" => { - ExpressionKind::Width(Range::Eq(try!(specified::Length::parse_non_negative(input)))) + ExpressionKind::Width(Range::Eq(try!(specified::Length::parse_non_negative(context, input)))) }, _ => return Err(()) })) diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index f9bfe30fd38..3aa214df9e2 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -905,7 +905,7 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> { let url_string = input.expect_url_or_string()?; let specified_url = SpecifiedUrl::parse_from_string(url_string, &self.context)?; - let media = parse_media_query_list(input); + let media = parse_media_query_list(&self.context, input); let noop_loader = NoOpLoader; let loader = if !specified_url.is_invalid() { @@ -1054,7 +1054,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { -> Result, ()> { match_ignore_ascii_case! { name, "media" => { - let media_queries = parse_media_query_list(input); + let media_queries = parse_media_query_list(self.context, input); let arc = Arc::new(self.shared_lock.wrap(media_queries)); Ok(AtRuleType::WithBlock(AtRulePrelude::Media(arc))) }, diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 469614a2b9f..83a711b38b2 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -662,8 +662,8 @@ impl Default for ShapeRadius { } impl Parse for ShapeRadius { - fn parse(_: &ParserContext, input: &mut Parser) -> Result { - input.try(|i| LengthOrPercentage::parse_non_negative(i)).map(ShapeRadius::Length).or_else(|_| { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + input.try(|i| LengthOrPercentage::parse_non_negative(context, i)).map(ShapeRadius::Length).or_else(|_| { match_ignore_ascii_case! { &try!(input.expect_ident()), "closest-side" => Ok(ShapeRadius::ClosestSide), "farthest-side" => Ok(ShapeRadius::FarthestSide), @@ -749,10 +749,10 @@ impl ToCss for BorderRadius { } impl Parse for BorderRadius { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - let mut widths = try!(parse_one_set_of_border_values(input)); + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + let mut widths = try!(parse_one_set_of_border_values(context, input)); let mut heights = if input.try(|input| input.expect_delim('/')).is_ok() { - try!(parse_one_set_of_border_values(input)) + try!(parse_one_set_of_border_values(context, input)) } else { [widths[0].clone(), widths[1].clone(), @@ -768,22 +768,22 @@ impl Parse for BorderRadius { } } -fn parse_one_set_of_border_values(mut input: &mut Parser) +fn parse_one_set_of_border_values(context: &ParserContext, mut input: &mut Parser) -> Result<[LengthOrPercentage; 4], ()> { - let a = try!(LengthOrPercentage::parse_non_negative(input)); - let b = if let Ok(b) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) { + let a = try!(LengthOrPercentage::parse_non_negative(context, input)); + let b = if let Ok(b) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { b } else { return Ok([a.clone(), a.clone(), a.clone(), a]) }; - let c = if let Ok(c) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) { + let c = if let Ok(c) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { c } else { return Ok([a.clone(), b.clone(), a, b]) }; - if let Ok(d) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) { + if let Ok(d) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { Ok([a, b, c, d]) } else { Ok([a, b.clone(), c, b]) diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index e04e85b9394..92dbc4fbcaa 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -138,8 +138,8 @@ pub fn parse_flex(input: &mut Parser) -> Result { } impl Parse for TrackBreadth { - fn parse(_: &ParserContext, input: &mut Parser) -> Result { - if let Ok(lop) = input.try(LengthOrPercentage::parse_non_negative) { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { return Ok(TrackBreadth::Breadth(lop)) } @@ -230,7 +230,7 @@ impl Parse for TrackSize { if input.try(|i| i.expect_function_matching("minmax")).is_ok() { return input.parse_nested_block(|input| { let inflexible_breadth = - match input.try(LengthOrPercentage::parse_non_negative) { + match input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) { Ok(lop) => TrackBreadth::Breadth(lop), Err(..) => { let keyword = try!(TrackKeyword::parse(input)); diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 253ced6b6e2..48059b04584 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -373,7 +373,7 @@ impl Mul for NoCalcLength { impl NoCalcLength { /// Parse a given absolute or relative dimension. - pub fn parse_dimension(value: CSSFloat, unit: &str) -> Result { + pub fn parse_dimension(_context: &ParserContext, value: CSSFloat, unit: &str) -> Result { match_ignore_ascii_case! { unit, "px" => Ok(NoCalcLength::Absolute(AbsoluteLength::Px(value))), "in" => Ok(NoCalcLength::Absolute(AbsoluteLength::In(value))), @@ -512,19 +512,20 @@ impl Length { } /// Parse a given absolute or relative dimension. - pub fn parse_dimension(value: CSSFloat, unit: &str) -> Result { - NoCalcLength::parse_dimension(value, unit).map(Length::NoCalc) + pub fn parse_dimension(context: &ParserContext, value: CSSFloat, unit: &str) -> Result { + NoCalcLength::parse_dimension(context, value, unit).map(Length::NoCalc) } #[inline] - fn parse_internal(input: &mut Parser, context: AllowedNumericType) -> Result { + fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) + -> Result { match try!(input.next()) { - Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => - Length::parse_dimension(value.value, unit), + Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + Length::parse_dimension(context, value.value, unit), Token::Number(ref value) if value.value == 0. => Ok(Length::zero()), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => input.parse_nested_block(|input| { - CalcLengthOrPercentage::parse_length(input, context) + CalcLengthOrPercentage::parse_length(context, input, num_context) }), _ => Err(()) } @@ -532,8 +533,8 @@ impl Length { /// Parse a non-negative length #[inline] - pub fn parse_non_negative(input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::NonNegative) + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::NonNegative) } /// Get an absolute length from a px value. @@ -552,8 +553,8 @@ impl Length { } impl Parse for Length { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::All) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::All) } } @@ -564,7 +565,7 @@ impl Either { if input.try(|input| None_::parse(context, input)).is_ok() { return Ok(Either::Second(None_)); } - Length::parse_non_negative(input).map(Either::First) + Length::parse_non_negative(context, input).map(Either::First) } } @@ -575,7 +576,7 @@ impl Either { if input.try(|input| Normal::parse(context, input)).is_ok() { return Ok(Either::Second(Normal)); } - Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First) + Length::parse_internal(context, input, AllowedNumericType::NonNegative).map(Either::First) } } @@ -586,7 +587,7 @@ impl Either { if input.try(|input| Auto::parse(context, input)).is_ok() { return Ok(Either::Second(Auto)); } - Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First) + Length::parse_internal(context, input, AllowedNumericType::NonNegative).map(Either::First) } } @@ -645,9 +646,9 @@ pub struct CalcLengthOrPercentage { impl CalcLengthOrPercentage { /// Parse a calc sum node. - pub fn parse_sum(input: &mut Parser, expected_unit: CalcUnit) -> Result { + pub fn parse_sum(context: &ParserContext, input: &mut Parser, expected_unit: CalcUnit) -> Result { let mut products = Vec::new(); - products.push(try!(CalcLengthOrPercentage::parse_product(input, expected_unit))); + products.push(try!(CalcLengthOrPercentage::parse_product(context, input, expected_unit))); loop { let position = input.position(); @@ -658,10 +659,10 @@ impl CalcLengthOrPercentage { } match input.next() { Ok(Token::Delim('+')) => { - products.push(try!(CalcLengthOrPercentage::parse_product(input, expected_unit))); + products.push(try!(CalcLengthOrPercentage::parse_product(context, input, expected_unit))); } Ok(Token::Delim('-')) => { - let mut right = try!(CalcLengthOrPercentage::parse_product(input, expected_unit)); + let mut right = try!(CalcLengthOrPercentage::parse_product(context, input, expected_unit)); right.values.push(CalcValueNode::Number(-1.)); products.push(right); } @@ -679,15 +680,16 @@ impl CalcLengthOrPercentage { Ok(CalcSumNode { products: products }) } - fn parse_product(input: &mut Parser, expected_unit: CalcUnit) -> Result { + fn parse_product(context: &ParserContext, input: &mut Parser, expected_unit: CalcUnit) + -> Result { let mut values = Vec::new(); - values.push(try!(CalcLengthOrPercentage::parse_value(input, expected_unit))); + values.push(try!(CalcLengthOrPercentage::parse_value(context, input, expected_unit))); loop { let position = input.position(); match input.next() { Ok(Token::Delim('*')) => { - values.push(try!(CalcLengthOrPercentage::parse_value(input, expected_unit))); + values.push(try!(CalcLengthOrPercentage::parse_value(context, input, expected_unit))); } Ok(Token::Delim('/')) if expected_unit != CalcUnit::Integer => { if let Ok(Token::Number(ref value)) = input.next() { @@ -709,12 +711,12 @@ impl CalcLengthOrPercentage { Ok(CalcProductNode { values: values }) } - fn parse_value(input: &mut Parser, expected_unit: CalcUnit) -> Result { + fn parse_value(context: &ParserContext, input: &mut Parser, expected_unit: CalcUnit) -> Result { match (try!(input.next()), expected_unit) { (Token::Number(ref value), _) => Ok(CalcValueNode::Number(value.value)), (Token::Dimension(ref value, ref unit), CalcUnit::Length) | (Token::Dimension(ref value, ref unit), CalcUnit::LengthOrPercentage) => { - NoCalcLength::parse_dimension(value.value, unit).map(CalcValueNode::Length) + NoCalcLength::parse_dimension(context, value.value, unit).map(CalcValueNode::Length) } (Token::Dimension(ref value, ref unit), CalcUnit::Angle) => { Angle::parse_dimension(value.value, unit).map(|angle| { @@ -729,7 +731,7 @@ impl CalcLengthOrPercentage { (Token::Percentage(ref value), CalcUnit::LengthOrPercentage) => Ok(CalcValueNode::Percentage(value.unit_value)), (Token::ParenthesisBlock, _) => { - input.parse_nested_block(|i| CalcLengthOrPercentage::parse_sum(i, expected_unit)) + input.parse_nested_block(|i| CalcLengthOrPercentage::parse_sum(context, i, expected_unit)) .map(|result| CalcValueNode::Sum(Box::new(result))) }, _ => Err(()) @@ -810,21 +812,23 @@ impl CalcLengthOrPercentage { } } - fn parse_length(input: &mut Parser, - context: AllowedNumericType) -> Result { - CalcLengthOrPercentage::parse(input, CalcUnit::Length).map(|calc| { - Length::Calc(Box::new(calc), context) + fn parse_length(context: &ParserContext, + input: &mut Parser, + num_context: AllowedNumericType) -> Result { + CalcLengthOrPercentage::parse(context, input, CalcUnit::Length).map(|calc| { + Length::Calc(Box::new(calc), num_context) }) } - fn parse_length_or_percentage(input: &mut Parser) -> Result { - CalcLengthOrPercentage::parse(input, CalcUnit::LengthOrPercentage) + fn parse_length_or_percentage(context: &ParserContext, input: &mut Parser) -> Result { + CalcLengthOrPercentage::parse(context, input, CalcUnit::LengthOrPercentage) } #[allow(missing_docs)] - pub fn parse(input: &mut Parser, + pub fn parse(context: &ParserContext, + input: &mut Parser, expected_unit: CalcUnit) -> Result { - let ast = try!(CalcLengthOrPercentage::parse_sum(input, expected_unit)); + let ast = try!(CalcLengthOrPercentage::parse_sum(context, input, expected_unit)); let mut simplified = Vec::new(); for ref node in ast.products { @@ -893,8 +897,8 @@ impl CalcLengthOrPercentage { } #[allow(missing_docs)] - pub fn parse_time(input: &mut Parser) -> Result { - let ast = try!(CalcLengthOrPercentage::parse_sum(input, CalcUnit::Time)); + pub fn parse_time(context: &ParserContext, input: &mut Parser) -> Result { + let ast = try!(CalcLengthOrPercentage::parse_sum(context, input, CalcUnit::Time)); let mut simplified = Vec::new(); for ref node in ast.products { @@ -921,8 +925,8 @@ impl CalcLengthOrPercentage { } #[allow(missing_docs)] - pub fn parse_angle(input: &mut Parser) -> Result { - let ast = try!(CalcLengthOrPercentage::parse_sum(input, CalcUnit::Angle)); + pub fn parse_angle(context: &ParserContext, input: &mut Parser) -> Result { + let ast = try!(CalcLengthOrPercentage::parse_sum(context, input, CalcUnit::Angle)); let mut simplified = Vec::new(); for ref node in ast.products { @@ -1119,18 +1123,20 @@ impl LengthOrPercentage { LengthOrPercentage::Length(NoCalcLength::zero()) } - fn parse_internal(input: &mut Parser, context: AllowedNumericType) + fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) -> Result { match try!(input.next()) { - Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => - NoCalcLength::parse_dimension(value.value, unit).map(LengthOrPercentage::Length), - Token::Percentage(ref value) if context.is_ok(value.unit_value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentage::Length), + Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => Ok(LengthOrPercentage::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => Ok(LengthOrPercentage::zero()), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); + let calc = try!(input.parse_nested_block(|i| { + CalcLengthOrPercentage::parse_length_or_percentage(context, i) + })); Ok(LengthOrPercentage::Calc(Box::new(calc))) }, _ => Err(()) @@ -1139,15 +1145,15 @@ impl LengthOrPercentage { /// Parse a non-negative length. #[inline] - pub fn parse_non_negative(input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::NonNegative) + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::NonNegative) } /// Parse a length, treating dimensionless numbers as pixels /// /// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value - pub fn parse_numbers_are_pixels(input: &mut Parser) -> Result { - if let Ok(lop) = input.try(|i| Self::parse_internal(i, AllowedNumericType::All)) { + pub fn parse_numbers_are_pixels(context: &ParserContext, input: &mut Parser) -> Result { + if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedNumericType::All)) { return Ok(lop) } @@ -1160,8 +1166,10 @@ impl LengthOrPercentage { /// Parse a non-negative length, treating dimensionless numbers as pixels /// /// This is nonstandard behavior used by Firefox for SVG - pub fn parse_numbers_are_pixels_non_negative(input: &mut Parser) -> Result { - if let Ok(lop) = input.try(|i| Self::parse_internal(i, AllowedNumericType::NonNegative)) { + pub fn parse_numbers_are_pixels_non_negative(context: &ParserContext, + input: &mut Parser) + -> Result { + if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedNumericType::NonNegative)) { return Ok(lop) } @@ -1186,8 +1194,8 @@ impl LengthOrPercentage { impl Parse for LengthOrPercentage { #[inline] - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::All) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::All) } } @@ -1240,19 +1248,21 @@ impl ToCss for LengthOrPercentageOrAuto { } impl LengthOrPercentageOrAuto { - fn parse_internal(input: &mut Parser, context: AllowedNumericType) + fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) -> Result { match try!(input.next()) { - Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => - NoCalcLength::parse_dimension(value.value, unit).map(LengthOrPercentageOrAuto::Length), - Token::Percentage(ref value) if context.is_ok(value.unit_value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length), + Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => Ok(Self::zero()), Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Ok(LengthOrPercentageOrAuto::Auto), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); + let calc = try!(input.parse_nested_block(|i| { + CalcLengthOrPercentage::parse_length_or_percentage(context, i) + })); Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc))) }, _ => Err(()) @@ -1261,8 +1271,8 @@ impl LengthOrPercentageOrAuto { /// Parse a non-negative length, percentage, or auto. #[inline] - pub fn parse_non_negative(input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::NonNegative) + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::NonNegative) } /// Returns the `auto` value. @@ -1278,8 +1288,8 @@ impl LengthOrPercentageOrAuto { impl Parse for LengthOrPercentageOrAuto { #[inline] - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::All) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::All) } } @@ -1316,18 +1326,20 @@ impl ToCss for LengthOrPercentageOrNone { } } impl LengthOrPercentageOrNone { - fn parse_internal(input: &mut Parser, context: AllowedNumericType) + fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType) -> Result { match try!(input.next()) { - Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => - NoCalcLength::parse_dimension(value.value, unit).map(LengthOrPercentageOrNone::Length), - Token::Percentage(ref value) if context.is_ok(value.unit_value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length), + Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => Ok(LengthOrPercentageOrNone::Length(NoCalcLength::zero())), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); + let calc = try!(input.parse_nested_block(|i| { + CalcLengthOrPercentage::parse_length_or_percentage(context, i) + })); Ok(LengthOrPercentageOrNone::Calc(Box::new(calc))) }, Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => @@ -1337,15 +1349,15 @@ impl LengthOrPercentageOrNone { } /// Parse a non-negative LengthOrPercentageOrNone. #[inline] - pub fn parse_non_negative(input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::NonNegative) + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::NonNegative) } } impl Parse for LengthOrPercentageOrNone { #[inline] - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - Self::parse_internal(input, AllowedNumericType::All) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse_internal(context, input, AllowedNumericType::All) } } @@ -1379,12 +1391,13 @@ pub enum LengthOrPercentageOrAutoOrContent { impl LengthOrPercentageOrAutoOrContent { /// Parse a non-negative LengthOrPercentageOrAutoOrContent. - pub fn parse_non_negative(input: &mut Parser) -> Result { - let context = AllowedNumericType::NonNegative; + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + let num_context = AllowedNumericType::NonNegative; match try!(input.next()) { - Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => - NoCalcLength::parse_dimension(value.value, unit).map(LengthOrPercentageOrAutoOrContent::Length), - Token::Percentage(ref value) if context.is_ok(value.unit_value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + NoCalcLength::parse_dimension(context, value.value, unit) + .map(LengthOrPercentageOrAutoOrContent::Length), + Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => Ok(Self::zero()), @@ -1393,7 +1406,9 @@ impl LengthOrPercentageOrAutoOrContent { Token::Ident(ref value) if value.eq_ignore_ascii_case("content") => Ok(LengthOrPercentageOrAutoOrContent::Content), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); + let calc = try!(input.parse_nested_block(|i| { + CalcLengthOrPercentage::parse_length_or_percentage(context, i) + })); Ok(LengthOrPercentageOrAutoOrContent::Calc(Box::new(calc))) }, _ => Err(()) @@ -1438,15 +1453,15 @@ pub type LengthOrNumber = Either; impl LengthOrNumber { /// Parse a non-negative LengthOrNumber. - pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result { + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { // We try to parse as a Number first because, for cases like // LengthOrNumber, we want "0" to be parsed as a plain Number rather // than a Length (0px); this matches the behaviour of all major browsers - if let Ok(v) = input.try(Number::parse_non_negative) { + if let Ok(v) = input.try(|i| Number::parse_non_negative(context, i)) { return Ok(Either::Second(v)) } - Length::parse_non_negative(input).map(Either::First) + Length::parse_non_negative(context, input).map(Either::First) } } @@ -1485,9 +1500,10 @@ impl ToCss for MinLength { } impl Parse for MinLength { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { input.try(ExtremumLength::parse).map(MinLength::ExtremumLength) - .or_else(|()| input.try(LengthOrPercentage::parse_non_negative).map(MinLength::LengthOrPercentage)) + .or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) + .map(MinLength::LengthOrPercentage)) .or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto)) } } @@ -1525,9 +1541,10 @@ impl ToCss for MaxLength { } impl Parse for MaxLength { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength) - .or_else(|()| input.try(LengthOrPercentage::parse_non_negative).map(MaxLength::LengthOrPercentage)) + .or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) + .map(MaxLength::LengthOrPercentage)) .or_else(|()| { match_ignore_ascii_case! { &try!(input.expect_ident()), "none" => diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index ab97aa20479..05ebe2dc211 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -208,12 +208,12 @@ impl<'a> Mul for &'a SimplifiedValueNode { } #[allow(missing_docs)] -pub fn parse_integer(input: &mut Parser) -> Result { +pub fn parse_integer(context: &ParserContext, input: &mut Parser) -> Result { match try!(input.next()) { Token::Number(ref value) => value.int_value.ok_or(()).map(Integer::new), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { let ast = try!(input.parse_nested_block(|i| { - CalcLengthOrPercentage::parse_sum(i, CalcUnit::Integer) + CalcLengthOrPercentage::parse_sum(context, i, CalcUnit::Integer) })); let mut result = None; @@ -236,7 +236,7 @@ pub fn parse_integer(input: &mut Parser) -> Result { } #[allow(missing_docs)] -pub fn parse_number(input: &mut Parser) -> Result { +pub fn parse_number(context: &ParserContext, input: &mut Parser) -> Result { match try!(input.next()) { Token::Number(ref value) => { Ok(Number { @@ -245,7 +245,9 @@ pub fn parse_number(input: &mut Parser) -> Result { }) }, Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - let ast = try!(input.parse_nested_block(|i| CalcLengthOrPercentage::parse_sum(i, CalcUnit::Number))); + let ast = try!(input.parse_nested_block(|i| { + CalcLengthOrPercentage::parse_sum(context, i, CalcUnit::Number) + })); let mut result = None; @@ -298,9 +300,9 @@ impl BorderRadiusSize { impl Parse for BorderRadiusSize { #[inline] - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - let first = try!(LengthOrPercentage::parse_non_negative(input)); - let second = input.try(LengthOrPercentage::parse_non_negative) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + let first = try!(LengthOrPercentage::parse_non_negative(context, input)); + let second = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) .unwrap_or_else(|()| first.clone()); Ok(BorderRadiusSize(Size2D::new(first, second))) } @@ -428,11 +430,11 @@ impl Angle { impl Parse for Angle { /// Parses an angle according to CSS-VALUES ยง 6.1. - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { match try!(input.next()) { Token::Dimension(ref value, ref unit) => Angle::parse_dimension(value.value, unit), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - input.parse_nested_block(CalcLengthOrPercentage::parse_angle) + input.parse_nested_block(|i| CalcLengthOrPercentage::parse_angle(context, i)) }, _ => Err(()) } @@ -457,12 +459,12 @@ impl Angle { /// unitless 0 angle and stores it as '0deg'. We can remove this and /// get back to the unified version Angle::parse once /// https://github.com/w3c/csswg-drafts/issues/1162 is resolved. - pub fn parse_with_unitless(_context: &ParserContext, input: &mut Parser) -> Result { + pub fn parse_with_unitless(context: &ParserContext, input: &mut Parser) -> Result { match try!(input.next()) { Token::Dimension(ref value, ref unit) => Angle::parse_dimension(value.value, unit), Token::Number(ref value) if value.value == 0. => Ok(Angle::zero()), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { - input.parse_nested_block(CalcLengthOrPercentage::parse_angle) + input.parse_nested_block(|i| CalcLengthOrPercentage::parse_angle(context, i)) }, _ => Err(()) } @@ -485,8 +487,8 @@ pub fn parse_border_radius(context: &ParserContext, input: &mut Parser) -> Resul } #[allow(missing_docs)] -pub fn parse_border_width(input: &mut Parser) -> Result { - input.try(Length::parse_non_negative).or_else(|()| { +pub fn parse_border_width(context: &ParserContext, input: &mut Parser) -> Result { + input.try(|i| Length::parse_non_negative(context, i)).or_else(|()| { match_ignore_ascii_case! { &try!(input.expect_ident()), "thin" => Ok(Length::from_px(1.)), "medium" => Ok(Length::from_px(3.)), @@ -507,8 +509,8 @@ pub enum BorderWidth { } impl Parse for BorderWidth { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - match input.try(Length::parse_non_negative) { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + match input.try(|i| Length::parse_non_negative(context, i)) { Ok(length) => Ok(BorderWidth::Width(length)), Err(_) => match_ignore_ascii_case! { &try!(input.expect_ident()), "thin" => Ok(BorderWidth::Thin), @@ -659,13 +661,13 @@ impl ToComputedValue for Time { } impl Parse for Time { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { match input.next() { Ok(Token::Dimension(ref value, ref unit)) => { Time::parse_dimension(value.value, &unit) } Ok(Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => { - input.parse_nested_block(CalcLengthOrPercentage::parse_time) + input.parse_nested_block(|i| CalcLengthOrPercentage::parse_time(context, i)) } _ => Err(()) } @@ -700,14 +702,14 @@ pub struct Number { no_viewport_percentage!(Number); impl Parse for Number { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - parse_number(input) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + parse_number(context, input) } } impl Number { - fn parse_with_minimum(input: &mut Parser, min: CSSFloat) -> Result { - match parse_number(input) { + fn parse_with_minimum(context: &ParserContext, input: &mut Parser, min: CSSFloat) -> Result { + match parse_number(context, input) { Ok(value) if value.value >= min => Ok(value), _ => Err(()), } @@ -722,13 +724,13 @@ impl Number { } #[allow(missing_docs)] - pub fn parse_non_negative(input: &mut Parser) -> Result { - Number::parse_with_minimum(input, 0.0) + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + Number::parse_with_minimum(context, input, 0.0) } #[allow(missing_docs)] - pub fn parse_at_least_one(input: &mut Parser) -> Result { - Number::parse_with_minimum(input, 1.0) + pub fn parse_at_least_one(context: &ParserContext, input: &mut Parser) -> Result { + Number::parse_with_minimum(context, input, 1.0) } } @@ -775,12 +777,12 @@ pub enum NumberOrPercentage { no_viewport_percentage!(NumberOrPercentage); impl Parse for NumberOrPercentage { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { if let Ok(per) = input.try(Percentage::parse_non_negative) { return Ok(NumberOrPercentage::Percentage(per)); } - Number::parse_non_negative(input).map(NumberOrPercentage::Number) + Number::parse_non_negative(context, input).map(NumberOrPercentage::Number) } } @@ -801,8 +803,8 @@ pub struct Opacity(Number); no_viewport_percentage!(Opacity); impl Parse for Opacity { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - parse_number(input).map(Opacity) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + parse_number(context, input).map(Opacity) } } @@ -860,27 +862,27 @@ impl Integer { no_viewport_percentage!(Integer); impl Parse for Integer { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - parse_integer(input) + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + parse_integer(context, input) } } impl Integer { - fn parse_with_minimum(input: &mut Parser, min: i32) -> Result { - match parse_integer(input) { + fn parse_with_minimum(context: &ParserContext, input: &mut Parser, min: i32) -> Result { + match parse_integer(context, input) { Ok(value) if value.value() >= min => Ok(value), _ => Err(()), } } #[allow(missing_docs)] - pub fn parse_non_negative(input: &mut Parser) -> Result { - Integer::parse_with_minimum(input, 0) + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { + Integer::parse_with_minimum(context, input, 0) } #[allow(missing_docs)] - pub fn parse_positive(input: &mut Parser) -> Result { - Integer::parse_with_minimum(input, 1) + pub fn parse_positive(context: &ParserContext, input: &mut Parser) -> Result { + Integer::parse_with_minimum(context, input, 1) } } @@ -990,7 +992,7 @@ impl ToComputedValue for Shadow { impl Shadow { // disable_spread_and_inset is for filter: drop-shadow(...) #[allow(missing_docs)] - pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result { + pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result { let mut lengths = [Length::zero(), Length::zero(), Length::zero(), Length::zero()]; let mut lengths_parsed = false; let mut color = None; @@ -1007,7 +1009,7 @@ impl Shadow { if let Ok(value) = input.try(|i| Length::parse(context, i)) { lengths[0] = value; lengths[1] = try!(Length::parse(context, input)); - if let Ok(value) = input.try(|i| Length::parse_non_negative(i)) { + if let Ok(value) = input.try(|i| Length::parse_non_negative(context, i)) { lengths[2] = value; if !disable_spread_and_inset { if let Ok(value) = input.try(|i| Length::parse(context, i)) { @@ -1204,14 +1206,14 @@ pub type LengthOrPercentageOrNumber = Either; impl LengthOrPercentageOrNumber { /// parse a | enforcing that the contents aren't negative - pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result { + pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result { // NB: Parse numbers before Lengths so we are consistent about how to // recognize and serialize "0". - if let Ok(num) = input.try(Number::parse_non_negative) { + if let Ok(num) = input.try(|i| Number::parse_non_negative(context, i)) { return Ok(Either::Second(num)) } - LengthOrPercentage::parse_non_negative(input).map(Either::First) + LengthOrPercentage::parse_non_negative(context, input).map(Either::First) } } diff --git a/components/style/viewport.rs b/components/style/viewport.rs index 20266bae5e5..4c05ff52107 100644 --- a/components/style/viewport.rs +++ b/components/style/viewport.rs @@ -166,10 +166,10 @@ impl FromMeta for ViewportLength { } impl ViewportLength { - fn parse(input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { // we explicitly do not accept 'extend-to-zoom', since it is a UA // internal value for viewport translation - LengthOrPercentageOrAuto::parse_non_negative(input).map(ViewportLength::Specified) + LengthOrPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified) } } @@ -245,9 +245,9 @@ impl ToCss for ViewportDescriptorDeclaration { } } -fn parse_shorthand(input: &mut Parser) -> Result<(ViewportLength, ViewportLength), ()> { - let min = try!(ViewportLength::parse(input)); - match input.try(ViewportLength::parse) { +fn parse_shorthand(context: &ParserContext, input: &mut Parser) -> Result<(ViewportLength, ViewportLength), ()> { + let min = try!(ViewportLength::parse(context, input)); + match input.try(|i| ViewportLength::parse(context, i)) { Err(()) => Ok((min.clone(), min)), Ok(max) => Ok((min, max)) } @@ -263,7 +263,7 @@ impl<'a, 'b> DeclarationParser for ViewportRuleParser<'a, 'b> { fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result, ()> { macro_rules! declaration { - ($declaration:ident($parse:path)) => { + ($declaration:ident($parse:expr)) => { declaration!($declaration(value: try!($parse(input)), important: input.try(parse_important).is_ok())) }; @@ -276,11 +276,11 @@ impl<'a, 'b> DeclarationParser for ViewportRuleParser<'a, 'b> { } macro_rules! ok { - ($declaration:ident($parse:path)) => { + ($declaration:ident($parse:expr)) => { Ok(vec![declaration!($declaration($parse))]) }; (shorthand -> [$min:ident, $max:ident]) => {{ - let shorthand = try!(parse_shorthand(input)); + let shorthand = try!(parse_shorthand(self.context, input)); let important = input.try(parse_important).is_ok(); Ok(vec![declaration!($min(value: shorthand.0, important: important)), @@ -289,11 +289,11 @@ impl<'a, 'b> DeclarationParser for ViewportRuleParser<'a, 'b> { } match_ignore_ascii_case! { name, - "min-width" => ok!(MinWidth(ViewportLength::parse)), - "max-width" => ok!(MaxWidth(ViewportLength::parse)), + "min-width" => ok!(MinWidth(|i| ViewportLength::parse(self.context, i))), + "max-width" => ok!(MaxWidth(|i| ViewportLength::parse(self.context, i))), "width" => ok!(shorthand -> [MinWidth, MaxWidth]), - "min-height" => ok!(MinHeight(ViewportLength::parse)), - "max-height" => ok!(MaxHeight(ViewportLength::parse)), + "min-height" => ok!(MinHeight(|i| ViewportLength::parse(self.context, i))), + "max-height" => ok!(MaxHeight(|i| ViewportLength::parse(self.context, i))), "height" => ok!(shorthand -> [MinHeight, MaxHeight]), "zoom" => ok!(Zoom(Zoom::parse)), "min-zoom" => ok!(MinZoom(Zoom::parse)), diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index f4867e2b292..b706c4b8f71 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1166,8 +1166,11 @@ pub extern "C" fn Servo_MediaList_GetText(list: RawServoMediaListBorrowed, resul pub extern "C" fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed, text: *const nsACString) { let text = unsafe { text.as_ref().unwrap().as_str_unchecked() }; let mut parser = Parser::new(&text); - write_locked_arc(list, |list: &mut MediaList| { - *list = parse_media_query_list(&mut parser); + let url_data = unsafe { dummy_url_data() }; + let reporter = StdoutErrorReporter; + let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media)); + write_locked_arc(list, |list: &mut MediaList| { + *list = parse_media_query_list(&context, &mut parser); }) } @@ -1193,8 +1196,11 @@ pub extern "C" fn Servo_MediaList_GetMediumAt(list: RawServoMediaListBorrowed, i pub extern "C" fn Servo_MediaList_AppendMedium(list: RawServoMediaListBorrowed, new_medium: *const nsACString) { let new_medium = unsafe { new_medium.as_ref().unwrap().as_str_unchecked() }; + let url_data = unsafe { dummy_url_data() }; + let reporter = StdoutErrorReporter; + let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media)); write_locked_arc(list, |list: &mut MediaList| { - list.append_medium(new_medium); + list.append_medium(&context, new_medium); }) } @@ -1202,7 +1208,10 @@ pub extern "C" fn Servo_MediaList_AppendMedium(list: RawServoMediaListBorrowed, pub extern "C" fn Servo_MediaList_DeleteMedium(list: RawServoMediaListBorrowed, old_medium: *const nsACString) -> bool { let old_medium = unsafe { old_medium.as_ref().unwrap().as_str_unchecked() }; - write_locked_arc(list, |list: &mut MediaList| list.delete_medium(old_medium)) + let url_data = unsafe { dummy_url_data() }; + let reporter = StdoutErrorReporter; + let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media)); + write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium)) } macro_rules! get_longhand_from_id { diff --git a/tests/unit/style/value.rs b/tests/unit/style/value.rs index 4214b5ef1b5..d81d987a3cc 100644 --- a/tests/unit/style/value.rs +++ b/tests/unit/style/value.rs @@ -4,6 +4,9 @@ use app_units::Au; use cssparser::Parser; +use media_queries::CSSErrorReporterTest; +use style::parser::ParserContext; +use style::stylesheets::{CssRuleType, Origin}; use style::values::HasViewportPercentage; use style::values::specified::{AbsoluteLength, ViewportPercentageLength, NoCalcLength}; use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit}; @@ -19,8 +22,11 @@ fn length_has_viewport_percentage() { #[test] fn calc_top_level_number_with_unit() { fn parse(text: &str, unit: CalcUnit) -> Result { + let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); + let reporter = CSSErrorReporterTest; + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); let mut parser = Parser::new(text); - CalcLengthOrPercentage::parse(&mut parser, unit) + CalcLengthOrPercentage::parse(&context, &mut parser, unit) } assert_eq!(parse("1", CalcUnit::Length), Err(())); assert_eq!(parse("1", CalcUnit::LengthOrPercentage), Err(())); From 925af6c3f83a9190203db6336db1adb03c92d009 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 11 Apr 2017 16:25:05 +0800 Subject: [PATCH 5/5] Disable viewport units in @page rules Gecko disables viewport units in @page rules (bug 811391). This makes the same change in Servo. MozReview-Commit-ID: 3KGiLGn619G --- components/style/values/specified/length.rs | 32 +++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 48059b04584..1a509ea06a0 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -16,6 +16,7 @@ use std::ascii::AsciiExt; use std::ops::Mul; use style_traits::ToCss; use style_traits::values::specified::AllowedNumericType; +use stylesheets::CssRuleType; use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time, ToComputedValue}; use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal}; use values::ExtremumLength; @@ -373,7 +374,8 @@ impl Mul for NoCalcLength { impl NoCalcLength { /// Parse a given absolute or relative dimension. - pub fn parse_dimension(_context: &ParserContext, value: CSSFloat, unit: &str) -> Result { + pub fn parse_dimension(context: &ParserContext, value: CSSFloat, unit: &str) -> Result { + let in_page_rule = context.rule_type.map_or(false, |rule_type| rule_type == CssRuleType::Page); match_ignore_ascii_case! { unit, "px" => Ok(NoCalcLength::Absolute(AbsoluteLength::Px(value))), "in" => Ok(NoCalcLength::Absolute(AbsoluteLength::In(value))), @@ -388,10 +390,30 @@ impl NoCalcLength { "ch" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Ch(value))), "rem" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Rem(value))), // viewport percentages - "vw" => Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value))), - "vh" => Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value))), - "vmin" => Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value))), - "vmax" => Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value))), + "vw" => { + if in_page_rule { + return Err(()) + } + Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value))) + }, + "vh" => { + if in_page_rule { + return Err(()) + } + Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value))) + }, + "vmin" => { + if in_page_rule { + return Err(()) + } + Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value))) + }, + "vmax" => { + if in_page_rule { + return Err(()) + } + Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value))) + }, _ => Err(()) } }