servo: Merge #16609 - Implement unitless length quirk (from nox:quirks); r=Manishearth,emilio

The Gecko side doesn't propagate its quirks mode yet.

Source-Repo: https://github.com/servo/servo
Source-Revision: d8bcc0db1aad26e007b7e2bdeda3cea4953c0db0

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 9dc47c4a8059e1788be23db57794b77e2b0c010d
This commit is contained in:
Anthony Ramine 2017-04-27 22:32:24 -05:00
Родитель 873955b81f
Коммит 3cebcd4d00
57 изменённых файлов: 499 добавлений и 180 удалений

Просмотреть файл

@ -601,7 +601,7 @@ impl LayoutThread {
Msg::AddStylesheet(style_info) => { Msg::AddStylesheet(style_info) => {
self.handle_add_stylesheet(style_info, possibly_locked_rw_data) self.handle_add_stylesheet(style_info, possibly_locked_rw_data)
} }
Msg::SetQuirksMode => self.handle_set_quirks_mode(possibly_locked_rw_data), Msg::SetQuirksMode(mode) => self.handle_set_quirks_mode(possibly_locked_rw_data, mode),
Msg::GetRPC(response_chan) => { Msg::GetRPC(response_chan) => {
response_chan.send(box LayoutRPCImpl(self.rw_data.clone()) as response_chan.send(box LayoutRPCImpl(self.rw_data.clone()) as
Box<LayoutRPC + Send>).unwrap(); Box<LayoutRPC + Send>).unwrap();
@ -772,9 +772,11 @@ impl LayoutThread {
} }
/// Sets quirks mode for the document, causing the quirks mode stylesheet to be used. /// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
fn handle_set_quirks_mode<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) { fn handle_set_quirks_mode<'a, 'b>(&self,
possibly_locked_rw_data: &mut RwData<'a, 'b>,
quirks_mode: QuirksMode) {
let mut rw_data = possibly_locked_rw_data.lock(); let mut rw_data = possibly_locked_rw_data.lock();
Arc::get_mut(&mut rw_data.stylist).unwrap().set_quirks_mode(true); Arc::get_mut(&mut rw_data.stylist).unwrap().set_quirks_mode(quirks_mode);
possibly_locked_rw_data.block(rw_data); possibly_locked_rw_data.block(rw_data);
} }
@ -1587,7 +1589,8 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
MediaList::empty(), MediaList::empty(),
shared_lock.clone(), shared_lock.clone(),
None, None,
&NullReporter)) &NullReporter,
QuirksMode::NoQuirks))
} }
let shared_lock = SharedRwLock::new(); let shared_lock = SharedRwLock::new();
@ -1600,7 +1603,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
for &(ref contents, ref url) in &opts::get().user_stylesheets { for &(ref contents, ref url) in &opts::get().user_stylesheets {
user_or_user_agent_stylesheets.push(Stylesheet::from_bytes( user_or_user_agent_stylesheets.push(Stylesheet::from_bytes(
&contents, url.clone(), None, None, Origin::User, MediaList::empty(), &contents, url.clone(), None, None, Origin::User, MediaList::empty(),
shared_lock.clone(), None, &RustLogReporter)); shared_lock.clone(), None, &RustLogReporter, QuirksMode::NoQuirks));
} }
let quirks_mode_stylesheet = try!(parse_ua_stylesheet(&shared_lock, "quirks-mode.css")); let quirks_mode_stylesheet = try!(parse_ua_stylesheet(&shared_lock, "quirks-mode.css"));

Просмотреть файл

@ -9,6 +9,7 @@ use dom::bindings::reflector::Reflector;
use dom::bindings::str::DOMString; 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::parser::{LengthParsingMode, ParserContext}; use style::parser::{LengthParsingMode, 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};
@ -31,7 +32,8 @@ 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); LengthParsingMode::Default,
QuirksMode::NoQuirks);
decl.eval(&context) decl.eval(&context)
} }
@ -42,7 +44,8 @@ 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); LengthParsingMode::Default,
QuirksMode::NoQuirks);
cond.eval(&context) cond.eval(&context)
} else { } else {
false false

Просмотреть файл

@ -5,6 +5,7 @@
use cssparser::Parser; use cssparser::Parser;
use dom::bindings::codegen::Bindings::CSSMediaRuleBinding; use dom::bindings::codegen::Bindings::CSSMediaRuleBinding;
use dom::bindings::codegen::Bindings::CSSMediaRuleBinding::CSSMediaRuleMethods; use dom::bindings::codegen::Bindings::CSSMediaRuleBinding::CSSMediaRuleMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use dom::bindings::js::{MutNullableJS, Root}; use dom::bindings::js::{MutNullableJS, Root};
use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
@ -72,8 +73,10 @@ impl CSSMediaRule {
let global = self.global(); let global = self.global();
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
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); LengthParsingMode::Default,
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();

Просмотреть файл

@ -256,9 +256,12 @@ impl CSSStyleDeclaration {
// Step 6 // Step 6
let window = self.owner.window(); let window = self.owner.window();
let quirks_mode = window.Document().quirks_mode();
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(), LengthParsingMode::Default); window.css_error_reporter(),
LengthParsingMode::Default,
quirks_mode);
// Step 7 // Step 7
let parsed = match result { let parsed = match result {
@ -434,11 +437,13 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
return Err(Error::NoModificationAllowed); return Err(Error::NoModificationAllowed);
} }
let quirks_mode = window.Document().quirks_mode();
self.owner.mutate_associated_block(|mut pdb, mut _changed| { self.owner.mutate_associated_block(|mut pdb, mut _changed| {
// Step 3 // Step 3
*pdb = parse_style_attribute(&value, *pdb = parse_style_attribute(&value,
&self.owner.base_url(), &self.owner.base_url(),
window.css_error_reporter()); window.css_error_reporter(),
quirks_mode);
}); });
Ok(()) Ok(())

Просмотреть файл

@ -61,8 +61,10 @@ impl CSSSupportsRule {
let global = self.global(); let global = self.global();
let win = global.as_window(); let win = global.as_window();
let url = win.Document().url(); let url = win.Document().url();
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); LengthParsingMode::Default,
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();
let rule = self.supportsrule.write_with(&mut guard); let rule = self.supportsrule.write_with(&mut guard);

Просмотреть файл

@ -542,7 +542,7 @@ impl Document {
self.quirks_mode.set(mode); self.quirks_mode.set(mode);
if mode == QuirksMode::Quirks { if mode == QuirksMode::Quirks {
self.window.layout_chan().send(Msg::SetQuirksMode).unwrap(); self.window.layout_chan().send(Msg::SetQuirksMode(mode)).unwrap();
} }
} }

Просмотреть файл

@ -2196,7 +2196,8 @@ impl VirtualMethods for Element {
Arc::new(doc.style_shared_lock().wrap(parse_style_attribute( Arc::new(doc.style_shared_lock().wrap(parse_style_attribute(
&attr.value(), &attr.value(),
&doc.base_url(), &doc.base_url(),
win.css_error_reporter()))) win.css_error_reporter(),
doc.quirks_mode())))
}; };
Some(block) Some(block)

Просмотреть файл

@ -282,7 +282,8 @@ 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); LengthParsingMode::Default,
document.quirks_mode());
let media = parse_media_query_list(&context, &mut css_parser); let media = parse_media_query_list(&context, &mut css_parser);
let im_attribute = element.get_attribute(&ns!(), &local_name!("integrity")); let im_attribute = element.get_attribute(&ns!(), &local_name!("integrity"));

Просмотреть файл

@ -113,6 +113,7 @@ impl HTMLMetaElement {
// force all styles to be recomputed. // force all styles to be recomputed.
dirty_on_viewport_size_change: AtomicBool::new(false), dirty_on_viewport_size_change: AtomicBool::new(false),
disabled: AtomicBool::new(false), disabled: AtomicBool::new(false),
quirks_mode: document.quirks_mode(),
})); }));
let doc = document_from_node(self); let doc = document_from_node(self);
doc.invalidate_stylesheets(); doc.invalidate_stylesheets();

Просмотреть файл

@ -76,6 +76,7 @@ impl HTMLStyleElement {
assert!(node.is_in_doc()); assert!(node.is_in_doc());
let win = window_from_node(node); let win = window_from_node(node);
let doc = document_from_node(self);
let mq_attribute = element.get_attribute(&ns!(), &local_name!("media")); let mq_attribute = element.get_attribute(&ns!(), &local_name!("media"));
let mq_str = match mq_attribute { let mq_str = match mq_attribute {
@ -88,7 +89,8 @@ 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); LengthParsingMode::Default,
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(
parse_media_query_list(&context, &mut CssParser::new(&mq_str)))); parse_media_query_list(&context, &mut CssParser::new(&mq_str))));
@ -96,6 +98,7 @@ impl HTMLStyleElement {
let sheet = Stylesheet::from_str(&data, win.get_url(), Origin::Author, mq, let sheet = Stylesheet::from_str(&data, win.get_url(), Origin::Author, mq,
shared_lock, Some(&loader), shared_lock, Some(&loader),
win.css_error_reporter(), win.css_error_reporter(),
doc.quirks_mode(),
self.line_number); self.line_number);
let sheet = Arc::new(sheet); let sheet = Arc::new(sheet);
@ -107,7 +110,6 @@ impl HTMLStyleElement {
win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap(); win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap();
*self.stylesheet.borrow_mut() = Some(sheet); *self.stylesheet.borrow_mut() = Some(sheet);
let doc = document_from_node(self);
doc.invalidate_stylesheets(); doc.invalidate_stylesheets();
} }

Просмотреть файл

