mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Introduce NodeRareData and ElementRareData
This commit is contained in:
parent
813b242419
commit
6af4729f42
4 changed files with 46 additions and 17 deletions
|
@ -76,6 +76,7 @@ use crate::dom::node::{BindContext, NodeDamage, NodeFlags, UnbindContext};
|
||||||
use crate::dom::node::{ChildrenMutation, LayoutNodeHelpers, Node};
|
use crate::dom::node::{ChildrenMutation, LayoutNodeHelpers, Node};
|
||||||
use crate::dom::nodelist::NodeList;
|
use crate::dom::nodelist::NodeList;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
|
use crate::dom::raredata::ElementRareData;
|
||||||
use crate::dom::servoparser::ServoParser;
|
use crate::dom::servoparser::ServoParser;
|
||||||
use crate::dom::shadowroot::ShadowRoot;
|
use crate::dom::shadowroot::ShadowRoot;
|
||||||
use crate::dom::text::Text;
|
use crate::dom::text::Text;
|
||||||
|
@ -172,10 +173,7 @@ pub struct Element {
|
||||||
custom_element_definition: DomRefCell<Option<Rc<CustomElementDefinition>>>,
|
custom_element_definition: DomRefCell<Option<Rc<CustomElementDefinition>>>,
|
||||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
|
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
|
||||||
custom_element_state: Cell<CustomElementState>,
|
custom_element_state: Cell<CustomElementState>,
|
||||||
/// https://dom.spec.whatwg.org/#dom-element-shadowroot
|
rare_data: Box<ElementRareData>,
|
||||||
/// XXX This is currently not exposed to web content. Only for
|
|
||||||
/// internal use.
|
|
||||||
shadow_root: MutNullableDom<ShadowRoot>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Element {
|
impl fmt::Debug for Element {
|
||||||
|
@ -310,7 +308,7 @@ impl Element {
|
||||||
custom_element_reaction_queue: Default::default(),
|
custom_element_reaction_queue: Default::default(),
|
||||||
custom_element_definition: Default::default(),
|
custom_element_definition: Default::default(),
|
||||||
custom_element_state: Cell::new(CustomElementState::Uncustomized),
|
custom_element_state: Cell::new(CustomElementState::Uncustomized),
|
||||||
shadow_root: Default::default(),
|
rare_data: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +450,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_shadow_host(&self) -> bool {
|
pub fn is_shadow_host(&self) -> bool {
|
||||||
self.shadow_root.get().is_some()
|
self.rare_data.shadow_root.get().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://dom.spec.whatwg.org/#dom-element-attachshadow
|
/// https://dom.spec.whatwg.org/#dom-element-attachshadow
|
||||||
|
@ -496,6 +494,7 @@ impl Element {
|
||||||
|
|
||||||
// Steps 4, 5 and 6.
|
// Steps 4, 5 and 6.
|
||||||
let shadow_root = self
|
let shadow_root = self
|
||||||
|
.rare_data
|
||||||
.shadow_root
|
.shadow_root
|
||||||
.or_init(|| ShadowRoot::new(self, &*self.node.owner_doc()));
|
.or_init(|| ShadowRoot::new(self, &*self.node.owner_doc()));
|
||||||
|
|
||||||
|
@ -1070,7 +1069,10 @@ impl LayoutElementHelpers for LayoutDom<Element> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_shadow_root_for_layout(&self) -> Option<LayoutDom<ShadowRoot>> {
|
unsafe fn get_shadow_root_for_layout(&self) -> Option<LayoutDom<ShadowRoot>> {
|
||||||
(*self.unsafe_get()).shadow_root.get_inner_as_layout()
|
(*self.unsafe_get())
|
||||||
|
.rare_data
|
||||||
|
.shadow_root
|
||||||
|
.get_inner_as_layout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2847,7 +2849,7 @@ impl VirtualMethods for Element {
|
||||||
|
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
|
|
||||||
if let Some(shadow_root) = self.shadow_root.get() {
|
if let Some(shadow_root) = self.rare_data.shadow_root.get() {
|
||||||
doc.unregister_shadow_root(&shadow_root);
|
doc.unregister_shadow_root(&shadow_root);
|
||||||
let shadow_root = shadow_root.upcast::<Node>();
|
let shadow_root = shadow_root.upcast::<Node>();
|
||||||
shadow_root.set_flag(NodeFlags::IS_CONNECTED, false);
|
shadow_root.set_flag(NodeFlags::IS_CONNECTED, false);
|
||||||
|
|
|
@ -443,6 +443,7 @@ pub mod promisenativehandler;
|
||||||
pub mod promiserejectionevent;
|
pub mod promiserejectionevent;
|
||||||
pub mod radionodelist;
|
pub mod radionodelist;
|
||||||
pub mod range;
|
pub mod range;
|
||||||
|
pub mod raredata;
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
pub mod rtcicecandidate;
|
pub mod rtcicecandidate;
|
||||||
|
|
|
@ -53,6 +53,7 @@ use crate::dom::mutationobserver::{Mutation, MutationObserver, RegisteredObserve
|
||||||
use crate::dom::nodelist::NodeList;
|
use crate::dom::nodelist::NodeList;
|
||||||
use crate::dom::processinginstruction::ProcessingInstruction;
|
use crate::dom::processinginstruction::ProcessingInstruction;
|
||||||
use crate::dom::range::WeakRangeVec;
|
use crate::dom::range::WeakRangeVec;
|
||||||
|
use crate::dom::raredata::NodeRareData;
|
||||||
use crate::dom::shadowroot::{LayoutShadowRootHelpers, ShadowRoot};
|
use crate::dom::shadowroot::{LayoutShadowRootHelpers, ShadowRoot};
|
||||||
use crate::dom::stylesheetlist::StyleSheetListOwner;
|
use crate::dom::stylesheetlist::StyleSheetListOwner;
|
||||||
use crate::dom::svgsvgelement::{LayoutSVGSVGElementHelpers, SVGSVGElement};
|
use crate::dom::svgsvgelement::{LayoutSVGSVGElementHelpers, SVGSVGElement};
|
||||||
|
@ -124,10 +125,8 @@ pub struct Node {
|
||||||
/// The document that this node belongs to.
|
/// The document that this node belongs to.
|
||||||
owner_doc: MutNullableDom<Document>,
|
owner_doc: MutNullableDom<Document>,
|
||||||
|
|
||||||
/// The shadow root this node belongs to.
|
/// Rare node data.
|
||||||
/// This is None if the node is not in a shadow tree or
|
rare_data: Box<NodeRareData>,
|
||||||
/// if it is a ShadowRoot.
|
|
||||||
owner_shadow_root: MutNullableDom<ShadowRoot>,
|
|
||||||
|
|
||||||
/// The live list of children return by .childNodes.
|
/// The live list of children return by .childNodes.
|
||||||
child_list: MutNullableDom<NodeList>,
|
child_list: MutNullableDom<NodeList>,
|
||||||
|
@ -937,11 +936,11 @@ impl Node {
|
||||||
if let Some(ref shadow_root) = self.downcast::<ShadowRoot>() {
|
if let Some(ref shadow_root) = self.downcast::<ShadowRoot>() {
|
||||||
return Some(DomRoot::from_ref(shadow_root));
|
return Some(DomRoot::from_ref(shadow_root));
|
||||||
}
|
}
|
||||||
self.owner_shadow_root.get()
|
self.rare_data.owner_shadow_root.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_owner_shadow_root(&self, shadow_root: &ShadowRoot) {
|
pub fn set_owner_shadow_root(&self, shadow_root: &ShadowRoot) {
|
||||||
self.owner_shadow_root.set(Some(shadow_root));
|
self.rare_data.owner_shadow_root.set(Some(shadow_root));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_in_html_doc(&self) -> bool {
|
pub fn is_in_html_doc(&self) -> bool {
|
||||||
|
@ -1272,7 +1271,10 @@ impl LayoutNodeHelpers for LayoutDom<Node> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn owner_shadow_root_for_layout(&self) -> Option<LayoutDom<ShadowRoot>> {
|
unsafe fn owner_shadow_root_for_layout(&self) -> Option<LayoutDom<ShadowRoot>> {
|
||||||
(*self.unsafe_get()).owner_shadow_root.get_inner_as_layout()
|
(*self.unsafe_get())
|
||||||
|
.rare_data
|
||||||
|
.owner_shadow_root
|
||||||
|
.get_inner_as_layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1641,7 +1643,7 @@ impl Node {
|
||||||
next_sibling: Default::default(),
|
next_sibling: Default::default(),
|
||||||
prev_sibling: Default::default(),
|
prev_sibling: Default::default(),
|
||||||
owner_doc: MutNullableDom::new(doc),
|
owner_doc: MutNullableDom::new(doc),
|
||||||
owner_shadow_root: Default::default(),
|
rare_data: Default::default(),
|
||||||
child_list: Default::default(),
|
child_list: Default::default(),
|
||||||
children_count: Cell::new(0u32),
|
children_count: Cell::new(0u32),
|
||||||
flags: Cell::new(flags),
|
flags: Cell::new(flags),
|
||||||
|
@ -2280,7 +2282,7 @@ impl NodeMethods for Node {
|
||||||
// https://dom.spec.whatwg.org/#dom-node-getrootnode
|
// https://dom.spec.whatwg.org/#dom-node-getrootnode
|
||||||
fn GetRootNode(&self, options: &GetRootNodeOptions) -> DomRoot<Node> {
|
fn GetRootNode(&self, options: &GetRootNodeOptions) -> DomRoot<Node> {
|
||||||
if options.composed {
|
if options.composed {
|
||||||
if let Some(shadow_root) = self.owner_shadow_root.get() {
|
if let Some(shadow_root) = self.rare_data.owner_shadow_root.get() {
|
||||||
// shadow-including root.
|
// shadow-including root.
|
||||||
return shadow_root.Host().upcast::<Node>().GetRootNode(options);
|
return shadow_root.Host().upcast::<Node>().GetRootNode(options);
|
||||||
}
|
}
|
||||||
|
|
24
components/script/dom/raredata.rs
Normal file
24
components/script/dom/raredata.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/* 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::MutNullableDom;
|
||||||
|
use crate::dom::shadowroot::ShadowRoot;
|
||||||
|
|
||||||
|
#[derive(Default, JSTraceable, MallocSizeOf)]
|
||||||
|
#[must_root]
|
||||||
|
pub struct NodeRareData {
|
||||||
|
/// The shadow root the node belongs to.
|
||||||
|
/// This is None if the node is not in a shadow tree or
|
||||||
|
/// if it is a ShadowRoot.
|
||||||
|
pub owner_shadow_root: MutNullableDom<ShadowRoot>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, JSTraceable, MallocSizeOf)]
|
||||||
|
#[must_root]
|
||||||
|
pub struct ElementRareData {
|
||||||
|
/// https://dom.spec.whatwg.org/#dom-element-shadowroot
|
||||||
|
/// XXX This is currently not exposed to web content. Only for
|
||||||
|
/// internal use.
|
||||||
|
pub shadow_root: MutNullableDom<ShadowRoot>,
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue