Add event runnables

Make tasks a wrapper over runnables
This commit is contained in:
Connor Brewster 2016-07-11 22:21:45 -06:00
parent 9b01a4cc97
commit afc0ccb48d
9 changed files with 79 additions and 61 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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 std::result::Result;
@ -27,44 +27,31 @@ impl DOMManipulationTaskSource {
bubbles: EventBubbles,
cancelable: EventCancelable) {
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(DOMManipulationTask(runnable));
}
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom) {
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(DOMManipulationTask(runnable));
}
}
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);
}
}
}