Title: [200953] trunk/Source/WebCore
Revision
200953
Author
[email protected]
Date
2016-05-16 11:44:02 -0700 (Mon, 16 May 2016)

Log Message

containingBlockFor*Position functions should take the renderer instead of the parent.
https://bugs.webkit.org/show_bug.cgi?id=157659

Reviewed by Simon Fraser.

containingBlockForFixedPosition, containingBlockForAbsolutePosition and containingBlockForObjectInFlow functions
expect the renderer's parent to be passed in (unless it is a RenderInline!). It is rather misleading and highly error-prone.
We should call them with the renderer itself instead.

* dom/Element.cpp:
(WebCore::layoutOverflowRectContainsAllDescendants): This expects ancestor containing block.
* rendering/LogicalSelectionOffsetCaches.h:
(WebCore::LogicalSelectionOffsetCaches::LogicalSelectionOffsetCaches):
* rendering/RenderElement.cpp:
(WebCore::containingBlockForFixedPosition):
(WebCore::containingBlockForAbsolutePosition):
(WebCore::containingBlockForObjectInFlow):
* rendering/RenderElement.h:
* rendering/RenderInline.cpp:
(WebCore::RenderInline::styleWillChange):
* rendering/RenderLineBreak.cpp:
(WebCore::RenderLineBreak::collectSelectionRects): Not a behaviour change.
* rendering/RenderObject.cpp:
(WebCore::RenderObject::containingBlock): RenderScrollbarPart renderer now returns
the containing block based on its owning renderer's style.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (200952 => 200953)


--- trunk/Source/WebCore/ChangeLog	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/ChangeLog	2016-05-16 18:44:02 UTC (rev 200953)
@@ -1,3 +1,31 @@
+2016-05-16  Zalan Bujtas  <[email protected]>
+
+        containingBlockFor*Position functions should take the renderer instead of the parent.
+        https://bugs.webkit.org/show_bug.cgi?id=157659
+
+        Reviewed by Simon Fraser.
+
+        containingBlockForFixedPosition, containingBlockForAbsolutePosition and containingBlockForObjectInFlow functions
+        expect the renderer's parent to be passed in (unless it is a RenderInline!). It is rather misleading and highly error-prone.
+        We should call them with the renderer itself instead.
+
+        * dom/Element.cpp:
+        (WebCore::layoutOverflowRectContainsAllDescendants): This expects ancestor containing block.
+        * rendering/LogicalSelectionOffsetCaches.h:
+        (WebCore::LogicalSelectionOffsetCaches::LogicalSelectionOffsetCaches):
+        * rendering/RenderElement.cpp:
+        (WebCore::containingBlockForFixedPosition):
+        (WebCore::containingBlockForAbsolutePosition):
+        (WebCore::containingBlockForObjectInFlow):
+        * rendering/RenderElement.h:
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::styleWillChange):
+        * rendering/RenderLineBreak.cpp:
+        (WebCore::RenderLineBreak::collectSelectionRects): Not a behaviour change.
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::containingBlock): RenderScrollbarPart renderer now returns
+        the containing block based on its owning renderer's style.
+
 2016-05-16  Brent Fulgham  <[email protected]>
 
         REGRESSION (r192098): Content missing after copy and paste to Notes App on retina displays

Modified: trunk/Source/WebCore/dom/Element.cpp (200952 => 200953)


--- trunk/Source/WebCore/dom/Element.cpp	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-05-16 18:44:02 UTC (rev 200953)
@@ -976,7 +976,7 @@
     }
 
     // This renderer may have positioned descendants whose containing block is some ancestor.
