mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
servo: Merge #16454 - Stylo: SVG length parsing mode (from jryans:svg-parse-unitless); r=emilio
Reviewed by @emilio in [bug 1329088](https://bugzilla.mozilla.org/show_bug.cgi?id=1329088). r? @emilio --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors Source-Repo: https://github.com/servo/servo Source-Revision: 5c56640508b4f24a67fe92c5d3179d89d030e959 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 1f33735051b5be8d58a32eec5044f6365b6dab32
This commit is contained in:
parent
02d7482da7
commit
a498868ba9
@ -9,7 +9,7 @@ use dom::bindings::reflector::Reflector;
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{LengthParsingMode, ParserContext};
|
||||
use style::stylesheets::CssRuleType;
|
||||
use style::supports::{Declaration, parse_condition_or_declaration};
|
||||
|
||||
@ -30,7 +30,8 @@ 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(), Some(CssRuleType::Supports));
|
||||
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports),
|
||||
LengthParsingMode::Default);
|
||||
decl.eval(&context)
|
||||
}
|
||||
|
||||
@ -40,7 +41,8 @@ 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(), Some(CssRuleType::Supports));
|
||||
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports),
|
||||
LengthParsingMode::Default);
|
||||
cond.eval(&context)
|
||||
} else {
|
||||
false
|
||||
|
@ -16,7 +16,7 @@ use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use std::sync::Arc;
|
||||
use style::media_queries::parse_media_query_list;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{LengthParsingMode, ParserContext};
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::{CssRuleType, MediaRule};
|
||||
use style_traits::ToCss;
|
||||
@ -72,7 +72,8 @@ impl CSSMediaRule {
|
||||
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 context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
let new_medialist = parse_media_query_list(&context, &mut input);
|
||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||
|
||||
|
@ -18,6 +18,7 @@ use servo_url::ServoUrl;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::sync::Arc;
|
||||
use style::attr::AttrValue;
|
||||
use style::parser::LengthParsingMode;
|
||||
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
||||
use style::properties::{parse_one_declaration, parse_style_attribute};
|
||||
use style::selector_parser::PseudoElement;
|
||||
@ -257,7 +258,7 @@ impl CSSStyleDeclaration {
|
||||
let window = self.owner.window();
|
||||
let result =
|
||||
parse_one_declaration(id, &value, &self.owner.base_url(),
|
||||
window.css_error_reporter());
|
||||
window.css_error_reporter(), LengthParsingMode::Default);
|
||||
|
||||
// Step 7
|
||||
let parsed = match result {
|
||||
|
@ -14,7 +14,7 @@ use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use std::sync::Arc;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{LengthParsingMode, ParserContext};
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::{CssRuleType, SupportsRule};
|
||||
use style::supports::SupportsCondition;
|
||||
@ -61,7 +61,8 @@ 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(), Some(CssRuleType::Supports));
|
||||
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports),
|
||||
LengthParsingMode::Default);
|
||||
let enabled = cond.eval(&context);
|
||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||
let rule = self.supportsrule.write_with(&mut guard);
|
||||
|
@ -33,7 +33,7 @@ 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::parser::{LengthParsingMode, ParserContext as CssParserContext};
|
||||
use style::str::HTML_SPACE_CHARACTERS;
|
||||
use style::stylesheets::{CssRuleType, Stylesheet};
|
||||
use stylesheet_loader::{StylesheetLoader, StylesheetContextSource, StylesheetOwner};
|
||||
@ -281,7 +281,8 @@ impl HTMLLinkElement {
|
||||
let mut css_parser = CssParser::new(&mq_str);
|
||||
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 context = CssParserContext::new_for_cssom(&doc_url, win.css_error_reporter(), Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
let media = parse_media_query_list(&context, &mut css_parser);
|
||||
|
||||
let im_attribute = element.get_attribute(&ns!(), &local_name!("integrity"));
|
||||
|
@ -25,7 +25,7 @@ use script_layout_interface::message::Msg;
|
||||
use std::cell::Cell;
|
||||
use std::sync::Arc;
|
||||
use style::media_queries::parse_media_query_list;
|
||||
use style::parser::ParserContext as CssParserContext;
|
||||
use style::parser::{LengthParsingMode, ParserContext as CssParserContext};
|
||||
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
||||
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};
|
||||
|
||||
@ -87,7 +87,8 @@ impl HTMLStyleElement {
|
||||
let url = win.get_url();
|
||||
let context = CssParserContext::new_for_cssom(&url,
|
||||
win.css_error_reporter(),
|
||||
Some(CssRuleType::Media));
|
||||
Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
let shared_lock = node.owner_doc().style_shared_lock().clone();
|
||||
let mq = Arc::new(shared_lock.wrap(
|
||||
parse_media_query_list(&context, &mut CssParser::new(&mq_str))));
|
||||
|
@ -15,7 +15,7 @@ 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::parser::{LengthParsingMode, ParserContext};
|
||||
use style::shared_lock::{SharedRwLock, Locked};
|
||||
use style::stylesheets::CssRuleType;
|
||||
use style_traits::ToCss;
|
||||
@ -75,7 +75,8 @@ impl MediaListMethods for MediaList {
|
||||
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 context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
*media_queries = parse_media_query_list(&context, &mut parser);
|
||||
}
|
||||
|
||||
@ -108,7 +109,8 @@ impl MediaListMethods for MediaList {
|
||||
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 context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
let m = MediaQuery::parse(&context, &mut parser);
|
||||
// Step 2
|
||||
if let Err(_) = m {
|
||||
@ -133,7 +135,8 @@ impl MediaListMethods for MediaList {
|
||||
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 context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
let m = MediaQuery::parse(&context, &mut parser);
|
||||
// Step 2
|
||||
if let Err(_) = m {
|
||||
|
@ -105,7 +105,7 @@ 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::parser::{LengthParsingMode, ParserContext as CssParserContext};
|
||||
use style::properties::PropertyId;
|
||||
use style::properties::longhands::overflow_x;
|
||||
use style::selector_parser::PseudoElement;
|
||||
@ -972,7 +972,8 @@ impl WindowMethods for Window {
|
||||
fn MatchMedia(&self, query: DOMString) -> Root<MediaQueryList> {
|
||||
let mut parser = Parser::new(&query);
|
||||
let url = self.get_url();
|
||||
let context = CssParserContext::new_for_cssom(&url, self.css_error_reporter(), Some(CssRuleType::Media));
|
||||
let context = CssParserContext::new_for_cssom(&url, self.css_error_reporter(), Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
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);
|
||||
|
@ -467,6 +467,7 @@ mod bindings {
|
||||
"mozilla::Side",
|
||||
"mozilla::binding_danger::AssertAndSuppressCleanupPolicy",
|
||||
"RawServoAnimationValueMapBorrowed",
|
||||
"mozilla::LengthParsingMode",
|
||||
];
|
||||
let opaque_types = [
|
||||
"std::pair__PCCP",
|
||||
@ -721,6 +722,7 @@ mod bindings {
|
||||
"ServoStyleSheet",
|
||||
"EffectCompositor_CascadeLevel",
|
||||
"UpdateAnimationsTasks",
|
||||
"LengthParsingMode",
|
||||
];
|
||||
struct ArrayType {
|
||||
cpp_type: &'static str,
|
||||
|
@ -37,6 +37,9 @@
|
||||
pseudo_element!(":backdrop",
|
||||
atom!(":backdrop"),
|
||||
false);
|
||||
pseudo_element!(":cue",
|
||||
atom!(":cue"),
|
||||
false);
|
||||
pseudo_element!(":first-letter",
|
||||
atom!(":first-letter"),
|
||||
false);
|
||||
|
@ -188,6 +188,7 @@ use gecko_bindings::structs::Loader;
|
||||
use gecko_bindings::structs::ServoStyleSheet;
|
||||
use gecko_bindings::structs::EffectCompositor_CascadeLevel;
|
||||
use gecko_bindings::structs::UpdateAnimationsTasks;
|
||||
use gecko_bindings::structs::LengthParsingMode;
|
||||
pub type nsTArrayBorrowed_uintptr_t<'a> = &'a mut ::gecko_bindings::structs::nsTArray<usize>;
|
||||
pub type ServoCssRulesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoCssRules>;
|
||||
pub type ServoCssRulesBorrowed<'a> = &'a ServoCssRules;
|
||||
@ -1817,8 +1818,9 @@ extern "C" {
|
||||
property: *const nsACString,
|
||||
value: *const nsACString,
|
||||
is_important: bool,
|
||||
data: *mut RawGeckoURLExtraData)
|
||||
-> bool;
|
||||
data: *mut RawGeckoURLExtraData,
|
||||
length_parsing_mode:
|
||||
LengthParsingMode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_DeclarationBlock_SetPropertyById(declarations:
|
||||
@ -1827,7 +1829,9 @@ extern "C" {
|
||||
value: *const nsACString,
|
||||
is_important: bool,
|
||||
data:
|
||||
*mut RawGeckoURLExtraData)
|
||||
*mut RawGeckoURLExtraData,
|
||||
length_parsing_mode:
|
||||
LengthParsingMode)
|
||||
-> bool;
|
||||
}
|
||||
extern "C" {
|
||||
|
@ -6126,6 +6126,13 @@ pub mod root {
|
||||
"Alignment of field: " , stringify ! ( URLExtraData )
|
||||
, "::" , stringify ! ( mPrincipal ) ));
|
||||
}
|
||||
pub mod dmd {
|
||||
#[allow(unused_imports)]
|
||||
use self::super::super::super::root;
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct JSONWriteFunc([u8; 0]);
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ArenaObjectID {
|
||||
@ -6653,6 +6660,9 @@ pub mod root {
|
||||
root::mozilla::UpdateAnimationsTasks =
|
||||
8;
|
||||
pub type UpdateAnimationsTasks = u8;
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum LengthParsingMode { Default = 0, SVG = 1, }
|
||||
pub type CSSPseudoElementTypeBase = u8;
|
||||
pub const CSSPseudoElementType_InheritingAnonBox:
|
||||
root::mozilla::CSSPseudoElementType =
|
||||
|
@ -6029,6 +6029,13 @@ pub mod root {
|
||||
"Alignment of field: " , stringify ! ( URLExtraData )
|
||||
, "::" , stringify ! ( mPrincipal ) ));
|
||||
}
|
||||
pub mod dmd {
|
||||
#[allow(unused_imports)]
|
||||
use self::super::super::super::root;
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct JSONWriteFunc([u8; 0]);
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ArenaObjectID {
|
||||
@ -6556,6 +6563,9 @@ pub mod root {
|
||||
root::mozilla::UpdateAnimationsTasks =
|
||||
8;
|
||||
pub type UpdateAnimationsTasks = u8;
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum LengthParsingMode { Default = 0, SVG = 1, }
|
||||
pub type CSSPseudoElementTypeBase = u8;
|
||||
pub const CSSPseudoElementType_InheritingAnonBox:
|
||||
root::mozilla::CSSPseudoElementType =
|
||||
|
@ -4790,6 +4790,8 @@ cfg_if! {
|
||||
pub static nsCSSPseudoElements_before: *mut nsICSSPseudoElement;
|
||||
#[link_name = "_ZN19nsCSSPseudoElements8backdropE"]
|
||||
pub static nsCSSPseudoElements_backdrop: *mut nsICSSPseudoElement;
|
||||
#[link_name = "_ZN19nsCSSPseudoElements3cueE"]
|
||||
pub static nsCSSPseudoElements_cue: *mut nsICSSPseudoElement;
|
||||
#[link_name = "_ZN19nsCSSPseudoElements11firstLetterE"]
|
||||
pub static nsCSSPseudoElements_firstLetter: *mut nsICSSPseudoElement;
|
||||
#[link_name = "_ZN19nsCSSPseudoElements9firstLineE"]
|
||||
@ -9721,6 +9723,8 @@ cfg_if! {
|
||||
pub static nsCSSPseudoElements_before: *mut nsICSSPseudoElement;
|
||||
#[link_name = "?backdrop@nsCSSPseudoElements@@2PEAVnsICSSPseudoElement@@EA"]
|
||||
pub static nsCSSPseudoElements_backdrop: *mut nsICSSPseudoElement;
|
||||
#[link_name = "?cue@nsCSSPseudoElements@@2PEAVnsICSSPseudoElement@@EA"]
|
||||
pub static nsCSSPseudoElements_cue: *mut nsICSSPseudoElement;
|
||||
#[link_name = "?firstLetter@nsCSSPseudoElements@@2PEAVnsICSSPseudoElement@@EA"]
|
||||
pub static nsCSSPseudoElements_firstLetter: *mut nsICSSPseudoElement;
|
||||
#[link_name = "?firstLine@nsCSSPseudoElements@@2PEAVnsICSSPseudoElement@@EA"]
|
||||
@ -14652,6 +14656,8 @@ cfg_if! {
|
||||
pub static nsCSSPseudoElements_before: *mut nsICSSPseudoElement;
|
||||
#[link_name = "\x01?backdrop@nsCSSPseudoElements@@2PAVnsICSSPseudoElement@@A"]
|
||||
pub static nsCSSPseudoElements_backdrop: *mut nsICSSPseudoElement;
|
||||
#[link_name = "\x01?cue@nsCSSPseudoElements@@2PAVnsICSSPseudoElement@@A"]
|
||||
pub static nsCSSPseudoElements_cue: *mut nsICSSPseudoElement;
|
||||
#[link_name = "\x01?firstLetter@nsCSSPseudoElements@@2PAVnsICSSPseudoElement@@A"]
|
||||
pub static nsCSSPseudoElements_firstLetter: *mut nsICSSPseudoElement;
|
||||
#[link_name = "\x01?firstLine@nsCSSPseudoElements@@2PAVnsICSSPseudoElement@@A"]
|
||||
@ -19586,6 +19592,8 @@ macro_rules! atom {
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsCSSPseudoElements_before as *mut _) } };
|
||||
(":backdrop") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsCSSPseudoElements_backdrop as *mut _) } };
|
||||
(":cue") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsCSSPseudoElements_cue as *mut _) } };
|
||||
(":first-letter") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsCSSPseudoElements_firstLetter as *mut _) } };
|
||||
(":first-line") =>
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser};
|
||||
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule};
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use parser::{LengthParsingMode, ParserContext, log_css_error};
|
||||
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
||||
use properties::{PropertyDeclarationId, LonghandId, ParsedDeclaration};
|
||||
use properties::LonghandIdSet;
|
||||
@ -129,7 +129,8 @@ impl Keyframe {
|
||||
let context = ParserContext::new(parent_stylesheet.origin,
|
||||
&parent_stylesheet.url_data,
|
||||
&error_reporter,
|
||||
Some(CssRuleType::Keyframe));
|
||||
Some(CssRuleType::Keyframe),
|
||||
LengthParsingMode::Default);
|
||||
let mut input = Parser::new(css);
|
||||
|
||||
let mut rule_parser = KeyframeListParser {
|
||||
|
@ -11,6 +11,24 @@ use error_reporting::ParseErrorReporter;
|
||||
use style_traits::OneOrMoreCommaSeparated;
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
|
||||
/// The mode to use when parsing lengths.
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub enum LengthParsingMode {
|
||||
/// In CSS, lengths must have units, except for zero values, where the unit can be omitted.
|
||||
/// https://www.w3.org/TR/css3-values/#lengths
|
||||
Default,
|
||||
/// In SVG, a coordinate or length value without a unit identifier (e.g., "25") is assumed to be in user units (px).
|
||||
/// https://www.w3.org/TR/SVG/coords.html#Units
|
||||
SVG,
|
||||
}
|
||||
|
||||
impl LengthParsingMode {
|
||||
/// Whether the parsing mode allows unitless lengths for non-zero values to be intpreted as px.
|
||||
pub fn allows_unitless_lengths(&self) -> bool {
|
||||
*self == LengthParsingMode::SVG
|
||||
}
|
||||
}
|
||||
|
||||
/// The data that the parser needs from outside in order to parse a stylesheet.
|
||||
pub struct ParserContext<'a> {
|
||||
/// The `Origin` of the stylesheet, whether it's a user, author or
|
||||
@ -22,8 +40,10 @@ pub struct ParserContext<'a> {
|
||||
pub error_reporter: &'a ParseErrorReporter,
|
||||
/// The current rule type, if any.
|
||||
pub rule_type: Option<CssRuleType>,
|
||||
/// line number offsets for inline stylesheets
|
||||
/// Line number offsets for inline stylesheets
|
||||
pub line_number_offset: u64,
|
||||
/// The mode to use when parsing lengths.
|
||||
pub length_parsing_mode: LengthParsingMode,
|
||||
}
|
||||
|
||||
impl<'a> ParserContext<'a> {
|
||||
@ -31,7 +51,8 @@ impl<'a> ParserContext<'a> {
|
||||
pub fn new(stylesheet_origin: Origin,
|
||||
url_data: &'a UrlExtraData,
|
||||
error_reporter: &'a ParseErrorReporter,
|
||||
rule_type: Option<CssRuleType>)
|
||||
rule_type: Option<CssRuleType>,
|
||||
length_parsing_mode: LengthParsingMode)
|
||||
-> ParserContext<'a> {
|
||||
ParserContext {
|
||||
stylesheet_origin: stylesheet_origin,
|
||||
@ -39,15 +60,17 @@ impl<'a> ParserContext<'a> {
|
||||
error_reporter: error_reporter,
|
||||
rule_type: rule_type,
|
||||
line_number_offset: 0u64,
|
||||
length_parsing_mode: length_parsing_mode,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a parser context for on-the-fly parsing in CSSOM
|
||||
pub fn new_for_cssom(url_data: &'a UrlExtraData,
|
||||
error_reporter: &'a ParseErrorReporter,
|
||||
rule_type: Option<CssRuleType>)
|
||||
rule_type: Option<CssRuleType>,
|
||||
length_parsing_mode: LengthParsingMode)
|
||||
-> ParserContext<'a> {
|
||||
Self::new(Origin::Author, url_data, error_reporter, rule_type)
|
||||
Self::new(Origin::Author, url_data, error_reporter, rule_type, length_parsing_mode)
|
||||
}
|
||||
|
||||
/// Create a parser context based on a previous context, but with a modified rule type.
|
||||
@ -60,19 +83,16 @@ impl<'a> ParserContext<'a> {
|
||||
error_reporter: context.error_reporter,
|
||||
rule_type: rule_type,
|
||||
line_number_offset: context.line_number_offset,
|
||||
length_parsing_mode: context.length_parsing_mode,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.")
|
||||
}
|
||||
|
||||
/// Create a parser context for inline CSS which accepts additional line offset argument.
|
||||
pub fn new_with_line_number_offset(stylesheet_origin: Origin,
|
||||
url_data: &'a UrlExtraData,
|
||||
error_reporter: &'a ParseErrorReporter,
|
||||
line_number_offset: u64)
|
||||
line_number_offset: u64,
|
||||
length_parsing_mode: LengthParsingMode)
|
||||
-> ParserContext<'a> {
|
||||
ParserContext {
|
||||
stylesheet_origin: stylesheet_origin,
|
||||
@ -80,8 +100,14 @@ impl<'a> ParserContext<'a> {
|
||||
error_reporter: error_reporter,
|
||||
rule_type: None,
|
||||
line_number_offset: line_number_offset,
|
||||
length_parsing_mode: length_parsing_mode,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Defaults to a no-op.
|
||||
|
@ -9,7 +9,7 @@
|
||||
use cssparser::{DeclarationListParser, parse_important};
|
||||
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
||||
use error_reporting::ParseErrorReporter;
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use parser::{LengthParsingMode, ParserContext, log_css_error};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
@ -617,7 +617,11 @@ pub fn parse_style_attribute(input: &str,
|
||||
url_data: &UrlExtraData,
|
||||
error_reporter: &ParseErrorReporter)
|
||||
-> PropertyDeclarationBlock {
|
||||
let context = ParserContext::new(Origin::Author, url_data, error_reporter, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new(Origin::Author,
|
||||
url_data,
|
||||
error_reporter,
|
||||
Some(CssRuleType::Style),
|
||||
LengthParsingMode::Default);
|
||||
parse_property_declaration_list(&context, &mut Parser::new(input))
|
||||
}
|
||||
|
||||
@ -629,9 +633,14 @@ pub fn parse_style_attribute(input: &str,
|
||||
pub fn parse_one_declaration(id: PropertyId,
|
||||
input: &str,
|
||||
url_data: &UrlExtraData,
|
||||
error_reporter: &ParseErrorReporter)
|
||||
error_reporter: &ParseErrorReporter,
|
||||
length_parsing_mode: LengthParsingMode)
|
||||
-> Result<ParsedDeclaration, ()> {
|
||||
let context = ParserContext::new(Origin::Author, url_data, error_reporter, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new(Origin::Author,
|
||||
url_data,
|
||||
error_reporter,
|
||||
Some(CssRuleType::Style),
|
||||
length_parsing_mode);
|
||||
Parser::new(input).parse_entirely(|parser| {
|
||||
ParsedDeclaration::parse(id, &context, parser)
|
||||
.map_err(|_| ())
|
||||
|
@ -27,7 +27,7 @@ use font_metrics::FontMetricsProvider;
|
||||
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
|
||||
use logical_geometry::WritingMode;
|
||||
use media_queries::Device;
|
||||
use parser::{Parse, ParserContext};
|
||||
use parser::{LengthParsingMode, Parse, ParserContext};
|
||||
use properties::animated_properties::TransitionProperty;
|
||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use shared_lock::StylesheetGuards;
|
||||
@ -369,7 +369,11 @@ 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, None);
|
||||
let context = ParserContext::new(Origin::Author,
|
||||
url_data,
|
||||
error_reporter,
|
||||
None,
|
||||
LengthParsingMode::Default);
|
||||
Parser::new(&css).parse_entirely(|input| {
|
||||
match from_shorthand {
|
||||
None => {
|
||||
|
@ -23,7 +23,7 @@ use gecko_bindings::sugar::refptr::RefPtr;
|
||||
use keyframes::{Keyframe, parse_keyframe_list};
|
||||
use media_queries::{Device, MediaList, parse_media_query_list};
|
||||
use parking_lot::RwLock;
|
||||
use parser::{Parse, ParserContext, log_css_error};
|
||||
use parser::{LengthParsingMode, Parse, ParserContext, log_css_error};
|
||||
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
|
||||
use selector_parser::{SelectorImpl, SelectorParser};
|
||||
use selectors::parser::SelectorList;
|
||||
@ -422,7 +422,8 @@ impl CssRule {
|
||||
let context = ParserContext::new(parent_stylesheet.origin,
|
||||
&parent_stylesheet.url_data,
|
||||
&error_reporter,
|
||||
None);
|
||||
None,
|
||||
LengthParsingMode::Default);
|
||||
let mut input = Parser::new(css);
|
||||
|
||||
// nested rules are in the body state
|
||||
@ -695,7 +696,7 @@ impl Stylesheet {
|
||||
shared_lock: shared_lock,
|
||||
loader: stylesheet_loader,
|
||||
context: ParserContext::new_with_line_number_offset(origin, url_data, error_reporter,
|
||||
line_number_offset),
|
||||
line_number_offset, LengthParsingMode::Default),
|
||||
state: Cell::new(State::Start),
|
||||
};
|
||||
|
||||
|
@ -551,7 +551,12 @@ impl Length {
|
||||
match try!(input.next()) {
|
||||
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::Number(ref value) => {
|
||||
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() {
|
||||
return Err(())
|
||||
}
|
||||
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value))))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") =>
|
||||
input.parse_nested_block(|input| {
|
||||
CalcLengthOrPercentage::parse_length(context, input, num_context)
|
||||
|
@ -71,7 +71,7 @@ use style::gecko_properties::{self, style_structs};
|
||||
use style::keyframes::KeyframesStepValue;
|
||||
use style::media_queries::{MediaList, parse_media_query_list};
|
||||
use style::parallel;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{LengthParsingMode, ParserContext};
|
||||
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration};
|
||||
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
||||
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||
@ -1003,7 +1003,8 @@ 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, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new(Origin::Author, url_data, &reporter,
|
||||
Some(CssRuleType::Style), LengthParsingMode::Default);
|
||||
|
||||
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value)) {
|
||||
Ok(parsed) => {
|
||||
@ -1025,7 +1026,8 @@ 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, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new(Origin::Author, url_data, &reporter,
|
||||
Some(CssRuleType::Style), LengthParsingMode::Default);
|
||||
let easing = unsafe { (*easing).to_string() };
|
||||
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) {
|
||||
Ok(parsed_easing) => {
|
||||
@ -1157,12 +1159,16 @@ pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: Ra
|
||||
}
|
||||
|
||||
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
||||
value: *const nsACString, is_important: bool, data: *mut URLExtraData) -> bool {
|
||||
value: *const nsACString, is_important: bool, data: *mut URLExtraData,
|
||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||
if let Ok(parsed) = parse_one_declaration(property_id, value, url_data,
|
||||
&StdoutErrorReporter) {
|
||||
let length_parsing_mode = match length_parsing_mode {
|
||||
structs::LengthParsingMode::Default => LengthParsingMode::Default,
|
||||
structs::LengthParsingMode::SVG => LengthParsingMode::SVG,
|
||||
};
|
||||
if let Ok(parsed) = parse_one_declaration(property_id, value, url_data, &StdoutErrorReporter,
|
||||
length_parsing_mode) {
|
||||
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||
parsed.expand_set_into(decls, importance)
|
||||
@ -1175,19 +1181,19 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||
property: *const nsACString, value: *const nsACString,
|
||||
is_important: bool,
|
||||
data: *mut URLExtraData) -> bool {
|
||||
is_important: bool, data: *mut URLExtraData,
|
||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
||||
set_property(declarations, get_property_id_from_property!(property, false),
|
||||
value, is_important, data)
|
||||
value, is_important, data, length_parsing_mode)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
||||
property: nsCSSPropertyID, value: *const nsACString,
|
||||
is_important: bool,
|
||||
data: *mut URLExtraData) -> bool {
|
||||
is_important: bool, data: *mut URLExtraData,
|
||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
||||
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
||||
value, is_important, data)
|
||||
value, is_important, data, length_parsing_mode)
|
||||
}
|
||||
|
||||
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
||||
@ -1246,7 +1252,8 @@ pub extern "C" fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed, text:
|
||||
let mut parser = Parser::new(&text);
|
||||
let url_data = unsafe { dummy_url_data() };
|
||||
let reporter = StdoutErrorReporter;
|
||||
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media));
|
||||
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
write_locked_arc(list, |list: &mut MediaList| {
|
||||
*list = parse_media_query_list(&context, &mut parser);
|
||||
})
|
||||
@ -1276,7 +1283,8 @@ pub extern "C" fn Servo_MediaList_AppendMedium(list: RawServoMediaListBorrowed,
|
||||
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));
|
||||
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
write_locked_arc(list, |list: &mut MediaList| {
|
||||
list.append_medium(&context, new_medium);
|
||||
})
|
||||
@ -1288,7 +1296,8 @@ pub extern "C" fn Servo_MediaList_DeleteMedium(list: RawServoMediaListBorrowed,
|
||||
let old_medium = unsafe { old_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));
|
||||
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media),
|
||||
LengthParsingMode::Default);
|
||||
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
|
||||
}
|
||||
|
||||
@ -1639,7 +1648,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(declarations:
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) };
|
||||
let string = unsafe { (*value).to_string() };
|
||||
let error_reporter = StdoutErrorReporter;
|
||||
let context = ParserContext::new(Origin::Author, url_data, &error_reporter, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new(Origin::Author, url_data, &error_reporter,
|
||||
Some(CssRuleType::Style), LengthParsingMode::Default);
|
||||
if let Ok(url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
|
||||
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
||||
vec![SingleBackgroundImage(
|
||||
@ -1677,7 +1687,7 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const
|
||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||
|
||||
let url_data = unsafe { dummy_url_data() };
|
||||
parse_one_declaration(id, &value, url_data, &StdoutErrorReporter).is_ok()
|
||||
parse_one_declaration(id, &value, url_data, &StdoutErrorReporter, LengthParsingMode::Default).is_ok()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -1688,7 +1698,8 @@ 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, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Style),
|
||||
LengthParsingMode::Default);
|
||||
cond.eval(&context)
|
||||
} else {
|
||||
false
|
||||
|
@ -32,7 +32,6 @@ mod size_of;
|
||||
mod str;
|
||||
mod stylesheets;
|
||||
mod stylist;
|
||||
mod value;
|
||||
mod viewport;
|
||||
|
||||
mod writing_modes {
|
||||
|
@ -2,14 +2,11 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use servo_atoms::Atom;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::parser::Parse;
|
||||
use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount;
|
||||
use style::properties::longhands::animation_name;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
|
@ -2,24 +2,16 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::ParserContext;
|
||||
use parsing::parse;
|
||||
use style::properties::longhands::{background_attachment, background_clip, background_color, background_image};
|
||||
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::{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, 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();
|
||||
let input = "url(\"http://servo/test.png\") top center / 200px 200px repeat-x fixed padding-box content-box red";
|
||||
let result = parse(background::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\")"));
|
||||
assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "center"));
|
||||
@ -34,43 +26,33 @@ fn background_shorthand_should_parse_all_available_properties_when_specified() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("14px 40px repeat-y");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "14px 40px repeat-y").unwrap();
|
||||
|
||||
assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "14px"));
|
||||
assert_eq!(result.background_position_y, parse_longhand!(background_position_y, "40px"));
|
||||
assert_eq!(result.background_repeat, parse_longhand!(background_repeat, "repeat-y"));
|
||||
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\") repeat blue");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "url(\"http://servo/test.png\") repeat blue").unwrap();
|
||||
|
||||
assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\")"));
|
||||
assert_eq!(result.background_repeat, parse_longhand!(background_repeat, "repeat"));
|
||||
assert_eq!(result.background_color, parse_longhand!(background_color, "blue"));
|
||||
|
||||
let mut parser = Parser::new("padding-box");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "padding-box").unwrap();
|
||||
|
||||
assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box"));
|
||||
assert_eq!(result.background_clip, parse_longhand!(background_clip, "padding-box"));
|
||||
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\")");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "url(\"http://servo/test.png\")").unwrap();
|
||||
|
||||
assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\")"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, 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();
|
||||
let input = "url(\"http://servo/test.png\") top left no-repeat, url(\"http://servo/test.png\") \
|
||||
center / 100% 100% no-repeat, white";
|
||||
let result = parse(background::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\"), \
|
||||
url(\"http://servo/test.png\"), none"));
|
||||
@ -87,48 +69,35 @@ fn background_shorthand_should_parse_comma_separated_declarations() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("7px 4px");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "7px 4px").unwrap();
|
||||
|
||||
assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "7px"));
|
||||
assert_eq!(result.background_position_y, parse_longhand!(background_position_y, "4px"));
|
||||
|
||||
let mut parser = Parser::new("7px 4px / 30px 20px");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "7px 4px / 30px 20px").unwrap();
|
||||
|
||||
assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "7px"));
|
||||
assert_eq!(result.background_position_y, parse_longhand!(background_position_y, "4px"));
|
||||
assert_eq!(result.background_size, parse_longhand!(background_size, "30px 20px"));
|
||||
|
||||
let mut parser = Parser::new("/ 30px 20px");
|
||||
assert!(background::parse_value(&context, &mut parser).is_err());
|
||||
assert!(parse(background::parse_value, "/ 30px 20px").is_err());
|
||||
|
||||
let mut parser = Parser::new("repeat-x / 30px 20px");
|
||||
assert!(background::parse_value(&context, &mut parser).is_err());
|
||||
assert!(parse(background::parse_value, "repeat-x / 30px 20px").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("padding-box content-box");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "padding-box content-box").unwrap();
|
||||
|
||||
assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box"));
|
||||
assert_eq!(result.background_clip, parse_longhand!(background_clip, "content-box"));
|
||||
|
||||
let mut parser = Parser::new("padding-box padding-box");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "padding-box padding-box").unwrap();
|
||||
|
||||
assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box"));
|
||||
assert_eq!(result.background_clip, parse_longhand!(background_clip, "padding-box"));
|
||||
|
||||
let mut parser = Parser::new("padding-box");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(background::parse_value, "padding-box").unwrap();
|
||||
|
||||
assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box"));
|
||||
assert_eq!(result.background_clip, parse_longhand!(background_clip, "padding-box"));
|
||||
|
@ -2,11 +2,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::parser::Parse;
|
||||
use style::values::specified::basic_shape::*;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
@ -2,24 +2,17 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::{ParserContext, Parse};
|
||||
use parsing::parse;
|
||||
use style::parser::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::{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, 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();
|
||||
let input = "linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px round stretch";
|
||||
let result = parse(border_image::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.border_image_source,
|
||||
parse_longhand!(border_image_source, "linear-gradient(red, blue)"));
|
||||
@ -31,11 +24,8 @@ fn border_image_shorthand_should_parse_when_all_properties_specified() {
|
||||
|
||||
#[test]
|
||||
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, 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();
|
||||
let input = "linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch";
|
||||
let result = parse(border_image::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.border_image_source,
|
||||
parse_longhand!(border_image_source, "linear-gradient(red, blue)"));
|
||||
@ -47,11 +37,8 @@ fn border_image_shorthand_should_parse_without_width() {
|
||||
|
||||
#[test]
|
||||
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, 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();
|
||||
let input = "linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round";
|
||||
let result = parse(border_image::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.border_image_source,
|
||||
parse_longhand!(border_image_source, "linear-gradient(red, blue)"));
|
||||
@ -63,11 +50,8 @@ fn border_image_shorthand_should_parse_without_outset() {
|
||||
|
||||
#[test]
|
||||
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, 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();
|
||||
let input = "linear-gradient(red, blue) 30 30% 45 fill round";
|
||||
let result = parse(border_image::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.border_image_source,
|
||||
parse_longhand!(border_image_source, "linear-gradient(red, blue)"));
|
||||
@ -79,11 +63,7 @@ fn border_image_shorthand_should_parse_without_width_or_outset() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("linear-gradient(red, blue)");
|
||||
let result = border_image::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(border_image::parse_value, "linear-gradient(red, blue)").unwrap();
|
||||
|
||||
assert_eq!(result.border_image_source,
|
||||
parse_longhand!(border_image_source, "linear-gradient(red, blue)"));
|
||||
@ -95,41 +75,25 @@ fn border_image_shorthand_should_parse_with_just_source() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("-1em");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
let result = parse(border_image_outset::parse, "-1em");
|
||||
assert_eq!(result, Err(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("-15");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
let result = parse(border_image_outset::parse, "-15");
|
||||
assert_eq!(result, Err(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("0");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
let result = parse(border_image_outset::parse, "0");
|
||||
assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("0em");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
let result = parse(border_image_outset::parse, "0em");
|
||||
assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0em"));
|
||||
}
|
||||
|
||||
@ -153,7 +117,7 @@ fn test_border_style() {
|
||||
fn test_border_spacing() {
|
||||
use style::properties::longhands::border_spacing;
|
||||
|
||||
assert_parser_exhausted!(border_spacing, "1px rubbish", false);
|
||||
assert_parser_exhausted!(border_spacing, "1px", true);
|
||||
assert_parser_exhausted!(border_spacing, "1px 2px", true);
|
||||
assert_parser_exhausted!(border_spacing::parse, "1px rubbish", false);
|
||||
assert_parser_exhausted!(border_spacing::parse, "1px", true);
|
||||
assert_parser_exhausted!(border_spacing::parse, "1px 2px", true);
|
||||
}
|
||||
|
@ -2,11 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
|
@ -2,11 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use parsing::parse;
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
@ -18,12 +14,7 @@ fn test_column_width() {
|
||||
assert_roundtrip_with_context!(column_width::parse, "2.5em");
|
||||
assert_roundtrip_with_context!(column_width::parse, "0.3vw");
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
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());
|
||||
assert!(parse(column_width::parse, "-6px").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -35,10 +26,5 @@ fn test_column_gap() {
|
||||
assert_roundtrip_with_context!(column_gap::parse, "2.5em");
|
||||
assert_roundtrip_with_context!(column_gap::parse, "0.3vw");
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
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());
|
||||
assert!(parse(column_gap::parse, "-6px").is_err());
|
||||
}
|
||||
|
@ -2,10 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use parsing::parse;
|
||||
|
||||
#[test]
|
||||
fn contain_longhand_should_parse_correctly() {
|
||||
@ -22,5 +19,5 @@ fn contain_longhand_should_parse_correctly() {
|
||||
assert_eq!(style_paint, contain::STYLE | contain::PAINT);
|
||||
|
||||
// Assert that the `2px` is not consumed, which would trigger parsing failure in real use
|
||||
assert_parser_exhausted!(contain, "layout 2px", false);
|
||||
assert_parser_exhausted!(contain::parse, "layout 2px", false);
|
||||
}
|
||||
|
@ -2,13 +2,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::longhands::{self, perspective_origin, transform_origin};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
@ -37,48 +32,21 @@ fn test_clip() {
|
||||
|
||||
#[test]
|
||||
fn test_longhands_parse_origin() {
|
||||
let 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("1px some-rubbish");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
assert!(parsed.is_ok());
|
||||
assert_eq!(parser.is_exhausted(), false);
|
||||
|
||||
let mut parser = Parser::new("1px 2px");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
assert!(parsed.is_ok());
|
||||
assert_eq!(parser.is_exhausted(), true);
|
||||
|
||||
let mut parser = Parser::new("center left");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
assert!(parsed.is_ok());
|
||||
assert_eq!(parser.is_exhausted(), true);
|
||||
|
||||
let mut parser = Parser::new("center right");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
assert!(parsed.is_ok());
|
||||
assert_eq!(parser.is_exhausted(), true);
|
||||
|
||||
let mut parser = Parser::new("center right 1px");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
assert!(parsed.is_ok());
|
||||
assert_eq!(parser.is_exhausted(), true);
|
||||
|
||||
let mut parser = Parser::new("1% right");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
assert!(parsed.is_ok());
|
||||
assert_eq!(parser.is_exhausted(), false);
|
||||
assert_parser_exhausted!(longhands::parse_origin, "1px some-rubbish", false);
|
||||
assert_parser_exhausted!(longhands::parse_origin, "1px 2px", true);
|
||||
assert_parser_exhausted!(longhands::parse_origin, "center left", true);
|
||||
assert_parser_exhausted!(longhands::parse_origin, "center right", true);
|
||||
assert_parser_exhausted!(longhands::parse_origin, "center right 1px", true);
|
||||
assert_parser_exhausted!(longhands::parse_origin, "1% right", false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_effects_parser_exhaustion() {
|
||||
assert_parser_exhausted!(perspective_origin, "1px 1px", true);
|
||||
assert_parser_exhausted!(transform_origin, "1px 1px", true);
|
||||
assert_parser_exhausted!(perspective_origin::parse, "1px 1px", true);
|
||||
assert_parser_exhausted!(transform_origin::parse, "1px 1px", true);
|
||||
|
||||
assert_parser_exhausted!(perspective_origin, "1px some-rubbish", false);
|
||||
assert_parser_exhausted!(transform_origin, "1px some-rubbish", false);
|
||||
assert_parser_exhausted!(perspective_origin::parse, "1px some-rubbish", false);
|
||||
assert_parser_exhausted!(transform_origin::parse, "1px some-rubbish", false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2,14 +2,10 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::ParserContext;
|
||||
use parsing::parse;
|
||||
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::{CssRuleType, Origin};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
@ -52,21 +48,10 @@ fn font_feature_settings_should_parse_properly() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
|
||||
let mut empty = Parser::new("");
|
||||
assert!(font_feature_settings::parse(&context, &mut empty).is_err());
|
||||
|
||||
let mut negative = Parser::new("\"abcd\" -1");
|
||||
assert!(font_feature_settings::parse(&context, &mut negative).is_err());
|
||||
|
||||
let mut short_tag = Parser::new("\"abc\"");
|
||||
assert!(font_feature_settings::parse(&context, &mut short_tag).is_err());
|
||||
|
||||
let mut illegal_tag = Parser::new("\"abcó\"");
|
||||
assert!(font_feature_settings::parse(&context, &mut illegal_tag).is_err());
|
||||
assert!(parse(font_feature_settings::parse, "").is_err());
|
||||
assert!(parse(font_feature_settings::parse, "\"abcd\" -1").is_err());
|
||||
assert!(parse(font_feature_settings::parse, "\"abc\"").is_err());
|
||||
assert!(parse(font_feature_settings::parse, "\"abcó\"").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -103,16 +88,11 @@ fn font_language_override_should_parse_properly() {
|
||||
fn font_weight_keyword_should_preserve_keyword() {
|
||||
use style::properties::longhands::font_weight::SpecifiedValue;
|
||||
|
||||
let 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("normal");
|
||||
let result = font_weight::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), SpecifiedValue::Normal);
|
||||
let result = parse(font_weight::parse, "normal").unwrap();
|
||||
assert_eq!(result, SpecifiedValue::Normal);
|
||||
|
||||
let mut parser = Parser::new("bold");
|
||||
let result = font_weight::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), SpecifiedValue::Bold);
|
||||
let result = parse(font_weight::parse, "bold").unwrap();
|
||||
assert_eq!(result, SpecifiedValue::Bold);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2,15 +2,12 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use euclid::size::TypedSize2D;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use std::f32::consts::PI;
|
||||
use style::font_metrics::ServoMetricsProvider;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::ComputedValues;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::values::computed;
|
||||
use style::values::computed::{Angle, Context, ToComputedValue};
|
||||
use style::values::specified;
|
||||
|
@ -2,10 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use parsing::parse;
|
||||
|
||||
#[test]
|
||||
fn image_orientation_longhand_should_parse_properly() {
|
||||
|
@ -2,10 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use parsing::parse;
|
||||
|
||||
#[test]
|
||||
fn negative_letter_spacing_should_parse_properly() {
|
||||
@ -104,52 +101,32 @@ fn test_text_emphasis_position() {
|
||||
|
||||
#[test]
|
||||
fn webkit_text_stroke_shorthand_should_parse_properly() {
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::properties::longhands::_webkit_text_stroke_color;
|
||||
use style::properties::longhands::_webkit_text_stroke_width;
|
||||
use style::properties::shorthands::_webkit_text_stroke;
|
||||
|
||||
let 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("thin red");
|
||||
let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(_webkit_text_stroke::parse_value, "thin red").unwrap();
|
||||
assert_eq!(result._webkit_text_stroke_color, parse_longhand!(_webkit_text_stroke_color, "red"));
|
||||
assert_eq!(result._webkit_text_stroke_width, parse_longhand!(_webkit_text_stroke_width, "thin"));
|
||||
|
||||
// ensure its no longer sensitive to order
|
||||
let mut parser = Parser::new("red thin");
|
||||
let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(_webkit_text_stroke::parse_value, "red thin").unwrap();
|
||||
assert_eq!(result._webkit_text_stroke_color, parse_longhand!(_webkit_text_stroke_color, "red"));
|
||||
assert_eq!(result._webkit_text_stroke_width, parse_longhand!(_webkit_text_stroke_width, "thin"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_height_should_return_number_on_plain_zero() {
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::properties::longhands::line_height;
|
||||
|
||||
let 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("0");
|
||||
let result = line_height::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0"));
|
||||
let result = parse(line_height::parse, "0").unwrap();
|
||||
assert_eq!(result, parse_longhand!(line_height, "0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_height_should_return_length_on_length_zero() {
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::properties::longhands::line_height;
|
||||
|
||||
let 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("0px");
|
||||
let result = line_height::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0px"));
|
||||
let result = parse(line_height::parse, "0px").unwrap();
|
||||
assert_eq!(result, parse_longhand!(line_height, "0px"));
|
||||
}
|
||||
|
@ -5,9 +5,9 @@
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::parser::{LengthParsingMode, Parse, ParserContext};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::values::specified::length::Length;
|
||||
use style::values::specified::length::{AbsoluteLength, Length, NoCalcLength};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
@ -28,3 +28,19 @@ fn test_length_literals() {
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33pt", "0.33pt");
|
||||
assert_roundtrip_with_context!(Length::parse, "0.33pc", "0.33pc");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_length_parsing_modes() {
|
||||
// In default length mode, non-zero lengths must have a unit.
|
||||
assert!(parse(Length::parse, "1").is_err());
|
||||
|
||||
// In SVG length mode, non-zero lengths are assumed to be px.
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
||||
Some(CssRuleType::Style), LengthParsingMode::SVG);
|
||||
let mut parser = Parser::new("1");
|
||||
let result = Length::parse(&context, &mut parser);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(1.))));
|
||||
}
|
||||
|
@ -2,23 +2,15 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::ParserContext;
|
||||
use parsing::parse;
|
||||
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::{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, 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();
|
||||
let input = "url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px repeat-x padding-box border-box subtract";
|
||||
let result = parse(mask::parse_value, input).unwrap();
|
||||
|
||||
assert_eq!(result.mask_image, parse_longhand!(mask_image, "url(\"http://servo/test.png\")"));
|
||||
assert_eq!(result.mask_mode, parse_longhand!(mask_mode, "luminance"));
|
||||
@ -33,78 +25,58 @@ fn mask_shorthand_should_parse_all_available_properties_when_specified() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("14px 40px repeat-y");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "14px 40px repeat-y").unwrap();
|
||||
|
||||
assert_eq!(result.mask_position_x, parse_longhand!(mask_position_x, "14px"));
|
||||
assert_eq!(result.mask_position_y, parse_longhand!(mask_position_y, "40px"));
|
||||
assert_eq!(result.mask_repeat, parse_longhand!(mask_repeat, "repeat-y"));
|
||||
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\") repeat add");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "url(\"http://servo/test.png\") repeat add").unwrap();
|
||||
|
||||
assert_eq!(result.mask_image, parse_longhand!(mask_image, "url(\"http://servo/test.png\")"));
|
||||
assert_eq!(result.mask_repeat, parse_longhand!(mask_repeat, "repeat"));
|
||||
assert_eq!(result.mask_composite, parse_longhand!(mask_composite, "add"));
|
||||
|
||||
let mut parser = Parser::new("intersect");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "intersect").unwrap();
|
||||
|
||||
assert_eq!(result.mask_composite, parse_longhand!(mask_composite, "intersect"));
|
||||
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\")");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "url(\"http://servo/test.png\")").unwrap();
|
||||
|
||||
assert_eq!(result.mask_image, parse_longhand!(mask_image, "url(\"http://servo/test.png\")"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("7px 4px");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "7px 4px").unwrap();
|
||||
|
||||
assert_eq!(result.mask_position_x, parse_longhand!(mask_position_x, "7px"));
|
||||
assert_eq!(result.mask_position_y, parse_longhand!(mask_position_y, "4px"));
|
||||
|
||||
let mut parser = Parser::new("7px 4px / 30px 20px");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "7px 4px / 30px 20px").unwrap();
|
||||
|
||||
assert_eq!(result.mask_position_x, parse_longhand!(mask_position_x, "7px"));
|
||||
assert_eq!(result.mask_position_y, parse_longhand!(mask_position_y, "4px"));
|
||||
assert_eq!(result.mask_size, parse_longhand!(mask_size, "30px 20px"));
|
||||
|
||||
let mut parser = Parser::new("/ 30px 20px");
|
||||
assert!(mask::parse_value(&context, &mut parser).is_err());
|
||||
assert!(parse(mask::parse_value, "/ 30px 20px").is_err());
|
||||
|
||||
let mut parser = Parser::new("match-source repeat-x / 30px 20px");
|
||||
assert!(mask::parse_value(&context, &mut parser).is_err());
|
||||
assert!(parse(mask::parse_value, "match-source repeat-x / 30px 20px").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("padding-box content-box");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "padding-box content-box").unwrap();
|
||||
|
||||
assert_eq!(result.mask_origin, parse_longhand!(mask_origin, "padding-box"));
|
||||
assert_eq!(result.mask_clip, parse_longhand!(mask_clip, "content-box"));
|
||||
|
||||
let mut parser = Parser::new("padding-box padding-box");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "padding-box padding-box").unwrap();
|
||||
|
||||
assert_eq!(result.mask_origin, parse_longhand!(mask_origin, "padding-box"));
|
||||
assert_eq!(result.mask_clip, parse_longhand!(mask_clip, "padding-box"));
|
||||
|
||||
let mut parser = Parser::new("padding-box");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
let result = parse(mask::parse_value, "padding-box").unwrap();
|
||||
|
||||
assert_eq!(result.mask_origin, parse_longhand!(mask_origin, "padding-box"));
|
||||
assert_eq!(result.mask_clip, parse_longhand!(mask_clip, "padding-box"));
|
||||
@ -112,14 +84,8 @@ fn mask_shorthand_should_parse_origin_and_clip_correctly() {
|
||||
|
||||
#[test]
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new("luminance 7px 4px repeat-x padding-box");
|
||||
assert!(mask::parse_value(&context, &mut parser).is_ok());
|
||||
|
||||
let mut parser = Parser::new("alpha");
|
||||
assert!(mask::parse_value(&context, &mut parser).is_ok());
|
||||
assert!(parse(mask::parse_value, "luminance 7px 4px repeat-x padding-box").is_ok());
|
||||
assert!(parse(mask::parse_value, "alpha").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -153,23 +119,13 @@ fn mask_repeat_should_parse_shorthand_correctly() {
|
||||
fn mask_repeat_should_parse_longhand_correctly() {
|
||||
use style::properties::longhands::mask_repeat::single_value::{RepeatKeyword, SpecifiedValue};
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
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");
|
||||
assert!(mask_repeat::parse(&context, &mut parser).is_err());
|
||||
|
||||
let mut parser = Parser::new("no-repeat repeat-x");
|
||||
assert!(mask_repeat::parse(&context, &mut parser).is_err());
|
||||
assert!(parse(mask_repeat::parse, "repeat-x no-repeat").is_err());
|
||||
assert!(parse(mask_repeat::parse, "no-repeat repeat-x").is_err());
|
||||
|
||||
// repeat-y is not available in longhand form.
|
||||
let mut parser = Parser::new("repeat-y no-repeat");
|
||||
assert!(mask_repeat::parse(&context, &mut parser).is_err());
|
||||
|
||||
let mut parser = Parser::new("no-repeat repeat-y");
|
||||
assert!(mask_repeat::parse(&context, &mut parser).is_err());
|
||||
assert!(parse(mask_repeat::parse, "repeat-y no-repeat").is_err());
|
||||
assert!(parse(mask_repeat::parse, "no-repeat repeat-y").is_err());
|
||||
|
||||
// Longhand form supports two directions.
|
||||
let no_repeat_and_round = parse_longhand!(mask_repeat, "no-repeat round");
|
||||
@ -178,8 +134,7 @@ fn mask_repeat_should_parse_longhand_correctly() {
|
||||
Some(RepeatKeyword::Round))]));
|
||||
|
||||
// Not three directions.
|
||||
let mut parser = Parser::new("repeat no-repeat round");
|
||||
assert!(mask_repeat::parse(&context, &mut parser).is_err());
|
||||
assert!(parse(mask_repeat::parse, "repeat no-repeat round").is_err());
|
||||
|
||||
// Multiple values with mixed shortform and longform should parse.
|
||||
let multiple = parse_longhand!(mask_repeat, "repeat, no-repeat round");
|
||||
|
@ -6,13 +6,14 @@
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{LengthParsingMode, ParserContext};
|
||||
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, Some(CssRuleType::Style));
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
|
||||
LengthParsingMode::Default);
|
||||
let mut parser = Parser::new(s);
|
||||
f(&context, &mut parser)
|
||||
}
|
||||
@ -23,29 +24,30 @@ macro_rules! assert_roundtrip_with_context {
|
||||
($fun:expr, $string:expr) => {
|
||||
assert_roundtrip_with_context!($fun, $string, $string);
|
||||
};
|
||||
($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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new($input);
|
||||
let parsed = $fun(&context, &mut parser)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
($fun:expr, $input:expr, $output:expr) => {{
|
||||
let serialized = parse(|context, i| {
|
||||
let parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
Ok(serialized)
|
||||
}, $input).unwrap();
|
||||
|
||||
let mut parser = Parser::new(&serialized);
|
||||
let re_parsed = $fun(&context, &mut parser)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
}
|
||||
parse(|context, i| {
|
||||
let re_parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
Ok(())
|
||||
}, &serialized).unwrap()
|
||||
}}
|
||||
}
|
||||
|
||||
macro_rules! assert_roundtrip {
|
||||
($fun:expr, $string:expr) => {
|
||||
assert_roundtrip!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr,$input:expr, $output:expr) => {
|
||||
($fun:expr, $input:expr, $output:expr) => {
|
||||
let mut parser = Parser::new($input);
|
||||
let parsed = $fun(&mut parser)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
@ -56,29 +58,25 @@ macro_rules! assert_roundtrip {
|
||||
let re_parsed = $fun(&mut parser)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
assert_eq!(serialized, re_serialized)
|
||||
}
|
||||
}
|
||||
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new($string);
|
||||
let parsed = $name::parse(&context, &mut parser);
|
||||
assert_eq!(parsed.is_ok(), true);
|
||||
assert_eq!(parser.is_exhausted(), $should_exhausted);
|
||||
($fun:expr, $string:expr, $should_exhausted:expr) => {{
|
||||
parse(|context, input| {
|
||||
let parsed = $fun(context, input);
|
||||
assert_eq!(parsed.is_ok(), true);
|
||||
assert_eq!(input.is_exhausted(), $should_exhausted);
|
||||
Ok(())
|
||||
}, $string).unwrap()
|
||||
}}
|
||||
}
|
||||
|
||||
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, Some(CssRuleType::Style));
|
||||
$name::parse(&context, &mut Parser::new($s)).unwrap()
|
||||
}};
|
||||
($name:ident, $s:expr) => {
|
||||
parse($name::parse, $s).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
mod animation;
|
||||
@ -103,3 +101,4 @@ mod text;
|
||||
mod text_overflow;
|
||||
mod transition_timing_function;
|
||||
mod ui;
|
||||
mod value;
|
||||
|
@ -2,10 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use parsing::parse;
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
@ -23,16 +20,7 @@ fn test_outline_style() {
|
||||
assert_roundtrip_with_context!(outline_style::parse, r#"inset"#);
|
||||
assert_roundtrip_with_context!(outline_style::parse, r#"outset"#);
|
||||
|
||||
{
|
||||
// The outline-style property accepts the same values as border-style,
|
||||
// except that 'hidden' is not a legal outline style.
|
||||
|
||||
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(r#"hidden"#);
|
||||
let parsed = outline_style::parse(&context, &mut parser);
|
||||
assert!(parsed.is_err());
|
||||
};
|
||||
|
||||
// The outline-style property accepts the same values as border-style,
|
||||
// except that 'hidden' is not a legal outline style.
|
||||
assert!(parse(outline_style::parse, r#"hidden"#).is_err());
|
||||
}
|
||||
|
@ -2,11 +2,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::parser::Parse;
|
||||
use style::values::specified::position::*;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
@ -3,13 +3,11 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::{Parser, ToCss};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use selectors::parser::SelectorList;
|
||||
use style::parser::ParserContext;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::stylesheets::{CssRuleType, Origin, Namespaces};
|
||||
use style::stylesheets::{Origin, Namespaces};
|
||||
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
|
||||
fn parse_selector(input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
|
||||
let mut ns = Namespaces::default();
|
||||
ns.prefixes.insert("svg".into(), ns!(svg));
|
||||
let parser = SelectorParser {
|
||||
@ -21,8 +19,8 @@ fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SelectorList<Se
|
||||
|
||||
#[test]
|
||||
fn test_selectors() {
|
||||
assert_roundtrip_with_context!(parse, "div");
|
||||
assert_roundtrip_with_context!(parse, "svg|circle");
|
||||
assert_roundtrip_with_context!(parse, "p:before", "p::before");
|
||||
assert_roundtrip_with_context!(parse, "[border = \"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
|
||||
assert_roundtrip!(parse_selector, "div");
|
||||
assert_roundtrip!(parse_selector, "svg|circle");
|
||||
assert_roundtrip!(parse_selector, "p:before", "p::before");
|
||||
assert_roundtrip!(parse_selector, "[border = \"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
|
||||
}
|
||||
|
@ -2,11 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
|
@ -2,10 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use parsing::parse;
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
@ -20,15 +17,14 @@ fn test_text_overflow() {
|
||||
assert_roundtrip_with_context!(text_overflow::parse, r#"clip "x""#);
|
||||
assert_roundtrip_with_context!(text_overflow::parse, r#""x" clip"#);
|
||||
assert_roundtrip_with_context!(text_overflow::parse, r#""x" "y""#);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_overflow_parser_exhaustion() {
|
||||
use style::properties::longhands::text_overflow;
|
||||
|
||||
assert_parser_exhausted!(text_overflow, r#"clip rubbish"#, false);
|
||||
assert_parser_exhausted!(text_overflow, r#"clip"#, true);
|
||||
assert_parser_exhausted!(text_overflow, r#"ellipsis"#, true);
|
||||
assert_parser_exhausted!(text_overflow, r#"clip ellipsis"#, true);
|
||||
assert_parser_exhausted!(text_overflow::parse, r#"clip rubbish"#, false);
|
||||
assert_parser_exhausted!(text_overflow::parse, r#"clip"#, true);
|
||||
assert_parser_exhausted!(text_overflow::parse, r#"ellipsis"#, true);
|
||||
assert_parser_exhausted!(text_overflow::parse, r#"clip ellipsis"#, true);
|
||||
}
|
||||
|
@ -2,12 +2,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::longhands::transition_timing_function;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::ToCss;
|
||||
|
||||
#[test]
|
||||
|
@ -2,11 +2,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::{Color, Parser, RGBA};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use cssparser::{Color, RGBA};
|
||||
use parsing::parse;
|
||||
use style::values::{Auto, Either};
|
||||
use style::values::specified::CSSColor;
|
||||
use style_traits::ToCss;
|
||||
@ -26,12 +23,7 @@ fn test_moz_user_select() {
|
||||
assert_roundtrip_with_context!(_moz_user_select::parse, "-moz-none");
|
||||
assert_roundtrip_with_context!(_moz_user_select::parse, "-moz-text");
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
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());
|
||||
assert!(parse(_moz_user_select::parse, "potato").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
35
servo/tests/unit/style/parsing/value.rs
Normal file
35
servo/tests/unit/style/parsing/value.rs
Normal file
@ -0,0 +1,35 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use parsing::parse;
|
||||
use style::values::HasViewportPercentage;
|
||||
use style::values::specified::{AbsoluteLength, NoCalcLength, ViewportPercentageLength};
|
||||
use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit};
|
||||
|
||||
#[test]
|
||||
fn length_has_viewport_percentage() {
|
||||
let l = NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.));
|
||||
assert!(l.has_viewport_percentage());
|
||||
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
|
||||
assert!(!l.has_viewport_percentage());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calc_top_level_number_with_unit() {
|
||||
fn parse_value(text: &str, unit: CalcUnit) -> Result<CalcLengthOrPercentage, ()> {
|
||||
parse(|context, input| CalcLengthOrPercentage::parse(context, input, unit), text)
|
||||
}
|
||||
assert_eq!(parse_value("1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse_value("1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse_value("1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse_value("1", CalcUnit::Time), Err(()));
|
||||
assert_eq!(parse_value("1px + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse_value("1em + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse_value("1px + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse_value("1% + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse_value("1rad + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse_value("1deg + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse_value("1s + 1", CalcUnit::Time), Err(()));
|
||||
}
|
@ -2,19 +2,10 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use properties::parse;
|
||||
use style::properties::longhands::background_size;
|
||||
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, Some(CssRuleType::Style));
|
||||
|
||||
let parse_result = background_size::parse(&context, &mut Parser::new("-40% -40%"));
|
||||
|
||||
assert_eq!(parse_result.is_err(), true);
|
||||
assert!(parse(background_size::parse, "-40% -40%").is_err());
|
||||
}
|
||||
|
@ -2,6 +2,43 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::{LengthParsingMode, ParserContext};
|
||||
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, Some(CssRuleType::Style),
|
||||
LengthParsingMode::Default);
|
||||
let mut parser = Parser::new(s);
|
||||
f(&context, &mut parser)
|
||||
}
|
||||
|
||||
macro_rules! assert_roundtrip_with_context {
|
||||
($fun:expr, $string:expr) => {
|
||||
assert_roundtrip_with_context!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr, $input:expr, $output:expr) => {{
|
||||
let serialized = parse(|context, i| {
|
||||
let parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
Ok(serialized)
|
||||
}, $input).unwrap();
|
||||
|
||||
parse(|context, i| {
|
||||
let re_parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
Ok(())
|
||||
}, &serialized).unwrap()
|
||||
}}
|
||||
}
|
||||
|
||||
mod background;
|
||||
mod scaffolding;
|
||||
mod serialization;
|
||||
|
@ -2,15 +2,11 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_url::ServoUrl;
|
||||
use properties::parse;
|
||||
use style::computed_values::display::T::inline_block;
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, Importance, PropertyId};
|
||||
use style::properties::{PropertyDeclaration, Importance, PropertyId};
|
||||
use style::properties::longhands::outline_color::computed_value::T as ComputedColor;
|
||||
use style::properties::parse_property_declaration_list;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::values::{RGBA, Auto};
|
||||
use style::values::specified::{BorderStyle, BorderWidth, CSSColor, Length, NoCalcLength};
|
||||
use style::values::specified::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrAutoOrContent};
|
||||
@ -18,14 +14,6 @@ use style::values::specified::url::SpecifiedUrl;
|
||||
use style_traits::ToCss;
|
||||
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, Some(CssRuleType::Style));
|
||||
let mut parser = Parser::new(css_properties);
|
||||
parse_property_declaration_list(&context, &mut parser)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn property_declaration_block_should_serialize_correctly() {
|
||||
use style::properties::longhands::overflow_x::SpecifiedValue as OverflowXValue;
|
||||
@ -626,7 +614,7 @@ mod shorthand_serialization {
|
||||
font-language-override: normal; \
|
||||
font-kerning: none";
|
||||
|
||||
let block = parse_declaration_block(block_text);
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let mut s = String::new();
|
||||
let id = PropertyId::parse("font".into()).unwrap();
|
||||
@ -651,7 +639,7 @@ mod shorthand_serialization {
|
||||
font-variant-position: normal; \
|
||||
font-language-override: normal;";
|
||||
|
||||
let block = parse_declaration_block(block_text);
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -675,7 +663,8 @@ mod shorthand_serialization {
|
||||
background-position-y: 4px; \
|
||||
background-origin: border-box; \
|
||||
background-clip: padding-box;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -698,7 +687,8 @@ mod shorthand_serialization {
|
||||
background-position-y: 4px; \
|
||||
background-origin: padding-box; \
|
||||
background-clip: padding-box;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -721,7 +711,8 @@ mod shorthand_serialization {
|
||||
background-position-y: 4px, 40px; \
|
||||
background-origin: border-box, padding-box; \
|
||||
background-clip: padding-box, padding-box;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -751,7 +742,8 @@ mod shorthand_serialization {
|
||||
background-position: 7px 4px, 5px 6px; \
|
||||
background-origin: border-box; \
|
||||
background-clip: padding-box, padding-box;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -909,7 +901,7 @@ mod shorthand_serialization {
|
||||
#[test]
|
||||
fn serialize_mask_position_with_multiple_values() {
|
||||
let block_text = "mask-position: 1px 2px, 4px 3px;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, block_text);
|
||||
}
|
||||
@ -967,22 +959,9 @@ mod shorthand_serialization {
|
||||
|
||||
#[test]
|
||||
fn should_serialize_none_correctly() {
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::longhands::transform;
|
||||
use style::stylesheets::Origin;
|
||||
|
||||
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, Some(CssRuleType::Style));
|
||||
|
||||
let parsed = transform::parse(&context, &mut Parser::new("none")).unwrap();
|
||||
let try_serialize = parsed.to_css(&mut s);
|
||||
|
||||
assert_eq!(try_serialize.is_ok(), true);
|
||||
assert_eq!(s, "none");
|
||||
assert_roundtrip_with_context!(transform::parse, "none");
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@ -1031,22 +1010,9 @@ mod shorthand_serialization {
|
||||
|
||||
#[test]
|
||||
fn should_serialize_none_correctly() {
|
||||
use cssparser::Parser;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::longhands::quotes;
|
||||
use style::stylesheets::Origin;
|
||||
|
||||
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, Some(CssRuleType::Style));
|
||||
|
||||
let parsed = quotes::parse(&context, &mut Parser::new("none")).unwrap();
|
||||
let try_serialize = parsed.to_css(&mut s);
|
||||
|
||||
assert_eq!(try_serialize.is_ok(), true);
|
||||
assert_eq!(s, "none");
|
||||
assert_roundtrip_with_context!(quotes::parse, "none");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1055,7 +1021,7 @@ mod shorthand_serialization {
|
||||
|
||||
#[test]
|
||||
fn serialize_single_animation() {
|
||||
let block = parse_declaration_block("\
|
||||
let block_text = "\
|
||||
animation-name: bounce;\
|
||||
animation-duration: 1s;\
|
||||
animation-timing-function: ease-in;\
|
||||
@ -1063,7 +1029,9 @@ mod shorthand_serialization {
|
||||
animation-direction: normal;\
|
||||
animation-fill-mode: forwards;\
|
||||
animation-iteration-count: infinite;\
|
||||
animation-play-state: paused;");
|
||||
animation-play-state: paused;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1072,7 +1040,7 @@ mod shorthand_serialization {
|
||||
|
||||
#[test]
|
||||
fn serialize_multiple_animations() {
|
||||
let block = parse_declaration_block("\
|
||||
let block_text = "\
|
||||
animation-name: bounce, roll;\
|
||||
animation-duration: 1s, 0.2s;\
|
||||
animation-timing-function: ease-in, linear;\
|
||||
@ -1080,7 +1048,9 @@ mod shorthand_serialization {
|
||||
animation-direction: normal, reverse;\
|
||||
animation-fill-mode: forwards, backwards;\
|
||||
animation-iteration-count: infinite, 2;\
|
||||
animation-play-state: paused, running;");
|
||||
animation-play-state: paused, running;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1105,7 +1075,8 @@ mod shorthand_serialization {
|
||||
animation-fill-mode: forwards, backwards; \
|
||||
animation-iteration-count: infinite, 2; \
|
||||
animation-play-state: paused, running;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1121,7 +1092,8 @@ mod shorthand_serialization {
|
||||
animation-fill-mode: forwards, backwards; \
|
||||
animation-iteration-count: infinite, 2; \
|
||||
animation-play-state: paused, running;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1138,7 +1110,8 @@ mod shorthand_serialization {
|
||||
transition-duration: 3s; \
|
||||
transition-delay: 4s; \
|
||||
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2);";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1151,7 +1124,8 @@ mod shorthand_serialization {
|
||||
transition-duration: 3s, 2s; \
|
||||
transition-delay: 4s, 5s; \
|
||||
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1172,7 +1146,8 @@ mod shorthand_serialization {
|
||||
transition-duration: 3s, 2s, 4s; \
|
||||
transition-delay: 4s, 5s; \
|
||||
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
@ -1185,7 +1160,7 @@ mod shorthand_serialization {
|
||||
#[test]
|
||||
fn css_wide_keywords_should_be_parsed() {
|
||||
let block_text = "--a:inherit;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, "--a: inherit;");
|
||||
@ -1194,7 +1169,7 @@ mod shorthand_serialization {
|
||||
#[test]
|
||||
fn non_keyword_custom_property_should_be_unparsed() {
|
||||
let block_text = "--main-color: #06c;";
|
||||
let block = parse_declaration_block(block_text);
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, block_text);
|
||||
@ -1214,7 +1189,7 @@ mod shorthand_serialization {
|
||||
let shadow_decl = BoxShadow(vec![shadow_val]);
|
||||
properties.push(PropertyDeclaration:: BoxShadow(shadow_decl));
|
||||
let shadow_css = "box-shadow: 1px 2px 3px 4px;";
|
||||
let shadow = parse_declaration_block(shadow_css);
|
||||
let shadow = parse(|c, i| Ok(parse_property_declaration_list(c, i)), shadow_css).unwrap();
|
||||
|
||||
assert_eq!(shadow.to_css_string(), shadow_css);
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use 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};
|
||||
|
||||
#[test]
|
||||
fn length_has_viewport_percentage() {
|
||||
let l = NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.));
|
||||
assert!(l.has_viewport_percentage());
|
||||
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
|
||||
assert!(!l.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(&context, &mut parser, unit)
|
||||
}
|
||||
assert_eq!(parse("1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse("1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse("1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse("1", CalcUnit::Time), Err(()));
|
||||
assert_eq!(parse("1px + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse("1em + 1", CalcUnit::Length), Err(()));
|
||||
assert_eq!(parse("1px + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse("1% + 1", CalcUnit::LengthOrPercentage), Err(()));
|
||||
assert_eq!(parse("1rad + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse("1deg + 1", CalcUnit::Angle), Err(()));
|
||||
assert_eq!(parse("1s + 1", CalcUnit::Time), Err(()));
|
||||
}
|
@ -9,7 +9,7 @@ use servo_config::prefs::{PREFS, PrefValue};
|
||||
use servo_url::ServoUrl;
|
||||
use std::sync::Arc;
|
||||
use style::media_queries::{Device, MediaList, MediaType};
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::parser::{LengthParsingMode, Parse, ParserContext};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
||||
use style::values::specified::LengthOrPercentageOrAuto::{self, Auto};
|
||||
@ -292,7 +292,8 @@ 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, Some(CssRuleType::Viewport));
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Viewport),
|
||||
LengthParsingMode::Default);
|
||||
|
||||
macro_rules! from_css {
|
||||
($css:expr) => {
|
||||
|
Loading…
Reference in New Issue
Block a user