Skip to main content

script/dom/css/
cssfontfeaturevaluesrule.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::reflect_dom_object_with_cx;
8use servo_arc::Arc;
9use style::shared_lock::ToCssWithGuard;
10use style::stylesheets::{CssRuleType, FontFeatureValuesRule};
11
12use super::cssrule::{CSSRule, SpecificCSSRule};
13use super::cssstylesheet::CSSStyleSheet;
14use crate::dom::bindings::root::DomRoot;
15use crate::dom::bindings::str::DOMString;
16use crate::dom::window::Window;
17
18#[dom_struct]
19pub(crate) struct CSSFontFeatureValuesRule {
20    css_rule: CSSRule,
21    #[no_trace]
22    #[conditional_malloc_size_of]
23    font_feature_values_rule: Arc<FontFeatureValuesRule>,
24}
25
26impl CSSFontFeatureValuesRule {
27    fn new_inherited(
28        parent_stylesheet: &CSSStyleSheet,
29        font_feature_values_rule: Arc<FontFeatureValuesRule>,
30    ) -> CSSFontFeatureValuesRule {
31        CSSFontFeatureValuesRule {
32            css_rule: CSSRule::new_inherited(parent_stylesheet),
33            font_feature_values_rule,
34        }
35    }
36
37    pub(crate) fn new(
38        cx: &mut JSContext,
39        window: &Window,
40        parent_stylesheet: &CSSStyleSheet,
41        font_feature_values_rule: Arc<FontFeatureValuesRule>,
42    ) -> DomRoot<CSSFontFeatureValuesRule> {
43        reflect_dom_object_with_cx(
44            Box::new(CSSFontFeatureValuesRule::new_inherited(
45                parent_stylesheet,
46                font_feature_values_rule,
47            )),
48            window,
49            cx,
50        )
51    }
52}
53
54impl SpecificCSSRule for CSSFontFeatureValuesRule {
55    fn ty(&self) -> CssRuleType {
56        CssRuleType::FontFeatureValues
57    }
58
59    fn get_css(&self) -> DOMString {
60        let guard = self.css_rule.shared_lock().read();
61        self.font_feature_values_rule.to_css_string(&guard).into()
62    }
63}