Auto merge of #16373 - jryans:at-page-viewport-units, r=emilio

Stylo: Disable viewport units for @page

Reviewed by @emilio in [bug 1353191](https://bugzilla.mozilla.org/show_bug.cgi?id=1353191).

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16373)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-12 05:38:50 -05:00 committed by GitHub
commit 5f6c27bb94
63 changed files with 472 additions and 360 deletions

View file

@ -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

View file

@ -16,8 +16,9 @@ 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::MediaRule;
use style::stylesheets::{CssRuleType, MediaRule};
use style_traits::ToCss;
#[dom_struct]
@ -68,7 +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 new_medialist = parse_media_query_list(&mut input);
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(&context, &mut input);
let mut guard = self.cssconditionrule.shared_lock().write();
// Clone an Arc because we cant borrow `guard` twice at the same time.

View file

@ -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);

View file

@ -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>) {

View file

@ -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());

View file

@ -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;

View file

@ -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);

View file

@ -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()?;

View file

@ -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<Self::QualifiedRule, ()> {
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<ParsedDeclaration, ()> {
let id = try!(PropertyId::parse(name.into()));
match ParsedDeclaration::parse(id, self.context, input, true, CssRuleType::Keyframe) {
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() {

View file

@ -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; }
};

View file

@ -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<CssRuleType>,
}
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<CssRuleType>)
-> 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<CssRuleType>)
-> 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<CssRuleType>)
-> 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.")
}
}

View file

@ -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<ParsedDeclaration, ()> {
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)
.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)
.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() {

View file

@ -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 {

View file

@ -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))
}
}

View file

@ -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(())
}))

View file

@ -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>

View file

@ -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),

View file

@ -681,8 +681,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))
}
@ -788,14 +788,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>

View file

@ -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

View file

@ -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);
}
}

View file

@ -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))
}

View file

@ -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 {

View file

@ -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)}

View file

@ -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

View file

@ -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) => {

View file

@ -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",

View file

@ -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 => {
@ -976,9 +976,9 @@ 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, rule_type: CssRuleType)
pub fn parse(id: PropertyId, context: &ParserContext, input: &mut Parser)
-> Result<ParsedDeclaration, PropertyDeclarationParseError> {
let rule_type = context.rule_type();
debug_assert!(rule_type == CssRuleType::Keyframe ||
rule_type == CssRuleType::Page ||
rule_type == CssRuleType::Style,
@ -999,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
@ -1032,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

View file

@ -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

View file

@ -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(())
}))

View file

@ -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),
};
@ -904,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() {
@ -1011,8 +1012,15 @@ struct NestedRuleParser<'a, 'b: 'a> {
}
impl<'a, 'b> NestedRuleParser<'a, 'b> {
fn parse_nested_rules(&self, input: &mut Parser) -> Arc<Locked<CssRules>> {
let mut iter = RuleListParser::new_for_nested_rule(input, self.clone());
fn parse_nested_rules(&self, input: &mut Parser, rule_type: CssRuleType) -> Arc<Locked<CssRules>> {
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 {
@ -1046,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)))
},
@ -1087,35 +1095,39 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
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 => {
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 +1150,8 @@ impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> {
fn parse_block(&mut self, prelude: SelectorList<SelectorImpl>, input: &mut Parser)
-> Result<CssRule, ()> {
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))

View file

@ -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);
let _ = input.try(parse_important);
res.is_ok() && input.is_exhausted()
}

View file

@ -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])

View file

@ -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));

View file

@ -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<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, ()> {
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(())
}
}
@ -512,19 +534,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 +555,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 +575,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 +587,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 +598,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 +609,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 +668,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 +681,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 +702,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 +733,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 +753,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 +834,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 +919,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 +947,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 +1145,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 +1167,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 +1188,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 +1216,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 +1270,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 +1293,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 +1310,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 +1348,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 +1371,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 +1413,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 +1428,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 +1475,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 +1522,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 +1563,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" =>

View file

@ -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)
}
}

View file

@ -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)),

View file

@ -957,9 +957,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)) {
Ok(parsed) => {
let global_style_data = &*GLOBAL_STYLE_DATA;
let mut block = PropertyDeclarationBlock::new();
@ -979,7 +979,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) => {
@ -1173,8 +1173,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);
})
}
@ -1200,8 +1203,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);
})
}
@ -1209,7 +1215,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 {
@ -1518,7 +1527,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

View file

@ -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]

View file

@ -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();

View file

@ -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;

View file

@ -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"));

View file

@ -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]

View file

@ -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());

View file

@ -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() {

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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() {

View file

@ -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"));

View file

@ -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;

View file

@ -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");

View file

@ -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<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
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()
}};
}

View file

@ -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());

View file

@ -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;

View file

@ -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<SelectorList<SelectorImpl>, ()> {
let mut ns = Namespaces::default();

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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());

View file

@ -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%"));

View file

@ -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);

View file

@ -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(()));

View file

@ -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) => {