Skip to content

Commit

Permalink
Clean up DOMManipulationTaskSource
Browse files Browse the repository at this point in the history
  • Loading branch information
KiChjang committed Jun 2, 2016
1 parent bdecfa1 commit 05fc799
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions components/script/dom/bindings/global.rs
Expand Up @@ -26,7 +26,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
use script_thread::{MainThreadScriptChan, ScriptThread};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest};
use task_source::TaskSource;
use task_source::dom_manipulation::DOMManipulationTask;
use task_source::dom_manipulation::{DOMManipulationTask, DOMManipulationTaskSource};
use timers::{OneshotTimerCallback, OneshotTimerHandle};
use url::Url;

Expand Down Expand Up @@ -193,7 +193,7 @@ impl<'a> GlobalRef<'a> {

/// `TaskSource` used to queue DOM manipulation messages to the event loop of this global's
/// thread.
pub fn dom_manipulation_task_source(&self) -> Box<TaskSource<DOMManipulationTask> + Send> {
pub fn dom_manipulation_task_source(&self) -> DOMManipulationTaskSource {
match *self {
GlobalRef::Window(ref window) => window.dom_manipulation_task_source(),
GlobalRef::Worker(_) => unimplemented!(),
Expand Down
6 changes: 2 additions & 4 deletions components/script/dom/document.rs
Expand Up @@ -1471,10 +1471,8 @@ impl Document {

update_with_current_time_ms(&self.dom_content_loaded_event_start);

let doctarget = Trusted::new(self.upcast::<EventTarget>());
let task_source = self.window().dom_manipulation_task_source();
let _ = task_source.queue(DOMManipulationTask::FireEvent(
atom!("DOMContentLoaded"), doctarget, EventBubbles::Bubbles, EventCancelable::NotCancelable));
self.window().dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"),
EventBubbles::Bubbles, EventCancelable::NotCancelable);
self.window().reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
ReflowReason::DOMContentLoaded);
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/htmldetailselement.rs
Expand Up @@ -18,6 +18,7 @@ use dom::virtualmethods::VirtualMethods;
use script_thread::Runnable;
use std::cell::Cell;
use string_cache::Atom;
use task_source::TaskSource;
use task_source::dom_manipulation::DOMManipulationTask;

#[dom_struct]
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -50,6 +50,7 @@ use std::borrow::ToOwned;
use std::cell::Cell;
use std::sync::mpsc::Sender;
use string_cache::Atom;
use task_source::TaskSource;
use task_source::dom_manipulation::DOMManipulationTask;
use url::form_urlencoded;
use util::str::split_html_space_chars;
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/htmlmediaelement.rs
Expand Up @@ -32,6 +32,7 @@ use script_thread::{Runnable, ScriptThread};
use std::cell::Cell;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use task_source::TaskSource;
use task_source::dom_manipulation::DOMManipulationTask;
use time::{self, Timespec, Duration};
use url::Url;
Expand Down
8 changes: 2 additions & 6 deletions components/script/dom/htmlscriptelement.rs
Expand Up @@ -462,16 +462,12 @@ impl HTMLScriptElement {
if external {
self.dispatch_load_event();
} else {
let script_element = Trusted::new(self.upcast::<EventTarget>());
let task_source = window.dom_manipulation_task_source();
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("load"), script_element)).unwrap();
window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"));
}
}

pub fn queue_error_event(&self) {
let task_source = window_from_node(self).dom_manipulation_task_source();
let script_element = Trusted::new(self.upcast::<EventTarget>());
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("error"), script_element)).unwrap();
window_from_node(self).dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error"));
}

pub fn dispatch_before_script_execute_event(&self) -> bool {
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/storage.rs
Expand Up @@ -18,6 +18,7 @@ use ipc_channel::ipc::{self, IpcSender};
use net_traits::IpcSend;
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
use script_thread::{MainThreadRunnable, ScriptThread};
use task_source::TaskSource;
use task_source::dom_manipulation::DOMManipulationTask;
use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/window.rs
Expand Up @@ -280,7 +280,7 @@ impl Window {
self.js_runtime.borrow().as_ref().unwrap().cx()
}

pub fn dom_manipulation_task_source(&self) -> Box<TaskSource<DOMManipulationTask> + Send> {
pub fn dom_manipulation_task_source(&self) -> DOMManipulationTaskSource {
self.dom_manipulation_task_source.clone()
}

Expand Down
28 changes: 22 additions & 6 deletions components/script/task_source/dom_manipulation.rs
Expand Up @@ -21,18 +21,34 @@ impl TaskSource<DOMManipulationTask> for DOMManipulationTaskSource {
}

impl DOMManipulationTaskSource {
pub fn clone(&self) -> Box<TaskSource<DOMManipulationTask> + Send> {
box DOMManipulationTaskSource((&self.0).clone())
pub fn queue_event(&self,
target: &EventTarget,
name: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable) {
let target = Trusted::new(target);
let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireEvent(
target, name, bubbles, cancelable)));
}

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)));
}

pub fn clone(&self) -> DOMManipulationTaskSource {
DOMManipulationTaskSource((&self.0).clone())
}
}

pub enum DOMManipulationTask {
// https://html.spec.whatwg.org/multipage/#the-end step 7
DocumentProgress(Box<Runnable + Send>),
// https://dom.spec.whatwg.org/#concept-event-fire
FireEvent(Atom, Trusted<EventTarget>, EventBubbles, EventCancelable),
FireEvent(Trusted<EventTarget>, Atom, EventBubbles, EventCancelable),
// https://html.spec.whatwg.org/multipage/#fire-a-simple-event
FireSimpleEvent(Atom, Trusted<EventTarget>),
FireSimpleEvent(Trusted<EventTarget>, Atom),
// https://html.spec.whatwg.org/multipage/#details-notification-task-steps
FireToggleEvent(Box<Runnable + Send>),
// Placeholder until there's a real media element task queue implementation
Expand All @@ -49,11 +65,11 @@ impl DOMManipulationTask {

match self {
DocumentProgress(runnable) => runnable.handler(),
FireEvent(name, element, bubbles, cancelable) => {
FireEvent(element, name, bubbles, cancelable) => {
let target = element.root();
target.fire_event(&*name, bubbles, cancelable);
}
FireSimpleEvent(name, element) => {
FireSimpleEvent(element, name) => {
let target = element.root();
target.fire_simple_event(&*name);
}
Expand Down

0 comments on commit 05fc799

Please sign in to comment.