Add task_source directory

Use DOMManipulationTaskSource whenever possible
This commit is contained in:
Keith Yeung 2016-01-06 11:44:54 -05:00
parent fa93d3f467
commit 3f2cbf0025
17 changed files with 261 additions and 185 deletions

View file

@ -19,6 +19,7 @@ use dom::bindings::trace::JSTraceable;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, ElementCreator};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
use dom::node::{document_from_node, window_from_node};
@ -34,13 +35,13 @@ use js::jsapi::RootedValue;
use js::jsval::UndefinedValue;
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata};
use network_listener::{NetworkListener, PreInvoke};
use script_thread::ScriptThreadEventCategory::ScriptEvent;
use script_thread::{CommonScriptMsg, Runnable, ScriptChan};
use script_thread::{MainThreadScriptChan, ScriptChan};
use std::ascii::AsciiExt;
use std::cell::Cell;
use std::mem;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use task_source::dom_manipulation::DOMManipulationTask;
use url::Url;
use util::str::{DOMString, HTML_SPACE_CHARACTERS, StaticStringVec};
@ -442,26 +443,20 @@ impl HTMLScriptElement {
if external {
self.dispatch_load_event();
} else {
let chan = window.dom_manipulation_task_source();
let handler = Trusted::new(self, chan.clone());
let dispatcher = box EventDispatcher {
element: handler,
is_error: false,
};
chan.send(CommonScriptMsg::RunnableMsg(ScriptEvent, dispatcher)).unwrap();
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
let script_element = Trusted::new(self.upcast::<EventTarget>(), chan);
let task_source = window.dom_manipulation_task_source();
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("load"), script_element)).unwrap();
}
}
pub fn queue_error_event(&self) {
let window = window_from_node(self);
let window = window.r();
let chan = window.dom_manipulation_task_source();
let handler = Trusted::new(self, chan.clone());
let dispatcher = box EventDispatcher {
element: handler,
is_error: true,
};
chan.send(CommonScriptMsg::RunnableMsg(ScriptEvent, dispatcher)).unwrap();
let chan = MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
let task_source = window.dom_manipulation_task_source();
let script_element = Trusted::new(self.upcast::<EventTarget>(), chan);
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("error"), script_element)).unwrap();
}
pub fn dispatch_before_script_execute_event(&self) -> bool {
@ -610,19 +605,3 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
self.upcast::<Node>().SetTextContent(Some(value))
}
}
struct EventDispatcher {
element: Trusted<HTMLScriptElement>,
is_error: bool,
}
impl Runnable for EventDispatcher {
fn handler(self: Box<EventDispatcher>) {
let target = self.element.root();
if self.is_error {
target.dispatch_error_event();
} else {
target.dispatch_load_event();
}
}
}