Auto merge of #22093 - ferjm:media.playing, r=Manishearth

HTMLMediaElement played attribute

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22093)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-11-21 04:00:44 -05:00 committed by GitHub
commit 45a1ca2bdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 19 deletions

View file

@ -33,6 +33,7 @@ use crate::dom::mediaerror::MediaError;
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, UnbindContext}; use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, UnbindContext};
use crate::dom::performanceresourcetiming::InitiatorType; use crate::dom::performanceresourcetiming::InitiatorType;
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
use crate::dom::timeranges::{TimeRanges, TimeRangesContainer};
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use crate::fetch::FetchCanceller; use crate::fetch::FetchCanceller;
use crate::microtask::{Microtask, MicrotaskRunnable}; use crate::microtask::{Microtask, MicrotaskRunnable};
@ -182,6 +183,9 @@ pub struct HTMLMediaElement {
seeking: Cell<bool>, seeking: Cell<bool>,
/// URL of the media resource, if any. /// URL of the media resource, if any.
resource_url: DomRefCell<Option<ServoUrl>>, resource_url: DomRefCell<Option<ServoUrl>>,
/// https://html.spec.whatwg.org/multipage/#dom-media-played
#[ignore_malloc_size_of = "Rc"]
played: Rc<DomRefCell<TimeRangesContainer>>,
} }
/// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate> /// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate>
@ -233,6 +237,7 @@ impl HTMLMediaElement {
default_playback_start_position: Cell::new(0.), default_playback_start_position: Cell::new(0.),
seeking: Cell::new(false), seeking: Cell::new(false),
resource_url: DomRefCell::new(None), resource_url: DomRefCell::new(None),
played: Rc::new(DomRefCell::new(TimeRangesContainer::new())),
} }
} }
@ -1186,7 +1191,12 @@ impl HTMLMediaElement {
// XXX Steps 12 and 13 require audio and video tracks support. // XXX Steps 12 and 13 require audio and video tracks support.
}, },
PlayerEvent::PositionChanged(position) => { PlayerEvent::PositionChanged(position) => {
self.playback_position.set(position as f64); let position = position as f64;
let _ = self
.played
.borrow_mut()
.add(self.playback_position.get(), position);
self.playback_position.set(position);
}, },
PlayerEvent::StateChanged(ref state) => match *state { PlayerEvent::StateChanged(ref state) => match *state {
PlaybackState::Paused => { PlaybackState::Paused => {
@ -1356,6 +1366,11 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
fn FastSeek(&self, time: Finite<f64>) { fn FastSeek(&self, time: Finite<f64>) {
self.seek(*time, /* approximat_for_speed */ true); self.seek(*time, /* approximat_for_speed */ true);
} }
// https://html.spec.whatwg.org/multipage/#dom-media-played
fn Played(&self) -> DomRoot<TimeRanges> {
TimeRanges::new(self.global().as_window(), self.played.clone())
}
} }
impl VirtualMethods for HTMLMediaElement { impl VirtualMethods for HTMLMediaElement {

View file

@ -12,6 +12,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window; use crate::dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::fmt; use std::fmt;
use std::rc::Rc;
#[derive(JSTraceable, MallocSizeOf)] #[derive(JSTraceable, MallocSizeOf)]
struct TimeRange { struct TimeRange {
@ -127,23 +128,27 @@ impl TimeRangesContainer {
#[dom_struct] #[dom_struct]
pub struct TimeRanges { pub struct TimeRanges {
reflector_: Reflector, reflector_: Reflector,
ranges: DomRefCell<TimeRangesContainer>, #[ignore_malloc_size_of = "Rc"]
ranges: Rc<DomRefCell<TimeRangesContainer>>,
} }
//XXX(ferjm) We'll get warnings about unused methods until we use this //XXX(ferjm) We'll get warnings about unused methods until we use this
// on the media element implementation. // on the media element implementation.
#[allow(dead_code)] #[allow(dead_code)]
impl TimeRanges { impl TimeRanges {
fn new_inherited() -> TimeRanges { fn new_inherited(ranges: Rc<DomRefCell<TimeRangesContainer>>) -> TimeRanges {
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
ranges: DomRefCell::new(TimeRangesContainer::new()), ranges,
} }
} }
pub fn new(window: &Window) -> DomRoot<TimeRanges> { pub fn new(
window: &Window,
ranges: Rc<DomRefCell<TimeRangesContainer>>,
) -> DomRoot<TimeRanges> {
reflect_dom_object( reflect_dom_object(
Box::new(TimeRanges::new_inherited()), Box::new(TimeRanges::new_inherited(ranges)),
window, window,
TimeRangesBinding::Wrap, TimeRangesBinding::Wrap,
) )

View file

@ -44,7 +44,7 @@ interface HTMLMediaElement : HTMLElement {
readonly attribute boolean paused; readonly attribute boolean paused;
// attribute double defaultPlaybackRate; // attribute double defaultPlaybackRate;
// attribute double playbackRate; // attribute double playbackRate;
// readonly attribute TimeRanges played; readonly attribute TimeRanges played;
// readonly attribute TimeRanges seekable; // readonly attribute TimeRanges seekable;
// readonly attribute boolean ended; // readonly attribute boolean ended;
[CEReactions] attribute boolean autoplay; [CEReactions] attribute boolean autoplay;

View file

@ -6792,9 +6792,6 @@
[HTMLMediaElement interface: document.createElement("video") must inherit property "playbackRate" with the proper type] [HTMLMediaElement interface: document.createElement("video") must inherit property "playbackRate" with the proper type]
expected: FAIL expected: FAIL
[HTMLMediaElement interface: document.createElement("video") must inherit property "played" with the proper type]
expected: FAIL
[HTMLMediaElement interface: document.createElement("video") must inherit property "seekable" with the proper type] [HTMLMediaElement interface: document.createElement("video") must inherit property "seekable" with the proper type]
expected: FAIL expected: FAIL
@ -6849,9 +6846,6 @@
[HTMLMediaElement interface: document.createElement("audio") must inherit property "playbackRate" with the proper type] [HTMLMediaElement interface: document.createElement("audio") must inherit property "playbackRate" with the proper type]
expected: FAIL expected: FAIL
[HTMLMediaElement interface: document.createElement("audio") must inherit property "played" with the proper type]
expected: FAIL
[HTMLMediaElement interface: document.createElement("audio") must inherit property "seekable" with the proper type] [HTMLMediaElement interface: document.createElement("audio") must inherit property "seekable" with the proper type]
expected: FAIL expected: FAIL
@ -6906,9 +6900,6 @@
[HTMLMediaElement interface: new Audio() must inherit property "playbackRate" with the proper type] [HTMLMediaElement interface: new Audio() must inherit property "playbackRate" with the proper type]
expected: FAIL expected: FAIL
[HTMLMediaElement interface: new Audio() must inherit property "played" with the proper type]
expected: FAIL
[HTMLMediaElement interface: new Audio() must inherit property "seekable" with the proper type] [HTMLMediaElement interface: new Audio() must inherit property "seekable" with the proper type]
expected: FAIL expected: FAIL
@ -7038,9 +7029,6 @@
[HTMLMediaElement interface: attribute playbackRate] [HTMLMediaElement interface: attribute playbackRate]
expected: FAIL expected: FAIL
[HTMLMediaElement interface: attribute played]
expected: FAIL
[HTMLMediaElement interface: attribute seekable] [HTMLMediaElement interface: attribute seekable]
expected: FAIL expected: FAIL