[VNE layout] Move visually non-empty content reporting to RenderTreeBuilder
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2020 03:46:21 +0000 (03:46 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2020 03:46:21 +0000 (03:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208606
<rdar://problem/60056951>

Reviewed by Simon Fraser.

Move the VNE reporting logic from the c'tors to the RenderTreeBuilder.

* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::RenderEmbeddedObject):
* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::RenderHTMLCanvas):
* rendering/RenderText.cpp:
(WebCore::RenderText::RenderText):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::attach):
(WebCore::RenderTreeBuilder::attachInternal):
(WebCore::RenderTreeBuilder::attachIgnoringContinuation):
(WebCore::RenderTreeBuilder::reportVisuallyNonEmptyContent):
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::createRenderer):
(WebCore::RenderTreeUpdater::createTextRenderer):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257899 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderHTMLCanvas.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Source/WebCore/rendering/updating/RenderTreeBuilder.h
Source/WebCore/rendering/updating/RenderTreeUpdater.cpp

index 18ff5f3..78fd4e6 100644 (file)
@@ -1,3 +1,29 @@
+2020-03-04  Zalan Bujtas  <zalan@apple.com>
+
+        [VNE layout] Move visually non-empty content reporting to RenderTreeBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=208606
+        <rdar://problem/60056951>
+
+        Reviewed by Simon Fraser.
+
+        Move the VNE reporting logic from the c'tors to the RenderTreeBuilder.
+
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::RenderEmbeddedObject):
+        * rendering/RenderHTMLCanvas.cpp:
+        (WebCore::RenderHTMLCanvas::RenderHTMLCanvas):
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::RenderText):
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::attach):
+        (WebCore::RenderTreeBuilder::attachInternal):
+        (WebCore::RenderTreeBuilder::attachIgnoringContinuation):
+        (WebCore::RenderTreeBuilder::reportVisuallyNonEmptyContent):
+        * rendering/updating/RenderTreeBuilder.h:
+        * rendering/updating/RenderTreeUpdater.cpp:
+        (WebCore::RenderTreeUpdater::createRenderer):
+        (WebCore::RenderTreeUpdater::createTextRenderer):
+
 2020-03-04  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Add system trace points around display list replay
index 2d00dff..c6a9962 100644 (file)
@@ -104,8 +104,6 @@ RenderEmbeddedObject::RenderEmbeddedObject(HTMLFrameOwnerElement& element, Rende
     , m_unavailablePluginIndicatorIsPressed(false)
     , m_mouseDownWasInUnavailablePluginIndicator(false)
 {
-    // Actual size is not known yet, report the default intrinsic size.
-    view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
 }
 
 RenderEmbeddedObject::~RenderEmbeddedObject()
index 5a3086e..d192c73 100644 (file)
@@ -48,8 +48,6 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(RenderHTMLCanvas);
 RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement& element, RenderStyle&& style)
     : RenderReplaced(element, WTFMove(style), element.size())
 {
-    // Actual size is not known yet, report the default intrinsic size.
-    view().frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(intrinsicSize()));
 }
 
 HTMLCanvasElement& RenderHTMLCanvas::canvasElement() const
index 426eca4..b61bf6c 100644 (file)
@@ -195,16 +195,6 @@ inline RenderText::RenderText(Node& node, const String& text)
     ASSERT(!m_text.isNull());
     setIsText();
     m_canUseSimpleFontCodePath = computeCanUseSimpleFontCodePath();
-
-    // FIXME: Find out how to increment the visually non empty character count when the font becomes available.
-    auto isTextVisible = false;
-    if (auto* parentElement = node.parentElement()) {
-        auto* style = parentElement->renderer() ? &parentElement->renderer()->style() : nullptr;
-        isTextVisible = style && style->visibility() == Visibility::Visible && !style->fontCascade().isLoadingCustomFonts();
-    }
-
-    if (isTextVisible)
-        view().frameView().incrementVisuallyNonEmptyCharacterCount(text);
 }
 
 RenderText::RenderText(Text& textNode, const String& text)
index 8a5ffb4..5ec3c0c 100644 (file)
 #include "RenderButton.h"
 #include "RenderCounter.h"
 #include "RenderElement.h"
+#include "RenderEmbeddedObject.h"
 #include "RenderFullScreen.h"
 #include "RenderGrid.h"
+#include "RenderHTMLCanvas.h"
 #include "RenderLineBreak.h"
 #include "RenderMathMLFenced.h"
 #include "RenderMenuList.h"
 #include "RenderMultiColumnFlow.h"
 #include "RenderMultiColumnSpannerPlaceholder.h"
+#include "RenderReplaced.h"
 #include "RenderRuby.h"
 #include "RenderRubyBase.h"
 #include "RenderRubyRun.h"