-    if (auto containingBlock = containingBlockForAbsolutePosition(&renderer)) {
+    if (auto containingBlock = renderer.containingBlockForAbsolutePosition()) {
         if (auto positionedObjects = containingBlock->positionedObjects()) {
             for (RenderBox* it : *positionedObjects) {
                 if (it != &renderer && renderer.element()->contains(it->element()))

Modified: trunk/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h (200952 => 200953)


--- trunk/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h	2016-05-16 18:44:02 UTC (rev 200953)
@@ -88,12 +88,10 @@
         // such that we can remove this assertion.
         ASSERT(rootBlock.isSelectionRoot());
 #endif
-        auto parent = rootBlock.parent();
-
         // LogicalSelectionOffsetCaches should not be used on an orphaned tree.
-        m_containingBlockForFixedPosition.setBlock(containingBlockForFixedPosition(parent), nullptr);
-        m_containingBlockForAbsolutePosition.setBlock(containingBlockForAbsolutePosition(parent), nullptr);
-        m_containingBlockForInflowPosition.setBlock(containingBlockForObjectInFlow(parent), nullptr);
+        m_containingBlockForFixedPosition.setBlock(rootBlock.containingBlockForFixedPosition(), nullptr);
+        m_containingBlockForAbsolutePosition.setBlock(rootBlock.containingBlockForAbsolutePosition(), nullptr);
+        m_containingBlockForInflowPosition.setBlock(rootBlock.containingBlockForObjectInFlow(), nullptr);
     }
 
     LogicalSelectionOffsetCaches(RenderBlock& block, const LogicalSelectionOffsetCaches& cache)

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (200952 => 200953)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2016-05-16 18:44:02 UTC (rev 200953)
@@ -2243,41 +2243,4 @@
 }
 #endif // ENABLE(IOS_TEXT_AUTOSIZING)
 
-RenderBlock* containingBlockForFixedPosition(const RenderElement* element)
-{
-    const auto* object = element;
-    while (object && !object->canContainFixedPositionObjects())
-        object = object->parent();
-
-    ASSERT(!object || !object->isAnonymousBlock());
-    return const_cast<RenderBlock*>(downcast<RenderBlock>(object));
 }
-
-RenderBlock* containingBlockForAbsolutePosition(const RenderElement* element)
-{
-    const auto* object = element;
-    while (object && !object->canContainAbsolutelyPositionedObjects())
-        object = object->parent();
-
-    // For a relatively positioned inline, return its nearest non-anonymous containing block,
-    // not the inline itself, to avoid having a positioned objects list in all RenderInlines
-    // and use RenderBlock* as RenderElement::containingBlock's return type.
-    // Use RenderBlock::container() to obtain the inline.
-    if (object && !is<RenderBlock>(*object))
-        object = object->containingBlock();
-
-    while (object && object->isAnonymousBlock())
-        object = object->containingBlock();
-
-    return const_cast<RenderBlock*>(downcast<RenderBlock>(object));
-}
-
-RenderBlock* containingBlockForObjectInFlow(const RenderElement* element)
-{
-    const auto* object = element;
-    while (object && ((object->isInline() && !object->isReplaced()) || !object->isRenderBlock()))
-        object = object->parent();
-    return const_cast<RenderBlock*>(downcast<RenderBlock>(object));
-}
-
-}

Modified: trunk/Source/WebCore/rendering/RenderElement.h (200952 => 200953)


--- trunk/Source/WebCore/rendering/RenderElement.h	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2016-05-16 18:44:02 UTC (rev 200953)
@@ -488,9 +488,6 @@
     return adjustLayoutUnitForAbsoluteZoom(value, renderer.style());
 }
 
-RenderBlock* containingBlockForFixedPosition(const RenderElement*);
-RenderBlock* containingBlockForAbsolutePosition(const RenderElement*);
-RenderBlock* containingBlockForObjectInFlow(const RenderElement*);
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderElement, isRenderElement())

Modified: trunk/Source/WebCore/rendering/RenderInline.cpp (200952 => 200953)


--- trunk/Source/WebCore/rendering/RenderInline.cpp	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/RenderInline.cpp	2016-05-16 18:44:02 UTC (rev 200953)
@@ -171,7 +171,7 @@
     // Check if this inline can hold absolute positioned elmements even after the style change.
     if (canContainAbsolutelyPositionedObjects() && newStyle.position() == StaticPosition) {
         // RenderInlines forward their absolute positioned descendants to their (non-anonymous) containing block.
-        auto* container = containingBlockForAbsolutePosition(this);
+        auto* container = containingBlockForAbsolutePosition();
         if (container && !container->canContainAbsolutelyPositionedObjects())
             container->removePositionedObjects(nullptr, NewContainingBlock);
     }

Modified: trunk/Source/WebCore/rendering/RenderLineBreak.cpp (200952 => 200953)


--- trunk/Source/WebCore/rendering/RenderLineBreak.cpp	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/RenderLineBreak.cpp	2016-05-16 18:44:02 UTC (rev 200953)
@@ -241,7 +241,7 @@
             rect.shiftXEdgeTo(rootBox.lineTopWithLeading());
     }
 
