Skip to content

Commit

Permalink
Make aspect-ratio work on <video> properly.
Browse files Browse the repository at this point in the history
See w3c/csswg-drafts#7524 for discussion. This
matches what we do for images.

Differential Revision: https://phabricator.services.mozilla.com/D153664

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1783069
gecko-commit: 4a697ec6ca7ca5e5c69883a102797757e4752831
gecko-reviewers: boris, layout-reviewers
  • Loading branch information
emilio authored and moz-wptsync-bot committed Aug 3, 2022
1 parent f6d82a8 commit 4bd8e49
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,30 @@
video.setAttribute("height", "100");
video.src = getVideoURI('/media/2x2-green');
document.body.appendChild(video);
// Videos default to a size of 300x150px and calculate their aspect ratio
// based on that before the video is loaded. So this should be 2, ignoring
// the 2.5 that it would be based on the attributes.
assert_ratio(video, 2);
assert_ratio(video, 2.5);

video.onloadeddata = t.step_func_done(function() {
// When loaded this video is square.
assert_ratio(video, 1);
});
}, "aspect ratio for regular video");

// Same but with auto width.
t.step(function() {
video = document.createElement("video");
video.setAttribute("width", "250");
video.setAttribute("height", "100");
video.style.width = "auto";
video.src = getVideoURI('/media/2x2-green');
document.body.appendChild(video);
assert_ratio(video, 2.5);

video.onloadeddata = t.step_func_done(function() {
// When loaded this video is square.
assert_ratio(video, 1);
});
}, "aspect ratio for regular video with width: auto and height: auto");

test_computed_style("10", "20", "auto 10 / 20");
test_computed_style("0.5", "1.5", "auto 0.5 / 1.5");
test_computed_style("0", "1", "auto 0 / 1");
Expand Down

0 comments on commit 4bd8e49

Please sign in to comment.