/
githubmirror
/
servo
Обзор
Документация
Войти
/
githubmirror
/
servo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
components/script/dom/css/csspropertyrule.rs
112 строк
3 KB
Simon Wülker
script: Account for nested rules when parsing selectors for CSSOM (#46687)
21 июл 2026, 20:17
Не верифицирован
21 июл 2026, 20:17
f26e518
Код
Авторство
О чём код?
/* 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 https://mozilla.org/MPL/2.0/. */ use std::cell::RefCell; use dom_struct::dom_struct; use js::context::JSContext; use script_bindings::reflector::reflect_dom_object_with_cx; use servo_arc::Arc; use style::shared_lock::ToCssWithGuard; use style::stylesheets::{CssRuleType, PropertyRule}; use style_traits::ToCss; use super::cssrule::{CSSRule, SpecificCSSRule}; use super::cssstylesheet::CSSStyleSheet; use crate::dom::bindings::codegen::Bindings::CSSPropertyRuleBinding::CSSPropertyRuleMethods; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::css::cssgroupingrule::CSSGroupingRule; use crate::dom::window::Window; #[dom_struct] pub(crate) struct CSSPropertyRule { css_rule: CSSRule, #[ignore_malloc_size_of = "Stylo"] #[no_trace] property_rule: RefCell<Arc<PropertyRule>>, } impl CSSPropertyRule { fn new_inherited( parent_rule: Option<&CSSGroupingRule>, parent_stylesheet: &CSSStyleSheet, property_rule: Arc<PropertyRule>, ) -> Self { CSSPropertyRule { css_rule: CSSRule::new_inherited(parent_rule, parent_stylesheet), property_rule: RefCell::new(property_rule), } } pub(crate) fn new( cx: &mut JSContext, window: &Window, parent_rule: Option<&CSSGroupingRule>, parent_stylesheet: &CSSStyleSheet, property_rule: Arc<PropertyRule>, ) -> DomRoot<Self> { reflect_dom_object_with_cx( Box::new(Self::new_inherited( parent_rule, parent_stylesheet, property_rule, )), window, cx, ) } pub(crate) fn update_rule(&self, property_rule: Arc<PropertyRule>) { *self.property_rule.borrow_mut() = property_rule; } } impl SpecificCSSRule for CSSPropertyRule { fn ty(&self) -> CssRuleType { CssRuleType::Property } fn get_css(&self) -> DOMString { let guard = self.css_rule.shared_lock().read(); self.property_rule.borrow().to_css_string(&guard).into() } } impl CSSPropertyRuleMethods<crate::DomTypeHolder> for CSSPropertyRule { /// <https://drafts.css-houdini.org/css-properties-values-api/#dom-csspropertyrule-name> fn Name(&self) -> DOMString { format!("--{}", self.property_rule.borrow().name.0).into() } /// <https://drafts.css-houdini.org/css-properties-values-api/#dom-csspropertyrule-syntax> fn Syntax(&self) -> DOMString { self.property_rule .borrow() .descriptors .syntax .as_ref() .and_then(|s| s.specified_string()) .unwrap_or_else(|| { debug_assert!(false, "PropertyRule exists but missing a syntax string?"); "*" }) .into() } /// <https://drafts.css-houdini.org/css-properties-values-api/#dom-csspropertyrule-initialvalue> fn GetInitialValue(&self) -> Option<DOMString> { self.property_rule .borrow() .descriptors .initial_value .as_ref() .map(|value| value.to_css_string().into()) } /// <https://drafts.css-houdini.org/css-properties-values-api/#dom-csspropertyrule-inherits> fn Inherits(&self) -> bool { self.property_rule.borrow().descriptors.inherits() } }