Title: [174068] trunk/Source
Revision
174068
Author
cdu...@apple.com
Date
2014-09-29 10:20:18 -0700 (Mon, 29 Sep 2014)

Log Message

Use the new is<>() / downcast<>() for Text Nodes
https://bugs.webkit.org/show_bug.cgi?id=137188

Reviewed by Darin Adler.

Use the new is<>() / downcast<>() functions for Text Nodes instead of
isText() / toText().

Source/WebCore:

No new tests, no behavior change.

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::textUnderElement):
* bindings/gobject/WebKitDOMPrivate.cpp:
(WebKit::wrap):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* dom/CharacterData.cpp:
(WebCore::CharacterData::parserAppendData):
(WebCore::CharacterData::setDataAndUpdate):
* dom/ContainerNode.cpp:
(WebCore::destroyRenderTreeIfNeeded):
* dom/Node.cpp:
(WebCore::Node::normalize):
* dom/Position.cpp:
(WebCore::Position::containerNode):
(WebCore::Position::containerText):
(WebCore::Position::isRenderedCharacter):
(WebCore::Position::leadingWhitespacePosition):
* dom/Range.cpp:
(WebCore::Range::insertNode):
(WebCore::Range::getBorderAndTextQuads):
* dom/Text.cpp:
(WebCore::earliestLogicallyAdjacentTextNode):
(WebCore::latestLogicallyAdjacentTextNode):
* dom/Text.h:
(WebCore::isText):
* dom/TextNodeTraversal.cpp:
(WebCore::TextNodeTraversal::contentsAsString):
* dom/TextNodeTraversal.h:
(WebCore::TextNodeTraversal::firstTextChildTemplate):
(WebCore::TextNodeTraversal::firstTextWithinTemplate):
(WebCore::TextNodeTraversal::traverseNextTextTemplate):
(WebCore::TextNodeTraversal::nextSibling):
* editing/ApplyBlockElementCommand.cpp:
(WebCore::isNewLineAtPosition):
(WebCore::ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfNeeded):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::splitTextAtEnd):
(WebCore::ApplyStyleCommand::splitTextElementAtEnd):
(WebCore::ApplyStyleCommand::joinChildTextNodes):
* editing/BreakBlockquoteCommand.cpp:
(WebCore::BreakBlockquoteCommand::doApply):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::insertNodeAt):
(WebCore::CompositeEditCommand::positionOutsideTabSpan):
(WebCore::CompositeEditCommand::canRebalance):
(WebCore::CompositeEditCommand::rebalanceWhitespaceAt):
(WebCore::CompositeEditCommand::prepareWhitespaceAtPositionForSplit):
(WebCore::CompositeEditCommand::deleteInsignificantText):
(WebCore::CompositeEditCommand::removePlaceholderAt):
(WebCore::CompositeEditCommand::cleanupAfterDeletion):
(WebCore::CompositeEditCommand::moveParagraphs):
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::handleGeneralDelete):
(WebCore::DeleteSelectionCommand::fixupWhitespace):
(WebCore::DeleteSelectionCommand::doApply):
* editing/Editor.cpp:
(WebCore::Editor::setComposition):
* editing/InsertLineBreakCommand.cpp:
(WebCore::InsertLineBreakCommand::doApply):
* editing/InsertParagraphSeparatorCommand.cpp:
(WebCore::InsertParagraphSeparatorCommand::doApply):
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::insertTab):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendStartMarkup):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds):
(WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):
(WebCore::ReplaceSelectionCommand::mergeTextNodesAroundPosition):
(WebCore::ReplaceSelectionCommand::insertAsListItems):
(WebCore::ReplaceSelectionCommand::performTrivialReplace):
* editing/TextIterator.cpp:
(WebCore::TextIterator::handleTextNode):
(WebCore::TextIterator::handleTextBox):
(WebCore::SimplifiedBackwardsTextIterator::handleTextNode):
* editing/VisibleUnits.cpp:
(WebCore::startPositionForLine):
(WebCore::endPositionForLine):
(WebCore::startOfParagraph):
(WebCore::endOfParagraph):
* editing/htmlediting.cpp:
(WebCore::lineBreakExistsAtPosition):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::renderedText):
(WebCore::replaceChildrenWithFragment):
(WebCore::replaceChildrenWithText):
* html/HTMLElement.cpp:
(WebCore::mergeWithNextTextNode):
(WebCore::HTMLElement::setOuterHTML):
(WebCore::HTMLElement::setOuterText):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::hasFallbackContent):
(WebCore::HTMLObjectElement::updateDocNamedItem):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::setText):
* html/HTMLScriptElement.cpp:
(WebCore::HTMLScriptElement::setText):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::innerTextValue):
(WebCore::positionForIndex):
(WebCore::HTMLTextFormControlElement::indexForPosition):
(WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks):
* html/HTMLTitleElement.cpp:
(WebCore::HTMLTitleElement::setText):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::insertTextNode):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::setNodeValue):
* rendering/RenderCombineText.h:
* rendering/RenderNamedFlowThread.cpp:
(WebCore::RenderNamedFlowThread::getRanges):
* rendering/RenderText.cpp:
(WebCore::RenderText::textNode):
* rendering/svg/RenderSVGInlineText.h:
* style/StyleResolveTree.cpp:
(WebCore::Style::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded):
(WebCore::Style::attachChildren):
(WebCore::Style::attachDistributedChildren):
(WebCore::Style::detachDistributedChildren):
(WebCore::Style::detachChildren):
(WebCore::Style::resolveShadowTree):
(WebCore::Style::resolveTree):

Source/WebKit2:

* WebProcess/InjectedBundle/API/mac/WKDOMText.mm:
(-[WKDOMText data]):
(-[WKDOMText setData:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174067 => 174068)


--- trunk/Source/WebCore/ChangeLog	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/ChangeLog	2014-09-29 17:20:18 UTC (rev 174068)
@@ -1,5 +1,141 @@
 2014-09-29  Christophe Dumez  <cdu...@apple.com>
 
+        Use the new is<>() / downcast<>() for Text Nodes
+        https://bugs.webkit.org/show_bug.cgi?id=137188
+
+        Reviewed by Darin Adler.
+
+        Use the new is<>() / downcast<>() functions for Text Nodes instead of
+        isText() / toText().
+
+        No new tests, no behavior change.
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::textUnderElement):
+        * bindings/gobject/WebKitDOMPrivate.cpp:
+        (WebKit::wrap):
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::checkOne):
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::parserAppendData):
+        (WebCore::CharacterData::setDataAndUpdate):
+        * dom/ContainerNode.cpp:
+        (WebCore::destroyRenderTreeIfNeeded):
+        * dom/Node.cpp:
+        (WebCore::Node::normalize):
+        * dom/Position.cpp:
+        (WebCore::Position::containerNode):
+        (WebCore::Position::containerText):
+        (WebCore::Position::isRenderedCharacter):
+        (WebCore::Position::leadingWhitespacePosition):
+        * dom/Range.cpp:
+        (WebCore::Range::insertNode):
+        (WebCore::Range::getBorderAndTextQuads):
+        * dom/Text.cpp:
+        (WebCore::earliestLogicallyAdjacentTextNode):
+        (WebCore::latestLogicallyAdjacentTextNode):
+        * dom/Text.h:
+        (WebCore::isText):
+        * dom/TextNodeTraversal.cpp:
+        (WebCore::TextNodeTraversal::contentsAsString):
+        * dom/TextNodeTraversal.h:
+        (WebCore::TextNodeTraversal::firstTextChildTemplate):
+        (WebCore::TextNodeTraversal::firstTextWithinTemplate):
+        (WebCore::TextNodeTraversal::traverseNextTextTemplate):
+        (WebCore::TextNodeTraversal::nextSibling):
+        * editing/ApplyBlockElementCommand.cpp:
+        (WebCore::isNewLineAtPosition):
+        (WebCore::ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfNeeded):
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::splitTextAtEnd):
+        (WebCore::ApplyStyleCommand::splitTextElementAtEnd):
+        (WebCore::ApplyStyleCommand::joinChildTextNodes):
+        * editing/BreakBlockquoteCommand.cpp:
+        (WebCore::BreakBlockquoteCommand::doApply):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::insertNodeAt):
+        (WebCore::CompositeEditCommand::positionOutsideTabSpan):
+        (WebCore::CompositeEditCommand::canRebalance):
+        (WebCore::CompositeEditCommand::rebalanceWhitespaceAt):
+        (WebCore::CompositeEditCommand::prepareWhitespaceAtPositionForSplit):
+        (WebCore::CompositeEditCommand::deleteInsignificantText):
+        (WebCore::CompositeEditCommand::removePlaceholderAt):
+        (WebCore::CompositeEditCommand::cleanupAfterDeletion):
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::handleGeneralDelete):
+        (WebCore::DeleteSelectionCommand::fixupWhitespace):
+        (WebCore::DeleteSelectionCommand::doApply):
+        * editing/Editor.cpp:
+        (WebCore::Editor::setComposition):
+        * editing/InsertLineBreakCommand.cpp:
+        (WebCore::InsertLineBreakCommand::doApply):
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::doApply):
+        * editing/InsertTextCommand.cpp:
+        (WebCore::InsertTextCommand::insertTab):
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::appendStartMarkup):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds):
+        (WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):
+        (WebCore::ReplaceSelectionCommand::mergeTextNodesAroundPosition):
+        (WebCore::ReplaceSelectionCommand::insertAsListItems):
+        (WebCore::ReplaceSelectionCommand::performTrivialReplace):
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::handleTextNode):
+        (WebCore::TextIterator::handleTextBox):
+        (WebCore::SimplifiedBackwardsTextIterator::handleTextNode):
+        * editing/VisibleUnits.cpp:
+        (WebCore::startPositionForLine):
+        (WebCore::endPositionForLine):
+        (WebCore::startOfParagraph):
+        (WebCore::endOfParagraph):
+        * editing/htmlediting.cpp:
+        (WebCore::lineBreakExistsAtPosition):
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::renderedText):
+        (WebCore::replaceChildrenWithFragment):
+        (WebCore::replaceChildrenWithText):
+        * html/HTMLElement.cpp:
+        (WebCore::mergeWithNextTextNode):
+        (WebCore::HTMLElement::setOuterHTML):
+        (WebCore::HTMLElement::setOuterText):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::hasFallbackContent):
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::setText):
+        * html/HTMLScriptElement.cpp:
+        (WebCore::HTMLScriptElement::setText):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::innerTextValue):
+        (WebCore::positionForIndex):
+        (WebCore::HTMLTextFormControlElement::indexForPosition):
+        (WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks):
+        * html/HTMLTitleElement.cpp:
+        (WebCore::HTMLTitleElement::setText):
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore::HTMLConstructionSite::insertTextNode):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::setNodeValue):
+        * rendering/RenderCombineText.h:
+        * rendering/RenderNamedFlowThread.cpp:
+        (WebCore::RenderNamedFlowThread::getRanges):
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::textNode):
+        * rendering/svg/RenderSVGInlineText.h:
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded):
+        (WebCore::Style::attachChildren):
+        (WebCore::Style::attachDistributedChildren):
+        (WebCore::Style::detachDistributedChildren):
+        (WebCore::Style::detachChildren):
+        (WebCore::Style::resolveShadowTree):
+        (WebCore::Style::resolveTree):
+
+2014-09-29  Christophe Dumez  <cdu...@apple.com>
+
         Remove remaining uses of NODE_TYPE_CASTS() from html/
         https://bugs.webkit.org/show_bug.cgi?id=137172
 

Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (174067 => 174068)


