Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic <media> infrastructure #8454

Merged
merged 13 commits into from May 4, 2016

Pause media elements when they're removed from the document.

  • Loading branch information
jdm committed May 3, 2016
commit d718da1c6abe083c602dcbe39d586c845f5817ef
@@ -20,7 +20,7 @@ use dom::event::{Event, EventBubbles, EventCancelable};
use dom::htmlelement::HTMLElement;
use dom::htmlsourceelement::HTMLSourceElement;
use dom::mediaerror::MediaError;
use dom::node::{window_from_node, document_from_node};
use dom::node::{window_from_node, document_from_node, Node, UnbindContext};
use dom::virtualmethods::VirtualMethods;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
@@ -602,6 +602,15 @@ impl VirtualMethods for HTMLMediaElement {
_ => (),
};
}

// https://html.spec.whatwg.org/multipage/#playing-the-media-resource:media-element-75
fn unbind_from_tree(&self, context: &UnbindContext) {
self.super_type().unwrap().unbind_from_tree(context);

if context.tree_in_doc {
ScriptThread::await_stable_state(PauseIfNotInDocumentTask::new(self));
}
}
}

struct FireSimpleEventTask {
@@ -663,6 +672,27 @@ impl Runnable for DedicatedMediaSourceFailureTask {
}
}

struct PauseIfNotInDocumentTask {
elem: Trusted<HTMLMediaElement>,
}

impl PauseIfNotInDocumentTask {
fn new(elem: &HTMLMediaElement) -> PauseIfNotInDocumentTask {
PauseIfNotInDocumentTask {
elem: Trusted::new(elem),
}
}
}

impl Runnable for PauseIfNotInDocumentTask {
fn handler(self: Box<PauseIfNotInDocumentTask>) {
let elem = self.elem.root();
if !elem.upcast::<Node>().is_in_doc() {
elem.internal_pause_steps();
}
}
}

enum ResourceSelectionMode {
Object,
Attribute(String),

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.