mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Auto merge of #16851 - hiikezoe:allow-all-numeric-values, r=emilio
Allow all numeric values for SMIL values <!-- Please describe your changes on the following line: --> This is a PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1357295 . --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16851) <!-- Reviewable:end -->
This commit is contained in:
commit
0900ad4e4e
25 changed files with 453 additions and 355 deletions
|
@ -10,7 +10,7 @@ use dom::bindings::str::DOMString;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::stylesheets::CssRuleType;
|
use style::stylesheets::CssRuleType;
|
||||||
use style::supports::{Declaration, parse_condition_or_declaration};
|
use style::supports::{Declaration, parse_condition_or_declaration};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ impl CSS {
|
||||||
let decl = Declaration { prop: property.into(), val: value.into() };
|
let decl = Declaration { prop: property.into(), val: value.into() };
|
||||||
let url = win.Document().url();
|
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
decl.eval(&context)
|
decl.eval(&context)
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ impl CSS {
|
||||||
if let Ok(cond) = cond {
|
if let Ok(cond) = cond {
|
||||||
let url = win.Document().url();
|
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
cond.eval(&context)
|
cond.eval(&context)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,7 +16,7 @@ use dom::medialist::MediaList;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||||
use style::stylearc::Arc;
|
use style::stylearc::Arc;
|
||||||
use style::stylesheets::{CssRuleType, MediaRule};
|
use style::stylesheets::{CssRuleType, MediaRule};
|
||||||
|
@ -75,7 +75,7 @@ impl CSSMediaRule {
|
||||||
let url = win.get_url();
|
let url = win.get_url();
|
||||||
let quirks_mode = win.Document().quirks_mode();
|
let quirks_mode = win.Document().quirks_mode();
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
let new_medialist = parse_media_query_list(&context, &mut input);
|
let new_medialist = parse_media_query_list(&context, &mut input);
|
||||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||||
|
|
|
@ -17,7 +17,7 @@ use dom_struct::dom_struct;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use style::attr::AttrValue;
|
use style::attr::AttrValue;
|
||||||
use style::parser::LengthParsingMode;
|
use style::parser::PARSING_MODE_DEFAULT;
|
||||||
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
||||||
use style::properties::{parse_one_declaration, parse_style_attribute};
|
use style::properties::{parse_one_declaration, parse_style_attribute};
|
||||||
use style::selector_parser::PseudoElement;
|
use style::selector_parser::PseudoElement;
|
||||||
|
@ -260,7 +260,7 @@ impl CSSStyleDeclaration {
|
||||||
let result =
|
let result =
|
||||||
parse_one_declaration(id, &value, &self.owner.base_url(),
|
parse_one_declaration(id, &value, &self.owner.base_url(),
|
||||||
window.css_error_reporter(),
|
window.css_error_reporter(),
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
|
|
||||||
// Step 7
|
// Step 7
|
||||||
|
|
|
@ -13,7 +13,7 @@ use dom::cssrule::SpecificCSSRule;
|
||||||
use dom::cssstylesheet::CSSStyleSheet;
|
use dom::cssstylesheet::CSSStyleSheet;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||||
use style::stylearc::Arc;
|
use style::stylearc::Arc;
|
||||||
use style::stylesheets::{CssRuleType, SupportsRule};
|
use style::stylesheets::{CssRuleType, SupportsRule};
|
||||||
|
@ -63,7 +63,7 @@ impl CSSSupportsRule {
|
||||||
let url = win.Document().url();
|
let url = win.Document().url();
|
||||||
let quirks_mode = win.Document().quirks_mode();
|
let quirks_mode = win.Document().quirks_mode();
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
let enabled = cond.eval(&context);
|
let enabled = cond.eval(&context);
|
||||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||||
|
|
|
@ -32,7 +32,7 @@ use std::cell::Cell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use style::attr::AttrValue;
|
use style::attr::AttrValue;
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::parser::{LengthParsingMode, ParserContext as CssParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext as CssParserContext};
|
||||||
use style::str::HTML_SPACE_CHARACTERS;
|
use style::str::HTML_SPACE_CHARACTERS;
|
||||||
use style::stylearc::Arc;
|
use style::stylearc::Arc;
|
||||||
use style::stylesheets::{CssRuleType, Stylesheet};
|
use style::stylesheets::{CssRuleType, Stylesheet};
|
||||||
|
@ -282,7 +282,7 @@ impl HTMLLinkElement {
|
||||||
let win = document.window();
|
let win = document.window();
|
||||||
let doc_url = document.url();
|
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,
|
PARSING_MODE_DEFAULT,
|
||||||
document.quirks_mode());
|
document.quirks_mode());
|
||||||
let media = parse_media_query_list(&context, &mut css_parser);
|
let media = parse_media_query_list(&context, &mut css_parser);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ use net_traits::ReferrerPolicy;
|
||||||
use script_layout_interface::message::Msg;
|
use script_layout_interface::message::Msg;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::parser::{LengthParsingMode, ParserContext as CssParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext as CssParserContext};
|
||||||
use style::stylearc::Arc;
|
use style::stylearc::Arc;
|
||||||
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
||||||
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};
|
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};
|
||||||
|
@ -88,7 +88,7 @@ impl HTMLStyleElement {
|
||||||
let context = CssParserContext::new_for_cssom(&url,
|
let context = CssParserContext::new_for_cssom(&url,
|
||||||
win.css_error_reporter(),
|
win.css_error_reporter(),
|
||||||
Some(CssRuleType::Media),
|
Some(CssRuleType::Media),
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
doc.quirks_mode());
|
doc.quirks_mode());
|
||||||
let shared_lock = node.owner_doc().style_shared_lock().clone();
|
let shared_lock = node.owner_doc().style_shared_lock().clone();
|
||||||
let mq = Arc::new(shared_lock.wrap(
|
let mq = Arc::new(shared_lock.wrap(
|
||||||
|
|
|
@ -14,7 +14,7 @@ use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use style::media_queries::{MediaQuery, parse_media_query_list};
|
use style::media_queries::{MediaQuery, parse_media_query_list};
|
||||||
use style::media_queries::MediaList as StyleMediaList;
|
use style::media_queries::MediaList as StyleMediaList;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::shared_lock::{SharedRwLock, Locked};
|
use style::shared_lock::{SharedRwLock, Locked};
|
||||||
use style::stylearc::Arc;
|
use style::stylearc::Arc;
|
||||||
use style::stylesheets::CssRuleType;
|
use style::stylesheets::CssRuleType;
|
||||||
|
@ -77,7 +77,7 @@ impl MediaListMethods for MediaList {
|
||||||
let url = win.get_url();
|
let url = win.get_url();
|
||||||
let quirks_mode = win.Document().quirks_mode();
|
let quirks_mode = win.Document().quirks_mode();
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
*media_queries = parse_media_query_list(&context, &mut parser);
|
*media_queries = parse_media_query_list(&context, &mut parser);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ impl MediaListMethods for MediaList {
|
||||||
let url = win.get_url();
|
let url = win.get_url();
|
||||||
let quirks_mode = win.Document().quirks_mode();
|
let quirks_mode = win.Document().quirks_mode();
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
let m = MediaQuery::parse(&context, &mut parser);
|
let m = MediaQuery::parse(&context, &mut parser);
|
||||||
// Step 2
|
// Step 2
|
||||||
|
@ -141,7 +141,7 @@ impl MediaListMethods for MediaList {
|
||||||
let url = win.get_url();
|
let url = win.get_url();
|
||||||
let quirks_mode = win.Document().quirks_mode();
|
let quirks_mode = win.Document().quirks_mode();
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
let m = MediaQuery::parse(&context, &mut parser);
|
let m = MediaQuery::parse(&context, &mut parser);
|
||||||
// Step 2
|
// Step 2
|
||||||
|
|
|
@ -104,7 +104,7 @@ use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
|
||||||
use style::context::ReflowGoal;
|
use style::context::ReflowGoal;
|
||||||
use style::error_reporting::ParseErrorReporter;
|
use style::error_reporting::ParseErrorReporter;
|
||||||
use style::media_queries;
|
use style::media_queries;
|
||||||
use style::parser::{LengthParsingMode, ParserContext as CssParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext as CssParserContext};
|
||||||
use style::properties::PropertyId;
|
use style::properties::PropertyId;
|
||||||
use style::properties::longhands::overflow_x;
|
use style::properties::longhands::overflow_x;
|
||||||
use style::selector_parser::PseudoElement;
|
use style::selector_parser::PseudoElement;
|
||||||
|
@ -978,7 +978,7 @@ impl WindowMethods for Window {
|
||||||
let url = self.get_url();
|
let url = self.get_url();
|
||||||
let quirks_mode = self.Document().quirks_mode();
|
let quirks_mode = self.Document().quirks_mode();
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
let media_query_list = media_queries::parse_media_query_list(&context, &mut parser);
|
let media_query_list = media_queries::parse_media_query_list(&context, &mut parser);
|
||||||
let document = self.Document();
|
let document = self.Document();
|
||||||
|
|
|
@ -334,6 +334,7 @@ mod bindings {
|
||||||
.bitfield_enum("nsChangeHint")
|
.bitfield_enum("nsChangeHint")
|
||||||
.bitfield_enum("nsRestyleHint")
|
.bitfield_enum("nsRestyleHint")
|
||||||
.constified_enum("UpdateAnimationsTasks")
|
.constified_enum("UpdateAnimationsTasks")
|
||||||
|
.constified_enum("ParsingMode")
|
||||||
.parse_callbacks(Box::new(Callbacks));
|
.parse_callbacks(Box::new(Callbacks));
|
||||||
let whitelist_vars = [
|
let whitelist_vars = [
|
||||||
"NS_AUTHOR_SPECIFIED_.*",
|
"NS_AUTHOR_SPECIFIED_.*",
|
||||||
|
@ -488,7 +489,7 @@ mod bindings {
|
||||||
"mozilla::DefaultDelete",
|
"mozilla::DefaultDelete",
|
||||||
"mozilla::Side",
|
"mozilla::Side",
|
||||||
"mozilla::binding_danger::AssertAndSuppressCleanupPolicy",
|
"mozilla::binding_danger::AssertAndSuppressCleanupPolicy",
|
||||||
"mozilla::LengthParsingMode",
|
"mozilla::ParsingMode",
|
||||||
"mozilla::InheritTarget",
|
"mozilla::InheritTarget",
|
||||||
];
|
];
|
||||||
let opaque_types = [
|
let opaque_types = [
|
||||||
|
@ -751,7 +752,7 @@ mod bindings {
|
||||||
"ServoStyleSheet",
|
"ServoStyleSheet",
|
||||||
"EffectCompositor_CascadeLevel",
|
"EffectCompositor_CascadeLevel",
|
||||||
"UpdateAnimationsTasks",
|
"UpdateAnimationsTasks",
|
||||||
"LengthParsingMode",
|
"ParsingMode",
|
||||||
"InheritTarget",
|
"InheritTarget",
|
||||||
"URLMatchingFunction",
|
"URLMatchingFunction",
|
||||||
];
|
];
|
||||||
|
|
|
@ -192,7 +192,7 @@ use gecko_bindings::structs::Loader;
|
||||||
use gecko_bindings::structs::ServoStyleSheet;
|
use gecko_bindings::structs::ServoStyleSheet;
|
||||||
use gecko_bindings::structs::EffectCompositor_CascadeLevel;
|
use gecko_bindings::structs::EffectCompositor_CascadeLevel;
|
||||||
use gecko_bindings::structs::UpdateAnimationsTasks;
|
use gecko_bindings::structs::UpdateAnimationsTasks;
|
||||||
use gecko_bindings::structs::LengthParsingMode;
|
use gecko_bindings::structs::ParsingMode;
|
||||||
use gecko_bindings::structs::InheritTarget;
|
use gecko_bindings::structs::InheritTarget;
|
||||||
use gecko_bindings::structs::URLMatchingFunction;
|
use gecko_bindings::structs::URLMatchingFunction;
|
||||||
pub type nsTArrayBorrowed_uintptr_t<'a> = &'a mut ::gecko_bindings::structs::nsTArray<usize>;
|
pub type nsTArrayBorrowed_uintptr_t<'a> = &'a mut ::gecko_bindings::structs::nsTArray<usize>;
|
||||||
|
@ -1865,7 +1865,7 @@ extern "C" {
|
||||||
pub fn Servo_ParseProperty(property: nsCSSPropertyID,
|
pub fn Servo_ParseProperty(property: nsCSSPropertyID,
|
||||||
value: *const nsACString,
|
value: *const nsACString,
|
||||||
data: *mut RawGeckoURLExtraData,
|
data: *mut RawGeckoURLExtraData,
|
||||||
length_parsing_mode: LengthParsingMode)
|
parsing_mode: ParsingMode)
|
||||||
-> RawServoDeclarationBlockStrong;
|
-> RawServoDeclarationBlockStrong;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -2034,8 +2034,8 @@ extern "C" {
|
||||||
value: *const nsACString,
|
value: *const nsACString,
|
||||||
is_important: bool,
|
is_important: bool,
|
||||||
data: *mut RawGeckoURLExtraData,
|
data: *mut RawGeckoURLExtraData,
|
||||||
length_parsing_mode:
|
parsing_mode: ParsingMode)
|
||||||
LengthParsingMode) -> bool;
|
-> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_DeclarationBlock_SetPropertyById(declarations:
|
pub fn Servo_DeclarationBlock_SetPropertyById(declarations:
|
||||||
|
@ -2045,8 +2045,7 @@ extern "C" {
|
||||||
is_important: bool,
|
is_important: bool,
|
||||||
data:
|
data:
|
||||||
*mut RawGeckoURLExtraData,
|
*mut RawGeckoURLExtraData,
|
||||||
length_parsing_mode:
|
parsing_mode: ParsingMode)
|
||||||
LengthParsingMode)
|
|
||||||
-> bool;
|
-> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@
|
||||||
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser};
|
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser};
|
||||||
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule};
|
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule};
|
||||||
use error_reporting::NullReporter;
|
use error_reporting::NullReporter;
|
||||||
use parser::{LengthParsingMode, ParserContext, log_css_error};
|
use parser::{PARSING_MODE_DEFAULT, ParserContext, log_css_error};
|
||||||
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
||||||
use properties::{PropertyDeclarationId, LonghandId, ParsedDeclaration};
|
use properties::{PropertyDeclarationId, LonghandId, ParsedDeclaration};
|
||||||
use properties::LonghandIdSet;
|
use properties::LonghandIdSet;
|
||||||
|
@ -131,7 +131,7 @@ impl Keyframe {
|
||||||
&parent_stylesheet.url_data,
|
&parent_stylesheet.url_data,
|
||||||
&error_reporter,
|
&error_reporter,
|
||||||
Some(CssRuleType::Keyframe),
|
Some(CssRuleType::Keyframe),
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
parent_stylesheet.quirks_mode);
|
parent_stylesheet.quirks_mode);
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
|
||||||
|
|
|
@ -10,21 +10,57 @@ use error_reporting::ParseErrorReporter;
|
||||||
use style_traits::OneOrMoreCommaSeparated;
|
use style_traits::OneOrMoreCommaSeparated;
|
||||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||||
|
|
||||||
/// The mode to use when parsing lengths.
|
bitflags! {
|
||||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
/// The mode to use when parsing values.
|
||||||
pub enum LengthParsingMode {
|
pub flags ParsingMode: u8 {
|
||||||
/// In CSS, lengths must have units, except for zero values, where the unit can be omitted.
|
/// In CSS, lengths must have units, except for zero values, where the unit can be omitted.
|
||||||
/// https://www.w3.org/TR/css3-values/#lengths
|
/// https://www.w3.org/TR/css3-values/#lengths
|
||||||
Default,
|
const PARSING_MODE_DEFAULT = 0x00,
|
||||||
/// In SVG, a coordinate or length value without a unit identifier (e.g., "25") is assumed to be in user units (px).
|
/// In SVG, a coordinate or length value without a unit identifier (e.g., "25") is assumed
|
||||||
/// https://www.w3.org/TR/SVG/coords.html#Units
|
/// to be in user units (px).
|
||||||
SVG,
|
/// https://www.w3.org/TR/SVG/coords.html#Units
|
||||||
|
const PARSING_MODE_ALLOW_UNITLESS_LENGTH = 0x01,
|
||||||
|
/// In SVG, out-of-range values are not treated as an error in parsing.
|
||||||
|
/// https://www.w3.org/TR/SVG/implnote.html#RangeClamping
|
||||||
|
const PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES = 0x02,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LengthParsingMode {
|
impl ParsingMode {
|
||||||
/// Whether the parsing mode allows unitless lengths for non-zero values to be intpreted as px.
|
/// Whether the parsing mode allows unitless lengths for non-zero values to be intpreted as px.
|
||||||
pub fn allows_unitless_lengths(&self) -> bool {
|
pub fn allows_unitless_lengths(&self) -> bool {
|
||||||
*self == LengthParsingMode::SVG
|
self.intersects(PARSING_MODE_ALLOW_UNITLESS_LENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the parsing mode allows all numeric values.
|
||||||
|
pub fn allows_all_numeric_values(&self) -> bool {
|
||||||
|
self.intersects(PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asserts that all ParsingMode flags have a matching ParsingMode value in gecko.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
#[inline]
|
||||||
|
pub fn assert_parsing_mode_match() {
|
||||||
|
use gecko_bindings::structs;
|
||||||
|
|
||||||
|
macro_rules! check_parsing_modes {
|
||||||
|
( $( $a:ident => $b:ident ),*, ) => {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
let mut modes = ParsingMode::all();
|
||||||
|
$(
|
||||||
|
assert_eq!(structs::$a as usize, $b.bits() as usize, stringify!($b));
|
||||||
|
modes.remove($b);
|
||||||
|
)*
|
||||||
|
assert_eq!(modes, ParsingMode::empty(), "all ParsingMode bits should have an assertion");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check_parsing_modes! {
|
||||||
|
ParsingMode_Default => PARSING_MODE_DEFAULT,
|
||||||
|
ParsingMode_AllowUnitlessLength => PARSING_MODE_ALLOW_UNITLESS_LENGTH,
|
||||||
|
ParsingMode_AllowAllNumericValues => PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +77,8 @@ pub struct ParserContext<'a> {
|
||||||
pub rule_type: Option<CssRuleType>,
|
pub rule_type: Option<CssRuleType>,
|
||||||
/// Line number offsets for inline stylesheets
|
/// Line number offsets for inline stylesheets
|
||||||
pub line_number_offset: u64,
|
pub line_number_offset: u64,
|
||||||
/// The mode to use when parsing lengths.
|
/// The mode to use when parsing.
|
||||||
pub length_parsing_mode: LengthParsingMode,
|
pub parsing_mode: ParsingMode,
|
||||||
/// The quirks mode of this stylesheet.
|
/// The quirks mode of this stylesheet.
|
||||||
pub quirks_mode: QuirksMode,
|
pub quirks_mode: QuirksMode,
|
||||||
}
|
}
|
||||||
|
@ -53,7 +89,7 @@ impl<'a> ParserContext<'a> {
|
||||||
url_data: &'a UrlExtraData,
|
url_data: &'a UrlExtraData,
|
||||||
error_reporter: &'a ParseErrorReporter,
|
error_reporter: &'a ParseErrorReporter,
|
||||||
rule_type: Option<CssRuleType>,
|
rule_type: Option<CssRuleType>,
|
||||||
length_parsing_mode: LengthParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode)
|
quirks_mode: QuirksMode)
|
||||||
-> ParserContext<'a> {
|
-> ParserContext<'a> {
|
||||||
ParserContext {
|
ParserContext {
|
||||||
|
@ -62,7 +98,7 @@ impl<'a> ParserContext<'a> {
|
||||||
error_reporter: error_reporter,
|
error_reporter: error_reporter,
|
||||||
rule_type: rule_type,
|
rule_type: rule_type,
|
||||||
line_number_offset: 0u64,
|
line_number_offset: 0u64,
|
||||||
length_parsing_mode: length_parsing_mode,
|
parsing_mode: parsing_mode,
|
||||||
quirks_mode: quirks_mode,
|
quirks_mode: quirks_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,10 +107,10 @@ impl<'a> ParserContext<'a> {
|
||||||
pub fn new_for_cssom(url_data: &'a UrlExtraData,
|
pub fn new_for_cssom(url_data: &'a UrlExtraData,
|
||||||
error_reporter: &'a ParseErrorReporter,
|
error_reporter: &'a ParseErrorReporter,
|
||||||
rule_type: Option<CssRuleType>,
|
rule_type: Option<CssRuleType>,
|
||||||
length_parsing_mode: LengthParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode)
|
quirks_mode: QuirksMode)
|
||||||
-> ParserContext<'a> {
|
-> ParserContext<'a> {
|
||||||
Self::new(Origin::Author, url_data, error_reporter, rule_type, length_parsing_mode, quirks_mode)
|
Self::new(Origin::Author, url_data, error_reporter, rule_type, parsing_mode, quirks_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a parser context based on a previous context, but with a modified rule type.
|
/// Create a parser context based on a previous context, but with a modified rule type.
|
||||||
|
@ -87,7 +123,7 @@ impl<'a> ParserContext<'a> {
|
||||||
error_reporter: context.error_reporter,
|
error_reporter: context.error_reporter,
|
||||||
rule_type: rule_type,
|
rule_type: rule_type,
|
||||||
line_number_offset: context.line_number_offset,
|
line_number_offset: context.line_number_offset,
|
||||||
length_parsing_mode: context.length_parsing_mode,
|
parsing_mode: context.parsing_mode,
|
||||||
quirks_mode: context.quirks_mode,
|
quirks_mode: context.quirks_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +133,7 @@ impl<'a> ParserContext<'a> {
|
||||||
url_data: &'a UrlExtraData,
|
url_data: &'a UrlExtraData,
|
||||||
error_reporter: &'a ParseErrorReporter,
|
error_reporter: &'a ParseErrorReporter,
|
||||||
line_number_offset: u64,
|
line_number_offset: u64,
|
||||||
length_parsing_mode: LengthParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode)
|
quirks_mode: QuirksMode)
|
||||||
-> ParserContext<'a> {
|
-> ParserContext<'a> {
|
||||||
ParserContext {
|
ParserContext {
|
||||||
|
@ -106,7 +142,7 @@ impl<'a> ParserContext<'a> {
|
||||||
error_reporter: error_reporter,
|
error_reporter: error_reporter,
|
||||||
rule_type: None,
|
rule_type: None,
|
||||||
line_number_offset: line_number_offset,
|
line_number_offset: line_number_offset,
|
||||||
length_parsing_mode: length_parsing_mode,
|
parsing_mode: parsing_mode,
|
||||||
quirks_mode: quirks_mode,
|
quirks_mode: quirks_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use context::QuirksMode;
|
||||||
use cssparser::{DeclarationListParser, parse_important};
|
use cssparser::{DeclarationListParser, parse_important};
|
||||||
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
||||||
use error_reporting::ParseErrorReporter;
|
use error_reporting::ParseErrorReporter;
|
||||||
use parser::{LengthParsingMode, ParserContext, log_css_error};
|
use parser::{PARSING_MODE_DEFAULT, ParsingMode, ParserContext, log_css_error};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||||
|
@ -649,7 +649,7 @@ pub fn parse_style_attribute(input: &str,
|
||||||
url_data,
|
url_data,
|
||||||
error_reporter,
|
error_reporter,
|
||||||
Some(CssRuleType::Style),
|
Some(CssRuleType::Style),
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
parse_property_declaration_list(&context, &mut Parser::new(input))
|
parse_property_declaration_list(&context, &mut Parser::new(input))
|
||||||
}
|
}
|
||||||
|
@ -663,14 +663,14 @@ pub fn parse_one_declaration(id: PropertyId,
|
||||||
input: &str,
|
input: &str,
|
||||||
url_data: &UrlExtraData,
|
url_data: &UrlExtraData,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter,
|
||||||
length_parsing_mode: LengthParsingMode,
|
parsing_mode: ParsingMode,
|
||||||
quirks_mode: QuirksMode)
|
quirks_mode: QuirksMode)
|
||||||
-> Result<ParsedDeclaration, ()> {
|
-> Result<ParsedDeclaration, ()> {
|
||||||
let context = ParserContext::new(Origin::Author,
|
let context = ParserContext::new(Origin::Author,
|
||||||
url_data,
|
url_data,
|
||||||
error_reporter,
|
error_reporter,
|
||||||
Some(CssRuleType::Style),
|
Some(CssRuleType::Style),
|
||||||
length_parsing_mode,
|
parsing_mode,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
Parser::new(input).parse_entirely(|parser| {
|
Parser::new(input).parse_entirely(|parser| {
|
||||||
ParsedDeclaration::parse(id, &context, parser)
|
ParsedDeclaration::parse(id, &context, parser)
|
||||||
|
|
|
@ -29,7 +29,7 @@ use font_metrics::FontMetricsProvider;
|
||||||
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
|
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
|
||||||
use logical_geometry::WritingMode;
|
use logical_geometry::WritingMode;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use parser::{LengthParsingMode, Parse, ParserContext};
|
use parser::{PARSING_MODE_DEFAULT, Parse, ParserContext};
|
||||||
use properties::animated_properties::TransitionProperty;
|
use properties::animated_properties::TransitionProperty;
|
||||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||||
use shared_lock::StylesheetGuards;
|
use shared_lock::StylesheetGuards;
|
||||||
|
@ -387,7 +387,7 @@ impl PropertyDeclarationIdSet {
|
||||||
url_data,
|
url_data,
|
||||||
error_reporter,
|
error_reporter,
|
||||||
None,
|
None,
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
quirks_mode);
|
quirks_mode);
|
||||||
Parser::new(&css).parse_entirely(|input| {
|
Parser::new(&css).parse_entirely(|input| {
|
||||||
match from_shorthand {
|
match from_shorthand {
|
||||||
|
|
|
@ -26,7 +26,7 @@ use gecko_bindings::sugar::refptr::RefPtr;
|
||||||
use keyframes::{Keyframe, parse_keyframe_list};
|
use keyframes::{Keyframe, parse_keyframe_list};
|
||||||
use media_queries::{Device, MediaList, parse_media_query_list};
|
use media_queries::{Device, MediaList, parse_media_query_list};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use parser::{LengthParsingMode, Parse, ParserContext, log_css_error};
|
use parser::{PARSING_MODE_DEFAULT, Parse, ParserContext, log_css_error};
|
||||||
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
|
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
|
||||||
use selector_parser::{SelectorImpl, SelectorParser};
|
use selector_parser::{SelectorImpl, SelectorParser};
|
||||||
use selectors::parser::SelectorList;
|
use selectors::parser::SelectorList;
|
||||||
|
@ -442,7 +442,7 @@ impl CssRule {
|
||||||
&parent_stylesheet.url_data,
|
&parent_stylesheet.url_data,
|
||||||
&error_reporter,
|
&error_reporter,
|
||||||
None,
|
None,
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
parent_stylesheet.quirks_mode);
|
parent_stylesheet.quirks_mode);
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
|
||||||
|
@ -744,7 +744,7 @@ impl Stylesheet {
|
||||||
shared_lock: shared_lock,
|
shared_lock: shared_lock,
|
||||||
loader: stylesheet_loader,
|
loader: stylesheet_loader,
|
||||||
context: ParserContext::new_with_line_number_offset(origin, url_data, error_reporter,
|
context: ParserContext::new_with_line_number_offset(origin, url_data, error_reporter,
|
||||||
line_number_offset, LengthParsingMode::Default,
|
line_number_offset, PARSING_MODE_DEFAULT,
|
||||||
quirks_mode),
|
quirks_mode),
|
||||||
state: Cell::new(State::Start),
|
state: Cell::new(State::Start),
|
||||||
};
|
};
|
||||||
|
|
|
@ -630,7 +630,7 @@ impl Length {
|
||||||
Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
|
Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
|
||||||
Length::parse_dimension(context, value.value, unit),
|
Length::parse_dimension(context, value.value, unit),
|
||||||
Token::Number(ref value) if num_context.is_ok(value.value) => {
|
Token::Number(ref value) if num_context.is_ok(value.value) => {
|
||||||
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() &&
|
if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||||
!allow_quirks.allowed(context.quirks_mode) {
|
!allow_quirks.allowed(context.quirks_mode) {
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
|
@ -972,7 +972,7 @@ impl LengthOrPercentageOrAuto {
|
||||||
Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
|
Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
|
||||||
Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))),
|
Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))),
|
||||||
Token::Number(ref value) if num_context.is_ok(value.value) => {
|
Token::Number(ref value) if num_context.is_ok(value.value) => {
|
||||||
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() &&
|
if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||||
!allow_quirks.allowed(context.quirks_mode) {
|
!allow_quirks.allowed(context.quirks_mode) {
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
|
@ -1080,7 +1080,7 @@ impl LengthOrPercentageOrNone {
|
||||||
Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
|
Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
|
||||||
Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))),
|
Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))),
|
||||||
Token::Number(value) if num_context.is_ok(value.value) => {
|
Token::Number(value) if num_context.is_ok(value.value) => {
|
||||||
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() &&
|
if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
|
||||||
!allow_quirks.allowed(context.quirks_mode) {
|
!allow_quirks.allowed(context.quirks_mode) {
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -632,12 +632,20 @@ impl Number {
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
|
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
|
||||||
parse_number_with_clamping_mode(context, input, AllowedNumericType::NonNegative)
|
if context.parsing_mode.allows_all_numeric_values() {
|
||||||
|
parse_number(context, input)
|
||||||
|
} else {
|
||||||
|
parse_number_with_clamping_mode(context, input, AllowedNumericType::NonNegative)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn parse_at_least_one(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
|
pub fn parse_at_least_one(context: &ParserContext, input: &mut Parser) -> Result<Number, ()> {
|
||||||
parse_number_with_clamping_mode(context, input, AllowedNumericType::AtLeastOne)
|
if context.parsing_mode.allows_all_numeric_values() {
|
||||||
|
parse_number(context, input)
|
||||||
|
} else {
|
||||||
|
parse_number_with_clamping_mode(context, input, AllowedNumericType::AtLeastOne)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ use style::gecko_properties::{self, style_structs};
|
||||||
use style::keyframes::KeyframesStepValue;
|
use style::keyframes::KeyframesStepValue;
|
||||||
use style::media_queries::{MediaList, parse_media_query_list};
|
use style::media_queries::{MediaList, parse_media_query_list};
|
||||||
use style::parallel;
|
use style::parallel;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration, StyleBuilder};
|
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration, StyleBuilder};
|
||||||
use style::properties::{LonghandIdSet, PropertyDeclarationBlock, PropertyId};
|
use style::properties::{LonghandIdSet, PropertyDeclarationBlock, PropertyId};
|
||||||
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||||
|
@ -115,6 +115,8 @@ static mut DUMMY_URL_DATA: *mut URLExtraData = 0 as *mut URLExtraData;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
|
pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
|
||||||
|
use style::parser::assert_parsing_mode_match;
|
||||||
|
|
||||||
// Initialize logging.
|
// Initialize logging.
|
||||||
let mut builder = LogBuilder::new();
|
let mut builder = LogBuilder::new();
|
||||||
let default_level = if cfg!(debug_assertions) { "warn" } else { "error" };
|
let default_level = if cfg!(debug_assertions) { "warn" } else { "error" };
|
||||||
|
@ -128,6 +130,7 @@ pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
|
||||||
|
|
||||||
// Perform some debug-only runtime assertions.
|
// Perform some debug-only runtime assertions.
|
||||||
restyle_hints::assert_restyle_hints_match();
|
restyle_hints::assert_restyle_hints_match();
|
||||||
|
assert_parsing_mode_match();
|
||||||
|
|
||||||
// Initialize some static data.
|
// Initialize some static data.
|
||||||
gecko_properties::initialize();
|
gecko_properties::initialize();
|
||||||
|
@ -1133,30 +1136,29 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) {
|
||||||
fn parse_property(property_id: PropertyId,
|
fn parse_property(property_id: PropertyId,
|
||||||
value: *const nsACString,
|
value: *const nsACString,
|
||||||
data: *mut URLExtraData,
|
data: *mut URLExtraData,
|
||||||
length_parsing_mode: structs::LengthParsingMode) -> Result<ParsedDeclaration, ()> {
|
parsing_mode: structs::ParsingMode) -> Result<ParsedDeclaration, ()> {
|
||||||
|
use style::parser::ParsingMode;
|
||||||
|
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||||
let length_parsing_mode = match length_parsing_mode {
|
let parsing_mode = ParsingMode::from_bits_truncate(parsing_mode);
|
||||||
structs::LengthParsingMode::Default => LengthParsingMode::Default,
|
|
||||||
structs::LengthParsingMode::SVG => LengthParsingMode::SVG,
|
|
||||||
};
|
|
||||||
|
|
||||||
parse_one_declaration(property_id,
|
parse_one_declaration(property_id,
|
||||||
value,
|
value,
|
||||||
url_data,
|
url_data,
|
||||||
&RustLogReporter,
|
&RustLogReporter,
|
||||||
length_parsing_mode,
|
parsing_mode,
|
||||||
QuirksMode::NoQuirks)
|
QuirksMode::NoQuirks)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseProperty(property: nsCSSPropertyID, value: *const nsACString,
|
pub extern "C" fn Servo_ParseProperty(property: nsCSSPropertyID, value: *const nsACString,
|
||||||
data: *mut URLExtraData,
|
data: *mut URLExtraData,
|
||||||
length_parsing_mode: structs::LengthParsingMode)
|
parsing_mode: structs::ParsingMode)
|
||||||
-> RawServoDeclarationBlockStrong {
|
-> RawServoDeclarationBlockStrong {
|
||||||
let id = get_property_id_from_nscsspropertyid!(property,
|
let id = get_property_id_from_nscsspropertyid!(property,
|
||||||
RawServoDeclarationBlockStrong::null());
|
RawServoDeclarationBlockStrong::null());
|
||||||
match parse_property(id, value, data, length_parsing_mode) {
|
match parse_property(id, value, data, parsing_mode) {
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
let mut block = PropertyDeclarationBlock::new();
|
let mut block = PropertyDeclarationBlock::new();
|
||||||
|
@ -1180,7 +1182,7 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
|
||||||
url_data,
|
url_data,
|
||||||
&reporter,
|
&reporter,
|
||||||
Some(CssRuleType::Style),
|
Some(CssRuleType::Style),
|
||||||
LengthParsingMode::Default,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
let easing = unsafe { (*easing).to_string() };
|
let easing = unsafe { (*easing).to_string() };
|
||||||
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) {
|
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) {
|
||||||
|
@ -1314,8 +1316,8 @@ pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: Ra
|
||||||
|
|
||||||
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
||||||
value: *const nsACString, is_important: bool, data: *mut URLExtraData,
|
value: *const nsACString, is_important: bool, data: *mut URLExtraData,
|
||||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
parsing_mode: structs::ParsingMode) -> bool {
|
||||||
match parse_property(property_id, value, data, length_parsing_mode) {
|
match parse_property(property_id, value, data, parsing_mode) {
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
||||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||||
|
@ -1330,18 +1332,18 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property: *const nsACString, value: *const nsACString,
|
property: *const nsACString, value: *const nsACString,
|
||||||
is_important: bool, data: *mut URLExtraData,
|
is_important: bool, data: *mut URLExtraData,
|
||||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
parsing_mode: structs::ParsingMode) -> bool {
|
||||||
set_property(declarations, get_property_id_from_property!(property, false),
|
set_property(declarations, get_property_id_from_property!(property, false),
|
||||||
value, is_important, data, length_parsing_mode)
|
value, is_important, data, parsing_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property: nsCSSPropertyID, value: *const nsACString,
|
property: nsCSSPropertyID, value: *const nsACString,
|
||||||
is_important: bool, data: *mut URLExtraData,
|
is_important: bool, data: *mut URLExtraData,
|
||||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
parsing_mode: structs::ParsingMode) -> bool {
|
||||||
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
||||||
value, is_important, data, length_parsing_mode)
|
value, is_important, data, parsing_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
||||||
|
@ -1410,7 +1412,7 @@ pub extern "C" fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed, text:
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let reporter = RustLogReporter;
|
let reporter = RustLogReporter;
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
write_locked_arc(list, |list: &mut MediaList| {
|
write_locked_arc(list, |list: &mut MediaList| {
|
||||||
*list = parse_media_query_list(&context, &mut parser);
|
*list = parse_media_query_list(&context, &mut parser);
|
||||||
|
@ -1442,7 +1444,7 @@ pub extern "C" fn Servo_MediaList_AppendMedium(list: RawServoMediaListBorrowed,
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let reporter = RustLogReporter;
|
let reporter = RustLogReporter;
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
write_locked_arc(list, |list: &mut MediaList| {
|
write_locked_arc(list, |list: &mut MediaList| {
|
||||||
list.append_medium(&context, new_medium);
|
list.append_medium(&context, new_medium);
|
||||||
|
@ -1456,7 +1458,7 @@ pub extern "C" fn Servo_MediaList_DeleteMedium(list: RawServoMediaListBorrowed,
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let reporter = RustLogReporter;
|
let reporter = RustLogReporter;
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
|
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
|
||||||
}
|
}
|
||||||
|
@ -1810,7 +1812,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(declarations:
|
||||||
let string = unsafe { (*value).to_string() };
|
let string = unsafe { (*value).to_string() };
|
||||||
let error_reporter = RustLogReporter;
|
let error_reporter = RustLogReporter;
|
||||||
let context = ParserContext::new(Origin::Author, url_data, &error_reporter,
|
let context = ParserContext::new(Origin::Author, url_data, &error_reporter,
|
||||||
Some(CssRuleType::Style), LengthParsingMode::Default,
|
Some(CssRuleType::Style), PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
if let Ok(url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
|
if let Ok(url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
|
||||||
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
||||||
|
@ -1842,7 +1844,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(declarat
|
||||||
pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const nsACString) -> bool {
|
pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const nsACString) -> bool {
|
||||||
let id = get_property_id_from_property!(property, false);
|
let id = get_property_id_from_property!(property, false);
|
||||||
|
|
||||||
parse_property(id, value, unsafe { DUMMY_URL_DATA }, structs::LengthParsingMode::Default).is_ok()
|
parse_property(id, value, unsafe { DUMMY_URL_DATA }, structs::ParsingMode_Default).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1854,7 +1856,7 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let reporter = RustLogReporter;
|
let reporter = RustLogReporter;
|
||||||
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
cond.eval(&context)
|
cond.eval(&context)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use cssparser::Parser;
|
||||||
use media_queries::CSSErrorReporterTest;
|
use media_queries::CSSErrorReporterTest;
|
||||||
use parsing::parse;
|
use parsing::parse;
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
use style::parser::{LengthParsingMode, Parse, ParserContext};
|
use style::parser::{PARSING_MODE_ALLOW_UNITLESS_LENGTH, Parse, ParserContext};
|
||||||
use style::stylesheets::{CssRuleType, Origin};
|
use style::stylesheets::{CssRuleType, Origin};
|
||||||
use style::values::Either;
|
use style::values::Either;
|
||||||
use style::values::specified::{LengthOrPercentageOrNumber, Number};
|
use style::values::specified::{LengthOrPercentageOrNumber, Number};
|
||||||
|
@ -35,7 +35,7 @@ fn test_length_literals() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_length_parsing_modes() {
|
fn test_parsing_modes() {
|
||||||
// In default length mode, non-zero lengths must have a unit.
|
// In default length mode, non-zero lengths must have a unit.
|
||||||
assert!(parse(Length::parse, "1").is_err());
|
assert!(parse(Length::parse, "1").is_err());
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ fn test_length_parsing_modes() {
|
||||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||||
let reporter = CSSErrorReporterTest;
|
let reporter = CSSErrorReporterTest;
|
||||||
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
||||||
Some(CssRuleType::Style), LengthParsingMode::SVG,
|
Some(CssRuleType::Style), PARSING_MODE_ALLOW_UNITLESS_LENGTH,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
let mut parser = Parser::new("1");
|
let mut parser = Parser::new("1");
|
||||||
let result = Length::parse(&context, &mut parser);
|
let result = Length::parse(&context, &mut parser);
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use media_queries::CSSErrorReporterTest;
|
use media_queries::CSSErrorReporterTest;
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::stylesheets::{CssRuleType, Origin};
|
use style::stylesheets::{CssRuleType, Origin};
|
||||||
|
|
||||||
fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
|
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 url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||||
let reporter = CSSErrorReporterTest;
|
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
let mut parser = Parser::new(s);
|
let mut parser = Parser::new(s);
|
||||||
f(&context, &mut parser)
|
f(&context, &mut parser)
|
||||||
|
|
|
@ -3,8 +3,13 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
use cssparser::Parser;
|
||||||
|
use media_queries::CSSErrorReporterTest;
|
||||||
|
use style::context::QuirksMode;
|
||||||
|
use style::parser::{PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES, ParserContext};
|
||||||
|
use style::stylesheets::{CssRuleType, Origin};
|
||||||
use style::values::HasViewportPercentage;
|
use style::values::HasViewportPercentage;
|
||||||
use style::values::specified::{AbsoluteLength, NoCalcLength, ViewportPercentageLength};
|
use style::values::specified::{AbsoluteLength, NoCalcLength, Number, ViewportPercentageLength};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn length_has_viewport_percentage() {
|
fn length_has_viewport_percentage() {
|
||||||
|
@ -13,3 +18,18 @@ fn length_has_viewport_percentage() {
|
||||||
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
|
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
|
||||||
assert!(!l.has_viewport_percentage());
|
assert!(!l.has_viewport_percentage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parsing_allo_all_numeric_values() {
|
||||||
|
// 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), PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES,
|
||||||
|
QuirksMode::NoQuirks);
|
||||||
|
let mut parser = Parser::new("-1");
|
||||||
|
let result = Number::parse_non_negative(&context, &mut parser);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(result.unwrap(), Number::new(-1.));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use media_queries::CSSErrorReporterTest;
|
use media_queries::CSSErrorReporterTest;
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
use style::parser::{LengthParsingMode, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||||
use style::stylesheets::{CssRuleType, Origin};
|
use style::stylesheets::{CssRuleType, Origin};
|
||||||
|
|
||||||
fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
|
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 url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||||
let reporter = CSSErrorReporterTest;
|
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
let mut parser = Parser::new(s);
|
let mut parser = Parser::new(s);
|
||||||
f(&context, &mut parser)
|
f(&context, &mut parser)
|
||||||
|
|
|
@ -9,7 +9,7 @@ use servo_config::prefs::{PREFS, PrefValue};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
use style::media_queries::{Device, MediaList, MediaType};
|
use style::media_queries::{Device, MediaList, MediaType};
|
||||||
use style::parser::{LengthParsingMode, Parse, ParserContext};
|
use style::parser::{PARSING_MODE_DEFAULT, Parse, ParserContext};
|
||||||
use style::shared_lock::SharedRwLock;
|
use style::shared_lock::SharedRwLock;
|
||||||
use style::stylearc::Arc;
|
use style::stylearc::Arc;
|
||||||
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
||||||
|
@ -295,7 +295,7 @@ fn constrain_viewport() {
|
||||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||||
let reporter = CSSErrorReporterTest;
|
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,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks);
|
||||||
|
|
||||||
macro_rules! from_css {
|
macro_rules! from_css {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue