Use is<>() / downcast<>() for RenderText / RenderTextFragment
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Oct 2014 19:33:53 +0000 (19:33 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Oct 2014 19:33:53 +0000 (19:33 +0000)
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: https://svn.webkit.org/repository/webkit/trunk@174403 268f45cc-cd09-0410-ab3c-d52691b4dbfc

46 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/atk/AccessibilityObjectAtk.cpp
Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/DocumentMarkerController.cpp
Source/WebCore/dom/Position.cpp
Source/WebCore/dom/PositionIterator.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/rendering/BidiRun.cpp
Source/WebCore/rendering/InlineIterator.cpp
Source/WebCore/rendering/InlineIterator.h
Source/WebCore/rendering/InlineTextBox.h
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderInline.cpp
Source/WebCore/rendering/RenderInline.h
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderLineBoxList.cpp
Source/WebCore/rendering/RenderNamedFlowThread.cpp
Source/WebCore/rendering/RenderRubyRun.cpp
Source/WebCore/rendering/RenderSelectionInfo.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderText.h
Source/WebCore/rendering/RenderTextFragment.h
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/rendering/SimpleLineLayout.cpp
Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp
Source/WebCore/rendering/SimpleLineLayoutResolver.h
Source/WebCore/rendering/TextAutoSizing.cpp
Source/WebCore/rendering/TextAutosizer.cpp
Source/WebCore/rendering/line/BreakingContextInlineHeaders.h
Source/WebCore/rendering/line/LineBreaker.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebRenderNode.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebRenderObject.cpp

index 1b05ad5..81bc8b0 100644 (file)
@@ -1,3 +1,154 @@
+2014-10-07  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for RenderText / RenderTextFragment
+        https://bugs.webkit.org/show_bug.cgi?id=137476
+
+        Reviewed by Darin Adler.
+
+        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):
+
 2014-10-07  Jer Noble  <jer.noble@apple.com>
 
         [Media] Expose AudioTracks in the "captions" menu.
index f996977..4b16510 100644 (file)
@@ -1628,6 +1628,7 @@ __ZNK7WebCore11RenderStyle11fontMetricsEv
 __ZNK7WebCore11RenderStyle15fontDescriptionEv
 __ZNK7WebCore11RenderStyle21visitedDependentColorEi
 __ZNK7WebCore11RenderStyle4fontEv
+__ZNK7WebCore12RenderInline16linesBoundingBoxEv
 __ZNK7WebCore12RenderObject14enclosingLayerEv
 __ZNK7WebCore12RenderObject15localToAbsoluteERKNS_10FloatPointEj
 __ZNK7WebCore12RenderObject16repaintRectangleERKNS_10LayoutRectEb
index cf07cec..236f9fa 100644 (file)
                BCEA4875097D93020094C9E4 /* RenderImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4836097D93020094C9E4 /* RenderImage.cpp */; };
                BCEA4876097D93020094C9E4 /* RenderImage.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4837097D93020094C9E4 /* RenderImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BCEA4877097D93020094C9E4 /* RenderInline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4838097D93020094C9E4 /* RenderInline.cpp */; };
-               BCEA4878097D93020094C9E4 /* RenderInline.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4839097D93020094C9E4 /* RenderInline.h */; };
+               BCEA4878097D93020094C9E4 /* RenderInline.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4839097D93020094C9E4 /* RenderInline.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BCEA4879097D93020094C9E4 /* RenderLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA483A097D93020094C9E4 /* RenderLayer.cpp */; };
                BCEA487A097D93020094C9E4 /* RenderLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA483B097D93020094C9E4 /* RenderLayer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BCEA487F097D93020094C9E4 /* RenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4840097D93020094C9E4 /* RenderObject.cpp */; };
index 4e22f5f..ef3218f 100644 (file)
@@ -647,13 +647,13 @@ String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElement
 #if ENABLE(MATHML)
     // Math operators create RenderText nodes on the fly that are not tied into the DOM in a reasonable way,
     // so rangeOfContents does not work for them (nor does regular text selection).
-    if (m_renderer->isText() && m_renderer->isAnonymous() && ancestorsOfType<RenderMathMLOperator>(*m_renderer).first())
-        return toRenderText(*m_renderer).text();
+    if (is<RenderText>(*m_renderer) && m_renderer->isAnonymous() && ancestorsOfType<RenderMathMLOperator>(*m_renderer).first())
+        return downcast<RenderText>(*m_renderer).text();
 #endif
 
     // We use a text iterator for text objects AND for those cases where we are
     // explicitly asking for the full text under a given element.
-    if (m_renderer->isText() || mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeAllChildren) {
+    if (is<RenderText>(*m_renderer) || mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeAllChildren) {
         // If possible, use a text iterator to get the text, so that whitespace
         // is handled consistently.
         Document* nodeDocument = nullptr;
@@ -692,18 +692,18 @@ String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElement
     
         // Sometimes text fragments don't have Nodes associated with them (like when
         // CSS content is used to insert text or when a RenderCounter is used.)
-        if (m_renderer->isText()) {
-            RenderText* renderTextObject = toRenderText(m_renderer);
-            if (renderTextObject->isTextFragment()) {
-                
+        if (is<RenderText>(*m_renderer)) {
+            RenderText& renderTextObject = downcast<RenderText>(*m_renderer);
+            if (is<RenderTextFragment>(renderTextObject)) {
+                RenderTextFragment& renderTextFragment = downcast<RenderTextFragment>(renderTextObject);
                 // The alt attribute may be set on a text fragment through CSS, which should be honored.
-                const String& altText = toRenderTextFragment(renderTextObject)->altText();
+                const String& altText = renderTextFragment.altText();
                 if (!altText.isEmpty())
                     return altText;
-                return String(static_cast<RenderTextFragment*>(m_renderer)->contentString());
+                return renderTextFragment.contentString();
             }
 
-            return String(renderTextObject->text());
+            return renderTextObject.text();
         }
     }
     
@@ -821,8 +821,8 @@ LayoutRect AccessibilityRenderObject::boundingBoxRect() const
     if (obj->isSVGRoot())
         isSVGRoot = true;
 
-    if (obj->isText())
-        quads = toRenderText(obj)->absoluteQuadsClippedToEllipsis();
+    if (is<RenderText>(*obj))
+        quads = downcast<RenderText>(*obj).absoluteQuadsClippedToEllipsis();
     else if (isWebArea() || isSVGRoot)
         obj->absoluteQuads(quads);
     else
@@ -1211,12 +1211,12 @@ bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
     if (m_renderer->isBR())
         return true;
 
-    if (m_renderer->isText()) {
+    if (is<RenderText>(*m_renderer)) {
         // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
         AccessibilityObject* parent = parentObjectUnignored();
         if (parent && (parent->isMenuItem() || parent->ariaRoleAttribute() == MenuButtonRole))
             return true;
-        auto& renderText = toRenderText(*m_renderer);
+        auto& renderText = downcast<RenderText>(*m_renderer);
         if (!renderText.hasRenderedText())
             return true;
 
@@ -1227,8 +1227,8 @@ bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
         }
         
         // The alt attribute may be set on a text fragment through CSS, which should be honored.
-        if (renderText.isTextFragment()) {
-            AccessibilityObjectInclusion altTextInclusion = objectInclusionFromAltText(toRenderTextFragment(&renderText)->altText());
+        if (is<RenderTextFragment>(renderText)) {
+            AccessibilityObjectInclusion altTextInclusion = objectInclusionFromAltText(downcast<RenderTextFragment>(renderText).altText());
             if (altTextInclusion == IgnoreObject)
                 return true;
             if (altTextInclusion == IncludeObject)
@@ -3443,14 +3443,14 @@ String AccessibilityRenderObject::passwordFieldValue() const
 
     // Look for the RenderText object in the RenderObject tree for this input field.
     RenderObject* renderer = node()->renderer();
-    while (renderer && !renderer->isText())
-        renderer = toRenderElement(renderer)->firstChild();
+    while (renderer && !is<RenderText>(renderer))
+        renderer = downcast<RenderElement>(*renderer).firstChild();
 
-    if (!renderer || !renderer->isText())
+    if (!is<RenderText>(renderer))
         return String();
 
     // Return the text that is actually being rendered in the input field.
-    return toRenderText(renderer)->textWithoutConvertingBackslashToYenSymbol();
+    return downcast<RenderText>(*renderer).textWithoutConvertingBackslashToYenSymbol();
 }
 
 ScrollableArea* AccessibilityRenderObject::getScrollableAreaIfScrollable() const
index 1d16ec1..48c9fa7 100644 (file)
@@ -166,9 +166,9 @@ unsigned AccessibilityObject::getLengthForTextRange() const
 
     // Gtk ATs need this for all text objects; not just text controls.
     Node* node = this->node();
-    RenderObject* renderer = node ? node->renderer() : 0;
-    if (renderer && renderer->isText())
-        textLength = toRenderText(*renderer).textLength();
+    RenderObject* renderer = node ? node->renderer() : nullptr;
+    if (is<RenderText>(renderer))
+        textLength = downcast<RenderText>(*renderer).textLength();
 
     // Get the text length from the elements under the
     // accessibility object if the value is still zero.
index b4a98b2..c55db01 100644 (file)
@@ -242,11 +242,9 @@ using WebCore::VisiblePosition;
 
 - (CGFloat)textHeight
 {  
-    RenderObject *o = core(self)->renderer();
-    if (o && o->isText()) {
-        RenderText *t = toRenderText(o);
-        return t->style().computedLineHeight();;
-    }
+    RenderObject* renderer = core(self)->renderer();
+    if (is<RenderText>(renderer))
+        return downcast<RenderText>(*renderer).style().computedLineHeight();
     
     return CGFLOAT_MAX;
 }
@@ -258,11 +256,11 @@ using WebCore::VisiblePosition;
     // a node returned from elementAtPoint.  We make the assumption that either the node or one
     // of its immediate children contains the root line boxes in question.
     // See <rdar://problem/6824650> for context.
-    RenderObject *renderer = core(self)->renderer();
-    if (!renderer || !renderer->isRenderBlockFlow())
+    RenderObjectrenderer = core(self)->renderer();
+    if (!is<RenderBlockFlow>(renderer))
         return nil;
 
-    RenderBlock *block = static_cast<RenderBlock *>(renderer);
+    RenderBlock* block = downcast<RenderBlockFlow>(renderer);
     
     FloatPoint absPoint(point);
     FloatPoint localPoint = block->absoluteToLocal(absPoint);
@@ -279,7 +277,7 @@ using WebCore::VisiblePosition;
                 nextChild = nextChild->nextSiblingBox();
             if (!nextChild) {
                 if (localPoint.y() >= top) {
-                    block = static_cast<RenderBlock *>(child);
+                    block = downcast<RenderBlock>(child);
                     break;
                 }
                 continue;
@@ -287,8 +285,8 @@ using WebCore::VisiblePosition;
             
             float bottom = nextChild->y();
             
-            if (localPoint.y() >= top && localPoint.y() < bottom && child->isRenderBlock()) {
-                block = static_cast<RenderBlock *>(child);
+            if (localPoint.y() >= top && localPoint.y() < bottom && is<RenderBlock>(*child)) {
+                block = downcast<RenderBlock>(child);
                 break;
             }                
         }
@@ -299,25 +297,24 @@ using WebCore::VisiblePosition;
         localPoint = block->absoluteToLocal(absPoint);
     }
 
-    RenderBlockFlow *blockFlow = toRenderBlockFlow(block);
+    RenderBlockFlow& blockFlow = downcast<RenderBlockFlow>(*block);
     
     // Only check the gaps between the root line boxes.  We deliberately ignore overflow because
     // experience has shown that hit tests on an exploded text node can fail when within the
     // overflow region.
-    for (RootInlineBox *cur = blockFlow->firstRootBox(); cur && cur != blockFlow->lastRootBox(); cur = cur->nextRootBox()) {
-        float currentBottom = cur->y() + cur->logicalHeight();        
+    for (RootInlineBox* current = blockFlow.firstRootBox(); current && current != blockFlow.lastRootBox(); current = current->nextRootBox()) {
+        float currentBottom = current->y() + current->logicalHeight();
         if (localPoint.y() < currentBottom)
             return nil;
 
-        RootInlineBox *next = cur->nextRootBox();
+        RootInlineBox* next = current->nextRootBox();
         float nextTop = next->y();
         if (localPoint.y() < nextTop) {
-            InlineBox *inlineBox = cur->closestLeafChildForLogicalLeftPosition(localPoint.x());
-            if (inlineBox && inlineBox->behavesLikeText() && inlineBox->renderer().isText()) {
-                RenderText *t = toRenderText(&inlineBox->renderer());
-                if (t->textNode()) {
-                    return kit(t->textNode());
-                }
+            InlineBox* inlineBox = current->closestLeafChildForLogicalLeftPosition(localPoint.x());
+            if (inlineBox && inlineBox->behavesLikeText() && is<RenderText>(inlineBox->renderer())) {
+                RenderText& renderText = downcast<RenderText>(inlineBox->renderer());
+                if (renderText.textNode())
+                    return kit(renderText.textNode());
             }
         }
 
index 8a4f3ab..c1a18be 100644 (file)
@@ -841,16 +841,14 @@ bool ContainerNode::getUpperLeftCorner(FloatPoint& point) const
             return true;
         }
 
-        if (p->node() && p->node() == this && o->isText() && !toRenderText(o)->firstTextBox()) {
+        if (p->node() && p->node() == this && is<RenderText>(*o) && !downcast<RenderText>(*o).firstTextBox()) {
             // do nothing - skip unrendered whitespace that is a child or next sibling of the anchor
-        } else if (o->isText() || o->isReplaced()) {
+        } else if (is<RenderText>(*o) || o->isReplaced()) {
             point = FloatPoint();
-            if (o->isText() && toRenderText(o)->firstTextBox()) {
-                point.move(toRenderText(o)->linesBoundingBox().x(), toRenderText(o)->firstTextBox()->root().lineTop());
-            } else if (o->isBox()) {
-                RenderBox* box = toRenderBox(o);
-                point.moveBy(box->location());
-            }
+            if (is<RenderText>(*o) && downcast<RenderText>(*o).firstTextBox())
+                point.move(downcast<RenderText>(*o).linesBoundingBox().x(), downcast<RenderText>(*o).firstTextBox()->root().lineTop());
+            else if (is<RenderBox>(*o))
+                point.moveBy(downcast<RenderBox>(*o).location());
             point = o->container()->localToAbsolute(point, UseTransforms);
             return true;
         }
@@ -894,18 +892,15 @@ bool ContainerNode::getLowerRightCorner(FloatPoint& point) const
             o = prev;
         }
         ASSERT(o);
-        if (o->isText() || o->isReplaced()) {
+        if (is<RenderText>(*o) || o->isReplaced()) {
             point = FloatPoint();
-            if (o->isText()) {
-                RenderText* text = toRenderText(o);
-                IntRect linesBox = text->linesBoundingBox();
+            if (is<RenderText>(*o)) {
+                IntRect linesBox = downcast<RenderText>(*o).linesBoundingBox();
                 if (!linesBox.maxX() && !linesBox.maxY())
                     continue;
                 point.moveBy(linesBox.maxXMaxYCorner());
-            } else {
-                RenderBox* box = toRenderBox(o);
-                point.moveBy(box->frameRect().maxXMaxYCorner());
-            }
+            } else
+                point.moveBy(downcast<RenderBox>(*o).frameRect().maxXMaxYCorner());
             point = o->container()->localToAbsolute(point, UseTransforms);
             return true;
         }
index 4748165..9cb8ae6 100644 (file)
@@ -169,10 +169,10 @@ void DocumentMarkerController::addMarker(Node* node, const DocumentMarker& newMa
 
     if (auto* renderer = node->renderer()) {
         // FIXME: Factor the marker painting code out of InlineTextBox and teach simple line layout to use it.
-        if (renderer->isText())
-            toRenderText(*renderer).ensureLineBoxes();
-        else if (renderer->isRenderBlockFlow())
-            toRenderBlockFlow(*renderer).ensureLineBoxes();
+        if (is<RenderText>(*renderer))
+            downcast<RenderText>(*renderer).ensureLineBoxes();
+        else if (is<RenderBlockFlow>(*renderer))
+            downcast<RenderBlockFlow>(*renderer).ensureLineBoxes();
     }
 
     m_possiblyExistingMarkerTypes.add(newMarker.type());
index 4bba4d2..798a9c4 100644 (file)
@@ -55,11 +55,11 @@ using namespace HTMLNames;
 
 static bool hasInlineBoxWrapper(RenderObject& renderer)
 {
-    if (renderer.isBox() && toRenderBox(renderer).inlineBoxWrapper())
+    if (is<RenderBox>(renderer) && downcast<RenderBox>(renderer).inlineBoxWrapper())
         return true;
-    if (renderer.isText() && toRenderText(renderer).firstTextBox())
+    if (is<RenderText>(renderer) && downcast<RenderText>(renderer).firstTextBox())
         return true;
-    if (renderer.isLineBreak() && toRenderLineBreak(renderer).inlineBoxWrapper())
+    if (is<RenderLineBreak>(renderer) && downcast<RenderLineBreak>(renderer).inlineBoxWrapper())
         return true;
     return false;
 }
@@ -625,8 +625,8 @@ Position Position::upstream(EditingBoundaryCrossingRule rule) const
         }
 
         // return current position if it is in rendered text
-        if (renderer->isText()) {
-            auto& textRenderer = toRenderText(*renderer);
+        if (is<RenderText>(*renderer)) {
+            auto& textRenderer = downcast<RenderText>(*renderer);
             textRenderer.ensureLineBoxes();
 
             if (!textRenderer.firstTextBox())
@@ -757,8 +757,8 @@ Position Position::downstream(EditingBoundaryCrossingRule rule) const
         }
 
         // return current position if it is in rendered text
-        if (renderer->isText()) {
-            auto& textRenderer = toRenderText(*renderer);
+        if (is<RenderText>(*renderer)) {
+            auto& textRenderer = downcast<RenderText>(*renderer);
             textRenderer.ensureLineBoxes();
 
             if (!textRenderer.firstTextBox())
@@ -846,23 +846,23 @@ bool Position::hasRenderedNonAnonymousDescendantsWithHeight(const RenderElement&
     for (RenderObject* o = renderer.firstChild(); o && o != stop; o = o->nextInPreOrder()) {
         if (!o->nonPseudoNode())
             continue;
-        if (o->isText()) {
-            if (boundingBoxLogicalHeight(o, toRenderText(o)->linesBoundingBox()))
+        if (is<RenderText>(*o)) {
+            if (boundingBoxLogicalHeight(o, downcast<RenderText>(*o).linesBoundingBox()))
                 return true;
             continue;
         }
-        if (o->isLineBreak()) {
-            if (boundingBoxLogicalHeight(o, toRenderLineBreak(o)->linesBoundingBox()))
+        if (is<RenderLineBreak>(*o)) {
+            if (boundingBoxLogicalHeight(o, downcast<RenderLineBreak>(*o).linesBoundingBox()))
                 return true;
             continue;
         }
-        if (o->isBox()) {
-            if (toRenderBox(o)->pixelSnappedLogicalHeight())
+        if (is<RenderBox>(*o)) {
+            if (downcast<RenderBox>(*o).pixelSnappedLogicalHeight())
                 return true;
             continue;
         }
-        if (o->isRenderInline()) {
-            const RenderInline& renderInline = toRenderInline(*o);
+        if (is<RenderInline>(*o)) {
+            const RenderInline& renderInline = downcast<RenderInline>(*o);
             if (isEmptyInline(renderInline) && boundingBoxLogicalHeight(o, renderInline.linesBoundingBox()))
                 return true;
             continue;
@@ -926,8 +926,8 @@ bool Position::isCandidate() const
         // FIXME: The condition should be m_anchorType == PositionIsBeforeAnchor, but for now we still need to support legacy positions.
         return !m_offset && m_anchorType != PositionIsAfterAnchor && !nodeIsUserSelectNone(deprecatedNode()->parentNode());
 
-    if (renderer->isText())
-        return !nodeIsUserSelectNone(deprecatedNode()) && toRenderText(renderer)->containsCaretOffset(m_offset);
+    if (is<RenderText>(*renderer))
+        return !nodeIsUserSelectNone(deprecatedNode()) && downcast<RenderText>(*renderer).containsCaretOffset(m_offset);
 
     if (isRenderedTable(deprecatedNode()) || editingIgnoresContent(deprecatedNode()))
         return (atFirstEditingPositionForNode() || atLastEditingPositionForNode()) && !nodeIsUserSelectNone(deprecatedNode()->parentNode());
@@ -935,8 +935,8 @@ bool Position::isCandidate() const
     if (m_anchorNode->hasTagName(htmlTag))
         return false;
         
-    if (renderer->isRenderBlockFlow()) {
-        RenderBlockFlow& block = toRenderBlockFlow(*renderer);
+    if (is<RenderBlockFlow>(*renderer)) {
+        RenderBlockFlow& block = downcast<RenderBlockFlow>(*renderer);
         if (block.logicalHeight() || m_anchorNode->hasTagName(bodyTag)) {
             if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(block))
                 return atFirstEditingPositionForNode() && !Position::nodeIsUserSelectNone(deprecatedNode());
@@ -1004,14 +1004,14 @@ bool Position::rendersInDifferentPosition(const Position &pos) const
     if (!inSameEnclosingBlockFlowElement(deprecatedNode(), pos.deprecatedNode()))
         return true;
 
-    if (renderer->isText() && !toRenderText(renderer)->containsCaretOffset(m_offset))
+    if (is<RenderText>(*renderer) && !downcast<RenderText>(*renderer).containsCaretOffset(m_offset))
         return false;
 
-    if (posRenderer->isText() && !toRenderText(posRenderer)->containsCaretOffset(pos.m_offset))
+    if (is<RenderText>(*posRenderer) && !downcast<RenderText>(*posRenderer).containsCaretOffset(pos.m_offset))
         return false;
 
-    int thisRenderedOffset = renderer->isText() ? toRenderText(renderer)->countRenderedCharacterOffsetsUntil(m_offset) : m_offset;
-    int posRenderedOffset = posRenderer->isText() ? toRenderText(posRenderer)->countRenderedCharacterOffsetsUntil(pos.m_offset) : pos.m_offset;
+    int thisRenderedOffset = is<RenderText>(*renderer) ? downcast<RenderText>(*renderer).countRenderedCharacterOffsetsUntil(m_offset) : m_offset;
+    int posRenderedOffset = is<RenderText>(*posRenderer) ? downcast<RenderText>(*posRenderer).countRenderedCharacterOffsetsUntil(pos.m_offset) : pos.m_offset;
 
     if (renderer == posRenderer && thisRenderedOffset == posRenderedOffset)
         return false;
@@ -1109,16 +1109,16 @@ static InlineTextBox* searchAheadForBetterMatch(RenderObject* renderer)
     RenderBlock* container = renderer->containingBlock();
     RenderObject* next = renderer;
     while ((next = next->nextInPreOrder(container))) {
-        if (next->isRenderBlock())
-            return 0;
+        if (is<RenderBlock>(*next))
+            return nullptr;
         if (next->isBR())
-            return 0;
+            return nullptr;
         if (isNonTextLeafChild(next))
-            return 0;
-        if (next->isText()) {
-            InlineTextBox* match = 0;
+            return nullptr;
+        if (is<RenderText>(*next)) {
+            InlineTextBox* match = nullptr;
             int minOffset = INT_MAX;
-            for (InlineTextBox* box = toRenderText(next)->firstTextBox(); box; box = box->nextTextBox()) {
+            for (InlineTextBox* box = downcast<RenderText>(*next).firstTextBox(); box; box = box->nextTextBox()) {
                 int caretMinOffset = box->caretMinOffset();
                 if (caretMinOffset < minOffset) {
                     match = box;
@@ -1129,7 +1129,7 @@ static InlineTextBox* searchAheadForBetterMatch(RenderObject* renderer)
                 return match;
         }
     }
-    return 0;
+    return nullptr;
 }
 
 static Position downstreamIgnoringEditingBoundaries(Position position)
@@ -1159,14 +1159,14 @@ void Position::getInlineBoxAndOffset(EAffinity affinity, TextDirection primaryDi
 
     if (renderer->isBR())
         inlineBox = !caretOffset ? toRenderLineBreak(renderer)->inlineBoxWrapper() : nullptr;
-    else if (renderer->isText()) {
-        auto textRenderer = toRenderText(renderer);
-        textRenderer->ensureLineBoxes();
+    else if (is<RenderText>(*renderer)) {
+        auto& textRenderer = downcast<RenderText>(*renderer);
+        textRenderer.ensureLineBoxes();
 
         InlineTextBox* box;
-        InlineTextBox* candidate = 0;
+        InlineTextBox* candidate = nullptr;
 
-        for (box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
+        for (box = textRenderer.firstTextBox(); box; box = box->nextTextBox()) {
             int caretMinOffset = box->caretMinOffset();
             int caretMaxOffset = box->caretMaxOffset();
 
@@ -1185,15 +1185,15 @@ void Position::getInlineBoxAndOffset(EAffinity affinity, TextDirection primaryDi
 
             candidate = box;
         }
-        if (candidate && candidate == textRenderer->lastTextBox() && affinity == DOWNSTREAM) {
-            box = searchAheadForBetterMatch(textRenderer);
+        if (candidate && candidate == textRenderer.lastTextBox() && affinity == DOWNSTREAM) {
+            box = searchAheadForBetterMatch(&textRenderer);
             if (box)
                 caretOffset = box->caretMinOffset();
         }
         inlineBox = box ? box : candidate;
     } else {
-        inlineBox = 0;
-        if (canHaveChildrenForEditing(deprecatedNode()) && renderer->isRenderBlockFlow() && hasRenderedNonAnonymousDescendantsWithHeight(toRenderBlock(*renderer))) {
+        inlineBox = nullptr;
+        if (canHaveChildrenForEditing(deprecatedNode()) && is<RenderBlockFlow>(*renderer) && hasRenderedNonAnonymousDescendantsWithHeight(downcast<RenderBlockFlow>(*renderer))) {
             // Try a visually equivalent position with possibly opposite editability. This helps in case |this| is in
             // an editable block but surrounded by non-editable positions. It acts to negate the logic at the beginning
             // of RenderObject::createVisiblePosition().
@@ -1207,8 +1207,8 @@ void Position::getInlineBoxAndOffset(EAffinity affinity, TextDirection primaryDi
             equivalent.getInlineBoxAndOffset(UPSTREAM, primaryDirection, inlineBox, caretOffset);
             return;
         }
-        if (renderer->isBox()) {
-            inlineBox = toRenderBox(renderer)->inlineBoxWrapper();
+        if (is<RenderBox>(*renderer)) {
+            inlineBox = downcast<RenderBox>(*renderer).inlineBoxWrapper();
             if (!inlineBox || (caretOffset > inlineBox->caretMinOffset() && caretOffset < inlineBox->caretMaxOffset()))
                 return;
         }
index b31a1b8..c8de033 100644 (file)
 #include "config.h"
 #include "PositionIterator.h"
 
+#include "HTMLBodyElement.h"
 #include "HTMLElement.h"
+#include "HTMLHtmlElement.h"
 #include "HTMLNames.h"
-#include "RenderBlock.h"
+#include "RenderBlockFlow.h"
 #include "RenderText.h"
 #include "htmlediting.h"
 
@@ -154,15 +156,15 @@ bool PositionIterator::isCandidate() const
     if (renderer->isBR())
         return !m_offsetInAnchor && !Position::nodeIsUserSelectNone(m_anchorNode->parentNode());
 
-    if (renderer->isText())
-        return !Position::nodeIsUserSelectNone(m_anchorNode) && toRenderText(renderer)->containsCaretOffset(m_offsetInAnchor);
+    if (is<RenderText>(*renderer))
+        return !Position::nodeIsUserSelectNone(m_anchorNode) && downcast<RenderText>(*renderer).containsCaretOffset(m_offsetInAnchor);
 
     if (isRenderedTable(m_anchorNode) || editingIgnoresContent(m_anchorNode))
         return (atStartOfNode() || atEndOfNode()) && !Position::nodeIsUserSelectNone(m_anchorNode->parentNode());
 
-    if (!m_anchorNode->hasTagName(htmlTag) && renderer->isRenderBlockFlow()) {
-        RenderBlock& block = toRenderBlock(*renderer);
-        if (block.logicalHeight() || m_anchorNode->hasTagName(bodyTag)) {
+    if (!is<HTMLHtmlElement>(*m_anchorNode) && is<RenderBlockFlow>(*renderer)) {
+        RenderBlockFlow& block = downcast<RenderBlockFlow>(*renderer);
+        if (block.logicalHeight() || is<HTMLBodyElement>(*m_anchorNode)) {
             if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(block))
                 return atStartOfNode() && !Position::nodeIsUserSelectNone(m_anchorNode);
             return m_anchorNode->hasEditableStyle() && !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).atEditingBoundary();
index ce32f69..6e4f41a 100644 (file)
@@ -1614,16 +1614,16 @@ void Range::textRects(Vector<IntRect>& rects, bool useSelectionHeight, RangeInFi
 
     Node* stopNode = pastLastNode();
     for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(node)) {
-        RenderObject* r = node->renderer();
-        if (!r)
+        RenderObject* renderer = node->renderer();
+        if (!renderer)
             continue;
         bool isFixed = false;
-        if (r->isBR())
-            r->absoluteRects(rects, flooredLayoutPoint(r->localToAbsolute()));
-        else if (r->isText()) {
+        if (renderer->isBR())
+            renderer->absoluteRects(rects, flooredLayoutPoint(renderer->localToAbsolute()));
+        else if (is<RenderText>(*renderer)) {
             int startOffset = node == startContainer ? m_start.offset() : 0;
             int endOffset = node == endContainer ? m_end.offset() : std::numeric_limits<int>::max();
-            rects.appendVector(toRenderText(r)->absoluteRectsForRange(startOffset, endOffset, useSelectionHeight, &isFixed));
+            rects.appendVector(downcast<RenderText>(*renderer).absoluteRectsForRange(startOffset, endOffset, useSelectionHeight, &isFixed));
         } else
             continue;
         allFixed &= isFixed;
@@ -1650,16 +1650,16 @@ void Range::textQuads(Vector<FloatQuad>& quads, bool useSelectionHeight, RangeIn
 
     Node* stopNode = pastLastNode();
     for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(node)) {
-        RenderObject* r = node->renderer();
-        if (!r)
+        RenderObject* renderer = node->renderer();
+        if (!renderer)
             continue;
         bool isFixed = false;
-        if (r->isBR())
-            r->absoluteQuads(quads, &isFixed);
-        else if (r->isText()) {
+        if (renderer->isBR())
+            renderer->absoluteQuads(quads, &isFixed);
+        else if (is<RenderText>(*renderer)) {
             int startOffset = node == startContainer ? m_start.offset() : 0;
             int endOffset = node == endContainer ? m_end.offset() : std::numeric_limits<int>::max();
-            quads.appendVector(toRenderText(r)->absoluteQuadsForRange(startOffset, endOffset, useSelectionHeight, &isFixed));
+            quads.appendVector(downcast<RenderText>(*renderer).absoluteQuadsForRange(startOffset, endOffset, useSelectionHeight, &isFixed));
         } else
             continue;
         allFixed &= isFixed;
@@ -2233,13 +2233,12 @@ void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const
                 quads.appendVector(elementQuads);
             }
         } else if (is<Text>(*node)) {
-            if (RenderObject* renderer = downcast<Text>(*node).renderer()) {
-                const RenderText& renderText = toRenderText(*renderer);
+            if (RenderText* renderText = downcast<Text>(*node).renderer()) {
                 int startOffset = (node == startContainer) ? m_start.offset() : 0;
                 int endOffset = (node == endContainer) ? m_end.offset() : INT_MAX;
                 
-                auto textQuads = renderText.absoluteQuadsForRange(startOffset, endOffset);
-                ownerDocument().adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(textQuads, renderText.style());
+                auto textQuads = renderText->absoluteQuadsForRange(startOffset, endOffset);
+                ownerDocument().adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(textQuads, renderText->style());
 
                 quads.appendVector(textQuads);
             }
index e824210..8c76621 100644 (file)
@@ -1525,15 +1525,15 @@ void FrameSelection::debugRenderer(RenderObject* renderer, bool selected) const
     if (is<Element>(*renderer->node())) {
         Element& element = downcast<Element>(*renderer->node());
         fprintf(stderr, "%s%s\n", selected ? "==> " : "    ", element.localName().string().utf8().data());
-    } else if (renderer->isText()) {
-        RenderText* textRenderer = toRenderText(renderer);
-        if (!textRenderer->textLength() || !textRenderer->firstTextBox()) {
+    } else if (is<RenderText>(*renderer)) {
+        RenderText& textRenderer = downcast<RenderText>(*renderer);
+        if (!textRenderer.textLength() || !textRenderer.firstTextBox()) {
             fprintf(stderr, "%s#text (empty)\n", selected ? "==> " : "    ");
             return;
         }
         
         static const int max = 36;
-        String text = textRenderer->text();
+        String text = textRenderer.text();
         int textLength = text.length();
         if (selected) {
             int offset = 0;
@@ -1543,7 +1543,7 @@ void FrameSelection::debugRenderer(RenderObject* renderer, bool selected) const
                 offset = m_selection.end().computeOffsetInContainerNode();
 
             int pos;
-            InlineTextBox* box = textRenderer->findNextInlineTextBox(offset, pos);
+            InlineTextBox* box = textRenderer.findNextInlineTextBox(offset, pos);
             text = text.substring(box->start(), box->len());
             
             String show;
index 8eb4f00..725a802 100644 (file)
@@ -490,8 +490,8 @@ static bool hasVisibleTextNode(RenderText& renderer)
 {
     if (renderer.style().visibility() == VISIBLE)
         return true;
-    if (renderer.isTextFragment()) {
-        if (auto firstLetter = toRenderTextFragment(renderer).firstLetter()) {
+    if (is<RenderTextFragment>(renderer)) {
+        if (auto firstLetter = downcast<RenderTextFragment>(renderer).firstLetter()) {
             if (firstLetter->style().visibility() == VISIBLE)
                 return true;
         }
@@ -518,8 +518,8 @@ bool TextIterator::handleTextNode()
             emitCharacter(' ', textNode, nullptr, runStart, runStart);
             return false;
         }
-        if (!m_handledFirstLetter && renderer.isTextFragment() && !m_offset) {
-            handleTextNodeFirstLetter(toRenderTextFragment(renderer));
+        if (!m_handledFirstLetter && is<RenderTextFragment>(renderer) && !m_offset) {
+            handleTextNodeFirstLetter(downcast<RenderTextFragment>(renderer));
             if (m_firstLetterText) {
                 String firstLetter = m_firstLetterText->text();
                 emitText(textNode, *m_firstLetterText, m_offset, m_offset + firstLetter.length());
@@ -575,9 +575,9 @@ bool TextIterator::handleTextNode()
     if (renderer.firstTextBox())
         m_textBox = renderer.firstTextBox();
 
-    bool shouldHandleFirstLetter = !m_handledFirstLetter && renderer.isTextFragment() && !m_offset;
+    bool shouldHandleFirstLetter = !m_handledFirstLetter && is<RenderTextFragment>(renderer) && !m_offset;
     if (shouldHandleFirstLetter)
-        handleTextNodeFirstLetter(toRenderTextFragment(renderer));
+        handleTextNodeFirstLetter(downcast<RenderTextFragment>(renderer));
 
     if (!renderer.firstTextBox() && rendererText.length() && !shouldHandleFirstLetter) {
         if (renderer.style().visibility() != VISIBLE && !(m_behavior & TextIteratorIgnoresStyleVisibility))
@@ -912,8 +912,8 @@ static int maxOffsetIncludingCollapsedSpaces(Node& node)
 {
     int offset = caretMaxOffset(&node);
     if (auto* renderer = node.renderer()) {
-        if (renderer->isText())
-            offset += collapsedSpaceLength(toRenderText(*renderer), offset);
+        if (is<RenderText>(*renderer))
+            offset += collapsedSpaceLength(downcast<RenderText>(*renderer), offset);
     }
     return offset;
 }
@@ -1301,31 +1301,31 @@ bool SimplifiedBackwardsTextIterator::handleTextNode()
 
 RenderText* SimplifiedBackwardsTextIterator::handleFirstLetter(int& startOffset, int& offsetInNode)
 {
-    RenderText* renderer = toRenderText(m_node->renderer());
+    RenderText& renderer = downcast<RenderText>(*m_node->renderer());
     startOffset = (m_node == m_startContainer) ? m_startOffset : 0;
 
-    if (!renderer->isTextFragment()) {
+    if (!is<RenderTextFragment>(renderer)) {
         offsetInNode = 0;
-        return renderer;
+        return &renderer;
     }
 
-    RenderTextFragment* fragment = toRenderTextFragment(renderer);
-    int offsetAfterFirstLetter = fragment->start();
+    RenderTextFragment& fragment = downcast<RenderTextFragment>(renderer);
+    int offsetAfterFirstLetter = fragment.start();
     if (startOffset >= offsetAfterFirstLetter) {
         ASSERT(!m_shouldHandleFirstLetter);
         offsetInNode = offsetAfterFirstLetter;
-        return renderer;
+        return &renderer;
     }
 
     if (!m_shouldHandleFirstLetter && startOffset + offsetAfterFirstLetter < m_offset) {
         m_shouldHandleFirstLetter = true;
         offsetInNode = offsetAfterFirstLetter;
-        return renderer;
+        return &renderer;
     }
 
     m_shouldHandleFirstLetter = false;
     offsetInNode = 0;
-    return firstRenderTextInFirstLetter(fragment->firstLetter());
+    return firstRenderTextInFirstLetter(fragment.firstLetter());
 }
 
 bool SimplifiedBackwardsTextIterator::handleReplacedElement()
index eb5de06..ddecf29 100644 (file)
@@ -1142,11 +1142,11 @@ VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
         if (r->isBR() || isBlock(n))
             break;
 
-        if (r->isText() && toRenderText(r)->hasRenderedText()) {
+        if (is<RenderText>(*r) && downcast<RenderText>(*r).hasRenderedText()) {
             ASSERT_WITH_SECURITY_IMPLICATION(is<Text>(*n));
             type = Position::PositionIsOffsetInAnchor;
             if (style.preserveNewline()) {
-                StringImpl& text = *toRenderText(r)->text();
+                StringImpl& text = *downcast<RenderText>(*r).text();
                 int i = text.length();
                 int o = offset;
                 if (n == startNode && o < i)
@@ -1225,11 +1225,11 @@ VisiblePosition endOfParagraph(const VisiblePosition& c, EditingBoundaryCrossing
             break;
 
         // FIXME: We avoid returning a position where the renderer can't accept the caret.
-        if (r->isText() && toRenderText(r)->hasRenderedText()) {
+        if (is<RenderText>(*r) && downcast<RenderText>(*r).hasRenderedText()) {
             ASSERT_WITH_SECURITY_IMPLICATION(is<Text>(*n));
             type = Position::PositionIsOffsetInAnchor;
             if (style.preserveNewline()) {
-                StringImpl& text = *toRenderText(r)->text();
+                StringImpl& text = *downcast<RenderText>(*r).text();
                 int o = n == startNode ? offset : 0;
                 int length = text.length();
                 for (int i = o; i < length; ++i) {
index 533fa0d..be6b600 100644 (file)
@@ -2237,8 +2237,8 @@ void FrameView::repaintContentRectangle(const IntRect& r)
 static unsigned countRenderedCharactersInRenderObjectWithThreshold(const RenderObject& renderer, unsigned countSoFar, unsigned threshold)
 {
     // FIXME: Consider writing this using RenderObject::nextInPreOrder() instead of using recursion.
-    if (renderer.isText())
-        countSoFar += toRenderText(renderer).text()->length();
+    if (is<RenderText>(renderer))
+        countSoFar += downcast<RenderText>(renderer).text()->length();
 
     for (RenderObject* child = renderer.firstChildSlow(); child; child = child->nextSibling()) {
         if (countSoFar >= threshold)
index a6f3919..fd3e022 100644 (file)
@@ -41,7 +41,7 @@ BidiRun::BidiRun(int start, int stop, RenderObject& renderer, BidiContext* conte
 #ifndef NDEBUG
     bidiRunCounter.increment();
 #endif
-    ASSERT(!m_renderer.isText() || static_cast<unsigned>(stop) <= toRenderText(m_renderer).textLength());
+    ASSERT(!is<RenderText>(m_renderer) || static_cast<unsigned>(stop) <= downcast<RenderText>(m_renderer).textLength());
     // Stored in base class to save space.
     m_hasHyphen = false;
 }
index 43e9c76..fd96419 100644 (file)
@@ -31,7 +31,7 @@ namespace WebCore {
 
 UCharDirection InlineIterator::surrogateTextDirection(UChar currentCodeUnit) const
 {
-    RenderText& text = toRenderText(*m_renderer);
+    RenderText& text = downcast<RenderText>(*m_renderer);
     UChar lead;
     UChar trail;
     if (U16_IS_LEAD(currentCodeUnit)) {
index 0115c1c..f08681a 100644 (file)
@@ -83,13 +83,12 @@ public:
     void fastDecrement();
     bool atEnd() const;
 
-    inline bool atTextParagraphSeparator()
+    bool atTextParagraphSeparator() const
     {
-        return m_renderer && m_renderer->preservesNewline() && m_renderer->isText() && toRenderText(m_renderer)->textLength()
-            && toRenderText(m_renderer)->characterAt(m_pos) == '\n';
+        return is<RenderText>(m_renderer) && m_renderer->preservesNewline() && downcast<RenderText>(*m_renderer).characterAt(m_pos) == '\n';
     }
     
-    inline bool atParagraphSeparator()
+    bool atParagraphSeparator() const
     {
         return (m_renderer && m_renderer->isBR()) || atTextParagraphSeparator();
     }
@@ -195,15 +194,15 @@ enum EmptyInlineBehavior {
 
 static bool isEmptyInline(const RenderInline& renderer)
 {
-    for (RenderObject* curr = renderer.firstChild(); curr; curr = curr->nextSibling()) {
-        if (curr->isFloatingOrOutOfFlowPositioned())
+    for (RenderObject* current = renderer.firstChild(); current; current = current->nextSibling()) {
+        if (current->isFloatingOrOutOfFlowPositioned())
             continue;
-        if (curr->isText()) {
-            if (!toRenderText(curr)->isAllCollapsibleWhitespace())
+        if (is<RenderText>(*current)) {
+            if (!downcast<RenderText>(*current).isAllCollapsibleWhitespace())
                 return false;
             continue;
         }
-        if (!curr->isRenderInline() || !isEmptyInline(toRenderInline(*curr)))
+        if (!is<RenderInline>(*current) || !isEmptyInline(downcast<RenderInline>(*current)))
             return false;
     }
     return true;
@@ -331,9 +330,8 @@ static inline RenderObject* bidiFirstIncludingEmptyInlines(RenderElement& root)
 inline void InlineIterator::fastIncrementInTextNode()
 {
     ASSERT(m_renderer);
-    ASSERT(m_renderer->isText());
-    ASSERT(m_pos <= toRenderText(m_renderer)->textLength());
-    m_pos++;
+    ASSERT(m_pos <= downcast<RenderText>(*m_renderer).textLength());
+    ++m_pos;
 }
 
 inline void InlineIterator::setOffset(unsigned position)
@@ -384,9 +382,9 @@ inline void InlineIterator::increment(InlineBidiResolver* resolver)
 {
     if (!m_renderer)
         return;
-    if (m_renderer->isText()) {
+    if (is<RenderText>(*m_renderer)) {
         fastIncrementInTextNode();
-        if (m_pos < toRenderText(m_renderer)->textLength())
+        if (m_pos < downcast<RenderText>(*m_renderer).textLength())
             return;
     }
     // bidiNext can return 0, so use moveTo instead of moveToStartOf
@@ -409,10 +407,10 @@ inline bool InlineIterator::atEnd() const
 
 inline UChar InlineIterator::characterAt(unsigned index) const
 {
-    if (!m_renderer || !m_renderer->isText())
+    if (!is<RenderText>(m_renderer))
         return 0;
 
-    return toRenderText(m_renderer)->characterAt(index);
+    return downcast<RenderText>(*m_renderer).characterAt(index);
 }
 
 inline UChar InlineIterator::current() const
@@ -430,8 +428,8 @@ ALWAYS_INLINE UCharDirection InlineIterator::direction() const
     if (UNLIKELY(!m_renderer))
         return U_OTHER_NEUTRAL;
 
-    if (LIKELY(m_renderer->isText())) {
-        UChar codeUnit = toRenderText(*m_renderer).characterAt(m_pos);
+    if (LIKELY(is<RenderText>(*m_renderer))) {
+        UChar codeUnit = downcast<RenderText>(*m_renderer).characterAt(m_pos);
         if (LIKELY(U16_IS_SINGLE(codeUnit)))
             return u_charDirection(codeUnit);
         return surrogateTextDirection(codeUnit);
index f5f1ac8..38c6e74 100644 (file)
@@ -51,7 +51,7 @@ public:
 
     virtual ~InlineTextBox();
 
-    RenderText& renderer() const { return toRenderText(InlineBox::renderer()); }
+    RenderText& renderer() const { return downcast<RenderText>(InlineBox::renderer()); }
     const RenderStyle& lineStyle() const { return isFirstLine() ? renderer().firstLineStyle() : renderer().style(); }
 
     InlineTextBox* prevTextBox() const { return m_prevTextBox; }
index e495c18..e12ebb5 100644 (file)
@@ -3151,14 +3151,14 @@ void RenderBlock::updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderO
         // Move the first letter into the new renderer.
         LayoutStateDisabler layoutStateDisabler(&view());
         while (RenderObject* child = firstLetter->firstChild()) {
-            if (child->isText())
-                toRenderText(child)->removeAndDestroyTextBoxes();
+            if (is<RenderText>(*child))
+                downcast<RenderText>(*child).removeAndDestroyTextBoxes();
             firstLetter->removeChild(*child);
-            newFirstLetter->addChild(child, 0);
+            newFirstLetter->addChild(child, nullptr);
         }
 
         RenderObject* nextSibling = firstLetter->nextSibling();
-        if (RenderTextFragment* remainingText = toRenderBoxModelObject(firstLetter)->firstLetterRemainingText()) {
+        if (RenderTextFragment* remainingText = downcast<RenderBoxModelObject>(*firstLetter).firstLetterRemainingText()) {
             ASSERT(remainingText->isAnonymous() || remainingText->textNode()->renderer() == remainingText);
             // Replace the old renderer with the new one.
             remainingText->setFirstLetter(*newFirstLetter);
@@ -3314,14 +3314,14 @@ void RenderBlock::updateFirstLetter()
         return;
     }
 
-    if (!firstLetterObj->isText())
+    if (!is<RenderText>(*firstLetterObj))
         return;
 
     // Our layout state is not valid for the repaints we are going to trigger by
     // adding and removing children of firstLetterContainer.
     LayoutStateDisabler layoutStateDisabler(&view());
 
-    createFirstLetterRenderer(firstLetterContainer, toRenderText(firstLetterObj));
+    createFirstLetterRenderer(firstLetterContainer, downcast<RenderText>(firstLetterObj));
 }
 
 LayoutUnit RenderBlock::paginationStrut() const
index c737714..d85bd82 100644 (file)
@@ -3500,7 +3500,7 @@ void RenderBlockFlow::deleteLineBoxesBeforeSimpleLineLayout()
 {
     ASSERT(m_lineLayoutPath == SimpleLinesPath);
     lineBoxes().deleteLineBoxes();
-    toRenderText(firstChild())->deleteLineBoxesBeforeSimpleLineLayout();
+    downcast<RenderText>(*firstChild()).deleteLineBoxesBeforeSimpleLineLayout();
 }
 
 void RenderBlockFlow::ensureLineBoxes()
@@ -3555,10 +3555,10 @@ void RenderBlockFlow::materializeRareBlockFlowData()
 #if ENABLE(IOS_TEXT_AUTOSIZING)
 inline static bool isVisibleRenderText(RenderObject* renderer)
 {
-    if (!renderer->isText())
+    if (!is<RenderText>(*renderer))
         return false;
-    RenderText* renderText = toRenderText(renderer);
-    return !renderText->linesBoundingBox().isEmpty() && !renderText->text()->containsOnlyWhitespace();
+    RenderText& renderText = downcast<RenderText>(*renderer);
+    return !renderText.linesBoundingBox().isEmpty() && !renderText.text()->containsOnlyWhitespace();
 }
 
 inline static bool resizeTextPermitted(RenderObject* render)
@@ -3638,8 +3638,8 @@ void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth)
     
     for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) {
         if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) {
-            RenderText* text = toRenderText(descendent);
-            RenderStyle& oldStyle = text->style();
+            RenderText& text = downcast<RenderText>(*descendent);
+            RenderStyle& oldStyle = text.style();
             FontDescription fontDescription = oldStyle.fontDescription();
             float specifiedSize = fontDescription.specifiedSize();
             float scaledSize = roundf(specifiedSize * scale);
@@ -3654,8 +3654,8 @@ void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth)
                 float candidateNewSize = 0;
                 float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize);
                 candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
-                if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text->textNode() && oldStyle.textSizeAdjust().isAuto())
-                    document().addAutoSizingNode(text->textNode(), candidateNewSize);
+                if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
+                    document().addAutoSizingNode(text.textNode(), candidateNewSize);
             }
         }
     }
@@ -3931,12 +3931,12 @@ static LayoutUnit getBorderPaddingMargin(const RenderBoxModelObject& child, bool
 
 static inline void stripTrailingSpace(float& inlineMax, float& inlineMin, RenderObject* trailingSpaceChild)
 {
-    if (trailingSpaceChild && trailingSpaceChild->isText()) {
+    if (is<RenderText>(trailingSpaceChild)) {
         // Collapse away the trailing space at the end of a block.
-        RenderText* t = toRenderText(trailingSpaceChild);
+        RenderText& renderText = downcast<RenderText>(*trailingSpaceChild);
         const UChar space = ' ';
-        const Font& font = t->style().font(); // FIXME: This ignores first-line.
-        float spaceWidth = font.width(RenderBlock::constructTextRun(t, font, &space, 1, t->style()));
+        const Font& font = renderText.style().font(); // FIXME: This ignores first-line.
+        float spaceWidth = font.width(RenderBlock::constructTextRun(&renderText, font, &space, 1, renderText.style()));
         inlineMax -= spaceWidth + font.wordSpacing();
         if (inlineMin > inlineMax)
             inlineMin = inlineMax;
@@ -3960,7 +3960,7 @@ void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogical
     // If we are at the start of a line, we want to ignore all white-space.
     // Also strip spaces if we previously had text that ended in a trailing space.
     bool stripFrontSpaces = true;
-    RenderObject* trailingSpaceChild = 0;
+    RenderObject* trailingSpaceChild = nullptr;
 
     // Firefox and Opera will allow a table cell to grow to fit an image inside it under
     // very specific cirucumstances (in order to match common WinIE renderings). 
@@ -4121,14 +4121,14 @@ void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogical
                 // We are no longer stripping whitespace at the start of a line.
                 if (!child->isFloating()) {
                     stripFrontSpaces = false;
-                    trailingSpaceChild = 0;
+                    trailingSpaceChild = nullptr;
                 }
-            } else if (child->isText()) {
+            } else if (is<RenderText>(*child)) {
                 // Case (3). Text.
-                RenderText* t = toRenderText(child);
+                RenderText& renderText = downcast<RenderText>(*child);
 
-                if (t->style().hasTextCombine() && t->isCombineText())
-                    toRenderCombineText(*t).combineText();
+                if (renderText.style().hasTextCombine() && renderText.isCombineText())
+                    downcast<RenderCombineText>(renderText).combineText();
 
                 // Determine if we have a breakable character. Pass in
                 // whether or not we should ignore any spaces at the front
@@ -4139,7 +4139,7 @@ void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogical
                 float beginMin, endMin;
                 bool beginWS, endWS;
                 float beginMax, endMax;
-                t->trimmedPrefWidths(inlineMax, beginMin, beginWS, endMin, endWS,
+                renderText.trimmedPrefWidths(inlineMax, beginMin, beginWS, endMin, endWS,
                                      hasBreakableChar, hasBreak, beginMax, endMax,
                                      childMin, childMax, stripFrontSpaces);
 
index 6127882..b82e756 100644 (file)
@@ -136,41 +136,41 @@ RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
     return rootBox;
 }
 
-static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false)
+static inline InlineBox* createInlineBoxForRenderer(RenderObject* renderer, bool isRootLineBox, bool isOnlyRun = false)
 {
     if (isRootLineBox)
-        return toRenderBlockFlow(obj)->createAndAppendRootInlineBox();
+        return downcast<RenderBlockFlow>(*renderer).createAndAppendRootInlineBox();
 
-    if (obj->isText())
-        return toRenderText(obj)->createInlineTextBox();
+    if (is<RenderText>(*renderer))
+        return downcast<RenderText>(*renderer).createInlineTextBox();
 
-    if (obj->isBox()) {
+    if (is<RenderBox>(*renderer)) {
         // FIXME: This is terrible. This branch returns an *owned* pointer!
-        return toRenderBox(obj)->createInlineBox().release();
+        return downcast<RenderBox>(*renderer).createInlineBox().release();
     }
 
-    if (obj->isLineBreak()) {
+    if (is<RenderLineBreak>(*renderer)) {
         // FIXME: This is terrible. This branch returns an *owned* pointer!
-        auto inlineBox = toRenderLineBreak(obj)->createInlineBox().release();
+        auto inlineBox = downcast<RenderLineBreak>(*renderer).createInlineBox().release();
         // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
         // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
-        inlineBox->setBehavesLikeText(isOnlyRun || obj->document().inNoQuirksMode() || obj->isLineBreakOpportunity());
+        inlineBox->setBehavesLikeText(isOnlyRun || renderer->document().inNoQuirksMode() || renderer->isLineBreakOpportunity());
         return inlineBox;
     }
 
-    return toRenderInline(obj)->createAndAppendInlineFlowBox();
+    return downcast<RenderInline>(*renderer).createAndAppendInlineFlowBox();
 }
 
 static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout)
 {
-    if (renderer.isText()) {
-        RenderText& renderText = toRenderText(renderer);
+    if (is<RenderText>(renderer)) {
+        RenderText& renderText = downcast<RenderText>(renderer);
         updateCounterIfNeeded(renderText);
         renderText.dirtyLineBoxes(fullLayout);
-    } else if (renderer.isLineBreak())
-        toRenderLineBreak(renderer).dirtyLineBoxes(fullLayout);
+    } else if (is<RenderLineBreak>(renderer))
+        downcast<RenderLineBreak>(renderer).dirtyLineBoxes(fullLayout);
     else
-        toRenderInline(renderer).dirtyLineBoxes(fullLayout);
+        downcast<RenderInline>(renderer).dirtyLineBoxes(fullLayout);
 }
 
 static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
@@ -262,10 +262,10 @@ static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
     if (!run)
         return true;
     unsigned pos = run->stop();
-    const RenderObject& r = run->renderer();
-    if (!r.isText())
+    const RenderObject& renderer = run->renderer();
+    if (!is<RenderText>(renderer))
         return false;
-    const RenderText& renderText = toRenderText(r);
+    const RenderText& renderText = downcast<RenderText>(renderer);
     unsigned length = renderText.textLength();
     if (pos >= length)
         return true;
@@ -669,7 +669,7 @@ BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBo
     unsigned expansionOpportunityCount = 0;
     bool isAfterExpansion = true;
     Vector<unsigned, 16> expansionOpportunities;
-    RenderObject* previousObject = 0;
+    RenderObject* previousObject = nullptr;
 
     BidiRun* r = firstRun;
     for (; r; r = r->next()) {
@@ -677,23 +677,23 @@ BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBo
             continue; // Positioned objects are only participating to figure out their
                       // correct static x position.  They have no effect on the width.
                       // Similarly, line break boxes have no effect on the width.
-        if (r->renderer().isText()) {
-            RenderText& rt = toRenderText(r->renderer());
+        if (is<RenderText>(r->renderer())) {
+            RenderText& renderText = downcast<RenderText>(r->renderer());
             if (textAlign == JUSTIFY && r != trailingSpaceRun) {
                 if (!isAfterExpansion)
                     toInlineTextBox(r->box())->setCanHaveLeadingExpansion(true);
-                unsigned opportunitiesInRun = Font::expansionOpportunityCount(rt.stringView(r->m_start, r->m_stop), r->box()->direction(), isAfterExpansion);
+                unsigned opportunitiesInRun = Font::expansionOpportunityCount(renderText.stringView(r->m_start, r->m_stop), r->box()->direction(), isAfterExpansion);
                 expansionOpportunities.append(opportunitiesInRun);
                 expansionOpportunityCount += opportunitiesInRun;
             }
 
-            if (int length = rt.textLength()) {
-                if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt.characterAt(r->m_start)))
-                    totalLogicalWidth += lineStyle(*rt.parent(), lineInfo).font().wordSpacing();
-                needsWordSpacing = !isSpaceOrNewline(rt.characterAt(r->m_stop - 1)) && r->m_stop == length;
+            if (int length = renderText.textLength()) {
+                if (!r->m_start && needsWordSpacing && isSpaceOrNewline(renderText.characterAt(r->m_start)))
+                    totalLogicalWidth += lineStyle(*renderText.parent(), lineInfo).font().wordSpacing();
+                needsWordSpacing = !isSpaceOrNewline(renderText.characterAt(r->m_stop - 1)) && r->m_stop == length;
             }
 
-            setLogicalWidthForTextRun(lineBox, r, &rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
+            setLogicalWidthForTextRun(lineBox, r, &renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
         } else {
             isAfterExpansion = false;
             if (!r->renderer().isRenderInline()) {
@@ -741,12 +741,12 @@ void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineB
 
         // Position is used to properly position both replaced elements and
         // to update the static normal flow x/y of positioned elements.
-        if (r->renderer().isText())
-            toRenderText(r->renderer()).positionLineBox(toInlineTextBox(box));
-        else if (r->renderer().isBox())
-            toRenderBox(r->renderer()).positionLineBox(toInlineElementBox(box));
-        else if (r->renderer().isLineBreak())
-            toRenderLineBreak(r->renderer()).replaceInlineBoxWrapper(toInlineElementBox(box));
+        if (is<RenderText>(r->renderer()))
+            downcast<RenderText>(r->renderer()).positionLineBox(toInlineTextBox(box));
+        else if (is<RenderBox>(r->renderer()))
+            downcast<RenderBox>(r->renderer()).positionLineBox(toInlineElementBox(box));
+        else if (is<RenderLineBreak>(r->renderer()))
+            downcast<RenderLineBreak>(r->renderer()).replaceInlineBoxWrapper(toInlineElementBox(box));
     }
     // Positioned objects and zero-length text nodes destroy their boxes in
     // position(), which unnecessarily dirties the line.
@@ -783,14 +783,14 @@ inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidi
     if (!bidiRuns.runCount()
         || !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
         || !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
-        return 0;
+        return nullptr;
 
     BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
     const RenderObject& lastObject = trailingSpaceRun->renderer();
-    if (!lastObject.isText())
-        return 0;
+    if (!is<RenderText>(lastObject))
+        return nullptr;
 
-    const RenderText& lastText = toRenderText(lastObject);
+    const RenderText& lastText = downcast<RenderText>(lastObject);
     int firstSpace;
     if (lastText.is8Bit())
         firstSpace = findFirstTrailingSpace(lastText, lastText.characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop());
@@ -798,7 +798,7 @@ inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidi
         firstSpace = findFirstTrailingSpace(lastText, lastText.characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop());
 
     if (firstSpace == trailingSpaceRun->stop())
-        return 0;
+        return nullptr;
 
     TextDirection direction = style().direction();
     bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun());
@@ -1561,10 +1561,11 @@ RootInlineBox* RenderBlockFlow::determineStartPosition(LineLayoutState& layoutSt
             // We have a dirty line.
             if (RootInlineBox* prevRootBox = curr->prevRootBox()) {
                 // We have a previous line.
-                if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength())))
+                if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (is<RenderText>(*prevRootBox->lineBreakObj()) && prevRootBox->lineBreakPos() >= downcast<RenderText>(*prevRootBox->lineBreakObj()).textLength()))) {
                     // The previous line didn't break cleanly or broke at a newline
                     // that has been deleted, so treat it as dirty too.
                     curr = prevRootBox;
+                }
             }
         } else {
             // No dirty lines were found.
index 1d0b6af..bafd84b 100644 (file)
@@ -2709,9 +2709,9 @@ void RenderBoxModelObject::moveChildrenTo(RenderBoxModelObject* toBoxModelObject
         // Check to make sure we're not saving the firstLetter as the nextSibling.
         // When the |child| object will be moved, its firstLetter will be recreated,
         // so saving it now in nextSibling would let us with a destroyed object.
-        if (child->isText() && toRenderText(child)->isTextFragment() && nextSibling && nextSibling->isText()) {
+        if (is<RenderTextFragment>(*child) && is<RenderText>(nextSibling)) {
             RenderObject* firstLetterObj = nullptr;
-            if (RenderBlock* block = toRenderTextFragment(child)->blockForAccompanyingFirstLetter()) {
+            if (RenderBlock* block = downcast<RenderTextFragment>(*child).blockForAccompanyingFirstLetter()) {
                 RenderElement* firstLetterContainer = nullptr;
                 block->getFirstLetter(firstLetterObj, firstLetterContainer, child);
             }
index cfa42bc..8f4f45e 100644 (file)
@@ -303,7 +303,7 @@ StyleDifference RenderElement::adjustStyleDifference(StyleDifference diff, unsig
 inline bool RenderElement::hasImmediateNonWhitespaceTextChildOrBorderOrOutline() const
 {
     for (auto& child : childrenOfType<RenderObject>(*this)) {
-        if (child.isText() && !toRenderText(child).isAllCollapsibleWhitespace())
+        if (is<RenderText>(child) && !downcast<RenderText>(child).isAllCollapsibleWhitespace())
             return true;
         if (child.style().hasOutline() || child.style().hasBorder())
             return true;
@@ -494,8 +494,8 @@ void RenderElement::addChild(RenderObject* newChild, RenderObject* beforeChild)
     } else
         insertChildInternal(newChild, beforeChild, NotifyChildren);
 
-    if (newChild->isText())
-        toRenderText(newChild)->styleDidChange(StyleDifferenceEqual, nullptr);
+    if (is<RenderText>(newChild))
+        downcast<RenderText>(*newChild).styleDidChange(StyleDifferenceEqual, nullptr);
 
     // SVG creates renderers for <g display="none">, as SVG requires children of hidden
     // <g>s to have renderers - at least that's how our implementation works. Consider:
index d1a1db3..f37f537 100644 (file)
@@ -570,31 +570,31 @@ void RenderInline::generateCulledLineBoxRects(GeneratorContext& context, const R
 
     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 @@ void RenderInline::generateCulledLineBoxRects(GeneratorContext& context, const R
                     }
                 }
             }
-        } 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 @@ void RenderInline::generateCulledLineBoxRects(GeneratorContext& context, const R
                 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 @@ IntRect RenderInline::linesBoundingBox() const
 
 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 @@ LayoutRect RenderInline::culledInlineVisualOverflowBoundingBox() const
     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 @@ void RenderInline::dirtyLineBoxes(bool fullLayout)
 
     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();
                 }
             }
         }
index 6281117..ce8e5f2 100644 (file)
@@ -53,6 +53,12 @@ public:
 
     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const override final;
 
+    virtual IntRect borderBoundingBox() const override final
+    {
+        IntRect boundingBox = linesBoundingBox();
+        return IntRect(0, 0, boundingBox.width(), boundingBox.height());
+    }
+
     IntRect linesBoundingBox() const;
     LayoutRect linesVisualOverflowBoundingBox() const;
     LayoutRect linesVisualOverflowBoundingBoxInRegion(const RenderRegion*) const;
@@ -148,12 +154,6 @@ private:
 
     virtual LayoutRect frameRectForStickyPositioning() const override final { return linesBoundingBox(); }
 
-    virtual IntRect borderBoundingBox() const override final
-    {
-        IntRect boundingBox = linesBoundingBox();
-        return IntRect(0, 0, boundingBox.width(), boundingBox.height());
-    }
-
     virtual std::unique_ptr<InlineFlowBox> createInlineFlowBox(); // Subclassed by RenderSVGInline
 
     virtual void dirtyLinesFromChangedChild(RenderObject* child) override final { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
index 98dd72a..49aff1c 100644 (file)
@@ -6286,16 +6286,16 @@ static bool hasPaintingNonLayerDescendants(const RenderElement& renderer, int de
         if (++siblingCount > maxSiblingCount)
             return true;
         
-        if (child.isText()) {
+        if (is<RenderText>(child)) {
             bool isSelectable = renderer.style().userSelect() != SELECT_NONE;
-            if (isSelectable || !toRenderText(child).isAllCollapsibleWhitespace())
+            if (isSelectable || !downcast<RenderText>(child).isAllCollapsibleWhitespace())
                 return true;
         }
         
-        if (!child.isRenderElement())
+        if (!is<RenderElement>(child))
             continue;
         
-        const RenderElement& renderElementChild = toRenderElement(child);
+        const RenderElement& renderElementChild = downcast<RenderElement>(child);
 
         if (renderElementChild.isRenderLayerModelObject() && toRenderLayerModelObject(renderElementChild).hasSelfPaintingLayer())
             continue;
index 836dce6..09276bb 100644 (file)
@@ -335,24 +335,23 @@ void RenderLineBoxList::dirtyLinesFromChangedChild(RenderBoxModelObject* contain
     // Try to figure out which line box we belong in.  First try to find a previous
     // line box by examining our siblings.  If we didn't find a line box, then use our 
     // parent's first line box.
-    RootInlineBox* box = 0;
-    RenderObject* curr = 0;
-    for (curr = child->previousSibling(); curr; curr = curr->previousSibling()) {
-        if (curr->isFloatingOrOutOfFlowPositioned())
+    RootInlineBox* box = nullptr;
+    RenderObject* current;
+    for (current = child->previousSibling(); current; current = current->previousSibling()) {
+        if (current->isFloatingOrOutOfFlowPositioned())
             continue;
 
-        if (curr->isReplaced()) {
-            if (auto wrapper = toRenderBox(curr)->inlineBoxWrapper())
+        if (current->isReplaced()) {
+            if (auto wrapper = downcast<RenderBox>(*current).inlineBoxWrapper())
                 box = &wrapper->root();
-        } if (curr->isLineBreak()) {
-            if (auto wrapper = toRenderLineBreak(curr)->inlineBoxWrapper())
+        } if (is<RenderLineBreak>(*current)) {
+            if (auto wrapper = downcast<RenderLineBreak>(*current).inlineBoxWrapper())
                 box = &wrapper->root();
-        } else if (curr->isText()) {
-            InlineTextBox* textBox = toRenderText(curr)->lastTextBox();
-            if (textBox)
+        } else if (is<RenderText>(*current)) {
+            if (InlineTextBox* textBox = downcast<RenderText>(*current).lastTextBox())
                 box = &textBox->root();
-        } else if (curr->isRenderInline()) {
-            InlineBox* lastSiblingBox = toRenderInline(curr)->lastLineBoxIncludingCulling();
+        } else if (is<RenderInline>(*current)) {
+            InlineBox* lastSiblingBox = downcast<RenderInline>(*current).lastLineBoxIncludingCulling();
             if (lastSiblingBox)
                 box = &lastSiblingBox->root();
         }
@@ -396,7 +395,7 @@ void RenderLineBoxList::dirtyLinesFromChangedChild(RenderBoxModelObject* contain
         // space, the search for |child|'s linebox will go past the leading space to the previous linebox and select that
         // one as |box|. If we hit that situation here, dirty the |box| actually containing the child too. 
         bool insertedAfterLeadingSpace = box->lineBreakObj() == child->previousSibling();
-        if (adjacentBox && (adjacentBox->lineBreakObj() == child || child->isBR() || (curr && curr->isBR())
+        if (adjacentBox && (adjacentBox->lineBreakObj() == child || child->isBR() || (current && current->isBR())
             || insertedAfterLeadingSpace || isIsolated(container->style().unicodeBidi())))
             adjacentBox->markDirty();
     }
index 86fa539..b211862 100644 (file)
@@ -658,7 +658,7 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
         bool startsAboveRegion = true;
         bool endsBelowRegion = true;
         bool skipOverOutsideNodes = false;
-        Node* lastEndNode = 0;
+        Node* lastEndNode = nullptr;
 
         for (Node* node = contentElement; node; node = nextNodeInsideContentElement(node, contentElement)) {
             RenderObject* renderer = node->renderer();
@@ -666,16 +666,17 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                 continue;
 
             LayoutRect boundingBox;
-            if (renderer->isRenderInline())
-                boundingBox = toRenderInline(renderer)->linesBoundingBox();
-            else if (renderer->isText())
-                boundingBox = toRenderText(renderer)->linesBoundingBox();
-            else if (renderer->isLineBreak())
-                boundingBox = toRenderLineBreak(renderer)->linesBoundingBox();
+            if (is<RenderInline>(*renderer))
+                boundingBox = downcast<RenderInline>(*renderer).linesBoundingBox();
+            else if (is<RenderText>(*renderer))
+                boundingBox = downcast<RenderText>(*renderer).linesBoundingBox();
+            else if (is<RenderLineBreak>(*renderer))
+                boundingBox = downcast<RenderLineBreak>(*renderer).linesBoundingBox();
             else if (renderer->isBox()) {
-                boundingBox = toRenderBox(renderer)->frameRect();
-                if (toRenderBox(renderer)->isRelPositioned())
-                    boundingBox.move(toRenderBox(renderer)->relativePositionLogicalOffset());
+                RenderBox& renderBox = downcast<RenderBox>(*renderer);
+                boundingBox = renderBox.frameRect();
+                if (renderBox.isRelPositioned())
+                    boundingBox.move(renderBox.relativePositionLogicalOffset());
             } else
                 continue;
 
@@ -710,11 +711,11 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
 
             // start position
             if (logicalTopForRenderer < logicalTopForRegion && startsAboveRegion) {
-                if (renderer->isText()) {
+                if (is<RenderText>(*renderer)) {
                     // Text crosses region top
                     // for Text elements, just find the last textbox that is contained inside the region and use its start() offset as start position
-                    RenderText* textRenderer = toRenderText(renderer);
-                    for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
+                    RenderText& textRenderer = downcast<RenderText>(*renderer);
+                    for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextTextBox()) {
                         if (offsetTop + box->logicalBottom() < logicalTopForRegion)
                             continue;
                         range->setStart(Position(downcast<Text>(node), box->start()));
@@ -742,11 +743,11 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
             // end position
             if (logicalBottomForRegion < logicalBottomForRenderer && (endsBelowRegion || (!endsBelowRegion && !node->isDescendantOf(lastEndNode)))) {
                 // for Text elements, just find just find the last textbox that is contained inside the region and use its start()+len() offset as end position
-                if (renderer->isText()) {
+                if (is<RenderText>(*renderer)) {
                     // Text crosses region bottom
-                    RenderText* textRenderer = toRenderText(renderer);
+                    RenderText& textRenderer = downcast<RenderText>(*renderer);
                     InlineTextBox* lastBox = nullptr;
-                    for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
+                    for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextTextBox()) {
                         if ((offsetTop + box->logicalTop()) < logicalBottomForRegion) {
                             lastBox = box;
                             continue;
index 8be33eb..1524ad3 100644 (file)
@@ -344,9 +344,9 @@ void RenderRubyRun::getOverhang(bool firstLine, RenderObject* startRenderer, Ren
     const RenderStyle& rubyTextStyle = firstLine ? rubyText->firstLineStyle() : rubyText->style();
     int halfWidthOfFontSize = rubyTextStyle.fontSize() / 2;
     if (startOverhang)
-        startOverhang = std::min<int>(startOverhang, std::min<int>(toRenderText(startRenderer)->minLogicalWidth(), halfWidthOfFontSize));
+        startOverhang = std::min<int>(startOverhang, std::min<int>(downcast<RenderText>(*startRenderer).minLogicalWidth(), halfWidthOfFontSize));
     if (endOverhang)
-        endOverhang = std::min<int>(endOverhang, std::min<int>(toRenderText(endRenderer)->minLogicalWidth(), halfWidthOfFontSize));
+        endOverhang = std::min<int>(endOverhang, std::min<int>(downcast<RenderText>(*endRenderer).minLogicalWidth(), halfWidthOfFontSize));
 }
 
 } // namespace WebCore
index 3b1194a..b9e85c6 100644 (file)
@@ -46,8 +46,8 @@ RenderSelectionInfo::RenderSelectionInfo(RenderObject& renderer, bool clipToVisi
     : RenderSelectionInfoBase(renderer)
 {
     if (renderer.canUpdateSelectionOnRootLineBoxes()) {
-        if (renderer.isText())
-            m_rect = toRenderText(renderer).collectSelectionRectsForLineBoxes(m_repaintContainer, clipToVisibleContent, m_collectedSelectionRects);
+        if (is<RenderText>(renderer))
+            m_rect = downcast<RenderText>(renderer).collectSelectionRectsForLineBoxes(m_repaintContainer, clipToVisibleContent, m_collectedSelectionRects);
         else
             m_rect = renderer.selectionRectForRepaint(m_repaintContainer, clipToVisibleContent);
     }
index 9fa82e6..73a1a4c 100644 (file)
@@ -35,6 +35,7 @@
 #include "Range.h"
 #include "RenderBlock.h"
 #include "RenderCombineText.h"
+#include "RenderInline.h"
 #include "RenderLayer.h"
 #include "RenderView.h"
 #include "Settings.h"
@@ -961,13 +962,13 @@ void RenderText::setTextWithOffset(const String& text, unsigned offset, unsigned
     setText(text, force || m_linesDirty);
 }
 
-static inline bool isInlineFlowOrEmptyText(const RenderObject* o)
+static inline bool isInlineFlowOrEmptyText(const RenderObject& renderer)
 {
-    if (o->isRenderInline())
+    if (is<RenderInline>(renderer))
         return true;
-    if (!o->isText())
+    if (!is<RenderText>(renderer))
         return false;
-    StringImpl* text = toRenderText(o)->text();
+    StringImpl* text = downcast<RenderText>(renderer).text();
     if (!text)
         return true;
     return !text->length();
@@ -978,12 +979,13 @@ UChar RenderText::previousCharacter() const
     // find previous text renderer if one exists
     const RenderObject* previousText = this;
     while ((previousText = previousText->previousInPreOrder()))
-        if (!isInlineFlowOrEmptyText(previousText))
+        if (!isInlineFlowOrEmptyText(*previousText))
             break;
     UChar prev = ' ';
-    if (previousText && previousText->isText())
-        if (StringImpl* previousString = toRenderText(previousText)->text())
+    if (is<RenderText>(previousText)) {
+        if (StringImpl* previousString = downcast<RenderText>(*previousText).text())
             prev = (*previousString)[previousString->length() - 1];
+    }
     return prev;
 }
 
index 0eb233c..d3da302 100644 (file)
@@ -223,8 +223,6 @@ private:
     RenderTextLineBoxes m_lineBoxes;
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderText, isText())
-
 inline UChar RenderText::uncheckedCharacterAt(unsigned i) const
 {
     ASSERT_WITH_SECURITY_IMPLICATION(i < textLength());
@@ -254,7 +252,7 @@ void makeCapitalized(String*, UChar previous);
     
 inline RenderText* Text::renderer() const
 {
-    return toRenderText(Node::renderer());
+    return downcast<RenderText>(Node::renderer());
 }
 
 } // namespace WebCore
index 6c2af2b..7231b56 100644 (file)
@@ -72,10 +72,11 @@ private:
     RenderBoxModelObject* m_firstLetter;
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderTextFragment, isText() && toRenderText(renderer).isTextFragment())
-
 } // namespace WebCore
 
-SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderTextFragment, isText() && toRenderText(renderer).isTextFragment())
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::RenderTextFragment)
+    static bool isType(const WebCore::RenderText& renderer) { return renderer.isTextFragment(); }
+    static bool isType(const WebCore::RenderObject& renderer) { return is<WebCore::RenderText>(renderer) && isType(downcast<WebCore::RenderText>(renderer)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 #endif // RenderTextFragment_h
index d33a934..927dd53 100644 (file)
@@ -197,32 +197,32 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
     bool adjustForTableCells = cb ? cb->isTableCell() : false;
 
     LayoutRect r;
-    if (o.isText()) {
+    if (is<RenderText>(o)) {
         // FIXME: Would be better to dump the bounding box x and y rather than the first run's x and y, but that would involve updating
         // many test results.
-        const RenderText& text = toRenderText(o);
+        const RenderText& text = downcast<RenderText>(o);
         r = IntRect(text.firstRunLocation(), text.linesBoundingBox().size());
         if (!text.firstTextBox() && !text.simpleLineLayout())
             adjustForTableCells = false;
     } else if (o.isBR()) {
-        const RenderLineBreak& br = toRenderLineBreak(o);
+        const RenderLineBreak& br = downcast<RenderLineBreak>(o);
         IntRect linesBox = br.linesBoundingBox();
         r = IntRect(linesBox.x(), linesBox.y(), linesBox.width(), linesBox.height());
         if (!br.inlineBoxWrapper())
             adjustForTableCells = false;
-    } else if (o.isRenderInline()) {
-        const RenderInline& inlineFlow = toRenderInline(o);
+    } else if (is<RenderInline>(o)) {
+        const RenderInline& inlineFlow = downcast<RenderInline>(o);
         // FIXME: Would be better not to just dump 0, 0 as the x and y here.
         r = IntRect(0, 0, inlineFlow.linesBoundingBox().width(), inlineFlow.linesBoundingBox().height());
         adjustForTableCells = false;
-    } else if (o.isTableCell()) {
+    } else if (is<RenderTableCell>(o)) {
         // FIXME: Deliberately dump the "inner" box of table cells, since that is what current results reflect.  We'd like
         // to clean up the results to dump both the outer box and the intrinsic padding so that both bits of information are
         // captured by the results.
-        const RenderTableCell& cell = *toRenderTableCell(&o);
+        const RenderTableCell& cell = downcast<RenderTableCell>(o);
         r = LayoutRect(cell.x(), cell.y() + cell.intrinsicPaddingBefore(), cell.width(), cell.height() - cell.intrinsicPaddingBefore() - cell.intrinsicPaddingAfter());
-    } else if (o.isBox())
-        r = toRenderBox(o).frameRect();
+    } else if (is<RenderBox>(o))
+        r = downcast<RenderBox>(o).frameRect();
 
     // FIXME: Temporary in order to ensure compatibility with existing layout test results.
     if (adjustForTableCells)
@@ -261,10 +261,10 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
                 ts << " [textStrokeWidth=" << o.style().textStrokeWidth() << "]";
         }
 
-        if (!o.isBoxModelObject() || o.isLineBreak())
+        if (!is<RenderBoxModelObject>(o) || is<RenderLineBreak>(o))
             return;
 
-        const RenderBoxModelObject& box = toRenderBoxModelObject(o);
+        const RenderBoxModelObject& box = downcast<RenderBoxModelObject>(o);
         if (box.borderTop() || box.borderRight() || box.borderBottom() || box.borderLeft()) {
             ts << " [border:";
 
@@ -343,15 +343,15 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
 #endif
     }
 
-    if (o.isTableCell()) {
-        const RenderTableCell& c = *toRenderTableCell(&o);
+    if (is<RenderTableCell>(o)) {
+        const RenderTableCell& c = downcast<RenderTableCell>(o);
         ts << " [r=" << c.rowIndex() << " c=" << c.col() << " rs=" << c.rowSpan() << " cs=" << c.colSpan() << "]";
     }
 
 #if ENABLE(DETAILS_ELEMENT)
-    if (o.isDetailsMarker()) {
+    if (is<RenderDetailsMarker>(o)) {
         ts << ": ";
-        switch (toRenderDetailsMarker(o).orientation()) {
+        switch (downcast<RenderDetailsMarker>(o).orientation()) {
         case RenderDetailsMarker::Left:
             ts << "left";
             break;
@@ -368,8 +368,8 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
     }
 #endif
 
-    if (o.isListMarker()) {
-        String text = toRenderListMarker(o).text();
+    if (is<RenderListMarker>(o)) {
+        String text = downcast<RenderListMarker>(o).text();
         if (!text.isEmpty()) {
             if (text.length() != 1)
                 text = quoteAndEscapeNonPrintables(text);
@@ -444,8 +444,8 @@ void RenderTreeAsText::writeRenderObject(TextStream& ts, const RenderObject& o,
             ts << ")";
     }
     
-    if (behavior & RenderAsTextShowOverflow && o.isBox()) {
-        const RenderBox& box = toRenderBox(o);
+    if (behavior & RenderAsTextShowOverflow && is<RenderBox>(o)) {
+        const RenderBox& box = downcast<RenderBox>(o);
         if (box.hasRenderOverflow()) {
             LayoutRect layoutOverflow = box.layoutOverflowRect();
             ts << " (layout overflow " << layoutOverflow.x().toInt() << "," << layoutOverflow.y().toInt() << " " << layoutOverflow.width().toInt() << "x" << layoutOverflow.height().toInt() << ")";
@@ -500,36 +500,36 @@ static void writeSimpleLine(TextStream& ts, const RenderText& o, const LayoutRec
 
 void write(TextStream& ts, const RenderObject& o, int indent, RenderAsTextBehavior behavior)
 {
-    if (o.isSVGShape()) {
-        write(ts, *toRenderSVGShape(&o), indent);
+    if (is<RenderSVGShape>(o)) {
+        write(ts, downcast<RenderSVGShape>(o), indent);
         return;
     }
-    if (o.isSVGGradientStop()) {
-        writeSVGGradientStop(ts, *toRenderSVGGradientStop(&o), indent);
+    if (is<RenderSVGGradientStop>(o)) {
+        writeSVGGradientStop(ts, downcast<RenderSVGGradientStop>(o), indent);
         return;
     }
-    if (o.isSVGResourceContainer()) {
-        writeSVGResourceContainer(ts, toRenderSVGResourceContainer(o), indent);
+    if (is<RenderSVGResourceContainer>(o)) {
+        writeSVGResourceContainer(ts, downcast<RenderSVGResourceContainer>(o), indent);
         return;
     }
-    if (o.isSVGContainer()) {
-        writeSVGContainer(ts, toRenderSVGContainer(o), indent);
+    if (is<RenderSVGContainer>(o)) {
+        writeSVGContainer(ts, downcast<RenderSVGContainer>(o), indent);
         return;
     }
-    if (o.isSVGRoot()) {
-        write(ts, *toRenderSVGRoot(&o), indent);
+    if (is<RenderSVGRoot>(o)) {
+        write(ts, downcast<RenderSVGRoot>(o), indent);
         return;
     }
-    if (o.isSVGText()) {
-        writeSVGText(ts, *toRenderSVGText(&o), indent);
+    if (is<RenderSVGText>(o)) {
+        writeSVGText(ts, downcast<RenderSVGText>(o), indent);
         return;
     }
-    if (o.isSVGInlineText()) {
-        writeSVGInlineText(ts, toRenderSVGInlineText(o), indent);
+    if (is<RenderSVGInlineText>(o)) {
+        writeSVGInlineText(ts, downcast<RenderSVGInlineText>(o), indent);
         return;
     }
-    if (o.isSVGImage()) {
-        writeSVGImage(ts, *toRenderSVGImage(&o), indent);
+    if (is<RenderSVGImage>(o)) {
+        writeSVGImage(ts, downcast<RenderSVGImage>(o), indent);
         return;
     }
 
@@ -538,8 +538,8 @@ void write(TextStream& ts, const RenderObject& o, int indent, RenderAsTextBehavi
     RenderTreeAsText::writeRenderObject(ts, o, behavior);
     ts << "\n";
 
-    if (o.isText()) {
-        auto& text = toRenderText(o);
+    if (is<RenderText>(o)) {
+        auto& text = downcast<RenderText>(o);
         if (auto layout = text.simpleLineLayout()) {
             ASSERT(!text.firstTextBox());
             auto resolver = runResolver(toRenderBlockFlow(*text.parent()), *layout);
@@ -556,7 +556,7 @@ void write(TextStream& ts, const RenderObject& o, int indent, RenderAsTextBehavi
         }
 
     } else {
-        for (RenderObject* child = toRenderElement(o).firstChild(); child; child = child->nextSibling()) {
+        for (RenderObject* child = downcast<RenderElement>(o).firstChild(); child; child = child->nextSibling()) {
             if (child->hasLayer())
                 continue;
             write(ts, *child, indent + 1, behavior);
index 6106c1d..0734a17 100644 (file)
@@ -97,7 +97,7 @@ bool canUseFor(const RenderBlockFlow& flow)
     // The <blockflow><inline>#text</inline></blockflow> case is also popular and should be relatively easy to cover.
     if (flow.firstChild() != flow.lastChild())
         return false;
-    if (!flow.firstChild()->isText())
+    if (!is<RenderText>(flow.firstChild()))
         return false;
     if (!flow.isHorizontalWritingMode())
         return false;
@@ -162,7 +162,7 @@ bool canUseFor(const RenderBlockFlow& flow)
         return false;
     if (style.borderFit() == BorderFitLines)
         return false;
-    const RenderText& textRenderer = toRenderText(*flow.firstChild());
+    const RenderText& textRenderer = downcast<RenderText>(*flow.firstChild());
     if (flow.containsFloats()) {
         // We can't use the code path if any lines would need to be shifted below floats. This is because we don't keep per-line y coordinates.
         float minimumWidthNeeded = textRenderer.minLogicalWidth();
@@ -441,7 +441,7 @@ std::unique_ptr<Layout> create(RenderBlockFlow& flow)
     Layout::RunVector runs;
     unsigned lineCount = 0;
 
-    RenderText& textRenderer = toRenderText(*flow.firstChild());
+    RenderText& textRenderer = downcast<RenderText>(*flow.firstChild());
     ASSERT(!textRenderer.firstTextBox());
 
     if (textRenderer.is8Bit())
index 3526407..ccf1bfa 100644 (file)
@@ -67,7 +67,7 @@ void paintFlow(const RenderBlockFlow& flow, const Layout& layout, PaintInfo& pai
     if (style.visibility() != VISIBLE)
         return;
 
-    RenderText& textRenderer = toRenderText(*flow.firstChild());
+    RenderText& textRenderer = downcast<RenderText>(*flow.firstChild());
     ASSERT(!textRenderer.firstTextBox());
 
     bool debugBordersEnabled = flow.frame().settings().simpleLineLayoutDebugBordersEnabled();
@@ -110,7 +110,7 @@ bool hitTestFlow(const RenderBlockFlow& flow, const Layout& layout, const HitTes
     if (style.visibility() != VISIBLE || style.pointerEvents() == PE_NONE)
         return false;
 
-    RenderText& textRenderer = toRenderText(*flow.firstChild());
+    RenderText& textRenderer = downcast<RenderText>(*flow.firstChild());
 
     LayoutRect rangeRect = locationInContainer.boundingBox();
     rangeRect.moveBy(-accumulatedOffset);
index 900e64b..bb9aa72 100644 (file)
@@ -252,7 +252,7 @@ inline const SimpleLineLayout::Run& RunResolver::Iterator::simpleRun() const
 
 inline RunResolver::RunResolver(const RenderBlockFlow& flow, const Layout& layout)
     : m_layout(layout)
-    , m_string(toRenderText(*flow.firstChild()).text())
+    , m_string(downcast<RenderText>(*flow.firstChild()).text())
     , m_lineHeight(lineHeightFromFlow(flow))
     , m_baseline(baselineFromFlow(flow))
     , m_borderAndPaddingBefore(flow.borderAndPaddingBefore())
index 1f61472..a3727e9 100644 (file)
@@ -100,8 +100,7 @@ int TextAutoSizingValue::numNodes() const
 void TextAutoSizingValue::addNode(Node* node, float size)
 {
     ASSERT(node);
-    RenderText* renderText = toRenderText(node->renderer());
-    renderText->setCandidateComputedTextSize(size);
+    downcast<RenderText>(*node->renderer()).setCandidateComputedTextSize(size);
     m_autoSizedNodes.add(node);
 }
 
index f6059fe..74c3c0a 100644 (file)
@@ -413,7 +413,7 @@ bool TextAutosizer::containerIsRowOfLinks(const RenderObject* container)
 
     while (renderer) {
         if (!isAutosizingContainer(renderer)) {
-            if (renderer->isText() && toRenderText(renderer)->text()->stripWhiteSpace()->length() > 3)
+            if (is<RenderText>(*renderer) && downcast<RenderText>(*renderer).text()->stripWhiteSpace()->length() > 3)
                 return false;
             if (!renderer->isInline())
                 return false;
@@ -493,9 +493,9 @@ void TextAutosizer::measureDescendantTextWidth(const RenderBlock* container, Tex
 
     RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(container, container);
     while (descendant) {
-        if (!skipLocalText && descendant->isText()) {
-            textWidth += toRenderText(descendant)->renderedTextLength() * descendant->style()->specifiedFontSize();
-        else if (isAutosizingContainer(descendant)) {
+        if (!skipLocalText && is<RenderText>(*descendant))
+            textWidth += downcast<RenderText>(*descendant).renderedTextLength() * descendant->style()->specifiedFontSize();
+        else if (isAutosizingContainer(descendant)) {
             RenderBlock* descendantBlock = toRenderBlock(descendant);
             if (!isAutosizingCluster(descendantBlock, clusterInfo))
                 measureDescendantTextWidth(descendantBlock, clusterInfo, minTextWidth, textWidth);
index 0166a63..0c6ea18 100644 (file)
@@ -125,10 +125,10 @@ public:
             m_lineBreak.clear();
     }
 
-    void commitLineBreakAtCurrentWidth(RenderObject* object, unsigned offset = 0, int nextBreak = -1)
+    void commitLineBreakAtCurrentWidth(RenderObject& object, unsigned offset = 0, int nextBreak = -1)
     {
         m_width.commit();
-        m_lineBreak.moveTo(object, offset, nextBreak);
+        m_lineBreak.moveTo(&object, offset, nextBreak);
     }
 
 private:
@@ -270,7 +270,7 @@ inline LayoutUnit borderPaddingMarginEnd(const RenderInline& child)
 inline bool shouldAddBorderPaddingMargin(RenderObject* child)
 {
     // When deciding whether we're at the edge of an inline, adjacent collapsed whitespace is the same as no sibling at all.
-    return !child || (child->isText() && !toRenderText(child)->textLength());
+    return !child || (is<RenderText>(*child) && !downcast<RenderText>(*child).textLength());
 }
 
 inline RenderObject* previousInFlowSibling(RenderObject* child)
@@ -359,11 +359,11 @@ inline bool shouldSkipWhitespaceAfterStartObject(RenderBlockFlow& block, RenderO
     while (next && next->isFloatingOrOutOfFlowPositioned())
         next = bidiNextSkippingEmptyInlines(block, next);
 
-    if (next && next->isText() && toRenderText(next)->textLength() > 0) {
-        RenderText* nextText = toRenderText(next);
-        UChar nextChar = nextText->characterAt(0);
-        if (nextText->style().isCollapsibleWhiteSpace(nextChar)) {
-            lineMidpointState.startIgnoringSpaces(InlineIterator(0, o, 0));
+    if (is<RenderText>(next) && downcast<RenderText>(*next).textLength() > 0) {
+        RenderText& nextText = downcast<RenderText>(*next);
+        UChar nextChar = nextText.characterAt(0);
+        if (nextText.style().isCollapsibleWhiteSpace(nextChar)) {
+            lineMidpointState.startIgnoringSpaces(InlineIterator(nullptr, o, 0));
             return true;
         }
     }
@@ -585,16 +585,16 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
     if (!m_current.offset())
         m_appliedStartWidth = false;
 
-    RenderText* renderText = toRenderText(m_current.renderer());
+    RenderText& renderText = downcast<RenderText>(*m_current.renderer());
 
-    bool isSVGText = renderText->isSVGInlineText();
+    bool isSVGText = renderText.isSVGInlineText();
 
     // If we have left a no-wrap inline and entered an autowrap inline while ignoring spaces
     // then we need to mark the start of the autowrap inline as a potential linebreak now.
     if (m_autoWrap && !RenderStyle::autoWrap(m_lastWS) && m_ignoringSpaces)
-        commitLineBreakAtCurrentWidth(m_current.renderer());
+        commitLineBreakAtCurrentWidth(renderText);
 
-    if (renderText->style().hasTextCombine() && m_current.renderer()->isCombineText() && !toRenderCombineText(*m_current.renderer()).isCombined()) {
+    if (renderText.style().hasTextCombine() && m_current.renderer()->isCombineText() && !toRenderCombineText(*m_current.renderer()).isCombined()) {
         RenderCombineText& combineRenderer = toRenderCombineText(*m_current.renderer());
         combineRenderer.combineText();
         // The length of the renderer's text may have changed. Increment stale iterator positions
@@ -605,7 +605,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
         }
     }
 
-    const RenderStyle& style = lineStyle(*renderText->parent(), m_lineInfo);
+    const RenderStyle& style = lineStyle(*renderText.parent(), m_lineInfo);
     const Font& font = style.font();
     bool isFixedPitch = font.isFixedPitch();
     bool canHyphenate = style.hyphens() == HyphensAuto && WebCore::canHyphenate(style.locale());
@@ -630,15 +630,15 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
         breakAll = false;
     }
 
-    if (m_renderTextInfo.m_text != renderText) {
-        updateCounterIfNeeded(*renderText);
-        m_renderTextInfo.m_text = renderText;
+    if (m_renderTextInfo.m_text != &renderText) {
+        updateCounterIfNeeded(renderText);
+        m_renderTextInfo.m_text = &renderText;
         m_renderTextInfo.m_font = &font;
-        m_renderTextInfo.m_layout = font.createLayout(renderText, m_width.currentWidth(), m_collapseWhiteSpace);
-        m_renderTextInfo.m_lineBreakIterator.resetStringAndReleaseIterator(renderText->text(), style.locale());
+        m_renderTextInfo.m_layout = font.createLayout(&renderText, m_width.currentWidth(), m_collapseWhiteSpace);
+        m_renderTextInfo.m_lineBreakIterator.resetStringAndReleaseIterator(renderText.text(), style.locale());
     } else if (m_renderTextInfo.m_layout && m_renderTextInfo.m_font != &font) {
         m_renderTextInfo.m_font = &font;
-        m_renderTextInfo.m_layout = font.createLayout(renderText, m_width.currentWidth(), m_collapseWhiteSpace);
+        m_renderTextInfo.m_layout = font.createLayout(&renderText, m_width.currentWidth(), m_collapseWhiteSpace);
     }
 
     TextLayout* textLayout = m_renderTextInfo.m_layout.get();
@@ -646,11 +646,11 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
     // Non-zero only when kerning is enabled and TextLayout isn't used, in which case we measure
     // words with their trailing space, then subtract its width.
     HashSet<const SimpleFontData*> fallbackFonts;
-    float wordTrailingSpaceWidth = (font.typesettingFeatures() & Kerning) && !textLayout ? font.width(RenderBlock::constructTextRun(renderText, font, &space, 1, style), &fallbackFonts) + wordSpacing : 0;
+    float wordTrailingSpaceWidth = (font.typesettingFeatures() & Kerning) && !textLayout ? font.width(RenderBlock::constructTextRun(&renderText, font, &space, 1, style), &fallbackFonts) + wordSpacing : 0;
 
     UChar lastCharacter = m_renderTextInfo.m_lineBreakIterator.lastCharacter();
     UChar secondToLastCharacter = m_renderTextInfo.m_lineBreakIterator.secondToLastCharacter();
-    for (; m_current.offset() < renderText->textLength(); m_current.fastIncrementInTextNode()) {
+    for (; m_current.offset() < renderText.textLength(); m_current.fastIncrementInTextNode()) {
         bool previousCharacterIsSpace = m_currentCharacterIsSpace;
         bool previousCharacterIsWS = m_currentCharacterIsWS;
         UChar c = m_current.current();
@@ -660,7 +660,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
             m_lineInfo.setEmpty(false, &m_block, &m_width);
 
         if (c == softHyphen && m_autoWrap && !hyphenWidth && style.hyphens() != HyphensNone) {
-            hyphenWidth = measureHyphenWidth(renderText, font, &fallbackFonts);
+            hyphenWidth = measureHyphenWidth(&renderText, font, &fallbackFonts);
             m_width.addUncommittedWidth(hyphenWidth);
         }
 
@@ -670,8 +670,8 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
 
         if ((breakAll || breakWords) && !midWordBreak && (!m_currentCharacterIsSpace || style.whiteSpace() != PRE_WRAP)) {
             wrapW += charWidth;
-            bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && m_current.offset() + 1 < renderText->textLength() && U16_IS_TRAIL((*renderText)[m_current.offset() + 1]);
-            charWidth = textWidth(renderText, m_current.offset(), midWordBreakIsBeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitch, m_collapseWhiteSpace, fallbackFonts, textLayout);
+            bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && m_current.offset() + 1 < renderText.textLength() && U16_IS_TRAIL(renderText[m_current.offset() + 1]);
+            charWidth = textWidth(&renderText, m_current.offset(), midWordBreakIsBeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitch, m_collapseWhiteSpace, fallbackFonts, textLayout);
             midWordBreak = m_width.committedWidth() + wrapW + charWidth > m_width.availableWidth();
         }
 
@@ -702,15 +702,15 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
             wordMeasurements.grow(wordMeasurements.size() + 1);
             WordMeasurement& wordMeasurement = wordMeasurements.last();
 
-            wordMeasurement.renderer = renderText;
+            wordMeasurement.renderer = &renderText;
             wordMeasurement.endOffset = m_current.offset();
             wordMeasurement.startOffset = lastSpace;
 
             float additionalTempWidth;
             if (wordTrailingSpaceWidth && c == ' ')
-                additionalTempWidth = textWidth(renderText, lastSpace, m_current.offset() + 1 - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) - wordTrailingSpaceWidth;
+                additionalTempWidth = textWidth(&renderText, lastSpace, m_current.offset() + 1 - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) - wordTrailingSpaceWidth;
             else
-                additionalTempWidth = textWidth(renderText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout);
+                additionalTempWidth = textWidth(&renderText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout);
 
             if (wordMeasurement.fallbackFonts.isEmpty() && !fallbackFonts.isEmpty())
                 wordMeasurement.fallbackFonts.swap(fallbackFonts);
@@ -738,7 +738,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
                 // as candidate width for this line.
                 bool lineWasTooWide = false;
                 if (m_width.fitsOnLine() && m_currentCharacterIsWS && m_currentStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) {
-                    float charWidth = textWidth(renderText, m_current.offset(), 1, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0);
+                    float charWidth = textWidth(&renderText, m_current.offset(), 1, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0);
                     // Check if line is too big even without the extra space
                     // at the end of the line. If it is not, do nothing.
                     // If the line needs the extra whitespace to be too long,
@@ -752,7 +752,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
                 }
                 if (lineWasTooWide || !m_width.fitsOnLine()) {
                     if (canHyphenate && !m_width.fitsOnLine()) {
-                        tryHyphenating(renderText, font, style.locale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
+                        tryHyphenating(&renderText, font, style.locale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
                         if (m_lineBreaker.m_hyphenated) {
                             m_atEnd = true;
                             return false;
@@ -765,7 +765,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
                         m_lineInfo.setPreviousLineBrokeCleanly(true);
                         wordMeasurement.endOffset = m_lineBreak.offset();
                     }
-                    if (m_lineBreak.renderer() && m_lineBreak.offset() && m_lineBreak.renderer()->isText() && toRenderText(m_lineBreak.renderer())->textLength() && toRenderText(m_lineBreak.renderer())->characterAt(m_lineBreak.offset() - 1) == softHyphen && style.hyphens() != HyphensNone)
+                    if (m_lineBreak.offset() && downcast<RenderText>(m_lineBreak.renderer()) && downcast<RenderText>(*m_lineBreak.renderer()).textLength() && downcast<RenderText>(*m_lineBreak.renderer()).characterAt(m_lineBreak.offset() - 1) == softHyphen && style.hyphens() != HyphensNone)
                         hyphenated = true;
                     if (m_lineBreak.offset() && m_lineBreak.offset() != (unsigned)wordMeasurement.endOffset && !wordMeasurement.width) {
                         if (charWidth) {
@@ -846,7 +846,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
 
         if (isSVGText && m_current.offset()) {
             // Force creation of new InlineBoxes for each absolute positioned character (those that start new text chunks).
-            if (toRenderSVGInlineText(renderText)->characterStartsNewTextChunk(m_current.offset()))
+            if (downcast<RenderSVGInlineText>(renderText).characterStartsNewTextChunk(m_current.offset()))
                 ensureCharacterGetsLineBox(m_lineMidpointState, m_current);
         }
 
@@ -859,7 +859,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
             if (m_nextObject && m_startOfIgnoredSpaces.offset() && m_nextObject->isBR() && (m_blockStyle.textAlign() == RIGHT || m_blockStyle.textAlign() == WEBKIT_RIGHT)) {
                 m_startOfIgnoredSpaces.setOffset(m_startOfIgnoredSpaces.offset() - 1);
                 // If there's just a single trailing space start ignoring it now so it collapses away.
-                if (m_current.offset() == renderText->textLength() - 1)
+                if (m_current.offset() == renderText.textLength() - 1)
                     m_lineMidpointState.startIgnoringSpaces(m_startOfIgnoredSpaces);
             }
         }
@@ -870,7 +870,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
         }
 
         if (m_collapseWhiteSpace && m_currentCharacterIsSpace && !m_ignoringSpaces)
-            m_trailingObjects.setTrailingWhitespace(toRenderText(m_current.renderer()));
+            m_trailingObjects.setTrailingWhitespace(downcast<RenderText>(m_current.renderer()));
         else if (!m_currentStyle->collapseWhiteSpace() || !m_currentCharacterIsSpace)
             m_trailingObjects.clear();
 
@@ -882,10 +882,10 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
 
     wordMeasurements.grow(wordMeasurements.size() + 1);
     WordMeasurement& wordMeasurement = wordMeasurements.last();
-    wordMeasurement.renderer = renderText;
+    wordMeasurement.renderer = &renderText;
 
     // IMPORTANT: current.m_pos is > length here!
-    float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(renderText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout);
+    float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(&renderText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout);
     wordMeasurement.startOffset = lastSpace;
     wordMeasurement.endOffset = m_current.offset();
     wordMeasurement.width = m_ignoringSpaces ? 0 : additionalTempWidth + wordSpacingForWordMeasurement;
@@ -905,7 +905,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
 
     if (!m_width.fitsOnLine()) {
         if (canHyphenate)
-            tryHyphenating(renderText, font, style.locale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
+            tryHyphenating(&renderText, font, style.locale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
 
         if (!hyphenated && m_lineBreak.previousInSameNode() == softHyphen && style.hyphens() != HyphensNone) {
             hyphenated = true;
@@ -915,14 +915,10 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
     return false;
 }
 
-inline bool textBeginsWithBreakablePosition(RenderObject* next)
+inline bool textBeginsWithBreakablePosition(RenderText& nextText)
 {
-    ASSERT(next->isText());
-    RenderText* nextText = toRenderText(next);
-    if (!nextText->textLength())
-        return false;
-    UChar c = nextText->characterAt(0);
-    return c == ' ' || c == '\t' || (c == '\n' && !nextText->preservesNewline());
+    UChar c = nextText.characterAt(0);
+    return c == ' ' || c == '\t' || (c == '\n' && !nextText.preservesNewline());
 }
 
 inline bool BreakingContext::canBreakAtThisPosition()
@@ -932,11 +928,11 @@ inline bool BreakingContext::canBreakAtThisPosition()
         return true;
 
     // Avoid breaking on empty inlines.
-    if (m_current.renderer()->isRenderInline() && isEmptyInline(toRenderInline(*m_current.renderer())))
+    if (is<RenderInline>(*m_current.renderer()) && isEmptyInline(downcast<RenderInline>(*m_current.renderer())))
         return false;
 
     // Avoid breaking before empty inlines.
-    if (m_nextObject && m_nextObject->isRenderInline() && isEmptyInline(toRenderInline(*m_nextObject)))
+    if (is<RenderInline>(m_nextObject) && isEmptyInline(downcast<RenderInline>(*m_nextObject)))
         return false;
 
     // Return early if we autowrap and the current character is a space as we will always want to break at such a position.
@@ -946,14 +942,15 @@ inline bool BreakingContext::canBreakAtThisPosition()
     if (m_nextObject && m_nextObject->isLineBreakOpportunity())
         return m_autoWrap;
 
-    bool nextIsAutoWrappingText = (m_nextObject && m_nextObject->isText() && (m_autoWrap || m_nextObject->style().autoWrap()));
+    bool nextIsAutoWrappingText = is<RenderText>(m_nextObject) && (m_autoWrap || m_nextObject->style().autoWrap());
     if (!nextIsAutoWrappingText)
         return m_autoWrap;
-    bool currentIsTextOrEmptyInline = m_current.renderer()->isText() || (m_current.renderer()->isRenderInline() && isEmptyInline(toRenderInline(*m_current.renderer())));
+    RenderText& nextRenderText = downcast<RenderText>(*m_nextObject);
+    bool currentIsTextOrEmptyInline = is<RenderText>(*m_current.renderer()) || (is<RenderInline>(*m_current.renderer()) && isEmptyInline(downcast<RenderInline>(*m_current.renderer())));
     if (!currentIsTextOrEmptyInline)
         return m_autoWrap;
 
-    bool canBreakHere = !m_currentCharacterIsSpace && textBeginsWithBreakablePosition(m_nextObject);
+    bool canBreakHere = !m_currentCharacterIsSpace && textBeginsWithBreakablePosition(nextRenderText);
 
     // See if attempting to fit below floats creates more available width on the line.
     if (!m_width.fitsOnLine() && !m_width.committedWidth())
@@ -962,7 +959,7 @@ inline bool BreakingContext::canBreakAtThisPosition()
     bool canPlaceOnLine = m_width.fitsOnLine() || !m_autoWrapWasEverTrueOnLine;
 
     if (canPlaceOnLine && canBreakHere)
-        commitLineBreakAtCurrentWidth(m_nextObject);
+        commitLineBreakAtCurrentWidth(nextRenderText);
 
     return canBreakHere;
 }
index 711c82c..d4774fe 100644 (file)
@@ -117,7 +117,7 @@ InlineIterator LineBreaker::nextSegmentBreak(InlineBidiResolver& resolver, LineI
                 return context.lineBreak();
             }
         } else if (context.currentObject()->isLineBreakOpportunity())
-            context.commitLineBreakAtCurrentWidth(context.currentObject());
+            context.commitLineBreakAtCurrentWidth(*context.currentObject());
         else
             ASSERT_NOT_REACHED();
 
index a441a8f..18b22e1 100644 (file)
@@ -1,3 +1,13 @@
+2014-10-07  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for RenderText / RenderTextFragment
+        https://bugs.webkit.org/show_bug.cgi?id=137476
+
+        Reviewed by Darin Adler.
+
+        * WebView/WebRenderNode.mm:
+        (copyRenderNode):
+
 2014-10-06  Dan Bernstein  <mitz@apple.com>
 
         Build fix.
index a68e6cb..6aeb099 100644 (file)
@@ -32,6 +32,7 @@
 #import <WebCore/Frame.h>
 #import <WebCore/FrameLoader.h>
 #import <WebCore/FrameLoaderClient.h>
+#import <WebCore/RenderInline.h>
 #import <WebCore/RenderText.h>
 #import <WebCore/RenderWidget.h>
 #import <WebCore/RenderView.h>
@@ -94,10 +95,10 @@ static WebRenderNode *copyRenderNode(RenderObject* node)
 
     NSString *name = [[NSString alloc] initWithUTF8String:node->renderName()];
     
-    RenderWidget* renderWidget = node->isWidget() ? toRenderWidget(node) : 0;
-    Widget* widget = renderWidget ? renderWidget->widget() : 0;
-    FrameView* frameView = widget && widget->isFrameView() ? toFrameView(widget) : 0;
-    Frame* frame = frameView ? &frameView->frame() : 0;
+    RenderWidget* renderWidget = node->isWidget() ? toRenderWidget(node) : nullptr;
+    Widget* widget = renderWidget ? renderWidget->widget() : nullptr;
+    FrameView* frameView = widget && widget->isFrameView() ? toFrameView(widget) : nullptr;
+    Frame* frame = frameView ? &frameView->frame() : nullptr;
 
     // FIXME: broken with transforms
     FloatPoint absPos = node->localToAbsolute();
@@ -105,24 +106,24 @@ static WebRenderNode *copyRenderNode(RenderObject* node)
     int y = 0;
     int width = 0;
     int height = 0;
-    if (node->isBox()) {
-        RenderBox* box = toRenderBox(node);
-        x = box->x();
-        y = box->y();
-        width = box->width();
-        height = box->height();
-    } else if (node->isText()) {
+    if (is<RenderBox>(*node)) {
+        RenderBox& box = downcast<RenderBox>(*node);
+        x = box.x();
+        y = box.y();
+        width = box.width();
+        height = box.height();
+    } else if (is<RenderText>(*node)) {
         // FIXME: Preserve old behavior even though it's strange.
-        RenderText* text = toRenderText(node);
-        IntPoint firstRunLocation = text->firstRunLocation();
+        RenderText& text = downcast<RenderText>(*node);
+        IntPoint firstRunLocation = text.firstRunLocation();
         x = firstRunLocation.x();
         y = firstRunLocation.y();
-        IntRect box = text->linesBoundingBox();
+        IntRect box = text.linesBoundingBox();
         width = box.width();
         height = box.height();
-    } else if (node->isRenderInline()) {
-        RenderBoxModelObject* inlineFlow = toRenderBoxModelObject(node);
-        IntRect boundingBox = inlineFlow->borderBoundingBox();
+    } else if (is<RenderInline>(*node)) {
+        RenderInline& inlineFlow = downcast<RenderInline>(*node);
+        IntRect boundingBox = inlineFlow.borderBoundingBox();
         x = boundingBox.x();
         y = boundingBox.y();
         width = boundingBox.width();
index a498e7b..c49b8aa 100644 (file)
@@ -1,5 +1,17 @@
 2014-10-07  Christophe Dumez  <cdumez@apple.com>
 
+        Use is<>() / downcast<>() for RenderText / RenderTextFragment
+        https://bugs.webkit.org/show_bug.cgi?id=137476
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for RenderText / RenderTextFragment.
+
+        * Shared/WebRenderObject.cpp:
+        (WebKit::WebRenderObject::WebRenderObject):
+
+2014-10-07  Christophe Dumez  <cdumez@apple.com>
+
         [WK2] Use is<>() / downcast<>() for DrawingAreaProxy subclasses
         https://bugs.webkit.org/show_bug.cgi?id=137477
 
index 79b7563..df2bd13 100644 (file)
@@ -33,6 +33,7 @@
 #include <WebCore/FrameLoader.h>
 #include <WebCore/FrameLoaderClient.h>
 #include <WebCore/MainFrame.h>
+#include <WebCore/RenderInline.h>
 #include <WebCore/RenderText.h>
 #include <WebCore/RenderView.h>
 #include <WebCore/RenderWidget.h>
@@ -87,13 +88,13 @@ WebRenderObject::WebRenderObject(RenderObject* renderer, bool shouldIncludeDesce
     // FIXME: broken with transforms
     m_absolutePosition = flooredIntPoint(renderer->localToAbsolute());
 
-    if (renderer->isBox())
-        m_frameRect = snappedIntRect(toRenderBox(renderer)->frameRect());
-    else if (renderer->isText()) {
-        m_frameRect = toRenderText(renderer)->linesBoundingBox();
-        m_frameRect.setLocation(toRenderText(renderer)->firstRunLocation());
-    } else if (renderer->isRenderInline())
-        m_frameRect = toRenderBoxModelObject(renderer)->borderBoundingBox();
+    if (is<RenderBox>(*renderer))
+        m_frameRect = snappedIntRect(downcast<RenderBox>(*renderer).frameRect());
+    else if (is<RenderText>(*renderer)) {
+        m_frameRect = downcast<RenderText>(*renderer).linesBoundingBox();
+        m_frameRect.setLocation(downcast<RenderText>(*renderer).firstRunLocation());
+    } else if (is<RenderInline>(*renderer))
+        m_frameRect = downcast<RenderInline>(*renderer).borderBoundingBox();
 
     if (!shouldIncludeDescendants)
         return;