mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01: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)]
|
||||
#[must_root]
|
||||
pub enum CustomElementReaction {
|
||||
// TODO: Support upgrade reactions
|
||||
Upgrade(
|
||||
#[ignore_heap_size_of = "Rc"]
|
||||
Rc<CustomElementDefinition>
|
||||
),
|
||||
Callback(
|
||||
#[ignore_heap_size_of = "Rc"]
|
||||
Rc<Function>,
|
||||
|
@ -545,6 +548,7 @@ impl CustomElementReaction {
|
|||
pub fn invoke(&self, element: &Element) {
|
||||
// Step 2.1
|
||||
match *self {
|
||||
CustomElementReaction::Upgrade(ref definition) => upgrade_element(definition.clone(), element),
|
||||
CustomElementReaction::Callback(ref callback, ref arguments) => {
|
||||
let arguments = arguments.iter().map(|arg| arg.handle()).collect();
|
||||
let _ = callback.Call_(&*element, arguments, ExceptionHandling::Report);
|
||||
|
@ -703,6 +707,14 @@ impl CustomElementReactionStack {
|
|||
// Step 6
|
||||
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
|
||||
|
|
|
@ -300,6 +300,10 @@ impl Element {
|
|||
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) {
|
||||
let mut reaction_queue = self.custom_element_reaction_queue.borrow_mut();
|
||||
for reaction in reaction_queue.iter() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue