mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Clean up DOMManipulationTaskSource
This commit is contained in:
parent
bdecfa13d2
commit
05fc799f92
9 changed files with 33 additions and 19 deletions
|
@ -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;
|
||||
|
||||
|
@ -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!(),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,24 @@ 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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,9 +46,9 @@ 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
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue