mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Partial ShadowRoot implementation of DocumentOrShadowRoot
This commit is contained in:
parent
18ae0fcbd6
commit
4304ee28dc
9 changed files with 161 additions and 54 deletions
40
components/script/dom/documentorshadowroot.rs
Normal file
40
components/script/dom/documentorshadowroot.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* 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 crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::shadowroot::ShadowRoot;
|
||||
|
||||
macro_rules! proxy_call(
|
||||
($fn_name:ident, $return_type:ty) => (
|
||||
pub fn $fn_name(&self) -> $return_type {
|
||||
match self {
|
||||
DocumentOrShadowRoot::Document(doc) => doc.$fn_name(),
|
||||
DocumentOrShadowRoot::ShadowRoot(root) => root.$fn_name(),
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
($fn_name:ident, $arg1:ident, $arg1_type:ty, $return_type:ty) => (
|
||||
pub fn $fn_name(&self, $arg1: $arg1_type) -> $return_type {
|
||||
match self {
|
||||
DocumentOrShadowRoot::Document(doc) => doc.$fn_name($arg1),
|
||||
DocumentOrShadowRoot::ShadowRoot(root) => root.$fn_name($arg1),
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
#[must_root]
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
pub enum DocumentOrShadowRoot {
|
||||
Document(Dom<Document>),
|
||||
ShadowRoot(Dom<ShadowRoot>),
|
||||
}
|
||||
|
||||
impl DocumentOrShadowRoot {
|
||||
proxy_call!(stylesheet_count, usize);
|
||||
proxy_call!(stylesheet_at, index, usize, Option<DomRoot<CSSStyleSheet>>);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue