Use is<>() / downcast<>() for RenderBlock objects
https://bugs.webkit.org/show_bug.cgi?id=137512

Reviewed by Darin Adler.

Source/WebCore:

Use is<>() / downcast<>() for RenderBlock objects and clean up the
surrounding code.

No new tests, no behavior change.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::firstChildConsideringContinuation):
(WebCore::lastChildConsideringContinuation):
(WebCore::AccessibilityRenderObject::firstChild):
(WebCore::startOfContinuations):
(WebCore::endOfContinuations):
(WebCore::childBeforeConsideringContinuations):
(WebCore::AccessibilityRenderObject::previousSibling):
(WebCore::AccessibilityRenderObject::nextSibling):
(WebCore::nextContinuation):
(WebCore::AccessibilityRenderObject::renderParentObject):
(WebCore::AccessibilityRenderObject::anchorElement):
(WebCore::AccessibilityRenderObject::setValue):
* bindings/objc/DOMUIKitExtensions.mm:
(-[DOMNode containsOnlyInlineObjects]):
(-[DOMNode isSelectableBlock]):
(-[DOMHTMLElement structuralComplexityContribution]):
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::valueForGridTrackList):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::addBlockPlaceholderIfNeeded):
* editing/TextIterator.cpp:
(WebCore::TextIterator::shouldRepresentNodeOffsetZero):
* page/ios/FrameIOS.mm:
(WebCore::Frame::preferredHeight):
* rendering/LogicalSelectionOffsetCaches.h:
(WebCore::containingBlockForFixedPosition):
(WebCore::containingBlockForAbsolutePosition):
(WebCore::containingBlockForObjectInFlow):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::styleWillChange):
(WebCore::RenderBlock::continuationBefore):
(WebCore::RenderBlock::splitBlocks):
(WebCore::RenderBlock::addChildIgnoringContinuation):
(WebCore::canMergeAnonymousBlock):
(WebCore::canMergeContiguousAnonymousBlocks):
(WebCore::RenderBlock::collapseAnonymousBoxChild):
(WebCore::RenderBlock::removeChild):
(WebCore::RenderBlock::blockElementContinuation):
(WebCore::RenderBlock::blockSelectionGaps):
(WebCore::RenderBlock::blockBeforeWithinSelectionRoot):
(WebCore::isChildHitTestCandidate):
(WebCore::RenderBlock::firstLineBlock):
(WebCore::findFirstLetterBlock):
(WebCore::RenderBlock::childBecameNonInline):
(WebCore::RenderBlock::hasMarginBeforeQuirk):
(WebCore::RenderBlock::hasMarginAfterQuirk):
* rendering/RenderBlock.h:
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::marginBeforeEstimateForChild):
(WebCore::RenderBlockFlow::estimateLogicalTopPosition):
(WebCore::RenderBlockFlow::adjustBlockChildForPagination):
(WebCore::RenderBlockFlow::positionNewFloats):
(WebCore::RenderBlockFlow::markSiblingsWithFloatsForLayout):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::RenderBlockFlow::positionNewFloatOnLine):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::computeReplacedLogicalHeightUsing):
(WebCore::RenderBox::availableLogicalHeightUsing):
(WebCore::RenderBox::containingBlockLogicalWidthForPositioned):
(WebCore::RenderBox::containingBlockLogicalHeightForPositioned):
(WebCore::computeInlineStaticDistance):
(WebCore::RenderBox::computePositionedLogicalWidth):
(WebCore::RenderBox::computePositionedLogicalHeight):
* rendering/RenderBoxModelObject.cpp:
(WebCore::accumulateInFlowPositionOffsets):
(WebCore::RenderBoxModelObject::moveChildTo):
(WebCore::RenderBoxModelObject::moveChildrenTo):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::propagateStyleToAnonymousChildren):
* rendering/RenderFlowThread.cpp:
(WebCore::RenderFlowThread::adjustedPositionRelativeToOffsetParent):
* rendering/RenderFullScreen.cpp:
(WebCore::RenderFullScreen::unwrapRenderer):
* rendering/RenderInline.cpp:
(WebCore::RenderInline::inlineElementContinuation):
(WebCore::updateStyleOfAnonymousBlockContinuations):
(WebCore::RenderInline::styleDidChange):
(WebCore::nextContinuation):
(WebCore::RenderInline::splitFlow):
(WebCore::RenderInline::positionForPoint):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateScrollbarsAfterLayout):
(WebCore::RenderLayer::calculateClipRects):
* rendering/RenderListItem.cpp:
(WebCore::getParentOfFirstLineBox):
(WebCore::RenderListItem::insertOrMoveMarkerRendererIfNeeded):
(WebCore::RenderListItem::positionListMarker):
* rendering/RenderNamedFlowFragment.cpp:
(WebCore::RenderNamedFlowFragment::maxPageLogicalHeight):
* rendering/RenderObject.cpp:
(WebCore::includeNonFixedHeight):
(WebCore::RenderObject::checkBlockPositionedObjectsNeedLayout):
(WebCore::RenderObject::containingBlock):
(WebCore::RenderObject::handleDynamicFloatPositionChange):
(WebCore::RenderObject::removeAnonymousWrappersForInlinesIfNecessary):
(WebCore::RenderObject::getTextDecorationColors):
* rendering/RenderRuby.cpp:
(WebCore::rubyBeforeBlock):
(WebCore::rubyAfterBlock):
* rendering/RenderRubyBase.cpp:
(WebCore::RenderRubyBase::moveInlineChildren):
(WebCore::RenderRubyBase::moveBlockChildren):
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintSnapshottedPluginOverlay):
* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::processSubtree):
(WebCore::TextAutosizer::processContainer):
(WebCore::TextAutosizer::measureDescendantTextWidth):
(WebCore::TextAutosizer::findDeepestBlockContainingAllText):
(WebCore::TextAutosizer::findFirstTextLeafNotInCluster):
* rendering/mathml/RenderMathMLRoot.cpp:
(WebCore::RenderMathMLRoot::layout):

Source/WebKit2:

Use is<>() / downcast<>() for RenderBlock objects and clean up the
surrounding code.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::rangeForWebSelectionAtPosition):
(WebKit::WebPage::contractedRangeFromHandle):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index fd0ca85..ce3e9ff 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,129 @@
+2014-10-08  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for RenderBlock objects
+        https://bugs.webkit.org/show_bug.cgi?id=137512
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for RenderBlock objects and clean up the
+        surrounding code.
+
+        No new tests, no behavior change.
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::firstChildConsideringContinuation):
+        (WebCore::lastChildConsideringContinuation):
+        (WebCore::AccessibilityRenderObject::firstChild):
+        (WebCore::startOfContinuations):
+        (WebCore::endOfContinuations):
+        (WebCore::childBeforeConsideringContinuations):
+        (WebCore::AccessibilityRenderObject::previousSibling):
+        (WebCore::AccessibilityRenderObject::nextSibling):
+        (WebCore::nextContinuation):
+        (WebCore::AccessibilityRenderObject::renderParentObject):
+        (WebCore::AccessibilityRenderObject::anchorElement):
+        (WebCore::AccessibilityRenderObject::setValue):
+        * bindings/objc/DOMUIKitExtensions.mm:
+        (-[DOMNode containsOnlyInlineObjects]):
+        (-[DOMNode isSelectableBlock]):
+        (-[DOMHTMLElement structuralComplexityContribution]):
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::valueForGridTrackList):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::addBlockPlaceholderIfNeeded):
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::shouldRepresentNodeOffsetZero):
+        * page/ios/FrameIOS.mm:
+        (WebCore::Frame::preferredHeight):
+        * rendering/LogicalSelectionOffsetCaches.h:
+        (WebCore::containingBlockForFixedPosition):
+        (WebCore::containingBlockForAbsolutePosition):
+        (WebCore::containingBlockForObjectInFlow):
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::styleWillChange):
+        (WebCore::RenderBlock::continuationBefore):
+        (WebCore::RenderBlock::splitBlocks):
+        (WebCore::RenderBlock::addChildIgnoringContinuation):
+        (WebCore::canMergeAnonymousBlock):
+        (WebCore::canMergeContiguousAnonymousBlocks):
+        (WebCore::RenderBlock::collapseAnonymousBoxChild):
+        (WebCore::RenderBlock::removeChild):
+        (WebCore::RenderBlock::blockElementContinuation):
+        (WebCore::RenderBlock::blockSelectionGaps):
+        (WebCore::RenderBlock::blockBeforeWithinSelectionRoot):
+        (WebCore::isChildHitTestCandidate):
+        (WebCore::RenderBlock::firstLineBlock):
+        (WebCore::findFirstLetterBlock):
+        (WebCore::RenderBlock::childBecameNonInline):
+        (WebCore::RenderBlock::hasMarginBeforeQuirk):
+        (WebCore::RenderBlock::hasMarginAfterQuirk):
+        * rendering/RenderBlock.h:
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::marginBeforeEstimateForChild):
+        (WebCore::RenderBlockFlow::estimateLogicalTopPosition):
+        (WebCore::RenderBlockFlow::adjustBlockChildForPagination):
+        (WebCore::RenderBlockFlow::positionNewFloats):
+        (WebCore::RenderBlockFlow::markSiblingsWithFloatsForLayout):
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlockFlow::positionNewFloatOnLine):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::computeReplacedLogicalHeightUsing):
+        (WebCore::RenderBox::availableLogicalHeightUsing):
+        (WebCore::RenderBox::containingBlockLogicalWidthForPositioned):
+        (WebCore::RenderBox::containingBlockLogicalHeightForPositioned):
+        (WebCore::computeInlineStaticDistance):
+        (WebCore::RenderBox::computePositionedLogicalWidth):
+        (WebCore::RenderBox::computePositionedLogicalHeight):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::accumulateInFlowPositionOffsets):
+        (WebCore::RenderBoxModelObject::moveChildTo):
+        (WebCore::RenderBoxModelObject::moveChildrenTo):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::propagateStyleToAnonymousChildren):
+        * rendering/RenderFlowThread.cpp:
+        (WebCore::RenderFlowThread::adjustedPositionRelativeToOffsetParent):
+        * rendering/RenderFullScreen.cpp:
+        (WebCore::RenderFullScreen::unwrapRenderer):
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::inlineElementContinuation):
+        (WebCore::updateStyleOfAnonymousBlockContinuations):
+        (WebCore::RenderInline::styleDidChange):
+        (WebCore::nextContinuation):
+        (WebCore::RenderInline::splitFlow):
+        (WebCore::RenderInline::positionForPoint):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::updateScrollbarsAfterLayout):
+        (WebCore::RenderLayer::calculateClipRects):
+        * rendering/RenderListItem.cpp:
+        (WebCore::getParentOfFirstLineBox):
+        (WebCore::RenderListItem::insertOrMoveMarkerRendererIfNeeded):
+        (WebCore::RenderListItem::positionListMarker):
+        * rendering/RenderNamedFlowFragment.cpp:
+        (WebCore::RenderNamedFlowFragment::maxPageLogicalHeight):
+        * rendering/RenderObject.cpp:
+        (WebCore::includeNonFixedHeight):
+        (WebCore::RenderObject::checkBlockPositionedObjectsNeedLayout):
+        (WebCore::RenderObject::containingBlock):
+        (WebCore::RenderObject::handleDynamicFloatPositionChange):
+        (WebCore::RenderObject::removeAnonymousWrappersForInlinesIfNecessary):
+        (WebCore::RenderObject::getTextDecorationColors):
+        * rendering/RenderRuby.cpp:
+        (WebCore::rubyBeforeBlock):
+        (WebCore::rubyAfterBlock):
+        * rendering/RenderRubyBase.cpp:
+        (WebCore::RenderRubyBase::moveInlineChildren):
+        (WebCore::RenderRubyBase::moveBlockChildren):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintSnapshottedPluginOverlay):
+        * rendering/TextAutosizer.cpp:
+        (WebCore::TextAutosizer::processSubtree):
+        (WebCore::TextAutosizer::processContainer):
+        (WebCore::TextAutosizer::measureDescendantTextWidth):
+        (WebCore::TextAutosizer::findDeepestBlockContainingAllText):
+        (WebCore::TextAutosizer::findFirstTextLeafNotInCluster):
+        * rendering/mathml/RenderMathMLRoot.cpp:
+        (WebCore::RenderMathMLRoot::layout):
+
 2014-10-08  Jer Noble  <jer.noble@apple.com>
 
         Unreviewed follow-up fix for r174460. Do not register for KVOs if the object does not respond to the requested property.
diff --git a/Source/WebCore/accessibility/AccessibilityRenderObject.cpp b/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
index ef3218f..f576914 100644
--- a/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
+++ b/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
@@ -186,37 +186,35 @@
     return nullptr;
 }
 
-static inline RenderObject* firstChildConsideringContinuation(RenderObject* renderer)
+static inline RenderObject* firstChildConsideringContinuation(RenderObject& renderer)
 {
-    RenderObject* firstChild = renderer->firstChildSlow();
+    RenderObject* firstChild = renderer.firstChildSlow();
 
-    if (!firstChild && isInlineWithContinuation(renderer))
-        firstChild = firstChildInContinuation(toRenderInline(*renderer));
+    if (!firstChild && isInlineWithContinuation(&renderer))
+        firstChild = firstChildInContinuation(downcast<RenderInline>(renderer));
 
     return firstChild;
 }
 
 
-static inline RenderObject* lastChildConsideringContinuation(RenderObject* renderer)
+static inline RenderObject* lastChildConsideringContinuation(RenderObject& renderer)
 {
-    RenderObject* lastChild = renderer->lastChildSlow();
-    RenderObject* prev;
-    RenderObject* cur = renderer;
+    if (!is<RenderInline>(renderer) && !is<RenderBlock>(renderer))
+        return &renderer;
 
-    if (!cur->isRenderInline() && !cur->isRenderBlock())
-        return renderer;
+    RenderObject* lastChild = downcast<RenderBoxModelObject>(renderer).lastChild();
+    RenderBoxModelObject* previous;
+    for (auto* current = &downcast<RenderBoxModelObject>(renderer); current; ) {
+        previous = current;
 
-    while (cur) {
-        prev = cur;
+        if (RenderObject* newLastChild = current->lastChild())
+            lastChild = newLastChild;
 
-        if (RenderObject* lc = cur->lastChildSlow())
-            lastChild = lc;
-
-        if (cur->isRenderInline()) {
-            cur = toRenderInline(cur)->inlineElementContinuation();
-            ASSERT_UNUSED(prev, cur || !toRenderInline(prev)->continuation());
+        if (is<RenderInline>(*current)) {
+            current = downcast<RenderInline>(*current).inlineElementContinuation();
+            ASSERT_UNUSED(previous, current || !downcast<RenderInline>(*previous).continuation());
         } else
-            cur = toRenderBlock(cur)->inlineElementContinuation();
+            current = downcast<RenderBlock>(*current).inlineElementContinuation();
     }
 
     return lastChild;
@@ -227,7 +225,7 @@
     if (!m_renderer)
         return nullptr;
     
-    RenderObject* firstChild = firstChildConsideringContinuation(m_renderer);
+    RenderObject* firstChild = firstChildConsideringContinuation(*m_renderer);
 
     // If an object can't have children, then it is using this method to help
     // calculate some internal property (like its description).
@@ -244,7 +242,7 @@
     if (!m_renderer)
         return nullptr;
 
-    RenderObject* lastChild = lastChildConsideringContinuation(m_renderer);
+    RenderObject* lastChild = lastChildConsideringContinuation(*m_renderer);
 
     if (!lastChild && !canHaveChildren())
         return AccessibilityNodeObject::lastChild();
@@ -252,67 +250,61 @@
     return axObjectCache()->getOrCreate(lastChild);
 }
 
-static inline RenderInline* startOfContinuations(RenderObject* r)
+static inline RenderInline* startOfContinuations(RenderObject& renderer)
 {
-    if (r->isInlineElementContinuation())
-        return toRenderInline(r->node()->renderer());
+    if (renderer.isInlineElementContinuation())
+        return downcast<RenderInline>(renderer.node()->renderer());
 
     // Blocks with a previous continuation always have a next continuation
-    if (r->isRenderBlock() && toRenderBlock(r)->inlineElementContinuation())
-        return toRenderInline(toRenderBlock(r)->inlineElementContinuation()->element()->renderer());
+    if (is<RenderBlock>(renderer) && downcast<RenderBlock>(renderer).inlineElementContinuation())
+        return downcast<RenderInline>(downcast<RenderBlock>(renderer).inlineElementContinuation()->element()->renderer());
 
     return nullptr;
 }
 
-static inline RenderObject* endOfContinuations(RenderObject* renderer)
+static inline RenderObject* endOfContinuations(RenderObject& renderer)
 {
-    RenderObject* prev = renderer;
-    RenderObject* cur = renderer;
+    if (!is<RenderInline>(renderer) && !is<RenderBlock>(renderer))
+        return &renderer;
 
-    if (!cur->isRenderInline() && !cur->isRenderBlock())
-        return renderer;
-
-    while (cur) {
-        prev = cur;
-        if (cur->isRenderInline()) {
-            cur = toRenderInline(cur)->inlineElementContinuation();
-            ASSERT(cur || !toRenderInline(prev)->continuation());
+    auto* previous = &downcast<RenderBoxModelObject>(renderer);
+    for (auto* current = previous; current; ) {
+        previous = current;
+        if (is<RenderInline>(*current)) {
+            current = downcast<RenderInline>(*current).inlineElementContinuation();
+            ASSERT(current || !downcast<RenderInline>(*previous).continuation());
         } else 
-            cur = toRenderBlock(cur)->inlineElementContinuation();
+            current = downcast<RenderBlock>(*current).inlineElementContinuation();
     }
 
-    return prev;
+    return previous;
 }
 
 
-static inline RenderObject* childBeforeConsideringContinuations(RenderInline* r, RenderObject* child)
+static inline RenderObject* childBeforeConsideringContinuations(RenderInline* renderer, RenderObject* child)
 {
-    RenderBoxModelObject* curContainer = r;
-    RenderObject* cur = nullptr;
-    RenderObject* prev = nullptr;
-
-    while (curContainer) {
-        if (curContainer->isRenderInline()) {
-            cur = curContainer->firstChild();
-            while (cur) {
-                if (cur == child)
-                    return prev;
-                prev = cur;
-                cur = cur->nextSibling();
+    RenderObject* previous = nullptr;
+    for (RenderBoxModelObject* currentContainer = renderer; currentContainer; ) {
+        if (is<RenderInline>(*currentContainer)) {
+            auto* current = currentContainer->firstChild();
+            while (current) {
+                if (current == child)
+                    return previous;
+                previous = current;
+                current = current->nextSibling();
             }
 
-            curContainer = toRenderInline(curContainer)->continuation();
-        } else if (curContainer->isRenderBlock()) {
-            if (curContainer == child)
-                return prev;
+            currentContainer = downcast<RenderInline>(*currentContainer).continuation();
+        } else if (is<RenderBlock>(*currentContainer)) {
+            if (currentContainer == child)
+                return previous;
 
-            prev = curContainer;
-            curContainer = toRenderBlock(curContainer)->inlineElementContinuation();
+            previous = currentContainer;
+            currentContainer = downcast<RenderBlock>(*currentContainer).inlineElementContinuation();
         }
     }
 
     ASSERT_NOT_REACHED();
-
     return nullptr;
 }
 
@@ -332,15 +324,15 @@
     // Case 1: The node is a block and is an inline's continuation. In that case, the inline's
     // last child is our previous sibling (or further back in the continuation chain)
     RenderInline* startOfConts;
-    if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer)))
+    if (is<RenderBox>(*m_renderer) && (startOfConts = startOfContinuations(*m_renderer)))
         previousSibling = childBeforeConsideringContinuations(startOfConts, m_renderer);
 
     // Case 2: Anonymous block parent of the end of a continuation - skip all the way to before
     // the parent of the start, since everything in between will be linked up via the continuation.
     else if (m_renderer->isAnonymousBlock() && firstChildIsInlineContinuation(m_renderer)) {
-        RenderObject* firstParent = startOfContinuations(m_renderer->firstChildSlow())->parent();
+        auto* firstParent = startOfContinuations(*m_renderer->firstChildSlow())->parent();
         while (firstChildIsInlineContinuation(firstParent))
-            firstParent = startOfContinuations(firstParent->firstChildSlow())->parent();
+            firstParent = startOfContinuations(*firstParent->firstChild())->parent();
         previousSibling = firstParent->previousSibling();
     }
 
@@ -350,7 +342,7 @@
 
     // Case 4: This node has no previous siblings, but its parent is an inline,
     // and is another node's inline continutation. Follow the continuation chain.
-    else if (m_renderer->parent()->isRenderInline() && (startOfConts = startOfContinuations(m_renderer->parent())))
+    else if (is<RenderInline>(*m_renderer->parent()) && (startOfConts = startOfContinuations(*m_renderer->parent())))
         previousSibling = childBeforeConsideringContinuations(startOfConts, m_renderer->parent()->firstChild());
 
     if (!previousSibling)
@@ -375,15 +367,15 @@
     // Case 1: node is a block and has an inline continuation. Next sibling is the inline continuation's
     // first child.
     RenderInline* inlineContinuation;
-    if (m_renderer->isRenderBlock() && (inlineContinuation = toRenderBlock(m_renderer)->inlineElementContinuation()))
-        nextSibling = firstChildConsideringContinuation(inlineContinuation);
+    if (is<RenderBlock>(*m_renderer) && (inlineContinuation = downcast<RenderBlock>(*m_renderer).inlineElementContinuation()))
+        nextSibling = firstChildConsideringContinuation(*inlineContinuation);
 
     // Case 2: Anonymous block parent of the start of a continuation - skip all the way to
     // after the parent of the end, since everything in between will be linked up via the continuation.
     else if (m_renderer->isAnonymousBlock() && lastChildHasContinuation(m_renderer)) {
-        RenderElement* lastParent = endOfContinuations(toRenderBlock(m_renderer)->lastChild())->parent();
+        RenderElement* lastParent = endOfContinuations(*downcast<RenderBlock>(*m_renderer).lastChild())->parent();
         while (lastChildHasContinuation(lastParent))
-            lastParent = endOfContinuations(lastParent->lastChild())->parent();
+            lastParent = endOfContinuations(*lastParent->lastChild())->parent();
         nextSibling = lastParent->nextSibling();
     }
 
@@ -394,15 +386,15 @@
     // Case 4: node is an inline with a continuation. Next sibling is the next sibling of the end 
     // of the continuation chain.
     else if (isInlineWithContinuation(m_renderer))
-        nextSibling = endOfContinuations(m_renderer)->nextSibling();
+        nextSibling = endOfContinuations(*m_renderer)->nextSibling();
 
     // Case 5: node has no next sibling, and its parent is an inline with a continuation.
     else if (isInlineWithContinuation(m_renderer->parent())) {
-        auto continuation = toRenderInline(m_renderer->parent())->continuation();
+        auto& continuation = *downcast<RenderInline>(*m_renderer->parent()).continuation();
         
         // Case 5a: continuation is a block - in this case the block itself is the next sibling.
-        if (continuation->isRenderBlock())
-            nextSibling = continuation;
+        if (is<RenderBlock>(continuation))
+            nextSibling = &continuation;
         // Case 5b: continuation is an inline - in this case the inline's first child is the next sibling
         else
             nextSibling = firstChildConsideringContinuation(continuation);
@@ -414,13 +406,12 @@
     return axObjectCache()->getOrCreate(nextSibling);
 }
 
-static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
+static RenderBoxModelObject* nextContinuation(RenderObject& renderer)
 {
-    ASSERT(renderer);
-    if (renderer->isRenderInline() && !renderer->isReplaced())
-        return toRenderInline(renderer)->continuation();
-    if (renderer->isRenderBlock())
-        return toRenderBlock(renderer)->inlineElementContinuation();
+    if (is<RenderInline>(renderer) && !renderer.isReplaced())
+        return downcast<RenderInline>(renderer).continuation();
+    if (is<RenderBlock>(renderer))
+        return downcast<RenderBlock>(renderer).inlineElementContinuation();
     return nullptr;
 }
     
@@ -435,12 +426,12 @@
     // is the start of the continuation chain.
     RenderInline* startOfConts = nullptr;
     RenderObject* firstChild = nullptr;
-    if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer)))
+    if (is<RenderBlock>(*m_renderer) && (startOfConts = startOfContinuations(*m_renderer)))
         parent = startOfConts;
 
     // Case 2: node's parent is an inline which is some node's continuation; parent is 
     // the earliest node in the continuation chain.
-    else if (parent && parent->isRenderInline() && (startOfConts = startOfContinuations(parent)))
+    else if (is<RenderInline>(parent) && (startOfConts = startOfContinuations(*parent)))
         parent = startOfConts;
     
     // Case 3: The first sibling is the beginning of a continuation chain. Find the origin of that continuation.
@@ -448,7 +439,7 @@
         // Get the node's renderer and follow that continuation chain until the first child is found
         RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
         while (nodeRenderFirstChild != firstChild) {
-            for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(contsTest)) {
+            for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(*contsTest)) {
                 if (contsTest == firstChild) {
                     parent = nodeRenderFirstChild->parent();
                     break;
@@ -566,25 +557,23 @@
     if (!cache)
         return nullptr;
     
-    RenderObject* currRenderer;
+    RenderObject* currentRenderer;
     
     // Search up the render tree for a RenderObject with a DOM node.  Defer to an earlier continuation, though.
-    for (currRenderer = m_renderer; currRenderer && !currRenderer->node(); currRenderer = currRenderer->parent()) {
-        if (currRenderer->isAnonymousBlock()) {
-            RenderObject* continuation = toRenderBlock(currRenderer)->continuation();
-            if (continuation)
+    for (currentRenderer = m_renderer; currentRenderer && !currentRenderer->node(); currentRenderer = currentRenderer->parent()) {
+        if (currentRenderer->isAnonymousBlock()) {
+            if (RenderObject* continuation = downcast<RenderBlock>(*currentRenderer).continuation())
                 return cache->getOrCreate(continuation)->anchorElement();
         }
     }
     
     // bail if none found
-    if (!currRenderer)
-        return 0;
+    if (!currentRenderer)
+        return nullptr;
     
     // search up the DOM tree for an anchor element
     // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
-    Node* node = currRenderer->node();
-    for ( ; node; node = node->parentNode()) {
+    for (Node* node = currentRenderer->node(); node; node = node->parentNode()) {
         if (is<HTMLAnchorElement>(*node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
             return downcast<Element>(node);
     }
@@ -1677,14 +1666,14 @@
         return;
     Element& element = downcast<Element>(*m_renderer->node());
 
-    if (!m_renderer->isBoxModelObject())
+    if (!is<RenderBoxModelObject>(*m_renderer))
         return;
-    RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
+    RenderBoxModelObject& renderer = downcast<RenderBoxModelObject>(*m_renderer);
 
     // FIXME: Do we want to do anything here for ARIA textboxes?
-    if (renderer->isTextField() && is<HTMLInputElement>(element))
+    if (renderer.isTextField() && is<HTMLInputElement>(element))
         downcast<HTMLInputElement>(element).setValue(string);
-    else if (renderer->isTextArea() && is<HTMLTextAreaElement>(element))
+    else if (renderer.isTextArea() && is<HTMLTextAreaElement>(element))
         downcast<HTMLTextAreaElement>(element).setValue(string);
 }
 
diff --git a/Source/WebCore/bindings/objc/DOMUIKitExtensions.mm b/Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
index c55db01..ca0d889 100644
--- a/Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
+++ b/Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
@@ -207,17 +207,17 @@
 
 - (BOOL)containsOnlyInlineObjects
 {
-    RenderObject * renderer = core(self)->renderer();
-    return  (renderer &&
-             renderer->childrenInline() &&
-             (renderer->isRenderBlock() && toRenderBlock(renderer)->inlineElementContinuation() == nil) &&
-             !renderer->isTable());
+    RenderObject* renderer = core(self)->renderer();
+    return renderer
+        && renderer->childrenInline()
+        && (is<RenderBlock>(*renderer) && !downcast<RenderBlock>(*renderer).inlineElementContinuation())
+        && !renderer->isTable();
 }
 
 - (BOOL)isSelectableBlock
 {
-    RenderObject * renderer = core(self)->renderer();
-    return (renderer && (renderer->isRenderBlockFlow() || (renderer->isRenderBlock() && toRenderBlock(renderer)->inlineElementContinuation() != nil)));
+    RenderObject* renderer = core(self)->renderer();
+    return renderer && (is<RenderBlockFlow>(*renderer) || (is<RenderBlock>(*renderer) && downcast<RenderBlock>(*renderer).inlineElementContinuation() != nil));
 }
 
 - (DOMRange *)rangeOfContainingParagraph
@@ -344,12 +344,12 @@
             result = INT_MAX;
         } else if (renderer->isEmpty()) {
             result = 0;
-        } else if (renderer->isRenderBlockFlow() || (renderer->isRenderBlock() && toRenderBlock(renderer)->inlineElementContinuation() != 0)) {
+        } else if (is<RenderBlockFlow>(*renderer) || (is<RenderBlock>(*renderer) && downcast<RenderBlock>(*renderer).inlineElementContinuation())) {
             BOOL noCost = NO;
-            if (renderer->isBox()) {
-                RenderBox &asBox = renderer->enclosingBox();
-                RenderObject *parent = asBox.parent();
-                RenderBox *parentRenderBox = (parent && parent->isBox()) ? toRenderBox(parent) : 0;
+            if (is<RenderBox>(*renderer)) {
+                RenderBox& asBox = renderer->enclosingBox();
+                RenderObject* parent = asBox.parent();
+                RenderBox* parentRenderBox = is<RenderBox>(parent) ? downcast<RenderBox>(parent) : nullptr;
                 if (parentRenderBox && asBox.width() == parentRenderBox->width()) {
                     noCost = YES;
                 }
diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
index ce5ee6e..da23d13 100644
--- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
+++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
@@ -1007,7 +1007,7 @@
 {
     const Vector<GridTrackSize>& trackSizes = direction == ForColumns ? style->gridColumns() : style->gridRows();
     const OrderedNamedGridLinesMap& orderedNamedGridLines = direction == ForColumns ? style->orderedNamedGridColumnLines() : style->orderedNamedGridRowLines();
-    bool isRenderGrid = renderer && renderer->isRenderGrid();
+    bool isRenderGrid = is<RenderGrid>(renderer);
 
     // Handle the 'none' case.
     bool trackListIsEmpty = trackSizes.isEmpty();
@@ -1015,7 +1015,7 @@
         // For grids we should consider every listed track, whether implicitly or explicitly created. If we don't have
         // any explicit track and there are no children then there are no implicit tracks. We cannot simply check the
         // number of rows/columns in our internal grid representation because it's always at least 1x1 (see r143331).
-        trackListIsEmpty = !toRenderBlock(renderer)->firstChild();
+        trackListIsEmpty = !downcast<RenderBlock>(*renderer).firstChild();
     }
 
     if (trackListIsEmpty) {
@@ -1025,7 +1025,7 @@
 
     auto list = CSSValueList::createSpaceSeparated();
     if (isRenderGrid) {
-        const Vector<LayoutUnit>& trackPositions = direction == ForColumns ? toRenderGrid(renderer)->columnPositions() : toRenderGrid(renderer)->rowPositions();
+        const Vector<LayoutUnit>& trackPositions = direction == ForColumns ? downcast<RenderGrid>(*renderer).columnPositions() : downcast<RenderGrid>(*renderer).rowPositions();
         // There are at least #tracks + 1 grid lines (trackPositions). Apart from that, the grid container can generate implicit grid tracks,
         // so we'll have more trackPositions than trackSizes as the latter only contain the explicit grid.
         ASSERT(trackPositions.size() - 1 >= trackSizes.size());
diff --git a/Source/WebCore/editing/CompositeEditCommand.cpp b/Source/WebCore/editing/CompositeEditCommand.cpp
index 3464c27..584948a 100644
--- a/Source/WebCore/editing/CompositeEditCommand.cpp
+++ b/Source/WebCore/editing/CompositeEditCommand.cpp
@@ -55,10 +55,10 @@
 #include "RemoveCSSPropertyCommand.h"
 #include "RemoveNodeCommand.h"
 #include "RemoveNodePreservingChildrenCommand.h"
+#include "RenderBlockFlow.h"
+#include "RenderText.h"
 #include "ReplaceNodeWithSpanCommand.h"
 #include "ReplaceSelectionCommand.h"
-#include "RenderBlock.h"
-#include "RenderText.h"
 #include "ScopedEventQueue.h"
 #include "SetNodeAttributeCommand.h"
 #include "SplitElementCommand.h"
@@ -929,21 +929,21 @@
 PassRefPtr<Node> CompositeEditCommand::addBlockPlaceholderIfNeeded(Element* container)
 {
     if (!container)
-        return 0;
+        return nullptr;
 
     document().updateLayoutIgnorePendingStylesheets();
 
     RenderObject* renderer = container->renderer();
-    if (!renderer || !renderer->isRenderBlockFlow())
-        return 0;
+    if (!is<RenderBlockFlow>(renderer))
+        return nullptr;
     
     // append the placeholder to make sure it follows
     // any unrendered blocks
-    RenderBlock* block = toRenderBlock(renderer);
-    if (block->height() == 0 || (block->isListItem() && block->isEmpty()))
+    RenderBlockFlow& blockFlow = downcast<RenderBlockFlow>(*renderer);
+    if (!blockFlow.height() || (blockFlow.isListItem() && blockFlow.isEmpty()))
         return appendBlockPlaceholder(container);
 
-    return 0;
+    return nullptr;
 }
 
 // Assumes that the position is at a placeholder and does the removal without much checking.
diff --git a/Source/WebCore/editing/TextIterator.cpp b/Source/WebCore/editing/TextIterator.cpp
index 725a802..6be9723 100644
--- a/Source/WebCore/editing/TextIterator.cpp
+++ b/Source/WebCore/editing/TextIterator.cpp
@@ -963,7 +963,7 @@
     // Additionally, if the range we are iterating over contains huge sections of unrendered content, 
     // we would create VisiblePositions on every call to this function without this check.
     if (!m_node->renderer() || m_node->renderer()->style().visibility() != VISIBLE
-        || (m_node->renderer()->isRenderBlockFlow() && !toRenderBlock(m_node->renderer())->height() && !m_node->hasTagName(bodyTag)))
+        || (is<RenderBlockFlow>(*m_node->renderer()) && !downcast<RenderBlockFlow>(*m_node->renderer()).height() && !is<HTMLBodyElement>(*m_node)))
         return false;
 
     // The startPos.isNotNull() check is needed because the start could be before the body,
diff --git a/Source/WebCore/page/ios/FrameIOS.mm b/Source/WebCore/page/ios/FrameIOS.mm
index dd943eb..2ac4cfd 100644
--- a/Source/WebCore/page/ios/FrameIOS.mm
+++ b/Source/WebCore/page/ios/FrameIOS.mm
@@ -552,11 +552,11 @@
         return 0;
 
     RenderObject* renderer = body->renderer();
-    if (!renderer || !renderer->isRenderBlock())
+    if (!is<RenderBlock>(renderer))
         return 0;
 
-    RenderBlock* block = toRenderBlock(renderer);
-    return block->height() + block->marginTop() + block->marginBottom();
+    RenderBlock& block = downcast<RenderBlock>(*renderer);
+    return block.height() + block.marginTop() + block.marginBottom();
 }
 
 int Frame::innerLineHeight(DOMNode* domNode) const
diff --git a/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h b/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h
index fec52f7..59839e6 100644
--- a/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h
+++ b/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h
@@ -44,7 +44,7 @@
     while (object && !object->canContainFixedPositionObjects())
         object = object->parent();
     ASSERT(!object || !object->isAnonymousBlock());
-    return toRenderBlock(object);
+    return downcast<RenderBlock>(object);
 }
 
 static inline RenderBlock* containingBlockForAbsolutePosition(RenderElement* parent)
@@ -57,13 +57,13 @@
     // not the inline itself, to avoid having a positioned objects list in all RenderInlines
     // and use RenderBlock* as RenderElement::containingBlock's return type.
     // Use RenderBlock::container() to obtain the inline.
-    if (object && !object->isRenderBlock())
+    if (object && !is<RenderBlock>(*object))
         object = object->containingBlock();
 
     while (object && object->isAnonymousBlock())
         object = object->containingBlock();
 
-    return toRenderBlock(object);
+    return downcast<RenderBlock>(object);
 }
 
 static inline RenderBlock* containingBlockForObjectInFlow(RenderElement* parent)
@@ -71,7 +71,7 @@
     RenderElement* object = parent;
     while (object && isNonRenderBlockInline(*object))
         object = object->parent();
-    return toRenderBlock(object);
+    return downcast<RenderBlock>(object);
 }
 
 class LogicalSelectionOffsetCaches {
diff --git a/Source/WebCore/rendering/RenderBlock.cpp b/Source/WebCore/rendering/RenderBlock.cpp
index e12ebb5..aa1551f 100644
--- a/Source/WebCore/rendering/RenderBlock.cpp
+++ b/Source/WebCore/rendering/RenderBlock.cpp
@@ -272,17 +272,17 @@
         else if (oldStyle->position() == StaticPosition) {
             // Remove our absolutely positioned descendants from their current containing block.
             // They will be inserted into our positioned objects list during layout.
-            auto cb = parent();
-            while (cb && (cb->style().position() == StaticPosition || (cb->isInline() && !cb->isReplaced())) && !cb->isRenderView()) {
-                if (cb->style().position() == RelativePosition && cb->isInline() && !cb->isReplaced()) {
-                    cb = cb->containingBlock();
+            auto containingBlock = parent();
+            while (containingBlock && (containingBlock->style().position() == StaticPosition || (containingBlock->isInline() && !containingBlock->isReplaced())) && !containingBlock->isRenderView()) {
+                if (containingBlock->style().position() == RelativePosition && containingBlock->isInline() && !containingBlock->isReplaced()) {
+                    containingBlock = containingBlock->containingBlock();
                     break;
                 }
-                cb = cb->parent();
+                containingBlock = containingBlock->parent();
             }
             
-            if (cb->isRenderBlock())
-                toRenderBlock(cb)->removePositionedObjects(this, NewContainingBlock);
+            if (is<RenderBlock>(*containingBlock))
+                downcast<RenderBlock>(*containingBlock).removePositionedObjects(this, NewContainingBlock);
         }
     }
 
@@ -332,19 +332,17 @@
     if (beforeChild && beforeChild->parent() == this)
         return this;
 
-    RenderBlock* curr = toRenderBlock(continuation());
     RenderBlock* nextToLast = this;
     RenderBlock* last = this;
-    while (curr) {
-        if (beforeChild && beforeChild->parent() == curr) {
-            if (curr->firstChild() == beforeChild)
+    for (auto* current = downcast<RenderBlock>(continuation()); current; current = downcast<RenderBlock>(current->continuation())) {
+        if (beforeChild && beforeChild->parent() == current) {
+            if (current->firstChild() == beforeChild)
                 return last;
-            return curr;
+            return current;
         }
 
         nextToLast = last;
-        last = curr;
-        curr = toRenderBlock(curr->continuation());
+        last = current;
     }
 
     if (!beforeChild && !last->firstChild())
@@ -413,77 +411,6 @@
     return cloneBlock;
 }
 
-void RenderBlock::splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock,
-                              RenderBlock* middleBlock,
-                              RenderObject* beforeChild, RenderBoxModelObject* oldCont)
-{
-    // Create a clone of this inline.
-    RenderPtr<RenderBlock> cloneBlock = clone();
-    if (!isAnonymousBlock())
-        cloneBlock->setContinuation(oldCont);
-
-    if (!beforeChild && isAfterContent(lastChild()))
-        beforeChild = lastChild();
-
-    // If we are moving inline children from |this| to cloneBlock, then we need
-    // to clear our line box tree.
-    if (beforeChild && childrenInline())
-        deleteLines();
-
-    // Now take all of the children from beforeChild to the end and remove
-    // them from |this| and place them in the clone.
-    moveChildrenTo(cloneBlock.get(), beforeChild, 0, true);
-    
-    // Hook |clone| up as the continuation of the middle block.
-    if (!cloneBlock->isAnonymousBlock())
-        middleBlock->setContinuation(cloneBlock.get());
-
-    // We have been reparented and are now under the fromBlock.  We need
-    // to walk up our block parent chain until we hit the containing anonymous columns block.
-    // Once we hit the anonymous columns block we're done.
-    RenderBoxModelObject* curr = toRenderBoxModelObject(parent());
-    RenderBoxModelObject* currChild = this;
-    RenderObject* currChildNextSibling = currChild->nextSibling();
-
-    while (curr && curr->isDescendantOf(fromBlock) && curr != fromBlock) {
-        RenderBlock* blockCurr = toRenderBlock(curr);
-        
-        // Create a new clone.
-        RenderPtr<RenderBlock> cloneChild = WTF::move(cloneBlock);
-        cloneBlock = blockCurr->clone();
-
-        // Insert our child clone as the first child.
-        cloneBlock->addChildIgnoringContinuation(cloneChild.leakPtr(), 0);
-
-        // Hook the clone up as a continuation of |curr|.  Note we do encounter
-        // anonymous blocks possibly as we walk up the block chain.  When we split an
-        // anonymous block, there's no need to do any continuation hookup, since we haven't
-        // actually split a real element.
-        if (!blockCurr->isAnonymousBlock()) {
-            oldCont = blockCurr->continuation();
-            blockCurr->setContinuation(cloneBlock.get());
-            cloneBlock->setContinuation(oldCont);
-        }
-
-        // Now we need to take all of the children starting from the first child
-        // *after* currChild and append them all to the clone.
-        blockCurr->moveChildrenTo(cloneBlock.get(), currChildNextSibling, 0, true);
-
-        // Keep walking up the chain.
-        currChild = curr;
-        currChildNextSibling = currChild->nextSibling();
-        curr = toRenderBoxModelObject(curr->parent());
-    }
-
-    // Now we are at the columns block level. We need to put the clone into the toBlock.
-    toBlock->insertChildInternal(cloneBlock.leakPtr(), nullptr, NotifyChildren);
-
-    // Now take all the children after currChild and remove them from the fromBlock
-    // and put them in the toBlock.
-    if (currChildNextSibling && currChildNextSibling->parent() == fromBlock)
-        fromBlock->moveChildrenTo(toBlock, currChildNextSibling, 0, true);
-}
-
 void RenderBlock::addChild(RenderObject* newChild, RenderObject* beforeChild)
 {
     if (continuation() && !isAnonymousBlock())
@@ -559,7 +486,7 @@
         RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : lastChild();
 
         if (afterChild && afterChild->isAnonymousBlock()) {
-            toRenderBlock(afterChild)->addChild(newChild);
+            downcast<RenderBlock>(*afterChild).addChild(newChild);
             return;
         }
 
@@ -576,8 +503,8 @@
 
     RenderBox::addChild(newChild, beforeChild);
  
-    if (madeBoxesNonInline && parent() && isAnonymousBlock() && parent()->isRenderBlock())
-        toRenderBlock(parent())->removeLeftoverAnonymousBlock(this);
+    if (madeBoxesNonInline && is<RenderBlock>(parent()) && isAnonymousBlock())
+        downcast<RenderBlock>(*parent()).removeLeftoverAnonymousBlock(this);
     // this object may be dead here
 }
 
@@ -722,11 +649,11 @@
     child->destroy();
 }
 
-static bool canMergeAnonymousBlock(RenderBlock* anonymousBlock)
+static bool canMergeAnonymousBlock(RenderBlock& anonymousBlock)
 {
-    if (anonymousBlock->beingDestroyed() || anonymousBlock->continuation())
+    if (anonymousBlock.beingDestroyed() || anonymousBlock.continuation())
         return false;
-    if (anonymousBlock->isRubyRun() || anonymousBlock->isRubyBase())
+    if (anonymousBlock.isRubyRun() || anonymousBlock.isRubyBase())
         return false;
     return true;
 }
@@ -739,24 +666,24 @@
     if (previous) {
         if (!previous->isAnonymousBlock())
             return false;
-        RenderBlock* previousAnonymousBlock = toRenderBlock(previous);
+        RenderBlock& previousAnonymousBlock = downcast<RenderBlock>(*previous);
         if (!canMergeAnonymousBlock(previousAnonymousBlock))
             return false;
     }
     if (next) {
         if (!next->isAnonymousBlock())
             return false;
-        RenderBlock* nextAnonymousBlock = toRenderBlock(next);
+        RenderBlock& nextAnonymousBlock = downcast<RenderBlock>(*next);
         if (!canMergeAnonymousBlock(nextAnonymousBlock))
             return false;
     }
     return true;
 }
 
-void RenderBlock::collapseAnonymousBoxChild(RenderBlock* parent, RenderBlock* child)
+void RenderBlock::collapseAnonymousBoxChild(RenderBlock& parent, RenderBlock* child)
 {
-    parent->setNeedsLayoutAndPrefWidthsRecalc();
-    parent->setChildrenInline(child->childrenInline());
+    parent.setNeedsLayoutAndPrefWidthsRecalc();
+    parent.setChildrenInline(child->childrenInline());
     RenderObject* nextSibling = child->nextSibling();
 
     RenderFlowThread* childFlowThread = child->flowThreadContainingBlock();
@@ -764,8 +691,8 @@
     if (childFlowThread && childFlowThread->isRenderNamedFlowThread())
         toRenderNamedFlowThread(childFlowThread)->removeFlowChildInfo(child);
 
-    parent->removeChildInternal(*child, child->hasLayer() ? NotifyChildren : DontNotifyChildren);
-    child->moveAllChildrenTo(parent, nextSibling, child->hasLayer());
+    parent.removeChildInternal(*child, child->hasLayer() ? NotifyChildren : DontNotifyChildren);
+    child->moveAllChildrenTo(&parent, nextSibling, child->hasLayer());
     // Delete the now-empty block's lines and nuke it.
     child->deleteLines();
     child->destroy();
@@ -786,44 +713,44 @@
     bool canMergeAnonymousBlocks = canMergeContiguousAnonymousBlocks(oldChild, prev, next);
     if (canMergeAnonymousBlocks && prev && next) {
         prev->setNeedsLayoutAndPrefWidthsRecalc();
-        RenderBlock* nextBlock = toRenderBlock(next);
-        RenderBlock* prevBlock = toRenderBlock(prev);
+        RenderBlock& nextBlock = downcast<RenderBlock>(*next);
+        RenderBlock& prevBlock = downcast<RenderBlock>(*prev);
        
         if (prev->childrenInline() != next->childrenInline()) {
-            RenderBlock* inlineChildrenBlock = prev->childrenInline() ? prevBlock : nextBlock;
-            RenderBlock* blockChildrenBlock = prev->childrenInline() ? nextBlock : prevBlock;
+            RenderBlock& inlineChildrenBlock = prev->childrenInline() ? prevBlock : nextBlock;
+            RenderBlock& blockChildrenBlock = prev->childrenInline() ? nextBlock : prevBlock;
             
             // Place the inline children block inside of the block children block instead of deleting it.
             // In order to reuse it, we have to reset it to just be a generic anonymous block.  Make sure
             // to clear out inherited column properties by just making a new style, and to also clear the
             // column span flag if it is set.
-            ASSERT(!inlineChildrenBlock->continuation());
+            ASSERT(!inlineChildrenBlock.continuation());
             // Cache this value as it might get changed in setStyle() call.
-            bool inlineChildrenBlockHasLayer = inlineChildrenBlock->hasLayer();
-            inlineChildrenBlock->setStyle(RenderStyle::createAnonymousStyleWithDisplay(&style(), BLOCK));
-            removeChildInternal(*inlineChildrenBlock, inlineChildrenBlockHasLayer ? NotifyChildren : DontNotifyChildren);
+            bool inlineChildrenBlockHasLayer = inlineChildrenBlock.hasLayer();
+            inlineChildrenBlock.setStyle(RenderStyle::createAnonymousStyleWithDisplay(&style(), BLOCK));
+            removeChildInternal(inlineChildrenBlock, inlineChildrenBlockHasLayer ? NotifyChildren : DontNotifyChildren);
             
             // Now just put the inlineChildrenBlock inside the blockChildrenBlock.
-            RenderObject* beforeChild = prev == inlineChildrenBlock ? blockChildrenBlock->firstChild() : nullptr;
-            blockChildrenBlock->insertChildInternal(inlineChildrenBlock, beforeChild,
-                (inlineChildrenBlockHasLayer || blockChildrenBlock->hasLayer()) ? NotifyChildren : DontNotifyChildren);
+            RenderObject* beforeChild = prev == &inlineChildrenBlock ? blockChildrenBlock.firstChild() : nullptr;
+            blockChildrenBlock.insertChildInternal(&inlineChildrenBlock, beforeChild,
+                (inlineChildrenBlockHasLayer || blockChildrenBlock.hasLayer()) ? NotifyChildren : DontNotifyChildren);
             next->setNeedsLayoutAndPrefWidthsRecalc();
             
             // inlineChildrenBlock got reparented to blockChildrenBlock, so it is no longer a child
             // of "this". we null out prev or next so that is not used later in the function.
-            if (inlineChildrenBlock == prevBlock)
-                prev = 0;
+            if (&inlineChildrenBlock == &prevBlock)
+                prev = nullptr;
             else
-                next = 0;
+                next = nullptr;
         } else {
             // Take all the children out of the |next| block and put them in
             // the |prev| block.
-            nextBlock->moveAllChildrenIncludingFloatsTo(prevBlock, nextBlock->hasLayer() || prevBlock->hasLayer());
+            nextBlock.moveAllChildrenIncludingFloatsTo(&prevBlock, nextBlock.hasLayer() || prevBlock.hasLayer());
             
             // Delete the now-empty block's lines and nuke it.
-            nextBlock->deleteLines();
-            nextBlock->destroy();
-            next = 0;
+            nextBlock.deleteLines();
+            nextBlock.destroy();
+            next = nullptr;
         }
     }
 
@@ -836,17 +763,17 @@
         // The removal has knocked us down to containing only a single anonymous
         // box.  We can go ahead and pull the content right back up into our
         // box.
-        collapseAnonymousBoxChild(this, toRenderBlock(child));
+        collapseAnonymousBoxChild(*this, downcast<RenderBlock>(child));
         nextSibling = nullptr;
     } else if (((prev && prev->isAnonymousBlock()) || (next && next->isAnonymousBlock())) && canCollapseAnonymousBlockChild()) {
         // It's possible that the removal has knocked us down to a single anonymous
         // block with pseudo-style element siblings (e.g. first-letter). If these
         // are floating, then we need to pull the content up also.
-        RenderBlock* anonBlock = toRenderBlock((prev && prev->isAnonymousBlock()) ? prev : next);
+        RenderBlock* anonBlock = downcast<RenderBlock>((prev && prev->isAnonymousBlock()) ? prev : next);
         if ((anonBlock->previousSibling() || anonBlock->nextSibling())
             && (!anonBlock->previousSibling() || (anonBlock->previousSibling()->style().styleType() != NOPSEUDO && anonBlock->previousSibling()->isFloating() && !anonBlock->previousSibling()->previousSibling()))
             && (!anonBlock->nextSibling() || (anonBlock->nextSibling()->style().styleType() != NOPSEUDO && anonBlock->nextSibling()->isFloating() && !anonBlock->nextSibling()->nextSibling()))) {
-            collapseAnonymousBoxChild(this, anonBlock);
+            collapseAnonymousBoxChild(*this, anonBlock);
             nextSibling = nullptr;
         }
     }
@@ -864,23 +791,23 @@
             auto containingBlockIgnoringAnonymous = containingBlock();
             while (containingBlockIgnoringAnonymous && containingBlockIgnoringAnonymous->isAnonymousBlock())
                 containingBlockIgnoringAnonymous = containingBlockIgnoringAnonymous->containingBlock();
-            for (RenderObject* curr = this; curr; curr = curr->previousInPreOrder(containingBlockIgnoringAnonymous)) {
-                if (curr->virtualContinuation() != this)
+            for (RenderObject* current = this; current; current = current->previousInPreOrder(containingBlockIgnoringAnonymous)) {
+                if (current->virtualContinuation() != this)
                     continue;
 
                 // Found our previous continuation. We just need to point it to
                 // |this|'s next continuation.
                 RenderBoxModelObject* nextContinuation = continuation();
-                if (curr->isRenderInline())
-                    toRenderInline(curr)->setContinuation(nextContinuation);
-                else if (curr->isRenderBlock())
-                    toRenderBlock(curr)->setContinuation(nextContinuation);
+                if (is<RenderInline>(*current))
+                    downcast<RenderInline>(*current).setContinuation(nextContinuation);
+                else if (is<RenderBlock>(*current))
+                    downcast<RenderBlock>(*current).setContinuation(nextContinuation);
                 else
                     ASSERT_NOT_REACHED();
 
                 break;
             }
-            setContinuation(0);
+            setContinuation(nullptr);
             destroy();
         }
     }
@@ -1741,11 +1668,11 @@
 {
     RenderBoxModelObject* currentContinuation = continuation();
     if (!currentContinuation || currentContinuation->isInline())
-        return 0;
-    RenderBlock* nextContinuation = toRenderBlock(currentContinuation);
-    if (nextContinuation->isAnonymousBlock())
-        return nextContinuation->blockElementContinuation();
-    return nextContinuation;
+        return nullptr;
+    RenderBlock& nextContinuation = downcast<RenderBlock>(*currentContinuation);
+    if (nextContinuation.isAnonymousBlock())
+        return nextContinuation.blockElementContinuation();
+    return &nextContinuation;
 }
     
 static ContinuationOutlineTableMap* continuationOutlineTable()
@@ -2042,7 +1969,7 @@
             lastLogicalRight = logicalRightSelectionOffset(rootBlock, curr->logicalBottom(), cache);
         } else if (childState != SelectionNone) {
             // We must be a block that has some selected object inside it.  Go ahead and recur.
-            result.unite(toRenderBlock(curr)->selectionGaps(rootBlock, rootBlockPhysicalPosition, LayoutSize(offsetFromRootBlock.width() + curr->x(), offsetFromRootBlock.height() + curr->y()), 
+            result.unite(downcast<RenderBlock>(*curr).selectionGaps(rootBlock, rootBlockPhysicalPosition, LayoutSize(offsetFromRootBlock.width() + curr->x(), offsetFromRootBlock.height() + curr->y()),
                 lastLogicalTop, lastLogicalLeft, lastLogicalRight, childCache, paintInfo));
         }
     }
@@ -2162,29 +2089,29 @@
 RenderBlock* RenderBlock::blockBeforeWithinSelectionRoot(LayoutSize& offset) const
 {
     if (isSelectionRoot())
-        return 0;
+        return nullptr;
 
     const RenderElement* object = this;
     RenderObject* sibling;
     do {
         sibling = object->previousSibling();
-        while (sibling && (!sibling->isRenderBlock() || toRenderBlock(sibling)->isSelectionRoot()))
+        while (sibling && (!is<RenderBlock>(*sibling) || downcast<RenderBlock>(*sibling).isSelectionRoot()))
             sibling = sibling->previousSibling();
 
-        offset -= LayoutSize(toRenderBlock(object)->logicalLeft(), toRenderBlock(object)->logicalTop());
+        offset -= LayoutSize(downcast<RenderBlock>(*object).logicalLeft(), downcast<RenderBlock>(*object).logicalTop());
         object = object->parent();
-    } while (!sibling && object && object->isRenderBlock() && !toRenderBlock(object)->isSelectionRoot());
+    } while (!sibling && is<RenderBlock>(object) && !downcast<RenderBlock>(*object).isSelectionRoot());
 
     if (!sibling)
-        return 0;
+        return nullptr;
 
-    RenderBlock* beforeBlock = toRenderBlock(sibling);
+    RenderBlock* beforeBlock = downcast<RenderBlock>(sibling);
 
     offset += LayoutSize(beforeBlock->logicalLeft(), beforeBlock->logicalTop());
 
     RenderObject* child = beforeBlock->lastChild();
-    while (child && child->isRenderBlock()) {
-        beforeBlock = toRenderBlock(child);
+    while (is<RenderBlock>(child)) {
+        beforeBlock = downcast<RenderBlock>(child);
         offset += LayoutSize(beforeBlock->logicalLeft(), beforeBlock->logicalTop());
         child = beforeBlock->lastChild();
     }
@@ -2682,7 +2609,7 @@
         return false;
     if (!region)
         return true;
-    const RenderBlock& block = box.isRenderBlock() ? toRenderBlock(box) : *box.containingBlock();
+    const RenderBlock& block = is<RenderBlock>(box) ? downcast<RenderBlock>(box) : *box.containingBlock();
     return block.regionAtBlockOffset(point.y()) == region;
 }
 
@@ -3042,11 +2969,11 @@
         if (firstLineBlock->isReplaced() || firstLineBlock->isFloating()
             || !parentBlock || parentBlock->firstChild() != firstLineBlock || !isRenderBlockFlowOrRenderButton(*parentBlock))
             break;
-        firstLineBlock = toRenderBlock(parentBlock);
+        firstLineBlock = downcast<RenderBlock>(parentBlock);
     } 
     
     if (!hasPseudo)
-        return 0;
+        return nullptr;
     
     return firstLineBlock;
 }
@@ -3125,11 +3052,11 @@
         RenderElement* parentBlock = firstLetterBlock->parent();
         if (firstLetterBlock->isReplaced() || !parentBlock || parentBlock->firstChild() != firstLetterBlock
             || !isRenderBlockFlowOrRenderButton(*parentBlock))
-            return 0;
-        firstLetterBlock = toRenderBlock(parentBlock);
+            return nullptr;
+        firstLetterBlock = downcast<RenderBlock>(parentBlock);
     } 
 
-    return 0;
+    return nullptr;
 }
 
 void RenderBlock::updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderObject* currentChild)
@@ -3421,8 +3348,8 @@
 void RenderBlock::childBecameNonInline(RenderObject*)
 {
     makeChildrenNonInline();
-    if (isAnonymousBlock() && parent() && parent()->isRenderBlock())
-        toRenderBlock(parent())->removeLeftoverAnonymousBlock(this);
+    if (isAnonymousBlock() && is<RenderBlock>(parent()))
+        downcast<RenderBlock>(*parent()).removeLeftoverAnonymousBlock(this);
     // |this| may be dead here
 }
 
@@ -3671,12 +3598,12 @@
     // If the child has the same directionality as we do, then we can just return its
     // margin quirk.
     if (!child.isWritingModeRoot())
-        return child.isRenderBlock() ? toRenderBlock(child).hasMarginBeforeQuirk() : child.style().hasMarginBeforeQuirk();
+        return is<RenderBlock>(child) ? downcast<RenderBlock>(child).hasMarginBeforeQuirk() : child.style().hasMarginBeforeQuirk();
     
     // The child has a different directionality. If the child is parallel, then it's just
     // flipped relative to us. We can use the opposite edge.
     if (child.isHorizontalWritingMode() == isHorizontalWritingMode())
-        return child.isRenderBlock() ? toRenderBlock(child).hasMarginAfterQuirk() : child.style().hasMarginAfterQuirk();
+        return is<RenderBlock>(child) ? downcast<RenderBlock>(child).hasMarginAfterQuirk() : child.style().hasMarginAfterQuirk();
     
     // The child is perpendicular to us and box sides are never quirky in html.css, and we don't really care about
     // whether or not authors specified quirky ems, since they're an implementation detail.
@@ -3688,12 +3615,12 @@
     // If the child has the same directionality as we do, then we can just return its
     // margin quirk.
     if (!child.isWritingModeRoot())
-        return child.isRenderBlock() ? toRenderBlock(child).hasMarginAfterQuirk() : child.style().hasMarginAfterQuirk();
+        return is<RenderBlock>(child) ? downcast<RenderBlock>(child).hasMarginAfterQuirk() : child.style().hasMarginAfterQuirk();
     
     // The child has a different directionality. If the child is parallel, then it's just
     // flipped relative to us. We can use the opposite edge.
     if (child.isHorizontalWritingMode() == isHorizontalWritingMode())
-        return child.isRenderBlock() ? toRenderBlock(child).hasMarginBeforeQuirk() : child.style().hasMarginBeforeQuirk();
+        return is<RenderBlock>(child) ? downcast<RenderBlock>(child).hasMarginBeforeQuirk() : child.style().hasMarginBeforeQuirk();
     
     // The child is perpendicular to us and box sides are never quirky in html.css, and we don't really care about
     // whether or not authors specified quirky ems, since they're an implementation detail.
diff --git a/Source/WebCore/rendering/RenderBlock.h b/Source/WebCore/rendering/RenderBlock.h
index 6400db6..b79f88e 100644
--- a/Source/WebCore/rendering/RenderBlock.h
+++ b/Source/WebCore/rendering/RenderBlock.h
@@ -195,7 +195,7 @@
 
     static RenderBlock* createAnonymousWithParentRendererAndDisplay(const RenderObject*, EDisplay = BLOCK);
     RenderBlock* createAnonymousBlock(EDisplay display = BLOCK) const { return createAnonymousWithParentRendererAndDisplay(this, display); }
-    static void collapseAnonymousBoxChild(RenderBlock* parent, RenderBlock* child);
+    static void collapseAnonymousBoxChild(RenderBlock& parent, RenderBlock* child);
 
     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const override;
 
@@ -486,10 +486,6 @@
 
     bool expandsToEncloseOverhangingFloats() const;
 
-    void splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
-                     RenderObject* beforeChild, RenderBoxModelObject* oldCont);
-    void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
-                   RenderObject* newChild, RenderBoxModelObject* oldCont);
     RenderPtr<RenderBlock> clone() const;
     RenderBlock* continuationBefore(RenderObject* beforeChild);
 
@@ -530,8 +526,6 @@
     static bool s_canPropagateFloatIntoSibling;
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderBlock, isRenderBlock())
-
 LayoutUnit blockDirectionOffset(RenderBlock& rootBlock, const LayoutSize& offsetFromRootBlock);
 LayoutUnit inlineDirectionOffset(RenderBlock& rootBlock, const LayoutSize& offsetFromRootBlock);
 VisiblePosition positionForPointRespectingEditingBoundaries(RenderBlock&, RenderBox&, const LayoutPoint&);
diff --git a/Source/WebCore/rendering/RenderBlockFlow.cpp b/Source/WebCore/rendering/RenderBlockFlow.cpp
index d85bd82..ff96d51 100644
--- a/Source/WebCore/rendering/RenderBlockFlow.cpp
+++ b/Source/WebCore/rendering/RenderBlockFlow.cpp
@@ -1219,10 +1219,10 @@
     // Make sure to update the block margins now for the grandchild box so that we're looking at current values.
     if (grandchildBox->needsLayout()) {
         grandchildBox->computeAndSetBlockDirectionMargins(this);
-        if (grandchildBox->isRenderBlock()) {
-            RenderBlock* grandchildBlock = toRenderBlock(grandchildBox);
-            grandchildBlock->setHasMarginBeforeQuirk(grandchildBox->style().hasMarginBeforeQuirk());
-            grandchildBlock->setHasMarginAfterQuirk(grandchildBox->style().hasMarginAfterQuirk());
+        if (is<RenderBlock>(*grandchildBox)) {
+            RenderBlock& grandchildBlock = downcast<RenderBlock>(*grandchildBox);
+            grandchildBlock.setHasMarginBeforeQuirk(grandchildBox->style().hasMarginBeforeQuirk());
+            grandchildBlock.setHasMarginAfterQuirk(grandchildBox->style().hasMarginAfterQuirk());
         }
     }
 
@@ -1274,8 +1274,8 @@
         // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one.
         logicalTopEstimate = adjustForUnsplittableChild(child, logicalTopEstimate);
         
-        if (!child.selfNeedsLayout() && child.isRenderBlock())
-            logicalTopEstimate += toRenderBlock(child).paginationStrut();
+        if (!child.selfNeedsLayout() && is<RenderBlock>(child))
+            logicalTopEstimate += downcast<RenderBlock>(child).paginationStrut();
     }
 
     return logicalTopEstimate;
@@ -1522,7 +1522,7 @@
 
 LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox& child, bool atBeforeSideOfBlock)
 {
-    RenderBlock* childRenderBlock = child.isRenderBlock() ? toRenderBlock(&child) : nullptr;
+    RenderBlock* childRenderBlock = is<RenderBlock>(child) ? &downcast<RenderBlock>(child) : nullptr;
 
     if (estimateWithoutPagination != logicalTopAfterClear) {
         // Our guess prior to pagination movement was wrong. Before we attempt to paginate, let's try again at the new
@@ -2457,7 +2457,7 @@
             // See if we have a pagination strut that is making us move down further.
             // Note that an unsplittable child can't also have a pagination strut, so this is
             // exclusive with the case above.
-            RenderBlock* childBlock = childBox.isRenderBlock() ? toRenderBlock(&childBox) : nullptr;
+            RenderBlock* childBlock = is<RenderBlock>(childBox) ? &downcast<RenderBlock>(childBox) : nullptr;
             if (childBlock && childBlock->paginationStrut()) {
                 newLogicalTop += childBlock->paginationStrut();
                 childBlock->setPaginationStrut(0);
@@ -2729,16 +2729,16 @@
     auto end = floatingObjectSet.end();
 
     for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) {
-        if (!next->isRenderBlockFlow() || next->isFloatingOrOutOfFlowPositioned() || toRenderBlock(next)->avoidsFloats())
+        if (!is<RenderBlockFlow>(*next) || next->isFloatingOrOutOfFlowPositioned() || downcast<RenderBlockFlow>(*next).avoidsFloats())
             continue;
 
-        RenderBlockFlow* nextBlock = toRenderBlockFlow(next);
+        RenderBlockFlow& nextBlock = downcast<RenderBlockFlow>(*next);
         for (auto it = floatingObjectSet.begin(); it != end; ++it) {
             RenderBox& floatingBox = (*it)->renderer();
             if (floatToRemove && &floatingBox != floatToRemove)
                 continue;
-            if (nextBlock->containsFloat(floatingBox))
-                nextBlock->markAllDescendantsWithFloatsForLayout(&floatingBox);
+            if (nextBlock.containsFloat(floatingBox))
+                nextBlock.markAllDescendantsWithFloatsForLayout(&floatingBox);
         }
     }
 }
diff --git a/Source/WebCore/rendering/RenderBlockLineLayout.cpp b/Source/WebCore/rendering/RenderBlockLineLayout.cpp
index b82e756..1a39de7 100644
--- a/Source/WebCore/rendering/RenderBlockLineLayout.cpp
+++ b/Source/WebCore/rendering/RenderBlockLineLayout.cpp
@@ -1894,8 +1894,8 @@
 
             if (updateRegionRangeForBoxChild(floatingObject->renderer()))
                 floatBox.setNeedsLayout(MarkOnlyThis);
-            else if (floatBox.isRenderBlock())
-                toRenderBlock(floatBox).setChildNeedsLayout(MarkOnlyThis);
+            else if (is<RenderBlock>(floatBox))
+                downcast<RenderBlock>(floatBox).setChildNeedsLayout(MarkOnlyThis);
             floatBox.layoutIfNeeded();
 
             // Save the old logical top before calling removePlacedObject which will set
diff --git a/Source/WebCore/rendering/RenderBox.cpp b/Source/WebCore/rendering/RenderBox.cpp
index e1de4207..6920867 100644
--- a/Source/WebCore/rendering/RenderBox.cpp
+++ b/Source/WebCore/rendering/RenderBox.cpp
@@ -2947,20 +2947,20 @@
         case Calculated:
         {
             auto cb = isOutOfFlowPositioned() ? container() : containingBlock();
-            while (cb->isAnonymous() && !cb->isRenderView()) {
+            while (cb->isAnonymous() && !is<RenderView>(*cb)) {
                 cb = cb->containingBlock();
-                toRenderBlock(cb)->addPercentHeightDescendant(const_cast<RenderBox&>(*this));
+                downcast<RenderBlock>(*cb).addPercentHeightDescendant(const_cast<RenderBox&>(*this));
             }
 
             // FIXME: This calculation is not patched for block-flow yet.
             // https://bugs.webkit.org/show_bug.cgi?id=46500
             if (cb->isOutOfFlowPositioned() && cb->style().height().isAuto() && !(cb->style().top().isAuto() || cb->style().bottom().isAuto())) {
                 ASSERT_WITH_SECURITY_IMPLICATION(cb->isRenderBlock());
-                RenderBlock* block = toRenderBlock(cb);
+                RenderBlock& block = downcast<RenderBlock>(*cb);
                 LogicalExtentComputedValues computedValues;
-                block->computeLogicalHeight(block->logicalHeight(), 0, computedValues);
-                LayoutUnit newContentHeight = computedValues.m_extent - block->borderAndPaddingLogicalHeight() - block->scrollbarLogicalHeight();
-                LayoutUnit newHeight = block->adjustContentBoxLogicalHeightForBoxSizing(newContentHeight);
+                block.computeLogicalHeight(block.logicalHeight(), 0, computedValues);
+                LayoutUnit newContentHeight = computedValues.m_extent - block.borderAndPaddingLogicalHeight() - block.scrollbarLogicalHeight();
+                LayoutUnit newHeight = block.adjustContentBoxLogicalHeightForBoxSizing(newContentHeight);
                 return adjustContentBoxLogicalHeightForBoxSizing(valueForLength(logicalHeight, newHeight));
             }
             
@@ -2984,7 +2984,7 @@
                         availableHeight = std::max(availableHeight, intrinsicLogicalHeight());
                         return valueForLength(logicalHeight, availableHeight - borderAndPaddingLogicalHeight());
                     }
-                    toRenderBlock(cb)->addPercentHeightDescendant(const_cast<RenderBox&>(*this));
+                    downcast<RenderBlock>(*cb).addPercentHeightDescendant(const_cast<RenderBox&>(*this));
                     cb = cb->containingBlock();
                 }
             }
@@ -3023,11 +3023,11 @@
 
     // FIXME: Check logicalTop/logicalBottom here to correctly handle vertical writing-mode.
     // https://bugs.webkit.org/show_bug.cgi?id=46500
