Use is<>() / downcast<>() for RenderText / RenderTextFragment
https://bugs.webkit.org/show_bug.cgi?id=137476

Reviewed by Darin Adler.

Source/WebCore:

Use is<>() / downcast<>() for RenderText / RenderTextFragment, and
clean up the surrounding code.

No new tests, no behavior change.

* WebCore.exp.in:
Export symbol for RenderInline::linesBoundingBox() as it is used by
RenderInline::orderBoundingBox() which is inlined and now called in
WebRenderNode.mm.

* WebCore.xcodeproj/project.pbxproj:
Make RenderInline.h header as Private so that it can be included by
WebRenderNode.mm, similarly to RenderText.h.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::textUnderElement):
(WebCore::AccessibilityRenderObject::boundingBoxRect):
(WebCore::AccessibilityRenderObject::computeAccessibilityIsIgnored):
(WebCore::AccessibilityRenderObject::passwordFieldValue):
* accessibility/atk/AccessibilityObjectAtk.cpp:
(WebCore::AccessibilityObject::getLengthForTextRange):
* bindings/objc/DOMUIKitExtensions.mm:
(-[DOMNode textHeight]):
(-[DOMNode findExplodedTextNodeAtPoint:]):
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::getUpperLeftCorner):
(WebCore::ContainerNode::getLowerRightCorner):
* dom/DocumentMarkerController.cpp:
(WebCore::DocumentMarkerController::addMarker):
* dom/Position.cpp:
(WebCore::hasInlineBoxWrapper):
(WebCore::Position::upstream):
(WebCore::Position::downstream):
(WebCore::Position::hasRenderedNonAnonymousDescendantsWithHeight):
(WebCore::Position::isCandidate):
(WebCore::Position::rendersInDifferentPosition):
(WebCore::searchAheadForBetterMatch):
(WebCore::Position::getInlineBoxAndOffset):
* dom/PositionIterator.cpp:
(WebCore::PositionIterator::isCandidate):
* dom/Range.cpp:
(WebCore::Range::textRects):
(WebCore::Range::textQuads):
(WebCore::Range::getBorderAndTextQuads):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::debugRenderer):
* editing/TextIterator.cpp:
(WebCore::hasVisibleTextNode):
(WebCore::TextIterator::handleTextNode):
(WebCore::maxOffsetIncludingCollapsedSpaces):
(WebCore::SimplifiedBackwardsTextIterator::handleFirstLetter):
* editing/VisibleUnits.cpp:
(WebCore::startOfParagraph):
(WebCore::endOfParagraph):
* page/FrameView.cpp:
(WebCore::countRenderedCharactersInRenderObjectWithThreshold):
* rendering/BidiRun.cpp:
(WebCore::BidiRun::BidiRun):
* rendering/InlineIterator.cpp:
(WebCore::InlineIterator::surrogateTextDirection):
* rendering/InlineIterator.h:
(WebCore::InlineIterator::atTextParagraphSeparator):
(WebCore::InlineIterator::atParagraphSeparator):
(WebCore::isEmptyInline):
(WebCore::InlineIterator::fastIncrementInTextNode):
(WebCore::InlineIterator::increment):
(WebCore::InlineIterator::characterAt):
(WebCore::InlineIterator::direction):
* rendering/InlineTextBox.h:
(WebCore::InlineTextBox::renderer):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::updateFirstLetterStyle):
(WebCore::RenderBlock::updateFirstLetter):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::deleteLineBoxesBeforeSimpleLineLayout):
(WebCore::isVisibleRenderText):
(WebCore::RenderBlockFlow::adjustComputedFontSizes):
(WebCore::stripTrailingSpace):
(WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::createInlineBoxForRenderer):
(WebCore::dirtyLineBoxesForRenderer):
(WebCore::reachedEndOfTextRenderer):
(WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment):
(WebCore::RenderBlockFlow::computeBlockDirectionPositionsForLine):
(WebCore::RenderBlockFlow::handleTrailingSpaces):
(WebCore::RenderBlockFlow::determineStartPosition):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::moveChildrenTo):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::hasImmediateNonWhitespaceTextChildOrBorderOrOutline):
(WebCore::RenderElement::addChild):
* rendering/RenderInline.cpp:
(WebCore::RenderInline::generateCulledLineBoxRects):
(WebCore::RenderInline::culledInlineFirstLineBox):
(WebCore::RenderInline::culledInlineLastLineBox):
(WebCore::RenderInline::culledInlineVisualOverflowBoundingBox):
(WebCore::RenderInline::dirtyLineBoxes):
* rendering/RenderInline.h:
Make borderBoundingBox() public so that call sites (here
WebRenderNode.mm) can use tighter typing and benefit from the virtual
function being final.

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::calculateClipRects):
* rendering/RenderLineBoxList.cpp:
(WebCore::RenderLineBoxList::dirtyLinesFromChangedChild):
* rendering/RenderNamedFlowThread.cpp:
(WebCore::RenderNamedFlowThread::getRanges):
* rendering/RenderRubyRun.cpp:
(WebCore::RenderRubyRun::getOverhang):
* rendering/RenderSelectionInfo.cpp:
(WebCore::RenderSelectionInfo::RenderSelectionInfo):
* rendering/RenderText.cpp:
(WebCore::isInlineFlowOrEmptyText):
(WebCore::RenderText::previousCharacter):
* rendering/RenderText.h:
(WebCore::Text::renderer):
* rendering/RenderTextFragment.h:
(isType):
* rendering/RenderTreeAsText.cpp:
(WebCore::RenderTreeAsText::writeRenderObject):
(WebCore::write):
* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseFor):
(WebCore::SimpleLineLayout::create):
* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::paintFlow):
(WebCore::SimpleLineLayout::hitTestFlow):
* rendering/SimpleLineLayoutResolver.h:
(WebCore::SimpleLineLayout::RunResolver::RunResolver):
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::addNode):
* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::containerIsRowOfLinks):
(WebCore::TextAutosizer::measureDescendantTextWidth):
* rendering/line/BreakingContextInlineHeaders.h:
(WebCore::BreakingContext::commitLineBreakAtCurrentWidth):
(WebCore::shouldAddBorderPaddingMargin):
(WebCore::shouldSkipWhitespaceAfterStartObject):
(WebCore::BreakingContext::handleText):
(WebCore::textBeginsWithBreakablePosition):
(WebCore::BreakingContext::canBreakAtThisPosition):

Source/WebKit/mac:

* WebView/WebRenderNode.mm:
(copyRenderNode):

Source/WebKit2:

Use is<>() / downcast<>() for RenderText / RenderTextFragment.

* Shared/WebRenderObject.cpp:
(WebKit::WebRenderObject::WebRenderObject):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/rendering/RenderInline.cpp b/Source/WebCore/rendering/RenderInline.cpp
index d1a1db3..f37f537 100644
--- a/Source/WebCore/rendering/RenderInline.cpp
+++ b/Source/WebCore/rendering/RenderInline.cpp
@@ -570,31 +570,31 @@
 
     bool isHorizontal = style().isHorizontalWritingMode();
 
-    for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
-        if (curr->isFloatingOrOutOfFlowPositioned())
+    for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
+        if (current->isFloatingOrOutOfFlowPositioned())
             continue;
             
         // We want to get the margin box in the inline direction, and then use our font ascent/descent in the block
         // direction (aligned to the root box's baseline).
-        if (curr->isBox()) {
-            RenderBox* currBox = toRenderBox(curr);
-            if (currBox->inlineBoxWrapper()) {
-                const RootInlineBox& rootBox = currBox->inlineBoxWrapper()->root();
+        if (is<RenderBox>(*current)) {
+            RenderBox& renderBox = downcast<RenderBox>(*current);
+            if (renderBox.inlineBoxWrapper()) {
+                const RootInlineBox& rootBox = renderBox.inlineBoxWrapper()->root();
                 const RenderStyle& containerStyle = rootBox.isFirstLine() ? container->firstLineStyle() : container->style();
                 int logicalTop = rootBox.logicalTop() + (rootBox.lineStyle().font().fontMetrics().ascent() - containerStyle.font().fontMetrics().ascent());
                 int logicalHeight = containerStyle.font().fontMetrics().height();
                 if (isHorizontal)
-                    context.addRect(FloatRect(currBox->inlineBoxWrapper()->x() - currBox->marginLeft(), logicalTop, currBox->width() + currBox->horizontalMarginExtent(), logicalHeight));
+                    context.addRect(FloatRect(renderBox.inlineBoxWrapper()->x() - renderBox.marginLeft(), logicalTop, renderBox.width() + renderBox.horizontalMarginExtent(), logicalHeight));
                 else
-                    context.addRect(FloatRect(logicalTop, currBox->inlineBoxWrapper()->y() - currBox->marginTop(), logicalHeight, currBox->height() + currBox->verticalMarginExtent()));
+                    context.addRect(FloatRect(logicalTop, renderBox.inlineBoxWrapper()->y() - renderBox.marginTop(), logicalHeight, renderBox.height() + renderBox.verticalMarginExtent()));
             }
-        } else if (curr->isRenderInline()) {
+        } else if (is<RenderInline>(*current)) {
             // If the child doesn't need line boxes either, then we can recur.
-            RenderInline* currInline = toRenderInline(curr);
-            if (!currInline->alwaysCreateLineBoxes())
-                currInline->generateCulledLineBoxRects(context, container);
+            RenderInline& renderInline = downcast<RenderInline>(*current);
+            if (!renderInline.alwaysCreateLineBoxes())
+                renderInline.generateCulledLineBoxRects(context, container);
             else {
-                for (InlineFlowBox* childLine = currInline->firstLineBox(); childLine; childLine = childLine->nextLineBox()) {
+                for (InlineFlowBox* childLine = renderInline.firstLineBox(); childLine; childLine = childLine->nextLineBox()) {
                     const RootInlineBox& rootBox = childLine->root();
                     const RenderStyle& containerStyle = rootBox.isFirstLine() ? container->firstLineStyle() : container->style();
                     int logicalTop = rootBox.logicalTop() + (rootBox.lineStyle().font().fontMetrics().ascent() - containerStyle.font().fontMetrics().ascent());
@@ -612,9 +612,9 @@
                     }
                 }
             }
-        } else if (curr->isText()) {
-            RenderText* currText = toRenderText(curr);
-            for (InlineTextBox* childText = currText->firstTextBox(); childText; childText = childText->nextTextBox()) {
+        } else if (is<RenderText>(*current)) {
+            RenderText& currText = downcast<RenderText>(*current);
+            for (InlineTextBox* childText = currText.firstTextBox(); childText; childText = childText->nextTextBox()) {
                 const RootInlineBox& rootBox = childText->root();
                 const RenderStyle& containerStyle = rootBox.isFirstLine() ? container->firstLineStyle() : container->style();
                 int logicalTop = rootBox.logicalTop() + (rootBox.lineStyle().font().fontMetrics().ascent() - containerStyle.font().fontMetrics().ascent());
@@ -624,8 +624,8 @@
                 else
                     context.addRect(FloatRect(logicalTop, childText->y(), logicalHeight, childText->logicalWidth()));
             }
-        } else if (curr->isLineBreak()) {
-            if (InlineBox* inlineBox = toRenderLineBreak(curr)->inlineBoxWrapper()) {
+        } else if (is<RenderLineBreak>(*current)) {
+            if (InlineBox* inlineBox = downcast<RenderLineBreak>(*current).inlineBoxWrapper()) {
                 // FIXME: This could use a helper to share these with text path.
                 const RootInlineBox& rootBox = inlineBox->root();
                 const RenderStyle& containerStyle = rootBox.isFirstLine() ? container->firstLineStyle() : container->style();
@@ -930,58 +930,56 @@
 
 InlineBox* RenderInline::culledInlineFirstLineBox() const
 {
-    for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
-        if (curr->isFloatingOrOutOfFlowPositioned())
+    for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
+        if (current->isFloatingOrOutOfFlowPositioned())
             continue;
             
         // We want to get the margin box in the inline direction, and then use our font ascent/descent in the block
         // direction (aligned to the root box's baseline).
-        if (curr->isBox())
-            return toRenderBox(curr)->inlineBoxWrapper();
-        if (curr->isLineBreak()) {
-            RenderLineBreak* renderBR = toRenderLineBreak(curr);
-            if (renderBR->inlineBoxWrapper())
-                return renderBR->inlineBoxWrapper();
-        } else if (curr->isRenderInline()) {
-            RenderInline* currInline = toRenderInline(curr);
-            InlineBox* result = currInline->firstLineBoxIncludingCulling();
-            if (result)
+        if (is<RenderBox>(*current))
+            return downcast<RenderBox>(*current).inlineBoxWrapper();
+        if (is<RenderLineBreak>(*current)) {
+            RenderLineBreak& renderBR = downcast<RenderLineBreak>(*current);
+            if (renderBR.inlineBoxWrapper())
+                return renderBR.inlineBoxWrapper();
+        } else if (is<RenderInline>(*current)) {
+            RenderInline& renderInline = downcast<RenderInline>(*current);
+            if (InlineBox* result = renderInline.firstLineBoxIncludingCulling())
                 return result;
-        } else if (curr->isText()) {
-            RenderText* currText = toRenderText(curr);
-            if (currText->firstTextBox())
-                return currText->firstTextBox();
+        } else if (is<RenderText>(*current)) {
+            RenderText& renderText = downcast<RenderText>(*current);
+            if (renderText.firstTextBox())
+                return renderText.firstTextBox();
         }
     }
-    return 0;
+    return nullptr;
 }
 
 InlineBox* RenderInline::culledInlineLastLineBox() const
 {
-    for (RenderObject* curr = lastChild(); curr; curr = curr->previousSibling()) {
-        if (curr->isFloatingOrOutOfFlowPositioned())
+    for (RenderObject* current = lastChild(); current; current = current->previousSibling()) {
+        if (current->isFloatingOrOutOfFlowPositioned())
             continue;
             
         // We want to get the margin box in the inline direction, and then use our font ascent/descent in the block
         // direction (aligned to the root box's baseline).
-        if (curr->isBox())
-            return toRenderBox(curr)->inlineBoxWrapper();
-        if (curr->isLineBreak()) {
-            RenderLineBreak* renderBR = toRenderLineBreak(curr);
-            if (renderBR->inlineBoxWrapper())
-                return renderBR->inlineBoxWrapper();
-        } else if (curr->isRenderInline()) {
-            RenderInline* currInline = toRenderInline(curr);
-            InlineBox* result = currInline->lastLineBoxIncludingCulling();
-            if (result)
+        if (is<RenderBox>(*current))
+            return downcast<RenderBox>(*current).inlineBoxWrapper();
+        if (is<RenderLineBreak>(*current)) {
+            RenderLineBreak& renderBR = downcast<RenderLineBreak>(*current);
+            if (renderBR.inlineBoxWrapper())
+                return renderBR.inlineBoxWrapper();
+        } else if (is<RenderInline>(*current)) {
+            RenderInline& renderInline = downcast<RenderInline>(*current);
+            if (InlineBox* result = renderInline.lastLineBoxIncludingCulling())
                 return result;
-        } else if (curr->isText()) {
-            RenderText* currText = toRenderText(curr);
-            if (currText->lastTextBox())
-                return currText->lastTextBox();
+        } else if (is<RenderText>(*current)) {
+            RenderText& renderText = downcast<RenderText>(*current);
+            if (renderText.lastTextBox())
+                return renderText.lastTextBox();
         }
     }
-    return 0;
+    return nullptr;
 }
 
 LayoutRect RenderInline::culledInlineVisualOverflowBoundingBox() const
@@ -991,35 +989,35 @@
     generateCulledLineBoxRects(context, this);
     LayoutRect result(enclosingLayoutRect(floatResult));
     bool isHorizontal = style().isHorizontalWritingMode();
-    for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
-        if (curr->isFloatingOrOutOfFlowPositioned())
+    for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
+        if (current->isFloatingOrOutOfFlowPositioned())
             continue;
             
         // For overflow we just have to propagate by hand and recompute it all.
-        if (curr->isBox()) {
-            RenderBox* currBox = toRenderBox(curr);
-            if (!currBox->hasSelfPaintingLayer() && currBox->inlineBoxWrapper()) {
-                LayoutRect logicalRect = currBox->logicalVisualOverflowRectForPropagation(&style());
+        if (is<RenderBox>(*current)) {
+            RenderBox& renderBox = downcast<RenderBox>(*current);
+            if (!renderBox.hasSelfPaintingLayer() && renderBox.inlineBoxWrapper()) {
+                LayoutRect logicalRect = renderBox.logicalVisualOverflowRectForPropagation(&style());
                 if (isHorizontal) {
-                    logicalRect.moveBy(currBox->location());
+                    logicalRect.moveBy(renderBox.location());
                     result.uniteIfNonZero(logicalRect);
                 } else {
-                    logicalRect.moveBy(currBox->location());
+                    logicalRect.moveBy(renderBox.location());
                     result.uniteIfNonZero(logicalRect.transposedRect());
                 }
             }
-        } else if (curr->isRenderInline()) {
+        } else if (is<RenderInline>(*current)) {
             // If the child doesn't need line boxes either, then we can recur.
-            RenderInline* currInline = toRenderInline(curr);
-            if (!currInline->alwaysCreateLineBoxes())
-                result.uniteIfNonZero(currInline->culledInlineVisualOverflowBoundingBox());
-            else if (!currInline->hasSelfPaintingLayer())
-                result.uniteIfNonZero(currInline->linesVisualOverflowBoundingBox());
-        } else if (curr->isText()) {
+            RenderInline& renderInline = downcast<RenderInline>(*current);
+            if (!renderInline.alwaysCreateLineBoxes())
+                result.uniteIfNonZero(renderInline.culledInlineVisualOverflowBoundingBox());
+            else if (!renderInline.hasSelfPaintingLayer())
+                result.uniteIfNonZero(renderInline.linesVisualOverflowBoundingBox());
+        } else if (is<RenderText>(*current)) {
             // FIXME; Overflow from text boxes is lost. We will need to cache this information in
             // InlineTextBoxes.
-            RenderText* currText = toRenderText(curr);
-            result.uniteIfNonZero(currText->linesVisualOverflowBoundingBox());
+            RenderText& renderText = downcast<RenderText>(*current);
+            result.uniteIfNonZero(renderText.linesVisualOverflowBoundingBox());
         }
     }
     return result;
@@ -1354,26 +1352,26 @@
 
     if (!alwaysCreateLineBoxes()) {
         // We have to grovel into our children in order to dirty the appropriate lines.
-        for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
-            if (curr->isFloatingOrOutOfFlowPositioned())
+        for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
+            if (current->isFloatingOrOutOfFlowPositioned())
                 continue;
-            if (curr->isBox() && !curr->needsLayout()) {
-                RenderBox* currBox = toRenderBox(curr);
-                if (currBox->inlineBoxWrapper())
-                    currBox->inlineBoxWrapper()->root().markDirty();
-            } else if (!curr->selfNeedsLayout()) {
-                if (curr->isRenderInline()) {
-                    RenderInline* currInline = toRenderInline(curr);
-                    for (InlineFlowBox* childLine = currInline->firstLineBox(); childLine; childLine = childLine->nextLineBox())
+            if (is<RenderBox>(*current) && !current->needsLayout()) {
+                RenderBox& renderBox = downcast<RenderBox>(*current);
+                if (renderBox.inlineBoxWrapper())
+                    renderBox.inlineBoxWrapper()->root().markDirty();
+            } else if (!current->selfNeedsLayout()) {
+                if (is<RenderInline>(*current)) {
+                    RenderInline& renderInline = downcast<RenderInline>(*current);
+                    for (InlineFlowBox* childLine = renderInline.firstLineBox(); childLine; childLine = childLine->nextLineBox())
                         childLine->root().markDirty();
-                } else if (curr->isText()) {
-                    RenderText* currText = toRenderText(curr);
-                    for (InlineTextBox* childText = currText->firstTextBox(); childText; childText = childText->nextTextBox())
+                } else if (is<RenderText>(*current)) {
+                    RenderText& renderText = downcast<RenderText>(*current);
+                    for (InlineTextBox* childText = renderText.firstTextBox(); childText; childText = childText->nextTextBox())
                         childText->root().markDirty();
-                } else if (curr->isLineBreak()) {
-                    RenderLineBreak* currBR = toRenderLineBreak(curr);
-                    if (currBR->inlineBoxWrapper())
-                        currBR->inlineBoxWrapper()->root().markDirty();
+                } else if (is<RenderLineBreak>(*current)) {
+                    RenderLineBreak& renderBR = downcast<RenderLineBreak>(*current);
+                    if (renderBR.inlineBoxWrapper())
+                        renderBR.inlineBoxWrapper()->root().markDirty();
                 }
             }
         }