- Revision
- 260045
- Author
- [email protected]
- Date
- 2020-04-13 15:13:06 -0700 (Mon, 13 Apr 2020)
Log Message
Background images should figure into visually non empty heuristic
https://bugs.webkit.org/show_bug.cgi?id=208501
Reviewed by Simon Fraser.
This makes the visually non-empty heuristic treat background images the same
as it treats regular images. This is in line with first contentful paint spec in paint timing:
https://w3c.github.io/paint-timing/.
Note that the pixel count is computed based on the image size rather than the box size, as the box size might not be known at this time.
This is equivalent to the pixel reporting done for RenderImage.
Border-images and masks are excluded, as per the spec.
* rendering/RenderBox.cpp:
(WebCore::RenderBox::imageChanged):
Call incrementVisuallyNonEmptyPixelCountIfNeeded for background images
* rendering/RenderElement.cpp:
(WebCore::RenderElement::RenderElement):
* rendering/RenderBox.cpp:
(WebCore::RenderElement::incrementVisuallyNonEmptyPixelCountIfNeeded):
* rendering/RenderBox.h:
* rendering/RenderImage.cpp:
(WebCore::RenderImage::incrementVisuallyNonEmptyPixelCountIfNeeded): Deleted.
* rendering/RenderImage.h:
Moved incrementVisuallyNonEmptyPixelCountIfNeeded from RenderImage to RenderElement
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (260044 => 260045)
--- trunk/Source/WebCore/ChangeLog 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/ChangeLog 2020-04-13 22:13:06 UTC (rev 260045)
@@ -1,3 +1,33 @@
+2020-04-13 Noam Rosenthal <[email protected]>
+
+ Background images should figure into visually non empty heuristic
+ https://bugs.webkit.org/show_bug.cgi?id=208501
+
+ Reviewed by Simon Fraser.
+
+ This makes the visually non-empty heuristic treat background images the same
+ as it treats regular images. This is in line with first contentful paint spec in paint timing:
+ https://w3c.github.io/paint-timing/.
+
+ Note that the pixel count is computed based on the image size rather than the box size, as the box size might not be known at this time.
+ This is equivalent to the pixel reporting done for RenderImage.
+
+ Border-images and masks are excluded, as per the spec.
+
+ * rendering/RenderBox.cpp:
+ (WebCore::RenderBox::imageChanged):
+ Call incrementVisuallyNonEmptyPixelCountIfNeeded for background images
+
+ * rendering/RenderElement.cpp:
+ (WebCore::RenderElement::RenderElement):
+ * rendering/RenderBox.cpp:
+ (WebCore::RenderElement::incrementVisuallyNonEmptyPixelCountIfNeeded):
+ * rendering/RenderBox.h:
+ * rendering/RenderImage.cpp:
+ (WebCore::RenderImage::incrementVisuallyNonEmptyPixelCountIfNeeded): Deleted.
+ * rendering/RenderImage.h:
+ Moved incrementVisuallyNonEmptyPixelCountIfNeeded from RenderImage to RenderElement
+
2020-04-13 Yusuke Suzuki <[email protected]>
module's default cross-origin value should be "anonymous"
Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (260044 => 260045)
--- trunk/Source/WebCore/rendering/RenderBox.cpp 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp 2020-04-13 22:13:06 UTC (rev 260045)
@@ -1688,13 +1688,13 @@
paintFillLayerExtended(paintInfo, c, fillLayer, rect, bleedAvoidance, nullptr, LayoutSize(), op, backgroundObject, baseBgColorUsage);
}
-static bool layersUseImage(WrappedImagePtr image, const FillLayer& layers)
+static StyleImage* findLayerUsedImage(WrappedImagePtr image, const FillLayer& layers)
{
for (auto* layer = &layers; layer; layer = layer->next()) {
if (layer->image() && image == layer->image()->data())
- return true;
+ return layer->image();
}
- return false;
+ return nullptr;
}
void RenderBox::imageChanged(WrappedImagePtr image, const IntRect*)
@@ -1721,12 +1721,24 @@
if (!isComposited())
return;
- if (layer()->hasCompositedMask() && layersUseImage(image, style().maskLayers()))
+ if (layer()->hasCompositedMask() && findLayerUsedImage(image, style().maskLayers()))
layer()->contentChanged(MaskImageChanged);
- if (layersUseImage(image, style().backgroundLayers()))
+
+ if (auto* styleImage = findLayerUsedImage(image, style().backgroundLayers())) {
layer()->contentChanged(BackgroundImageChanged);
+ incrementVisuallyNonEmptyPixelCountIfNeeded(flooredIntSize(styleImage->imageSize(this, style().effectiveZoom())));
+ }
}
+void RenderBox::incrementVisuallyNonEmptyPixelCountIfNeeded(const IntSize& size)
+{
+ if (didContibuteToVisuallyNonEmptyPixelCount())
+ return;
+
+ view().frameView().incrementVisuallyNonEmptyPixelCount(size);
+ setDidContibuteToVisuallyNonEmptyPixelCount();
+}
+
bool RenderBox::repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer& layers, bool drawingBackground)
{
LayoutRect rendererRect;
Modified: trunk/Source/WebCore/rendering/RenderBox.h (260044 => 260045)
--- trunk/Source/WebCore/rendering/RenderBox.h 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/rendering/RenderBox.h 2020-04-13 22:13:06 UTC (rev 260045)
@@ -690,6 +690,8 @@
bool skipContainingBlockForPercentHeightCalculation(const RenderBox& containingBlock, bool isPerpendicularWritingMode) const;
+ void incrementVisuallyNonEmptyPixelCountIfNeeded(const IntSize&);
+
private:
bool replacedMinMaxLogicalHeightComputesAsNone(SizeType) const;
Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (260044 => 260045)
--- trunk/Source/WebCore/rendering/RenderElement.cpp 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp 2020-04-13 22:13:06 UTC (rev 260045)
@@ -118,6 +118,7 @@
, m_renderBlockFlowLineLayoutPath(RenderBlockFlow::UndeterminedPath)
, m_isRegisteredForVisibleInViewportCallback(false)
, m_visibleInViewportState(static_cast<unsigned>(VisibleInViewportState::Unknown))
+ , m_didContributeToVisuallyNonEmptyPixelCount(false)
, m_firstChild(nullptr)
, m_lastChild(nullptr)
, m_style(WTFMove(style))
Modified: trunk/Source/WebCore/rendering/RenderElement.h (260044 => 260045)
--- trunk/Source/WebCore/rendering/RenderElement.h 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/rendering/RenderElement.h 2020-04-13 22:13:06 UTC (rev 260045)
@@ -185,6 +185,9 @@
void setVisibleInViewportState(VisibleInViewportState);
virtual void visibleInViewportStateChanged();
+ bool didContibuteToVisuallyNonEmptyPixelCount() const { return m_didContributeToVisuallyNonEmptyPixelCount; }
+ void setDidContibuteToVisuallyNonEmptyPixelCount() { m_didContributeToVisuallyNonEmptyPixelCount = true; }
+
bool repaintForPausedImageAnimationsIfNeeded(const IntRect& visibleRect, CachedImage&);
bool hasPausedImageAnimations() const { return m_hasPausedImageAnimations; }
void setHasPausedImageAnimations(bool b) { m_hasPausedImageAnimations = b; }
@@ -353,6 +356,8 @@
unsigned m_isRegisteredForVisibleInViewportCallback : 1;
unsigned m_visibleInViewportState : 2;
+ unsigned m_didContributeToVisuallyNonEmptyPixelCount : 1;
+
RenderObject* m_firstChild;
RenderObject* m_lastChild;
Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (260044 => 260045)
--- trunk/Source/WebCore/rendering/RenderImage.cpp 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp 2020-04-13 22:13:06 UTC (rev 260045)
@@ -909,13 +909,4 @@
return nullptr;
}
-void RenderImage::incrementVisuallyNonEmptyPixelCountIfNeeded(const IntSize& size)
-{
- if (m_didIncrementVisuallyNonEmptyPixelCount)
- return;
-
- view().frameView().incrementVisuallyNonEmptyPixelCount(size);
- m_didIncrementVisuallyNonEmptyPixelCount = true;
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/RenderImage.h (260044 => 260045)
--- trunk/Source/WebCore/rendering/RenderImage.h 2020-04-13 22:07:16 UTC (rev 260044)
+++ trunk/Source/WebCore/rendering/RenderImage.h 2020-04-13 22:13:06 UTC (rev 260045)
@@ -102,8 +102,6 @@
imageChanged(imageResource().imagePtr());
}
- void incrementVisuallyNonEmptyPixelCountIfNeeded(const IntSize&);
-
private:
const char* renderName() const override { return "RenderImage"; }
@@ -147,7 +145,6 @@
String m_altText;
std::unique_ptr<RenderImageResource> m_imageResource;
bool m_needsToSetSizeForAltText { false };
- bool m_didIncrementVisuallyNonEmptyPixelCount { false };
bool m_isGeneratedContent { false };
bool m_hasShadowControls { false };
float m_imageDevicePixelRatio { 1 };