- Revision
- 250100
- Author
- [email protected]
- Date
- 2019-09-19 12:19:37 -0700 (Thu, 19 Sep 2019)
Log Message
HTMLVideoElement with a broken poster image will take square dimension
https://bugs.webkit.org/show_bug.cgi?id=174122
<rdar://problem/33121806>
Patch by Peng Liu <[email protected]> on 2019-09-19
Reviewed by Daniel Bates.
Source/WebCore:
For a video element, if only the width attribute is given and the height attribute is missing,
an invalid poster image will make its aspect ratio to be 1, which is the historical WebKit behavior
if we're painting alt text and/or a broken image. This fix prevents that behavior to impact video elements.
We add a virtual function shouldDisplayBrokenImageIcon() to RenderImage and it will return true
only when the image source is given but cannot be downloaded. RenderMedia overrides this virtual function
and always return false because it never shows the broken image icon. RenderVideo inherits
that behavior from RenderMedia.
Then, in RenderImage::computeIntrinsicRatioInformation(), we only set the aspect ratio to 1
when we need to show the broken image icon. It is the historical WebKit behavior that we want to keep
for image element, but we also want to avoid its impact (this bug) on video elements.
We also replace the imageResource().errorOccurred() with shouldDisplayBrokenImageIcon() in
TreeBuilder::createLayoutBox() for the same reason.
The logic to display the broken image icon in RenderImage::renderReplaced() is also cleaned up.
Test: media/video-poster-not-found.html
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::createLayoutBox):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::shouldDisplayBrokenImageIcon const):
(WebCore::RenderImage::paintReplaced):
(WebCore::RenderImage::computeIntrinsicRatioInformation const):
* rendering/RenderImage.h:
* rendering/RenderMedia.h:
LayoutTests:
When only the width (no height) attribute of a video element is given
and the the poster image is missing (cannot be downloaded),
the aspect ratio of the video element should not be 1, which is the default behavior
of WebKit to paint a broken image. Instead, it should be the aspect ratio of the video content.
* media/video-poster-not-found-expected.txt: Added.
* media/video-poster-not-found.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (250099 => 250100)
--- trunk/LayoutTests/ChangeLog 2019-09-19 19:02:06 UTC (rev 250099)
+++ trunk/LayoutTests/ChangeLog 2019-09-19 19:19:37 UTC (rev 250100)
@@ -1,3 +1,19 @@
+2019-09-19 Peng Liu <[email protected]>
+
+ HTMLVideoElement with a broken poster image will take square dimension
+ https://bugs.webkit.org/show_bug.cgi?id=174122
+ <rdar://problem/33121806>
+
+ Reviewed by Daniel Bates.
+
+ When only the width (no height) attribute of a video element is given
+ and the the poster image is missing (cannot be downloaded),
+ the aspect ratio of the video element should not be 1, which is the default behavior
+ of WebKit to paint a broken image. Instead, it should be the aspect ratio of the video content.
+
+ * media/video-poster-not-found-expected.txt: Added.
+ * media/video-poster-not-found.html: Added.
+
2019-09-19 Miguel Gomez <[email protected]>
[WPE][GTK] Gardening after r250087
Added: trunk/LayoutTests/media/video-poster-not-found-expected.txt (0 => 250100)
--- trunk/LayoutTests/media/video-poster-not-found-expected.txt (rev 0)
+++ trunk/LayoutTests/media/video-poster-not-found-expected.txt 2019-09-19 19:19:37 UTC (rev 250100)
@@ -0,0 +1,9 @@
+
+Test <video> element with only width attribute and the poster is missing (cannot be downloaded).
+
+RUN(video.src = "" "content/test"))
+EVENT(canplaythrough)
+EXPECTED (video.clientWidth == '320') OK
+EXPECTED (video.clientHeight == '240') OK
+END OF TEST
+
Added: trunk/LayoutTests/media/video-poster-not-found.html (0 => 250100)
--- trunk/LayoutTests/media/video-poster-not-found.html (rev 0)
+++ trunk/LayoutTests/media/video-poster-not-found.html 2019-09-19 19:19:37 UTC (rev 250100)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>video-poster-not-found</title>
+ <script src=""
+ <script src=""
+
+ <script>
+ function go()
+ {
+ findMediaElement();
+ run('video.src = "" "content/test")');
+ waitForEventOnce('canplaythrough', canplaythrough);
+ }
+
+ function canplaythrough()
+ {
+ // When only the width attribute is given and the height attribute is missing,
+ // for an image element, if it cannot download the image (a broken url?),
+ // the historical WebKit behavior is to set the aspect ratio of the element to 1.
+ // However, for a video element, if the poster image cannot be downloaded,
+ // the aspect ratio of the element should not be hardcoded 1, instead, it must be decided by the video content.
+ testExpected("video.clientWidth", 320);
+ testExpected("video.clientHeight", 240);
+ endTest();
+ }
+ </script>
+ </head>
+
+ <body _onload_="go()">
+ <video width=320 poster="notfound.jpg"></video>
+ <p>Test <video> element with only width attribute and the poster is missing (cannot be downloaded).</p>
+ </body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (250099 => 250100)
--- trunk/Source/WebCore/ChangeLog 2019-09-19 19:02:06 UTC (rev 250099)
+++ trunk/Source/WebCore/ChangeLog 2019-09-19 19:19:37 UTC (rev 250100)
@@ -1,3 +1,40 @@
+2019-09-19 Peng Liu <[email protected]>
+
+ HTMLVideoElement with a broken poster image will take square dimension
+ https://bugs.webkit.org/show_bug.cgi?id=174122
+ <rdar://problem/33121806>
+
+ Reviewed by Daniel Bates.
+
+ For a video element, if only the width attribute is given and the height attribute is missing,
+ an invalid poster image will make its aspect ratio to be 1, which is the historical WebKit behavior
+ if we're painting alt text and/or a broken image. This fix prevents that behavior to impact video elements.
+
+ We add a virtual function shouldDisplayBrokenImageIcon() to RenderImage and it will return true
+ only when the image source is given but cannot be downloaded. RenderMedia overrides this virtual function
+ and always return false because it never shows the broken image icon. RenderVideo inherits
+ that behavior from RenderMedia.
+
+ Then, in RenderImage::computeIntrinsicRatioInformation(), we only set the aspect ratio to 1
+ when we need to show the broken image icon. It is the historical WebKit behavior that we want to keep
+ for image element, but we also want to avoid its impact (this bug) on video elements.
+
+ We also replace the imageResource().errorOccurred() with shouldDisplayBrokenImageIcon() in
+ TreeBuilder::createLayoutBox() for the same reason.
+
+ The logic to display the broken image icon in RenderImage::renderReplaced() is also cleaned up.
+
+ Test: media/video-poster-not-found.html
+
+ * layout/layouttree/LayoutTreeBuilder.cpp:
+ (WebCore::Layout::TreeBuilder::createLayoutBox):
+ * rendering/RenderImage.cpp:
+ (WebCore::RenderImage::shouldDisplayBrokenImageIcon const):
+ (WebCore::RenderImage::paintReplaced):
+ (WebCore::RenderImage::computeIntrinsicRatioInformation const):
+ * rendering/RenderImage.h:
+ * rendering/RenderMedia.h:
+
2019-09-19 Antti Koivisto <[email protected]>
Turn static DocumentRuleSets::s_isInvalidatingStyleWithRuleSets assertion bit into a member
Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (250099 => 250100)
--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2019-09-19 19:02:06 UTC (rev 250099)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2019-09-19 19:19:37 UTC (rev 250100)
@@ -142,7 +142,7 @@
childLayoutBox->replaced()->setIntrinsicSize(downcast<RenderReplaced>(renderer).intrinsicSize());
if (is<RenderImage>(renderer)) {
auto& imageRenderer = downcast<RenderImage>(renderer);
- if (imageRenderer.imageResource().errorOccurred())
+ if (imageRenderer.shouldDisplayBrokenImageIcon())
childLayoutBox->replaced()->setIntrinsicRatio(1);
}
} else {
Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (250099 => 250100)
--- trunk/Source/WebCore/rendering/RenderImage.cpp 2019-09-19 19:02:06 UTC (rev 250099)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp 2019-09-19 19:19:37 UTC (rev 250100)
@@ -390,6 +390,11 @@
return isShowingMissingOrImageError() && !m_altText.isEmpty();
}
+bool RenderImage::shouldDisplayBrokenImageIcon() const
+{
+ return imageResource().errorOccurred();
+}
+
bool RenderImage::hasNonBitmapImage() const
{
if (!imageResource().cachedImage())
@@ -431,7 +436,7 @@
float deviceScaleFactor = document().deviceScaleFactor();
LayoutUnit missingImageBorderWidth(1 / deviceScaleFactor);
- if (!imageResource().cachedImage() || imageResource().errorOccurred()) {
+ if (!imageResource().cachedImage() || shouldDisplayBrokenImageIcon()) {
if (paintInfo.phase == PaintPhase::Selection)
return;
@@ -449,17 +454,18 @@
bool errorPictureDrawn = false;
LayoutSize imageOffset;
// When calculating the usable dimensions, exclude the pixels of
- // the ouline rect so the error image/alt text doesn't draw on it.
+ // the outline rect so the error image/alt text doesn't draw on it.
LayoutSize usableSize = contentSize - LayoutSize(2 * missingImageBorderWidth, 2 * missingImageBorderWidth);
RefPtr<Image> image = imageResource().image();
- if (imageResource().errorOccurred() && !image->isNull() && usableSize.width() >= image->width() && usableSize.height() >= image->height()) {
+ if (shouldDisplayBrokenImageIcon() && !image->isNull() && usableSize.width() >= image->width() && usableSize.height() >= image->height()) {
// Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
std::pair<Image*, float> brokenImageAndImageScaleFactor = cachedImage()->brokenImage(deviceScaleFactor);
image = brokenImageAndImageScaleFactor.first;
FloatSize imageSize = image->size();
imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
+
// Center the error image, accounting for border and padding.
LayoutUnit centerX { (usableSize.width() - imageSize.width()) / 2 };
if (centerX < 0)
@@ -827,8 +833,9 @@
intrinsicSize.setHeight(box.availableLogicalHeight(IncludeMarginBorderPadding));
}
}
+
// Don't compute an intrinsic ratio to preserve historical WebKit behavior if we're painting alt text and/or a broken image.
- if (imageResource().errorOccurred()) {
+ if (shouldDisplayBrokenImageIcon()) {
intrinsicRatio = 1;
return;
}
Modified: trunk/Source/WebCore/rendering/RenderImage.h (250099 => 250100)
--- trunk/Source/WebCore/rendering/RenderImage.h 2019-09-19 19:02:06 UTC (rev 250099)
+++ trunk/Source/WebCore/rendering/RenderImage.h 2019-09-19 19:19:37 UTC (rev 250100)
@@ -74,6 +74,8 @@
bool isShowingMissingOrImageError() const;
bool isShowingAltText() const;
+ virtual bool shouldDisplayBrokenImageIcon() const;
+
bool hasNonBitmapImage() const;
bool isEditableImage() const;
Modified: trunk/Source/WebCore/rendering/RenderMedia.h (250099 => 250100)
--- trunk/Source/WebCore/rendering/RenderMedia.h 2019-09-19 19:02:06 UTC (rev 250099)
+++ trunk/Source/WebCore/rendering/RenderMedia.h 2019-09-19 19:19:37 UTC (rev 250100)
@@ -41,6 +41,8 @@
HTMLMediaElement& mediaElement() const { return downcast<HTMLMediaElement>(nodeForNonAnonymous()); }
+ bool shouldDisplayBrokenImageIcon() const final { return false; }
+
protected:
void layout() override;