-    if (isRenderBlock() && isOutOfFlowPositioned() && style().height().isAuto() && !(style().top().isAuto() || style().bottom().isAuto())) {
-        RenderBlock* block = const_cast<RenderBlock*>(toRenderBlock(this));
+    if (is<RenderBlock>(*this) && isOutOfFlowPositioned() && style().height().isAuto() && !(style().top().isAuto() || style().bottom().isAuto())) {
+        RenderBlock& block = const_cast<RenderBlock&>(downcast<RenderBlock>(*this));
         LogicalExtentComputedValues computedValues;
-        block->computeLogicalHeight(block->logicalHeight(), 0, computedValues);
-        LayoutUnit newContentHeight = computedValues.m_extent - block->borderAndPaddingLogicalHeight() - block->scrollbarLogicalHeight();
+        block.computeLogicalHeight(block.logicalHeight(), 0, computedValues);
+        LayoutUnit newContentHeight = computedValues.m_extent - block.borderAndPaddingLogicalHeight() - block.scrollbarLogicalHeight();
         return adjustContentBoxLogicalHeightForBoxSizing(newContentHeight);
     }
 
@@ -3072,39 +3072,39 @@
     if (checkForPerpendicularWritingMode && containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode())
         return containingBlockLogicalHeightForPositioned(containingBlock, false);
 
-    if (containingBlock->isBox()) {
+    if (is<RenderBox>(*containingBlock)) {
         bool isFixedPosition = style().position() == FixedPosition;
 
         RenderFlowThread* flowThread = flowThreadContainingBlock();
         if (!flowThread) {
-            if (isFixedPosition && containingBlock->isRenderView())
-                return toRenderView(containingBlock)->clientLogicalWidthForFixedPosition();
+            if (isFixedPosition && is<RenderView>(*containingBlock))
+                return downcast<RenderView>(*containingBlock).clientLogicalWidthForFixedPosition();
 
-            return toRenderBox(containingBlock)->clientLogicalWidth();
+            return downcast<RenderBox>(*containingBlock).clientLogicalWidth();
         }
 
-        if (isFixedPosition && containingBlock->isRenderNamedFlowThread())
+        if (isFixedPosition && is<RenderNamedFlowThread>(*containingBlock))
             return containingBlock->view().clientLogicalWidth();
 
-        if (!containingBlock->isRenderBlock())
-            return toRenderBox(*containingBlock).clientLogicalWidth();
+        if (!is<RenderBlock>(*containingBlock))
+            return downcast<RenderBox>(*containingBlock).clientLogicalWidth();
 
-        const RenderBlock* cb = toRenderBlock(containingBlock);
-        RenderBoxRegionInfo* boxInfo = 0;
+        const RenderBlock& cb = downcast<RenderBlock>(*containingBlock);
+        RenderBoxRegionInfo* boxInfo = nullptr;
         if (!region) {
             if (containingBlock->isRenderFlowThread() && !checkForPerpendicularWritingMode)
                 return toRenderFlowThread(containingBlock)->contentLogicalWidthOfFirstRegion();
             if (isWritingModeRoot()) {
-                LayoutUnit cbPageOffset = cb->offsetFromLogicalTopOfFirstPage();
-                RenderRegion* cbRegion = cb->regionAtBlockOffset(cbPageOffset);
+                LayoutUnit cbPageOffset = cb.offsetFromLogicalTopOfFirstPage();
+                RenderRegion* cbRegion = cb.regionAtBlockOffset(cbPageOffset);
                 if (cbRegion)
-                    boxInfo = cb->renderBoxRegionInfo(cbRegion);
+                    boxInfo = cb.renderBoxRegionInfo(cbRegion);
             }
         } else if (region && flowThread->isHorizontalWritingMode() == containingBlock->isHorizontalWritingMode()) {
-            RenderRegion* containingBlockRegion = cb->clampToStartAndEndRegions(region);
-            boxInfo = cb->renderBoxRegionInfo(containingBlockRegion);
+            RenderRegion* containingBlockRegion = cb.clampToStartAndEndRegions(region);
+            boxInfo = cb.renderBoxRegionInfo(containingBlockRegion);
         }
-        return (boxInfo) ? std::max<LayoutUnit>(0, cb->clientLogicalWidth() - (cb->logicalWidth() - boxInfo->logicalWidth())) : cb->clientLogicalWidth();
+        return (boxInfo) ? std::max<LayoutUnit>(0, cb.clientLogicalWidth() - (cb.logicalWidth() - boxInfo->logicalWidth())) : cb.clientLogicalWidth();
     }
 
     ASSERT(containingBlock->isRenderInline() && containingBlock->isInFlowPositioned());
@@ -3133,37 +3133,37 @@
 LayoutUnit RenderBox::containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode) const
 {
     if (checkForPerpendicularWritingMode && containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode())
-        return containingBlockLogicalWidthForPositioned(containingBlock, 0, false);
+        return containingBlockLogicalWidthForPositioned(containingBlock, nullptr, false);
 
     if (containingBlock->isBox()) {
         bool isFixedPosition = style().position() == FixedPosition;
 
-        if (isFixedPosition && containingBlock->isRenderView())
-            return toRenderView(containingBlock)->clientLogicalHeightForFixedPosition();
+        if (isFixedPosition && is<RenderView>(*containingBlock))
+            return downcast<RenderView>(*containingBlock).clientLogicalHeightForFixedPosition();
 
-        const RenderBlock* cb = containingBlock->isRenderBlock() ? toRenderBlock(containingBlock) : containingBlock->containingBlock();
+        const RenderBlock* cb = is<RenderBlock>(*containingBlock) ? downcast<RenderBlock>(containingBlock) : containingBlock->containingBlock();
         LayoutUnit result = cb->clientLogicalHeight();
         RenderFlowThread* flowThread = flowThreadContainingBlock();
-        if (flowThread && containingBlock->isRenderFlowThread() && flowThread->isHorizontalWritingMode() == containingBlock->isHorizontalWritingMode()) {
-            if (containingBlock->isRenderNamedFlowThread() && isFixedPosition)
+        if (flowThread && is<RenderFlowThread>(*containingBlock) && flowThread->isHorizontalWritingMode() == containingBlock->isHorizontalWritingMode()) {
+            if (is<RenderNamedFlowThread>(*containingBlock) && isFixedPosition)
                 return containingBlock->view().clientLogicalHeight();
-            return toRenderFlowThread(containingBlock)->contentLogicalHeightOfFirstRegion();
+            return downcast<RenderFlowThread>(*containingBlock).contentLogicalHeightOfFirstRegion();
         }
         return result;
     }
         
-    ASSERT(containingBlock->isRenderInline() && containingBlock->isInFlowPositioned());
+    ASSERT(is<RenderInline>(*containingBlock) && containingBlock->isInFlowPositioned());
 
-    const RenderInline* flow = toRenderInline(containingBlock);
-    InlineFlowBox* first = flow->firstLineBox();
-    InlineFlowBox* last = flow->lastLineBox();
+    const RenderInline& flow = downcast<RenderInline>(*containingBlock);
+    InlineFlowBox* first = flow.firstLineBox();
+    InlineFlowBox* last = flow.lastLineBox();
 
     // If the containing block is empty, return a height of 0.
     if (!first || !last)
         return 0;
 
     LayoutUnit heightResult;
-    LayoutRect boundingBox = flow->linesBoundingBox();
+    LayoutRect boundingBox = flow.linesBoundingBox();
     if (containingBlock->isHorizontalWritingMode())
         heightResult = boundingBox.height();
     else
@@ -3180,13 +3180,13 @@
     // FIXME: The static distance computation has not been patched for mixed writing modes yet.
     if (child->parent()->style().direction() == LTR) {
         LayoutUnit staticPosition = child->layer()->staticInlinePosition() - containerBlock->borderLogicalLeft();
-        for (auto curr = child->parent(); curr && curr != containerBlock; curr = curr->container()) {
-            if (curr->isBox()) {
-                staticPosition += toRenderBox(curr)->logicalLeft();
-                if (region && toRenderBox(curr)->isRenderBlock()) {
-                    const RenderBlock* cb = toRenderBlock(curr);
-                    region = cb->clampToStartAndEndRegions(region);
-                    RenderBoxRegionInfo* boxInfo = cb->renderBoxRegionInfo(region);
+        for (auto current = child->parent(); current && current != containerBlock; current = current->container()) {
+            if (is<RenderBox>(*current)) {
+                staticPosition += downcast<RenderBox>(*current).logicalLeft();
+                if (region && is<RenderBlock>(*current)) {
+                    const RenderBlock& currentBlock = downcast<RenderBlock>(*current);
+                    region = currentBlock.clampToStartAndEndRegions(region);
+                    RenderBoxRegionInfo* boxInfo = currentBlock.renderBoxRegionInfo(region);
                     if (boxInfo)
                         staticPosition += boxInfo->logicalLeft();
                 }
@@ -3196,25 +3196,25 @@
     } else {
         RenderBox& enclosingBox = child->parent()->enclosingBox();
         LayoutUnit staticPosition = child->layer()->staticInlinePosition() + containerLogicalWidth + containerBlock->borderLogicalLeft();
-        for (RenderElement* curr = &enclosingBox; curr; curr = curr->container()) {
-            if (curr->isBox()) {
-                if (curr != containerBlock)
-                    staticPosition -= toRenderBox(curr)->logicalLeft();
-                if (curr == &enclosingBox)
+        for (RenderElement* current = &enclosingBox; current; current = current->container()) {
+            if (is<RenderBox>(*current)) {
+                if (current != containerBlock)
+                    staticPosition -= downcast<RenderBox>(*current).logicalLeft();
+                if (current == &enclosingBox)
                     staticPosition -= enclosingBox.logicalWidth();
-                if (region && curr->isRenderBlock()) {
-                    const RenderBlock* cb = toRenderBlock(curr);
-                    region = cb->clampToStartAndEndRegions(region);
-                    RenderBoxRegionInfo* boxInfo = cb->renderBoxRegionInfo(region);
+                if (region && is<RenderBlock>(*current)) {
+                    const RenderBlock& currentBlock = downcast<RenderBlock>(*current);
+                    region = currentBlock.clampToStartAndEndRegions(region);
+                    RenderBoxRegionInfo* boxInfo = currentBlock.renderBoxRegionInfo(region);
                     if (boxInfo) {
-                        if (curr != containerBlock)
-                            staticPosition -= cb->logicalWidth() - (boxInfo->logicalLeft() + boxInfo->logicalWidth());
-                        if (curr == &enclosingBox)
+                        if (current != containerBlock)
+                            staticPosition -= currentBlock.logicalWidth() - (boxInfo->logicalLeft() + boxInfo->logicalWidth());
+                        if (current == &enclosingBox)
                             staticPosition += enclosingBox.logicalWidth() - boxInfo->logicalWidth();
                     }
                 }
             }
-            if (curr == containerBlock)
+            if (current == containerBlock)
                 break;
         }
         logicalRight.setValue(Fixed, staticPosition);
@@ -3338,14 +3338,14 @@
     // Adjust logicalLeft if we need to for the flipped version of our writing mode in regions.
     // FIXME: Add support for other types of objects as containerBlock, not only RenderBlock.
     RenderFlowThread* flowThread = flowThreadContainingBlock();
-    if (flowThread && !region && isWritingModeRoot() && isHorizontalWritingMode() == containerBlock->isHorizontalWritingMode() && containerBlock->isRenderBlock()) {
+    if (flowThread && !region && isWritingModeRoot() && isHorizontalWritingMode() == containerBlock->isHorizontalWritingMode() && is<RenderBlock>(*containerBlock)) {
         ASSERT(containerBlock->canHaveBoxInfoInRegion());
         LayoutUnit logicalLeftPos = computedValues.m_position;
-        const RenderBlock* cb = toRenderBlock(containerBlock);
-        LayoutUnit cbPageOffset = cb->offsetFromLogicalTopOfFirstPage();
-        RenderRegion* cbRegion = cb->regionAtBlockOffset(cbPageOffset);
+        const RenderBlock& renderBlock = downcast<RenderBlock>(*containerBlock);
+        LayoutUnit cbPageOffset = renderBlock.offsetFromLogicalTopOfFirstPage();
+        RenderRegion* cbRegion = renderBlock.regionAtBlockOffset(cbPageOffset);
         if (cbRegion) {
-            RenderBoxRegionInfo* boxInfo = cb->renderBoxRegionInfo(cbRegion);
+            RenderBoxRegionInfo* boxInfo = renderBlock.renderBoxRegionInfo(cbRegion);
             if (boxInfo) {
                 logicalLeftPos += boxInfo->logicalLeft();
                 computedValues.m_position = logicalLeftPos;
@@ -3655,14 +3655,14 @@
     // Adjust logicalTop if we need to for perpendicular writing modes in regions.
     // FIXME: Add support for other types of objects as containerBlock, not only RenderBlock.
     RenderFlowThread* flowThread = flowThreadContainingBlock();
-    if (flowThread && isHorizontalWritingMode() != containerBlock->isHorizontalWritingMode() && containerBlock->isRenderBlock()) {
+    if (flowThread && isHorizontalWritingMode() != containerBlock->isHorizontalWritingMode() && is<RenderBlock>(*containerBlock)) {
         ASSERT(containerBlock->canHaveBoxInfoInRegion());
         LayoutUnit logicalTopPos = computedValues.m_position;
-        const RenderBlock* cb = toRenderBlock(containerBlock);
-        LayoutUnit cbPageOffset = cb->offsetFromLogicalTopOfFirstPage() - logicalLeft();
-        RenderRegion* cbRegion = cb->regionAtBlockOffset(cbPageOffset);
+        const RenderBlock& renderBox = downcast<RenderBlock>(*containerBlock);
+        LayoutUnit cbPageOffset = renderBox.offsetFromLogicalTopOfFirstPage() - logicalLeft();
+        RenderRegion* cbRegion = renderBox.regionAtBlockOffset(cbPageOffset);
         if (cbRegion) {
-            RenderBoxRegionInfo* boxInfo = cb->renderBoxRegionInfo(cbRegion);
+            RenderBoxRegionInfo* boxInfo = renderBox.renderBoxRegionInfo(cbRegion);
             if (boxInfo) {
                 logicalTopPos += boxInfo->logicalLeft();
                 computedValues.m_position = logicalTopPos;
diff --git a/Source/WebCore/rendering/RenderBoxModelObject.cpp b/Source/WebCore/rendering/RenderBoxModelObject.cpp
index bafd84b..73f3ee4 100644
--- a/Source/WebCore/rendering/RenderBoxModelObject.cpp
+++ b/Source/WebCore/rendering/RenderBoxModelObject.cpp
@@ -213,11 +213,11 @@
     if (!child->isAnonymousBlock() || !child->isInFlowPositioned())
         return LayoutSize();
     LayoutSize offset;
-    RenderElement* p = toRenderBlock(child)->inlineElementContinuation();
-    while (p && p->isRenderInline()) {
+    RenderElement* p = downcast<RenderBlock>(*child).inlineElementContinuation();
+    while (is<RenderInline>(p)) {
         if (p->isInFlowPositioned()) {
-            RenderInline* renderInline = toRenderInline(p);
-            offset += renderInline->offsetForInFlowPosition();
+            RenderInline& renderInline = downcast<RenderInline>(*p);
+            offset += renderInline.offsetForInFlowPosition();
         }
         p = p->parent();
     }
@@ -2674,7 +2674,7 @@
 {
     // We assume that callers have cleared their positioned objects list for child moves (!fullRemoveInsert) so the
     // positioned renderer maps don't become stale. It would be too slow to do the map lookup on each call.
-    ASSERT(!fullRemoveInsert || !isRenderBlock() || !toRenderBlock(this)->hasPositionedObjects());
+    ASSERT(!fullRemoveInsert || !is<RenderBlock>(*this) || !downcast<RenderBlock>(*this).hasPositionedObjects());
 
     ASSERT(this == child->parent());
     ASSERT(!beforeChild || toBoxModelObject == beforeChild->parent());
@@ -2695,10 +2695,10 @@
     // This condition is rarely hit since this function is usually called on
     // anonymous blocks which can no longer carry positioned objects (see r120761)
     // or when fullRemoveInsert is false.
-    if (fullRemoveInsert && isRenderBlock()) {
-        toRenderBlock(this)->removePositionedObjects(0);
-        if (isRenderBlockFlow())
-            toRenderBlockFlow(this)->removeFloatingObjects(); 
+    if (fullRemoveInsert && is<RenderBlock>(*this)) {
+        downcast<RenderBlock>(*this).removePositionedObjects(nullptr);
+        if (is<RenderBlockFlow>(*this))
+            downcast<RenderBlockFlow>(*this).removeFloatingObjects();
     }
 
     ASSERT(!beforeChild || toBoxModelObject == beforeChild->parent());
diff --git a/Source/WebCore/rendering/RenderElement.cpp b/Source/WebCore/rendering/RenderElement.cpp
index 8f4f45e..0827caa 100644
--- a/Source/WebCore/rendering/RenderElement.cpp
+++ b/Source/WebCore/rendering/RenderElement.cpp
@@ -762,7 +762,7 @@
         if (!elementChild.isAnonymous() || elementChild.style().styleType() != NOPSEUDO)
             continue;
 
-        if (propagationType == PropagateToBlockChildrenOnly && !elementChild.isRenderBlock())
+        if (propagationType == PropagateToBlockChildrenOnly && !is<RenderBlock>(elementChild))
             continue;
 
 #if ENABLE(FULLSCREEN_API)
@@ -771,7 +771,7 @@
 #endif
 
         // RenderFlowThreads are updated through the RenderView::styleDidChange function.
-        if (elementChild.isRenderFlowThread())
+        if (is<RenderFlowThread>(elementChild))
             continue;
 
         auto newStyle = RenderStyle::createAnonymousStyleWithDisplay(&style(), elementChild.style().display());
@@ -784,7 +784,7 @@
 
         // Preserve the position style of anonymous block continuations as they can have relative or sticky position when
         // they contain block descendants of relative or sticky positioned inlines.
-        if (elementChild.isInFlowPositioned() && toRenderBlock(elementChild).isAnonymousBlockContinuation())
+        if (elementChild.isInFlowPositioned() && downcast<RenderBlock>(elementChild).isAnonymousBlockContinuation())
             newStyle.get().setPosition(elementChild.style().position());
 
         elementChild.setStyle(WTF::move(newStyle));
diff --git a/Source/WebCore/rendering/RenderFlowThread.cpp b/Source/WebCore/rendering/RenderFlowThread.cpp
index f1f5b32a..a860096 100644
--- a/Source/WebCore/rendering/RenderFlowThread.cpp
+++ b/Source/WebCore/rendering/RenderFlowThread.cpp
@@ -473,16 +473,16 @@
             
             // Get the logical top coordinate of the current object.
             LayoutUnit top = 0;
-            if (boxModelObject.isRenderBlock())
-                top = toRenderBlock(boxModelObject).offsetFromLogicalTopOfFirstPage();
+            if (is<RenderBlock>(boxModelObject))
+                top = downcast<RenderBlock>(boxModelObject).offsetFromLogicalTopOfFirstPage();
             else {
                 if (boxModelObject.containingBlock())
                     top = boxModelObject.containingBlock()->offsetFromLogicalTopOfFirstPage();
                 
-                if (boxModelObject.isBox())
-                    top += toRenderBox(boxModelObject).topLeftLocation().y();
-                else if (boxModelObject.isRenderInline())
-                    top -= toRenderInline(boxModelObject).borderTop();
+                if (is<RenderBox>(boxModelObject))
+                    top += downcast<RenderBox>(boxModelObject).topLeftLocation().y();
+                else if (is<RenderInline>(boxModelObject))
+                    top -= downcast<RenderInline>(boxModelObject).borderTop();
             }
             
             // Get the logical top of the region this object starts in
diff --git a/Source/WebCore/rendering/RenderFullScreen.cpp b/Source/WebCore/rendering/RenderFullScreen.cpp
index 64433fc..7451221 100644
--- a/Source/WebCore/rendering/RenderFullScreen.cpp
+++ b/Source/WebCore/rendering/RenderFullScreen.cpp
@@ -149,14 +149,14 @@
         if (child != lastChild())
             requiresRenderTreeRebuild = true;
         else if (child && child->isAnonymousBlock()) {
-            auto& anonymousBlock = toRenderBlock(*child);
+            auto& anonymousBlock = downcast<RenderBlock>(*child);
             if (anonymousBlock.firstChild() != anonymousBlock.lastChild())
                 requiresRenderTreeRebuild = true;
         }
 
         while ((child = firstChild())) {
             if (child->isAnonymousBlock() && !requiresRenderTreeRebuild) {
-                if (auto* nonAnonymousChild = toRenderBlock(*child).firstChild())
+                if (auto* nonAnonymousChild = downcast<RenderBlock>(*child).firstChild())
                     child = nonAnonymousChild;
                 else {
                     child->removeFromParent();
diff --git a/Source/WebCore/rendering/RenderInline.cpp b/Source/WebCore/rendering/RenderInline.cpp
index f37f537..1fd36aa 100644
--- a/Source/WebCore/rendering/RenderInline.cpp
+++ b/Source/WebCore/rendering/RenderInline.cpp
@@ -121,10 +121,10 @@
     if (!continuation)
         return nullptr;
 
-    if (continuation->isRenderInline())
-        return toRenderInline(continuation);
+    if (is<RenderInline>(*continuation))
+        return downcast<RenderInline>(continuation);
 
-    return continuation->isRenderBlock() ? toRenderBlock(continuation)->inlineElementContinuation() : nullptr;
+    return is<RenderBlock>(*continuation) ? downcast<RenderBlock>(*continuation).inlineElementContinuation() : nullptr;
 }
 
 void RenderInline::updateFromStyle()
@@ -152,21 +152,21 @@
         if (box->style().position() == newStyle->position())
             continue;
         
-        if (!box->isRenderBlock())
+        if (!is<RenderBlock>(*box))
             continue;
 
-        RenderBlock* block = toRenderBlock(box);
-        if (!block->isAnonymousBlockContinuation())
+        RenderBlock& block = downcast<RenderBlock>(*box);
+        if (!block.isAnonymousBlockContinuation())
             continue;
         
         // If we are no longer in-flow positioned but our descendant block(s) still have an in-flow positioned ancestor then
         // their containing anonymous block should keep its in-flow positioning. 
-        RenderInline* cont = block->inlineElementContinuation();
-        if (oldStyle->hasInFlowPosition() && inFlowPositionedInlineAncestor(cont))
+        RenderInline* continuation = block.inlineElementContinuation();
+        if (oldStyle->hasInFlowPosition() && inFlowPositionedInlineAncestor(continuation))
             continue;
-        auto blockStyle = RenderStyle::createAnonymousStyleWithDisplay(&block->style(), BLOCK);
+        auto blockStyle = RenderStyle::createAnonymousStyleWithDisplay(&block.style(), BLOCK);
         blockStyle.get().setPosition(newStyle->position());
-        block->setStyle(WTF::move(blockStyle));
+        block.setStyle(WTF::move(blockStyle));
     }
 }
 
@@ -196,7 +196,7 @@
         // If any descendant blocks exist then they will be in the next anonymous block and its siblings.
         RenderObject* block = containingBlock()->nextSibling();
         ASSERT(block && block->isAnonymousBlock());
-        updateStyleOfAnonymousBlockContinuations(toRenderBlock(block), &newStyle, oldStyle);
+        updateStyleOfAnonymousBlockContinuations(downcast<RenderBlock>(block), &newStyle, oldStyle);
     }
 
     if (!alwaysCreateLineBoxes()) {
@@ -277,9 +277,9 @@
 
 static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
 {
-    if (renderer->isInline() && !renderer->isReplaced())
-        return toRenderInline(renderer)->continuation();
-    return toRenderBlock(renderer)->inlineElementContinuation();
+    if (is<RenderInline>(*renderer) && !renderer->isReplaced())
+        return downcast<RenderInline>(*renderer).continuation();
+    return downcast<RenderBlock>(*renderer).inlineElementContinuation();
 }
 
 RenderBoxModelObject* RenderInline::continuationBefore(RenderObject* beforeChild)
@@ -443,7 +443,7 @@
 void RenderInline::splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
                              RenderObject* newChild, RenderBoxModelObject* oldCont)
 {
-    RenderBlock* pre = 0;
+    RenderBlock* pre = nullptr;
     RenderBlock* block = containingBlock();
     
     // Delete our line boxes before we do the inline split into continuations.
@@ -453,12 +453,12 @@
     if (block->isAnonymousBlock() && (!block->parent() || !block->parent()->createsAnonymousWrapper())) {
         // We can reuse this block and make it the preBlock of the next continuation.
         pre = block;
-        pre->removePositionedObjects(0);
+        pre->removePositionedObjects(nullptr);
         // FIXME-BLOCKFLOW: The enclosing method should likely be switched over
         // to only work on RenderBlockFlow, in which case this conversion can be
         // removed.
-        if (pre->isRenderBlockFlow())
-            toRenderBlockFlow(pre)->removeFloatingObjects();
+        if (is<RenderBlockFlow>(*pre))
+            downcast<RenderBlockFlow>(*pre).removeFloatingObjects();
         block = block->containingBlock();
     } else {
         // No anonymous block available for use.  Make one.
@@ -466,13 +466,13 @@
         madeNewBeforeBlock = true;
     }
 
-    RenderBlock* post = toRenderBlock(pre->createAnonymousBoxWithSameTypeAs(block));
+    RenderBlock& post = downcast<RenderBlock>(*pre->createAnonymousBoxWithSameTypeAs(block));
 
     RenderObject* boxFirst = madeNewBeforeBlock ? block->firstChild() : pre->nextSibling();
     if (madeNewBeforeBlock)
         block->insertChildInternal(pre, boxFirst, NotifyChildren);
     block->insertChildInternal(newBlockBox, boxFirst, NotifyChildren);
-    block->insertChildInternal(post, boxFirst, NotifyChildren);
+    block->insertChildInternal(&post, boxFirst, NotifyChildren);
     block->setChildrenInline(false);
     
     if (madeNewBeforeBlock) {
@@ -486,7 +486,7 @@
         }
     }
 
-    splitInlines(pre, post, newBlockBox, beforeChild, oldCont);
+    splitInlines(pre, &post, newBlockBox, beforeChild, oldCont);
 
     // We already know the newBlockBox isn't going to contain inline kids, so avoid wasting
     // time in makeChildrenNonInline by just setting this explicitly up front.
@@ -502,7 +502,7 @@
     // make new line boxes instead of leaving the old line boxes around.
     pre->setNeedsLayoutAndPrefWidthsRecalc();
     block->setNeedsLayoutAndPrefWidthsRecalc();
-    post->setNeedsLayoutAndPrefWidthsRecalc();
+    post.setNeedsLayoutAndPrefWidthsRecalc();
 }
 
 void RenderInline::addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild)
@@ -853,21 +853,21 @@
 VisiblePosition RenderInline::positionForPoint(const LayoutPoint& point, const RenderRegion* region)
 {
     // FIXME: Does not deal with relative or sticky positioned inlines (should it?)
-    RenderBlock* cb = containingBlock();
+    RenderBlock& containingBlock = *this->containingBlock();
     if (firstLineBox()) {
         // This inline actually has a line box.  We must have clicked in the border/padding of one of these boxes.  We
         // should try to find a result by asking our containing block.
-        return cb->positionForPoint(point, region);
+        return containingBlock.positionForPoint(point, region);
     }
 
     // Translate the coords from the pre-anonymous block to the post-anonymous block.
-    LayoutPoint parentBlockPoint = cb->location() + point;  
-    RenderBoxModelObject* c = continuation();
-    while (c) {
-        RenderBox* contBlock = c->isInline() ? c->containingBlock() : toRenderBlock(c);
-        if (c->isInline() || c->firstChild())
-            return c->positionForPoint(parentBlockPoint - contBlock->locationOffset(), region);
-        c = toRenderBlock(c)->inlineElementContinuation();
+    LayoutPoint parentBlockPoint = containingBlock.location() + point;
+    RenderBoxModelObject* continuation = this->continuation();
+    while (continuation) {
+        RenderBlock* currentBlock = continuation->isInline() ? continuation->containingBlock() : downcast<RenderBlock>(continuation);
+        if (continuation->isInline() || continuation->firstChild())
+            return continuation->positionForPoint(parentBlockPoint - currentBlock->locationOffset(), region);
+        continuation = downcast<RenderBlock>(*continuation).inlineElementContinuation();
     }
     
     return RenderBoxModelObject::positionForPoint(point, region);
diff --git a/Source/WebCore/rendering/RenderLayer.cpp b/Source/WebCore/rendering/RenderLayer.cpp
index 49aff1c..7189bfb 100644
--- a/Source/WebCore/rendering/RenderLayer.cpp
+++ b/Source/WebCore/rendering/RenderLayer.cpp
@@ -3298,8 +3298,8 @@
                 // Our proprietary overflow: overlay value doesn't trigger a layout.
                 m_inOverflowRelayout = true;
                 renderer().setNeedsLayout(MarkOnlyThis);
-                if (renderer().isRenderBlock()) {
-                    RenderBlock& block = toRenderBlock(renderer());
+                if (is<RenderBlock>(renderer())) {
+                    RenderBlock& block = downcast<RenderBlock>(renderer());
                     block.scrollbarsChanged(autoHorizontalScrollBarChanged, autoVerticalScrollBarChanged);
                     block.layoutBlock(true);
                 } else
@@ -5417,7 +5417,7 @@
             else
                 layerBoundsWithVisualOverflow.moveBy(LayoutPoint(flowThread->width(), 0));
         } else {
-            RenderBlock* rendererContainingBlock = boxModelObject.enclosingBox().isRenderBlock() ? toRenderBlock(&boxModelObject.enclosingBox()) : 0;
+            RenderBlock* rendererContainingBlock = is<RenderBlock>(boxModelObject.enclosingBox()) ? &downcast<RenderBlock>(boxModelObject.enclosingBox()) : nullptr;
             if (rendererContainingBlock)
                 rendererContainingBlock->flipForWritingMode(layerBoundsWithVisualOverflow);
         }
diff --git a/Source/WebCore/rendering/RenderListItem.cpp b/Source/WebCore/rendering/RenderListItem.cpp
index ea7f218..62f745f 100644
--- a/Source/WebCore/rendering/RenderListItem.cpp
+++ b/Source/WebCore/rendering/RenderListItem.cpp
@@ -27,8 +27,10 @@
 #include "ElementTraversal.h"
 #include "HTMLNames.h"
 #include "HTMLOListElement.h"
+#include "HTMLUListElement.h"
 #include "InlineElementBox.h"
 #include "PseudoElement.h"
+#include "RenderInline.h"
 #include "RenderListMarker.h"
 #include "RenderMultiColumnFlowThread.h"
 #include "RenderView.h"
@@ -227,25 +229,24 @@
         if (currChild == marker)
             continue;
 
-        if (currChild->isInline() && (!currChild->isRenderInline() || curr->generatesLineBoxesForInlineChild(currChild)))
+        if (currChild->isInline() && (!is<RenderInline>(*currChild) || curr->generatesLineBoxesForInlineChild(currChild)))
             return curr;
 
         if (currChild->isFloating() || currChild->isOutOfFlowPositioned())
             continue;
 
-        if (currChild->isTable() || !currChild->isRenderBlock() || (currChild->isBox() && toRenderBox(currChild)->isWritingModeRoot()))
+        if (currChild->isTable() || !is<RenderBlock>(*currChild) || (is<RenderBox>(*currChild) && downcast<RenderBox>(*currChild).isWritingModeRoot()))
             break;
 
         if (curr->isListItem() && inQuirksMode && currChild->node() &&
-            (currChild->node()->hasTagName(ulTag)|| currChild->node()->hasTagName(olTag)))
+            (is<HTMLUListElement>(*currChild->node()) || is<HTMLOListElement>(*currChild->node())))
             break;
 
-        RenderBlock* lineBox = getParentOfFirstLineBox(toRenderBlock(currChild), marker);
-        if (lineBox)
+        if (RenderBlock* lineBox = getParentOfFirstLineBox(downcast<RenderBlock>(currChild), marker))
             return lineBox;
     }
 
-    return 0;
+    return nullptr;
 }
 
 void RenderListItem::updateValue()
@@ -294,7 +295,7 @@
         newParent->addChild(m_marker.get(), firstNonMarkerChild(newParent));
         m_marker->updateMarginsAndContent();
         // If current parent is an anonymous block that has lost all its children, destroy it.
-        if (currentParent && currentParent->isAnonymousBlock() && !currentParent->firstChild() && !toRenderBlock(currentParent)->continuation())
+        if (currentParent && currentParent->isAnonymousBlock() && !currentParent->firstChild() && !downcast<RenderBlock>(*currentParent).continuation())
             currentParent->destroy();
     }
 
@@ -406,11 +407,11 @@
                 o = o->parentBox();
                 if (o->hasOverflowClip())
                     propagateVisualOverflow = false;
-                if (o->isRenderBlock()) {
+                if (is<RenderBlock>(*o)) {
                     if (propagateVisualOverflow)
-                        toRenderBlock(o)->addVisualOverflow(markerRect);
+                        downcast<RenderBlock>(*o).addVisualOverflow(markerRect);
                     if (propagateLayoutOverflow)
-                        toRenderBlock(o)->addLayoutOverflow(markerRect);
+                        downcast<RenderBlock>(*o).addLayoutOverflow(markerRect);
                 }
                 if (o->hasOverflowClip())
                     propagateLayoutOverflow = false;
diff --git a/Source/WebCore/rendering/RenderNamedFlowFragment.cpp b/Source/WebCore/rendering/RenderNamedFlowFragment.cpp
index 61362ee..1664d47 100644
--- a/Source/WebCore/rendering/RenderNamedFlowFragment.cpp
+++ b/Source/WebCore/rendering/RenderNamedFlowFragment.cpp
@@ -184,7 +184,7 @@
     ASSERT(parent());
 
     const RenderStyle& styleToUse = parent()->style();
-    return styleToUse.logicalMaxHeight().isUndefined() ? RenderFlowThread::maxLogicalHeight() : toRenderBlock(parent())->computeReplacedLogicalHeightUsing(styleToUse.logicalMaxHeight());
+    return styleToUse.logicalMaxHeight().isUndefined() ? RenderFlowThread::maxLogicalHeight() : downcast<RenderBlock>(*parent()).computeReplacedLogicalHeightUsing(styleToUse.logicalMaxHeight());
 }
 
 LayoutRect RenderNamedFlowFragment::flowThreadPortionRectForClipping(bool isFirstRegionInRange, bool isLastRegionInRange) const
diff --git a/Source/WebCore/rendering/RenderObject.cpp b/Source/WebCore/rendering/RenderObject.cpp
index cc6425f..d953ce5 100644
--- a/Source/WebCore/rendering/RenderObject.cpp
+++ b/Source/WebCore/rendering/RenderObject.cpp
@@ -399,15 +399,15 @@
     return 0;
 }
 
-static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject* render)
+static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject* renderer)
 {
-    const RenderStyle& style = render->style();
+    const RenderStyle& style = renderer->style();
     if (style.height().type() == Fixed) {
-        if (render->isRenderBlock()) {
-            const RenderBlock* block = toRenderBlock(render);
+        if (is<RenderBlock>(*renderer)) {
             // For fixed height styles, if the overflow size of the element spills out of the specified
             // height, assume we can apply text auto-sizing.
-            if (style.overflowY() == OVISIBLE && style.height().value() < block->layoutOverflowRect().maxY())
+            if (style.overflowY() == OVISIBLE
+                && style.height().value() < downcast<RenderBlock>(renderer).layoutOverflowRect().maxY())
                 return RenderObject::OverflowHeight;
         }
         return RenderObject::FixedHeight;
@@ -672,8 +672,8 @@
 {
     ASSERT(!needsLayout());
 
-    if (isRenderBlock())
-        toRenderBlock(this)->checkPositionedObjectsNeedLayout();
+    if (is<RenderBlock>(*this))
+        downcast<RenderBlock>(*this).checkPositionedObjectsNeedLayout();
 }
 #endif
 
@@ -720,22 +720,22 @@
 
 RenderBlock* RenderObject::containingBlock() const
 {
-    auto o = parent();
-    if (!o && isRenderScrollbarPart())
-        o = toRenderScrollbarPart(this)->rendererOwningScrollbar();
+    auto parent = this->parent();
+    if (!parent && is<RenderScrollbarPart>(*this))
+        parent = downcast<RenderScrollbarPart>(*this).rendererOwningScrollbar();
 
     const RenderStyle& style = this->style();
-    if (!isText() && style.position() == FixedPosition)
-        o = containingBlockForFixedPosition(o);
-    else if (!isText() && style.position() == AbsolutePosition)
-        o = containingBlockForAbsolutePosition(o);
+    if (!is<RenderText>(*this) && style.position() == FixedPosition)
+        parent = containingBlockForFixedPosition(parent);
+    else if (!is<RenderText>(*this) && style.position() == AbsolutePosition)
+        parent = containingBlockForAbsolutePosition(parent);
     else
-        o = containingBlockForObjectInFlow(o);
+        parent = containingBlockForObjectInFlow(parent);
 
-    if (!o || !o->isRenderBlock())
-        return 0; // This can still happen in case of an orphaned tree
+    if (!is<RenderBlock>(parent))
+        return nullptr; // This can still happen in case of an orphaned tree
 
-    return toRenderBlock(o);
+    return downcast<RenderBlock>(parent);
 }
 
 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, float x1, float y1, float x2, float y2,
@@ -1679,10 +1679,10 @@
     setInline(style().isDisplayInlineType());
     if (isInline() != parent()->childrenInline()) {
         if (!isInline())
-            toRenderBoxModelObject(parent())->childBecameNonInline(this);
+            downcast<RenderBoxModelObject>(*parent()).childBecameNonInline(this);
         else {
             // An anonymous block must be made to wrap this inline.
-            RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
+            RenderBlock* block = downcast<RenderBlock>(*parent()).createAnonymousBlock();
             parent()->insertChildInternal(block, this, RenderElement::NotifyChildren);
             parent()->removeChildInternal(*this, RenderElement::NotifyChildren);
             block->insertChildInternal(this, nullptr, RenderElement::NotifyChildren);
@@ -1692,8 +1692,8 @@
 
 void RenderObject::removeAnonymousWrappersForInlinesIfNecessary()
 {
-    RenderBlock* parentBlock = toRenderBlock(parent());
-    if (!parentBlock->canCollapseAnonymousBlockChild())
+    RenderBlock& parentBlock = downcast<RenderBlock>(*parent());
+    if (!parentBlock.canCollapseAnonymousBlockChild())
         return;
 
     // We have changed to floated or out-of-flow positioning so maybe all our parent's
@@ -1701,19 +1701,18 @@
     // otherwise we can proceed to stripping solitary anonymous wrappers from the inlines.
     // FIXME: We should also handle split inlines here - we exclude them at the moment by returning
     // if we find a continuation.
-    RenderObject* curr = parent()->firstChild();
-    while (curr && ((curr->isAnonymousBlock() && !toRenderBlock(curr)->isAnonymousBlockContinuation()) || curr->style().isFloating() || curr->style().hasOutOfFlowPosition()))
-        curr = curr->nextSibling();
+    RenderObject* current = parent()->firstChild();
+    while (current && ((current->isAnonymousBlock() && !downcast<RenderBlock>(*current).isAnonymousBlockContinuation()) || current->style().isFloating() || current->style().hasOutOfFlowPosition()))
+        current = current->nextSibling();
 
-    if (curr)
+    if (current)
         return;
 
-    curr = parent()->firstChild();
-    while (curr) {
-        RenderObject* next = curr->nextSibling();
-        if (curr->isAnonymousBlock())
-            parentBlock->collapseAnonymousBoxChild(parentBlock, toRenderBlock(curr));
-        curr = next;
+    RenderObject* next;
+    for (current = parent()->firstChild(); current; current = next) {
+        next = current->nextSibling();
+        if (current->isAnonymousBlock())
+            parentBlock.collapseAnonymousBoxChild(parentBlock, downcast<RenderBlock>(current));
     }
 }
 
@@ -2270,12 +2269,12 @@
 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
                                            Color& linethrough, bool quirksMode, bool firstlineStyle)
 {
-    RenderObject* curr = this;
-    RenderStyle* styleToUse = 0;
+    RenderObject* current = this;
+    RenderStyle* styleToUse = nullptr;
     TextDecoration currDecs = TextDecorationNone;
     Color resultColor;
     do {
-        styleToUse = firstlineStyle ? &curr->firstLineStyle() : &curr->style();
+        styleToUse = firstlineStyle ? &current->firstLineStyle() : &current->style();
         currDecs = styleToUse->textDecoration();
         resultColor = decorationColor(styleToUse);
         // Parameter 'decorations' is cast as an int to enable the bitwise operations below.
@@ -2293,16 +2292,16 @@
                 linethrough = resultColor;
             }
         }
-        if (curr->isRubyText())
+        if (current->isRubyText())
             return;
-        curr = curr->parent();
-        if (curr && curr->isAnonymousBlock() && toRenderBlock(curr)->continuation())
-            curr = toRenderBlock(curr)->continuation();
-    } while (curr && decorations && (!quirksMode || !curr->node() || (!is<HTMLAnchorElement>(*curr->node()) && !curr->node()->hasTagName(fontTag))));
+        current = current->parent();
+        if (current && current->isAnonymousBlock() && downcast<RenderBlock>(*current).continuation())
+            current = downcast<RenderBlock>(*current).continuation();
+    } while (current && decorations && (!quirksMode || !current->node() || (!is<HTMLAnchorElement>(*current->node()) && !current->node()->hasTagName(fontTag))));
 
     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
-    if (decorations && curr) {
-        styleToUse = firstlineStyle ? &curr->firstLineStyle() : &curr->style();
+    if (decorations && current) {
+        styleToUse = firstlineStyle ? &current->firstLineStyle() : &current->style();
         resultColor = decorationColor(styleToUse);
         if (decorations & TextDecorationUnderline)
             underline = resultColor;
diff --git a/Source/WebCore/rendering/RenderRuby.cpp b/Source/WebCore/rendering/RenderRuby.cpp
index 51b0d1c..cdec59a 100644
--- a/Source/WebCore/rendering/RenderRuby.cpp
+++ b/Source/WebCore/rendering/RenderRuby.cpp
@@ -75,13 +75,13 @@
 static inline RenderBlock* rubyBeforeBlock(const RenderElement* ruby)
 {
     RenderObject* child = ruby->firstChild();
-    return isRubyBeforeBlock(child) ? toRenderBlock(child) : 0;
+    return isRubyBeforeBlock(child) ? downcast<RenderBlock>(child) : nullptr;
 }
 
 static inline RenderBlock* rubyAfterBlock(const RenderElement* ruby)
 {
     RenderObject* child = ruby->lastChild();
-    return isRubyAfterBlock(child) ? toRenderBlock(child) : 0;
+    return isRubyAfterBlock(child) ? downcast<RenderBlock>(child) : nullptr;
 }
 
 static RenderBlock* createAnonymousRubyInlineBlock(RenderObject& ruby)
diff --git a/Source/WebCore/rendering/RenderRubyBase.cpp b/Source/WebCore/rendering/RenderRubyBase.cpp
index 7dbe145..ea0cd63 100644
--- a/Source/WebCore/rendering/RenderRubyBase.cpp
+++ b/Source/WebCore/rendering/RenderRubyBase.cpp
@@ -92,7 +92,7 @@
         // If toBase has a suitable block, we re-use it, otherwise create a new one.
         RenderObject* lastChild = toBase->lastChild();
         if (lastChild && lastChild->isAnonymousBlock() && lastChild->childrenInline())
-            toBlock = toRenderBlock(lastChild);
+            toBlock = downcast<RenderBlock>(lastChild);
         else {
             toBlock = toBase->createAnonymousBlock();
             toBase->insertChildInternal(toBlock, nullptr, NotifyChildren);
@@ -118,8 +118,8 @@
     RenderObject* lastChildThere = toBase->lastChild();
     if (firstChildHere->isAnonymousBlock() && firstChildHere->childrenInline() 
             && lastChildThere && lastChildThere->isAnonymousBlock() && lastChildThere->childrenInline()) {            
-        RenderBlock* anonBlockHere = toRenderBlock(firstChildHere);
-        RenderBlock* anonBlockThere = toRenderBlock(lastChildThere);
+        RenderBlock* anonBlockHere = downcast<RenderBlock>(firstChildHere);
+        RenderBlock* anonBlockThere = downcast<RenderBlock>(lastChildThere);
         anonBlockHere->moveAllChildrenTo(anonBlockThere, true);
         anonBlockHere->deleteLines();
         anonBlockHere->destroy();
diff --git a/Source/WebCore/rendering/RenderThemeMac.mm b/Source/WebCore/rendering/RenderThemeMac.mm
index 3355546..2b2c3f4 100644
--- a/Source/WebCore/rendering/RenderThemeMac.mm
+++ b/Source/WebCore/rendering/RenderThemeMac.mm
@@ -1821,15 +1821,15 @@
     return false;
 }
 
-bool RenderThemeMac::paintSnapshottedPluginOverlay(const RenderObject& o, const PaintInfo& paintInfo, const IntRect&)
+bool RenderThemeMac::paintSnapshottedPluginOverlay(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect&)
 {
     if (paintInfo.phase != PaintPhaseBlockBackground)
         return true;
 
-    if (!o.isRenderBlock())
+    if (!is<RenderBlock>(renderer))
         return true;
 
-    const RenderBlock& renderBlock = *toRenderBlock(&o);
+    const RenderBlock& renderBlock = downcast<RenderBlock>(renderer);
 
     LayoutUnit contentWidth = renderBlock.contentWidth();
     LayoutUnit contentHeight = renderBlock.contentHeight();
@@ -1878,13 +1878,11 @@
 
     // We could draw the snapshot with that coordinates, but we need to make sure there
     // isn't a composited layer between us and the plugInRenderer.
-    const RenderBox* renderBox = toRenderBox(&o);
-    while (renderBox != plugInRenderer) {
+    for (auto* renderBox = &downcast<RenderBox>(renderer); renderBox != plugInRenderer; renderBox = renderBox->parentBox()) {
         if (renderBox->hasLayer() && renderBox->layer() && renderBox->layer()->isComposited()) {
             snapshotAbsPos = -renderBox->location();
             break;
         }
-        renderBox = renderBox->parentBox();
     }
 
     LayoutSize pluginSize(plugInRenderer->contentWidth(), plugInRenderer->contentHeight());
diff --git a/Source/WebCore/rendering/TextAutosizer.cpp b/Source/WebCore/rendering/TextAutosizer.cpp
index 74c3c0a..b7b64ea 100644
--- a/Source/WebCore/rendering/TextAutosizer.cpp
+++ b/Source/WebCore/rendering/TextAutosizer.cpp
@@ -126,7 +126,7 @@
     }
 
     // The layoutRoot could be neither a container nor a cluster, so walk up the tree till we find each of these.
-    RenderBlock* container = layoutRoot->isRenderBlock() ? toRenderBlock(layoutRoot) : layoutRoot->containingBlock();
+    RenderBlock* container = is<RenderBlock>(*layoutRoot) ? downcast<RenderBlock>(layoutRoot) : layoutRoot->containingBlock();
     while (container && !isAutosizingContainer(container))
         container = container->containingBlock();
 
@@ -204,14 +204,14 @@
 
     RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(subtreeRoot, subtreeRoot);
     while (descendant) {
-        if (descendant->isText()) {
+        if (is<RenderText>(*descendant)) {
             if (localMultiplier != 1 && descendant->style()->textAutosizingMultiplier() == 1) {
                 setMultiplier(descendant, localMultiplier);
                 setMultiplier(descendant->parent(), localMultiplier); // Parent does line spacing.
             }
             // FIXME: Increase list marker size proportionately.
         } else if (isAutosizingContainer(descendant)) {
-            RenderBlock* descendantBlock = toRenderBlock(descendant);
+            RenderBlock* descendantBlock = downcast<RenderBlock>(descendant);
             TextAutosizingClusterInfo descendantClusterInfo(descendantBlock);
             if (isWiderDescendant(descendantBlock, clusterInfo) || isIndependentDescendant(descendantBlock))
                 processCluster(descendantClusterInfo, descendantBlock, descendantBlock, windowInfo);
@@ -496,7 +496,7 @@
         if (!skipLocalText && is<RenderText>(*descendant))
             textWidth += downcast<RenderText>(*descendant).renderedTextLength() * descendant->style()->specifiedFontSize();
         else if (isAutosizingContainer(descendant)) {
-            RenderBlock* descendantBlock = toRenderBlock(descendant);
+            RenderBlock* descendantBlock = downcast<RenderBlock>(descendant);
             if (!isAutosizingCluster(descendantBlock, clusterInfo))
                 measureDescendantTextWidth(descendantBlock, clusterInfo, minTextWidth, textWidth);
         }
@@ -542,8 +542,8 @@
         lastNode = lastNode->parent();
     }
 
-    if (firstNode->isRenderBlock())
-        return toRenderBlock(firstNode);
+    if (is<RenderBlock>(*firstNode))
+        return downcast<RenderBlock>(firstNode);
 
     // containingBlock() should never leave the cluster, since it only skips ancestors when finding the
     // container of position:absolute/fixed blocks, and those cannot exist between a cluster and its text
@@ -558,21 +558,20 @@
 const RenderObject* TextAutosizer::findFirstTextLeafNotInCluster(const RenderObject* parent, size_t& depth, TraversalDirection direction)
 {
     if (parent->isEmpty())
-        return parent->isText() ? parent : 0;
+        return is<RenderText>(*parent) ? parent : nullptr;
 
     ++depth;
     const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild();
     while (child) {
-        if (!isAutosizingContainer(child) || !isIndependentDescendant(toRenderBlock(child))) {
-            const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction);
-            if (leaf)
+        if (!isAutosizingContainer(child) || !isIndependentDescendant(downcast<RenderBlock>(child))) {
+            if (const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction))
                 return leaf;
         }
         child = (direction == FirstToLast) ? child->nextSibling() : child->previousSibling();
     }
     --depth;
 
-    return 0;
+    return nullptr;
 }
 
 namespace {
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp b/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp
index 2806390..b63acf4 100644
--- a/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp
+++ b/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp
@@ -300,7 +300,7 @@
             auto index = indexWrapper();
             float indexHeight = 0;
             if (!index->isEmpty())
-                indexHeight = toRenderBlock(index->firstChild())->logicalHeight();
+                indexHeight = downcast<RenderBlock>(*index->firstChild()).logicalHeight();
             float indexTopMargin = (1.0 - m_degreeBottomRaisePercent) * radical->stretchSize() + radicalTopMargin - indexHeight;
             if (indexTopMargin < 0) {
                 // If the index is too tall, we must add space at the top of renderer.
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index f7ebe53..697d1ce 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,17 @@
+2014-10-08  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for RenderBlock objects
+        https://bugs.webkit.org/show_bug.cgi?id=137512
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for RenderBlock objects and clean up the 
+        surrounding code.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::rangeForWebSelectionAtPosition):
+        (WebKit::WebPage::contractedRangeFromHandle):
+
 2014-10-08  Ada Chan  <adachan@apple.com>
 
         Implement WKPageIsPlayingAudio().
diff --git a/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
index 956983ba..3001059 100644
--- a/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
+++ b/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
@@ -774,7 +774,7 @@
     if (!renderer || renderer->style().userSelect() == SELECT_NONE)
         return nullptr;
 
-    if (renderer->childrenInline() && (renderer->isRenderBlock() && !toRenderBlock(renderer)->inlineElementContinuation()) && !renderer->isTable()) {
+    if (renderer->childrenInline() && (is<RenderBlock>(*renderer) && !downcast<RenderBlock>(*renderer).inlineElementContinuation()) && !renderer->isTable()) {
         range = enclosingTextUnitOfGranularity(position, WordGranularity, DirectionBackward);
         if (range && !range->collapsed(ASSERT_NO_EXCEPTION))
             return range;
@@ -1316,7 +1316,7 @@
         node = node->parentElement();
 
     RenderObject* renderer = node->renderer();
-    if (renderer && renderer->childrenInline() && (renderer->isRenderBlock() && !toRenderBlock(renderer)->inlineElementContinuation()) && !renderer->isTable())
+    if (renderer && renderer->childrenInline() && (is<RenderBlock>(*renderer) && !downcast<RenderBlock>(*renderer).inlineElementContinuation()) && !renderer->isTable())
         flags = None;
 
     return bestRange;