mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #12292 - ConnorGBrewster:runnable_variant, r=KiChjang
Consolidate runnable variants on DOMManipulationTask into a single Runnable variant. <!-- Please describe your changes on the following line: --> Consolidates the runnable variants on `DOMManipulationTask` into a single `Runnable` variant. Also combines `MainThreadRunnable` into the `Runnable` trait. I plan on filing a few E-Easy issues after this lands to implement `name` on each of the structs that implement `Runnable`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12292) <!-- Reviewable:end -->
This commit is contained in:
commit
fdfde1c5eb
7 changed files with 25 additions and 36 deletions
|
@ -79,7 +79,7 @@ impl VirtualMethods for HTMLDetailsElement {
|
||||||
element: details,
|
element: details,
|
||||||
toggle_number: counter
|
toggle_number: counter
|
||||||
};
|
};
|
||||||
let _ = task_source.queue(DOMManipulationTask::FireToggleEvent(runnable));
|
let _ = task_source.queue(DOMManipulationTask::Runnable(runnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,8 +484,7 @@ impl HTMLFormElement {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 3
|
// Step 3
|
||||||
window.dom_manipulation_task_source().queue(
|
window.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(nav)).unwrap();
|
||||||
DOMManipulationTask::PlannedNavigation(nav)).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interactively validate the constraints of form elements
|
/// Interactively validate the constraints of form elements
|
||||||
|
|
|
@ -183,7 +183,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::Miscellaneous(runnable));
|
let _ = task.queue(DOMManipulationTask::Runnable(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::MediaTask(box task));
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(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::MediaTask(box task));
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(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::MediaTask(box task));
|
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fire_simple_event(&self, type_: &str) {
|
fn fire_simple_event(&self, type_: &str) {
|
||||||
|
@ -497,7 +497,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::MediaTask(box DedicatedMediaSourceFailureTask::new(self)));
|
DOMManipulationTask::Runnable(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
|
||||||
|
|
|
@ -17,7 +17,7 @@ use dom::urlhelper::UrlHelper;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
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::{Runnable, ScriptThread};
|
||||||
use task_source::TaskSource;
|
use task_source::TaskSource;
|
||||||
use task_source::dom_manipulation::DOMManipulationTask;
|
use task_source::dom_manipulation::DOMManipulationTask;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -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::SendStorageNotification(
|
task_source.queue(DOMManipulationTask::Runnable(
|
||||||
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
|
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,8 +180,10 @@ impl StorageEventRunnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainThreadRunnable for StorageEventRunnable {
|
impl Runnable for StorageEventRunnable {
|
||||||
fn handler(self: Box<StorageEventRunnable>, script_thread: &ScriptThread) {
|
fn name(&self) -> &'static str { "StorageEventRunnable" }
|
||||||
|
|
||||||
|
fn main_thread_handler(self: Box<StorageEventRunnable>, script_thread: &ScriptThread) {
|
||||||
let this = *self;
|
let this = *self;
|
||||||
let storage_root = this.element.root();
|
let storage_root = this.element.root();
|
||||||
let storage = storage_root.r();
|
let storage = storage_root.r();
|
||||||
|
|
|
@ -200,11 +200,9 @@ impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
|
||||||
|
|
||||||
pub trait Runnable {
|
pub trait Runnable {
|
||||||
fn is_cancelled(&self) -> bool { false }
|
fn is_cancelled(&self) -> bool { false }
|
||||||
fn handler(self: Box<Self>);
|
fn name(&self) -> &'static str { "generic runnable" }
|
||||||
}
|
fn handler(self: Box<Self>) {}
|
||||||
|
fn main_thread_handler(self: Box<Self>, _script_thread: &ScriptThread) { self.handler(); }
|
||||||
pub trait MainThreadRunnable {
|
|
||||||
fn handler(self: Box<Self>, script_thread: &ScriptThread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MixedMessage {
|
enum MixedMessage {
|
||||||
|
@ -1223,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::DocumentProgress(handler)).unwrap();
|
self.dom_manipulation_task_source.queue(DOMManipulationTask::Runnable(handler)).unwrap();
|
||||||
|
|
||||||
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
|
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{EventBubbles, EventCancelable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use script_thread::{MainThreadRunnable, MainThreadScriptMsg, Runnable, ScriptThread};
|
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;
|
||||||
|
@ -39,21 +39,12 @@ impl DOMManipulationTaskSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum DOMManipulationTask {
|
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
|
// https://dom.spec.whatwg.org/#concept-event-fire
|
||||||
FireEvent(Trusted<EventTarget>, Atom, 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(Trusted<EventTarget>, Atom),
|
FireSimpleEvent(Trusted<EventTarget>, Atom),
|
||||||
// https://html.spec.whatwg.org/multipage/#details-notification-task-steps
|
|
||||||
FireToggleEvent(Box<Runnable + Send>),
|
Runnable(Box<Runnable + Send>),
|
||||||
// Placeholder until there's a real media element task queue implementation
|
|
||||||
MediaTask(Box<Runnable + Send>),
|
|
||||||
// https://html.spec.whatwg.org/multipage/#planned-navigation
|
|
||||||
PlannedNavigation(Box<Runnable + Send>),
|
|
||||||
// https://html.spec.whatwg.org/multipage/#send-a-storage-notification
|
|
||||||
SendStorageNotification(Box<MainThreadRunnable + Send>),
|
|
||||||
Miscellaneous(Box<Runnable + Send>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DOMManipulationTask {
|
impl DOMManipulationTask {
|
||||||
|
@ -61,7 +52,6 @@ impl DOMManipulationTask {
|
||||||
use self::DOMManipulationTask::*;
|
use self::DOMManipulationTask::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
DocumentProgress(runnable) => runnable.handler(),
|
|
||||||
FireEvent(element, name, 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);
|
||||||
|
@ -70,11 +60,11 @@ impl DOMManipulationTask {
|
||||||
let target = element.root();
|
let target = element.root();
|
||||||
target.fire_simple_event(&*name);
|
target.fire_simple_event(&*name);
|
||||||
}
|
}
|
||||||
FireToggleEvent(runnable) => runnable.handler(),
|
Runnable(runnable) => {
|
||||||
MediaTask(runnable) => runnable.handler(),
|
if !runnable.is_cancelled() {
|
||||||
PlannedNavigation(runnable) => runnable.handler(),
|
runnable.main_thread_handler(script_thread);
|
||||||
SendStorageNotification(runnable) => runnable.handler(script_thread),
|
}
|
||||||
Miscellaneous(runnable) => runnable.handler(),
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue