diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2017-11-07 20:57:30 +0100 |
---|---|---|
committer | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2018-07-30 14:21:36 +0200 |
commit | 7ee42e4223dc970aeffc56ecddec2738c8340f8c (patch) | |
tree | 1f53a3dc650992ab7b84c9a9e0e748d11ca97a7d /components/script/dom/audioparam.rs | |
parent | de48f25d0b0b5ecaf0499030f8617a3d37b3fde2 (diff) | |
download | servo-7ee42e4223dc970aeffc56ecddec2738c8340f8c.tar.gz servo-7ee42e4223dc970aeffc56ecddec2738c8340f8c.zip |
Initial WebAudio API stubs
Diffstat (limited to 'components/script/dom/audioparam.rs')
-rw-r--r-- | components/script/dom/audioparam.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/components/script/dom/audioparam.rs b/components/script/dom/audioparam.rs new file mode 100644 index 00000000000..1b42af0a4e5 --- /dev/null +++ b/components/script/dom/audioparam.rs @@ -0,0 +1,66 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::Bindings::AudioParamBinding; +use dom::bindings::codegen::Bindings::AudioParamBinding::AudioParamMethods; +use dom::bindings::num::Finite; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::root::DomRoot; +use dom::globalscope::GlobalScope; +use dom_struct::dom_struct; +use std::cell::Cell; + +#[dom_struct] +pub struct AudioParam { + reflector_: Reflector, + value: Cell<f32>, + default_value: f32, + min_value: f32, + max_value: f32, +} + +impl AudioParam { + pub fn new_inherited(default_value: f32, + min_value: f32, + max_value: f32) -> AudioParam { + AudioParam { + reflector_: Reflector::new(), + value: Cell::new(default_value), + default_value, + min_value, + max_value, + } + } + + #[allow(unrooted_must_root)] + pub fn new(global: &GlobalScope, + default_value: f32, + min_value: f32, + max_value: f32) -> DomRoot<AudioParam> { + let audio_param = AudioParam::new_inherited(default_value, min_value, max_value); + reflect_dom_object(Box::new(audio_param), global, AudioParamBinding::Wrap) + } +} + +impl AudioParamMethods for AudioParam { + fn Value(&self) -> Finite<f32> { + Finite::wrap(self.value.get()) + } + + fn SetValue(&self, value: Finite<f32>) { + self.value.set(*value); + } + + fn DefaultValue(&self) -> Finite<f32> { + Finite::wrap(self.default_value) + } + + fn MinValue(&self) -> Finite<f32> { + Finite::wrap(self.min_value) + } + + fn MaxValue(&self) -> Finite<f32> { + Finite::wrap(self.max_value) + } +} |