mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01: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_thread::{MainThreadScriptChan, ScriptThread};
|
||||||
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest};
|
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest};
|
||||||
use task_source::TaskSource;
|
use task_source::TaskSource;
|
||||||
use task_source::dom_manipulation::DOMManipulationTask;
|
use task_source::dom_manipulation::{DOMManipulationTask, DOMManipulationTaskSource};
|
||||||
use timers::{OneshotTimerCallback, OneshotTimerHandle};
|
use timers::{OneshotTimerCallback, OneshotTimerHandle};
|
||||||
use url::Url;
|
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
|
/// `TaskSource` used to queue DOM manipulation messages to the event loop of this global's
|
||||||
/// thread.
|
/// thread.
|
||||||
pub fn dom_manipulation_task_source(&self) -> Box<TaskSource<DOMManipulationTask> + Send> {
|
pub fn dom_manipulation_task_source(&self) -> DOMManipulationTaskSource {
|
||||||
match *self {
|
match *self {
|
||||||
GlobalRef::Window(ref window) => window.dom_manipulation_task_source(),
|
GlobalRef::Window(ref window) => window.dom_manipulation_task_source(),
|
||||||
GlobalRef::Worker(_) => unimplemented!(),
|
GlobalRef::Worker(_) => unimplemented!(),
|
||||||
|
|
|
@ -1471,10 +1471,8 @@ impl Document {
|
||||||
|
|
||||||
update_with_current_time_ms(&self.dom_content_loaded_event_start);
|
update_with_current_time_ms(&self.dom_content_loaded_event_start);
|
||||||
|
|
||||||
let doctarget = Trusted::new(self.upcast::<EventTarget>());
|
self.window().dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"),
|
||||||
let task_source = self.window().dom_manipulation_task_source();
|
EventBubbles::Bubbles, EventCancelable::NotCancelable);
|
||||||
let _ = task_source.queue(DOMManipulationTask::FireEvent(
|
|
||||||
atom!("DOMContentLoaded"), doctarget, EventBubbles::Bubbles, EventCancelable::NotCancelable));
|
|
||||||
self.window().reflow(ReflowGoal::ForDisplay,
|
self.window().reflow(ReflowGoal::ForDisplay,
|
||||||
ReflowQueryType::NoQuery,
|
ReflowQueryType::NoQuery,
|
||||||
ReflowReason::DOMContentLoaded);
|
ReflowReason::DOMContentLoaded);
|
||||||
|
|
|
@ -18,6 +18,7 @@ use dom::virtualmethods::VirtualMethods;
|
||||||
use script_thread::Runnable;
|
use script_thread::Runnable;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
use task_source::TaskSource;
|
||||||
use task_source::dom_manipulation::DOMManipulationTask;
|
use task_source::dom_manipulation::DOMManipulationTask;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
|
|
@ -50,6 +50,7 @@ use std::borrow::ToOwned;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
use task_source::TaskSource;
|
||||||
use task_source::dom_manipulation::DOMManipulationTask;
|
use task_source::dom_manipulation::DOMManipulationTask;
|
||||||
use url::form_urlencoded;
|
use url::form_urlencoded;
|
||||||
use util::str::split_html_space_chars;
|
use util::str::split_html_space_chars;
|
||||||
|
|
|
@ -32,6 +32,7 @@ use script_thread::{Runnable, ScriptThread};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
use task_source::TaskSource;
|
||||||
use task_source::dom_manipulation::DOMManipulationTask;
|
use task_source::dom_manipulation::DOMManipulationTask;
|
||||||
use time::{self, Timespec, Duration};
|
use time::{self, Timespec, Duration};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
|
@ -462,16 +462,12 @@ impl HTMLScriptElement {
|
||||||
if external {
|
if external {
|
||||||
self.dispatch_load_event();
|
self.dispatch_load_event();
|
||||||
} else {
|
} else {
|
||||||
let script_element = Trusted::new(self.upcast::<EventTarget>());
|
window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"));
|
||||||
let task_source = window.dom_manipulation_task_source();
|
|
||||||
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("load"), script_element)).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_error_event(&self) {
|
pub fn queue_error_event(&self) {
|
||||||
let task_source = window_from_node(self).dom_manipulation_task_source();
|
window_from_node(self).dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error"));
|
||||||
let script_element = Trusted::new(self.upcast::<EventTarget>());
|
|
||||||
task_source.queue(DOMManipulationTask::FireSimpleEvent(atom!("error"), script_element)).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch_before_script_execute_event(&self) -> bool {
|
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::IpcSend;
|
||||||
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
|
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
|
||||||
use script_thread::{MainThreadRunnable, ScriptThread};
|
use script_thread::{MainThreadRunnable, ScriptThread};
|
||||||
|
use task_source::TaskSource;
|
||||||
use task_source::dom_manipulation::DOMManipulationTask;
|
use task_source::dom_manipulation::DOMManipulationTask;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,7 @@ impl Window {
|
||||||
self.js_runtime.borrow().as_ref().unwrap().cx()
|
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()
|
self.dom_manipulation_task_source.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,24 @@ impl TaskSource<DOMManipulationTask> for DOMManipulationTaskSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DOMManipulationTaskSource {
|
impl DOMManipulationTaskSource {
|
||||||
pub fn clone(&self) -> Box<TaskSource<DOMManipulationTask> + Send> {
|
pub fn queue_event(&self,
|
||||||
box DOMManipulationTaskSource((&self.0).clone())
|
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
|
// https://html.spec.whatwg.org/multipage/#the-end step 7
|
||||||
DocumentProgress(Box<Runnable + Send>),
|
DocumentProgress(Box<Runnable + Send>),
|
||||||
// https://dom.spec.whatwg.org/#concept-event-fire
|
// 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
|
// 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
|
// https://html.spec.whatwg.org/multipage/#details-notification-task-steps
|
||||||
FireToggleEvent(Box<Runnable + Send>),
|
FireToggleEvent(Box<Runnable + Send>),
|
||||||
// Placeholder until there's a real media element task queue implementation
|
// Placeholder until there's a real media element task queue implementation
|
||||||
|
@ -49,11 +65,11 @@ impl DOMManipulationTask {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
DocumentProgress(runnable) => runnable.handler(),
|
DocumentProgress(runnable) => runnable.handler(),
|
||||||
FireEvent(name, element, bubbles, cancelable) => {
|
FireEvent(element, name, bubbles, cancelable) => {
|
||||||
let target = element.root();
|
let target = element.root();
|
||||||
target.fire_event(&*name, bubbles, cancelable);
|
target.fire_event(&*name, bubbles, cancelable);
|
||||||
}
|
}
|
||||||
FireSimpleEvent(name, element) => {
|
FireSimpleEvent(element, name) => {
|
||||||
let target = element.root();
|
let target = element.root();
|
||||||
target.fire_simple_event(&*name);
|
target.fire_simple_event(&*name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue