mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Add event runnables
Make tasks a wrapper over runnables
This commit is contained in:
parent
9b01a4cc97
commit
afc0ccb48d
9 changed files with 79 additions and 61 deletions
|
@ -8,9 +8,11 @@ use dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethod
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
use script_thread::Runnable;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
@ -26,7 +28,7 @@ pub enum EventPhase {
|
||||||
Bubbling = EventConstants::BUBBLING_PHASE,
|
Bubbling = EventConstants::BUBBLING_PHASE,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, HeapSizeOf)]
|
#[derive(PartialEq, HeapSizeOf, Copy, Clone)]
|
||||||
pub enum EventBubbles {
|
pub enum EventBubbles {
|
||||||
Bubbles,
|
Bubbles,
|
||||||
DoesNotBubble
|
DoesNotBubble
|
||||||
|
@ -50,7 +52,7 @@ impl From<bool> for EventBubbles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, HeapSizeOf)]
|
#[derive(PartialEq, HeapSizeOf, Copy, Clone)]
|
||||||
pub enum EventCancelable {
|
pub enum EventCancelable {
|
||||||
Cancelable,
|
Cancelable,
|
||||||
NotCancelable
|
NotCancelable
|
||||||
|
@ -297,3 +299,35 @@ impl Event {
|
||||||
target.dispatch_event(self)
|
target.dispatch_event(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#concept-event-fire
|
||||||
|
pub struct EventRunnable {
|
||||||
|
pub target: Trusted<EventTarget>,
|
||||||
|
pub name: Atom,
|
||||||
|
pub bubbles: EventBubbles,
|
||||||
|
pub cancelable: EventCancelable,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for EventRunnable {
|
||||||
|
fn name(&self) -> &'static str { "EventRunnable" }
|
||||||
|
|
||||||
|
fn handler(self: Box<EventRunnable>) {
|
||||||
|
let target = self.target.root();
|
||||||
|
target.fire_event(&*self.name, self.bubbles, self.cancelable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#fire-a-simple-event
|
||||||
|
pub struct SimpleEventRunnable {
|
||||||
|
pub target: Trusted<EventTarget>,
|
||||||
|
pub name: Atom,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for SimpleEventRunnable {
|
||||||
|
fn name(&self) -> &'static str { "SimpleEventRunnable" }
|
||||||
|
|
||||||
|
fn handler(self: Box<SimpleEventRunnable>) {
|
||||||
|
let target = self.target.root();
|
||||||
|
target.fire_simple_event(&*self.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl VirtualMethods for HTMLDetailsElement {
|
||||||
element: details,
|
element: details,
|
||||||
toggle_number: counter
|
toggle_number: counter
|
||||||
};
|
};
|
||||||
let _ = task_source.queue(DOMManipulationTask::Runnable(runnable));
|
let _ = task_source.queue(DOMManipulationTask(runnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,7 +484,7 @@ impl HTMLFormElement {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 3
|
// Step 3
|
||||||
window.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(nav)).unwrap();
|
window.dom_manipulation_task_source().queue(DOMManipulationTask(nav)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interactively validate the constraints of form elements
|
/// Interactively validate the constraints of form elements
|
||||||
|
|
|
@ -185,7 +185,7 @@ impl HTMLImageElement {
|
||||||
src: src.into(),
|
src: src.into(),
|
||||||
});
|
});
|
||||||
let task = window.dom_manipulation_task_source();
|
let task = window.dom_manipulation_task_source();
|
||||||
let _ = task.queue(DOMManipulationTask::Runnable(runnable));
|
let _ = task.queue(DOMManipulationTask(runnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ impl HTMLMediaElement {
|
||||||
elem: Trusted::new(self),
|
elem: Trusted::new(self),
|
||||||
};
|
};
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2
|
// https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2
|
||||||
|
@ -266,13 +266,13 @@ impl HTMLMediaElement {
|
||||||
elem: Trusted::new(self),
|
elem: Trusted::new(self),
|
||||||
};
|
};
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_fire_simple_event(&self, type_: &'static str) {
|
fn queue_fire_simple_event(&self, type_: &'static str) {
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
let task = FireSimpleEventTask::new(self, type_);
|
let task = FireSimpleEventTask::new(self, type_);
|
||||||
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fire_simple_event(&self, type_: &str) {
|
fn fire_simple_event(&self, type_: &str) {
|
||||||
|
@ -499,7 +499,7 @@ impl HTMLMediaElement {
|
||||||
|
|
||||||
fn queue_dedicated_media_source_failure_steps(&self) {
|
fn queue_dedicated_media_source_failure_steps(&self) {
|
||||||
let _ = window_from_node(self).dom_manipulation_task_source().queue(
|
let _ = window_from_node(self).dom_manipulation_task_source().queue(
|
||||||
DOMManipulationTask::Runnable(box DedicatedMediaSourceFailureTask::new(self)));
|
DOMManipulationTask(box DedicatedMediaSourceFailureTask::new(self)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps
|
// https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps
|
||||||
|
|
|
@ -161,7 +161,7 @@ impl Storage {
|
||||||
let global_ref = global_root.r();
|
let global_ref = global_root.r();
|
||||||
let task_source = global_ref.as_window().dom_manipulation_task_source();
|
let task_source = global_ref.as_window().dom_manipulation_task_source();
|
||||||
let trusted_storage = Trusted::new(self);
|
let trusted_storage = Trusted::new(self);
|
||||||
task_source.queue(DOMManipulationTask::Runnable(
|
task_source.queue(DOMManipulationTask(
|
||||||
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
|
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -982,7 +982,7 @@ impl ScriptThread {
|
||||||
MainThreadScriptMsg::DOMManipulation(task) =>
|
MainThreadScriptMsg::DOMManipulation(task) =>
|
||||||
task.handle_task(self),
|
task.handle_task(self),
|
||||||
MainThreadScriptMsg::UserInteraction(task) =>
|
MainThreadScriptMsg::UserInteraction(task) =>
|
||||||
task.handle_task(),
|
task.handle_task(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1221,7 +1221,7 @@ impl ScriptThread {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#the-end step 7
|
// https://html.spec.whatwg.org/multipage/#the-end step 7
|
||||||
let handler = box DocumentProgressHandler::new(Trusted::new(doc));
|
let handler = box DocumentProgressHandler::new(Trusted::new(doc));
|
||||||
self.dom_manipulation_task_source.queue(DOMManipulationTask::Runnable(handler)).unwrap();
|
self.dom_manipulation_task_source.queue(DOMManipulationTask(handler)).unwrap();
|
||||||
|
|
||||||
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
|
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread};
|
use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread};
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
|
@ -27,44 +27,31 @@ impl DOMManipulationTaskSource {
|
||||||
bubbles: EventBubbles,
|
bubbles: EventBubbles,
|
||||||
cancelable: EventCancelable) {
|
cancelable: EventCancelable) {
|
||||||
let target = Trusted::new(target);
|
let target = Trusted::new(target);
|
||||||
let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireEvent(
|
let runnable = box EventRunnable {
|
||||||
target, name, bubbles, cancelable)));
|
target: target,
|
||||||
|
name: name,
|
||||||
|
bubbles: bubbles,
|
||||||
|
cancelable: cancelable,
|
||||||
|
};
|
||||||
|
let _ = self.queue(DOMManipulationTask(runnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom) {
|
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom) {
|
||||||
let target = Trusted::new(target);
|
let target = Trusted::new(target);
|
||||||
let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireSimpleEvent(
|
let runnable = box SimpleEventRunnable {
|
||||||
target, name)));
|
target: target,
|
||||||
|
name: name,
|
||||||
|
};
|
||||||
|
let _ = self.queue(DOMManipulationTask(runnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum DOMManipulationTask {
|
pub struct DOMManipulationTask(pub Box<Runnable + Send>);
|
||||||
// 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>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DOMManipulationTask {
|
impl DOMManipulationTask {
|
||||||
pub fn handle_task(self, script_thread: &ScriptThread) {
|
pub fn handle_task(self, script_thread: &ScriptThread) {
|
||||||
use self::DOMManipulationTask::*;
|
if !self.0.is_cancelled() {
|
||||||
|
self.0.main_thread_handler(script_thread);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{EventBubbles, EventCancelable, EventRunnable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use script_thread::MainThreadScriptMsg;
|
use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread};
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
@ -27,25 +27,22 @@ impl UserInteractionTaskSource {
|
||||||
bubbles: EventBubbles,
|
bubbles: EventBubbles,
|
||||||
cancelable: EventCancelable) {
|
cancelable: EventCancelable) {
|
||||||
let target = Trusted::new(target);
|
let target = Trusted::new(target);
|
||||||
let _ = self.0.send(MainThreadScriptMsg::UserInteraction(UserInteractionTask::FireEvent(
|
let runnable = box EventRunnable {
|
||||||
target, name, bubbles, cancelable)));
|
target: target,
|
||||||
|
name: name,
|
||||||
|
bubbles: bubbles,
|
||||||
|
cancelable: cancelable,
|
||||||
|
};
|
||||||
|
let _ = self.queue(UserInteractionTask(runnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum UserInteractionTask {
|
pub struct UserInteractionTask(pub Box<Runnable + Send>);
|
||||||
// https://dom.spec.whatwg.org/#concept-event-fire
|
|
||||||
FireEvent(Trusted<EventTarget>, Atom, EventBubbles, EventCancelable),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserInteractionTask {
|
impl UserInteractionTask {
|
||||||
pub fn handle_task(self) {
|
pub fn handle_task(self, script_thread: &ScriptThread) {
|
||||||
use self::UserInteractionTask::*;
|
if !self.0.is_cancelled() {
|
||||||
|
self.0.main_thread_handler(script_thread);
|
||||||
match self {
|
|
||||||
FireEvent(element, name, bubbles, cancelable) => {
|
|
||||||
let target = element.root();
|
|
||||||
target.fire_event(&*name, bubbles, cancelable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue