https://bugs.webkit.org/show_bug.cgi?id=68480
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 22:23:41 +0000 (22:23 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 22:23:41 +0000 (22:23 +0000)
De-virtualize containingBlock() and make RenderView return 0 instead
of itself to make the construction of normal loops that terminate via
a null-check possible.

Fix the only two places in the tree that needed null checks.

Eliminating RenderTableCell::containingBlock() is fine since the base class
does the same thing anyway.

Reviewed by Simon Fraser.

* editing/VisiblePosition.cpp:
(WebCore::VisiblePosition::lineDirectionPointForBlockDirectionNavigation):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::containingBlock):
* rendering/RenderObject.h:
* rendering/RenderTableCell.cpp:
* rendering/RenderTableCell.h:
* rendering/RenderTreeAsText.cpp:
(WebCore::RenderTreeAsText::writeRenderObject):
* rendering/RenderView.cpp:
* rendering/RenderView.h:

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

Source/WebCore/ChangeLog
Source/WebCore/editing/VisiblePosition.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/RenderTableCell.cpp
Source/WebCore/rendering/RenderTableCell.h
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/rendering/RenderView.cpp
Source/WebCore/rendering/RenderView.h

index 163e6ea..74a7ddd 100644 (file)
@@ -1,3 +1,30 @@
+2011-09-20  David Hyatt  <hyatt@apple.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=68480
+        
+        De-virtualize containingBlock() and make RenderView return 0 instead
+        of itself to make the construction of normal loops that terminate via
+        a null-check possible.
+
+        Fix the only two places in the tree that needed null checks.
+
+        Eliminating RenderTableCell::containingBlock() is fine since the base class
+        does the same thing anyway.
+
+        Reviewed by Simon Fraser.
+
+        * editing/VisiblePosition.cpp:
+        (WebCore::VisiblePosition::lineDirectionPointForBlockDirectionNavigation):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::containingBlock):
+        * rendering/RenderObject.h:
+        * rendering/RenderTableCell.cpp:
+        * rendering/RenderTableCell.h:
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::RenderTreeAsText::writeRenderObject):
+        * rendering/RenderView.cpp:
+        * rendering/RenderView.h:
+
 2011-09-20  Anders Carlsson  <andersca@apple.com>
 
         Remove ScrollView::platformContentsSize
index d8e731d..56e5af6 100644 (file)
@@ -607,7 +607,10 @@ int VisiblePosition::lineDirectionPointForBlockDirectionNavigation() const
     // without consulting transforms, so that 'up' in transformed text is 'up'
     // relative to the text, not absolute 'up'.
     FloatPoint caretPoint = renderer->localToAbsolute(localRect.location());
-    return renderer->containingBlock()->isHorizontalWritingMode() ? caretPoint.x() : caretPoint.y();
+    RenderObject* containingBlock = renderer->containingBlock();
+    if (!containingBlock)
+        containingBlock = renderer; // Just use ourselves to determine the writing mode if we have no containing block.
+    return containingBlock->isHorizontalWritingMode() ? caretPoint.x() : caretPoint.y();
 }
 
 #ifndef NDEBUG
index 375895a..7d7327d 100644 (file)
@@ -636,9 +636,6 @@ void RenderObject::setLayerNeedsFullRepaint()
 
 RenderBlock* RenderObject::containingBlock() const
 {
-    ASSERT(!isTableCell());
-    ASSERT(!isRenderView());
-
     RenderObject* o = parent();
     if (!isText() && m_style->position() == FixedPosition) {
         while (o && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock()))
index 3bd2457..a898e96 100644 (file)
@@ -600,7 +600,7 @@ public:
     void setStyleInternal(PassRefPtr<RenderStyle>);
 
     // returns the containing block level element for this element.
-    virtual RenderBlock* containingBlock() const;
+    RenderBlock* containingBlock() const;
 
     // Convert the given local point to absolute coordinates
     // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
index 28c1ff1..c9c3d96 100644 (file)
@@ -319,13 +319,6 @@ void RenderTableCell::styleDidChange(StyleDifference diff, const RenderStyle* ol
     setHasBoxDecorations(true);
 }
 
-RenderBlock* RenderTableCell::containingBlock() const
-{
-    if (parent() && section())
-        return table();
-    return 0;
-}
-
 // The following rules apply for resolving conflicts and figuring out which border
 // to use.
 // (1) Borders with the 'border-style' of 'hidden' take precedence over all other conflicting 
index a6061c4..5b235d6 100644 (file)
@@ -137,8 +137,6 @@ private:
 
     virtual bool isTableCell() const { return true; }
 
-    virtual RenderBlock* containingBlock() const;
-
     virtual void willBeDestroyed();
 
     virtual void computeLogicalWidth();
index 3a04e35..96459d9 100644 (file)
@@ -246,7 +246,8 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
         }
     }
     
-    bool adjustForTableCells = o.containingBlock()->isTableCell();
+    RenderBlock* cb = o.containingBlock();
+    bool adjustForTableCells = cb ? cb->isTableCell() : false;
 
     IntRect r;
     if (o.isText()) {
index ae1112c..4fefaa1 100644 (file)
@@ -265,11 +265,6 @@ bool RenderView::shouldRepaint(const IntRect& r) const
     return true;
 }
 
-RenderBlock* RenderView::containingBlock() const
-{
-    return const_cast<RenderView*>(this);
-}
-
 void RenderView::repaintViewRectangle(const IntRect& ur, bool immediate)
 {
     if (!shouldRepaint(ur))
index efea416..8d431e6 100644 (file)
@@ -193,8 +193,6 @@ protected:
 
 private:
     bool shouldRepaint(const IntRect& r) const;
-    
-    virtual RenderBlock* containingBlock() const;
 
     // These functions may only be accessed by LayoutStateMaintainer.
     void pushLayoutState(RenderFlowThread*);