-    auto* containingBlock = containingBlockForObjectInFlow(this);
+    auto* containingBlock = containingBlockForObjectInFlow();
     // Map rect, extended left to leftOffset, and right to rightOffset, through transforms to get minX and maxX.
     LogicalSelectionOffsetCaches cache(*containingBlock);
     LayoutUnit leftOffset = containingBlock->logicalLeftSelectionOffset(*containingBlock, box->logicalTop(), cache);

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (200952 => 200953)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2016-05-16 18:44:02 UTC (rev 200953)
@@ -622,21 +622,66 @@
 
 RenderBlock* RenderObject::containingBlock() const
 {
-    auto* parent = this->parent();
+    auto containingBlockForRenderer = [](const RenderObject& renderer)
+    {
+        auto& style = renderer.style();
+        if (style.position() == AbsolutePosition)
+            return renderer.containingBlockForAbsolutePosition();
+        if (style.position() == FixedPosition)
+            return renderer.containingBlockForFixedPosition();
+        return renderer.containingBlockForObjectInFlow();
+    };
+
     if (is<RenderText>(*this))
-        return containingBlockForObjectInFlow(parent);
+        return containingBlockForObjectInFlow();
 
-    if (!parent && is<RenderScrollbarPart>(*this))
-        parent = downcast<RenderScrollbarPart>(*this).rendererOwningScrollbar();
+    if (!parent() && is<RenderScrollbarPart>(*this)) {
+        if (auto* renderer = downcast<RenderScrollbarPart>(*this).rendererOwningScrollbar())
+            return containingBlockForRenderer(*renderer);
+        return nullptr;
+    }
+    return containingBlockForRenderer(*this);
+}
 
-    auto& style = this->style();
-    if (style.position() == AbsolutePosition)
-        return containingBlockForAbsolutePosition(parent);
-    if (style.position() == FixedPosition)
-        return containingBlockForFixedPosition(parent);
-    return containingBlockForObjectInFlow(parent);
+RenderBlock* RenderObject::containingBlockForFixedPosition() const
+{
+    auto* renderer = parent();
+    while (renderer && !renderer->canContainFixedPositionObjects())
+        renderer = renderer->parent();
+
+    ASSERT(!renderer || !renderer->isAnonymousBlock());
+    return downcast<RenderBlock>(renderer);
 }
 
+RenderBlock* RenderObject::containingBlockForAbsolutePosition() const
+{
+    // RenderInlines forward their absolute positioned descendants to the containing block, so
+    // we need to start searching from 'this' and not from 'parent()'.
+    auto* renderer = isRenderInline() ? const_cast<RenderElement*>(downcast<RenderElement>(this)) : parent();
+    while (renderer && !renderer->canContainAbsolutelyPositionedObjects())
+        renderer = renderer->parent();
+
+    // For a relatively positioned inline, return its nearest non-anonymous containing block,
+    // not the inline itself, to avoid having a positioned objects list in all RenderInlines
+    // and use RenderBlock* as RenderElement::containingBlock's return type.
+    // Use RenderBlock::container() to obtain the inline.
+    if (renderer && !is<RenderBlock>(*renderer))
+        renderer = renderer->containingBlock();
+
+    while (renderer && renderer->isAnonymousBlock())
+        renderer = renderer->containingBlock();
+
+    return downcast<RenderBlock>(renderer);
+}
+
+RenderBlock* RenderObject::containingBlockForObjectInFlow() const
+{
+    auto* renderer = parent();
+    while (renderer && ((renderer->isInline() && !renderer->isReplaced()) || !renderer->isRenderBlock()))
+        renderer = renderer->parent();
+    return downcast<RenderBlock>(renderer);
+}
+
 void RenderObject::addPDFURLRect(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
 {
     Vector<LayoutRect> focusRingRects;

Modified: trunk/Source/WebCore/rendering/RenderObject.h (200952 => 200953)


--- trunk/Source/WebCore/rendering/RenderObject.h	2016-05-16 18:26:32 UTC (rev 200952)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2016-05-16 18:44:02 UTC (rev 200953)
@@ -647,6 +647,9 @@
 
     // returns the containing block level element for this element.
     RenderBlock* containingBlock() const;
+    RenderBlock* containingBlockForFixedPosition() const;
+    RenderBlock* containingBlockForAbsolutePosition() const;
+    RenderBlock* containingBlockForObjectInFlow() const;
 
     // Convert the given local point to absolute coordinates. If MapCoordinatesFlags includes UseTransforms, take transforms into account.
     WEBCORE_EXPORT FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(), MapCoordinatesFlags = 0, bool* wasFixed = nullptr) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to