Skip to content

Commit

Permalink
Auto merge of #22449 - georgeroman:implement_htmlmediaelement_playbac…
Browse files Browse the repository at this point in the history
…k_rates, r=<try>

Implement HTMLMediaElement defaultPlaybackRate and playbackRate

<!-- Please describe your changes on the following line: -->

---
<!-- 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
- [X] These changes fix #22293

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22449)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Dec 14, 2018
2 parents f7fd128 + e7e89ad commit 34a45c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
1 change: 1 addition & 0 deletions components/atoms/static_atoms.txt
Expand Up @@ -67,6 +67,7 @@ print
progress
radio
range
ratechange
readystatechange
reftest-wait
rejectionhandled
Expand Down
40 changes: 39 additions & 1 deletion components/script/dom/htmlmediaelement.rs
Expand Up @@ -164,6 +164,10 @@ pub struct HTMLMediaElement {
error: MutNullableDom<MediaError>,
/// <https://html.spec.whatwg.org/multipage/#dom-media-paused>
paused: Cell<bool>,
/// <https://html.spec.whatwg.org/multipage/#dom-media-defaultplaybackrate>
defaultPlaybackRate: Cell<f64>,
/// <https://html.spec.whatwg.org/multipage/#dom-media-playbackrate>
playbackRate: Cell<f64>,
/// <https://html.spec.whatwg.org/multipage/#attr-media-autoplay>
autoplaying: Cell<bool>,
/// <https://html.spec.whatwg.org/multipage/#delaying-the-load-event-flag>
Expand Down Expand Up @@ -235,6 +239,8 @@ impl HTMLMediaElement {
fired_loadeddata_event: Cell::new(false),
error: Default::default(),
paused: Cell::new(true),
defaultPlaybackRate: Cell::new(1.0),
playbackRate: Cell::new(1.0),
// FIXME(nox): Why is this initialised to true?
autoplaying: Cell::new(true),
delaying_the_load_event_flag: Default::default(),
Expand Down Expand Up @@ -960,7 +966,7 @@ impl HTMLMediaElement {
}

// Step 7.
// FIXME(nox): Set playbackRate to defaultPlaybackRate.
self.playbackRate.set(self.defaultPlaybackRate.get());

// Step 8.
self.error.set(None);
Expand Down Expand Up @@ -1350,6 +1356,38 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
self.paused.get()
}

/// https://html.spec.whatwg.org/multipage/#dom-media-defaultplaybackrate
fn DefaultPlaybackRate(&self) -> Finite<f64> {
Finite::wrap(self.defaultPlaybackRate.get())
}

/// https://html.spec.whatwg.org/multipage/#dom-media-defaultplaybackrate
fn SetDefaultPlaybackRate(&self, value: Finite<f64>) {
if *value != self.defaultPlaybackRate.get() {
self.defaultPlaybackRate.set(*value);

let window = window_from_node(self);
let task_source = window.task_manager().media_element_task_source();
task_source.queue_simple_event(self.upcast(), atom!("ratechange"), &window);
}
}

/// https://html.spec.whatwg.org/multipage/#dom-media-playbackrate
fn PlaybackRate(&self) -> Finite<f64> {
Finite::wrap(self.playbackRate.get())
}

/// https://html.spec.whatwg.org/multipage/#dom-media-playbackrate
fn SetPlaybackRate(&self, value: Finite<f64>) {
if *value != self.playbackRate.get() {
self.playbackRate.set(*value);

let window = window_from_node(self);
let task_source = window.task_manager().media_element_task_source();
task_source.queue_simple_event(self.upcast(), atom!("ratechange"), &window);
}
}

// https://html.spec.whatwg.org/multipage/#dom-media-duration
fn Duration(&self) -> f64 {
self.duration.get()
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/webidls/HTMLMediaElement.webidl
Expand Up @@ -42,8 +42,8 @@ interface HTMLMediaElement : HTMLElement {
readonly attribute unrestricted double duration;
// Date getStartDate();
readonly attribute boolean paused;
// attribute double defaultPlaybackRate;
// attribute double playbackRate;
attribute double defaultPlaybackRate;
attribute double playbackRate;
readonly attribute TimeRanges played;
// readonly attribute TimeRanges seekable;
// readonly attribute boolean ended;
Expand Down

This file was deleted.

0 comments on commit 34a45c2

Please sign in to comment.