Auto merge of #25923 - iulianR:issue-22312, r=jdm

Add VTTRegion and part of VTTCue DOM interfaces

<!-- Please describe your changes on the following line: -->
Hello! In this PR I implemented the VTTRegion DOM interface and part of VTTCue (#22312). Before continuing I thought it's maybe a good idea to first request a review or even merge what I did up to this point, as I might get stuck on the next part. I have a slight idea of what needs to be done (I assume it's hooking the GStreamer parser somewhere in `GetCueAsHTML()`), but a short outline or some more instructions would help a lot.

I updated test expectations by first running:
```
./mach test-wpt tests/wpt/web-platform-tests/webvtt/api --log-raw servo.log --pref dom.webvtt.enabled=true
```
then
```
./mach update-wpt servo.log
```
Thanks!
---
<!-- 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
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- 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. -->
This commit is contained in:
bors-servo 2020-03-09 17:33:15 -04:00 committed by GitHub
commit 95f3d46644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
299 changed files with 1500 additions and 8 deletions

View file

@ -538,6 +538,8 @@ pub mod vrfieldofview;
pub mod vrframedata;
pub mod vrpose;
pub mod vrstageparameters;
pub mod vttcue;
pub mod vttregion;
pub mod webgl_extensions;
pub use self::webgl_extensions::ext::*;
pub mod webgl2renderingcontext;

View file

@ -25,24 +25,32 @@ pub struct TextTrackCue {
}
impl TextTrackCue {
// FIXME(#22314, dlrobertson) implement VTTCue.
#[allow(dead_code)]
pub fn new_inherited(id: DOMString, track: Option<&TextTrack>) -> TextTrackCue {
pub fn new_inherited(
id: DOMString,
start_time: f64,
end_time: f64,
track: Option<&TextTrack>,
) -> TextTrackCue {
TextTrackCue {
eventtarget: EventTarget::new_inherited(),
id: DomRefCell::new(id),
track: track.map(Dom::from_ref),
start_time: Cell::new(0.),
end_time: Cell::new(0.),
start_time: Cell::new(start_time),
end_time: Cell::new(end_time),
pause_on_exit: Cell::new(false),
}
}
// FIXME(#22314, dlrobertson) implement VTTCue.
#[allow(dead_code)]
pub fn new(window: &Window, id: DOMString, track: Option<&TextTrack>) -> DomRoot<TextTrackCue> {
pub fn new(
window: &Window,
id: DOMString,
start_time: f64,
end_time: f64,
track: Option<&TextTrack>,
) -> DomRoot<TextTrackCue> {
reflect_dom_object(
Box::new(TextTrackCue::new_inherited(id, track)),
Box::new(TextTrackCue::new_inherited(id, start_time, end_time, track)),
window,
TextTrackCueBinding::Wrap,
)

View file

@ -0,0 +1,232 @@
/* 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 https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::VTTCueBinding::{
self, AlignSetting, AutoKeyword, DirectionSetting, LineAlignSetting, PositionAlignSetting,
VTTCueMethods,
};
use crate::dom::bindings::error::{Error, ErrorResult};
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::documentfragment::DocumentFragment;
use crate::dom::globalscope::GlobalScope;
use crate::dom::texttrackcue::TextTrackCue;
use crate::dom::vttregion::VTTRegion;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use std::cell::Cell;
#[dom_struct]
pub struct VTTCue {
texttrackcue: TextTrackCue,
region: DomRefCell<Option<Dom<VTTRegion>>>,
vertical: Cell<DirectionSetting>,
snap_to_lines: Cell<bool>,
line: DomRefCell<LineAndPositionSetting>,
line_align: Cell<LineAlignSetting>,
position: DomRefCell<LineAndPositionSetting>,
position_align: Cell<PositionAlignSetting>,
size: Cell<f64>,
align: Cell<AlignSetting>,
text: DomRefCell<DOMString>,
}
impl VTTCue {
pub fn new_inherited(start_time: f64, end_time: f64, text: DOMString) -> Self {
VTTCue {
texttrackcue: TextTrackCue::new_inherited(
DOMString::default(),
start_time,
end_time,
None,
),
region: DomRefCell::new(None),
vertical: Cell::new(DirectionSetting::default()),
snap_to_lines: Cell::new(true),
line: DomRefCell::new(LineAndPositionSetting::Auto),
line_align: Cell::new(LineAlignSetting::Start),
position: DomRefCell::new(LineAndPositionSetting::Auto),
position_align: Cell::new(PositionAlignSetting::Auto),
size: Cell::new(100_f64),
align: Cell::new(AlignSetting::Center),
text: DomRefCell::new(text),
}
}
pub fn new(
global: &GlobalScope,
start_time: f64,
end_time: f64,
text: DOMString,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(Self::new_inherited(start_time, end_time, text)),
global,
VTTCueBinding::Wrap,
)
}
#[allow(non_snake_case)]
pub fn Constructor(
window: &Window,
start_time: Finite<f64>,
end_time: Finite<f64>,
text: DOMString,
) -> DomRoot<Self> {
VTTCue::new(&window.global(), *start_time, *end_time, text)
}
}
impl VTTCueMethods for VTTCue {
// https://w3c.github.io/webvtt/#dom-vttcue-region
fn GetRegion(&self) -> Option<DomRoot<VTTRegion>> {
self.region
.borrow()
.as_ref()
.map(|r| DomRoot::from_ref(&**r))
}
// https://w3c.github.io/webvtt/#dom-vttcue-region
fn SetRegion(&self, value: Option<&VTTRegion>) {
*self.region.borrow_mut() = value.map(|r| Dom::from_ref(r))
}
// https://w3c.github.io/webvtt/#dom-vttcue-vertical
fn Vertical(&self) -> DirectionSetting {
self.vertical.get()
}
// https://w3c.github.io/webvtt/#dom-vttcue-vertical
fn SetVertical(&self, value: DirectionSetting) {
self.vertical.set(value);
}
// https://w3c.github.io/webvtt/#dom-vttcue-snaptolines
fn SnapToLines(&self) -> bool {
self.snap_to_lines.get()
}
// https://w3c.github.io/webvtt/#dom-vttcue-snaptolines
fn SetSnapToLines(&self, value: bool) {
self.snap_to_lines.set(value)
}
// https://w3c.github.io/webvtt/#dom-vttcue-line
fn Line(&self) -> VTTCueBinding::LineAndPositionSetting {
VTTCueBinding::LineAndPositionSetting::from(self.line.borrow().clone())
}
// https://w3c.github.io/webvtt/#dom-vttcue-line
fn SetLine(&self, value: VTTCueBinding::LineAndPositionSetting) {
*self.line.borrow_mut() = value.into();
}
// https://w3c.github.io/webvtt/#dom-vttcue-linealign
fn LineAlign(&self) -> LineAlignSetting {
self.line_align.get()
}
// https://w3c.github.io/webvtt/#dom-vttcue-linealign
fn SetLineAlign(&self, value: LineAlignSetting) {
self.line_align.set(value);
}
// https://w3c.github.io/webvtt/#dom-vttcue-position
fn Position(&self) -> VTTCueBinding::LineAndPositionSetting {
VTTCueBinding::LineAndPositionSetting::from(self.position.borrow().clone())
}
// https://w3c.github.io/webvtt/#dom-vttcue-position
fn SetPosition(&self, value: VTTCueBinding::LineAndPositionSetting) -> ErrorResult {
if let VTTCueBinding::LineAndPositionSetting::Double(x) = value {
if *x < 0_f64 || *x > 100_f64 {
return Err(Error::IndexSize);
}
}
*self.position.borrow_mut() = value.into();
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttcue-positionalign
fn PositionAlign(&self) -> PositionAlignSetting {
self.position_align.get()
}
// https://w3c.github.io/webvtt/#dom-vttcue-positionalign
fn SetPositionAlign(&self, value: PositionAlignSetting) {
self.position_align.set(value);
}
// https://w3c.github.io/webvtt/#dom-vttcue-size
fn Size(&self) -> Finite<f64> {
Finite::wrap(self.size.get())
}
// https://w3c.github.io/webvtt/#dom-vttcue-size
fn SetSize(&self, value: Finite<f64>) -> ErrorResult {
if *value < 0_f64 || *value > 100_f64 {
return Err(Error::IndexSize);
}
self.size.set(*value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttcue-align
fn Align(&self) -> AlignSetting {
self.align.get()
}
// https://w3c.github.io/webvtt/#dom-vttcue-align
fn SetAlign(&self, value: AlignSetting) {
self.align.set(value);
}
// https://w3c.github.io/webvtt/#dom-vttcue-text
fn Text(&self) -> DOMString {
self.text.borrow().clone()
}
// https://w3c.github.io/webvtt/#dom-vttcue-text
fn SetText(&self, value: DOMString) {
*self.text.borrow_mut() = value;
}
// https://w3c.github.io/webvtt/#dom-vttcue-getcueashtml
fn GetCueAsHTML(&self) -> DomRoot<DocumentFragment> {
todo!()
}
}
#[derive(Clone, JSTraceable, MallocSizeOf)]
enum LineAndPositionSetting {
Double(f64),
Auto,
}
impl From<VTTCueBinding::LineAndPositionSetting> for LineAndPositionSetting {
fn from(value: VTTCueBinding::LineAndPositionSetting) -> Self {
match value {
VTTCueBinding::LineAndPositionSetting::Double(x) => LineAndPositionSetting::Double(*x),
VTTCueBinding::LineAndPositionSetting::AutoKeyword(_) => LineAndPositionSetting::Auto,
}
}
}
impl From<LineAndPositionSetting> for VTTCueBinding::LineAndPositionSetting {
fn from(value: LineAndPositionSetting) -> Self {
match value {
LineAndPositionSetting::Double(x) => {
VTTCueBinding::LineAndPositionSetting::Double(Finite::wrap(x))
},
LineAndPositionSetting::Auto => {
VTTCueBinding::LineAndPositionSetting::AutoKeyword(AutoKeyword::Auto)
},
}
}
}

View file

@ -0,0 +1,167 @@
/* 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 https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::VTTRegionBinding::{
self, ScrollSetting, VTTRegionMethods,
};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use std::cell::Cell;
#[dom_struct]
pub struct VTTRegion {
reflector_: Reflector,
id: DomRefCell<DOMString>,
width: Cell<f64>,
lines: Cell<u32>,
region_anchor_x: Cell<f64>,
region_anchor_y: Cell<f64>,
viewport_anchor_x: Cell<f64>,
viewport_anchor_y: Cell<f64>,
scroll: Cell<ScrollSetting>,
}
impl VTTRegion {
pub fn new_inherited() -> Self {
VTTRegion {
reflector_: Reflector::new(),
id: DomRefCell::new(DOMString::default()),
width: Cell::new(100_f64),
lines: Cell::new(3),
region_anchor_x: Cell::new(0_f64),
region_anchor_y: Cell::new(100_f64),
viewport_anchor_x: Cell::new(0_f64),
viewport_anchor_y: Cell::new(100_f64),
scroll: Cell::new(Default::default()),
}
}
pub fn new(global: &GlobalScope) -> DomRoot<Self> {
reflect_dom_object(
Box::new(Self::new_inherited()),
global,
VTTRegionBinding::Wrap,
)
}
#[allow(non_snake_case)]
pub fn Constructor(window: &Window) -> Fallible<DomRoot<Self>> {
Ok(VTTRegion::new(&window.global()))
}
}
impl VTTRegionMethods for VTTRegion {
// https://w3c.github.io/webvtt/#dom-vttregion-id
fn Id(&self) -> DOMString {
self.id.borrow().clone()
}
// https://w3c.github.io/webvtt/#dom-vttregion-id
fn SetId(&self, value: DOMString) {
*self.id.borrow_mut() = value;
}
// https://w3c.github.io/webvtt/#dom-vttregion-width
fn Width(&self) -> Finite<f64> {
Finite::wrap(self.width.get())
}
// https://w3c.github.io/webvtt/#dom-vttregion-width
fn SetWidth(&self, value: Finite<f64>) -> ErrorResult {
if *value < 0_f64 || *value > 100_f64 {
return Err(Error::IndexSize);
}
self.width.set(*value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttregion-lines
fn Lines(&self) -> u32 {
self.lines.get()
}
// https://w3c.github.io/webvtt/#dom-vttregion-lines
fn SetLines(&self, value: u32) -> ErrorResult {
self.lines.set(value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttregion-regionanchorx
fn RegionAnchorX(&self) -> Finite<f64> {
Finite::wrap(self.region_anchor_x.get())
}
// https://w3c.github.io/webvtt/#dom-vttregion-regionanchorx
fn SetRegionAnchorX(&self, value: Finite<f64>) -> ErrorResult {
if *value < 0_f64 || *value > 100_f64 {
return Err(Error::IndexSize);
}
self.region_anchor_x.set(*value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttregion-regionanchory
fn RegionAnchorY(&self) -> Finite<f64> {
Finite::wrap(self.region_anchor_y.get())
}
// https://w3c.github.io/webvtt/#dom-vttregion-regionanchory
fn SetRegionAnchorY(&self, value: Finite<f64>) -> ErrorResult {
if *value < 0_f64 || *value > 100_f64 {
return Err(Error::IndexSize);
}
self.region_anchor_y.set(*value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttregion-viewportanchorx
fn ViewportAnchorX(&self) -> Finite<f64> {
Finite::wrap(self.viewport_anchor_x.get())
}
// https://w3c.github.io/webvtt/#dom-vttregion-viewportanchorx
fn SetViewportAnchorX(&self, value: Finite<f64>) -> ErrorResult {
if *value < 0_f64 || *value > 100_f64 {
return Err(Error::IndexSize);
}
self.viewport_anchor_x.set(*value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttregion-viewportanchory
fn ViewportAnchorY(&self) -> Finite<f64> {
Finite::wrap(self.viewport_anchor_y.get())
}
// https://w3c.github.io/webvtt/#dom-vttregion-viewportanchory
fn SetViewportAnchorY(&self, value: Finite<f64>) -> ErrorResult {
if *value < 0_f64 || *value > 100_f64 {
return Err(Error::IndexSize);
}
self.viewport_anchor_y.set(*value);
Ok(())
}
// https://w3c.github.io/webvtt/#dom-vttregion-scroll
fn Scroll(&self) -> ScrollSetting {
self.scroll.get()
}
// https://w3c.github.io/webvtt/#dom-vttregion-scroll
fn SetScroll(&self, value: ScrollSetting) {
self.scroll.set(value);
}
}

View file

@ -0,0 +1,30 @@
/* 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 https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/webvtt/#the-vttcue-interface
enum AutoKeyword { "auto"};
typedef (double or AutoKeyword) LineAndPositionSetting;
enum DirectionSetting { "" /* horizontal */, "rl", "lr" };
enum LineAlignSetting { "start", "center", "end" };
enum PositionAlignSetting { "line-left", "center", "line-right", "auto" };
enum AlignSetting { "start", "center", "end", "left", "right" };
[Pref="dom.webvtt.enabled", Exposed=Window]
interface VTTCue : TextTrackCue {
constructor(double startTime, double endTime, DOMString text);
attribute VTTRegion? region;
attribute DirectionSetting vertical;
attribute boolean snapToLines;
attribute LineAndPositionSetting line;
attribute LineAlignSetting lineAlign;
[SetterThrows]
attribute LineAndPositionSetting position;
attribute PositionAlignSetting positionAlign;
[SetterThrows]
attribute double size;
attribute AlignSetting align;
attribute DOMString text;
DocumentFragment getCueAsHTML();
};

View file

@ -0,0 +1,26 @@
/* 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 https://mozilla.org/MPL/2.0/. */
// https://w3c.github.io/webvtt/#the-vttregion-interface
enum ScrollSetting { "" /* none */, "up"};
[Pref="dom.webvtt.enabled", Exposed=Window]
interface VTTRegion {
[Throws] constructor();
attribute DOMString id;
[SetterThrows]
attribute double width;
[SetterThrows]
attribute unsigned long lines;
[SetterThrows]
attribute double regionAnchorX;
[SetterThrows]
attribute double regionAnchorY;
[SetterThrows]
attribute double viewportAnchorX;
[SetterThrows]
attribute double viewportAnchorY;
attribute ScrollSetting scroll;
};