@@ -191,6 +194,12 @@ void RenderTreeBuilder::destroy(RenderObject& renderer)
 
 void RenderTreeBuilder::attach(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
 {
+    reportVisuallyNonEmptyContent(parent, *child);
+    attachInternal(parent, WTFMove(child), beforeChild);
+}
+
+void RenderTreeBuilder::attachInternal(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
+{
     auto insertRecursiveIfNeeded = [&](RenderElement& parentCandidate) {
         if (&parent == &parentCandidate) {
             // Parents inside multicols can't call internal attach directly.
@@ -201,7 +210,7 @@ void RenderTreeBuilder::attach(RenderElement& parent, RenderPtr<RenderObject> ch
             attachToRenderElement(parent, WTFMove(child), beforeChild);
             return;
         }
-        attach(parentCandidate, WTFMove(child), beforeChild);
+        attachInternal(parentCandidate, WTFMove(child), beforeChild);
     };
 
     ASSERT(&parent.view() == &m_view);
@@ -342,7 +351,7 @@ void RenderTreeBuilder::attachIgnoringContinuation(RenderElement& parent, Render
         return;
     }
 
-    attach(parent, WTFMove(child), beforeChild);
+    attachInternal(parent, WTFMove(child), beforeChild);
 }
 
 RenderPtr<RenderObject> RenderTreeBuilder::detach(RenderElement& parent, RenderObject& child, CanCollapseAnonymousBlock canCollapseAnonymousBlock)
@@ -386,11 +395,6 @@ RenderPtr<RenderObject> RenderTreeBuilder::detach(RenderElement& parent, RenderO
     return detachFromRenderElement(parent, child);
 }
 
-void RenderTreeBuilder::attach(RenderTreePosition& position, RenderPtr<RenderObject> child)
-{
-    attach(position.parent(), WTFMove(child), position.nextSibling());
-}
-
 #if ENABLE(FULLSCREEN_API)
 void RenderTreeBuilder::createPlaceholderForFullScreen(RenderFullScreen& renderer, std::unique_ptr<RenderStyle> style, const LayoutRect& frameRect)
 {
@@ -913,4 +917,23 @@ void RenderTreeBuilder::attachToRenderGrid(RenderGrid& parent, RenderPtr<RenderO
     parent.dirtyGrid();
 }
 
+void RenderTreeBuilder::reportVisuallyNonEmptyContent(const RenderElement& parent, const RenderObject& child)
+{
+    if (is<RenderText>(child)) {
+        auto& style = parent.style();
+        // FIXME: Find out how to increment the visually non empty character count when the font becomes available.
+        if (style.visibility() == Visibility::Visible && !style.fontCascade().isLoadingCustomFonts()) {
+            auto& textRenderer = downcast<RenderText>(child);
+            m_view.frameView().incrementVisuallyNonEmptyCharacterCount(textRenderer.text());
+        }
+        return;
+    }
+    if (is<RenderHTMLCanvas>(child) || is<RenderEmbeddedObject>(child)) {
+        // Actual size is not known yet, report the default intrinsic size for replaced elements.
+        auto& replacedRenderer = downcast<RenderReplaced>(child);
+        m_view.frameView().incrementVisuallyNonEmptyPixelCount(roundedIntSize(replacedRenderer.intrinsicSize()));
+        return;
+    }
+}
+
 }
index ad8007d..2bf5929 100644 (file)
@@ -42,7 +42,6 @@ public:
     // FIXME: Remove.
     static RenderTreeBuilder* current() { return s_current; }
 
-    void attach(RenderTreePosition&, RenderPtr<RenderObject>);
     void attach(RenderElement& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr);
 
     enum class CanCollapseAnonymousBlock { No, Yes };
@@ -63,6 +62,8 @@ public:
 #endif
 
 private:
+    void attachInternal(RenderElement& parent, RenderPtr<RenderObject>, RenderObject* beforeChild);
+
     void childFlowStateChangesAndAffectsParentBlock(RenderElement& child);
     void childFlowStateChangesAndNoLongerAffectsParentBlock(RenderElement& child);
     void attachIgnoringContinuation(RenderElement& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr);
@@ -86,6 +87,8 @@ private:
     void makeChildrenNonInline(RenderBlock& parent, RenderObject* insertionPoint = nullptr);
     void removeAnonymousWrappersForInlineChildrenIfNeeded(RenderElement& parent);
 
+    void reportVisuallyNonEmptyContent(const RenderElement& parent, const RenderObject& child);
+
     class FirstLetter;
     class List;
     class MultiColumn;
index bcb7e6a..195491a 100644 (file)
@@ -400,7 +400,7 @@ void RenderTreeUpdater::createRenderer(Element& element, RenderStyle&& style)
     }
 #endif
 
-    m_builder.attach(insertionPosition, WTFMove(newRenderer));
+    m_builder.attach(insertionPosition.parent(), WTFMove(newRenderer), insertionPosition.nextSibling());
 
     auto* textManipulationController = m_document.textManipulationControllerIfExists();
     if (UNLIKELY(textManipulationController))
@@ -478,14 +478,14 @@ void RenderTreeUpdater::createTextRenderer(Text& textNode, const Style::TextUpda
         auto newDisplayContentsAnonymousWrapper = WebCore::createRenderer<RenderInline>(textNode.document(), RenderStyle::clone(**textUpdate->inheritedDisplayContentsStyle));
         newDisplayContentsAnonymousWrapper->initializeStyle();
         auto& displayContentsAnonymousWrapper = *newDisplayContentsAnonymousWrapper;
-        m_builder.attach(renderTreePosition, WTFMove(newDisplayContentsAnonymousWrapper));
+        m_builder.attach(renderTreePosition.parent(), WTFMove(newDisplayContentsAnonymousWrapper), renderTreePosition.nextSibling());
 
         textRenderer->setInlineWrapperForDisplayContents(&displayContentsAnonymousWrapper);
         m_builder.attach(displayContentsAnonymousWrapper, WTFMove(textRenderer));
         return;
     }
 
-    m_builder.attach(renderTreePosition, WTFMove(textRenderer));
+    m_builder.attach(renderTreePosition.parent(), WTFMove(textRenderer), renderTreePosition.nextSibling());
 }
 
 void RenderTreeUpdater::updateTextRenderer(Text& text, const Style::TextUpdate* textUpdate)