Move visibleInViewportStateChanged callback from Element to render tree
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Mar 2017 00:06:28 +0000 (00:06 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Mar 2017 00:06:28 +0000 (00:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170039

Reviewed by Zalan Bujtas.

Make it easier to use from the render tree.

Also for simplicity move the bits from RenderObject rare data to RenderElement.
There is plenty of space there.

* dom/Element.h:
(WebCore::Element::isVisibleInViewportChanged): Deleted.
* html/HTMLMediaElement.h:
* rendering/RenderElement.cpp:
(WebCore::RenderElement::RenderElement):
(WebCore::RenderElement::willBeDestroyed):
(WebCore::RenderElement::registerForVisibleInViewportCallback):
(WebCore::RenderElement::unregisterForVisibleInViewportCallback):
(WebCore::RenderElement::setVisibleInViewportState):
(WebCore::RenderElement::visibleInViewportStateChanged):
* rendering/RenderElement.h:
(WebCore::RenderElement::visibleInViewportState):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::setIsRegisteredForVisibleInViewportCallback): Deleted.
(WebCore::RenderObject::setVisibleInViewportState): Deleted.
* rendering/RenderObject.h:
(WebCore::RenderObject::hasOutlineAutoAncestor):
(WebCore::RenderObject::RenderObjectRareData::RenderObjectRareData):
(WebCore::RenderObject::isRegisteredForVisibleInViewportCallback): Deleted.
(WebCore::RenderObject::visibleInViewportState): Deleted.
* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::visibleInViewportStateChanged):
* rendering/RenderVideo.h:
* rendering/RenderView.cpp:
(WebCore::RenderView::updateVisibleViewportRect):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Element.h
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/RenderVideo.cpp
Source/WebCore/rendering/RenderVideo.h
Source/WebCore/rendering/RenderView.cpp

index 28a1159..a1f6430 100644 (file)
@@ -1,3 +1,41 @@
+2017-03-27  Antti Koivisto  <antti@apple.com>
+
+        Move visibleInViewportStateChanged callback from Element to render tree
+        https://bugs.webkit.org/show_bug.cgi?id=170039
+
+        Reviewed by Zalan Bujtas.
+
+        Make it easier to use from the render tree.
+
+        Also for simplicity move the bits from RenderObject rare data to RenderElement.
+        There is plenty of space there.
+
+        * dom/Element.h:
+        (WebCore::Element::isVisibleInViewportChanged): Deleted.
+        * html/HTMLMediaElement.h:
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::RenderElement):
+        (WebCore::RenderElement::willBeDestroyed):
+        (WebCore::RenderElement::registerForVisibleInViewportCallback):
+        (WebCore::RenderElement::unregisterForVisibleInViewportCallback):
+        (WebCore::RenderElement::setVisibleInViewportState):
+        (WebCore::RenderElement::visibleInViewportStateChanged):
+        * rendering/RenderElement.h:
+        (WebCore::RenderElement::visibleInViewportState):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::setIsRegisteredForVisibleInViewportCallback): Deleted.
+        (WebCore::RenderObject::setVisibleInViewportState): Deleted.
+        * rendering/RenderObject.h:
+        (WebCore::RenderObject::hasOutlineAutoAncestor):
+        (WebCore::RenderObject::RenderObjectRareData::RenderObjectRareData):
+        (WebCore::RenderObject::isRegisteredForVisibleInViewportCallback): Deleted.
+        (WebCore::RenderObject::visibleInViewportState): Deleted.
+        * rendering/RenderVideo.cpp:
+        (WebCore::RenderVideo::visibleInViewportStateChanged):
+        * rendering/RenderVideo.h:
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::updateVisibleViewportRect):
+
 2017-03-27  Youenn Fablet  <youenn@apple.com>
 
         addIceCandidate should not throw if passed null or undefined
index 0812339..4a26629 100644 (file)
@@ -550,8 +550,6 @@ public:
     bool hasDisplayContents() const;
     void setHasDisplayContents(bool);
 
-    virtual void isVisibleInViewportChanged() { }
-
     using ContainerNode::setAttributeEventListener;
     void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
 
index 1a3ea92..182bc66 100644 (file)
@@ -497,6 +497,8 @@ public:
 
     bool isTemporarilyAllowingInlinePlaybackAfterFullscreen() const {return m_temporarilyAllowingInlinePlaybackAfterFullscreen; }
 
+    void isVisibleInViewportChanged();
+
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
     virtual ~HTMLMediaElement();
@@ -813,7 +815,6 @@ private:
 #endif
 
     bool isVideoTooSmallForInlinePlayback();
-    void isVisibleInViewportChanged() final;
     void updateShouldAutoplay();
 
     void pauseAfterDetachedTask();
