diff options
author | Connor Brewster <connor.brewster@eagles.oc.edu> | 2017-07-19 13:10:54 -0600 |
---|---|---|
committer | Connor Brewster <connor.brewster@eagles.oc.edu> | 2017-08-09 11:06:44 -0600 |
commit | e83a0045f9016b7d03631389107c1748a27fdb0c (patch) | |
tree | 5fd243b5602be68056c04bc1d0260aa40e03ef45 /components | |
parent | ec528e944a922ec4786b935be5a25e365174d1a1 (diff) | |
download | servo-e83a0045f9016b7d03631389107c1748a27fdb0c.tar.gz servo-e83a0045f9016b7d03631389107c1748a27fdb0c.zip |
Add upgrade reaction
Diffstat (limited to 'components')
-rw-r--r-- | components/script/dom/customelementregistry.rs | 14 | ||||
-rw-r--r-- | components/script/dom/element.rs | 4 | ||||
-rw-r--r-- | components/script/script_thread.rs | 13 |
3 files changed, 28 insertions, 3 deletions
diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index b2798267a86..fdf197d7d97 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -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 diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 328dd76e822..b44757d3aa1 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -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() { diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index e87938bfa1e..49c09787ecc 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -39,7 +39,7 @@ use dom::bindings::str::DOMString; use dom::bindings::structuredclone::StructuredCloneData; use dom::bindings::trace::JSTraceable; 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::element::Element; 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| { if let Some(script_thread) = root.get() { 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() { SCRIPT_THREAD_ROOT.with(|root| { if let Some(script_thread) = root.get() { |