Auto merge of #22052 - ferjm:durationchange.resize.event.once, r=ceyusa

HTMLMediaElement - fire durationchange and resize iff something changes

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- 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/22052)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-10-30 12:45:45 -04:00 committed by GitHub
commit 7a715519a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View file

@ -1122,21 +1122,29 @@ impl HTMLMediaElement {
self.playback_position.set(0.);
// Step 4.
let previous_duration = self.duration.get();
if let Some(duration) = metadata.duration {
self.duration.set(duration.as_secs() as f64);
} else {
self.duration.set(f64::INFINITY);
}
let window = window_from_node(self);
let task_source = window.dom_manipulation_task_source();
task_source.queue_simple_event(self.upcast(), atom!("durationchange"), &window);
if previous_duration != self.duration.get() {
let window = window_from_node(self);
let task_source = window.dom_manipulation_task_source();
task_source.queue_simple_event(self.upcast(), atom!("durationchange"), &window);
}
// Step 5.
if self.is::<HTMLVideoElement>() {
let video_elem = self.downcast::<HTMLVideoElement>().unwrap();
video_elem.set_video_width(metadata.width);
video_elem.set_video_height(metadata.height);
task_source.queue_simple_event(self.upcast(), atom!("resize"), &window);
if video_elem.get_video_width() != metadata.width ||
video_elem.get_video_height() != metadata.height {
video_elem.set_video_width(metadata.width);
video_elem.set_video_height(metadata.height);
let window = window_from_node(self);
let task_source = window.dom_manipulation_task_source();
task_source.queue_simple_event(self.upcast(), atom!("resize"), &window);
}
}
// Step 6.

View file

@ -49,10 +49,18 @@ impl HTMLVideoElement {
)
}
pub fn get_video_width(&self) -> u32 {
self.video_width.get()
}
pub fn set_video_width(&self, width: u32) {
self.video_width.set(width);
}
pub fn get_video_height(&self) -> u32 {
self.video_height.get()
}
pub fn set_video_height(&self, height: u32) {
self.video_height.set(height);
}