mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
Add upgrade reaction
This commit is contained in:
parent
ec528e944a
commit
e83a0045f9
3 changed files with 28 additions and 3 deletions
|
@ -531,7 +531,10 @@ pub fn try_upgrade_element(element: &Element) {
|
||||||
#[derive(HeapSizeOf, JSTraceable)]
|
#[derive(HeapSizeOf, JSTraceable)]
|
||||||
#[must_root]
|
#[must_root]
|
||||||
pub enum CustomElementReaction {
|
pub enum CustomElementReaction {
|
||||||
// TODO: Support upgrade reactions
|
Upgrade(
|
||||||
|
#[ignore_heap_size_of = "Rc"]
|
||||||
|
Rc<CustomElementDefinition>
|
||||||
|
),
|
||||||
Callback(
|
Callback(
|
||||||
#[ignore_heap_size_of = "Rc"]
|
#[ignore_heap_size_of = "Rc"]
|
||||||
Rc<Function>,
|
Rc<Function>,
|
||||||
|
@ -545,6 +548,7 @@ impl CustomElementReaction {
|
||||||
pub fn invoke(&self, element: &Element) {
|
pub fn invoke(&self, element: &Element) {
|
||||||
// Step 2.1
|
// Step 2.1
|
||||||
match *self {
|
match *self {
|
||||||
|
CustomElementReaction::Upgrade(ref definition) => upgrade_element(definition.clone(), element),
|
||||||
CustomElementReaction::Callback(ref callback, ref arguments) => {
|
CustomElementReaction::Callback(ref callback, ref arguments) => {
|
||||||
let arguments = arguments.iter().map(|arg| arg.handle()).collect();
|
let arguments = arguments.iter().map(|arg| arg.handle()).collect();
|
||||||
let _ = callback.Call_(&*element, arguments, ExceptionHandling::Report);
|
let _ = callback.Call_(&*element, arguments, ExceptionHandling::Report);
|
||||||
|
@ -703,6 +707,14 @@ impl CustomElementReactionStack {
|
||||||
// Step 6
|
// Step 6
|
||||||
self.enqueue_element(element);
|
self.enqueue_element(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#enqueue-a-custom-element-upgrade-reaction
|
||||||
|
pub fn enqueue_upgrade_reaction(&self, element: &Element, definition: Rc<CustomElementDefinition>) {
|
||||||
|
// Step 1
|
||||||
|
element.push_upgrade_reaction(definition);
|
||||||
|
// Step 2
|
||||||
|
self.enqueue_element(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#element-queue
|
/// https://html.spec.whatwg.org/multipage/#element-queue
|
||||||
|
|
|
@ -300,6 +300,10 @@ impl Element {
|
||||||
self.custom_element_reaction_queue.borrow_mut().push(CustomElementReaction::Callback(function, args));
|
self.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.borrow_mut().push(CustomElementReaction::Upgrade(definition));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn invoke_reactions(&self) {
|
pub fn invoke_reactions(&self) {
|
||||||
let mut reaction_queue = self.custom_element_reaction_queue.borrow_mut();
|
let mut reaction_queue = self.custom_element_reaction_queue.borrow_mut();
|
||||||
for reaction in reaction_queue.iter() {
|
for reaction in reaction_queue.iter() {
|
||||||
|
|
|
@ -39,7 +39,7 @@ use dom::bindings::str::DOMString;
|
||||||
use dom::bindings::structuredclone::StructuredCloneData;
|
use dom::bindings::structuredclone::StructuredCloneData;
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
use dom::bindings::utils::WRAP_CALLBACKS;
|
use dom::bindings::utils::WRAP_CALLBACKS;
|
||||||
use dom::customelementregistry::{CallbackReaction, CustomElementReactionStack};
|
use dom::customelementregistry::{CallbackReaction, CustomElementDefinition, CustomElementReactionStack};
|
||||||
use dom::document::{Document, DocumentSource, FocusType, HasBrowsingContext, IsHTMLDocument, TouchEventResult};
|
use dom::document::{Document, DocumentSource, FocusType, HasBrowsingContext, IsHTMLDocument, TouchEventResult};
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
@ -774,7 +774,7 @@ impl ScriptThread {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enqueue_callback_reaction(element:&Element, reaction: CallbackReaction) {
|
pub fn enqueue_callback_reaction(element: &Element, reaction: CallbackReaction) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = root.get() {
|
if let Some(script_thread) = root.get() {
|
||||||
let script_thread = unsafe { &*script_thread };
|
let script_thread = unsafe { &*script_thread };
|
||||||
|
@ -783,6 +783,15 @@ impl ScriptThread {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enqueue_upgrade_reaction(element: &Element, definition: Rc<CustomElementDefinition>) {
|
||||||
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
|
if let Some(script_thread) = root.get() {
|
||||||
|
let script_thread = unsafe { &*script_thread };
|
||||||
|
script_thread.custom_element_reaction_stack.enqueue_upgrade_reaction(element, definition);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn invoke_backup_element_queue() {
|
pub fn invoke_backup_element_queue() {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = root.get() {
|
if let Some(script_thread) = root.get() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue