diff options
Diffstat (limited to 'components/script/task_source/dom_manipulation.rs')
-rw-r--r-- | components/script/task_source/dom_manipulation.rs | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index a1c06f2c09e..4f5384ae2ed 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -2,10 +2,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::bindings::global::GlobalRef; use dom::bindings::refcounted::Trusted; -use dom::event::{EventBubbles, EventCancelable}; +use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable}; use dom::eventtarget::EventTarget; -use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread}; +use dom::window::Window; +use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper, ScriptThread}; use std::result::Result; use std::sync::mpsc::Sender; use string_cache::Atom; @@ -14,8 +16,13 @@ use task_source::TaskSource; #[derive(JSTraceable, Clone)] pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>); -impl TaskSource<DOMManipulationTask> for DOMManipulationTaskSource { - fn queue(&self, msg: DOMManipulationTask) -> Result<(), ()> { +impl TaskSource for DOMManipulationTaskSource { + fn queue_with_wrapper<T>(&self, + msg: Box<T>, + wrapper: &RunnableWrapper) + -> Result<(), ()> + where T: Runnable + Send + 'static { + let msg = DOMManipulationTask(wrapper.wrap_runnable(msg)); self.0.send(MainThreadScriptMsg::DOMManipulation(msg)).map_err(|_| ()) } } @@ -25,46 +32,34 @@ impl DOMManipulationTaskSource { target: &EventTarget, name: Atom, bubbles: EventBubbles, - cancelable: EventCancelable) { + cancelable: EventCancelable, + window: &Window) { let target = Trusted::new(target); - let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireEvent( - target, name, bubbles, cancelable))); + let runnable = box EventRunnable { + target: target, + name: name, + bubbles: bubbles, + cancelable: cancelable, + }; + let _ = self.queue(runnable, GlobalRef::Window(window)); } - pub fn queue_simple_event(&self, target: &EventTarget, name: Atom) { + pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) { let target = Trusted::new(target); - let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireSimpleEvent( - target, name))); + let runnable = box SimpleEventRunnable { + target: target, + name: name, + }; + let _ = self.queue(runnable, GlobalRef::Window(window)); } } -pub enum DOMManipulationTask { - // https://dom.spec.whatwg.org/#concept-event-fire - FireEvent(Trusted<EventTarget>, Atom, EventBubbles, EventCancelable), - // https://html.spec.whatwg.org/multipage/#fire-a-simple-event - FireSimpleEvent(Trusted<EventTarget>, Atom), - - Runnable(Box<Runnable + Send>), -} +pub struct DOMManipulationTask(pub Box<Runnable + Send>); impl DOMManipulationTask { pub fn handle_task(self, script_thread: &ScriptThread) { - use self::DOMManipulationTask::*; - - match self { - FireEvent(element, name, bubbles, cancelable) => { - let target = element.root(); - target.fire_event(&*name, bubbles, cancelable); - } - FireSimpleEvent(element, name) => { - let target = element.root(); - target.fire_simple_event(&*name); - } - Runnable(runnable) => { - if !runnable.is_cancelled() { - runnable.main_thread_handler(script_thread); - } - } + if !self.0.is_cancelled() { + self.0.main_thread_handler(script_thread); } } } |