mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implementing volume attribute into HTMLMediaElement
This commit is contained in:
parent
1046ae58a1
commit
ad3ec61d2f
10 changed files with 60 additions and 29 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue