aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Ryan Stinnett <jryans@gmail.com>2017-04-11 16:00:37 +0800
committerJ. Ryan Stinnett <jryans@gmail.com>2017-04-12 16:40:48 +0800
commit1a31b87c22adbd2b7a7350500e089fad3fa49453 (patch)
treeec991601022825c1534b2d7a265c735febfef067
parent1ae1d370f23d5b74902a1f7dc87421e516b5ac2e (diff)
downloadservo-1a31b87c22adbd2b7a7350500e089fad3fa49453.tar.gz
servo-1a31b87c22adbd2b7a7350500e089fad3fa49453.zip
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
-rw-r--r--components/script/dom/cssmediarule.rs8
-rw-r--r--components/script/dom/htmllinkelement.rs12
-rw-r--r--components/script/dom/htmlstyleelement.rs12
-rw-r--r--components/script/dom/medialist.rs22
-rw-r--r--components/script/dom/window.rs6
-rw-r--r--components/style/gecko/media_queries.rs5
-rw-r--r--components/style/media_queries.rs21
-rw-r--r--components/style/properties/longhand/background.mako.rs6
-rw-r--r--components/style/properties/longhand/border.mako.rs6
-rw-r--r--components/style/properties/longhand/box.mako.rs44
-rw-r--r--components/style/properties/longhand/counters.mako.rs14
-rw-r--r--components/style/properties/longhand/effects.mako.rs2
-rw-r--r--components/style/properties/longhand/font.mako.rs8
-rw-r--r--components/style/properties/longhand/inherited_svg.mako.rs3
-rw-r--r--components/style/properties/longhand/inherited_table.mako.rs6
-rw-r--r--components/style/properties/longhand/inherited_text.mako.rs6
-rw-r--r--components/style/properties/longhand/outline.mako.rs4
-rw-r--r--components/style/properties/longhand/padding.mako.rs1
-rw-r--r--components/style/properties/longhand/position.mako.rs6
-rw-r--r--components/style/properties/longhand/text.mako.rs2
-rw-r--r--components/style/properties/longhand/xul.mako.rs2
-rw-r--r--components/style/properties/shorthand/position.mako.rs8
-rw-r--r--components/style/servo/media_queries.rs9
-rw-r--r--components/style/stylesheets.rs4
-rw-r--r--components/style/values/specified/basic_shape.rs20
-rw-r--r--components/style/values/specified/grid.rs6
-rw-r--r--components/style/values/specified/length.rs177
-rw-r--r--components/style/values/specified/mod.rs86
-rw-r--r--components/style/viewport.rs24
-rw-r--r--ports/geckolib/glue.rs17
-rw-r--r--tests/unit/style/value.rs8
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<String>) {
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<MediaQueryList> {
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<Self, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<MediaQuery>
+ pub media_queries: Vec<MediaQuery>,
}
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<MediaQuery, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<MediaQuery, ()> {
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<SpecifiedValue,()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
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<SpecifiedValue, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
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<SpecifiedValue, ()> {
- parse_common(1, input)
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
+ parse_common(context, 1, input)
}
- pub fn parse_common(default_value: i32, input: &mut Parser) -> Result<SpecifiedValue, ()> {
+ pub fn parse_common(context: &ParserContext, default_value: i32, input: &mut Parser) -> Result<SpecifiedValue, ()> {
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<SpecifiedValue,()> {
- parse_common(0, input)
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
+ parse_common(context, 0, input)
}
</%helpers:longhand>
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",
}
}
/// <length> | <percentage> | <absolute-size> | <relative-size>
- pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
- if let Ok(lop) = input.try(specified::LengthOrPercentage::parse_non_negative) {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
+ 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 | <number>
- pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
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))))
}
</%helpers:longhand>
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<SpecifiedValue,()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
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 | <number> | <length> | <percentage>
- pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
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<SpecifiedValue, ()> {
- specified::parse_border_width(input).map(SpecifiedValue)
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
+ 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<Number>),()> {
- 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<Self, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<AtRuleType<AtRulePrelude, CssRule>, ()> {
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<Self, ()> {
- input.try(|i| LengthOrPercentage::parse_non_negative(i)).map(ShapeRadius::Length).or_else(|_| {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<Self, ()> {
- let mut widths = try!(parse_one_set_of_border_values(input));
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<CSSFloat, ()> {
}
impl Parse for TrackBreadth<LengthOrPercentage> {
- fn parse(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
- if let Ok(lop) = input.try(LengthOrPercentage::parse_non_negative) {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<LengthOrPercentage> {
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<CSSFloat> for NoCalcLength {
impl NoCalcLength {
/// Parse a given absolute or relative dimension.
- pub fn parse_dimension(value: CSSFloat, unit: &str) -> Result<NoCalcLength, ()> {
+ pub fn parse_dimension(_context: &ParserContext, value: CSSFloat, unit: &str) -> Result<NoCalcLength, ()> {
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<Length, ()> {
- NoCalcLength::parse_dimension(value, unit).map(Length::NoCalc)
+ pub fn parse_dimension(context: &ParserContext, value: CSSFloat, unit: &str) -> Result<Length, ()> {
+ NoCalcLength::parse_dimension(context, value, unit).map(Length::NoCalc)
}
#[inline]
- fn parse_internal(input: &mut Parser, context: AllowedNumericType) -> Result<Length, ()> {
+ fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedNumericType)
+ -> Result<Length, ()> {
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<Length, ()> {
- Self::parse_internal(input, AllowedNumericType::NonNegative)
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> {
+ 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, ()> {
- Self::parse_internal(input, AllowedNumericType::All)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ Self::parse_internal(context, input, AllowedNumericType::All)
}
}
@@ -564,7 +565,7 @@ impl Either<Length, None_> {
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<Length, Normal> {
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<Length, Auto> {
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<CalcSumNode, ()> {
+ pub fn parse_sum(context: &ParserContext, input: &mut Parser, expected_unit: CalcUnit) -> Result<CalcSumNode, ()> {
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<CalcProductNode, ()> {
+ fn parse_product(context: &ParserContext, input: &mut Parser, expected_unit: CalcUnit)
+ -> Result<CalcProductNode, ()> {
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<CalcValueNode, ()> {
+ fn parse_value(context: &ParserContext, input: &mut Parser, expected_unit: CalcUnit) -> Result<CalcValueNode, ()> {
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<Length, ()> {
- 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<Length, ()> {
+ 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, ()> {
- CalcLengthOrPercentage::parse(input, CalcUnit::LengthOrPercentage)
+ fn parse_length_or_percentage(context: &ParserContext, input: &mut Parser) -> Result<CalcLengthOrPercentage, ()> {
+ 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<CalcLengthOrPercentage, ()> {
- 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<Time, ()> {
- let ast = try!(CalcLengthOrPercentage::parse_sum(input, CalcUnit::Time));
+ pub fn parse_time(context: &ParserContext, input: &mut Parser) -> Result<Time, ()> {
+ 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<Angle, ()> {
- let ast = try!(CalcLengthOrPercentage::parse_sum(input, CalcUnit::Angle));
+ pub fn parse_angle(context: &ParserContext, input: &mut Parser) -> Result<Angle, ()> {
+ 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<LengthOrPercentage, ()>
{
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<LengthOrPercentage, ()> {
- Self::parse_internal(input, AllowedNumericType::NonNegative)
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> {
+ 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<LengthOrPercentage, ()> {
- 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<LengthOrPercentage, ()> {
+ 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<LengthOrPercentage, ()> {
- 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<LengthOrPercentage, ()> {
+ 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, ()> {
- Self::parse_internal(input, AllowedNumericType::All)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<Self, ()> {
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<LengthOrPercentageOrAuto, ()> {
- Self::parse_internal(input, AllowedNumericType::NonNegative)
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> {
+ 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, ()> {
- Self::parse_internal(input, AllowedNumericType::All)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<LengthOrPercentageOrNone, ()>
{
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, ()> {
- Self::parse_internal(input, AllowedNumericType::NonNegative)
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ Self::parse_internal(context, input, AllowedNumericType::NonNegative)
}
}
impl Parse for LengthOrPercentageOrNone {
#[inline]
- fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
- Self::parse_internal(input, AllowedNumericType::All)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<Self, ()> {
- let context = AllowedNumericType::NonNegative;
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<Length, Number>;
impl LengthOrNumber {
/// Parse a non-negative LengthOrNumber.
- pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
// 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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<CSSFloat> for &'a SimplifiedValueNode {
}
#[allow(missing_docs)]
-pub fn parse_integer(input: &mut Parser) -> Result<Integer, ()> {
+pub fn parse_integer(context: &ParserContext, input: &mut Parser) -> Result<Integer, ()> {
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<Integer, ()> {
}
#[allow(missing_docs)]
-pub fn parse_number(input: &mut Parser) -> Result<Number, ()> {
+pub fn parse_number(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
match try!(input.next()) {
Token::Number(ref value) => {
Ok(Number {
@@ -245,7 +245,9 @@ pub fn parse_number(input: &mut Parser) -> Result<Number, ()> {
})
},
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<Self, ()> {
- let first = try!(LengthOrPercentage::parse_non_negative(input));
- let second = input.try(LengthOrPercentage::parse_non_negative)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<Self, ()> {
+ pub fn parse_with_unitless(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<Length, ()> {
- input.try(Length::parse_non_negative).or_else(|()| {
+pub fn parse_border_width(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> {
+ 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<BorderWidth, ()> {
- match input.try(Length::parse_non_negative) {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<BorderWidth, ()> {
+ 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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<Self, ()> {
- parse_number(input)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ parse_number(context, input)
}
}
impl Number {
- fn parse_with_minimum(input: &mut Parser, min: CSSFloat) -> Result<Number, ()> {
- match parse_number(input) {
+ fn parse_with_minimum(context: &ParserContext, input: &mut Parser, min: CSSFloat) -> Result<Number, ()> {
+ 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, ()> {
- Number::parse_with_minimum(input, 0.0)
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
+ Number::parse_with_minimum(context, input, 0.0)
}
#[allow(missing_docs)]
- pub fn parse_at_least_one(input: &mut Parser) -> Result<Number, ()> {
- Number::parse_with_minimum(input, 1.0)
+ pub fn parse_at_least_one(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
+ 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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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<Self, ()> {
- parse_number(input).map(Opacity)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ 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<Self, ()> {
- parse_integer(input)
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ parse_integer(context, input)
}
}
impl Integer {
- fn parse_with_minimum(input: &mut Parser, min: i32) -> Result<Integer, ()> {
- match parse_integer(input) {
+ fn parse_with_minimum(context: &ParserContext, input: &mut Parser, min: i32) -> Result<Integer, ()> {
+ 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, ()> {
- Integer::parse_with_minimum(input, 0)
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Integer, ()> {
+ Integer::parse_with_minimum(context, input, 0)
}
#[allow(missing_docs)]
- pub fn parse_positive(input: &mut Parser) -> Result<Integer, ()> {
- Integer::parse_with_minimum(input, 1)
+ pub fn parse_positive(context: &ParserContext, input: &mut Parser) -> Result<Integer, ()> {
+ 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<Shadow, ()> {
+ pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result<Shadow, ()> {
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<LengthOrPercentage, Number>;
impl LengthOrPercentageOrNumber {
/// parse a <length-percentage> | <number> enforcing that the contents aren't negative
- pub fn parse_non_negative(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
// 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<Self, ()> {
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
// we explicitly do not accept 'extend-to-zoom', since it is a UA
// internal value for <META> 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<Vec<ViewportDescriptorDeclaration>, ()> {
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<CalcLengthOrPercentage, ()> {
+ 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(()));