--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -1640,8 +1640,8 @@
 String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMode mode) const
 {
     Node* node = this->node();
-    if (node && node->isTextNode())
-        return toText(node)->wholeText();
+    if (node && is<Text>(node))
+        return downcast<Text>(*node).wholeText();
 
     // The render tree should be stable before going ahead. Otherwise, further uses of the
     // TextIterator will force a layout update, potentially altering the accessibility tree

Modified: trunk/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp (174067 => 174068)


--- trunk/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -90,7 +90,7 @@
     case Node::ATTRIBUTE_NODE:
         return WEBKIT_DOM_NODE(wrapAttr(static_cast<Attr*>(node)));
     case Node::TEXT_NODE:
-        return WEBKIT_DOM_NODE(wrapText(toText(node)));
+        return WEBKIT_DOM_NODE(wrapText(downcast<Text>(node)));
     case Node::CDATA_SECTION_NODE:
         return WEBKIT_DOM_NODE(wrapCDATASection(static_cast<CDATASection*>(node)));
     case Node::ENTITY_REFERENCE_NODE:

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (174067 => 174068)


--- trunk/Source/WebCore/css/SelectorChecker.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -555,14 +555,14 @@
         case CSSSelector::PseudoClassEmpty:
             {
                 bool result = true;
-                for (Node* n = element->firstChild(); n; n = n->nextSibling()) {
-                    if (n->isElementNode()) {
+                for (Node* node = element->firstChild(); node; node = node->nextSibling()) {
+                    if (node->isElementNode()) {
                         result = false;
                         break;
                     }
-                    if (n->isTextNode()) {
-                        Text* textNode = toText(n);
-                        if (!textNode->data().isEmpty()) {
+                    if (is<Text>(node)) {
+                        Text& textNode = downcast<Text>(*node);
+                        if (!textNode.data().isEmpty()) {
                             result = false;
                             break;
                         }

Modified: trunk/Source/WebCore/dom/CharacterData.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/CharacterData.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/CharacterData.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -87,9 +87,9 @@
     else
         m_data.append(string.characters16() + offset, characterLengthLimit);
 
-    ASSERT(!renderer() || isTextNode());
-    if (isTextNode())
-        Style::updateTextRendererAfterContentChange(*toText(this), oldLength, 0);
+    ASSERT(!renderer() || is<Text>(this));
+    if (is<Text>(this))
+        Style::updateTextRendererAfterContentChange(downcast<Text>(*this), oldLength, 0);
 
     document().incDOMTreeVersion();
     // We don't call dispatchModifiedEvent here because we don't want the
@@ -194,9 +194,9 @@
     String oldData = m_data;
     m_data = newData;
 
-    ASSERT(!renderer() || isTextNode());
-    if (isTextNode())
-        Style::updateTextRendererAfterContentChange(*toText(this), offsetOfReplacedData, oldLength);
+    ASSERT(!renderer() || is<Text>(this));
+    if (is<Text>(this))
+        Style::updateTextRendererAfterContentChange(downcast<Text>(*this), offsetOfReplacedData, oldLength);
 
     if (is<ProcessingInstruction>(this))
         downcast<ProcessingInstruction>(*this).checkStyleSheet();

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -102,8 +102,8 @@
         return;
     if (child.isElementNode())
         Style::detachRenderTree(toElement(child));
-    else if (child.isTextNode())
-        Style::detachTextRenderer(toText(child));
+    else if (is<Text>(child))
+        Style::detachTextRenderer(downcast<Text>(child));
 }
 
 void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)

Modified: trunk/Source/WebCore/dom/Node.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/Node.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/Node.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -489,7 +489,7 @@
             continue;
         }
 
-        RefPtr<Text> text = toText(node.get());
+        RefPtr<Text> text = downcast<Text>(node.get());
 
         // Remove empty text nodes.
         if (!text->length()) {
@@ -503,7 +503,7 @@
         while (Node* nextSibling = node->nextSibling()) {
             if (nextSibling->nodeType() != TEXT_NODE)
                 break;
-            RefPtr<Text> nextText = toText(nextSibling);
+            RefPtr<Text> nextText = downcast<Text>(nextSibling);
 
             // Remove empty text nodes.
             if (!nextText->length()) {

Modified: trunk/Source/WebCore/dom/Position.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/Position.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/Position.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -151,7 +151,7 @@
 Node* Position::containerNode() const
 {
     if (!m_anchorNode)
-        return 0;
+        return nullptr;
 
     switch (anchorType()) {
     case PositionIsBeforeChildren:
@@ -163,24 +163,24 @@
         return findParent(m_anchorNode.get());
     }
     ASSERT_NOT_REACHED();
-    return 0;
+    return nullptr;
 }
 
 Text* Position::containerText() const
 {
     switch (anchorType()) {
     case PositionIsOffsetInAnchor:
-        return m_anchorNode && m_anchorNode->isTextNode() ? toText(m_anchorNode.get()) : 0;
+        return m_anchorNode && is<Text>(*m_anchorNode) ? downcast<Text>(m_anchorNode.get()) : nullptr;
     case PositionIsBeforeAnchor:
     case PositionIsAfterAnchor:
-        return 0;
+        return nullptr;
     case PositionIsBeforeChildren:
     case PositionIsAfterChildren:
-        ASSERT(!m_anchorNode || !m_anchorNode->isTextNode());
-        return 0;
+        ASSERT(!m_anchorNode || !is<Text>(*m_anchorNode));
+        return nullptr;
     }
     ASSERT_NOT_REACHED();
-    return 0;
+    return nullptr;
 }
 
 int Position::computeOffsetInContainerNode() const
@@ -950,10 +950,10 @@
 
 bool Position::isRenderedCharacter() const
 {
-    if (isNull() || !deprecatedNode()->isTextNode())
+    if (isNull() || !is<Text>(deprecatedNode()))
         return false;
         
-    RenderText* renderer = toText(deprecatedNode())->renderer();
+    RenderText* renderer = downcast<Text>(*deprecatedNode()).renderer();
     if (!renderer)
         return false;
     
@@ -1062,8 +1062,8 @@
         return Position();
 
     Position prev = previousCharacterPosition(affinity);
-    if (prev != *this && inSameEnclosingBlockFlowElement(deprecatedNode(), prev.deprecatedNode()) && prev.deprecatedNode()->isTextNode()) {
-        String string = toText(prev.deprecatedNode())->data();
+    if (prev != *this && inSameEnclosingBlockFlowElement(deprecatedNode(), prev.deprecatedNode()) && is<Text>(prev.deprecatedNode())) {
+        String string = downcast<Text>(*prev.deprecatedNode()).data();
         UChar c = string[prev.deprecatedEditingOffset()];
         if (considerNonCollapsibleWhitespace ? (isSpaceOrNewline(c) || c == noBreakSpace) : deprecatedIsCollapsibleWhitespace(c))
             if (isEditablePosition(prev))

Modified: trunk/Source/WebCore/dom/Range.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/Range.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/Range.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -978,7 +978,7 @@
     // does not allow children of the type of newNode or if newNode is an ancestor of the container.
 
     // an extra one here - if a text node is going to split, it must have a parent to insert into
-    bool startIsText = m_start.container()->isTextNode();
+    bool startIsText = is<Text>(m_start.container());
     if (startIsText && !m_start.container()->parentNode()) {
         ec = HIERARCHY_REQUEST_ERR;
         return;
@@ -1040,7 +1040,7 @@
     RefPtr<Node> container;
     if (startIsText) {
         container = m_start.container();
-        RefPtr<Text> newText = toText(container.get())->splitText(m_start.offset(), ec);
+        RefPtr<Text> newText = downcast<Text>(*container).splitText(m_start.offset(), ec);
         if (ec)
             return;
         
@@ -2232,8 +2232,8 @@
 
                 quads.appendVector(elementQuads);
             }
-        } else if (node->isTextNode()) {
-            if (RenderObject* renderer = toText(node)->renderer()) {
+        } else if (is<Text>(node)) {
+            if (RenderObject* renderer = downcast<Text>(*node).renderer()) {
                 const RenderText& renderText = toRenderText(*renderer);
                 int startOffset = (node == startContainer) ? m_start.offset() : 0;
                 int endOffset = (node == endContainer) ? m_end.offset() : INT_MAX;

Modified: trunk/Source/WebCore/dom/Text.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/Text.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/Text.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -94,9 +94,9 @@
 {
     const Node* node = text;
     while ((node = node->previousSibling())) {
-        if (!node->isTextNode())
+        if (!is<Text>(node))
             break;
-        text = toText(node);
+        text = downcast<Text>(node);
     }
     return text;
 }
@@ -105,9 +105,9 @@
 {
     const Node* node = text;
     while ((node = node->nextSibling())) {
-        if (!node->isTextNode())
+        if (!is<Text>(node))
             break;
-        text = toText(node);
+        text = downcast<Text>(node);
     }
     return text;
 }

Modified: trunk/Source/WebCore/dom/Text.h (174067 => 174068)


--- trunk/Source/WebCore/dom/Text.h	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/Text.h	2014-09-29 17:20:18 UTC (rev 174068)
@@ -74,12 +74,10 @@
 #endif
 };
 
-inline bool isText(const Node& node) { return node.isTextNode(); }
-void isText(const Text&); // Catch unnecessary runtime check of type known at compile time.
-void isText(const ContainerNode&); // Catch unnecessary runtime check of type known at compile time.
+SPECIALIZE_TYPE_TRAITS_BEGIN(Text)
+    static bool isText(const Node& node) { return node.isTextNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
-NODE_TYPE_CASTS(Text)
-
 } // namespace WebCore
 
 #endif // Text_h

Modified: trunk/Source/WebCore/dom/TextNodeTraversal.cpp (174067 => 174068)


--- trunk/Source/WebCore/dom/TextNodeTraversal.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/TextNodeTraversal.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -47,8 +47,8 @@
 
 String contentsAsString(const Node* root)
 {
-    if (root->isTextNode())
-        return toText(root)->data();
+    if (is<Text>(root))
+        return downcast<Text>(*root).data();
     if (root->isContainerNode())
         return contentsAsString(toContainerNode(root));
     return String();

Modified: trunk/Source/WebCore/dom/TextNodeTraversal.h (174067 => 174068)


--- trunk/Source/WebCore/dom/TextNodeTraversal.h	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/dom/TextNodeTraversal.h	2014-09-29 17:20:18 UTC (rev 174068)
@@ -66,9 +66,9 @@
 inline Text* firstTextChildTemplate(NodeType* current)
 {
     Node* node = current->firstChild();
-    while (node && !node->isTextNode())
+    while (node && !is<Text>(node))
         node = node->nextSibling();
-    return toText(node);
+    return downcast<Text>(node);
 }
 inline Text* firstChild(const Node* current) { return firstTextChildTemplate(current); }
 inline Text* firstChild(const ContainerNode* current) { return firstTextChildTemplate(current); }
@@ -77,9 +77,9 @@
 inline Text* firstTextWithinTemplate(NodeType* current)
 {
     Node* node = current->firstChild();
-    while (node && !node->isTextNode())
+    while (node && !is<Text>(node))
         node = NodeTraversal::next(node, current);
-    return toText(node);
+    return downcast<Text>(node);
 }
 inline Text* firstWithin(const Node* current) { return firstTextWithinTemplate(current); }
 inline Text* firstWithin(const ContainerNode* current) { return firstTextWithinTemplate(current); }
@@ -88,9 +88,9 @@
 inline Text* traverseNextTextTemplate(NodeType* current)
 {
     Node* node = NodeTraversal::next(current);
-    while (node && !node->isTextNode())
+    while (node && !is<Text>(node))
         node = NodeTraversal::next(node);
-    return toText(node);
+    return downcast<Text>(node);
 }
 inline Text* next(const Node* current) { return traverseNextTextTemplate(current); }
 inline Text* next(const Text* current) { return traverseNextTextTemplate(current); }
@@ -99,9 +99,9 @@
 inline Text* traverseNextTextTemplate(NodeType* current, const Node* stayWithin)
 {
     Node* node = NodeTraversal::next(current, stayWithin);
-    while (node && !node->isTextNode())
+    while (node && !is<Text>(node))
         node = NodeTraversal::next(node, stayWithin);
-    return toText(node);
+    return downcast<Text>(node);
 }
 inline Text* next(const Node* current, const Node* stayWithin) { return traverseNextTextTemplate(current, stayWithin); }
 inline Text* next(const Text* current, const Node* stayWithin) { return traverseNextTextTemplate(current, stayWithin); }
@@ -109,9 +109,9 @@
 inline Text* nextSibling(const Node* current)
 {
     Node* node = current->nextSibling();
-    while (node && !node->isTextNode())
+    while (node && !is<Text>(node))
         node = node->nextSibling();
-    return toText(node);
+    return downcast<Text>(node);
 }
 
 }

Modified: trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -164,11 +164,11 @@
 {
     Node* textNode = position.containerNode();
     int offset = position.offsetInContainerNode();
-    if (!textNode || !textNode->isTextNode() || offset < 0 || offset >= textNode->maxCharacterOffset())
+    if (!textNode || !is<Text>(textNode) || offset < 0 || offset >= textNode->maxCharacterOffset())
         return false;
 
     ExceptionCode ec = 0;
-    String textAtPosition = toText(textNode)->substringData(offset, 1, ec);
+    String textAtPosition = downcast<Text>(*textNode).substringData(offset, 1, ec);
     if (ec)
         return false;
 
@@ -267,20 +267,20 @@
     // Avoid this by splitting "\n"
     splitTextNode(text, 1);
 
-    if (text == start.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) {
+    if (text == start.containerNode() && text->previousSibling() && is<Text>(text->previousSibling())) {
         ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode());
-        start = Position(toText(text->previousSibling()), start.offsetInContainerNode());
+        start = Position(downcast<Text>(text->previousSibling()), start.offsetInContainerNode());
     }
-    if (text == end.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) {
+    if (text == end.containerNode() && text->previousSibling() && is<Text>(text->previousSibling())) {
         ASSERT(end.offsetInContainerNode() < position.offsetInContainerNode());
-        end = Position(toText(text->previousSibling()), end.offsetInContainerNode());
+        end = Position(downcast<Text>(text->previousSibling()), end.offsetInContainerNode());
     }
     if (text == m_endOfLastParagraph.containerNode()) {
         if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInContainerNode()) {
             // We can only fix endOfLastParagraph if the previous node was still text and hasn't been modified by script.
-            if (text->previousSibling()->isTextNode()
-                && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= toText(text->previousSibling())->length())
-                m_endOfLastParagraph = Position(toText(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
+            if (is<Text>(text->previousSibling())
+                && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= downcast<Text>(text->previousSibling())->length())
+                m_endOfLastParagraph = Position(downcast<Text>(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
         } else
             m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.offsetInContainerNode() - 1);
     }

Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -1201,17 +1201,17 @@
 
 void ApplyStyleCommand::splitTextAtEnd(const Position& start, const Position& end)
 {
-    ASSERT(end.containerNode()->isTextNode());
+    ASSERT(is<Text>(end.containerNode()));
 
     bool shouldUpdateStart = start.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode();
-    Text* text = toText(end.deprecatedNode());
-    splitTextNode(text, end.offsetInContainerNode());
+    Text& text = downcast<Text>(*end.deprecatedNode());
+    splitTextNode(&text, end.offsetInContainerNode());
 
-    Node* prevNode = text->previousSibling();
-    if (!prevNode || !prevNode->isTextNode())
+    Node* prevNode = text.previousSibling();
+    if (!prevNode || !is<Text>(prevNode))
         return;
 
-    Position newStart = shouldUpdateStart ? Position(toText(prevNode), start.offsetInContainerNode()) : start;
+    Position newStart = shouldUpdateStart ? Position(downcast<Text>(prevNode), start.offsetInContainerNode()) : start;
     updateStartEnd(newStart, lastPositionInNode(prevNode));
 }
 
@@ -1240,10 +1240,10 @@
     if (!parentElement || !parentElement->previousSibling())
         return;
     Node* firstTextNode = parentElement->previousSibling()->lastChild();
-    if (!firstTextNode || !firstTextNode->isTextNode())
+    if (!firstTextNode || !is<Text>(firstTextNode))
         return;
 
-    Position newStart = shouldUpdateStart ? Position(toText(firstTextNode), start.offsetInContainerNode()) : start;
+    Position newStart = shouldUpdateStart ? Position(downcast<Text>(firstTextNode), start.offsetInContainerNode()) : start;
     updateStartEnd(newStart, positionAfterNode(firstTextNode));
 }
 
@@ -1528,15 +1528,15 @@
     for (size_t i = 0; i < textNodes.size(); ++i) {
         Text* childText = textNodes[i].get();
         Node* next = childText->nextSibling();
-        if (!next || !next->isTextNode())
+        if (!next || !is<Text>(next))
             continue;
     
-        Text* nextText = toText(next);
+        Text& nextText = downcast<Text>(*next);
         if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode())
             newStart = Position(childText, childText->length() + start.offsetInContainerNode());
         if (end.anchorType() == Position::PositionIsOffsetInAnchor && next == end.containerNode())
             newEnd = Position(childText, childText->length() + end.offsetInContainerNode());
-        String textToMove = nextText->data();
+        String textToMove = nextText.data();
         insertTextIntoNode(childText, childText->length(), textToMove);
         removeNode(next);
         // don't move child node pointer. it may want to merge with more text nodes.

Modified: trunk/Source/WebCore/editing/BreakBlockquoteCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/BreakBlockquoteCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/BreakBlockquoteCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -106,13 +106,13 @@
     Node* startNode = pos.deprecatedNode();
         
     // Split at pos if in the middle of a text node.
-    if (startNode->isTextNode()) {
-        Text* textNode = toText(startNode);
-        if ((unsigned)pos.deprecatedEditingOffset() >= textNode->length()) {
+    if (is<Text>(startNode)) {
+        Text& textNode = downcast<Text>(*startNode);
+        if ((unsigned)pos.deprecatedEditingOffset() >= textNode.length()) {
             startNode = NodeTraversal::next(startNode);
             ASSERT(startNode);
         } else if (pos.deprecatedEditingOffset() > 0)
-            splitTextNode(textNode, pos.deprecatedEditingOffset());
+            splitTextNode(&textNode, pos.deprecatedEditingOffset());
     } else if (pos.deprecatedEditingOffset() > 0) {
         Node* childAtOffset = startNode->traverseToChildAt(pos.deprecatedEditingOffset());
         startNode = childAtOffset ? childAtOffset : NodeTraversal::next(startNode);

Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -376,8 +376,8 @@
             appendNode(insertChild, toContainerNode(refChild));
     } else if (caretMinOffset(refChild) >= offset)
         insertNodeBefore(insertChild, refChild);
-    else if (refChild->isTextNode() && caretMaxOffset(refChild) > offset) {
-        splitTextNode(toText(refChild), offset);
+    else if (is<Text>(refChild) && caretMaxOffset(refChild) > offset) {
+        splitTextNode(downcast<Text>(refChild), offset);
 
         // Mutation events (bug 22634) from the text node insertion may have removed the refChild
         if (!refChild->inDocument())
@@ -621,7 +621,7 @@
     if (pos.offsetInContainerNode() >= caretMaxOffset(pos.containerNode()))
         return positionInParentAfterNode(tabSpan);
 
-    splitTextNodeContainingElement(toText(pos.containerNode()), pos.offsetInContainerNode());
+    splitTextNodeContainingElement(downcast<Text>(pos.containerNode()), pos.offsetInContainerNode());
     return positionInParentBeforeNode(tabSpan);
 }
 
@@ -676,16 +676,16 @@
 bool CompositeEditCommand::canRebalance(const Position& position) const
 {
     Node* node = position.containerNode();
-    if (position.anchorType() != Position::PositionIsOffsetInAnchor || !node || !node->isTextNode())
+    if (position.anchorType() != Position::PositionIsOffsetInAnchor || !node || !is<Text>(node))
         return false;
 
-    Text* textNode = toText(node);
-    if (textNode->length() == 0)
+    Text& textNode = downcast<Text>(*node);
+    if (!textNode.length())
         return false;
 
     node->document().updateStyleIfNeeded();
 
-    RenderObject* renderer = textNode->renderer();
+    RenderObject* renderer = textNode.renderer();
     if (renderer && !renderer->style().collapseWhiteSpace())
         return false;
 
@@ -701,14 +701,14 @@
 
     // If the rebalance is for the single offset, and neither text[offset] nor text[offset - 1] are some form of whitespace, do nothing.
     int offset = position.deprecatedEditingOffset();
-    String text = toText(node)->data();
+    String text = downcast<Text>(*node).data();
     if (!isWhitespace(text[offset])) {
         offset--;
         if (offset < 0 || !isWhitespace(text[offset]))
             return;
     }
 
-    rebalanceWhitespaceOnTextSubstring(toText(node), position.offsetInContainerNode(), position.offsetInContainerNode());
+    rebalanceWhitespaceOnTextSubstring(downcast<Text>(node), position.offsetInContainerNode(), position.offsetInContainerNode());
 }
 
 void CompositeEditCommand::rebalanceWhitespaceOnTextSubstring(PassRefPtr<Text> prpTextNode, int startOffset, int endOffset)
@@ -748,13 +748,13 @@
 void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(Position& position)
 {
     Node* node = position.deprecatedNode();
-    if (!node || !node->isTextNode())
+    if (!node || !is<Text>(node))
         return;
-    Text* textNode = toText(node);    
+    Text& textNode = downcast<Text>(*node);
     
-    if (textNode->length() == 0)
+    if (!textNode.length())
         return;
-    RenderObject* renderer = textNode->renderer();
+    RenderObject* renderer = textNode.renderer();
     if (renderer && !renderer->style().collapseWhiteSpace())
         return;
 
@@ -767,10 +767,10 @@
     VisiblePosition previousVisiblePos(visiblePos.previous());
     Position previous(previousVisiblePos.deepEquivalent());
     
-    if (deprecatedIsCollapsibleWhitespace(previousVisiblePos.characterAfter()) && previous.deprecatedNode()->isTextNode() && !previous.deprecatedNode()->hasTagName(brTag))
-        replaceTextInNodePreservingMarkers(toText(previous.deprecatedNode()), previous.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
-    if (deprecatedIsCollapsibleWhitespace(visiblePos.characterAfter()) && position.deprecatedNode()->isTextNode() && !position.deprecatedNode()->hasTagName(brTag))
-        replaceTextInNodePreservingMarkers(toText(position.deprecatedNode()), position.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
+    if (deprecatedIsCollapsibleWhitespace(previousVisiblePos.characterAfter()) && is<Text>(previous.deprecatedNode()) && !is<HTMLBRElement>(previous.deprecatedNode()))
+        replaceTextInNodePreservingMarkers(downcast<Text>(previous.deprecatedNode()), previous.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
+    if (deprecatedIsCollapsibleWhitespace(visiblePos.characterAfter()) && is<Text>(position.deprecatedNode()) && !is<HTMLBRElement>(position.deprecatedNode()))
+        replaceTextInNodePreservingMarkers(downcast<Text>(position.deprecatedNode()), position.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
 }
 
 void CompositeEditCommand::rebalanceWhitespace()
@@ -875,8 +875,8 @@
 
     Vector<RefPtr<Text>> nodes;
     for (Node* node = start.deprecatedNode(); node; node = NodeTraversal::next(node)) {
-        if (node->isTextNode())
-            nodes.append(toText(node));
+        if (is<Text>(node))
+            nodes.append(downcast<Text>(node));
         if (node == end.deprecatedNode())
             break;
     }
@@ -949,12 +949,12 @@
     ASSERT(lineBreakExistsAtPosition(p));
     
     // We are certain that the position is at a line break, but it may be a br or a preserved newline.
-    if (p.anchorNode()->hasTagName(brTag)) {
+    if (is<HTMLBRElement>(p.anchorNode())) {
         removeNode(p.anchorNode());
         return;
     }
     
-    deleteTextFromNode(toText(p.anchorNode()), p.offsetInContainerNode(), 1);
+    deleteTextFromNode(downcast<Text>(p.anchorNode()), p.offsetInContainerNode(), 1);
 }
 
 PassRefPtr<Node> CompositeEditCommand::insertNewDefaultParagraphElementAt(const Position& position)
@@ -1119,7 +1119,7 @@
         Position position = caretAfterDelete.deepEquivalent().downstream();
         Node* node = position.deprecatedNode();
         // Normally deletion will leave a br as a placeholder.
-        if (node->hasTagName(brTag))
+        if (is<HTMLBRElement>(node))
             removeNodeAndPruneAncestors(node);
         // If the selection to move was empty and in an empty block that 
         // doesn't require a placeholder to prop itself open (like a bordered
@@ -1137,11 +1137,11 @@
         else if (lineBreakExistsAtPosition(position)) {
             // There is a preserved '\n' at caretAfterDelete.
             // We can safely assume this is a text node.
-            Text* textNode = toText(node);
-            if (textNode->length() == 1)
+            Text& textNode = downcast<Text>(*node);
+            if (textNode.length() == 1)
                 removeNodeAndPruneAncestors(node);
             else
-                deleteTextFromNode(textNode, position.deprecatedEditingOffset(), 1);
+                deleteTextFromNode(&textNode, position.deprecatedEditingOffset(), 1);
         }
     }
 }
@@ -1434,13 +1434,13 @@
     
     if (caretPos.deprecatedNode()->hasTagName(brTag))
         removeNodeAndPruneAncestors(caretPos.deprecatedNode());
-    else if (caretPos.deprecatedNode()->isTextNode()) {
+    else if (is<Text>(caretPos.deprecatedNode())) {
         ASSERT(caretPos.deprecatedEditingOffset() == 0);
-        Text* textNode = toText(caretPos.deprecatedNode());
-        ContainerNode* parentNode = textNode->parentNode();
+        Text& textNode = downcast<Text>(*caretPos.deprecatedNode());
+        ContainerNode* parentNode = textNode.parentNode();
         // The preserved newline must be the first thing in the node, since otherwise the previous
         // paragraph would be quoted, and we verified that it wasn't above.
-        deleteTextFromNode(textNode, 0, 1);
+        deleteTextFromNode(&textNode, 0, 1);
         prune(parentNode);
     }
 

Modified: trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -464,10 +464,10 @@
             return;
     }
 
-    if (startOffset >= caretMaxOffset(startNode) && startNode->isTextNode()) {
-        Text* text = toText(startNode);
-        if (text->length() > (unsigned)caretMaxOffset(startNode))
-            deleteTextFromNode(text, caretMaxOffset(startNode), text->length() - caretMaxOffset(startNode));
+    if (startOffset >= caretMaxOffset(startNode) && is<Text>(startNode)) {
+        Text& text = downcast<Text>(*startNode);
+        if (text.length() > static_cast<unsigned>(caretMaxOffset(startNode)))
+            deleteTextFromNode(&text, caretMaxOffset(startNode), text.length() - caretMaxOffset(startNode));
     }
 
     if (startOffset >= lastOffsetForEditing(startNode)) {
@@ -481,10 +481,10 @@
 
     if (startNode == m_downstreamEnd.deprecatedNode()) {
         if (m_downstreamEnd.deprecatedEditingOffset() - startOffset > 0) {
-            if (startNode->isTextNode()) {
+            if (is<Text>(startNode)) {
                 // in a text node that needs to be trimmed
-                Text* text = toText(startNode);
-                deleteTextFromNode(text, startOffset, m_downstreamEnd.deprecatedEditingOffset() - startOffset);
+                Text& text = downcast<Text>(*startNode);
+                deleteTextFromNode(&text, startOffset, m_downstreamEnd.deprecatedEditingOffset() - startOffset);
             } else {
                 removeChildrenInRange(startNode, startOffset, m_downstreamEnd.deprecatedEditingOffset());
                 m_endingPosition = m_upstreamStart;
@@ -501,17 +501,17 @@
         RefPtr<Node> node(startNode);
         
         if (startOffset > 0) {
-            if (startNode->isTextNode()) {
+            if (is<Text>(startNode)) {
                 // in a text node that needs to be trimmed
-                Text* text = toText(node.get());
-                deleteTextFromNode(text, startOffset, text->length() - startOffset);
+                Text& text = downcast<Text>(*node);
+                deleteTextFromNode(&text, startOffset, text.length() - startOffset);
                 node = NodeTraversal::next(node.get());
             } else {
                 node = startNode->traverseToChildAt(startOffset);
             }
-        } else if (startNode == m_upstreamEnd.deprecatedNode() && startNode->isTextNode()) {
-            Text* text = toText(m_upstreamEnd.deprecatedNode());
-            deleteTextFromNode(text, 0, m_upstreamEnd.deprecatedEditingOffset());
+        } else if (startNode == m_upstreamEnd.deprecatedNode() && is<Text>(startNode)) {
+            Text& text = downcast<Text>(*m_upstreamEnd.deprecatedNode());
+            deleteTextFromNode(&text, 0, m_upstreamEnd.deprecatedEditingOffset());
         }
         
         // handle deleting all nodes that are completely selected
@@ -541,11 +541,11 @@
                 // The node itself is fully selected, not just its contents.  Delete it.
                 removeNode(m_downstreamEnd.deprecatedNode());
             } else {
-                if (m_downstreamEnd.deprecatedNode()->isTextNode()) {
+                if (is<Text>(m_downstreamEnd.deprecatedNode())) {
                     // in a text node that needs to be trimmed
-                    Text* text = toText(m_downstreamEnd.deprecatedNode());
+                    Text& text = downcast<Text>(*m_downstreamEnd.deprecatedNode());
                     if (m_downstreamEnd.deprecatedEditingOffset() > 0) {
-                        deleteTextFromNode(text, 0, m_downstreamEnd.deprecatedEditingOffset());
+                        deleteTextFromNode(&text, 0, m_downstreamEnd.deprecatedEditingOffset());
                     }
                 // Remove children of m_downstreamEnd.deprecatedNode() that come after m_upstreamStart.
                 // Don't try to remove children if m_upstreamStart was inside m_downstreamEnd.deprecatedNode()
@@ -574,15 +574,15 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
     // FIXME: isRenderedCharacter should be removed, and we should use VisiblePosition::characterAfter and VisiblePosition::characterBefore
-    if (m_leadingWhitespace.isNotNull() && !m_leadingWhitespace.isRenderedCharacter() && m_leadingWhitespace.deprecatedNode()->isTextNode()) {
-        Text* textNode = toText(m_leadingWhitespace.deprecatedNode());
-        ASSERT(!textNode->renderer() || textNode->renderer()->style().collapseWhiteSpace());
-        replaceTextInNodePreservingMarkers(textNode, m_leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
+    if (m_leadingWhitespace.isNotNull() && !m_leadingWhitespace.isRenderedCharacter() && is<Text>(m_leadingWhitespace.deprecatedNode())) {
+        Text& textNode = downcast<Text>(*m_leadingWhitespace.deprecatedNode());
+        ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace());
+        replaceTextInNodePreservingMarkers(&textNode, m_leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
     }
-    if (m_trailingWhitespace.isNotNull() && !m_trailingWhitespace.isRenderedCharacter() && m_trailingWhitespace.deprecatedNode()->isTextNode()) {
-        Text* textNode = toText(m_trailingWhitespace.deprecatedNode());
-        ASSERT(!textNode->renderer() || textNode->renderer()->style().collapseWhiteSpace());
-        replaceTextInNodePreservingMarkers(textNode, m_trailingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
+    if (m_trailingWhitespace.isNotNull() && !m_trailingWhitespace.isRenderedCharacter() && is<Text>(m_trailingWhitespace.deprecatedNode())) {
+        Text& textNode = downcast<Text>(*m_trailingWhitespace.deprecatedNode());
+        ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace());
+        replaceTextInNodePreservingMarkers(&textNode, m_trailingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
     }
 }
 
@@ -864,10 +864,10 @@
     bool shouldRebalaceWhiteSpace = true;
     if (!frame().editor().behavior().shouldRebalanceWhiteSpacesInSecureField()) {
         Node* node = m_endingPosition.deprecatedNode();
-        if (node && node->isTextNode()) {
-            Text* textNode = toText(node);
-            if (textNode->length())
-                shouldRebalaceWhiteSpace = textNode->renderer()->style().textSecurity() == TSNONE;
+        if (node && is<Text>(node)) {
+            Text& textNode = downcast<Text>(*node);
+            if (textNode.length())
+                shouldRebalaceWhiteSpace = textNode.renderer()->style().textSecurity() == TSNONE;
         }        
     }
     if (shouldRebalaceWhiteSpace)

Modified: trunk/Source/WebCore/editing/Editor.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/Editor.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/Editor.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -1865,8 +1865,8 @@
         Node* extentNode = extent.deprecatedNode();
         unsigned extentOffset = extent.deprecatedEditingOffset();
 
-        if (baseNode && baseNode == extentNode && baseNode->isTextNode() && baseOffset + text.length() == extentOffset) {
-            m_compositionNode = toText(baseNode);
+        if (baseNode && baseNode == extentNode && is<Text>(baseNode) && baseOffset + text.length() == extentOffset) {
+            m_compositionNode = downcast<Text>(baseNode);
             m_compositionStart = baseOffset;
             m_compositionEnd = extentOffset;
             m_customCompositionUnderlines = underlines;

Modified: trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -137,23 +137,23 @@
     } else if (pos.deprecatedEditingOffset() >= caretMaxOffset(pos.deprecatedNode()) || !pos.deprecatedNode()->isTextNode()) {
         insertNodeAt(nodeToInsert.get(), pos);
         setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInsert.get()), DOWNSTREAM, endingSelection().isDirectional()));
-    } else if (pos.deprecatedNode()->isTextNode()) {
+    } else if (is<Text>(pos.deprecatedNode())) {
         // Split a text node
-        Text* textNode = toText(pos.deprecatedNode());
-        splitTextNode(textNode, pos.deprecatedEditingOffset());
-        insertNodeBefore(nodeToInsert, textNode);
-        Position endingPosition = firstPositionInNode(textNode);
+        Text& textNode = downcast<Text>(*pos.deprecatedNode());
+        splitTextNode(&textNode, pos.deprecatedEditingOffset());
+        insertNodeBefore(nodeToInsert, &textNode);
+        Position endingPosition = firstPositionInNode(&textNode);
         
         // Handle whitespace that occurs after the split
         document().updateLayoutIgnorePendingStylesheets();
         if (!endingPosition.isRenderedCharacter()) {
-            Position positionBeforeTextNode(positionInParentBeforeNode(textNode));
+            Position positionBeforeTextNode(positionInParentBeforeNode(&textNode));
             // Clear out all whitespace and insert one non-breaking space
             deleteInsignificantTextDownstream(endingPosition);
-            ASSERT(!textNode->renderer() || textNode->renderer()->style().collapseWhiteSpace());
+            ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace());
             // Deleting insignificant whitespace will remove textNode if it contains nothing but insignificant whitespace.
-            if (textNode->inDocument())
-                insertTextIntoNode(textNode, 0, nonBreakingSpaceString());
+            if (textNode.inDocument())
+                insertTextIntoNode(&textNode, 0, nonBreakingSpaceString());
             else {
                 RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpaceString());
                 insertNodeAt(nbspNode.get(), positionBeforeTextNode);

Modified: trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -331,16 +331,16 @@
     Position leadingWhitespace = insertionPosition.leadingWhitespacePosition(VP_DEFAULT_AFFINITY);
     // FIXME: leadingWhitespacePosition is returning the position before preserved newlines for positions
     // after the preserved newline, causing the newline to be turned into a nbsp.
-    if (leadingWhitespace.isNotNull() && leadingWhitespace.deprecatedNode()->isTextNode()) {
-        Text* textNode = toText(leadingWhitespace.deprecatedNode());
-        ASSERT(!textNode->renderer() || textNode->renderer()->style().collapseWhiteSpace());
-        replaceTextInNodePreservingMarkers(textNode, leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
+    if (leadingWhitespace.isNotNull() && is<Text>(leadingWhitespace.deprecatedNode())) {
+        Text& textNode = downcast<Text>(*leadingWhitespace.deprecatedNode());
+        ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace());
+        replaceTextInNodePreservingMarkers(&textNode, leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
     }
     
     // Split at pos if in the middle of a text node.
     Position positionAfterSplit;
-    if (insertionPosition.anchorType() == Position::PositionIsOffsetInAnchor && insertionPosition.containerNode()->isTextNode()) {
-        RefPtr<Text> textNode = toText(insertionPosition.containerNode());
+    if (insertionPosition.anchorType() == Position::PositionIsOffsetInAnchor && is<Text>(insertionPosition.containerNode())) {
+        RefPtr<Text> textNode = downcast<Text>(insertionPosition.containerNode());
         bool atEnd = static_cast<unsigned>(insertionPosition.offsetInContainerNode()) >= textNode->length();
         if (insertionPosition.deprecatedEditingOffset() > 0 && !atEnd) {
             splitTextNode(textNode, insertionPosition.offsetInContainerNode());
@@ -399,8 +399,8 @@
             // Clear out all whitespace and insert one non-breaking space
             ASSERT(!positionAfterSplit.containerNode()->renderer() || positionAfterSplit.containerNode()->renderer()->style().collapseWhiteSpace());
             deleteInsignificantTextDownstream(positionAfterSplit);
-            if (positionAfterSplit.deprecatedNode()->isTextNode())
-                insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0, nonBreakingSpaceString());
+            if (is<Text>(positionAfterSplit.deprecatedNode()))
+                insertTextIntoNode(downcast<Text>(positionAfterSplit.containerNode()), 0, nonBreakingSpaceString());
         }
     }
 

Modified: trunk/Source/WebCore/editing/InsertTextCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/InsertTextCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/InsertTextCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -241,7 +241,7 @@
 
     // keep tabs coalesced in tab span
     if (isTabSpanTextNode(node)) {
-        RefPtr<Text> textNode = toText(node);
+        RefPtr<Text> textNode = downcast<Text>(node);
         insertTextIntoNode(textNode, offset, "\t");
         return Position(textNode.release(), offset + 1);
     }
@@ -250,10 +250,10 @@
     RefPtr<Element> spanNode = createTabSpanElement(document());
     
     // place it
-    if (!node->isTextNode()) {
+    if (!is<Text>(node)) {
         insertNodeAt(spanNode.get(), insertPos);
     } else {
-        RefPtr<Text> textNode = toText(node);
+        RefPtr<Text> textNode = downcast<Text>(node);
         if (offset >= textNode->length())
             insertNodeAfter(spanNode, textNode.release());
         else {

Modified: trunk/Source/WebCore/editing/MarkupAccumulator.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/MarkupAccumulator.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -553,7 +553,7 @@
 
     switch (node.nodeType()) {
     case Node::TEXT_NODE:
-        appendText(result, toText(node));
+        appendText(result, downcast<Text>(node));
         break;
     case Node::COMMENT_NODE:
         appendComment(result, downcast<Comment>(node).data());

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -683,7 +683,7 @@
     document().updateLayoutIgnorePendingStylesheets();
 
     Node* lastLeafInserted = insertedNodes.lastLeafInserted();
-    if (lastLeafInserted && lastLeafInserted->isTextNode() && !hasRenderedText(toText(*lastLeafInserted))
+    if (lastLeafInserted && is<Text>(lastLeafInserted) && !hasRenderedText(downcast<Text>(*lastLeafInserted))
         && !enclosingElementWithTag(firstPositionInOrBeforeNode(lastLeafInserted), selectTag)
         && !enclosingElementWithTag(firstPositionInOrBeforeNode(lastLeafInserted), scriptTag)) {
         insertedNodes.willRemoveNode(lastLeafInserted);
@@ -693,7 +693,7 @@
     // We don't have to make sure that firstNodeInserted isn't inside a select or script element
     // because it is a top level node in the fragment and the user can't insert into those elements.
     Node* firstNodeInserted = insertedNodes.firstNodeInserted();
-    if (firstNodeInserted && firstNodeInserted->isTextNode() && !hasRenderedText(toText(*firstNodeInserted))) {
+    if (firstNodeInserted && is<Text>(firstNodeInserted) && !hasRenderedText(downcast<Text>(*firstNodeInserted))) {
         insertedNodes.willRemoveNode(firstNodeInserted);
         removeNode(firstNodeInserted);
     }
@@ -1291,7 +1291,7 @@
 
     Position endUpstream = endOfInsertedContent.deepEquivalent().upstream();
     Node* endNode = endUpstream.computeNodeBeforePosition();
-    int endOffset = endNode && endNode->isTextNode() ? toText(endNode)->length() : 0;
+    int endOffset = endNode && is<Text>(endNode) ? downcast<Text>(*endNode).length() : 0;
     if (endUpstream.anchorType() == Position::PositionIsOffsetInAnchor) {
         endNode = endUpstream.containerNode();
         endOffset = endUpstream.offsetInContainerNode();
@@ -1300,8 +1300,8 @@
     bool needsTrailingSpace = !isEndOfParagraph(endOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(endOfInsertedContent.characterAfter(), false);
     if (needsTrailingSpace && endNode) {
         bool collapseWhiteSpace = !endNode->renderer() || endNode->renderer()->style().collapseWhiteSpace();
-        if (endNode->isTextNode()) {
-            insertTextIntoNode(toText(endNode), endOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
+        if (is<Text>(endNode)) {
+            insertTextIntoNode(downcast<Text>(endNode), endOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
             if (m_endOfInsertedContent.containerNode() == endNode)
                 m_endOfInsertedContent.moveToOffset(m_endOfInsertedContent.offsetInContainerNode() + 1);
         } else {
@@ -1324,8 +1324,8 @@
     bool needsLeadingSpace = !isStartOfParagraph(startOfInsertedContent) && !isCharacterSmartReplaceExemptConsideringNonBreakingSpace(startOfInsertedContent.previous().characterAfter(), true);
     if (needsLeadingSpace && startNode) {
         bool collapseWhiteSpace = !startNode->renderer() || startNode->renderer()->style().collapseWhiteSpace();
-        if (startNode->isTextNode()) {
-            insertTextIntoNode(toText(startNode), startOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
+        if (is<Text>(startNode)) {
+            insertTextIntoNode(downcast<Text>(startNode), startOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
             if (m_endOfInsertedContent.containerNode() == startNode && m_endOfInsertedContent.offsetInContainerNode())
                 m_endOfInsertedContent.moveToOffset(m_endOfInsertedContent.offsetInContainerNode() + 1);
         } else {
@@ -1374,24 +1374,24 @@
 {
     bool positionIsOffsetInAnchor = position.anchorType() == Position::PositionIsOffsetInAnchor;
     bool positionOnlyToBeUpdatedIsOffsetInAnchor = positionOnlyToBeUpdated.anchorType() == Position::PositionIsOffsetInAnchor;
-    RefPtr<Text> text = 0;
-    if (positionIsOffsetInAnchor && position.containerNode() && position.containerNode()->isTextNode())
-        text = toText(position.containerNode());
+    RefPtr<Text> text;
+    if (positionIsOffsetInAnchor && position.containerNode() && is<Text>(position.containerNode()))
+        text = downcast<Text>(position.containerNode());
     else {
         Node* before = position.computeNodeBeforePosition();
-        if (before && before->isTextNode())
-            text = toText(before);
+        if (before && is<Text>(before))
+            text = downcast<Text>(before);
         else {
             Node* after = position.computeNodeAfterPosition();
-            if (after && after->isTextNode())
-                text = toText(after);
+            if (after && is<Text>(after))
+                text = downcast<Text>(after);
         }
     }
     if (!text)
         return;
 
-    if (text->previousSibling() && text->previousSibling()->isTextNode()) {
-        RefPtr<Text> previous = toText(text->previousSibling());
+    if (text->previousSibling() && is<Text>(text->previousSibling())) {
+        RefPtr<Text> previous = downcast<Text>(text->previousSibling());
         insertTextIntoNode(text, 0, previous->data());
 
         if (positionIsOffsetInAnchor)
@@ -1409,8 +1409,8 @@
 
         removeNode(previous);
     }
-    if (text->nextSibling() && text->nextSibling()->isTextNode()) {
-        RefPtr<Text> next = toText(text->nextSibling());
+    if (text->nextSibling() && is<Text>(text->nextSibling())) {
+        RefPtr<Text> next = downcast<Text>(text->nextSibling());
         unsigned originalLength = text->length();
         insertTextIntoNode(text, originalLength, next->data());
 
@@ -1449,8 +1449,8 @@
     // list items and insert these nodes between them.
     if (isMiddle) {
         int textNodeOffset = insertPos.offsetInContainerNode();
-        if (insertPos.deprecatedNode()->isTextNode() && textNodeOffset > 0)
-            splitTextNode(toText(insertPos.deprecatedNode()), textNodeOffset);
+        if (is<Text>(insertPos.deprecatedNode()) && textNodeOffset > 0)
+            splitTextNode(downcast<Text>(insertPos.deprecatedNode()), textNodeOffset);
         splitTreeToNode(insertPos.deprecatedNode(), lastNode, true);
     }
 
@@ -1488,7 +1488,7 @@
 // split text nodes.
 bool ReplaceSelectionCommand::performTrivialReplace(const ReplacementFragment& fragment)
 {
-    if (!fragment.firstChild() || fragment.firstChild() != fragment.lastChild() || !fragment.firstChild()->isTextNode())
+    if (!fragment.firstChild() || fragment.firstChild() != fragment.lastChild() || !is<Text>(fragment.firstChild()))
         return false;
 
     // FIXME: Would be nice to handle smart replace in the fast path.
@@ -1500,11 +1500,11 @@
         return false;
 
     RefPtr<Node> nodeAfterInsertionPos = endingSelection().end().downstream().anchorNode();
-    Text* textNode = toText(fragment.firstChild());
+    Text& textNode = downcast<Text>(*fragment.firstChild());
     // Our fragment creation code handles tabs, spaces, and newlines, so we don't have to worry about those here.
 
     Position start = endingSelection().start();
-    Position end = replaceSelectedTextInNode(textNode->data());
+    Position end = replaceSelectedTextInNode(textNode.data());
     if (end.isNull())
         return false;
 

Modified: trunk/Source/WebCore/editing/TextIterator.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/TextIterator.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/TextIterator.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -501,7 +501,7 @@
 
 bool TextIterator::handleTextNode()
 {
-    Text& textNode = toText(*m_node);
+    Text& textNode = downcast<Text>(*m_node);
 
     if (m_fullyClippedStack.top() && !(m_behavior & TextIteratorIgnoresStyleVisibility))
         return false;
@@ -603,7 +603,7 @@
 
 void TextIterator::handleTextBox()
 {    
-    Text& textNode = toText(*m_node);
+    Text& textNode = downcast<Text>(*m_node);
 
     auto& renderer = m_firstLetterText ? *m_firstLetterText : *textNode.renderer();
     if (renderer.style().visibility() != VISIBLE && !(m_behavior & TextIteratorIgnoresStyleVisibility)) {
@@ -1263,7 +1263,7 @@
 
 bool SimplifiedBackwardsTextIterator::handleTextNode()
 {
-    Text& textNode = toText(*m_node);
+    Text& textNode = downcast<Text>(*m_node);
 
     m_lastTextNode = &textNode;
 

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/VisibleUnits.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -767,7 +767,7 @@
         }
     }
 
-    return startNode->isTextNode() ? Position(toText(startNode), toInlineTextBox(startBox)->start())
+    return is<Text>(startNode) ? Position(downcast<Text>(startNode), toInlineTextBox(startBox)->start())
         : positionBeforeNode(startNode);
 }
 
@@ -838,12 +838,12 @@
     Position pos;
     if (endNode->hasTagName(brTag))
         pos = positionBeforeNode(endNode);
-    else if (endBox->isInlineTextBox() && endNode->isTextNode()) {
+    else if (endBox->isInlineTextBox() && is<Text>(endNode)) {
         InlineTextBox* endTextBox = toInlineTextBox(endBox);
         int endOffset = endTextBox->start();
         if (!endTextBox->isLineBreak())
             endOffset += endTextBox->len();
-        pos = Position(toText(endNode), endOffset);
+        pos = Position(downcast<Text>(endNode), endOffset);
     } else
         pos = positionAfterNode(endNode);
     
@@ -1138,7 +1138,7 @@
             break;
 
         if (r->isText() && toRenderText(r)->hasRenderedText()) {
-            ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
+            ASSERT_WITH_SECURITY_IMPLICATION(is<Text>(n));
             type = Position::PositionIsOffsetInAnchor;
             if (style.preserveNewline()) {
                 StringImpl& text = *toRenderText(r)->text();
@@ -1148,7 +1148,7 @@
                     i = std::max(0, o);
                 while (--i >= 0) {
                     if (text[i] == '\n')
-                        return VisiblePosition(Position(toText(n), i + 1), DOWNSTREAM);
+                        return VisiblePosition(Position(downcast<Text>(n), i + 1), DOWNSTREAM);
                 }
             }
             node = n;
@@ -1221,7 +1221,7 @@
 
         // FIXME: We avoid returning a position where the renderer can't accept the caret.
         if (r->isText() && toRenderText(r)->hasRenderedText()) {
-            ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
+            ASSERT_WITH_SECURITY_IMPLICATION(is<Text>(n));
             type = Position::PositionIsOffsetInAnchor;
             if (style.preserveNewline()) {
                 StringImpl& text = *toRenderText(r)->text();
@@ -1229,7 +1229,7 @@
                 int length = text.length();
                 for (int i = o; i < length; ++i) {
                     if (text[i] == '\n')
-                        return VisiblePosition(Position(toText(n), i), DOWNSTREAM);
+                        return VisiblePosition(Position(downcast<Text>(n), i), DOWNSTREAM);
                 }
             }
             node = n;

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -1055,12 +1055,12 @@
     if (!position.anchorNode()->renderer())
         return false;
     
-    if (!position.anchorNode()->isTextNode() || !position.anchorNode()->renderer()->style().preserveNewline())
+    if (!is<Text>(position.anchorNode()) || !position.anchorNode()->renderer()->style().preserveNewline())
         return false;
     
-    Text* textNode = toText(position.anchorNode());
+    Text& textNode = downcast<Text>(*position.anchorNode());
     unsigned offset = position.offsetInContainerNode();
-    return offset < textNode->length() && textNode->data()[offset] == '\n';
+    return offset < textNode.length() && textNode.data()[offset] == '\n';
 }
 
 // Modifies selections that have an end point at the edge of a table

Modified: trunk/Source/WebCore/editing/markup.cpp (174067 => 174068)


--- trunk/Source/WebCore/editing/markup.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/editing/markup.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -263,10 +263,10 @@
     
 String StyledMarkupAccumulator::renderedText(const Node& node, const Range* range)
 {
-    if (!node.isTextNode())
+    if (!is<Text>(node))
         return String();
 
-    const Text& textNode = toText(node);
+    const Text& textNode = downcast<Text>(node);
     unsigned startOffset = 0;
     unsigned endOffset = textNode.length();
 
@@ -1001,7 +1001,7 @@
     }
 
     if (hasOneTextChild(&containerNode.get()) && hasOneTextChild(fragment.get())) {
-        toText(containerNode->firstChild())->setData(toText(fragment->firstChild())->data(), ec);
+        downcast<Text>(*containerNode->firstChild()).setData(downcast<Text>(*fragment->firstChild()).data(), ec);
         return;
     }
 
@@ -1020,7 +1020,7 @@
     ChildListMutationScope mutation(containerNode.get());
 
     if (hasOneTextChild(&containerNode.get())) {
-        toText(containerNode->firstChild())->setData(text, ec);
+        downcast<Text>(*containerNode->firstChild()).setData(text, ec);
         return;
     }
 

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -436,11 +436,11 @@
 static void mergeWithNextTextNode(Text& node, ExceptionCode& ec)
 {
     Node* next = node.nextSibling();
-    if (!next || !next->isTextNode())
+    if (!next || !is<Text>(next))
         return;
 
     Ref<Text> textNode(node);
-    Ref<Text> textNext(toText(*next));
+    Ref<Text> textNext(downcast<Text>(*next));
     textNode->appendData(textNext->data(), ec);
     if (ec)
         return;
@@ -464,10 +464,10 @@
       
     parent->replaceChild(fragment.release(), this, ec);
     RefPtr<Node> node = next ? next->previousSibling() : nullptr;
-    if (!ec && node && node->isTextNode())
-        mergeWithNextTextNode(toText(*node), ec);
-    if (!ec && prev && prev->isTextNode())
-        mergeWithNextTextNode(toText(*prev), ec);
+    if (!ec && node && is<Text>(*node))
+        mergeWithNextTextNode(downcast<Text>(*node), ec);
+    if (!ec && prev && is<Text>(*prev))
+        mergeWithNextTextNode(downcast<Text>(*prev), ec);
 }
 
 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, ExceptionCode& ec)
@@ -597,10 +597,10 @@
     parent->replaceChild(newChild.release(), this, ec);
 
     RefPtr<Node> node = next ? next->previousSibling() : nullptr;
-    if (!ec && node && node->isTextNode())
-        mergeWithNextTextNode(toText(*node), ec);
-    if (!ec && prev && prev->isTextNode())
-        mergeWithNextTextNode(toText(*prev), ec);
+    if (!ec && node && is<Text>(*node))
+        mergeWithNextTextNode(downcast<Text>(*node), ec);
+    if (!ec && prev && is<Text>(*prev))
+        mergeWithNextTextNode(downcast<Text>(*prev), ec);
 }
 
 Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, ExceptionCode& ec)

Modified: trunk/Source/WebCore/html/HTMLObjectElement.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/HTMLObjectElement.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/HTMLObjectElement.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -231,10 +231,10 @@
 {
     for (Node* child = firstChild(); child; child = child->nextSibling()) {
         // Ignore whitespace-only text, and <param> tags, any other content is fallback content.
-        if (child->isTextNode()) {
-            if (!toText(child)->containsOnlyWhitespace())
+        if (is<Text>(child)) {
+            if (!downcast<Text>(*child).containsOnlyWhitespace())
                 return true;
-        } else if (!child->hasTagName(paramTag))
+        } else if (!is<HTMLParamElement>(child))
             return true;
     }
     return false;
@@ -428,8 +428,8 @@
             // FIXME: Use of isRecognizedTagName is almost certainly wrong here.
             if (isRecognizedTagName(element->tagQName()) && !element->hasTagName(paramTag))
                 isNamedItem = false;
-        } else if (child->isTextNode()) {
-            if (!toText(child)->containsOnlyWhitespace())
+        } else if (is<Text>(child)) {
+            if (!downcast<Text>(*child).containsOnlyWhitespace())
                 isNamedItem = false;
         } else
             isNamedItem = false;

Modified: trunk/Source/WebCore/html/HTMLOptionElement.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/HTMLOptionElement.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/HTMLOptionElement.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -129,8 +129,8 @@
 
     // Handle the common special case where there's exactly 1 child node, and it's a text node.
     Node* child = firstChild();
-    if (child && child->isTextNode() && !child->nextSibling())
-        toText(child)->setData(text, ec);
+    if (child && is<Text>(child) && !child->nextSibling())
+        downcast<Text>(*child).setData(text, ec);
     else {
         removeChildren();
         appendChild(Text::create(document(), text), ec);

Modified: trunk/Source/WebCore/html/HTMLScriptElement.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/HTMLScriptElement.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/HTMLScriptElement.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -81,8 +81,8 @@
 {
     Ref<HTMLScriptElement> protectFromMutationEvents(*this);
 
-    if (hasOneChild() && firstChild()->isTextNode()) {
-        toText(firstChild())->setData(value, IGNORE_EXCEPTION);
+    if (hasOneChild() && is<Text>(firstChild())) {
+        downcast<Text>(*firstChild()).setData(value, IGNORE_EXCEPTION);
         return;
     }
 

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -561,10 +561,10 @@
 
     StringBuilder result;
     for (Node* node = innerText; node; node = NodeTraversal::next(node, innerText)) {
-        if (node->hasTagName(brTag))
+        if (is<HTMLBRElement>(node))
             result.append(newlineCharacter);
-        else if (node->isTextNode())
-            result.append(toText(node)->data());
+        else if (is<Text>(node))
+            result.append(downcast<Text>(*node).data());
     }
     return finishText(result);
 }
@@ -579,8 +579,8 @@
                 return positionBeforeNode(node);
             remainingCharactersToMoveForward--;
             lastBrOrText = node;
-        } else if (node->isTextNode()) {
-            Text& text = toText(*node);
+        } else if (is<Text>(node)) {
+            Text& text = downcast<Text>(*node);
             if (remainingCharactersToMoveForward < text.length())
                 return Position(&text, remainingCharactersToMoveForward);
             remainingCharactersToMoveForward -= text.length();
@@ -607,14 +607,14 @@
     ASSERT(innerText->contains(startNode));
 
     for (Node* node = startNode; node; node = NodeTraversal::previous(node, innerText)) {
-        if (node->isTextNode()) {
-            unsigned length = toText(*node).length();
+        if (is<Text>(node)) {
+            unsigned length = downcast<Text>(*node).length();
             if (node == passedPosition.containerNode())
                 index += std::min<unsigned>(length, passedPosition.offsetInContainerNode());
             else
                 index += length;
-        } else if (node->hasTagName(brTag))
-            index++;
+        } else if (is<HTMLBRElement>(node))
+            ++index;
     }
 
     unsigned length = innerTextValue().length();
@@ -685,10 +685,10 @@
 
     StringBuilder result;
     for (Node* node = innerText->firstChild(); node; node = NodeTraversal::next(node, innerText)) {
-        if (node->hasTagName(brTag))
+        if (is<HTMLBRElement>(node))
             result.append(newlineCharacter);
-        else if (node->isTextNode()) {
-            String data = ""
+        else if (is<Text>(node)) {
+            String data = ""
             unsigned length = data.length();
             unsigned position = 0;
             while (breakNode == node && breakOffset <= length) {

Modified: trunk/Source/WebCore/html/HTMLTitleElement.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/HTMLTitleElement.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/HTMLTitleElement.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -97,8 +97,8 @@
 {
     Ref<HTMLTitleElement> protectFromMutationEvents(*this);
     
-    if (hasOneChild() && firstChild()->isTextNode())
-        toText(firstChild())->setData(value, IGNORE_EXCEPTION);
+    if (hasOneChild() && is<Text>(firstChild()))
+        downcast<Text>(*firstChild()).setData(value, IGNORE_EXCEPTION);
     else {
         // We make a copy here because entity of "value" argument can be Document::m_title,
         // which goes empty during removeChildren() invocation below,

Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp (174067 => 174068)


--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -547,11 +547,11 @@
     // for performance, see <https://bugs.webkit.org/show_bug.cgi?id=55898>.
 
     Node* previousChild = task.nextChild ? task.nextChild->previousSibling() : task.parent->lastChild();
-    if (previousChild && previousChild->isTextNode()) {
+    if (previousChild && is<Text>(previousChild)) {
         // FIXME: We're only supposed to append to this text node if it
         // was the last text node inserted by the parser.
-        Text* textNode = toText(previousChild);
-        currentPosition = textNode->parserAppendData(characters, 0, lengthLimit);
+        Text& textNode = downcast<Text>(*previousChild);
+        currentPosition = textNode.parserAppendData(characters, 0, lengthLimit);
     }
 
     while (currentPosition < characters.length()) {

Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (174067 => 174068)


--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -806,7 +806,7 @@
         return;
     }
 
-    m_domEditor->replaceWholeText(toText(node), value, errorString);
+    m_domEditor->replaceWholeText(downcast<Text>(node), value, errorString);
 }
 
 void InspectorDOMAgent::getEventListenersForNode(ErrorString* errorString, int nodeId, const String* objectGroup, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::DOM::EventListener>>& listenersArray)

Modified: trunk/Source/WebCore/rendering/RenderCombineText.h (174067 => 174068)


--- trunk/Source/WebCore/rendering/RenderCombineText.h	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/rendering/RenderCombineText.h	2014-09-29 17:20:18 UTC (rev 174068)
@@ -32,7 +32,7 @@
 public:
     RenderCombineText(Text&, PassRefPtr<StringImpl>);
 
-    Text& textNode() const { return toText(nodeForNonAnonymous()); }
+    Text& textNode() const { return downcast<Text>(nodeForNonAnonymous()); }
 
     void combineText();
     void adjustTextOrigin(FloatPoint& textOrigin, const FloatRect& boxRect) const;

Modified: trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp (174067 => 174068)


--- trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -717,7 +717,7 @@
                     for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
                         if (offsetTop + box->logicalBottom() < logicalTopForRegion)
                             continue;
-                        range->setStart(Position(toText(node), box->start()));
+                        range->setStart(Position(downcast<Text>(node), box->start()));
                         startsAboveRegion = false;
                         break;
                     }
@@ -745,7 +745,7 @@
                 if (renderer->isText()) {
                     // Text crosses region bottom
                     RenderText* textRenderer = toRenderText(renderer);
-                    InlineTextBox* lastBox = 0;
+                    InlineTextBox* lastBox = nullptr;
                     for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
                         if ((offsetTop + box->logicalTop()) < logicalBottomForRegion) {
                             lastBox = box;
@@ -753,7 +753,7 @@
                         }
                         ASSERT(lastBox);
                         if (lastBox)
-                            range->setEnd(Position(toText(node), lastBox->start() + lastBox->len()));
+                            range->setEnd(Position(downcast<Text>(node), lastBox->start() + lastBox->len()));
                         break;
                     }
                     endsBelowRegion = false;

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (174067 => 174068)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -201,7 +201,7 @@
 
 Text* RenderText::textNode() const
 {
-    return toText(RenderObject::node());
+    return downcast<Text>(RenderObject::node());
 }
 
 bool RenderText::isTextFragment() const

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h (174067 => 174068)


--- trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h	2014-09-29 17:20:18 UTC (rev 174068)
@@ -35,7 +35,7 @@
 public:
     RenderSVGInlineText(Text&, const String&);
 
-    Text& textNode() const { return toText(nodeForNonAnonymous()); }
+    Text& textNode() const { return downcast<Text>(nodeForNonAnonymous()); }
 
     bool characterStartsNewTextChunk(int position) const;
     SVGTextLayoutAttributes* layoutAttributes() { return &m_layoutAttributes; }

Modified: trunk/Source/WebCore/style/StyleResolveTree.cpp (174067 => 174068)


--- trunk/Source/WebCore/style/StyleResolveTree.cpp	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebCore/style/StyleResolveTree.cpp	2014-09-29 17:20:18 UTC (rev 174068)
@@ -365,9 +365,9 @@
                 continue;
             return;
         }
-        if (!sibling->isTextNode())
+        if (!is<Text>(sibling))
             continue;
-        Text& textSibling = toText(*sibling);
+        Text& textSibling = downcast<Text>(*sibling);
         if (!textSibling.containsOnlyWhitespace())
             continue;
         textSibling.setNeedsStyleRecalc();
@@ -478,8 +478,8 @@
             renderTreePosition.invalidateNextSibling(*child->renderer());
             continue;
         }
-        if (child->isTextNode()) {
-            attachTextRenderer(*toText(child), renderTreePosition);
+        if (is<Text>(child)) {
+            attachTextRenderer(downcast<Text>(*child), renderTreePosition);
             continue;
         }
         if (child->isElementNode())
@@ -495,10 +495,10 @@
     for (Node* current = insertionPoint.firstDistributed(); current; current = insertionPoint.nextDistributedTo(current)) {
         if (current->renderer())
             renderTreePosition.invalidateNextSibling(*current->renderer());
-        if (current->isTextNode()) {
+        if (is<Text>(current)) {
             if (current->renderer())
                 continue;
-            attachTextRenderer(*toText(current), renderTreePosition);
+            attachTextRenderer(downcast<Text>(*current), renderTreePosition);
             continue;
         }
         if (current->isElementNode()) {
@@ -651,8 +651,8 @@
 static void detachDistributedChildren(InsertionPoint& insertionPoint)
 {
     for (Node* current = insertionPoint.firstDistributed(); current; current = insertionPoint.nextDistributedTo(current)) {
-        if (current->isTextNode()) {
-            detachTextRenderer(*toText(current));
+        if (is<Text>(current)) {
+            detachTextRenderer(downcast<Text>(*current));
             continue;
         }
         if (current->isElementNode())
@@ -666,8 +666,8 @@
         detachDistributedChildren(downcast<InsertionPoint>(current));
 
     for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
-        if (child->isTextNode()) {
-            Style::detachTextRenderer(*toText(child));
+        if (is<Text>(child)) {
+            Style::detachTextRenderer(downcast<Text>(*child));
             continue;
         }
         if (child->isElementNode())
@@ -815,8 +815,8 @@
     for (Node* child = shadowRoot.firstChild(); child; child = child->nextSibling()) {
         if (child->renderer())
             renderTreePosition.invalidateNextSibling(*child->renderer());
-        if (child->isTextNode() && child->needsStyleRecalc()) {
-            resolveTextNode(*toText(child), renderTreePosition);
+        if (is<Text>(child) && child->needsStyleRecalc()) {
+            resolveTextNode(downcast<Text>(*child), renderTreePosition);
             continue;
         }
         if (child->isElementNode())
@@ -939,8 +939,8 @@
         for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
             if (RenderObject* childRenderer = child->renderer())
                 childRenderTreePosition.invalidateNextSibling(*childRenderer);
-            if (child->isTextNode() && child->needsStyleRecalc()) {
-                resolveTextNode(*toText(child), childRenderTreePosition);
+            if (is<Text>(child) && child->needsStyleRecalc()) {
+                resolveTextNode(downcast<Text>(*child), childRenderTreePosition);
                 continue;
             }
             if (!child->isElementNode())

Modified: trunk/Source/WebKit2/ChangeLog (174067 => 174068)


--- trunk/Source/WebKit2/ChangeLog	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebKit2/ChangeLog	2014-09-29 17:20:18 UTC (rev 174068)
@@ -1,5 +1,19 @@
 2014-09-29  Christophe Dumez  <cdu...@apple.com>
 
+        Use the new is<>() / downcast<>() for Text Nodes
+        https://bugs.webkit.org/show_bug.cgi?id=137188
+
+        Reviewed by Darin Adler.
+
+        Use the new is<>() / downcast<>() functions for Text Nodes instead of
+        isText() / toText().
+
+        * WebProcess/InjectedBundle/API/mac/WKDOMText.mm:
+        (-[WKDOMText data]):
+        (-[WKDOMText setData:]):
+
+2014-09-29  Christophe Dumez  <cdu...@apple.com>
+
         Make is<>() / downcast<>() work for HTMLDocument and its subclasses
         https://bugs.webkit.org/show_bug.cgi?id=137169
 

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMText.mm (174067 => 174068)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMText.mm	2014-09-29 17:16:32 UTC (rev 174067)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMText.mm	2014-09-29 17:20:18 UTC (rev 174068)
@@ -35,14 +35,14 @@
 
 - (NSString *)data
 {
-    return WebCore::toText(_impl.get())->data();
+    return WebCore::downcast<WebCore::Text>(*_impl).data();
 }
 
 - (void)setData:(NSString *)data
 {
     // FIXME: Do something about the exception.
     WebCore::ExceptionCode ec;
-    WebCore::toText(_impl.get())->setData(data, ec);
+    WebCore::downcast<WebCore::Text>(*_impl).setData(data, ec);
 }
 
 @end
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to