index 1e316b1..771b752 100644 (file)
@@ -114,6 +114,8 @@ inline RenderElement::RenderElement(ContainerNode& elementOrDocument, RenderStyl
     , m_renderBlockShouldForceRelayoutChildren(false)
     , m_renderBlockFlowHasMarkupTruncation(false)
     , m_renderBlockFlowLineLayoutPath(RenderBlockFlow::UndeterminedPath)
+    , m_isRegisteredForVisibleInViewportCallback(false)
+    , m_visibleInViewportState(VisibilityUnknown)
     , m_firstChild(nullptr)
     , m_lastChild(nullptr)
     , m_style(WTFMove(style))
@@ -1106,8 +1108,7 @@ void RenderElement::willBeDestroyed()
 
     destroyLeftoverChildren();
 
-    if (isRegisteredForVisibleInViewportCallback())
-        unregisterForVisibleInViewportCallback();
+    unregisterForVisibleInViewportCallback();
 
     if (hasCounterNodeMap())
         RenderCounter::destroyCounterNodes(*this);
@@ -1145,9 +1146,6 @@ void RenderElement::willBeDestroyed()
     }
     if (m_hasPausedImageAnimations)
         view().removeRendererWithPausedImageAnimations(*this);
-
-    if (isRegisteredForVisibleInViewportCallback())
-        view().unregisterForVisibleInViewportCallback(*this);
 }
 
 void RenderElement::setNeedsPositionedMovementLayout(const RenderStyle* oldStyle)
@@ -1467,30 +1465,33 @@ static bool shouldRepaintForImageAnimation(const RenderElement& renderer, const
 
 void RenderElement::registerForVisibleInViewportCallback()
 {
-    if (isRegisteredForVisibleInViewportCallback())
+    if (m_isRegisteredForVisibleInViewportCallback)
         return;
-    setIsRegisteredForVisibleInViewportCallback(true);
+    m_isRegisteredForVisibleInViewportCallback = true;
 
     view().registerForVisibleInViewportCallback(*this);
 }
 
 void RenderElement::unregisterForVisibleInViewportCallback()
 {
-    if (!isRegisteredForVisibleInViewportCallback())
+    if (!m_isRegisteredForVisibleInViewportCallback)
         return;
-    setIsRegisteredForVisibleInViewportCallback(false);
+    m_isRegisteredForVisibleInViewportCallback = false;
 
     view().unregisterForVisibleInViewportCallback(*this);
 }
 
-void RenderElement::visibleInViewportStateChanged(VisibleInViewportState state)
+void RenderElement::setVisibleInViewportState(VisibleInViewportState state)
 {
-    if (state == visibleInViewportState())
+    if (state == m_visibleInViewportState)
         return;
-    setVisibleInViewportState(state);
+    m_visibleInViewportState = state;
+    visibleInViewportStateChanged();
+}
 
-    if (element())
-        element()->isVisibleInViewportChanged();
+void RenderElement::visibleInViewportStateChanged()
+{
+    ASSERT_NOT_REACHED();
 }
 
 void RenderElement::newImageAnimationFrameAvailable(CachedImage& image)
index 74a2618..7448ac2 100644 (file)
@@ -185,7 +185,15 @@ public:
 
     void registerForVisibleInViewportCallback();
     void unregisterForVisibleInViewportCallback();
-    void visibleInViewportStateChanged(VisibleInViewportState);
+
+    enum VisibleInViewportState {
+        VisibilityUnknown,
+        VisibleInViewport,
+        NotVisibleInViewport,
+    };
+    VisibleInViewportState visibleInViewportState() const { return static_cast<VisibleInViewportState>(m_visibleInViewportState); }
+    void setVisibleInViewportState(VisibleInViewportState);
+    virtual void visibleInViewportStateChanged();
 
     bool repaintForPausedImageAnimationsIfNeeded(const IntRect& visibleRect);
     bool hasPausedImageAnimations() const { return m_hasPausedImageAnimations; }
@@ -337,6 +345,9 @@ private:
     unsigned m_renderBlockFlowHasMarkupTruncation : 1;
     unsigned m_renderBlockFlowLineLayoutPath : 2;
 
+    unsigned m_isRegisteredForVisibleInViewportCallback : 1;
+    unsigned m_visibleInViewportState : 2;
+
     RenderObject* m_firstChild;
     RenderObject* m_lastChild;
 
index 8aa4d2a..1169d92 100644 (file)
@@ -1985,18 +1985,6 @@ void RenderObject::setHasOutlineAutoAncestor(bool hasOutlineAutoAncestor)
         ensureRareData().setHasOutlineAutoAncestor(hasOutlineAutoAncestor);
 }
 
-void RenderObject::setIsRegisteredForVisibleInViewportCallback(bool registered)
-{
-    if (registered || hasRareData())
-        ensureRareData().setIsRegisteredForVisibleInViewportCallback(registered);
-}
-
-void RenderObject::setVisibleInViewportState(VisibleInViewportState visible)
-{
-    if (visible != VisibilityUnknown || hasRareData())
-        ensureRareData().setVisibleInViewportState(visible);
-}
-
 RenderObject::RareDataMap& RenderObject::rareDataMap()
 {
     static NeverDestroyed<RareDataMap> map;
index d296426..f126dad 100644 (file)
@@ -446,19 +446,11 @@ public:
     bool hasReflection() const { return m_bitfields.hasRareData() && rareData().hasReflection(); }
     bool isRenderFlowThread() const { return m_bitfields.hasRareData() && rareData().isRenderFlowThread(); }
     bool hasOutlineAutoAncestor() const { return m_bitfields.hasRareData() && rareData().hasOutlineAutoAncestor(); }
-    bool isRegisteredForVisibleInViewportCallback() { return m_bitfields.hasRareData() && rareData().isRegisteredForVisibleInViewportCallback(); }
 
     bool isExcludedFromNormalLayout() const { return m_bitfields.isExcludedFromNormalLayout(); }
     void setIsExcludedFromNormalLayout(bool excluded) { m_bitfields.setIsExcludedFromNormalLayout(excluded); }
     bool isExcludedAndPlacedInBorder() const { return isExcludedFromNormalLayout() && isLegend(); }
 
-    enum VisibleInViewportState {
-        VisibilityUnknown,
-        VisibleInViewport,
-        NotVisibleInViewport,
-    };
-    VisibleInViewportState visibleInViewportState() { return m_bitfields.hasRareData() ? rareData().visibleInViewportState() : VisibilityUnknown; }
-
     bool hasLayer() const { return m_bitfields.hasLayer(); }
 
     enum BoxDecorationState {
@@ -567,8 +559,6 @@ public:
     void setHasReflection(bool = true);
     void setIsRenderFlowThread(bool = true);
     void setHasOutlineAutoAncestor(bool = true);
-    void setIsRegisteredForVisibleInViewportCallback(bool);
-    void setVisibleInViewportState(VisibleInViewportState);
 
     // Hook so that RenderTextControl can return the line height of its inner renderer.
     // For other renderers, the value is the same as lineHeight(false).
@@ -982,8 +972,6 @@ private:
             , m_hasReflection(false)
             , m_isRenderFlowThread(false)
             , m_hasOutlineAutoAncestor(false)
-            , m_isRegisteredForVisibleInViewportCallback(false)
-            , m_visibleInViewportState(VisibilityUnknown)
         {
         }
         ADD_BOOLEAN_BITFIELD(isDragging, IsDragging);
@@ -992,8 +980,6 @@ private:
         ADD_BOOLEAN_BITFIELD(hasOutlineAutoAncestor, HasOutlineAutoAncestor);
 
         // From RenderElement
-        ADD_BOOLEAN_BITFIELD(isRegisteredForVisibleInViewportCallback, IsRegisteredForVisibleInViewportCallback);
-        ADD_ENUM_BITFIELD(visibleInViewportState, VisibleInViewportState, VisibleInViewportState, 2);
         std::unique_ptr<RenderStyle> cachedFirstLineStyle;
     };
     
index 07a5c38..ede6d9b 100644 (file)
@@ -67,6 +67,11 @@ void RenderVideo::willBeDestroyed()
     RenderMedia::willBeDestroyed();
 }
 
+void RenderVideo::visibleInViewportStateChanged()
+{
+    videoElement().isVisibleInViewportChanged();
+}
+
 IntSize RenderVideo::defaultSize()
 {
     // These values are specified in the spec.
index f82e79d..50e907c 100644 (file)
@@ -71,6 +71,8 @@ private:
 
     void layout() final;
 
+    void visibleInViewportStateChanged() final;
+
     LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const final;
     LayoutUnit minimumReplacedHeight() const final;
 
index 5846b65..ae7c6a5 100644 (file)
@@ -1389,8 +1389,10 @@ void RenderView::updateVisibleViewportRect(const IntRect& visibleRect)
 {
     resumePausedImageAnimationsIfNeeded(visibleRect);
 
-    for (auto* renderer : m_visibleInViewportRenderers)
-        renderer->visibleInViewportStateChanged(visibleRect.intersects(enclosingIntRect(renderer->absoluteClippedOverflowRect())) ? RenderElement::VisibleInViewport : RenderElement::NotVisibleInViewport);
+    for (auto* renderer : m_visibleInViewportRenderers) {
+        auto state = visibleRect.intersects(enclosingIntRect(renderer->absoluteClippedOverflowRect())) ? RenderElement::VisibleInViewport : RenderElement::NotVisibleInViewport;
+        renderer->setVisibleInViewportState(state);
+    }
 }
 
 void RenderView::addRendererWithPausedImageAnimations(RenderElement& renderer)