Auto merge of #22324 - lucasfantacuci:implement_html_media_element_volume_attribute, r=ferjm

Implementing HTMLMediaElement.volume attribute

<!-- Please describe your changes on the following line: -->
This P.R. is going to implement the volume attribute to the HTMLMediaElement

---
<!-- 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 #22292.
<!-- Either: -->
- [x] There are tests for these changes

<!-- 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/22324)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-12-12 13:54:55 -05:00 committed by GitHub
commit d5c1690cb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 60 additions and 29 deletions

11
Cargo.lock generated
View file

@ -3528,7 +3528,7 @@ dependencies = [
[[package]]
name = "servo-media"
version = "0.1.0"
source = "git+https://github.com/servo/media#a3a2e8586074227f2e4b175c94f759df3690b195"
source = "git+https://github.com/servo/media#352072f33b6d118f89aa4ccf000ceaf360a5f663"
dependencies = [
"servo-media-audio 0.1.0 (git+https://github.com/servo/media)",
"servo-media-gstreamer 0.1.0 (git+https://github.com/servo/media)",
@ -3538,7 +3538,7 @@ dependencies = [
[[package]]
name = "servo-media-audio"
version = "0.1.0"
source = "git+https://github.com/servo/media#a3a2e8586074227f2e4b175c94f759df3690b195"
source = "git+https://github.com/servo/media#352072f33b6d118f89aa4ccf000ceaf360a5f663"
dependencies = [
"boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-slice-cast 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3555,7 +3555,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer"
version = "0.1.0"
source = "git+https://github.com/servo/media#a3a2e8586074227f2e4b175c94f759df3690b195"
source = "git+https://github.com/servo/media#352072f33b6d118f89aa4ccf000ceaf360a5f663"
dependencies = [
"byte-slice-cast 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3563,6 +3563,7 @@ dependencies = [
"gstreamer-app 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer-audio 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer-player 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer-video 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-media-audio 0.1.0 (git+https://github.com/servo/media)",
@ -3573,7 +3574,7 @@ dependencies = [
[[package]]
name = "servo-media-player"
version = "0.1.0"
source = "git+https://github.com/servo/media#a3a2e8586074227f2e4b175c94f759df3690b195"
source = "git+https://github.com/servo/media#352072f33b6d118f89aa4ccf000ceaf360a5f663"
dependencies = [
"ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3660,7 +3661,7 @@ dependencies = [
[[package]]
name = "servo_media_derive"
version = "0.1.0"
source = "git+https://github.com/servo/media#a3a2e8586074227f2e4b175c94f759df3690b195"
source = "git+https://github.com/servo/media#352072f33b6d118f89aa4ccf000ceaf360a5f663"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -101,6 +101,7 @@ transitionend
unhandledrejection
unload
url
volumechange
waiting
webglcontextcreationerror
week

View file

@ -15,7 +15,7 @@ use crate::dom::bindings::codegen::Bindings::MediaErrorBinding::MediaErrorMethod
use crate::dom::bindings::codegen::Bindings::TextTrackBinding::{TextTrackKind, TextTrackMode};
use crate::dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId};
use crate::dom::bindings::codegen::InheritTypes::{HTMLMediaElementTypeId, NodeTypeId};
use crate::dom::bindings::error::{Error, ErrorResult};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::Trusted;
@ -187,6 +187,8 @@ pub struct HTMLMediaElement {
playback_position: Cell<f64>,
/// https://html.spec.whatwg.org/multipage/#default-playback-start-position
default_playback_start_position: Cell<f64>,
/// https://html.spec.whatwg.org/multipage/#dom-media-volume
volume: Cell<f64>,
/// https://html.spec.whatwg.org/multipage/#dom-media-seeking
seeking: Cell<bool>,
/// URL of the media resource, if any.
@ -245,6 +247,7 @@ impl HTMLMediaElement {
duration: Cell::new(f64::NAN),
playback_position: Cell::new(0.),
default_playback_start_position: Cell::new(0.),
volume: Cell::new(1.0),
seeking: Cell::new(false),
resource_url: DomRefCell::new(None),
played: Rc::new(DomRefCell::new(TimeRangesContainer::new())),
@ -1413,6 +1416,32 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
// Step 5
DomRoot::from_ref(&track)
}
// https://html.spec.whatwg.org/multipage/#dom-media-volume
fn GetVolume(&self) -> Fallible<Finite<f64>> {
Ok(Finite::wrap(self.volume.get()))
}
// https://html.spec.whatwg.org/multipage/#dom-media-volume
fn SetVolume(&self, value: Finite<f64>) -> ErrorResult {
let minimum_volume = 0.0;
let maximum_volume = 1.0;
if *value < minimum_volume || *value > maximum_volume {
return Err(Error::IndexSize);
}
if *value != self.volume.get() {
self.volume.set(*value);
let window = window_from_node(self);
window
.task_manager()
.media_element_task_source()
.queue_simple_event(self.upcast(), atom!("volumechange"), &window);
}
Ok(())
}
}
impl VirtualMethods for HTMLMediaElement {

View file

@ -54,7 +54,7 @@ interface HTMLMediaElement : HTMLElement {
// controls
// [CEReactions] attribute boolean controls;
// attribute double volume;
[Throws] attribute double volume;
// attribute boolean muted;
// [CEReactions] attribute boolean defaultMuted;

View file

@ -1062,7 +1062,7 @@
expected: FAIL
[HTMLMediaElement interface: document.createElement("video") must inherit property "volume" with the proper type]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: document.createElement("video") must inherit property "muted" with the proper type]
expected: FAIL
@ -1134,7 +1134,7 @@
expected: FAIL
[HTMLMediaElement interface: document.createElement("audio") must inherit property "volume" with the proper type]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: document.createElement("audio") must inherit property "muted" with the proper type]
expected: FAIL
@ -1278,7 +1278,7 @@
expected: FAIL
[HTMLMediaElement interface: new Audio() must inherit property "volume" with the proper type]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: new Audio() must inherit property "muted" with the proper type]
expected: FAIL
@ -1425,7 +1425,7 @@
expected: FAIL
[HTMLMediaElement interface: attribute volume]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: attribute muted]
expected: FAIL
@ -6793,7 +6793,7 @@
expected: FAIL
[HTMLMediaElement interface: document.createElement("video") must inherit property "volume" with the proper type]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: document.createElement("video") must inherit property "muted" with the proper type]
expected: FAIL
@ -6838,7 +6838,7 @@
expected: FAIL
[HTMLMediaElement interface: document.createElement("audio") must inherit property "volume" with the proper type]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: document.createElement("audio") must inherit property "muted" with the proper type]
expected: FAIL
@ -6883,7 +6883,7 @@
expected: FAIL
[HTMLMediaElement interface: new Audio() must inherit property "volume" with the proper type]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: new Audio() must inherit property "muted" with the proper type]
expected: FAIL
@ -7006,7 +7006,7 @@
expected: FAIL
[HTMLMediaElement interface: attribute volume]
expected: FAIL
expected: PASS
[HTMLMediaElement interface: attribute muted]
expected: FAIL

View file

@ -1,8 +1,8 @@
[audio_volume_check.html]
type: testharness
[Check if media.volume is set to new value less than 0.0 that expecting an IndexSizeError exception is to be thrown]
expected: FAIL
expected: PASS
[Check if audio.volume is set to new value greater than 1.0 that expecting an IndexSizeError exception is to be thrown]
expected: FAIL
expected: PASS

View file

@ -2,7 +2,7 @@
type: testharness
expected: TIMEOUT
[setting audio.volume fires volumechange]
expected: FAIL
expected: PASS
[setting audio.muted fires volumechange]
expected: FAIL
@ -14,7 +14,7 @@
expected: TIMEOUT
[setting video.volume fires volumechange]
expected: FAIL
expected: PASS
[setting video.muted fires volumechange]
expected: FAIL

View file

@ -1,6 +1,6 @@
[pause-remove-from-document.html]
type: testharness
expected: TIMEOUT
expected: OK
[paused state when removing from a document]
expected: TIMEOUT
expected: PASS

View file

@ -1,8 +1,8 @@
[video_volume_check.html]
type: testharness
[Check if media.volume is set to new value less than 0.0 that expecting an IndexSizeError exception is to be thrown]
expected: FAIL
expected: PASS
[Check if video.volume is set to new value greater than 1.0 that expecting an IndexSizeError exception is to be thrown]
expected: FAIL
expected: PASS

View file

@ -1,20 +1,20 @@
[volume_nonfinite.html]
type: testharness
[Setting audio.volume to NaN should throw a TypeError]
expected: FAIL
expected: PASS
[Setting audio.volume to Infinity should throw a TypeError]
expected: FAIL
expected: PASS
[Setting audio.volume to -Infinity should throw a TypeError]
expected: FAIL
expected: PASS
[Setting video.volume to NaN should throw a TypeError]
expected: FAIL
expected: PASS
[Setting video.volume to Infinity should throw a TypeError]
expected: FAIL
expected: PASS
[Setting video.volume to -Infinity should throw a TypeError]
expected: FAIL
expected: PASS