@ -5,6 +5,7 @@
use cssparser::Parser; use cssparser::Parser;
use dom::bindings::codegen::Bindings::MediaListBinding; use dom::bindings::codegen::Bindings::MediaListBinding;
use dom::bindings::codegen::Bindings::MediaListBinding::MediaListMethods; use dom::bindings::codegen::Bindings::MediaListBinding::MediaListMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use dom::bindings::js::{JS, Root}; use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
@ -74,8 +75,10 @@ impl MediaListMethods for MediaList {
let global = self.global(); let global = self.global();
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
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); LengthParsingMode::Default,
quirks_mode);
*media_queries = parse_media_query_list(&context, &mut parser); *media_queries = parse_media_query_list(&context, &mut parser);
} }
@ -108,8 +111,10 @@ impl MediaListMethods for MediaList {
let global = self.global(); let global = self.global();
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
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); LengthParsingMode::Default,
quirks_mode);
let m = MediaQuery::parse(&context, &mut parser); let m = MediaQuery::parse(&context, &mut parser);
// Step 2 // Step 2
if let Err(_) = m { if let Err(_) = m {
@ -134,8 +139,10 @@ impl MediaListMethods for MediaList {
let global = self.global(); let global = self.global();
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
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); LengthParsingMode::Default,
quirks_mode);
let m = MediaQuery::parse(&context, &mut parser); let m = MediaQuery::parse(&context, &mut parser);
// Step 2 // Step 2
if let Err(_) = m { if let Err(_) = m {

Просмотреть файл

@ -77,7 +77,7 @@ impl MediaQueryList {
if let Some(window_size) = self.document.window().window_size() { if let Some(window_size) = self.document.window().window_size() {
let viewport_size = window_size.initial_viewport; let viewport_size = window_size.initial_viewport;
let device = Device::new(MediaType::Screen, viewport_size); let device = Device::new(MediaType::Screen, viewport_size);
self.media_query_list.evaluate(&device) self.media_query_list.evaluate(&device, self.document.quirks_mode())
} else { } else {
false false
} }

Просмотреть файл

@ -976,8 +976,10 @@ impl WindowMethods for Window {
fn MatchMedia(&self, query: DOMString) -> Root<MediaQueryList> { fn MatchMedia(&self, query: DOMString) -> Root<MediaQueryList> {
let mut parser = Parser::new(&query); let mut parser = Parser::new(&query);
let url = self.get_url(); let url = self.get_url();
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); LengthParsingMode::Default,
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();
let mql = MediaQueryList::new(&document, media_query_list); let mql = MediaQueryList::new(&document, media_query_list);

Просмотреть файл

@ -144,7 +144,8 @@ impl FetchResponseListener for StylesheetContext {
media.take().unwrap(), media.take().unwrap(),
shared_lock, shared_lock,
Some(&loader), Some(&loader),
win.css_error_reporter())); win.css_error_reporter(),
document.quirks_mode()));
if link.is_alternate() { if link.is_alternate() {
sheet.set_disabled(true); sheet.set_disabled(true);

Просмотреть файл

@ -17,7 +17,7 @@ use script_traits::{LayoutMsg as ConstellationMsg, StackingContextScrollState, W
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::sync::Arc; use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::{Receiver, Sender};
use style::context::ReflowGoal; use style::context::{QuirksMode, ReflowGoal};
use style::properties::PropertyId; use style::properties::PropertyId;
use style::selector_parser::PseudoElement; use style::selector_parser::PseudoElement;
use style::stylesheets::Stylesheet; use style::stylesheets::Stylesheet;
@ -27,8 +27,8 @@ pub enum Msg {
/// Adds the given stylesheet to the document. /// Adds the given stylesheet to the document.
AddStylesheet(Arc<Stylesheet>), AddStylesheet(Arc<Stylesheet>),
/// Puts a document into quirks mode, causing the quirks mode stylesheet to be loaded. /// Change the quirks mode.
SetQuirksMode, SetQuirksMode(QuirksMode),
/// Requests a reflow. /// Requests a reflow.
Reflow(ScriptReflow), Reflow(ScriptReflow),

Просмотреть файл

@ -468,7 +468,8 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
/* cascade_info = */ None, /* cascade_info = */ None,
&*context.error_reporter, &*context.error_reporter,
font_metrics_provider, font_metrics_provider,
CascadeFlags::empty()); CascadeFlags::empty(),
context.quirks_mode);
computed computed
} }
} }

Просмотреть файл

@ -6,6 +6,7 @@
extern crate encoding; extern crate encoding;
use context::QuirksMode;
use cssparser::{stylesheet_encoding, EncodingSupport}; use cssparser::{stylesheet_encoding, EncodingSupport};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
use media_queries::MediaList; use media_queries::MediaList;
@ -56,7 +57,8 @@ impl Stylesheet {
media: MediaList, media: MediaList,
shared_lock: SharedRwLock, shared_lock: SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter) error_reporter: &ParseErrorReporter,
quirks_mode: QuirksMode)
-> Stylesheet { -> Stylesheet {
let (string, _) = decode_stylesheet_bytes( let (string, _) = decode_stylesheet_bytes(
bytes, protocol_encoding_label, environment_encoding); bytes, protocol_encoding_label, environment_encoding);
@ -67,6 +69,7 @@ impl Stylesheet {
shared_lock, shared_lock,
stylesheet_loader, stylesheet_loader,
error_reporter, error_reporter,
quirks_mode,
0u64) 0u64)
} }

Просмотреть файл

@ -5,6 +5,7 @@
//! Gecko's media-query device and expression representation. //! Gecko's media-query device and expression representation.
use app_units::Au; use app_units::Au;
use context::QuirksMode;
use cssparser::{CssStringWriter, Parser, Token}; use cssparser::{CssStringWriter, Parser, Token};
use euclid::Size2D; use euclid::Size2D;
use font_metrics::get_metrics_provider_for_product; use font_metrics::get_metrics_provider_for_product;
@ -521,7 +522,7 @@ impl Expression {
} }
/// Returns whether this media query evaluates to true for the given device. /// Returns whether this media query evaluates to true for the given device.
pub fn matches(&self, device: &Device) -> bool { pub fn matches(&self, device: &Device, quirks_mode: QuirksMode) -> bool {
let mut css_value = nsCSSValue::null(); let mut css_value = nsCSSValue::null();
unsafe { unsafe {
(self.feature.mGetter.unwrap())(device.pres_context, (self.feature.mGetter.unwrap())(device.pres_context,
@ -534,12 +535,13 @@ impl Expression {
None => return false, None => return false,
}; };
self.evaluate_against(device, &value) self.evaluate_against(device, &value, quirks_mode)
} }
fn evaluate_against(&self, fn evaluate_against(&self,
device: &Device, device: &Device,
actual_value: &MediaExpressionValue) actual_value: &MediaExpressionValue,
quirks_mode: QuirksMode)
-> bool { -> bool {
use self::MediaExpressionValue::*; use self::MediaExpressionValue::*;
use std::cmp::Ordering; use std::cmp::Ordering;
@ -564,6 +566,8 @@ impl Expression {
style: default_values.clone(), style: default_values.clone(),
font_metrics_provider: &provider, font_metrics_provider: &provider,
in_media_query: true, in_media_query: true,
// TODO: pass the correct value here.
quirks_mode: quirks_mode,
}; };
let required_value = match self.value { let required_value = match self.value {

Просмотреть файл

@ -16,7 +16,7 @@
use app_units::Au; use app_units::Au;
use atomic_refcell::AtomicRefCell; use atomic_refcell::AtomicRefCell;
use context::{SharedStyleContext, UpdateAnimationsTasks}; use context::{QuirksMode, SharedStyleContext, UpdateAnimationsTasks};
use data::ElementData; use data::ElementData;
use dom::{self, AnimationRules, DescendantsBit, LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode}; use dom::{self, AnimationRules, DescendantsBit, LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode};
use dom::{OpaqueNode, PresentationalHintsSynthetizer}; use dom::{OpaqueNode, PresentationalHintsSynthetizer};
@ -325,7 +325,7 @@ impl<'le> GeckoElement<'le> {
/// Parse the style attribute of an element. /// Parse the style attribute of an element.
pub fn parse_style_attribute(value: &str, pub fn parse_style_attribute(value: &str,
url_data: &UrlExtraData) -> PropertyDeclarationBlock { url_data: &UrlExtraData) -> PropertyDeclarationBlock {
parse_style_attribute(value, url_data, &RustLogReporter) parse_style_attribute(value, url_data, &RustLogReporter, QuirksMode::NoQuirks)
} }
fn flags(&self) -> u32 { fn flags(&self) -> u32 {

Просмотреть файл

@ -131,7 +131,8 @@ impl Keyframe {
&parent_stylesheet.url_data, &parent_stylesheet.url_data,
&error_reporter, &error_reporter,
Some(CssRuleType::Keyframe), Some(CssRuleType::Keyframe),
LengthParsingMode::Default); LengthParsingMode::Default,
parent_stylesheet.quirks_mode);
let mut input = Parser::new(css); let mut input = Parser::new(css);
let mut rule_parser = KeyframeListParser { let mut rule_parser = KeyframeListParser {

Просмотреть файл

@ -483,7 +483,8 @@ trait PrivateMatchMethods: TElement {
Some(&mut cascade_info), Some(&mut cascade_info),
&*shared_context.error_reporter, &*shared_context.error_reporter,
font_metrics_provider, font_metrics_provider,
cascade_flags)); cascade_flags,
shared_context.quirks_mode));
cascade_info.finish(&self.as_node()); cascade_info.finish(&self.as_node());
values values

Просмотреть файл

@ -7,6 +7,7 @@
//! [mq]: https://drafts.csswg.org/mediaqueries/ //! [mq]: https://drafts.csswg.org/mediaqueries/
use Atom; use Atom;
use context::QuirksMode;
use cssparser::{Delimiter, Parser, Token}; use cssparser::{Delimiter, Parser, Token};
use parser::ParserContext; use parser::ParserContext;
use serialize_comma_separated_list; use serialize_comma_separated_list;
@ -280,7 +281,7 @@ pub fn parse_media_query_list(context: &ParserContext, input: &mut Parser) -> Me
impl MediaList { impl MediaList {
/// Evaluate a whole `MediaList` against `Device`. /// Evaluate a whole `MediaList` against `Device`.
pub fn evaluate(&self, device: &Device) -> bool { pub fn evaluate(&self, device: &Device, quirks_mode: QuirksMode) -> bool {
// Check if it is an empty media query list or any queries match (OR condition) // Check if it is an empty media query list or any queries match (OR condition)
// https://drafts.csswg.org/mediaqueries-4/#mq-list // https://drafts.csswg.org/mediaqueries-4/#mq-list
self.media_queries.is_empty() || self.media_queries.iter().any(|mq| { self.media_queries.is_empty() || self.media_queries.iter().any(|mq| {
@ -290,7 +291,7 @@ impl MediaList {
let query_match = let query_match =
media_match && media_match &&
mq.expressions.iter() mq.expressions.iter()
.all(|expression| expression.matches(&device)); .all(|expression| expression.matches(&device, quirks_mode));
// Apply the logical NOT qualifier to the result // Apply the logical NOT qualifier to the result
match mq.qualifier { match mq.qualifier {

Просмотреть файл

@ -6,6 +6,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use context::QuirksMode;
use cssparser::{Parser, SourcePosition, UnicodeRange}; use cssparser::{Parser, SourcePosition, UnicodeRange};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
use style_traits::OneOrMoreCommaSeparated; use style_traits::OneOrMoreCommaSeparated;
@ -44,6 +45,8 @@ pub struct ParserContext<'a> {
pub line_number_offset: u64, pub line_number_offset: u64,
/// The mode to use when parsing lengths. /// The mode to use when parsing lengths.
pub length_parsing_mode: LengthParsingMode, pub length_parsing_mode: LengthParsingMode,
/// The quirks mode of this stylesheet.
pub quirks_mode: QuirksMode,
} }
impl<'a> ParserContext<'a> { impl<'a> ParserContext<'a> {
@ -52,7 +55,8 @@ 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) length_parsing_mode: LengthParsingMode,
quirks_mode: QuirksMode)
-> ParserContext<'a> { -> ParserContext<'a> {
ParserContext { ParserContext {
stylesheet_origin: stylesheet_origin, stylesheet_origin: stylesheet_origin,
@ -61,6 +65,7 @@ impl<'a> ParserContext<'a> {
rule_type: rule_type, rule_type: rule_type,
line_number_offset: 0u64, line_number_offset: 0u64,
length_parsing_mode: length_parsing_mode, length_parsing_mode: length_parsing_mode,
quirks_mode: quirks_mode,
} }
} }
@ -68,9 +73,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) length_parsing_mode: LengthParsingMode,
quirks_mode: QuirksMode)
-> ParserContext<'a> { -> ParserContext<'a> {
Self::new(Origin::Author, url_data, error_reporter, rule_type, length_parsing_mode) Self::new(Origin::Author, url_data, error_reporter, rule_type, length_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.
@ -84,6 +90,7 @@ impl<'a> ParserContext<'a> {
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, length_parsing_mode: context.length_parsing_mode,
quirks_mode: context.quirks_mode,
} }
} }
@ -92,7 +99,8 @@ 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) length_parsing_mode: LengthParsingMode,
quirks_mode: QuirksMode)
-> ParserContext<'a> { -> ParserContext<'a> {
ParserContext { ParserContext {
stylesheet_origin: stylesheet_origin, stylesheet_origin: stylesheet_origin,
@ -101,6 +109,7 @@ impl<'a> ParserContext<'a> {
rule_type: None, rule_type: None,
line_number_offset: line_number_offset, line_number_offset: line_number_offset,
length_parsing_mode: length_parsing_mode, length_parsing_mode: length_parsing_mode,
quirks_mode: quirks_mode,
} }
} }

Просмотреть файл

@ -140,7 +140,7 @@ class Longhand(object):
need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False,
allowed_in_keyframe_block=True, complex_color=False, cast_type='u8', allowed_in_keyframe_block=True, complex_color=False, cast_type='u8',
has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False, has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False,
flags=None, allowed_in_page_rule=False): flags=None, allowed_in_page_rule=False, allow_quirks=False):
self.name = name self.name = name
if not spec: if not spec:
raise TypeError("Spec should be specified for %s" % name) raise TypeError("Spec should be specified for %s" % name)
@ -166,6 +166,7 @@ class Longhand(object):
self.boxed = arg_to_bool(boxed) self.boxed = arg_to_bool(boxed)
self.flags = flags.split() if flags else [] self.flags = flags.split() if flags else []
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule) self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
self.allow_quirks = allow_quirks
# https://drafts.csswg.org/css-animations/#keyframes # https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property # > The <declaration-list> inside of <keyframe-block> accepts any CSS property

Просмотреть файл

@ -6,6 +6,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
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;
@ -641,13 +642,15 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
/// shared between Servo and Gecko. /// shared between Servo and Gecko.
pub fn parse_style_attribute(input: &str, pub fn parse_style_attribute(input: &str,
url_data: &UrlExtraData, url_data: &UrlExtraData,
error_reporter: &ParseErrorReporter) error_reporter: &ParseErrorReporter,
quirks_mode: QuirksMode)
-> PropertyDeclarationBlock { -> PropertyDeclarationBlock {
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),
LengthParsingMode::Default); LengthParsingMode::Default,
quirks_mode);
parse_property_declaration_list(&context, &mut Parser::new(input)) parse_property_declaration_list(&context, &mut Parser::new(input))
} }
@ -660,13 +663,15 @@ 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) length_parsing_mode: LengthParsingMode,
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); length_parsing_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)
.map_err(|_| ()) .map_err(|_| ())

Просмотреть файл

@ -8,11 +8,13 @@
%> %>
<%def name="predefined_type(name, type, initial_value, parse_method='parse', <%def name="predefined_type(name, type, initial_value, parse_method='parse',
needs_context=True, vector=False, computed_type=None, initial_specified_value=None, **kwargs)"> needs_context=True, vector=False, computed_type=None, initial_specified_value=None,
allow_quirks=False, **kwargs)">
<%def name="predefined_type_inner(name, type, initial_value, parse_method)"> <%def name="predefined_type_inner(name, type, initial_value, parse_method)">
#[allow(unused_imports)] #[allow(unused_imports)]
use app_units::Au; use app_units::Au;
use cssparser::{Color as CSSParserColor, RGBA}; use cssparser::{Color as CSSParserColor, RGBA};
use values::specified::AllowQuirks;
pub use values::specified::${type} as SpecifiedValue; pub use values::specified::${type} as SpecifiedValue;
pub mod computed_value { pub mod computed_value {
% if computed_type: % if computed_type:
@ -30,7 +32,9 @@
pub fn parse(context: &ParserContext, pub fn parse(context: &ParserContext,
input: &mut Parser) input: &mut Parser)
-> Result<SpecifiedValue, ()> { -> Result<SpecifiedValue, ()> {
% if needs_context: % if allow_quirks:
specified::${type}::${parse_method}_quirky(context, input, AllowQuirks::Yes)
% elif needs_context:
specified::${type}::${parse_method}(context, input) specified::${type}::${parse_method}(context, input)
% else: % else:
specified::${type}::${parse_method}(input) specified::${type}::${parse_method}(input)
@ -277,6 +281,7 @@
% if not property.derived_from: % if not property.derived_from:
{ {
let custom_props = context.style().custom_properties(); let custom_props = context.style().custom_properties();
let quirks_mode = context.quirks_mode;
::properties::substitute_variables_${property.ident}( ::properties::substitute_variables_${property.ident}(
&declared_value, &custom_props, &declared_value, &custom_props,
|value| { |value| {
@ -349,7 +354,7 @@
} }
} }
} }
}, error_reporter); }, error_reporter, quirks_mode);
} }
% if property.custom_cascade: % if property.custom_cascade:
@ -370,7 +375,11 @@
parse(context, input).map(|result| Box::new(result)) parse(context, input).map(|result| Box::new(result))
% else: % else:
-> Result<SpecifiedValue, ()> { -> Result<SpecifiedValue, ()> {
parse(context, input) % if property.allow_quirks:
parse_quirky(context, input, specified::AllowQuirks::Yes)
% else:
parse(context, input)
% endif
% endif % endif
} }
pub fn parse_declared(context: &ParserContext, input: &mut Parser) pub fn parse_declared(context: &ParserContext, input: &mut Parser)
@ -800,7 +809,8 @@
% endif % endif
</%def> </%def>
<%def name="four_sides_shorthand(name, sub_property_pattern, parser_function, needs_context=True, **kwargs)"> <%def name="four_sides_shorthand(name, sub_property_pattern, parser_function,
needs_context=True, allow_quirks=False, **kwargs)">
<% sub_properties=' '.join(sub_property_pattern % side for side in ['top', 'right', 'bottom', 'left']) %> <% sub_properties=' '.join(sub_property_pattern % side for side in ['top', 'right', 'bottom', 'left']) %>
<%call expr="self.shorthand(name, sub_properties=sub_properties, **kwargs)"> <%call expr="self.shorthand(name, sub_properties=sub_properties, **kwargs)">
#[allow(unused_imports)] #[allow(unused_imports)]
@ -810,7 +820,9 @@
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> { pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let (top, right, bottom, left) = let (top, right, bottom, left) =
% if needs_context: % if allow_quirks:
try!(parse_four_sides(input, |i| ${parser_function}_quirky(context, i, specified::AllowQuirks::Yes)));
% elif needs_context:
try!(parse_four_sides(input, |i| ${parser_function}(context, i))); try!(parse_four_sides(input, |i| ${parser_function}(context, i)));
% else: % else:
try!(parse_four_sides(input, ${parser_function})); try!(parse_four_sides(input, ${parser_function}));

Просмотреть файл

@ -515,6 +515,7 @@ impl AnimationValue {
% if prop.animatable: % if prop.animatable:
LonghandId::${prop.camel_case} => { LonghandId::${prop.camel_case} => {
let mut result = None; let mut result = None;
let quirks_mode = context.quirks_mode;
::properties::substitute_variables_${prop.ident}_slow( ::properties::substitute_variables_${prop.ident}_slow(
&variables.css, &variables.css,
variables.first_token_type, variables.first_token_type,
@ -533,7 +534,8 @@ impl AnimationValue {
}; };
result = AnimationValue::from_declaration(&declaration, context, initial); result = AnimationValue::from_declaration(&declaration, context, initial);
}, },
&reporter); &reporter,
quirks_mode);
result result
}, },
% else: % else:

Просмотреть файл

@ -33,7 +33,9 @@
computed_type="::app_units::Au", computed_type="::app_units::Au",
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-width"), alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-width"),
spec=maybe_logical_spec(side, "width"), spec=maybe_logical_spec(side, "width"),
animation_value_type="ComputedValue", logical=side[1])} animation_value_type="ComputedValue",
logical=side[1],
allow_quirks=not side[1])}
% endfor % endfor
${helpers.gecko_keyword_conversion(Keyword('border-style', ${helpers.gecko_keyword_conversion(Keyword('border-style',

Просмотреть файл

@ -264,6 +264,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::specified::AllowQuirks;
<% vertical_align = data.longhands_by_name["vertical-align"] %> <% vertical_align = data.longhands_by_name["vertical-align"] %>
<% vertical_align.keyword = Keyword("vertical-align", <% vertical_align.keyword = Keyword("vertical-align",
@ -306,7 +307,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
/// baseline | sub | super | top | text-top | middle | bottom | text-bottom /// baseline | sub | super | top | text-top | middle | bottom | text-bottom
/// | <percentage> | <length> /// | <percentage> | <length>
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
input.try(|i| specified::LengthOrPercentage::parse(context, i)) input.try(|i| specified::LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes))
.map(SpecifiedValue::LengthOrPercentage) .map(SpecifiedValue::LengthOrPercentage)
.or_else(|_| { .or_else(|_| {
match_ignore_ascii_case! { &try!(input.expect_ident()), match_ignore_ascii_case! { &try!(input.expect_ident()),

Просмотреть файл

@ -550,14 +550,14 @@ ${helpers.single_keyword_system("font-variant-caps",
</%helpers:longhand> </%helpers:longhand>
<%helpers:longhand name="font-size" need_clone="True" animation_value_type="ComputedValue" <%helpers:longhand name="font-size" need_clone="True" animation_value_type="ComputedValue"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size"> allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
use app_units::Au; use app_units::Au;
use properties::longhands::system_font::SystemFont; use properties::longhands::system_font::SystemFont;
use properties::style_structs::Font; use properties::style_structs::Font;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::{FONT_MEDIUM_PX, HasViewportPercentage}; use values::{FONT_MEDIUM_PX, HasViewportPercentage};
use values::specified::{FontRelativeLength, LengthOrPercentage, Length}; use values::specified::{AllowQuirks, FontRelativeLength, LengthOrPercentage, Length};
use values::specified::{NoCalcLength, Percentage}; use values::specified::{NoCalcLength, Percentage};
use values::specified::length::FontBaseSize; use values::specified::length::FontBaseSize;
@ -843,9 +843,19 @@ ${helpers.single_keyword_system("font-variant-caps",
)) ))
} }
} }
/// <length> | <percentage> | <absolute-size> | <relative-size> /// <length> | <percentage> | <absolute-size> | <relative-size>
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if let Ok(lop) = input.try(|i| specified::LengthOrPercentage::parse_non_negative(context, i)) { parse_quirky(context, input, AllowQuirks::No)
}
/// Parses a font-size, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<SpecifiedValue, ()> {
use self::specified::LengthOrPercentage;
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks)) {
return Ok(SpecifiedValue::Length(lop)) return Ok(SpecifiedValue::Length(lop))
} }

Просмотреть файл

@ -26,6 +26,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::specified::{AllowQuirks, Length};
pub mod computed_value { pub mod computed_value {
use app_units::Au; use app_units::Au;
@ -73,8 +74,8 @@ ${helpers.single_keyword("caption-side", "top bottom",
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue { pub struct SpecifiedValue {
pub horizontal: specified::Length, pub horizontal: Length,
pub vertical: Option<specified::Length>, pub vertical: Option<Length>,
} }
#[inline] #[inline]
@ -130,11 +131,11 @@ ${helpers.single_keyword("caption-side", "top bottom",
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
let mut first = None; let mut first = None;
let mut second = None; let mut second = None;
match specified::Length::parse_non_negative(context, input) { match Length::parse_non_negative_quirky(context, input, AllowQuirks::Yes) {
Err(()) => (), Err(()) => (),
Ok(length) => { Ok(length) => {
first = Some(length); first = Some(length);
if let Ok(len) = input.try(|input| specified::Length::parse_non_negative(context, input)) { if let Ok(len) = input.try(|i| Length::parse_non_negative_quirky(context, i, AllowQuirks::Yes)) {
second = Some(len); second = Some(len);
} }
} }

Просмотреть файл

@ -184,7 +184,8 @@ ${helpers.predefined_type("text-indent",
"LengthOrPercentage", "LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))", "computed::LengthOrPercentage::Length(Au(0))",
animation_value_type="ComputedValue", animation_value_type="ComputedValue",
spec="https://drafts.csswg.org/css-text/#propdef-text-indent")} spec="https://drafts.csswg.org/css-text/#propdef-text-indent",
allow_quirks=True)}
// Also known as "word-wrap" (which is more popular because of IE), but this is the preferred // Also known as "word-wrap" (which is more popular because of IE), but this is the preferred
// name per CSS-TEXT 6.2. // name per CSS-TEXT 6.2.
@ -411,6 +412,7 @@ ${helpers.single_keyword("text-align-last",
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::specified::AllowQuirks;
impl HasViewportPercentage for SpecifiedValue { impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool { fn has_viewport_percentage(&self) -> bool {
@ -487,7 +489,7 @@ ${helpers.single_keyword("text-align-last",
if input.try(|input| input.expect_ident_matching("normal")).is_ok() { if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal) Ok(SpecifiedValue::Normal)
} else { } else {
specified::Length::parse(context, input).map(SpecifiedValue::Specified) specified::Length::parse_quirky(context, input, AllowQuirks::Yes).map(SpecifiedValue::Specified)
} }
} }
</%helpers:longhand> </%helpers:longhand>
@ -497,6 +499,7 @@ ${helpers.single_keyword("text-align-last",
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::specified::AllowQuirks;
impl HasViewportPercentage for SpecifiedValue { impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool { fn has_viewport_percentage(&self) -> bool {
@ -572,7 +575,7 @@ ${helpers.single_keyword("text-align-last",
if input.try(|input| input.expect_ident_matching("normal")).is_ok() { if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
Ok(SpecifiedValue::Normal) Ok(SpecifiedValue::Normal)
} else { } else {
specified::LengthOrPercentage::parse(context, input) specified::LengthOrPercentage::parse_quirky(context, input, AllowQuirks::Yes)
.map(SpecifiedValue::Specified) .map(SpecifiedValue::Specified)
} }
} }

Просмотреть файл

@ -15,6 +15,7 @@
${helpers.predefined_type("margin-%s" % side[0], "LengthOrPercentageOrAuto", ${helpers.predefined_type("margin-%s" % side[0], "LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Length(Au(0))", "computed::LengthOrPercentageOrAuto::Length(Au(0))",
alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"), alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"),
allow_quirks=not side[1],
animation_value_type="ComputedValue", logical = side[1], spec = spec, animation_value_type="ComputedValue", logical = side[1], spec = spec,
allowed_in_page_rule=True)} allowed_in_page_rule=True)}
% endfor % endfor

Просмотреть файл

@ -18,5 +18,6 @@
alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"), alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"),
animation_value_type="ComputedValue", animation_value_type="ComputedValue",
logical = side[1], logical = side[1],
spec = spec)} spec = spec,
allow_quirks=not side[1])}
% endfor % endfor

Просмотреть файл

@ -13,7 +13,8 @@
${helpers.predefined_type(side, "LengthOrPercentageOrAuto", ${helpers.predefined_type(side, "LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Auto", "computed::LengthOrPercentageOrAuto::Auto",
spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side, spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side,
animation_value_type="ComputedValue")} animation_value_type="ComputedValue",
allow_quirks=True)}
% endfor % endfor
// offset-* logical properties, map to "top" / "left" / "bottom" / "right" // offset-* logical properties, map to "top" / "left" / "bottom" / "right"
% for side in LOGICAL_SIDES: % for side in LOGICAL_SIDES:
@ -157,6 +158,7 @@ ${helpers.predefined_type("flex-basis",
"computed::LengthOrPercentageOrAuto::Auto", "computed::LengthOrPercentageOrAuto::Auto",
"parse_non_negative", "parse_non_negative",
spec=spec % size, spec=spec % size,
allow_quirks=not logical,
animation_value_type="ComputedValue", logical = logical)} animation_value_type="ComputedValue", logical = logical)}
% if product == "gecko": % if product == "gecko":
% for min_max in ["min", "max"]: % for min_max in ["min", "max"]:
@ -177,7 +179,7 @@ ${helpers.predefined_type("flex-basis",
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::specified::${MinMax}Length; use values::specified::{AllowQuirks, ${MinMax}Length};
impl HasViewportPercentage for SpecifiedValue { impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool { fn has_viewport_percentage(&self) -> bool {
@ -199,7 +201,11 @@ ${helpers.predefined_type("flex-basis",
${MinMax}Length::${initial} ${MinMax}Length::${initial}
} }
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
% if logical:
let ret = ${MinMax}Length::parse(context, input); let ret = ${MinMax}Length::parse(context, input);
% else:
let ret = ${MinMax}Length::parse_quirky(context, input, AllowQuirks::Yes);
% endif
// Keyword values don't make sense in the block direction; don't parse them // Keyword values don't make sense in the block direction; don't parse them
% if "block" in size: % if "block" in size:
if let Ok(${MinMax}Length::ExtremumLength(..)) = ret { if let Ok(${MinMax}Length::ExtremumLength(..)) = ret {
@ -254,13 +260,17 @@ ${helpers.predefined_type("flex-basis",
"computed::LengthOrPercentage::Length(Au(0))", "computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative", "parse_non_negative",
spec=spec % ("min-%s" % size), spec=spec % ("min-%s" % size),
animation_value_type="ComputedValue", logical = logical)} animation_value_type="ComputedValue",
logical=logical,
allow_quirks=not logical)}
${helpers.predefined_type("max-%s" % size, ${helpers.predefined_type("max-%s" % size,
"LengthOrPercentageOrNone", "LengthOrPercentageOrNone",
"computed::LengthOrPercentageOrNone::None", "computed::LengthOrPercentageOrNone::None",
"parse_non_negative", "parse_non_negative",
spec=spec % ("min-%s" % size), spec=spec % ("min-%s" % size),
animation_value_type="ComputedValue", logical = logical)} animation_value_type="ComputedValue",
logical=logical,
allow_quirks=not logical)}
% endif % endif
% endfor % endfor

Просмотреть файл

@ -21,6 +21,7 @@ use cssparser::{Parser, TokenSerializationType};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
#[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D; #[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D;
use computed_values; use computed_values;
use context::QuirksMode;
use font_metrics::FontMetricsProvider; use font_metrics::FontMetricsProvider;
#[cfg(feature = "gecko")] use gecko_bindings::bindings; #[cfg(feature = "gecko")] use gecko_bindings::bindings;
#[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID}; #[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID};
@ -328,7 +329,8 @@ impl PropertyDeclarationIdSet {
% endif % endif
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>, custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
f: F, f: F,
error_reporter: &ParseErrorReporter) error_reporter: &ParseErrorReporter,
quirks_mode: QuirksMode)
% if property.boxed: % if property.boxed:
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>) where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
% else: % else:
@ -342,7 +344,8 @@ impl PropertyDeclarationIdSet {
with_variables.from_shorthand, with_variables.from_shorthand,
custom_properties, custom_properties,
f, f,
error_reporter); error_reporter,
quirks_mode);
} else { } else {
f(value); f(value);
} }
@ -357,7 +360,8 @@ impl PropertyDeclarationIdSet {
from_shorthand: Option<ShorthandId>, from_shorthand: Option<ShorthandId>,
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>, custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
f: F, f: F,
error_reporter: &ParseErrorReporter) error_reporter: &ParseErrorReporter,
quirks_mode: QuirksMode)
% if property.boxed: % if property.boxed:
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>) where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
% else: % else:
@ -375,7 +379,8 @@ impl PropertyDeclarationIdSet {
url_data, url_data,
error_reporter, error_reporter,
None, None,
LengthParsingMode::Default); LengthParsingMode::Default,
quirks_mode);
Parser::new(&css).parse_entirely(|input| { Parser::new(&css).parse_entirely(|input| {
match from_shorthand { match from_shorthand {
None => { None => {
@ -2116,7 +2121,8 @@ pub fn cascade(device: &Device,
cascade_info: Option<<&mut CascadeInfo>, cascade_info: Option<<&mut CascadeInfo>,
error_reporter: &ParseErrorReporter, error_reporter: &ParseErrorReporter,
font_metrics_provider: &FontMetricsProvider, font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags) flags: CascadeFlags,
quirks_mode: QuirksMode)
-> ComputedValues { -> ComputedValues {
debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some()); debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some());
let (is_root_element, inherited_style, layout_parent_style) = match parent_style { let (is_root_element, inherited_style, layout_parent_style) = match parent_style {
@ -2162,7 +2168,8 @@ pub fn cascade(device: &Device,
cascade_info, cascade_info,
error_reporter, error_reporter,
font_metrics_provider, font_metrics_provider,
flags) flags,
quirks_mode)
} }
/// NOTE: This function expects the declaration with more priority to appear /// NOTE: This function expects the declaration with more priority to appear
@ -2177,7 +2184,8 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
mut cascade_info: Option<<&mut CascadeInfo>, mut cascade_info: Option<<&mut CascadeInfo>,
error_reporter: &ParseErrorReporter, error_reporter: &ParseErrorReporter,
font_metrics_provider: &FontMetricsProvider, font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags) flags: CascadeFlags,
quirks_mode: QuirksMode)
-> ComputedValues -> ComputedValues
where F: Fn() -> I, where F: Fn() -> I,
I: Iterator<Item = &'a PropertyDeclaration>, I: Iterator<Item = &'a PropertyDeclaration>,
@ -2230,6 +2238,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
style: starting_style, style: starting_style,
font_metrics_provider: font_metrics_provider, font_metrics_provider: font_metrics_provider,
in_media_query: false, in_media_query: false,
quirks_mode: quirks_mode,
}; };
// Set computed values, overwriting earlier declarations for the same // Set computed values, overwriting earlier declarations for the same

Просмотреть файл

@ -194,8 +194,8 @@
sub_properties="background-position-x background-position-y" sub_properties="background-position-x background-position-y"
spec="https://drafts.csswg.org/css-backgrounds-4/#the-background-position"> spec="https://drafts.csswg.org/css-backgrounds-4/#the-background-position">
use properties::longhands::{background_position_x,background_position_y}; use properties::longhands::{background_position_x,background_position_y};
use values::specified::AllowQuirks;
use values::specified::position::Position; use values::specified::position::Position;
use parser::Parse;
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> { pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let mut position_x = background_position_x::SpecifiedValue(Vec::new()); let mut position_x = background_position_x::SpecifiedValue(Vec::new());
@ -204,7 +204,7 @@
try!(input.parse_comma_separated(|input| { try!(input.parse_comma_separated(|input| {
loop { loop {
if let Ok(value) = input.try(|input| Position::parse(context, input)) { if let Ok(value) = input.try(|input| Position::parse_quirky(context, input, AllowQuirks::Yes)) {
position_x.0.push(value.horizontal); position_x.0.push(value.horizontal);
position_y.0.push(value.vertical); position_y.0.push(value.vertical);
any = true; any = true;

Просмотреть файл

@ -17,11 +17,12 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
for side in PHYSICAL_SIDES)}" for side in PHYSICAL_SIDES)}"
spec="https://drafts.csswg.org/css-backgrounds/#border-width"> spec="https://drafts.csswg.org/css-backgrounds/#border-width">
use super::parse_four_sides; use super::parse_four_sides;
use parser::Parse; use values::specified::{AllowQuirks, BorderWidth};
use values::specified;
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> { pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let (top, right, bottom, left) = try!(parse_four_sides(input, |i| specified::BorderWidth::parse(context, i))); let (top, right, bottom, left) = try!(parse_four_sides(input, |i| {
BorderWidth::parse_quirky(context, i, AllowQuirks::Yes)
}));
Ok(Longhands { Ok(Longhands {
% for side in PHYSICAL_SIDES: % for side in PHYSICAL_SIDES:
${to_rust_ident('border-%s-width' % side)}: ${side}, ${to_rust_ident('border-%s-width' % side)}: ${side},

Просмотреть файл

@ -6,4 +6,5 @@
${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthOrPercentageOrAuto::parse", ${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthOrPercentageOrAuto::parse",
spec="https://drafts.csswg.org/css-box/#propdef-margin", spec="https://drafts.csswg.org/css-box/#propdef-margin",
allowed_in_page_rule=True)} allowed_in_page_rule=True,
allow_quirks=True)}

Просмотреть файл

@ -5,4 +5,5 @@
<%namespace name="helpers" file="/helpers.mako.rs" /> <%namespace name="helpers" file="/helpers.mako.rs" />
${helpers.four_sides_shorthand("padding", "padding-%s", "specified::LengthOrPercentage::parse", ${helpers.four_sides_shorthand("padding", "padding-%s", "specified::LengthOrPercentage::parse",
spec="https://drafts.csswg.org/css-box-3/#propdef-padding")} spec="https://drafts.csswg.org/css-box-3/#propdef-padding",
allow_quirks=True)}

Просмотреть файл

@ -5,6 +5,7 @@
//! Servo's media-query device and expression representation. //! Servo's media-query device and expression representation.
use app_units::Au; use app_units::Au;
use context::QuirksMode;
use cssparser::Parser; use cssparser::Parser;
use euclid::{Size2D, TypedSize2D}; use euclid::{Size2D, TypedSize2D};
use font_metrics::ServoMetricsProvider; use font_metrics::ServoMetricsProvider;
@ -128,12 +129,12 @@ impl Expression {
/// Evaluate this expression and return whether it matches the current /// Evaluate this expression and return whether it matches the current
/// device. /// device.
pub fn matches(&self, device: &Device) -> bool { pub fn matches(&self, device: &Device, quirks_mode: QuirksMode) -> bool {
let viewport_size = device.au_viewport_size(); let viewport_size = device.au_viewport_size();
let value = viewport_size.width; let value = viewport_size.width;
match self.0 { match self.0 {
ExpressionKind::Width(ref range) => { ExpressionKind::Width(ref range) => {
match range.to_computed_range(device) { match range.to_computed_range(device, quirks_mode) {
Range::Min(ref width) => { value >= *width }, Range::Min(ref width) => { value >= *width },
Range::Max(ref width) => { value <= *width }, Range::Max(ref width) => { value <= *width },
Range::Eq(ref width) => { value == *width }, Range::Eq(ref width) => { value == *width },
@ -175,7 +176,7 @@ pub enum Range<T> {
} }
impl Range<specified::Length> { impl Range<specified::Length> {
fn to_computed_range(&self, device: &Device) -> Range<Au> { fn to_computed_range(&self, device: &Device, quirks_mode: QuirksMode) -> Range<Au> {
let default_values = device.default_computed_values(); let default_values = device.default_computed_values();
// http://dev.w3.org/csswg/mediaqueries3/#units // http://dev.w3.org/csswg/mediaqueries3/#units
// em units are relative to the initial font-size. // em units are relative to the initial font-size.
@ -192,6 +193,7 @@ impl Range<specified::Length> {
// ch units can exist in media queries. // ch units can exist in media queries.
font_metrics_provider: &ServoMetricsProvider, font_metrics_provider: &ServoMetricsProvider,
in_media_query: true, in_media_query: true,
quirks_mode: quirks_mode,
}; };
match *self { match *self {

Просмотреть файл

@ -7,6 +7,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use {Atom, Prefix, Namespace}; use {Atom, Prefix, Namespace};
use context::QuirksMode;
use counter_style::{CounterStyleRule, parse_counter_style_name, parse_counter_style_body}; use counter_style::{CounterStyleRule, parse_counter_style_name, parse_counter_style_body};
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser}; use cssparser::{AtRuleParser, Parser, QualifiedRuleParser};
use cssparser::{AtRuleType, RuleListParser, parse_one_rule}; use cssparser::{AtRuleType, RuleListParser, parse_one_rule};
@ -263,6 +264,8 @@ pub struct Stylesheet {
pub dirty_on_viewport_size_change: AtomicBool, pub dirty_on_viewport_size_change: AtomicBool,
/// Whether this stylesheet should be disabled. /// Whether this stylesheet should be disabled.
pub disabled: AtomicBool, pub disabled: AtomicBool,
/// The quirks mode of this stylesheet.
pub quirks_mode: QuirksMode,
} }
@ -415,7 +418,8 @@ impl CssRule {
&parent_stylesheet.url_data, &parent_stylesheet.url_data,
&error_reporter, &error_reporter,
None, None,
LengthParsingMode::Default); LengthParsingMode::Default,
parent_stylesheet.quirks_mode);
let mut input = Parser::new(css); let mut input = Parser::new(css);
// nested rules are in the body state // nested rules are in the body state
@ -663,7 +667,7 @@ impl Stylesheet {
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules( let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
css, url_data, existing.origin, &mut namespaces, css, url_data, existing.origin, &mut namespaces,
&existing.shared_lock, stylesheet_loader, error_reporter, &existing.shared_lock, stylesheet_loader, error_reporter,
0u64); existing.quirks_mode, 0u64);
*existing.namespaces.write() = namespaces; *existing.namespaces.write() = namespaces;
existing.dirty_on_viewport_size_change existing.dirty_on_viewport_size_change
@ -681,6 +685,7 @@ impl Stylesheet {
shared_lock: &SharedRwLock, shared_lock: &SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter, error_reporter: &ParseErrorReporter,
quirks_mode: QuirksMode,
line_number_offset: u64) line_number_offset: u64)
-> (Vec<CssRule>, bool) { -> (Vec<CssRule>, bool) {
let mut rules = Vec::new(); let mut rules = Vec::new();
@ -691,7 +696,8 @@ 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, LengthParsingMode::Default,
quirks_mode),
state: Cell::new(State::Start), state: Cell::new(State::Start),
}; };
@ -726,11 +732,13 @@ impl Stylesheet {
shared_lock: SharedRwLock, shared_lock: SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter, error_reporter: &ParseErrorReporter,
line_number_offset: u64) -> Stylesheet { quirks_mode: QuirksMode,
line_number_offset: u64)
-> Stylesheet {
let mut namespaces = Namespaces::default(); let mut namespaces = Namespaces::default();
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules( let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
css, &url_data, origin, &mut namespaces, css, &url_data, origin, &mut namespaces,
&shared_lock, stylesheet_loader, error_reporter, line_number_offset &shared_lock, stylesheet_loader, error_reporter, quirks_mode, line_number_offset,
); );
Stylesheet { Stylesheet {
origin: origin, origin: origin,
@ -741,6 +749,7 @@ impl Stylesheet {
shared_lock: shared_lock, shared_lock: shared_lock,
dirty_on_viewport_size_change: AtomicBool::new(dirty_on_viewport_size_change), dirty_on_viewport_size_change: AtomicBool::new(dirty_on_viewport_size_change),
disabled: AtomicBool::new(false), disabled: AtomicBool::new(false),
quirks_mode: quirks_mode,
} }
} }
@ -769,7 +778,7 @@ impl Stylesheet {
/// ///
/// Always true if no associated MediaList exists. /// Always true if no associated MediaList exists.
pub fn is_effective_for_device(&self, device: &Device, guard: &SharedRwLockReadGuard) -> bool { pub fn is_effective_for_device(&self, device: &Device, guard: &SharedRwLockReadGuard) -> bool {
self.media.read_with(guard).evaluate(device) self.media.read_with(guard).evaluate(device, self.quirks_mode)
} }
/// Return an iterator over the effective rules within the style-sheet, as /// Return an iterator over the effective rules within the style-sheet, as
@ -781,7 +790,7 @@ impl Stylesheet {
#[inline] #[inline]
pub fn effective_rules<F>(&self, device: &Device, guard: &SharedRwLockReadGuard, mut f: F) pub fn effective_rules<F>(&self, device: &Device, guard: &SharedRwLockReadGuard, mut f: F)
where F: FnMut(&CssRule) { where F: FnMut(&CssRule) {
effective_rules(&self.rules.read_with(guard).0, device, guard, &mut f); effective_rules(&self.rules.read_with(guard).0, device, self.quirks_mode, guard, &mut f);
} }
/// Returns whether the stylesheet has been explicitly disabled through the /// Returns whether the stylesheet has been explicitly disabled through the
@ -802,17 +811,22 @@ impl Stylesheet {
} }
} }
fn effective_rules<F>(rules: &[CssRule], device: &Device, guard: &SharedRwLockReadGuard, f: &mut F) fn effective_rules<F>(rules: &[CssRule],
where F: FnMut(&CssRule) { device: &Device,
quirks_mode: QuirksMode,
guard: &SharedRwLockReadGuard,
f: &mut F)
where F: FnMut(&CssRule)
{
for rule in rules { for rule in rules {
f(rule); f(rule);
rule.with_nested_rules_and_mq(guard, |rules, mq| { rule.with_nested_rules_and_mq(guard, |rules, mq| {
if let Some(media_queries) = mq { if let Some(media_queries) = mq {
if !media_queries.evaluate(device) { if !media_queries.evaluate(device, quirks_mode) {
return return
} }
} }
effective_rules(rules, device, guard, f) effective_rules(rules, device, quirks_mode, guard, f)
}) })
} }
} }
@ -973,6 +987,7 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
namespaces: RwLock::new(Namespaces::default()), namespaces: RwLock::new(Namespaces::default()),
dirty_on_viewport_size_change: AtomicBool::new(false), dirty_on_viewport_size_change: AtomicBool::new(false),
disabled: AtomicBool::new(false), disabled: AtomicBool::new(false),
quirks_mode: self.context.quirks_mode,
}) })
} }
}, &mut |import_rule| { }, &mut |import_rule| {

Просмотреть файл

@ -8,6 +8,7 @@
use {Atom, LocalName}; use {Atom, LocalName};
use bit_vec::BitVec; use bit_vec::BitVec;
use context::QuirksMode;
use data::ComputedStyle; use data::ComputedStyle;
use dom::{AnimationRules, PresentationalHintsSynthetizer, TElement}; use dom::{AnimationRules, PresentationalHintsSynthetizer, TElement};
use error_reporting::RustLogReporter; use error_reporting::RustLogReporter;
@ -76,7 +77,7 @@ pub struct Stylist {
viewport_constraints: Option<ViewportConstraints>, viewport_constraints: Option<ViewportConstraints>,
/// If true, the quirks-mode stylesheet is applied. /// If true, the quirks-mode stylesheet is applied.
quirks_mode: bool, quirks_mode: QuirksMode,
/// If true, the device has changed, and the stylist needs to be updated. /// If true, the device has changed, and the stylist needs to be updated.
is_device_dirty: bool, is_device_dirty: bool,
@ -166,7 +167,7 @@ impl Stylist {
viewport_constraints: None, viewport_constraints: None,
device: Arc::new(device), device: Arc::new(device),
is_device_dirty: true, is_device_dirty: true,
quirks_mode: false, quirks_mode: QuirksMode::NoQuirks,
element_map: PerPseudoElementSelectorMap::new(), element_map: PerPseudoElementSelectorMap::new(),
pseudos_map: Default::default(), pseudos_map: Default::default(),
@ -240,7 +241,7 @@ impl Stylist {
}; };
self.viewport_constraints = self.viewport_constraints =
ViewportConstraints::maybe_new(&self.device, &cascaded_rule); ViewportConstraints::maybe_new(&self.device, &cascaded_rule, self.quirks_mode);
if let Some(ref constraints) = self.viewport_constraints { if let Some(ref constraints) = self.viewport_constraints {
Arc::get_mut(&mut self.device).unwrap() Arc::get_mut(&mut self.device).unwrap()
@ -269,7 +270,7 @@ impl Stylist {
self.add_stylesheet(&stylesheet, guards.ua_or_user, extra_data); self.add_stylesheet(&stylesheet, guards.ua_or_user, extra_data);
} }
if self.quirks_mode { if self.quirks_mode != QuirksMode::NoQuirks {
self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet, self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet,
guards.ua_or_user, extra_data); guards.ua_or_user, extra_data);
} }
@ -424,7 +425,8 @@ impl Stylist {
None, None,
&RustLogReporter, &RustLogReporter,
font_metrics, font_metrics,
cascade_flags); cascade_flags,
self.quirks_mode);
ComputedStyle::new(rule_node, Arc::new(computed)) ComputedStyle::new(rule_node, Arc::new(computed))
} }
@ -548,7 +550,8 @@ impl Stylist {
None, None,
&RustLogReporter, &RustLogReporter,
font_metrics, font_metrics,
CascadeFlags::empty()); CascadeFlags::empty(),
self.quirks_mode);
Some(ComputedStyle::new(rule_node, Arc::new(computed))) Some(ComputedStyle::new(rule_node, Arc::new(computed)))
} }
@ -581,22 +584,22 @@ impl Stylist {
}; };
self.viewport_constraints = self.viewport_constraints =
ViewportConstraints::maybe_new(&device, &cascaded_rule); ViewportConstraints::maybe_new(&device, &cascaded_rule, self.quirks_mode);
if let Some(ref constraints) = self.viewport_constraints { if let Some(ref constraints) = self.viewport_constraints {
device.account_for_viewport_rule(constraints); device.account_for_viewport_rule(constraints);
} }
fn mq_eval_changed(guard: &SharedRwLockReadGuard, rules: &[CssRule], fn mq_eval_changed(guard: &SharedRwLockReadGuard, rules: &[CssRule],
before: &Device, after: &Device) -> bool { before: &Device, after: &Device, quirks_mode: QuirksMode) -> bool {
for rule in rules { for rule in rules {
let changed = rule.with_nested_rules_and_mq(guard, |rules, mq| { let changed = rule.with_nested_rules_and_mq(guard, |rules, mq| {
if let Some(mq) = mq { if let Some(mq) = mq {
if mq.evaluate(before) != mq.evaluate(after) { if mq.evaluate(before, quirks_mode) != mq.evaluate(after, quirks_mode) {
return true return true
} }
} }
mq_eval_changed(guard, rules, before, after) mq_eval_changed(guard, rules, before, after, quirks_mode)
}); });
if changed { if changed {
return true return true
@ -606,11 +609,11 @@ impl Stylist {
} }
self.is_device_dirty |= stylesheets.iter().any(|stylesheet| { self.is_device_dirty |= stylesheets.iter().any(|stylesheet| {
let mq = stylesheet.media.read_with(guard); let mq = stylesheet.media.read_with(guard);
if mq.evaluate(&self.device) != mq.evaluate(&device) { if mq.evaluate(&self.device, self.quirks_mode) != mq.evaluate(&device, self.quirks_mode) {
return true return true
} }
mq_eval_changed(guard, &stylesheet.rules.read_with(guard).0, &self.device, &device) mq_eval_changed(guard, &stylesheet.rules.read_with(guard).0, &self.device, &device, self.quirks_mode)
}); });
self.device = Arc::new(device); self.device = Arc::new(device);
@ -623,14 +626,14 @@ impl Stylist {
} }
/// Sets the quirks mode of the document. /// Sets the quirks mode of the document.
pub fn set_quirks_mode(&mut self, enabled: bool) { pub fn set_quirks_mode(&mut self, quirks_mode: QuirksMode) {
// FIXME(emilio): We don't seem to change the quirks mode dynamically // FIXME(emilio): We don't seem to change the quirks mode dynamically
// during multiple layout passes, but this is totally bogus, in the // during multiple layout passes, but this is totally bogus, in the
// sense that it's updated asynchronously. // sense that it's updated asynchronously.
// //
// This should probably be an argument to `update`, and use the quirks // This should probably be an argument to `update`, and use the quirks
// mode info in the `SharedLayoutContext`. // mode info in the `SharedLayoutContext`.
self.quirks_mode = enabled; self.quirks_mode = quirks_mode;
} }
/// Returns the applicable CSS declarations for the given element. /// Returns the applicable CSS declarations for the given element.
@ -893,7 +896,8 @@ impl Stylist {
None, None,
&RustLogReporter, &RustLogReporter,
&metrics, &metrics,
CascadeFlags::empty())) CascadeFlags::empty(),
self.quirks_mode))
} }
} }

Просмотреть файл

@ -4,6 +4,7 @@
//! Computed values. //! Computed values.
use context::QuirksMode;
use euclid::size::Size2D; use euclid::size::Size2D;
use font_metrics::FontMetricsProvider; use font_metrics::FontMetricsProvider;
use media_queries::Device; use media_queries::Device;
@ -63,6 +64,9 @@ pub struct Context<'a> {
/// Whether or not we are computing the media list in a media query /// Whether or not we are computing the media list in a media query
pub in_media_query: bool, pub in_media_query: bool,
/// The quirks mode of this context.
pub quirks_mode: QuirksMode,
} }
impl<'a> Context<'a> { impl<'a> Context<'a> {

Просмотреть файл

@ -17,7 +17,7 @@ use std::ops::Mul;
use style_traits::ToCss; use style_traits::ToCss;
use style_traits::values::specified::AllowedLengthType; use style_traits::values::specified::AllowedLengthType;
use stylesheets::CssRuleType; use stylesheets::CssRuleType;
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time, ToComputedValue}; use super::{AllowQuirks, Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time, ToComputedValue};
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal}; use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal};
use values::ExtremumLength; use values::ExtremumLength;
use values::computed::{ComputedValueAsSpecified, Context}; use values::computed::{ComputedValueAsSpecified, Context};
@ -563,13 +563,17 @@ impl Length {
} }
#[inline] #[inline]
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType) fn parse_internal(context: &ParserContext,
input: &mut Parser,
num_context: AllowedLengthType,
allow_quirks: AllowQuirks)
-> Result<Length, ()> { -> Result<Length, ()> {
match try!(input.next()) { match try!(input.next()) {
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) => { 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.length_parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(()) return Err(())
} }
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value)))) Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value))))
@ -585,7 +589,16 @@ impl Length {
/// Parse a non-negative length /// Parse a non-negative length
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}
/// Parse a non-negative length, allowing quirks.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Length, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
} }
/// Get an absolute length from a px value. /// Get an absolute length from a px value.
@ -605,7 +618,17 @@ impl Length {
impl Parse for Length { impl Parse for Length {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All) Self::parse_quirky(context, input, AllowQuirks::No)
}
}
impl Length {
/// Parses a length, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
} }
} }
@ -616,7 +639,7 @@ impl<T: Parse> Either<Length, T> {
if let Ok(v) = input.try(|input| T::parse(context, input)) { if let Ok(v) = input.try(|input| T::parse(context, input)) {
return Ok(Either::Second(v)); return Ok(Either::Second(v));
} }
Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First) Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No).map(Either::First)
} }
} }
@ -1154,7 +1177,10 @@ impl LengthOrPercentage {
LengthOrPercentage::Length(NoCalcLength::zero()) LengthOrPercentage::Length(NoCalcLength::zero())
} }
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType) fn parse_internal(context: &ParserContext,
input: &mut Parser,
num_context: AllowedLengthType,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentage, ()> -> Result<LengthOrPercentage, ()>
{ {
match try!(input.next()) { match try!(input.next()) {
@ -1162,12 +1188,9 @@ impl LengthOrPercentage {
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentage::Length), NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentage::Length),
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(LengthOrPercentage::Percentage(Percentage(value.unit_value))), Ok(LengthOrPercentage::Percentage(Percentage(value.unit_value))),
Token::Number(ref value) => { Token::Number(value) if value.value == 0. ||
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() { (num_context.is_ok(value.value) && allow_quirks.allowed(context.quirks_mode)) =>
return Err(()) Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value.value))),
}
Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(AbsoluteLength::Px(value.value))))
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let calc = try!(input.parse_nested_block(|i| { let calc = try!(input.parse_nested_block(|i| {
CalcLengthOrPercentage::parse_length_or_percentage(context, i) CalcLengthOrPercentage::parse_length_or_percentage(context, i)
@ -1181,14 +1204,23 @@ impl LengthOrPercentage {
/// Parse a non-negative length. /// Parse a non-negative length.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}
/// Parse a non-negative length, with quirks.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentage, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
} }
/// Parse a length, treating dimensionless numbers as pixels /// Parse a length, treating dimensionless numbers as pixels
/// ///
/// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value /// https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value
pub fn parse_numbers_are_pixels(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> { pub fn parse_numbers_are_pixels(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> {
if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedLengthType::All)) { if let Ok(lop) = input.try(|i| Self::parse(context, i)) {
return Ok(lop) return Ok(lop)
} }
@ -1204,7 +1236,7 @@ impl LengthOrPercentage {
pub fn parse_numbers_are_pixels_non_negative(context: &ParserContext, pub fn parse_numbers_are_pixels_non_negative(context: &ParserContext,
input: &mut Parser) input: &mut Parser)
-> Result<LengthOrPercentage, ()> { -> Result<LengthOrPercentage, ()> {
if let Ok(lop) = input.try(|i| Self::parse_internal(context, i, AllowedLengthType::NonNegative)) { if let Ok(lop) = input.try(|i| Self::parse_non_negative(context, i)) {
return Ok(lop) return Ok(lop)
} }
@ -1230,7 +1262,18 @@ impl LengthOrPercentage {
impl Parse for LengthOrPercentage { impl Parse for LengthOrPercentage {
#[inline] #[inline]
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All) Self::parse_quirky(context, input, AllowQuirks::No)
}
}
impl LengthOrPercentage {
/// Parses a length or a percentage, allowing the unitless length quirk.
/// https://quirks.spec.whatwg.org/#the-unitless-length-quirk
#[inline]
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
} }
} }
@ -1283,15 +1326,19 @@ impl ToCss for LengthOrPercentageOrAuto {
} }
impl LengthOrPercentageOrAuto { impl LengthOrPercentageOrAuto {
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType) fn parse_internal(context: &ParserContext,
input: &mut Parser,
num_context: AllowedLengthType,
allow_quirks: AllowQuirks)
-> Result<Self, ()> { -> Result<Self, ()> {
match try!(input.next()) { match try!(input.next()) {
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) =>
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length), NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length),
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 value.value == 0. => { 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.length_parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(()) return Err(())
} }
Ok(LengthOrPercentageOrAuto::Length( Ok(LengthOrPercentageOrAuto::Length(
@ -1313,7 +1360,16 @@ impl LengthOrPercentageOrAuto {
/// Parse a non-negative length, percentage, or auto. /// Parse a non-negative length, percentage, or auto.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}
/// Parse a non-negative length, percentage, or auto.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
} }
/// Returns the `auto` value. /// Returns the `auto` value.
@ -1330,7 +1386,18 @@ impl LengthOrPercentageOrAuto {
impl Parse for LengthOrPercentageOrAuto { impl Parse for LengthOrPercentageOrAuto {
#[inline] #[inline]
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All) Self::parse_quirky(context, input, AllowQuirks::No)
}
}
impl LengthOrPercentageOrAuto {
/// Parses, with quirks.
#[inline]
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
} }
} }
@ -1367,7 +1434,10 @@ impl ToCss for LengthOrPercentageOrNone {
} }
} }
impl LengthOrPercentageOrNone { impl LengthOrPercentageOrNone {
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType) fn parse_internal(context: &ParserContext,
input: &mut Parser,
num_context: AllowedLengthType,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentageOrNone, ()> -> Result<LengthOrPercentageOrNone, ()>
{ {
match try!(input.next()) { match try!(input.next()) {
@ -1375,8 +1445,9 @@ impl LengthOrPercentageOrNone {
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length), NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length),
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(ref value) if value.value == 0. => { 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.length_parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(()) return Err(())
} }
Ok(LengthOrPercentageOrNone::Length( Ok(LengthOrPercentageOrNone::Length(
@ -1394,17 +1465,27 @@ impl LengthOrPercentageOrNone {
_ => Err(()) _ => Err(())
} }
} }
/// Parse a non-negative LengthOrPercentageOrNone. /// Parse a non-negative LengthOrPercentageOrNone.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}
/// Parse a non-negative LengthOrPercentageOrNone, with quirks.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
} }
} }
impl Parse for LengthOrPercentageOrNone { impl Parse for LengthOrPercentageOrNone {
#[inline] #[inline]
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All) Self::parse_internal(context, input, AllowedLengthType::All, AllowQuirks::No)
} }
} }
@ -1548,8 +1629,17 @@ impl ToCss for MinLength {
impl Parse for MinLength { impl Parse for MinLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
MinLength::parse_quirky(context, input, AllowQuirks::No)
}
}
impl MinLength {
/// Parses, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> {
input.try(ExtremumLength::parse).map(MinLength::ExtremumLength) input.try(ExtremumLength::parse).map(MinLength::ExtremumLength)
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) .or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
.map(MinLength::LengthOrPercentage)) .map(MinLength::LengthOrPercentage))
.or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto)) .or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto))
} }
@ -1589,8 +1679,17 @@ impl ToCss for MaxLength {
impl Parse for MaxLength { impl Parse for MaxLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
MaxLength::parse_quirky(context, input, AllowQuirks::No)
}
}
impl MaxLength {
/// Parses, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> {
input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength) input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength)
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) .or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
.map(MaxLength::LengthOrPercentage)) .map(MaxLength::LengthOrPercentage))
.or_else(|()| { .or_else(|()| {
match_ignore_ascii_case! { &try!(input.expect_ident()), match_ignore_ascii_case! { &try!(input.expect_ident()),

Просмотреть файл

@ -7,6 +7,7 @@
//! TODO(emilio): Enhance docs. //! TODO(emilio): Enhance docs.
use app_units::Au; use app_units::Au;
use context::QuirksMode;
use cssparser::{self, Parser, Token}; use cssparser::{self, Parser, Token};
use euclid::size::Size2D; use euclid::size::Size2D;
use parser::{ParserContext, Parse}; use parser::{ParserContext, Parse};
@ -490,7 +491,17 @@ pub enum BorderWidth {
impl Parse for BorderWidth { impl Parse for BorderWidth {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<BorderWidth, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<BorderWidth, ()> {
match input.try(|i| Length::parse_non_negative(context, i)) { Self::parse_quirky(context, input, AllowQuirks::No)
}
}
impl BorderWidth {
/// Parses a border width, allowing quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<BorderWidth, ()> {
match input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
Ok(length) => Ok(BorderWidth::Width(length)), Ok(length) => Ok(BorderWidth::Width(length)),
Err(_) => match_ignore_ascii_case! { &try!(input.expect_ident()), Err(_) => match_ignore_ascii_case! { &try!(input.expect_ident()),
"thin" => Ok(BorderWidth::Thin), "thin" => Ok(BorderWidth::Thin),
@ -1281,13 +1292,13 @@ impl ToComputedValue for ClipRect {
impl Parse for ClipRect { impl Parse for ClipRect {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
use values::specified::Length; use values::specified::{AllowQuirks, Length};
fn parse_argument(context: &ParserContext, input: &mut Parser) -> Result<Option<Length>, ()> { fn parse_argument(context: &ParserContext, input: &mut Parser) -> Result<Option<Length>, ()> {
if input.try(|input| input.expect_ident_matching("auto")).is_ok() { if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
Ok(None) Ok(None)
} else { } else {
Length::parse(context, input).map(Some) Length::parse_quirky(context, input, AllowQuirks::Yes).map(Some)
} }
} }
@ -1327,3 +1338,19 @@ pub type ClipRectOrAuto = Either<ClipRect, Auto>;
/// <color> | auto /// <color> | auto
pub type ColorOrAuto = Either<CSSColor, Auto>; pub type ColorOrAuto = Either<CSSColor, Auto>;
/// Whether quirks are allowed in this context.
#[derive(Clone, Copy, PartialEq)]
pub enum AllowQuirks {
/// Quirks are allowed.
Yes,
/// Quirks are not allowed.
No,
}
impl AllowQuirks {
/// Returns `true` if quirks are allowed in this context.
pub fn allowed(self, quirks_mode: QuirksMode) -> bool {
self == AllowQuirks::Yes && quirks_mode == QuirksMode::Quirks
}
}

Просмотреть файл

@ -19,7 +19,7 @@ use values::computed::position as computed_position;
use values::generics::position::{Position as GenericPosition, PositionValue, PositionWithKeyword}; use values::generics::position::{Position as GenericPosition, PositionValue, PositionWithKeyword};
use values::generics::position::HorizontalPosition as GenericHorizontalPosition; use values::generics::position::HorizontalPosition as GenericHorizontalPosition;
use values::generics::position::VerticalPosition as GenericVerticalPosition; use values::generics::position::VerticalPosition as GenericVerticalPosition;
use values::specified::{LengthOrPercentage, Percentage}; use values::specified::{AllowQuirks, LengthOrPercentage, Percentage};
pub use values::generics::position::Keyword; pub use values::generics::position::Keyword;
@ -132,13 +132,23 @@ impl Position {
impl Parse for Position { impl Parse for Position {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let first = input.try(|i| PositionComponent::parse(context, i))?; Position::parse_quirky(context, input, AllowQuirks::No)
let second = input.try(|i| PositionComponent::parse(context, i)) }
}
impl Position {
/// Parses, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
let first = input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks))?;
let second = input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
.unwrap_or(Either::Second(Keyword::Center)); .unwrap_or(Either::Second(Keyword::Center));
if let Ok(third) = input.try(|i| PositionComponent::parse(context, i)) { if let Ok(third) = input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) {
// There's a 3rd value. // There's a 3rd value.
if let Ok(fourth) = input.try(|i| PositionComponent::parse(context, i)) { if let Ok(fourth) = input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) {
// There's a 4th value. // There's a 4th value.
Position::from_components(Some(second), Some(fourth), Some(first), Some(third)) Position::from_components(Some(second), Some(fourth), Some(first), Some(third))
} else { } else {
@ -173,6 +183,17 @@ impl Parse for Position {
} }
} }
impl PositionComponent {
/// Parses, with quirks.
fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> {
input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
.map(Either::First)
.or_else(|()| input.try(Keyword::parse).map(Either::Second))
}
}
impl PositionValue<LengthOrPercentage> { impl PositionValue<LengthOrPercentage> {
/// Generic function for the computed value of a position. /// Generic function for the computed value of a position.
fn computed_value(&self, context: &Context) -> ComputedLengthOrPercentage { fn computed_value(&self, context: &Context) -> ComputedLengthOrPercentage {

Просмотреть файл

@ -10,6 +10,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use app_units::Au; use app_units::Au;
use context::QuirksMode;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
use cssparser::ToCss as ParserToCss; use cssparser::ToCss as ParserToCss;
use euclid::size::TypedSize2D; use euclid::size::TypedSize2D;
@ -588,13 +589,15 @@ pub trait MaybeNew {
/// Create a ViewportConstraints from a viewport size and a `@viewport` /// Create a ViewportConstraints from a viewport size and a `@viewport`
/// rule. /// rule.
fn maybe_new(device: &Device, fn maybe_new(device: &Device,
rule: &ViewportRule) rule: &ViewportRule,
quirks_mode: QuirksMode)
-> Option<ViewportConstraints>; -> Option<ViewportConstraints>;
} }
impl MaybeNew for ViewportConstraints { impl MaybeNew for ViewportConstraints {
fn maybe_new(device: &Device, fn maybe_new(device: &Device,
rule: &ViewportRule) rule: &ViewportRule,
quirks_mode: QuirksMode)
-> Option<ViewportConstraints> -> Option<ViewportConstraints>
{ {
use std::cmp; use std::cmp;
@ -684,6 +687,7 @@ impl MaybeNew for ViewportConstraints {
style: device.default_computed_values().clone(), style: device.default_computed_values().clone(),
font_metrics_provider: &provider, font_metrics_provider: &provider,
in_media_query: false, in_media_query: false,
quirks_mode: quirks_mode,
}; };
// DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom' // DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom'

Просмотреть файл

@ -513,7 +513,7 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
Arc::new(Stylesheet::from_str( Arc::new(Stylesheet::from_str(
"", unsafe { dummy_url_data() }.clone(), origin, "", unsafe { dummy_url_data() }.clone(), origin,
Arc::new(shared_lock.wrap(MediaList::empty())), Arc::new(shared_lock.wrap(MediaList::empty())),
shared_lock, None, &RustLogReporter, 0u64) shared_lock, None, &RustLogReporter, QuirksMode::NoQuirks, 0u64)
).into_strong() ).into_strong()
} }
@ -556,7 +556,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
Arc::new(Stylesheet::from_str( Arc::new(Stylesheet::from_str(
input, url_data.clone(), origin, media, input, url_data.clone(), origin, media,
shared_lock, loader, &RustLogReporter, 0u64) shared_lock, loader, &RustLogReporter, QuirksMode::NoQuirks, 0u64)
).into_strong() ).into_strong()
} }
@ -1012,7 +1012,8 @@ pub extern "C" fn Servo_ParseProperty(property: nsCSSPropertyID, value: *const n
let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
let reporter = RustLogReporter; let reporter = RustLogReporter;
let context = ParserContext::new(Origin::Author, url_data, &reporter, let context = ParserContext::new(Origin::Author, url_data, &reporter,
Some(CssRuleType::Style), LengthParsingMode::Default); Some(CssRuleType::Style), LengthParsingMode::Default,
QuirksMode::NoQuirks);
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value)) { match ParsedDeclaration::parse(id, &context, &mut Parser::new(value)) {
Ok(parsed) => { Ok(parsed) => {
@ -1035,7 +1036,8 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
let reporter = RustLogReporter; let reporter = RustLogReporter;
let context = ParserContext::new(Origin::Author, url_data, &reporter, let context = ParserContext::new(Origin::Author, url_data, &reporter,
Some(CssRuleType::Style), LengthParsingMode::Default); Some(CssRuleType::Style), LengthParsingMode::Default,
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)) {
Ok(parsed_easing) => { Ok(parsed_easing) => {
@ -1176,7 +1178,7 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro
structs::LengthParsingMode::SVG => LengthParsingMode::SVG, structs::LengthParsingMode::SVG => LengthParsingMode::SVG,
}; };
if let Ok(parsed) = parse_one_declaration(property_id, value, url_data, &RustLogReporter, if let Ok(parsed) = parse_one_declaration(property_id, value, url_data, &RustLogReporter,
length_parsing_mode) { length_parsing_mode, QuirksMode::NoQuirks) {
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| {
parsed.expand_set_into(decls, importance) parsed.expand_set_into(decls, importance)
@ -1243,7 +1245,7 @@ pub extern "C" fn Servo_MediaList_Matches(list: RawServoMediaListBorrowed,
-> bool { -> bool {
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
read_locked_arc(list, |list: &MediaList| { read_locked_arc(list, |list: &MediaList| {
list.evaluate(&per_doc_data.stylist.device) list.evaluate(&per_doc_data.stylist.device, QuirksMode::NoQuirks)
}) })
} }
@ -1270,7 +1272,8 @@ 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); LengthParsingMode::Default,
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);
}) })
@ -1301,7 +1304,8 @@ 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); LengthParsingMode::Default,
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);
}) })
@ -1314,7 +1318,8 @@ 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); LengthParsingMode::Default,
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))
} }
@ -1667,7 +1672,8 @@ 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), LengthParsingMode::Default,
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(
vec![SingleBackgroundImage( vec![SingleBackgroundImage(
@ -1705,7 +1711,12 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() }; let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
let url_data = unsafe { dummy_url_data() }; let url_data = unsafe { dummy_url_data() };
parse_one_declaration(id, &value, url_data, &RustLogReporter, LengthParsingMode::Default).is_ok() parse_one_declaration(id,
&value,
url_data,
&RustLogReporter,
LengthParsingMode::Default,
QuirksMode::NoQuirks).is_ok()
} }
#[no_mangle] #[no_mangle]
@ -1717,7 +1728,8 @@ 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); LengthParsingMode::Default,
QuirksMode::NoQuirks);
cond.eval(&context) cond.eval(&context)
} else { } else {
false false
@ -1947,6 +1959,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
style: (**style).clone(), style: (**style).clone(),
font_metrics_provider: &metrics, font_metrics_provider: &metrics,
in_media_query: false, in_media_query: false,
quirks_mode: QuirksMode::NoQuirks,
}; };
for (index, keyframe) in keyframes.iter().enumerate() { for (index, keyframe) in keyframes.iter().enumerate() {

Просмотреть файл

@ -8,6 +8,7 @@ use servo_url::ServoUrl;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::sync::Arc; use std::sync::Arc;
use style::Atom; use style::Atom;
use style::context::QuirksMode;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::media_queries::*; use style::media_queries::*;
use style::servo::media_queries::*; use style::servo::media_queries::*;
@ -37,7 +38,7 @@ fn test_media_rule<F>(css: &str, callback: F)
let media_list = Arc::new(lock.wrap(MediaList::empty())); let media_list = Arc::new(lock.wrap(MediaList::empty()));
let stylesheet = Stylesheet::from_str( let stylesheet = Stylesheet::from_str(
css, url, Origin::Author, media_list, lock, css, url, Origin::Author, media_list, lock,
None, &CSSErrorReporterTest, 0u64); None, &CSSErrorReporterTest, QuirksMode::NoQuirks, 0u64);
let mut rule_count = 0; let mut rule_count = 0;
let guard = stylesheet.shared_lock.read(); let guard = stylesheet.shared_lock.read();
media_queries(&guard, &stylesheet.rules.read_with(&guard).0, &mut |mq| { media_queries(&guard, &stylesheet.rules.read_with(&guard).0, &mut |mq| {
@ -66,7 +67,7 @@ fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
let media_list = Arc::new(lock.wrap(MediaList::empty())); let media_list = Arc::new(lock.wrap(MediaList::empty()));
let ss = Stylesheet::from_str( let ss = Stylesheet::from_str(
css, url, Origin::Author, media_list, lock, css, url, Origin::Author, media_list, lock,
None, &CSSErrorReporterTest, 0u64); None, &CSSErrorReporterTest, QuirksMode::NoQuirks, 0u64);
let mut rule_count = 0; let mut rule_count = 0;
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1); ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
assert!(rule_count == expected_rule_count, css.to_owned()); assert!(rule_count == expected_rule_count, css.to_owned());

Просмотреть файл

@ -5,6 +5,7 @@
use euclid::size::TypedSize2D; use euclid::size::TypedSize2D;
use parsing::parse; use parsing::parse;
use std::f32::consts::PI; use std::f32::consts::PI;
use style::context::QuirksMode;
use style::font_metrics::ServoMetricsProvider; use style::font_metrics::ServoMetricsProvider;
use style::media_queries::{Device, MediaType}; use style::media_queries::{Device, MediaType};
use style::properties::ComputedValues; use style::properties::ComputedValues;
@ -51,6 +52,7 @@ fn test_linear_gradient() {
style: initial_style.clone(), style: initial_style.clone(),
font_metrics_provider: &ServoMetricsProvider, font_metrics_provider: &ServoMetricsProvider,
in_media_query: false, in_media_query: false,
quirks_mode: QuirksMode::NoQuirks,
}; };
assert_eq!(specified::AngleOrCorner::None.to_computed_value(&specified_context), assert_eq!(specified::AngleOrCorner::None.to_computed_value(&specified_context),
computed::AngleOrCorner::Angle(Angle::from_radians(PI))); computed::AngleOrCorner::Angle(Angle::from_radians(PI)));

Просмотреть файл

@ -5,6 +5,7 @@
use cssparser::Parser; use cssparser::Parser;
use media_queries::CSSErrorReporterTest; use media_queries::CSSErrorReporterTest;
use parsing::parse; use parsing::parse;
use style::context::QuirksMode;
use style::parser::{LengthParsingMode, Parse, ParserContext}; use style::parser::{LengthParsingMode, Parse, ParserContext};
use style::stylesheets::{CssRuleType, Origin}; use style::stylesheets::{CssRuleType, Origin};
use style::values::specified::length::{AbsoluteLength, Length, NoCalcLength}; use style::values::specified::length::{AbsoluteLength, Length, NoCalcLength};
@ -38,7 +39,8 @@ 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), LengthParsingMode::SVG,
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);
assert!(result.is_ok()); assert!(result.is_ok());

Просмотреть файл

@ -6,6 +6,7 @@
use cssparser::Parser; use cssparser::Parser;
use media_queries::CSSErrorReporterTest; use media_queries::CSSErrorReporterTest;
use style::context::QuirksMode;
use style::parser::{LengthParsingMode, ParserContext}; use style::parser::{LengthParsingMode, ParserContext};
use style::stylesheets::{CssRuleType, Origin}; use style::stylesheets::{CssRuleType, Origin};
@ -13,7 +14,8 @@ fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str)
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); LengthParsingMode::Default,
QuirksMode::NoQuirks);
let mut parser = Parser::new(s); let mut parser = Parser::new(s);
f(&context, &mut parser) f(&context, &mut parser)
} }

Просмотреть файл

@ -4,6 +4,7 @@
use cssparser::Parser; use cssparser::Parser;
use media_queries::CSSErrorReporterTest; use media_queries::CSSErrorReporterTest;
use style::context::QuirksMode;
use style::parser::{LengthParsingMode, ParserContext}; use style::parser::{LengthParsingMode, ParserContext};
use style::stylesheets::{CssRuleType, Origin}; use style::stylesheets::{CssRuleType, Origin};
@ -11,7 +12,8 @@ fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str)
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); LengthParsingMode::Default,
QuirksMode::NoQuirks);
let mut parser = Parser::new(s); let mut parser = Parser::new(s);
f(&context, &mut parser) f(&context, &mut parser)
} }

Просмотреть файл

@ -6,6 +6,7 @@ use cssparser::{Parser, SourcePosition};
use rayon; use rayon;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::sync::Arc; use std::sync::Arc;
use style::context::QuirksMode;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::media_queries::MediaList; use style::media_queries::MediaList;
use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock};
@ -58,6 +59,7 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
lock, lock,
None, None,
&ErrorringErrorReporter, &ErrorringErrorReporter,
QuirksMode::NoQuirks,
0u64); 0u64);
let guard = s.shared_lock.read(); let guard = s.shared_lock.read();
let rules = s.rules.read_with(&guard); let rules = s.rules.read_with(&guard);

Просмотреть файл

@ -13,6 +13,7 @@ use std::borrow::ToOwned;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use style::context::QuirksMode;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage}; use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
use style::media_queries::MediaList; use style::media_queries::MediaList;
@ -66,7 +67,7 @@ fn test_parse_stylesheet() {
let lock = SharedRwLock::new(); let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty())); let media = Arc::new(lock.wrap(MediaList::empty()));
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock, let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
None, &CSSErrorReporterTest, 0u64); None, &CSSErrorReporterTest, QuirksMode::NoQuirks, 0u64);
let mut namespaces = Namespaces::default(); let mut namespaces = Namespaces::default();
namespaces.default = Some(ns!(html)); namespaces.default = Some(ns!(html));
let expected = Stylesheet { let expected = Stylesheet {
@ -77,6 +78,7 @@ fn test_parse_stylesheet() {
url_data: url, url_data: url,
dirty_on_viewport_size_change: AtomicBool::new(false), dirty_on_viewport_size_change: AtomicBool::new(false),
disabled: AtomicBool::new(false), disabled: AtomicBool::new(false),
quirks_mode: QuirksMode::NoQuirks,
rules: CssRules::new(vec![ rules: CssRules::new(vec![
CssRule::Namespace(Arc::new(stylesheet.shared_lock.wrap(NamespaceRule { CssRule::Namespace(Arc::new(stylesheet.shared_lock.wrap(NamespaceRule {
prefix: None, prefix: None,
@ -316,7 +318,7 @@ fn test_report_error_stylesheet() {
let lock = SharedRwLock::new(); let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty())); let media = Arc::new(lock.wrap(MediaList::empty()));
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock, Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
None, &error_reporter, 5u64); None, &error_reporter, QuirksMode::NoQuirks, 5u64);
let mut errors = errors.lock().unwrap(); let mut errors = errors.lock().unwrap();

Просмотреть файл

@ -8,6 +8,7 @@ use media_queries::CSSErrorReporterTest;
use servo_config::prefs::{PREFS, PrefValue}; use servo_config::prefs::{PREFS, PrefValue};
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::sync::Arc; use std::sync::Arc;
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::{LengthParsingMode, Parse, ParserContext};
use style::shared_lock::SharedRwLock; use style::shared_lock::SharedRwLock;
@ -32,6 +33,7 @@ macro_rules! stylesheet {
$shared_lock, $shared_lock,
None, None,
&$error_reporter, &$error_reporter,
QuirksMode::NoQuirks,
0u64 0u64
)) ))
} }
@ -293,7 +295,8 @@ 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); LengthParsingMode::Default,
QuirksMode::NoQuirks);
macro_rules! from_css { macro_rules! from_css {
($css:expr) => { ($css:expr) => {
@ -303,9 +306,9 @@ fn constrain_viewport() {
let initial_viewport = TypedSize2D::new(800., 600.); let initial_viewport = TypedSize2D::new(800., 600.);
let device = Device::new(MediaType::Screen, initial_viewport); let device = Device::new(MediaType::Screen, initial_viewport);
assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("")), None); assert_eq!(ViewportConstraints::maybe_new(&device, from_css!(""), QuirksMode::NoQuirks), None);
assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 320px auto")), assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 320px auto"), QuirksMode::NoQuirks),
Some(ViewportConstraints { Some(ViewportConstraints {
size: initial_viewport, size: initial_viewport,
@ -317,7 +320,7 @@ fn constrain_viewport() {
orientation: Orientation::Auto orientation: Orientation::Auto
})); }));
assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 320px auto")), assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 320px auto"), QuirksMode::NoQuirks),
Some(ViewportConstraints { Some(ViewportConstraints {
size: initial_viewport, size: initial_viewport,
@ -329,10 +332,12 @@ fn constrain_viewport() {
orientation: Orientation::Auto orientation: Orientation::Auto
})); }));
assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 800px; height: 600px;\ assert_eq!(ViewportConstraints::maybe_new(&device,
zoom: 1;\ from_css!("width: 800px; height: 600px;\
user-zoom: zoom;\ zoom: 1;\
orientation: auto;")), user-zoom: zoom;\
orientation: auto;"),
QuirksMode::NoQuirks),
Some(ViewportConstraints { Some(ViewportConstraints {
size: initial_viewport, size: initial_viewport,
@ -346,7 +351,7 @@ fn constrain_viewport() {
let initial_viewport = TypedSize2D::new(200., 150.); let initial_viewport = TypedSize2D::new(200., 150.);
let device = Device::new(MediaType::Screen, initial_viewport); let device = Device::new(MediaType::Screen, initial_viewport);
assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 320px auto")), assert_eq!(ViewportConstraints::maybe_new(&device, from_css!("width: 320px auto"), QuirksMode::NoQuirks),
Some(ViewportConstraints { Some(ViewportConstraints {
size: TypedSize2D::new(320., 240.), size: TypedSize2D::new(320., 240.),