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

HTMLMediaElement played attribute #22093

Merged
merged 1 commit into from Nov 21, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

HTMLMediaElement playing attribute

  • Loading branch information
ferjm committed Nov 21, 2018
commit f98da2e7b73885888b211736d4f7582511c9016a
@@ -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::performanceresourcetiming::InitiatorType;
use crate::dom::promise::Promise;
use crate::dom::timeranges::{TimeRanges, TimeRangesContainer};
use crate::dom::virtualmethods::VirtualMethods;
use crate::fetch::FetchCanceller;
use crate::microtask::{Microtask, MicrotaskRunnable};
@@ -182,6 +183,9 @@ pub struct HTMLMediaElement {
seeking: Cell<bool>,
/// URL of the media resource, if any.
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>
@@ -233,6 +237,7 @@ impl HTMLMediaElement {
default_playback_start_position: Cell::new(0.),
seeking: Cell::new(false),
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.
},
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 {
PlaybackState::Paused => {
@@ -1356,6 +1366,11 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
fn FastSeek(&self, time: Finite<f64>) {
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 {
@@ -12,6 +12,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use std::fmt;
use std::rc::Rc;

#[derive(JSTraceable, MallocSizeOf)]
struct TimeRange {
@@ -127,23 +128,27 @@ impl TimeRangesContainer {
#[dom_struct]
pub struct TimeRanges {
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
// on the media element implementation.
#[allow(dead_code)]
impl TimeRanges {
fn new_inherited() -> TimeRanges {
fn new_inherited(ranges: Rc<DomRefCell<TimeRangesContainer>>) -> TimeRanges {
Self {
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(
Box::new(TimeRanges::new_inherited()),
Box::new(TimeRanges::new_inherited(ranges)),
window,
TimeRangesBinding::Wrap,
)
@@ -44,7 +44,7 @@ interface HTMLMediaElement : HTMLElement {
readonly attribute boolean paused;
// attribute double defaultPlaybackRate;
// attribute double playbackRate;
// readonly attribute TimeRanges played;
readonly attribute TimeRanges played;
// readonly attribute TimeRanges seekable;
// readonly attribute boolean ended;
[CEReactions] attribute boolean autoplay;
@@ -6792,9 +6792,6 @@
[HTMLMediaElement interface: document.createElement("video") must inherit property "playbackRate" with the proper type]
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]
expected: FAIL

@@ -6849,9 +6846,6 @@
[HTMLMediaElement interface: document.createElement("audio") must inherit property "playbackRate" with the proper type]
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]
expected: FAIL

@@ -6906,9 +6900,6 @@
[HTMLMediaElement interface: new Audio() must inherit property "playbackRate" with the proper type]
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]
expected: FAIL

@@ -7038,9 +7029,6 @@
[HTMLMediaElement interface: attribute playbackRate]
expected: FAIL

[HTMLMediaElement interface: attribute played]
expected: FAIL

[HTMLMediaElement interface: attribute seekable]
expected: FAIL

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