mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add custom elements related stuff into ElementRareData
This commit is contained in:
parent
a9019da39d
commit
c75da615bd
5 changed files with 54 additions and 34 deletions
|
@ -72,8 +72,8 @@ use crate::dom::bindings::conversions::DerivedFrom;
|
|||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::create::create_native_html_element;
|
||||
use crate::dom::customelementregistry::ConstructionStackEntry;
|
||||
use crate::dom::element::{CustomElementState, Element, ElementCreator};
|
||||
use crate::dom::customelementregistry::{ConstructionStackEntry, CustomElementState};
|
||||
use crate::dom::element::{Element, ElementCreator};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::window::Window;
|
||||
use crate::script_thread::ScriptThread;
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
use crate::dom::bindings::error::{report_pending_exception, throw_dom_exception};
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::customelementregistry::{is_valid_custom_element_name, upgrade_element};
|
||||
use crate::dom::customelementregistry::{
|
||||
is_valid_custom_element_name, upgrade_element, CustomElementState,
|
||||
};
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::element::{CustomElementCreationMode, CustomElementState, Element, ElementCreator};
|
||||
use crate::dom::element::{CustomElementCreationMode, Element, ElementCreator};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::htmlanchorelement::HTMLAnchorElement;
|
||||
use crate::dom::htmlareaelement::HTMLAreaElement;
|
||||
|
|
|
@ -23,7 +23,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
|
|||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::domexception::{DOMErrorName, DOMException};
|
||||
use crate::dom::element::{CustomElementState, Element};
|
||||
use crate::dom::element::Element;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{document_from_node, window_from_node, Node, ShadowIncluding};
|
||||
|
@ -47,6 +47,21 @@ use std::ops::Deref;
|
|||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
|
||||
#[derive(Clone, Copy, Eq, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
pub enum CustomElementState {
|
||||
Undefined,
|
||||
Failed,
|
||||
Uncustomized,
|
||||
Custom,
|
||||
}
|
||||
|
||||
impl Default for CustomElementState {
|
||||
fn default() -> CustomElementState {
|
||||
CustomElementState::Uncustomized
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#customelementregistry>
|
||||
#[dom_struct]
|
||||
pub struct CustomElementRegistry {
|
||||
|
|
|
@ -33,7 +33,7 @@ use crate::dom::bindings::xmlname::{
|
|||
use crate::dom::characterdata::CharacterData;
|
||||
use crate::dom::create::create_element;
|
||||
use crate::dom::customelementregistry::{
|
||||
CallbackReaction, CustomElementDefinition, CustomElementReaction,
|
||||
CallbackReaction, CustomElementDefinition, CustomElementReaction, CustomElementState,
|
||||
};
|
||||
use crate::dom::document::{Document, LayoutDocumentHelpers};
|
||||
use crate::dom::documentfragment::DocumentFragment;
|
||||
|
@ -166,13 +166,6 @@ pub struct Element {
|
|||
/// when it has exclusive access to the element.
|
||||
#[ignore_malloc_size_of = "bitflags defined in rust-selectors"]
|
||||
selector_flags: Cell<ElementSelectorFlags>,
|
||||
/// <https://html.spec.whatwg.org/multipage/#custom-element-reaction-queue>
|
||||
custom_element_reaction_queue: DomRefCell<Vec<CustomElementReaction>>,
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-definition>
|
||||
#[ignore_malloc_size_of = "Rc"]
|
||||
custom_element_definition: DomRefCell<Option<Rc<CustomElementDefinition>>>,
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
|
||||
custom_element_state: Cell<CustomElementState>,
|
||||
rare_data: Box<ElementRareData>,
|
||||
}
|
||||
|
||||
|
@ -203,15 +196,6 @@ pub enum CustomElementCreationMode {
|
|||
Asynchronous,
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
|
||||
#[derive(Clone, Copy, Eq, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
pub enum CustomElementState {
|
||||
Undefined,
|
||||
Failed,
|
||||
Uncustomized,
|
||||
Custom,
|
||||
}
|
||||
|
||||
impl ElementCreator {
|
||||
pub fn is_parser_created(&self) -> bool {
|
||||
match *self {
|
||||
|
@ -305,9 +289,6 @@ impl Element {
|
|||
class_list: Default::default(),
|
||||
state: Cell::new(state),
|
||||
selector_flags: Cell::new(ElementSelectorFlags::empty()),
|
||||
custom_element_reaction_queue: Default::default(),
|
||||
custom_element_definition: Default::default(),
|
||||
custom_element_state: Cell::new(CustomElementState::Uncustomized),
|
||||
rare_data: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -349,45 +330,55 @@ impl Element {
|
|||
}
|
||||
|
||||
pub fn set_custom_element_state(&self, state: CustomElementState) {
|
||||
self.custom_element_state.set(state);
|
||||
self.rare_data.custom_element_state.set(state);
|
||||
}
|
||||
|
||||
pub fn get_custom_element_state(&self) -> CustomElementState {
|
||||
self.custom_element_state.get()
|
||||
self.rare_data.custom_element_state.get()
|
||||
}
|
||||
|
||||
pub fn set_custom_element_definition(&self, definition: Rc<CustomElementDefinition>) {
|
||||
*self.custom_element_definition.borrow_mut() = Some(definition);
|
||||
*self.rare_data.custom_element_definition.borrow_mut() = Some(definition);
|
||||
}
|
||||
|
||||
pub fn get_custom_element_definition(&self) -> Option<Rc<CustomElementDefinition>> {
|
||||
(*self.custom_element_definition.borrow()).clone()
|
||||
(*self.rare_data.custom_element_definition.borrow()).clone()
|
||||
}
|
||||
|
||||
pub fn push_callback_reaction(&self, function: Rc<Function>, args: Box<[Heap<JSVal>]>) {
|
||||
self.custom_element_reaction_queue
|
||||
self.rare_data
|
||||
.custom_element_reaction_queue
|
||||
.borrow_mut()
|
||||
.push(CustomElementReaction::Callback(function, args));
|
||||
}
|
||||
|
||||
pub fn push_upgrade_reaction(&self, definition: Rc<CustomElementDefinition>) {
|
||||
self.custom_element_reaction_queue
|
||||
self.rare_data
|
||||
.custom_element_reaction_queue
|
||||
.borrow_mut()
|
||||
.push(CustomElementReaction::Upgrade(definition));
|
||||
}
|
||||
|
||||
pub fn clear_reaction_queue(&self) {
|
||||
self.custom_element_reaction_queue.borrow_mut().clear();
|
||||
self.rare_data
|
||||
.custom_element_reaction_queue
|
||||
.borrow_mut()
|
||||
.clear();
|
||||
}
|
||||
|
||||
pub fn invoke_reactions(&self) {
|
||||
// TODO: This is not spec compliant, as this will allow some reactions to be processed
|
||||
// after clear_reaction_queue has been called.
|
||||
rooted_vec!(let mut reactions);
|
||||
while !self.custom_element_reaction_queue.borrow().is_empty() {
|
||||
while !self
|
||||
.rare_data
|
||||
.custom_element_reaction_queue
|
||||
.borrow()
|
||||
.is_empty()
|
||||
{
|
||||
mem::swap(
|
||||
&mut *reactions,
|
||||
&mut *self.custom_element_reaction_queue.borrow_mut(),
|
||||
&mut *self.rare_data.custom_element_reaction_queue.borrow_mut(),
|
||||
);
|
||||
for reaction in reactions.iter() {
|
||||
reaction.invoke(self);
|
||||
|
|
|
@ -4,8 +4,13 @@
|
|||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::root::MutNullableDom;
|
||||
use crate::dom::customelementregistry::{
|
||||
CustomElementDefinition, CustomElementReaction, CustomElementState,
|
||||
};
|
||||
use crate::dom::mutationobserver::RegisteredObserver;
|
||||
use crate::dom::shadowroot::ShadowRoot;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Default, JSTraceable, MallocSizeOf)]
|
||||
#[must_root]
|
||||
|
@ -25,4 +30,11 @@ pub struct ElementRareData {
|
|||
/// XXX This is currently not exposed to web content. Only for
|
||||
/// internal use.
|
||||
pub shadow_root: MutNullableDom<ShadowRoot>,
|
||||
/// <https://html.spec.whatwg.org/multipage/#custom-element-reaction-queue>
|
||||
pub custom_element_reaction_queue: DomRefCell<Vec<CustomElementReaction>>,
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-definition>
|
||||
#[ignore_malloc_size_of = "Rc"]
|
||||
pub custom_element_definition: DomRefCell<Option<Rc<CustomElementDefinition>>>,
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
|
||||
pub custom_element_state: Cell<CustomElementState>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue