Move RenderObject::isTransparentOrFullyClippedRespectingParentFrames() to RenderLayer
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Mar 2019 20:18:00 +0000 (20:18 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Mar 2019 20:18:00 +0000 (20:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195300

Reviewed by Simon Fraser.

Source/WebCore:

Move isTransparentOrFullyClippedRespectingParentFrames() from RenderObject to RenderLayer, since this function
asks questions about RenderLayers rather than their renderers. No change in behavior.

* rendering/RenderLayer.cpp:
(WebCore::enclosingFrameRenderLayer):
(WebCore::parentLayerCrossFrame):

Some static helpers currently in RenderObject that walk up the layer hierarchy through subframes are redundant
with static helpers in RenderLayer. Now that isTransparentOrFullyClippedRespectingParentFrames exists in
RenderLayer, simply use this existing helper instead and split logic to grab the enclosing layer around the
owner element of a frame into a separate helper.

* rendering/RenderLayer.h:
* rendering/RenderObject.cpp:
(WebCore::enclosingFrameRenderLayer): Deleted.
(WebCore::parentLayerCrossingFrameBoundaries): Deleted.
(WebCore::RenderObject::isTransparentOrFullyClippedRespectingParentFrames const): Deleted.

Moved from RenderObject.

* rendering/RenderObject.h:

Source/WebKit:

Refactor some logic to use isTransparentOrFullyClippedRespectingParentFrames on RenderLayer rather than
RenderObject; introduce a helper method to ask whether the enclosing layer of a renderer is transparent or
clipped.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::enclosingLayerIsTransparentOrFullyClipped):
(WebKit::WebPage::platformEditorState const):
(WebKit::WebPage::requestEvasionRectsAboveSelection):
(WebKit::WebPage::getFocusedElementInformation):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderLayer.h
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index 964e696..901211c 100644 (file)
@@ -1,3 +1,32 @@
+2019-03-06  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Move RenderObject::isTransparentOrFullyClippedRespectingParentFrames() to RenderLayer
+        https://bugs.webkit.org/show_bug.cgi?id=195300
+
+        Reviewed by Simon Fraser.
+
+        Move isTransparentOrFullyClippedRespectingParentFrames() from RenderObject to RenderLayer, since this function
+        asks questions about RenderLayers rather than their renderers. No change in behavior.
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::enclosingFrameRenderLayer):
+        (WebCore::parentLayerCrossFrame):
+
+        Some static helpers currently in RenderObject that walk up the layer hierarchy through subframes are redundant
+        with static helpers in RenderLayer. Now that isTransparentOrFullyClippedRespectingParentFrames exists in
+        RenderLayer, simply use this existing helper instead and split logic to grab the enclosing layer around the
+        owner element of a frame into a separate helper.
+
+        * rendering/RenderLayer.h:
+        * rendering/RenderObject.cpp:
+        (WebCore::enclosingFrameRenderLayer): Deleted.
+        (WebCore::parentLayerCrossingFrameBoundaries): Deleted.
+        (WebCore::RenderObject::isTransparentOrFullyClippedRespectingParentFrames const): Deleted.
+
+        Moved from RenderObject.
+
+        * rendering/RenderObject.h:
+
 2019-03-06  Sihui Liu  <sihui_liu@apple.com>
 
         Assertion Failed: m_databaseQueue.isKilled() in UniqueIDBDatabase::~UniqueIDBDatabase()
index a62564d..4d1811c 100644 (file)
@@ -1652,22 +1652,27 @@ RenderLayer* RenderLayer::enclosingAncestorForPosition(PositionType position) co
     return curr;
 }
 
-static RenderLayer* parentLayerCrossFrame(const RenderLayer& layer)
+static RenderLayer* enclosingFrameRenderLayer(const RenderLayer& layer)
 {
-    if (layer.parent())
-        return layer.parent();
-
-    HTMLFrameOwnerElement* ownerElement = layer.renderer().document().ownerElement();
+    auto* ownerElement = layer.renderer().document().ownerElement();
     if (!ownerElement)
         return nullptr;
 
-    RenderElement* ownerRenderer = ownerElement->renderer();
+    auto* ownerRenderer = ownerElement->renderer();
     if (!ownerRenderer)
         return nullptr;
 
     return ownerRenderer->enclosingLayer();
 }
 
+static RenderLayer* parentLayerCrossFrame(const RenderLayer& layer)
+{
+    if (auto* parent = layer.parent())
+        return parent;
+
+    return enclosingFrameRenderLayer(layer);
+}
+
 RenderLayer* RenderLayer::enclosingScrollableLayer() const
 {
     for (RenderLayer* nextLayer = parentLayerCrossFrame(*this); nextLayer; nextLayer = parentLayerCrossFrame(*nextLayer)) {
@@ -6594,6 +6599,25 @@ void RenderLayer::filterNeedsRepaint()
     renderer().repaint();
 }
 
+bool RenderLayer::isTransparentOrFullyClippedRespectingParentFrames() const
+{
+    static const double minimumVisibleOpacity = 0.01;
+
+    float currentOpacity = 1;
+    for (auto* layer = this; layer; layer = parentLayerCrossFrame(*layer)) {
+        currentOpacity *= layer->renderer().style().opacity();
+        if (currentOpacity < minimumVisibleOpacity)
+            return true;
+    }
+
+    for (auto* layer = this; layer; layer = enclosingFrameRenderLayer(*layer)) {
+        if (layer->selfClipRect().isEmpty())
+            return true;
+    }
+
+    return false;
+}
+
 TextStream& operator<<(TextStream& ts, const RenderLayer& layer)
 {
     ts << "RenderLayer " << &layer << " " << layer.size();
index 50a36f2..4580ce8 100644 (file)
@@ -857,6 +857,8 @@ public:
     void simulateFrequentPaint() { SinglePaintFrequencyTracking { m_paintFrequencyTracker }; }
     bool paintingFrequently() const { return m_paintFrequencyTracker.paintingFrequently(); }
 
+    WEBCORE_EXPORT bool isTransparentOrFullyClippedRespectingParentFrames() const;
+
 private:
 
     void setNextSibling(RenderLayer* next) { m_next = next; }
index 6f35d04..2f0b8ba 100644 (file)
@@ -1527,43 +1527,6 @@ void RenderObject::destroy()
     delete this;
 }
 
-static RenderLayer* enclosingFrameRenderLayer(RenderObject& renderObject)
-{
-    auto* owner = renderObject.frame().ownerElement();
-    if (!owner)
-        return nullptr;
-
-    auto* frameOwnerRenderer = owner->renderer();
-    return frameOwnerRenderer ? frameOwnerRenderer->enclosingLayer() : nullptr;
-}
-
-static RenderLayer* parentLayerCrossingFrameBoundaries(RenderLayer& layer)
-{
-    if (auto* parentLayer = layer.parent())
-        return parentLayer;
-
-    return enclosingFrameRenderLayer(layer.renderer());
-}
-
-bool RenderObject::isTransparentOrFullyClippedRespectingParentFrames() const
-{
-    static const double minimumVisibleOpacity = 0.01;
-
-    float currentOpacity = 1;
-    for (auto* layer = enclosingLayer(); layer; layer = parentLayerCrossingFrameBoundaries(*layer)) {
-        currentOpacity *= layer->renderer().style().opacity();
-        if (currentOpacity < minimumVisibleOpacity)
-            return true;
-    }
-
-    for (auto* layer = enclosingLayer(); layer; layer = enclosingFrameRenderLayer(layer->renderer())) {
-        if (layer->selfClipRect().isEmpty())
-            return true;
-    }
-
-    return false;
-}
-
 Position RenderObject::positionForPoint(const LayoutPoint& point)
 {
     // FIXME: This should just create a Position object instead (webkit.org/b/168566). 
index 87e8801..97626df 100644 (file)
@@ -798,8 +798,6 @@ public:
     void initializeFragmentedFlowStateOnInsertion();
     virtual void insertedIntoTree();
 
-    WEBCORE_EXPORT bool isTransparentOrFullyClippedRespectingParentFrames() const;
-
 protected:
     //////////////////////////////////////////
     // Helper functions. Dangerous to use!
index 9b1a6d1..88dfe43 100644 (file)
@@ -1,3 +1,20 @@
+2019-03-06  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Move RenderObject::isTransparentOrFullyClippedRespectingParentFrames() to RenderLayer
+        https://bugs.webkit.org/show_bug.cgi?id=195300
+
+        Reviewed by Simon Fraser.
+
+        Refactor some logic to use isTransparentOrFullyClippedRespectingParentFrames on RenderLayer rather than
+        RenderObject; introduce a helper method to ask whether the enclosing layer of a renderer is transparent or
+        clipped.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::enclosingLayerIsTransparentOrFullyClipped):
+        (WebKit::WebPage::platformEditorState const):
+        (WebKit::WebPage::requestEvasionRectsAboveSelection):
+        (WebKit::WebPage::getFocusedElementInformation):
+
 2019-03-06  Chris Dumez  <cdumez@apple.com>
 
         REGRESSION (r238490): YouTube.com: Returning PiP to Safari after sleeping device loses page
index 30ef5e1..166604c 100644 (file)
@@ -179,6 +179,12 @@ static void computeEditableRootHasContentAndPlainText(const VisibleSelection& se
     data.hasPlainText = data.hasContent && hasAnyPlainText(Range::create(root->document(), VisiblePosition { startInEditableRoot }, VisiblePosition { lastPositionInNode(root) }));
 }
 
+static bool enclosingLayerIsTransparentOrFullyClipped(const RenderObject& renderer)
+{
+    auto* enclosingLayer = renderer.enclosingLayer();
+    return enclosingLayer && enclosingLayer->isTransparentOrFullyClippedRespectingParentFrames();
+}
+
 void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePostLayoutDataHint shouldIncludePostLayoutData) const
 {
     if (frame.editor().hasComposition()) {
@@ -246,9 +252,10 @@ void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePost
     postLayoutData.insideFixedPosition = startNodeIsInsideFixedPosition || endNodeIsInsideFixedPosition;
     if (!selection.isNone()) {
         if (m_focusedElement && m_focusedElement->renderer()) {
-            postLayoutData.focusedElementRect = view->contentsToRootView(m_focusedElement->renderer()->absoluteBoundingBoxRect());
-            postLayoutData.caretColor = m_focusedElement->renderer()->style().caretColor();
-            postLayoutData.elementIsTransparentOrFullyClipped = m_focusedElement->renderer()->isTransparentOrFullyClippedRespectingParentFrames();
+            auto& renderer = *m_focusedElement->renderer();
+            postLayoutData.focusedElementRect = view->contentsToRootView(renderer.absoluteBoundingBoxRect());
+            postLayoutData.caretColor = renderer.style().caretColor();
+            postLayoutData.elementIsTransparentOrFullyClipped = enclosingLayerIsTransparentOrFullyClipped(renderer);
         }
         computeEditableRootHasContentAndPlainText(selection, postLayoutData);
     }
@@ -1523,7 +1530,7 @@ void WebPage::requestEvasionRectsAboveSelection(CompletionHandler<void(const Vec
         return;
     }
 
-    if (!m_focusedElement || !m_focusedElement->renderer() || m_focusedElement->renderer()->isTransparentOrFullyClippedRespectingParentFrames()) {
+    if (!m_focusedElement || !m_focusedElement->renderer() || enclosingLayerIsTransparentOrFullyClipped(*m_focusedElement->renderer())) {
         reply({ });
         return;
     }
@@ -2489,7 +2496,7 @@ void WebPage::getFocusedElementInformation(FocusedElementInformation& informatio
         auto& elementFrame = m_page->focusController().focusedOrMainFrame();
         information.elementRect = elementRectInRootViewCoordinates(*m_focusedElement, elementFrame);
         information.nodeFontSize = renderer->style().fontDescription().computedSize();
-        information.elementIsTransparentOrFullyClipped = renderer->isTransparentOrFullyClippedRespectingParentFrames();
+        information.elementIsTransparentOrFullyClipped = enclosingLayerIsTransparentOrFullyClipped(*renderer);
 
         bool inFixed = false;
         renderer->localToContainerPoint(FloatPoint(), nullptr, UseTransforms, &inFixed);