Pass ParserContext down to lengths

To make it possible to check the rule type when parsing lengths, we need to pass
the `ParserContext` down through many layers to the place where length units are
parsed.

This change leaves it unused, so it's only to prepare for the next change.

MozReview-Commit-ID: 70YwtcCxnWw
This commit is contained in:
J. Ryan Stinnett 2017-04-11 16:00:37 +08:00
parent 1ae1d370f2
commit 1a31b87c22
31 changed files with 304 additions and 251 deletions

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