Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSSOM bits for @supports: CSSConditionRule and CSSSupportsRule, with…
… conditionText attribute
- Loading branch information
1 parent
1b0842e
commit b4a83b6
Showing
12 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters