aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlmediaelement.rs
diff options
context:
space:
mode:
authorLucas Fantacuci <lucasfantacuci@gmail.com>2018-12-12 11:17:41 -0200
committerLucas Fantacuci <lucasfantacuci@gmail.com>2018-12-12 11:50:35 -0200
commitad3ec61d2fff041e032df30c813b742ae4d9bb72 (patch)
treed5aef9376f4e2f5082f516b861d6f11ef63e0154 /components/script/dom/htmlmediaelement.rs
parent1046ae58a155d3f1ab4d011242a03a81a712f3c4 (diff)
downloadservo-ad3ec61d2fff041e032df30c813b742ae4d9bb72.tar.gz
servo-ad3ec61d2fff041e032df30c813b742ae4d9bb72.zip
Implementing volume attribute into HTMLMediaElement
Diffstat (limited to 'components/script/dom/htmlmediaelement.rs')
-rw-r--r--components/script/dom/htmlmediaelement.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs
index bbdea90dee9..832a30f94c4 100644
--- a/components/script/dom/htmlmediaelement.rs
+++ b/components/script/dom/htmlmediaelement.rs
@@ -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 {