Add CSSOM support for CSS layers (#31481)

Instead of just crashing.
This commit is contained in:
Oriol Brufau 2024-03-03 13:47:39 +01:00 committed by GitHub
parent 845f503c34
commit 06aeeeb1f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 298 additions and 77 deletions

View file

@ -5,8 +5,11 @@
use dom_struct::dom_struct;
use servo_arc::Arc;
use style::shared_lock::{Locked, ToCssWithGuard};
use style::stylesheets::import_rule::ImportLayer;
use style::stylesheets::ImportRule;
use style_traits::ToCss;
use crate::dom::bindings::codegen::Bindings::CSSImportRuleBinding::CSSImportRuleMethods;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
@ -60,3 +63,15 @@ impl SpecificCSSRule for CSSImportRule {
.into()
}
}
impl CSSImportRuleMethods for CSSImportRule {
/// <https://drafts.csswg.org/cssom-1/#dom-cssimportrule-layername>
fn GetLayerName(&self) -> Option<DOMString> {
let guard = self.cssrule.shared_lock().read();
match &self.import_rule.read_with(&guard).layer {
ImportLayer::None => None,
ImportLayer::Anonymous => Some(DOMString::new()),
ImportLayer::Named(name) => Some(DOMString::from_string(name.to_css_string())),
}
}
}