mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Introduce a task! macro and use it for internal pause steps
This commit is contained in:
parent
46628fba05
commit
5412767f46
3 changed files with 29 additions and 10 deletions
|
@ -140,15 +140,11 @@ impl HTMLMediaElement {
|
||||||
|
|
||||||
// Step 2.3.
|
// Step 2.3.
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
|
let target = Trusted::new(self.upcast::<EventTarget>());
|
||||||
// FIXME(nox): Why are errors silenced here?
|
// FIXME(nox): Why are errors silenced here?
|
||||||
let _ = window.dom_manipulation_task_source().queue(
|
let _ = window.dom_manipulation_task_source().queue(
|
||||||
box InternalPauseStepsTask(Trusted::new(self.upcast())),
|
box task!(internal_pause_steps: move || {
|
||||||
window.upcast(),
|
let target = target.root();
|
||||||
);
|
|
||||||
struct InternalPauseStepsTask(Trusted<EventTarget>);
|
|
||||||
impl Task for InternalPauseStepsTask {
|
|
||||||
fn run(self: Box<Self>) {
|
|
||||||
let target = self.0.root();
|
|
||||||
|
|
||||||
// Step 2.3.1.
|
// Step 2.3.1.
|
||||||
target.fire_event(atom!("timeupdate"));
|
target.fire_event(atom!("timeupdate"));
|
||||||
|
@ -159,8 +155,9 @@ impl HTMLMediaElement {
|
||||||
// Step 2.3.3.
|
// Step 2.3.3.
|
||||||
// FIXME(nox): Reject pending play promises with promises
|
// FIXME(nox): Reject pending play promises with promises
|
||||||
// and an "AbortError" DOMException.
|
// and an "AbortError" DOMException.
|
||||||
}
|
}),
|
||||||
}
|
window.upcast(),
|
||||||
|
);
|
||||||
|
|
||||||
// Step 2.4.
|
// Step 2.4.
|
||||||
// FIXME(nox): Set the official playback position to the current
|
// FIXME(nox): Set the official playback position to the current
|
||||||
|
|
|
@ -106,6 +106,9 @@ extern crate webrender_api;
|
||||||
extern crate webvr_traits;
|
extern crate webvr_traits;
|
||||||
extern crate xml5ever;
|
extern crate xml5ever;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod task;
|
||||||
|
|
||||||
mod body;
|
mod body;
|
||||||
pub mod clipboard_provider;
|
pub mod clipboard_provider;
|
||||||
mod devtools;
|
mod devtools;
|
||||||
|
@ -123,7 +126,6 @@ pub mod script_thread;
|
||||||
mod serviceworker_manager;
|
mod serviceworker_manager;
|
||||||
mod serviceworkerjob;
|
mod serviceworkerjob;
|
||||||
mod stylesheet_loader;
|
mod stylesheet_loader;
|
||||||
mod task;
|
|
||||||
mod task_source;
|
mod task_source;
|
||||||
pub mod test;
|
pub mod test;
|
||||||
pub mod textinput;
|
pub mod textinput;
|
||||||
|
|
|
@ -9,6 +9,26 @@ use std::intrinsics;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
|
macro_rules! task {
|
||||||
|
($name:ident: move || $body:tt) => {{
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
struct $name<F>(F);
|
||||||
|
impl<F> ::task::Task for $name<F>
|
||||||
|
where
|
||||||
|
F: ::std::ops::FnOnce(),
|
||||||
|
{
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
stringify!($name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(self: Box<Self>) {
|
||||||
|
(self.0)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$name(move || $body)
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
/// A task that can be run. The name method is for profiling purposes.
|
/// A task that can be run. The name method is for profiling purposes.
|
||||||
pub trait Task {
|
pub trait Task {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue