mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Auto merge of #14789 - Manishearth:supports, r=SimonSapin
Support @supports fixes #14786 cc @heycam @upsuper r? @SimonSapin <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14789) <!-- Reviewable:end -->
This commit is contained in:
commit
50bba770d6
98 changed files with 638 additions and 218 deletions
|
@ -99,6 +99,7 @@ use style::media_queries::MediaList;
|
||||||
use style::properties::PropertyDeclarationBlock;
|
use style::properties::PropertyDeclarationBlock;
|
||||||
use style::selector_parser::{PseudoElement, Snapshot};
|
use style::selector_parser::{PseudoElement, Snapshot};
|
||||||
use style::stylesheets::{CssRules, KeyframesRule, MediaRule, NamespaceRule, StyleRule, ImportRule};
|
use style::stylesheets::{CssRules, KeyframesRule, MediaRule, NamespaceRule, StyleRule, ImportRule};
|
||||||
|
use style::stylesheets::SupportsRule;
|
||||||
use style::values::specified::Length;
|
use style::values::specified::Length;
|
||||||
use style::viewport::ViewportRule;
|
use style::viewport::ViewportRule;
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
|
@ -531,6 +532,12 @@ unsafe impl JSTraceable for RwLock<ImportRule> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl JSTraceable for RwLock<SupportsRule> {
|
||||||
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl JSTraceable for RwLock<MediaRule> {
|
unsafe impl JSTraceable for RwLock<MediaRule> {
|
||||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
|
|
|
@ -2,11 +2,14 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use cssparser::serialize_identifier;
|
use cssparser::{Parser, serialize_identifier};
|
||||||
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::reflector::Reflector;
|
use dom::bindings::reflector::Reflector;
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
use style::parser::ParserContext;
|
||||||
|
use style::supports::{Declaration, parse_condition_or_declaration};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct CSS {
|
pub struct CSS {
|
||||||
|
@ -14,10 +17,31 @@ pub struct CSS {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSS {
|
impl CSS {
|
||||||
// http://dev.w3.org/csswg/cssom/#serialize-an-identifier
|
/// http://dev.w3.org/csswg/cssom/#serialize-an-identifier
|
||||||
pub fn Escape(_: &Window, ident: DOMString) -> Fallible<DOMString> {
|
pub fn Escape(_: &Window, ident: DOMString) -> Fallible<DOMString> {
|
||||||
let mut escaped = String::new();
|
let mut escaped = String::new();
|
||||||
serialize_identifier(&ident, &mut escaped).unwrap();
|
serialize_identifier(&ident, &mut escaped).unwrap();
|
||||||
Ok(DOMString::from(escaped))
|
Ok(DOMString::from(escaped))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional/#dom-css-supports
|
||||||
|
pub fn Supports(win: &Window, property: DOMString, value: DOMString) -> bool {
|
||||||
|
let decl = Declaration { prop: property.into(), val: value.into() };
|
||||||
|
let url = win.Document().url();
|
||||||
|
let context = ParserContext::new_for_cssom(&url);
|
||||||
|
decl.eval(&context)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional/#dom-css-supports
|
||||||
|
pub fn Supports_(win: &Window, condition: DOMString) -> bool {
|
||||||
|
let mut input = Parser::new(&condition);
|
||||||
|
let cond = parse_condition_or_declaration(&mut input);
|
||||||
|
if let Ok(cond) = cond {
|
||||||
|
let url = win.Document().url();
|
||||||
|
let context = ParserContext::new_for_cssom(&url);
|
||||||
|
cond.eval(&context)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
53
components/script/dom/cssconditionrule.rs
Normal file
53
components/script/dom/cssconditionrule.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::CSSConditionRuleBinding::CSSConditionRuleMethods;
|
||||||
|
use dom::bindings::inheritance::Castable;
|
||||||
|
use dom::bindings::str::DOMString;
|
||||||
|
use dom::cssgroupingrule::CSSGroupingRule;
|
||||||
|
use dom::cssmediarule::CSSMediaRule;
|
||||||
|
use dom::cssstylesheet::CSSStyleSheet;
|
||||||
|
use dom::csssupportsrule::CSSSupportsRule;
|
||||||
|
use parking_lot::RwLock;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use style::stylesheets::CssRules as StyleCssRules;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct CSSConditionRule {
|
||||||
|
cssgroupingrule: CSSGroupingRule,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CSSConditionRule {
|
||||||
|
pub fn new_inherited(parent_stylesheet: &CSSStyleSheet,
|
||||||
|
rules: Arc<RwLock<StyleCssRules>>) -> CSSConditionRule {
|
||||||
|
CSSConditionRule {
|
||||||
|
cssgroupingrule: CSSGroupingRule::new_inherited(parent_stylesheet, rules),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CSSConditionRuleMethods for CSSConditionRule {
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#dom-cssconditionrule-conditiontext
|
||||||
|
fn ConditionText(&self) -> DOMString {
|
||||||
|
if let Some(rule) = self.downcast::<CSSMediaRule>() {
|
||||||
|
rule.get_condition_text()
|
||||||
|
} else if let Some(rule) = self.downcast::<CSSSupportsRule>() {
|
||||||
|
rule.get_condition_text()
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#dom-cssconditionrule-conditiontext
|
||||||
|
fn SetConditionText(&self, text: DOMString) {
|
||||||
|
if let Some(rule) = self.downcast::<CSSMediaRule>() {
|
||||||
|
rule.set_condition_text(text)
|
||||||
|
} else if let Some(rule) = self.downcast::<CSSSupportsRule>() {
|
||||||
|
rule.set_condition_text(text)
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,24 +2,26 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
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::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;
|
||||||
use dom::cssgroupingrule::CSSGroupingRule;
|
use dom::cssconditionrule::CSSConditionRule;
|
||||||
use dom::cssrule::SpecificCSSRule;
|
use dom::cssrule::SpecificCSSRule;
|
||||||
use dom::cssstylesheet::CSSStyleSheet;
|
use dom::cssstylesheet::CSSStyleSheet;
|
||||||
use dom::medialist::MediaList;
|
use dom::medialist::MediaList;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::stylesheets::MediaRule;
|
use style::stylesheets::MediaRule;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct CSSMediaRule {
|
pub struct CSSMediaRule {
|
||||||
cssrule: CSSGroupingRule,
|
cssrule: CSSConditionRule,
|
||||||
#[ignore_heap_size_of = "Arc"]
|
#[ignore_heap_size_of = "Arc"]
|
||||||
mediarule: Arc<RwLock<MediaRule>>,
|
mediarule: Arc<RwLock<MediaRule>>,
|
||||||
medialist: MutNullableJS<MediaList>,
|
medialist: MutNullableJS<MediaList>,
|
||||||
|
@ -30,7 +32,7 @@ impl CSSMediaRule {
|
||||||
-> CSSMediaRule {
|
-> CSSMediaRule {
|
||||||
let list = mediarule.read().rules.clone();
|
let list = mediarule.read().rules.clone();
|
||||||
CSSMediaRule {
|
CSSMediaRule {
|
||||||
cssrule: CSSGroupingRule::new_inherited(parent_stylesheet, list),
|
cssrule: CSSConditionRule::new_inherited(parent_stylesheet, list),
|
||||||
mediarule: mediarule,
|
mediarule: mediarule,
|
||||||
medialist: MutNullableJS::new(None),
|
medialist: MutNullableJS::new(None),
|
||||||
}
|
}
|
||||||
|
@ -48,6 +50,22 @@ impl CSSMediaRule {
|
||||||
self.medialist.or_init(|| MediaList::new(self.global().as_window(),
|
self.medialist.or_init(|| MediaList::new(self.global().as_window(),
|
||||||
self.mediarule.read().media_queries.clone()))
|
self.mediarule.read().media_queries.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface
|
||||||
|
pub fn get_condition_text(&self) -> DOMString {
|
||||||
|
let rule = self.mediarule.read();
|
||||||
|
let list = rule.media_queries.read();
|
||||||
|
list.to_css_string().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface
|
||||||
|
pub fn set_condition_text(&self, text: DOMString) {
|
||||||
|
let mut input = Parser::new(&text);
|
||||||
|
let new_medialist = parse_media_query_list(&mut input);
|
||||||
|
let rule = self.mediarule.read();
|
||||||
|
let mut list = rule.media_queries.write();
|
||||||
|
*list = new_medialist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecificCSSRule for CSSMediaRule {
|
impl SpecificCSSRule for CSSMediaRule {
|
||||||
|
|
|
@ -15,6 +15,7 @@ use dom::cssmediarule::CSSMediaRule;
|
||||||
use dom::cssnamespacerule::CSSNamespaceRule;
|
use dom::cssnamespacerule::CSSNamespaceRule;
|
||||||
use dom::cssstylerule::CSSStyleRule;
|
use dom::cssstylerule::CSSStyleRule;
|
||||||
use dom::cssstylesheet::CSSStyleSheet;
|
use dom::cssstylesheet::CSSStyleSheet;
|
||||||
|
use dom::csssupportsrule::CSSSupportsRule;
|
||||||
use dom::cssviewportrule::CSSViewportRule;
|
use dom::cssviewportrule::CSSViewportRule;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -59,6 +60,8 @@ impl CSSRule {
|
||||||
rule as &SpecificCSSRule
|
rule as &SpecificCSSRule
|
||||||
} else if let Some(rule) = self.downcast::<CSSImportRule>() {
|
} else if let Some(rule) = self.downcast::<CSSImportRule>() {
|
||||||
rule as &SpecificCSSRule
|
rule as &SpecificCSSRule
|
||||||
|
} else if let Some(rule) = self.downcast::<CSSSupportsRule>() {
|
||||||
|
rule as &SpecificCSSRule
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
@ -77,6 +80,7 @@ impl CSSRule {
|
||||||
StyleCssRule::Media(s) => Root::upcast(CSSMediaRule::new(window, parent_stylesheet, s)),
|
StyleCssRule::Media(s) => Root::upcast(CSSMediaRule::new(window, parent_stylesheet, s)),
|
||||||
StyleCssRule::Namespace(s) => Root::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s)),
|
StyleCssRule::Namespace(s) => Root::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s)),
|
||||||
StyleCssRule::Viewport(s) => Root::upcast(CSSViewportRule::new(window, parent_stylesheet, s)),
|
StyleCssRule::Viewport(s) => Root::upcast(CSSViewportRule::new(window, parent_stylesheet, s)),
|
||||||
|
StyleCssRule::Supports(s) => Root::upcast(CSSSupportsRule::new(window, parent_stylesheet, s)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
77
components/script/dom/csssupportsrule.rs
Normal file
77
components/script/dom/csssupportsrule.rs
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use cssparser::Parser;
|
||||||
|
use dom::bindings::codegen::Bindings::CSSSupportsRuleBinding;
|
||||||
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||||
|
use dom::bindings::js::Root;
|
||||||
|
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||||
|
use dom::bindings::str::DOMString;
|
||||||
|
use dom::cssconditionrule::CSSConditionRule;
|
||||||
|
use dom::cssrule::SpecificCSSRule;
|
||||||
|
use dom::cssstylesheet::CSSStyleSheet;
|
||||||
|
use dom::window::Window;
|
||||||
|
use parking_lot::RwLock;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use style::parser::ParserContext;
|
||||||
|
use style::stylesheets::SupportsRule;
|
||||||
|
use style::supports::SupportsCondition;
|
||||||
|
use style_traits::ToCss;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct CSSSupportsRule {
|
||||||
|
cssrule: CSSConditionRule,
|
||||||
|
#[ignore_heap_size_of = "Arc"]
|
||||||
|
supportsrule: Arc<RwLock<SupportsRule>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CSSSupportsRule {
|
||||||
|
fn new_inherited(parent_stylesheet: &CSSStyleSheet, supportsrule: Arc<RwLock<SupportsRule>>)
|
||||||
|
-> CSSSupportsRule {
|
||||||
|
let list = supportsrule.read().rules.clone();
|
||||||
|
CSSSupportsRule {
|
||||||
|
cssrule: CSSConditionRule::new_inherited(parent_stylesheet, list),
|
||||||
|
supportsrule: supportsrule,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
|
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||||
|
supportsrule: Arc<RwLock<SupportsRule>>) -> Root<CSSSupportsRule> {
|
||||||
|
reflect_dom_object(box CSSSupportsRule::new_inherited(parent_stylesheet, supportsrule),
|
||||||
|
window,
|
||||||
|
CSSSupportsRuleBinding::Wrap)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
|
||||||
|
pub fn get_condition_text(&self) -> DOMString {
|
||||||
|
let rule = self.supportsrule.read();
|
||||||
|
rule.condition.to_css_string().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
|
||||||
|
pub fn set_condition_text(&self, text: DOMString) {
|
||||||
|
let mut input = Parser::new(&text);
|
||||||
|
let cond = SupportsCondition::parse(&mut input);
|
||||||
|
if let Ok(cond) = cond {
|
||||||
|
let url = self.global().as_window().Document().url();
|
||||||
|
let context = ParserContext::new_for_cssom(&url);
|
||||||
|
let enabled = cond.eval(&context);
|
||||||
|
let mut rule = self.supportsrule.write();
|
||||||
|
rule.condition = cond;
|
||||||
|
rule.enabled = enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpecificCSSRule for CSSSupportsRule {
|
||||||
|
fn ty(&self) -> u16 {
|
||||||
|
use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants;
|
||||||
|
CSSRuleConstants::SUPPORTS_RULE
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_css(&self) -> DOMString {
|
||||||
|
self.supportsrule.read().to_css_string().into()
|
||||||
|
}
|
||||||
|
}
|
|
@ -240,6 +240,7 @@ pub mod console;
|
||||||
mod create;
|
mod create;
|
||||||
pub mod crypto;
|
pub mod crypto;
|
||||||
pub mod css;
|
pub mod css;
|
||||||
|
pub mod cssconditionrule;
|
||||||
pub mod cssfontfacerule;
|
pub mod cssfontfacerule;
|
||||||
pub mod cssgroupingrule;
|
pub mod cssgroupingrule;
|
||||||
pub mod cssimportrule;
|
pub mod cssimportrule;
|
||||||
|
@ -252,6 +253,7 @@ pub mod cssrulelist;
|
||||||
pub mod cssstyledeclaration;
|
pub mod cssstyledeclaration;
|
||||||
pub mod cssstylerule;
|
pub mod cssstylerule;
|
||||||
pub mod cssstylesheet;
|
pub mod cssstylesheet;
|
||||||
|
pub mod csssupportsrule;
|
||||||
pub mod cssviewportrule;
|
pub mod cssviewportrule;
|
||||||
pub mod customevent;
|
pub mod customevent;
|
||||||
pub mod dedicatedworkerglobalscope;
|
pub mod dedicatedworkerglobalscope;
|
||||||
|
|
|
@ -11,3 +11,9 @@ interface CSS {
|
||||||
[Throws]
|
[Throws]
|
||||||
static DOMString escape(DOMString ident);
|
static DOMString escape(DOMString ident);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-conditional-3/#the-css-interface
|
||||||
|
partial interface CSS {
|
||||||
|
static boolean supports(DOMString property, DOMString value);
|
||||||
|
static boolean supports(DOMString conditionText);
|
||||||
|
};
|
||||||
|
|
9
components/script/dom/webidls/CSSConditionRule.webidl
Normal file
9
components/script/dom/webidls/CSSConditionRule.webidl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-conditional/#cssconditionrule
|
||||||
|
[Abstract, Exposed=Window]
|
||||||
|
interface CSSConditionRule : CSSGroupingRule {
|
||||||
|
attribute DOMString conditionText;
|
||||||
|
};
|
|
@ -3,7 +3,8 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom/#the-cssmediarule-interface
|
// https://drafts.csswg.org/cssom/#the-cssmediarule-interface
|
||||||
|
// https://drafts.csswg.org/css-conditional/#cssmediarule
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
interface CSSMediaRule : CSSGroupingRule {
|
interface CSSMediaRule : CSSConditionRule {
|
||||||
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,3 +31,7 @@ partial interface CSSRule {
|
||||||
const unsigned short VIEWPORT_RULE = 15;
|
const unsigned short VIEWPORT_RULE = 15;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface
|
||||||
|
partial interface CSSRule {
|
||||||
|
const unsigned short SUPPORTS_RULE = 12;
|
||||||
|
};
|
||||||
|
|
8
components/script/dom/webidls/CSSSupportsRule.webidl
Normal file
8
components/script/dom/webidls/CSSSupportsRule.webidl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-conditional/#csssupportsrule
|
||||||
|
[Exposed=Window]
|
||||||
|
interface CSSSupportsRule : CSSConditionRule {
|
||||||
|
};
|
|
@ -122,6 +122,7 @@ pub mod sequential;
|
||||||
pub mod sink;
|
pub mod sink;
|
||||||
pub mod str;
|
pub mod str;
|
||||||
pub mod stylesheets;
|
pub mod stylesheets;
|
||||||
|
pub mod supports;
|
||||||
pub mod thread_state;
|
pub mod thread_state;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
pub mod traversal;
|
pub mod traversal;
|
||||||
|
|
|
@ -11,7 +11,7 @@ use error_reporting::ParseErrorReporter;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
|
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use stylesheets::Origin;
|
use stylesheets::{MemoryHoleReporter, Origin};
|
||||||
|
|
||||||
/// Extra data that the style backend may need to parse stylesheets.
|
/// Extra data that the style backend may need to parse stylesheets.
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
|
@ -78,6 +78,11 @@ impl<'a> ParserContext<'a> {
|
||||||
let extra_data = ParserContextExtraData::default();
|
let extra_data = ParserContextExtraData::default();
|
||||||
Self::new_with_extra_data(stylesheet_origin, base_url, error_reporter, extra_data)
|
Self::new_with_extra_data(stylesheet_origin, base_url, error_reporter, extra_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a parser context for on-the-fly parsing in CSSOM
|
||||||
|
pub fn new_for_cssom(base_url: &'a ServoUrl) -> ParserContext<'a> {
|
||||||
|
Self::new(Origin::User, base_url, Box::new(MemoryHoleReporter))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defaults to a no-op.
|
/// Defaults to a no-op.
|
||||||
|
|
|
@ -28,6 +28,7 @@ use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use stylist::FnvHashMap;
|
use stylist::FnvHashMap;
|
||||||
|
use supports::SupportsCondition;
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
use viewport::ViewportRule;
|
use viewport::ViewportRule;
|
||||||
|
|
||||||
|
@ -215,6 +216,7 @@ pub enum CssRule {
|
||||||
FontFace(Arc<RwLock<FontFaceRule>>),
|
FontFace(Arc<RwLock<FontFaceRule>>),
|
||||||
Viewport(Arc<RwLock<ViewportRule>>),
|
Viewport(Arc<RwLock<ViewportRule>>),
|
||||||
Keyframes(Arc<RwLock<KeyframesRule>>),
|
Keyframes(Arc<RwLock<KeyframesRule>>),
|
||||||
|
Supports(Arc<RwLock<SupportsRule>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
@ -274,6 +276,7 @@ impl CssRule {
|
||||||
CssRule::Keyframes(_) => CssRuleType::Keyframes,
|
CssRule::Keyframes(_) => CssRuleType::Keyframes,
|
||||||
CssRule::Namespace(_) => CssRuleType::Namespace,
|
CssRule::Namespace(_) => CssRuleType::Namespace,
|
||||||
CssRule::Viewport(_) => CssRuleType::Viewport,
|
CssRule::Viewport(_) => CssRuleType::Viewport,
|
||||||
|
CssRule::Supports(_) => CssRuleType::Supports,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,9 +293,10 @@ impl CssRule {
|
||||||
///
|
///
|
||||||
/// Note that only some types of rules can contain rules. An empty slice is
|
/// Note that only some types of rules can contain rules. An empty slice is
|
||||||
/// used for others.
|
/// used for others.
|
||||||
|
///
|
||||||
|
/// This will not recurse down unsupported @supports rules
|
||||||
pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R
|
pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R
|
||||||
where F: FnMut(&[CssRule], Option<&MediaList>) -> R
|
where F: FnMut(&[CssRule], Option<&MediaList>) -> R {
|
||||||
{
|
|
||||||
match *self {
|
match *self {
|
||||||
CssRule::Import(ref lock) => {
|
CssRule::Import(ref lock) => {
|
||||||
let rule = lock.read();
|
let rule = lock.read();
|
||||||
|
@ -315,6 +319,16 @@ impl CssRule {
|
||||||
let rules = &media_rule.rules.read().0;
|
let rules = &media_rule.rules.read().0;
|
||||||
f(rules, Some(&mq))
|
f(rules, Some(&mq))
|
||||||
}
|
}
|
||||||
|
CssRule::Supports(ref lock) => {
|
||||||
|
let supports_rule = lock.read();
|
||||||
|
let enabled = supports_rule.enabled;
|
||||||
|
if enabled {
|
||||||
|
let rules = &supports_rule.rules.read().0;
|
||||||
|
f(rules, None)
|
||||||
|
} else {
|
||||||
|
f(&[], None)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +381,7 @@ impl ToCss for CssRule {
|
||||||
CssRule::Viewport(ref lock) => lock.read().to_css(dest),
|
CssRule::Viewport(ref lock) => lock.read().to_css(dest),
|
||||||
CssRule::Keyframes(ref lock) => lock.read().to_css(dest),
|
CssRule::Keyframes(ref lock) => lock.read().to_css(dest),
|
||||||
CssRule::Media(ref lock) => lock.read().to_css(dest),
|
CssRule::Media(ref lock) => lock.read().to_css(dest),
|
||||||
|
CssRule::Supports(ref lock) => lock.read().to_css(dest),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,7 +456,12 @@ impl ToCss for KeyframesRule {
|
||||||
try!(dest.write_str(&*self.name.to_string()));
|
try!(dest.write_str(&*self.name.to_string()));
|
||||||
try!(dest.write_str(" { "));
|
try!(dest.write_str(" { "));
|
||||||
let iter = self.keyframes.iter();
|
let iter = self.keyframes.iter();
|
||||||
|
let mut first = true;
|
||||||
for lock in iter {
|
for lock in iter {
|
||||||
|
if !first {
|
||||||
|
try!(dest.write_str(" "));
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
let keyframe = lock.read();
|
let keyframe = lock.read();
|
||||||
try!(keyframe.to_css(dest));
|
try!(keyframe.to_css(dest));
|
||||||
}
|
}
|
||||||
|
@ -460,9 +480,34 @@ impl ToCss for MediaRule {
|
||||||
// Serialization of MediaRule is not specced.
|
// Serialization of MediaRule is not specced.
|
||||||
// https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSMediaRule
|
// https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSMediaRule
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
try!(dest.write_str("@media ("));
|
try!(dest.write_str("@media "));
|
||||||
try!(self.media_queries.read().to_css(dest));
|
try!(self.media_queries.read().to_css(dest));
|
||||||
try!(dest.write_str(") {"));
|
try!(dest.write_str(" {"));
|
||||||
|
for rule in self.rules.read().0.iter() {
|
||||||
|
try!(dest.write_str(" "));
|
||||||
|
try!(rule.to_css(dest));
|
||||||
|
}
|
||||||
|
dest.write_str(" }")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// An @supports rule
|
||||||
|
pub struct SupportsRule {
|
||||||
|
/// The parsed condition
|
||||||
|
pub condition: SupportsCondition,
|
||||||
|
/// Child rules
|
||||||
|
pub rules: Arc<RwLock<CssRules>>,
|
||||||
|
/// The result of evaluating the condition
|
||||||
|
pub enabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for SupportsRule {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
try!(dest.write_str("@supports "));
|
||||||
|
try!(self.condition.to_css(dest));
|
||||||
|
try!(dest.write_str(" {"));
|
||||||
for rule in self.rules.read().0.iter() {
|
for rule in self.rules.read().0.iter() {
|
||||||
try!(dest.write_str(" "));
|
try!(dest.write_str(" "));
|
||||||
try!(rule.to_css(dest));
|
try!(rule.to_css(dest));
|
||||||
|
@ -712,6 +757,7 @@ rule_filter! {
|
||||||
effective_font_face_rules(FontFace => FontFaceRule),
|
effective_font_face_rules(FontFace => FontFaceRule),
|
||||||
effective_viewport_rules(Viewport => ViewportRule),
|
effective_viewport_rules(Viewport => ViewportRule),
|
||||||
effective_keyframes_rules(Keyframes => KeyframesRule),
|
effective_keyframes_rules(Keyframes => KeyframesRule),
|
||||||
|
effective_supports_rules(Supports => SupportsRule),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The stylesheet loader is the abstraction used to trigger network requests
|
/// The stylesheet loader is the abstraction used to trigger network requests
|
||||||
|
@ -758,6 +804,8 @@ enum AtRulePrelude {
|
||||||
FontFace,
|
FontFace,
|
||||||
/// A @media rule prelude, with its media queries.
|
/// A @media rule prelude, with its media queries.
|
||||||
Media(Arc<RwLock<MediaList>>),
|
Media(Arc<RwLock<MediaList>>),
|
||||||
|
/// An @supports rule, with its conditional
|
||||||
|
Supports(SupportsCondition),
|
||||||
/// A @viewport rule prelude.
|
/// A @viewport rule prelude.
|
||||||
Viewport,
|
Viewport,
|
||||||
/// A @keyframes rule, with its animation name.
|
/// A @keyframes rule, with its animation name.
|
||||||
|
@ -913,6 +961,10 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
|
||||||
let media_queries = parse_media_query_list(input);
|
let media_queries = parse_media_query_list(input);
|
||||||
Ok(AtRuleType::WithBlock(AtRulePrelude::Media(Arc::new(RwLock::new(media_queries)))))
|
Ok(AtRuleType::WithBlock(AtRulePrelude::Media(Arc::new(RwLock::new(media_queries)))))
|
||||||
},
|
},
|
||||||
|
"supports" => {
|
||||||
|
let cond = SupportsCondition::parse(input)?;
|
||||||
|
Ok(AtRuleType::WithBlock(AtRulePrelude::Supports(cond)))
|
||||||
|
},
|
||||||
"font-face" => {
|
"font-face" => {
|
||||||
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
|
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
|
||||||
},
|
},
|
||||||
|
@ -949,6 +1001,14 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
|
||||||
rules: self.parse_nested_rules(input),
|
rules: self.parse_nested_rules(input),
|
||||||
}))))
|
}))))
|
||||||
}
|
}
|
||||||
|
AtRulePrelude::Supports(cond) => {
|
||||||
|
let enabled = cond.eval(self.context);
|
||||||
|
Ok(CssRule::Supports(Arc::new(RwLock::new(SupportsRule {
|
||||||
|
condition: cond,
|
||||||
|
rules: self.parse_nested_rules(input),
|
||||||
|
enabled: enabled,
|
||||||
|
}))))
|
||||||
|
}
|
||||||
AtRulePrelude::Viewport => {
|
AtRulePrelude::Viewport => {
|
||||||
Ok(CssRule::Viewport(Arc::new(RwLock::new(
|
Ok(CssRule::Viewport(Arc::new(RwLock::new(
|
||||||
try!(ViewportRule::parse(input, self.context))))))
|
try!(ViewportRule::parse(input, self.context))))))
|
||||||
|
|
|
@ -408,14 +408,15 @@ impl Stylist {
|
||||||
|
|
||||||
fn mq_eval_changed(rules: &[CssRule], before: &Device, after: &Device) -> bool {
|
fn mq_eval_changed(rules: &[CssRule], before: &Device, after: &Device) -> bool {
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
if rule.with_nested_rules_and_mq(|rules, mq| {
|
let changed = rule.with_nested_rules_and_mq(|rules, mq| {
|
||||||
if let Some(mq) = mq {
|
if let Some(mq) = mq {
|
||||||
if mq.evaluate(before) != mq.evaluate(after) {
|
if mq.evaluate(before) != mq.evaluate(after) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mq_eval_changed(rules, before, after)
|
mq_eval_changed(rules, before, after)
|
||||||
}) {
|
});
|
||||||
|
if changed {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
231
components/style/supports.rs
Normal file
231
components/style/supports.rs
Normal file
|
@ -0,0 +1,231 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! [@supports rules](https://drafts.csswg.org/css-conditional-3/#at-supports)
|
||||||
|
|
||||||
|
use cssparser::{parse_important, Parser, Token};
|
||||||
|
use parser::ParserContext;
|
||||||
|
use properties::{PropertyDeclaration, PropertyId};
|
||||||
|
use std::fmt;
|
||||||
|
use style_traits::ToCss;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// An @supports condition
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#at-supports
|
||||||
|
pub enum SupportsCondition {
|
||||||
|
/// `not (condition)`
|
||||||
|
Not(Box<SupportsCondition>),
|
||||||
|
/// `(condition)`
|
||||||
|
Parenthesized(Box<SupportsCondition>),
|
||||||
|
/// `(condition) and (condition) and (condition) ..`
|
||||||
|
And(Vec<SupportsCondition>),
|
||||||
|
/// `(condition) or (condition) or (condition) ..`
|
||||||
|
Or(Vec<SupportsCondition>),
|
||||||
|
/// `property-ident: value` (value can be any tokens)
|
||||||
|
Declaration(Declaration),
|
||||||
|
/// `(any tokens)` or `func(any tokens)`
|
||||||
|
FutureSyntax(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SupportsCondition {
|
||||||
|
/// Parse a condition
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-conditional/#supports_condition
|
||||||
|
pub fn parse(input: &mut Parser) -> Result<SupportsCondition, ()> {
|
||||||
|
if let Ok(_) = input.try(|i| i.expect_ident_matching("not")) {
|
||||||
|
let inner = SupportsCondition::parse_in_parens(input)?;
|
||||||
|
return Ok(SupportsCondition::Not(Box::new(inner)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let in_parens = SupportsCondition::parse_in_parens(input)?;
|
||||||
|
|
||||||
|
let (keyword, wrapper) = match input.next() {
|
||||||
|
Err(()) => {
|
||||||
|
// End of input
|
||||||
|
return Ok(in_parens)
|
||||||
|
}
|
||||||
|
Ok(Token::Ident(ident)) => {
|
||||||
|
match_ignore_ascii_case! { ident,
|
||||||
|
"and" => ("and", SupportsCondition::And as fn(_) -> _),
|
||||||
|
"or" => ("or", SupportsCondition::Or as fn(_) -> _),
|
||||||
|
_ => return Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => return Err(())
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut conditions = Vec::with_capacity(2);
|
||||||
|
conditions.push(in_parens);
|
||||||
|
loop {
|
||||||
|
conditions.push(SupportsCondition::parse_in_parens(input)?);
|
||||||
|
if input.try(|input| input.expect_ident_matching(keyword)).is_err() {
|
||||||
|
// Did not find the expected keyword.
|
||||||
|
// If we found some other token,
|
||||||
|
// it will be rejected by `Parser::parse_entirely` somewhere up the stack.
|
||||||
|
return Ok(wrapper(conditions))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#supports_condition_in_parens
|
||||||
|
fn parse_in_parens(input: &mut Parser) -> Result<SupportsCondition, ()> {
|
||||||
|
// Whitespace is normally taken care of in `Parser::next`,
|
||||||
|
// but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases.
|
||||||
|
while input.try(Parser::expect_whitespace).is_ok() {}
|
||||||
|
let pos = input.position();
|
||||||
|
match input.next()? {
|
||||||
|
Token::ParenthesisBlock => {
|
||||||
|
input.parse_nested_block(|input| {
|
||||||
|
// `input.try()` not needed here since the alternative uses `consume_all()`.
|
||||||
|
parse_condition_or_declaration(input).or_else(|()| {
|
||||||
|
consume_all(input);
|
||||||
|
Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Token::Function(_) => {
|
||||||
|
input.parse_nested_block(|i| Ok(consume_all(i))).unwrap();
|
||||||
|
Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
|
||||||
|
}
|
||||||
|
_ => Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Evaluate a supports condition
|
||||||
|
pub fn eval(&self, cx: &ParserContext) -> bool {
|
||||||
|
match *self {
|
||||||
|
SupportsCondition::Not(ref cond) => !cond.eval(cx),
|
||||||
|
SupportsCondition::Parenthesized(ref cond) => cond.eval(cx),
|
||||||
|
SupportsCondition::And(ref vec) => vec.iter().all(|c| c.eval(cx)),
|
||||||
|
SupportsCondition::Or(ref vec) => vec.iter().any(|c| c.eval(cx)),
|
||||||
|
SupportsCondition::Declaration(ref decl) => decl.eval(cx),
|
||||||
|
SupportsCondition::FutureSyntax(_) => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// supports_condition | declaration
|
||||||
|
/// https://drafts.csswg.org/css-conditional/#dom-css-supports-conditiontext-conditiontext
|
||||||
|
pub fn parse_condition_or_declaration(input: &mut Parser) -> Result<SupportsCondition, ()> {
|
||||||
|
if let Ok(condition) = input.try(SupportsCondition::parse) {
|
||||||
|
Ok(SupportsCondition::Parenthesized(Box::new(condition)))
|
||||||
|
} else {
|
||||||
|
Declaration::parse(input).map(SupportsCondition::Declaration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for SupportsCondition {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
|
where W: fmt::Write {
|
||||||
|
match *self {
|
||||||
|
SupportsCondition::Not(ref cond) => {
|
||||||
|
dest.write_str("not ")?;
|
||||||
|
cond.to_css(dest)
|
||||||
|
}
|
||||||
|
SupportsCondition::Parenthesized(ref cond) => {
|
||||||
|
dest.write_str("(")?;
|
||||||
|
cond.to_css(dest)?;
|
||||||
|
dest.write_str(")")
|
||||||
|
}
|
||||||
|
SupportsCondition::And(ref vec) => {
|
||||||
|
let mut first = true;
|
||||||
|
for cond in vec {
|
||||||
|
if !first {
|
||||||
|
dest.write_str(" and ")?;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
cond.to_css(dest)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
SupportsCondition::Or(ref vec) => {
|
||||||
|
let mut first = true;
|
||||||
|
for cond in vec {
|
||||||
|
if !first {
|
||||||
|
dest.write_str(" or ")?;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
cond.to_css(dest)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
SupportsCondition::Declaration(ref decl) => {
|
||||||
|
dest.write_str("(")?;
|
||||||
|
decl.to_css(dest)?;
|
||||||
|
dest.write_str(")")
|
||||||
|
}
|
||||||
|
SupportsCondition::FutureSyntax(ref s) => dest.write_str(&s),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// A possibly-invalid property declaration
|
||||||
|
pub struct Declaration {
|
||||||
|
/// The property name
|
||||||
|
pub prop: String,
|
||||||
|
/// The property value
|
||||||
|
pub val: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for Declaration {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
|
where W: fmt::Write {
|
||||||
|
dest.write_str(&self.prop)?;
|
||||||
|
dest.write_str(":")?;
|
||||||
|
// no space, the `val` already contains any possible spaces
|
||||||
|
dest.write_str(&self.val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Slurps up input till exhausted, return string from source position
|
||||||
|
fn parse_anything(input: &mut Parser) -> String {
|
||||||
|
let pos = input.position();
|
||||||
|
consume_all(input);
|
||||||
|
input.slice_from(pos).to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// consume input till done
|
||||||
|
fn consume_all(input: &mut Parser) {
|
||||||
|
while let Ok(_) = input.next() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Declaration {
|
||||||
|
/// Parse a declaration
|
||||||
|
pub fn parse(input: &mut Parser) -> Result<Declaration, ()> {
|
||||||
|
let prop = input.expect_ident()?.into_owned();
|
||||||
|
input.expect_colon()?;
|
||||||
|
let val = parse_anything(input);
|
||||||
|
Ok(Declaration { prop: prop, val: val })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine if a declaration parses
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-conditional-3/#support-definition
|
||||||
|
pub fn eval(&self, cx: &ParserContext) -> bool {
|
||||||
|
use properties::PropertyDeclarationParseResult::*;
|
||||||
|
let id = if let Ok(id) = PropertyId::parse((&*self.prop).into()) {
|
||||||
|
id
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
};
|
||||||
|
let mut input = Parser::new(&self.val);
|
||||||
|
let mut list = Vec::new();
|
||||||
|
let res = PropertyDeclaration::parse(id, cx, &mut input,
|
||||||
|
&mut list, /* in_keyframe */ false);
|
||||||
|
let _ = input.try(parse_important);
|
||||||
|
if !input.is_exhausted() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
match res {
|
||||||
|
UnknownProperty => false,
|
||||||
|
ExperimentalProperty => false, // only happens for experimental props
|
||||||
|
// that haven't been enabled
|
||||||
|
InvalidValue => false,
|
||||||
|
AnimationPropertyInKeyframeBlock => unreachable!(),
|
||||||
|
ValidOrIgnoredDeclaration => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -185,3 +185,9 @@ impl Index<Range<Position>> for ServoUrl {
|
||||||
&self.0[range]
|
&self.0[range]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Url> for ServoUrl {
|
||||||
|
fn from(url: Url) -> Self {
|
||||||
|
ServoUrl::from_url(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -276,6 +276,11 @@ class MachCommands(CommandBase):
|
||||||
args += ["%s" % ' '.join(features + ["testing"])]
|
args += ["%s" % ' '.join(features + ["testing"])]
|
||||||
else:
|
else:
|
||||||
args += ["testing"]
|
args += ["testing"]
|
||||||
|
|
||||||
|
args += test_patterns
|
||||||
|
|
||||||
|
if nocapture:
|
||||||
|
args += ["--", "--nocapture"]
|
||||||
return call(args, env=env, cwd=self.servo_crate())
|
return call(args, env=env, cwd=self.servo_crate())
|
||||||
|
|
||||||
@Command('test-stylo',
|
@Command('test-stylo',
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1.12.0
|
1.13.0
|
||||||
|
|
|
@ -39,6 +39,25 @@ macro_rules! assert_roundtrip_with_context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! assert_roundtrip {
|
||||||
|
($fun:expr, $string:expr) => {
|
||||||
|
assert_roundtrip!($fun, $string, $string);
|
||||||
|
};
|
||||||
|
($fun:expr,$input:expr, $output:expr) => {
|
||||||
|
let mut parser = Parser::new($input);
|
||||||
|
let parsed = $fun(&mut parser)
|
||||||
|
.expect(&format!("Failed to parse {}", $input));
|
||||||
|
let serialized = ToCss::to_css_string(&parsed);
|
||||||
|
assert_eq!(serialized, $output);
|
||||||
|
|
||||||
|
let mut parser = Parser::new(&serialized);
|
||||||
|
let re_parsed = $fun(&mut parser)
|
||||||
|
.expect(&format!("Failed to parse serialization {}", $input));
|
||||||
|
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||||
|
assert_eq!(serialized, re_serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! parse_longhand {
|
macro_rules! parse_longhand {
|
||||||
($name:ident, $s:expr) => {{
|
($name:ident, $s:expr) => {{
|
||||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||||
|
@ -58,3 +77,4 @@ mod inherited_text;
|
||||||
mod mask;
|
mod mask;
|
||||||
mod position;
|
mod position;
|
||||||
mod selectors;
|
mod selectors;
|
||||||
|
mod supports;
|
||||||
|
|
14
tests/unit/style/parsing/supports.rs
Normal file
14
tests/unit/style/parsing/supports.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use cssparser::Parser;
|
||||||
|
use style::supports::SupportsCondition;
|
||||||
|
use style_traits::ToCss;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_supports_condition() {
|
||||||
|
assert_roundtrip!(SupportsCondition::parse, "(margin: 1px)");
|
||||||
|
assert_roundtrip!(SupportsCondition::parse, "not (--be: to be)");
|
||||||
|
assert_roundtrip!(SupportsCondition::parse, "(color: blue) and future-extension(4)");
|
||||||
|
}
|
|
@ -21,6 +21,13 @@ skip: true
|
||||||
[xhtml1print]
|
[xhtml1print]
|
||||||
skip: true
|
skip: true
|
||||||
|
|
||||||
|
[css-conditional-3_dev]
|
||||||
|
skip: false
|
||||||
|
[xhtml1]
|
||||||
|
skip: true
|
||||||
|
[xhtml1print]
|
||||||
|
skip: true
|
||||||
|
|
||||||
[css-flexbox-1_dev]
|
[css-flexbox-1_dev]
|
||||||
skip: false
|
skip: false
|
||||||
[xhtml1]
|
[xhtml1]
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
[001.htm]
|
||||||
|
type: testharness
|
||||||
|
[Inserting @font-face inside @supports works]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[Inserting an @supports inside a style rule should fail]
|
||||||
|
expected: FAIL
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
type: testharness
|
type: testharness
|
||||||
[changing transition-property / values]
|
[changing transition-property / values]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-external-supports-01.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-01.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-02.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-03.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-04.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-05.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-06.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-07.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-08.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-09.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-10.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-11.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-12.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-13.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-14.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-15.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-16.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-17.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-18.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-19.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-20.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-21.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-22.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-23.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-24.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-25.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-26.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-27.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-28.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-29.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-30.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-31.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-32.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-33.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-34.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-35.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-36.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-37.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-38.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-39.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-40.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-41.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-42.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-43.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-44.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-45.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-46.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-47.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-48.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-49.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-50.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-51.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-52.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-53.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-54.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-55.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-56.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-57.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-58.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-59.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-60.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-61.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-62.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-63.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-64.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-65.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-66.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[variable-supports-67.htm]
|
|
||||||
type: reftest
|
|
||||||
expected: FAIL
|
|
|
@ -1,5 +1,6 @@
|
||||||
[css-style-declaration-modifications.htm]
|
[css-style-declaration-modifications.htm]
|
||||||
type: testharness
|
type: testharness
|
||||||
|
expected: TIMEOUT
|
||||||
[CSSStyleDeclaration_accessible]
|
[CSSStyleDeclaration_accessible]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -204,3 +204,9 @@
|
||||||
[PseudoElement interface: attribute usedStyle]
|
[PseudoElement interface: attribute usedStyle]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
[CSSMediaRule interface: existence and properties of interface object]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[CSSMediaRule interface: existence and properties of interface prototype object]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -45847,6 +45847,12 @@
|
||||||
"deleted_reftests": {},
|
"deleted_reftests": {},
|
||||||
"items": {
|
"items": {
|
||||||
"testharness": {
|
"testharness": {
|
||||||
|
"cssom/CSS.html": [
|
||||||
|
{
|
||||||
|
"path": "cssom/CSS.html",
|
||||||
|
"url": "/cssom/CSS.html"
|
||||||
|
}
|
||||||
|
],
|
||||||
"cssom/CSSKeyframeRule.html": [
|
"cssom/CSSKeyframeRule.html": [
|
||||||
{
|
{
|
||||||
"path": "cssom/CSSKeyframeRule.html",
|
"path": "cssom/CSSKeyframeRule.html",
|
||||||
|
|
|
@ -20,6 +20,7 @@ test_interfaces([
|
||||||
"CharacterData",
|
"CharacterData",
|
||||||
"CloseEvent",
|
"CloseEvent",
|
||||||
"CSS",
|
"CSS",
|
||||||
|
"CSSConditionRule",
|
||||||
"CSSFontFaceRule",
|
"CSSFontFaceRule",
|
||||||
"CSSGroupingRule",
|
"CSSGroupingRule",
|
||||||
"CSSImportRule",
|
"CSSImportRule",
|
||||||
|
@ -32,6 +33,7 @@ test_interfaces([
|
||||||
"CSSStyleDeclaration",
|
"CSSStyleDeclaration",
|
||||||
"CSSStyleRule",
|
"CSSStyleRule",
|
||||||
"CSSStyleSheet",
|
"CSSStyleSheet",
|
||||||
|
"CSSSupportsRule",
|
||||||
"CSSViewportRule",
|
"CSSViewportRule",
|
||||||
"DOMMatrix",
|
"DOMMatrix",
|
||||||
"DOMMatrixReadOnly",
|
"DOMMatrixReadOnly",
|
||||||
|
|
37
tests/wpt/web-platform-tests/cssom/CSS.html
Normal file
37
tests/wpt/web-platform-tests/cssom/CSS.html
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>CSSOM - CSS interface</title>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script>
|
||||||
|
test(function () {
|
||||||
|
// https://drafts.csswg.org/cssom/#dom-css-escape
|
||||||
|
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
||||||
|
assert_equals(CSS.escape("hello world"), "hello\\ world", "CSS.escape: spaces get escaped with backslashes");
|
||||||
|
assert_equals(CSS.escape("hello\0world"), "hello\u{FFFD}world", "CSS.escape: NULL get replaced with U+FFFD REPLACEMENT CHARACTER");
|
||||||
|
assert_equals(CSS.escape("hello0world"), "hello0world", "CSS.escape: Numbers within string preserved");
|
||||||
|
assert_equals(CSS.escape("hello\x10world"), "hello\\10 world", "CSS.escape: Values between \\x01 and \\x1f are unicode escaped");
|
||||||
|
assert_equals(CSS.escape("hello\\world"), "hello\\\\world", "CSS.escape: Backslashes get backslash-escaped");
|
||||||
|
assert_equals(CSS.escape("hello\u{1234}world"), "hello\u{1234}world", "CSS.escape: Code points greater than U+0080 are preserved");
|
||||||
|
assert_equals(CSS.escape("hello\x7Fworld"), "hello\\7f world", "CSS.escape: Some code points less than U+0080 are unicode-escaped");
|
||||||
|
assert_equals(CSS.escape("-"), "\\-", "CSS.escape: Single dash escaped");
|
||||||
|
assert_equals(CSS.escape("0foo"), "\\30 foo", "CSS.escape: Numbers at the beginning of an ident get unicode escaped");
|
||||||
|
assert_equals(CSS.escape("-0foo"), "-\\30 foo", "CSS.escape: Numbers at the beginning of an ident after single hyphen get unicode escaped");
|
||||||
|
assert_equals(CSS.escape("--0foo"), "--0foo", "CSS.escape: Numbers at the beginning of an ident after multiple hyphens do not get unicode escaped");
|
||||||
|
}, "CSS.escape");
|
||||||
|
test(function () {
|
||||||
|
// https://drafts.csswg.org/css-conditional/#dom-css-supports
|
||||||
|
// https://drafts.csswg.org/css-conditional/#typedef-supports-condition
|
||||||
|
assert_equals(CSS.supports("color: red"), true, "CSS.supports: Single-argument form allows for declarations without enclosing parentheses");
|
||||||
|
assert_equals(CSS.supports("(color: red) and (color: blue)"), true, "CSS.supports: Complex conditions allowed");
|
||||||
|
assert_equals(CSS.supports("not (foobar)"), true, "CSS.supports: general_enclosed still parses");
|
||||||
|
}, "CSS.supports, one argument form");
|
||||||
|
test(function () {
|
||||||
|
// https://drafts.csswg.org/css-conditional/#dom-css-supports
|
||||||
|
// https://drafts.csswg.org/css-conditional/#dfn-support
|
||||||
|
assert_equals(CSS.supports("color", "red"), true, "CSS.supports: two argument form succeeds for known property");
|
||||||
|
assert_equals(CSS.supports("unknownproperty", "blah"), false, "CSS.supports: two argument form fails for unknown property");
|
||||||
|
assert_equals(CSS.supports("width", "blah"), false, "CSS.supports: two argument form fails for invalid value");
|
||||||
|
assert_equals(CSS.supports("--foo", "blah"), true, "CSS.supports: two argument form succeeds for custom property");
|
||||||
|
}, "CSS.supports, two argument form");
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue