Use the new is<>() / downcast<>() for Text Nodes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 17:20:18 +0000 (17:20 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 17:20:18 +0000 (17:20 +0000)
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:]):

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

43 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
Source/WebCore/css/SelectorChecker.cpp
Source/WebCore/dom/CharacterData.cpp
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Position.cpp
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Text.cpp
Source/WebCore/dom/Text.h
Source/WebCore/dom/TextNodeTraversal.cpp
Source/WebCore/dom/TextNodeTraversal.h
Source/WebCore/editing/ApplyBlockElementCommand.cpp
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/BreakBlockquoteCommand.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/InsertLineBreakCommand.cpp
Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
Source/WebCore/editing/InsertTextCommand.cpp
Source/WebCore/editing/MarkupAccumulator.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLScriptElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/HTMLTitleElement.cpp
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/rendering/RenderCombineText.h
Source/WebCore/rendering/RenderNamedFlowThread.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/svg/RenderSVGInlineText.h
Source/WebCore/style/StyleResolveTree.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMText.mm

index a68e6a4..72aaa80 100644 (file)
@@ -1,5 +1,141 @@
 2014-09-29  Christophe Dumez  <cdumez@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  <cdumez@apple.com>
+
         Remove remaining uses of NODE_TYPE_CASTS() from html/
         https://bugs.webkit.org/show_bug.cgi?id=137172
 
index cf80b7b..b721d37 100644 (file)
@@ -1640,8 +1640,8 @@ static bool shouldAddSpaceBeforeAppendingNextElement(StringBuilder& builder, Str
 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
index 825dfac..a4643e3 100644 (file)
@@ -90,7 +90,7 @@ WebKitDOMNode* wrap(Node* node)
     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:
index c3c1b39..5387d4f 100644 (file)
@@ -555,14 +555,14 @@ bool SelectorChecker::checkOne(const CheckingContextWithStatus& context) const
         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;
                         }
index c3c9cc4..31a5943 100644 (file)
@@ -87,9 +87,9 @@ unsigned CharacterData::parserAppendData(const String& string, unsigned offset,
     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 @@ void CharacterData::setDataAndUpdate(const String& newData, unsigned offsetOfRep
     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();
index ae855ec..b17b09f 100644 (file)
@@ -102,8 +102,8 @@ static inline void destroyRenderTreeIfNeeded(Node& child)
         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)
index 3ec5bca..9a49e91 100644 (file)
@@ -489,7 +489,7 @@ void Node::normalize()
             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 @@ void Node::normalize()
         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()) {
index 676d1c7..39a4784 100644 (file)
@@ -151,7 +151,7 @@ void Position::moveToOffset(int offset)
 Node* Position::containerNode() const
 {
     if (!m_anchorNode)
-        return 0;
+        return nullptr;
 
     switch (anchorType()) {
     case PositionIsBeforeChildren:
@@ -163,24 +163,24 @@ Node* Position::containerNode() const
         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::isCandidate() const
 
 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 @@ Position Position::leadingWhitespacePosition(EAffinity affinity, bool considerNo
         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))
index 5a6c754..292fa5a 100644 (file)
@@ -978,7 +978,7 @@ void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec)
     // 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 @@ void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec)
     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 @@ void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const
 
                 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;
index 40533c3..c2b3be6 100644 (file)
@@ -94,9 +94,9 @@ static const Text* earliestLogicallyAdjacentTextNode(const Text* text)
 {
     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 @@ static const Text* latestLogicallyAdjacentTextNode(const Text* text)
 {
     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;
 }
index 186ae64..8b848ab 100644 (file)
@@ -74,11 +74,9 @@ private:
 #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.
-
-NODE_TYPE_CASTS(Text)
+SPECIALIZE_TYPE_TRAITS_BEGIN(Text)
+    static bool isText(const Node& node) { return node.isTextNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
 
index 1f30afe..658988a 100644 (file)
@@ -47,8 +47,8 @@ String contentsAsString(const ContainerNode* root)
 
 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();
index f97493e..b84a023 100644 (file)
@@ -66,9 +66,9 @@ template <class NodeType>
 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 @@ template <class NodeType>
 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 @@ template <class NodeType>
 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 @@ template <class NodeType>
 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* next(const Text* current, const Node* stayWithin) { return traverse
 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);
 }
 
 }
index b6938e4..a2cc5c9 100644 (file)
@@ -164,11 +164,11 @@ static bool isNewLineAtPosition(const Position& position)
 {
     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 @@ VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN
     // 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);
     }
index e90249c..a3ef549 100644 (file)
@@ -1201,17 +1201,17 @@ void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position&
 
 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 @@ void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Posit
     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 @@ void ApplyStyleCommand::joinChildTextNodes(Node* node, const Position& start, co
     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.
index 5548705..f61711a 100644 (file)
@@ -106,13 +106,13 @@ void BreakBlockquoteCommand::doApply()
     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);
index 1d8a7fb..5dd4c30 100644 (file)
@@ -376,8 +376,8 @@ void CompositeEditCommand::insertNodeAt(PassRefPtr<Node> insertChild, const Posi
             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 @@ Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos)
     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::shouldRebalanceLeadingWhitespaceFor(const String& tex
 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 @@ void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position)
 
     // 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::rebalanceWhitespaceOnTextSubstring(PassRefPtr<Text> p
 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 @@ void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(Position& positio
     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 @@ void CompositeEditCommand::deleteInsignificantText(const Position& start, const
 
     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 @@ void CompositeEditCommand::removePlaceholderAt(const Position& p)
     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 @@ void CompositeEditCommand::cleanupAfterDeletion(VisiblePosition destination)
         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 @@ void CompositeEditCommand::cleanupAfterDeletion(VisiblePosition destination)
         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 @@ bool CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph()
     
     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);
     }
 
index 3a57931..be376ff 100644 (file)
@@ -464,10 +464,10 @@ void DeleteSelectionCommand::handleGeneralDelete()
             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 @@ void DeleteSelectionCommand::handleGeneralDelete()
 
     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 @@ void DeleteSelectionCommand::handleGeneralDelete()
         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 @@ void DeleteSelectionCommand::handleGeneralDelete()
                 // 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 @@ void DeleteSelectionCommand::fixupWhitespace()
 {
     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 @@ void DeleteSelectionCommand::doApply()
     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)
index 99a1a9f..cd64ae9 100644 (file)
@@ -1865,8 +1865,8 @@ void Editor::setComposition(const String& text, const Vector<CompositionUnderlin
         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;
index 11a0747..4336c5c 100644 (file)
@@ -137,23 +137,23 @@ void InsertLineBreakCommand::doApply()
     } 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);
index 499dad9..2bfc107 100644 (file)
@@ -331,16 +331,16 @@ void InsertParagraphSeparatorCommand::doApply()
     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 @@ void InsertParagraphSeparatorCommand::doApply()
             // 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());
         }
     }
 
index 27e8934..a701f89 100644 (file)
@@ -241,7 +241,7 @@ Position InsertTextCommand::insertTab(const Position& pos)
 
     // 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 @@ Position InsertTextCommand::insertTab(const Position& pos)
     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 {
index e4d9ada..dbe9688 100644 (file)
@@ -553,7 +553,7 @@ void MarkupAccumulator::appendStartMarkup(StringBuilder& result, const Node& nod
 
     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());
index 07f1c50..418d658 100644 (file)
@@ -683,7 +683,7 @@ void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& ins
     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 @@ void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& ins
     // 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 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
 
     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 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
     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 @@ void ReplaceSelectionCommand::addSpacesForSmartReplace()
     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 @@ void ReplaceSelectionCommand::mergeTextNodesAroundPosition(Position& position, P
 {
     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 @@ void ReplaceSelectionCommand::mergeTextNodesAroundPosition(Position& position, P
 
         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 @@ Node* ReplaceSelectionCommand::insertAsListItems(PassRefPtr<HTMLElement> prpList
     // 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 @@ void ReplaceSelectionCommand::updateNodesInserted(Node *node)
 // 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 @@ bool ReplaceSelectionCommand::performTrivialReplace(const ReplacementFragment& f
         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;
 
index 9163b0a..257f4b4 100644 (file)
@@ -501,7 +501,7 @@ static bool hasVisibleTextNode(RenderText& renderer)
 
 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 @@ bool TextIterator::handleTextNode()
 
 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 @@ void SimplifiedBackwardsTextIterator::advance()
 
 bool SimplifiedBackwardsTextIterator::handleTextNode()
 {
-    Text& textNode = toText(*m_node);
+    Text& textNode = downcast<Text>(*m_node);
 
     m_lastTextNode = &textNode;
 
index ed000fa..9100056 100644 (file)
@@ -767,7 +767,7 @@ static VisiblePosition startPositionForLine(const VisiblePosition& c, LineEndpoi
         }
     }
 
-    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 @@ static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint
     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 @@ VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
             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 @@ VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
                     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 @@ VisiblePosition endOfParagraph(const VisiblePosition& c, EditingBoundaryCrossing
 
         // 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 @@ VisiblePosition endOfParagraph(const VisiblePosition& c, EditingBoundaryCrossing
                 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;
index 244da80..d10b11b 100644 (file)
@@ -1055,12 +1055,12 @@ bool lineBreakExistsAtPosition(const Position& position)
     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
index 097e32b..8add90c 100644 (file)
@@ -263,10 +263,10 @@ void StyledMarkupAccumulator::appendText(StringBuilder& out, const Text& text)
     
 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 @@ void replaceChildrenWithFragment(ContainerNode& container, PassRefPtr<DocumentFr
     }
 
     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 @@ void replaceChildrenWithText(ContainerNode& container, const String& text, Excep
     ChildListMutationScope mutation(containerNode.get());
 
     if (hasOneTextChild(&containerNode.get())) {
-        toText(containerNode->firstChild())->setData(text, ec);
+        downcast<Text>(*containerNode->firstChild()).setData(text, ec);
         return;
     }
 
index 43f57a6..bcd267d 100644 (file)
@@ -436,11 +436,11 @@ void HTMLElement::setInnerHTML(const String& html, ExceptionCode& ec)
 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 @@ void HTMLElement::setOuterHTML(const String& html, ExceptionCode& ec)
       
     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 @@ void HTMLElement::setOuterText(const String& text, ExceptionCode& ec)
     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)
index 6040ad8..8da943f 100644 (file)
@@ -231,10 +231,10 @@ bool HTMLObjectElement::hasFallbackContent() const
 {
     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 @@ void HTMLObjectElement::updateDocNamedItem()
             // 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;
index 7e9c9d1..4f75916 100644 (file)
@@ -129,8 +129,8 @@ void HTMLOptionElement::setText(const String &text, ExceptionCode& ec)
 
     // 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);
index 578cd39..1c275c1 100644 (file)
@@ -81,8 +81,8 @@ void HTMLScriptElement::setText(const String &value)
 {
     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;
     }
 
index c041e6e..d459ea7 100644 (file)
@@ -561,10 +561,10 @@ String HTMLTextFormControlElement::innerTextValue() const
 
     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 @@ static Position positionForIndex(TextControlInnerTextElement* innerText, unsigne
                 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 @@ unsigned HTMLTextFormControlElement::indexForPosition(const Position& passedPosi
     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 @@ String HTMLTextFormControlElement::valueWithHardLineBreaks() const
 
     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 = toText(node)->data();
+        else if (is<Text>(node)) {
+            String data = downcast<Text>(*node).data();
             unsigned length = data.length();
             unsigned position = 0;
             while (breakNode == node && breakOffset <= length) {
index 00e67b3..8e81825 100644 (file)
@@ -97,8 +97,8 @@ void HTMLTitleElement::setText(const String &value)
 {
     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,
index 90396ff..a9f0f8d 100644 (file)
@@ -547,11 +547,11 @@ void HTMLConstructionSite::insertTextNode(const String& characters, WhitespaceMo
     // 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()) {
index d6b5da0..bc3744d 100644 (file)
@@ -806,7 +806,7 @@ void InspectorDOMAgent::setNodeValue(ErrorString* errorString, int nodeId, const
         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)
index d76066a..3963b30 100644 (file)
@@ -32,7 +32,7 @@ class RenderCombineText final : public RenderText {
 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;
index 7057cad..6fe8ab9 100644 (file)
@@ -717,7 +717,7 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                     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 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                 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 @@ void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range>>& rangeObjects, const
                         }
                         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;
index 409ad6b..39012f2 100644 (file)
@@ -201,7 +201,7 @@ const char* RenderText::renderName() const
 
 Text* RenderText::textNode() const
 {
-    return toText(RenderObject::node());
+    return downcast<Text>(RenderObject::node());
 }
 
 bool RenderText::isTextFragment() const
index 17d5128..ba0d492 100644 (file)
@@ -35,7 +35,7 @@ class RenderSVGInlineText final : public RenderText {
 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; }
index 0889dfc..8a86a95 100644 (file)
@@ -365,9 +365,9 @@ static void invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node& curren
                 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 @@ static void attachChildren(ContainerNode& current, RenderStyle& inheritedStyle,
             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 @@ static void attachDistributedChildren(InsertionPoint& insertionPoint, RenderStyl
     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 attachRenderTree(Element& current, RenderStyle& inheritedStyle, Rend
 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 @@ static void detachChildren(ContainerNode& current, DetachType detachType)
         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 @@ static void resolveShadowTree(ShadowRoot& shadowRoot, Element& host, Style::Chan
     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 @@ void resolveTree(Element& current, RenderStyle& inheritedStyle, RenderTreePositi
         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())
index ba7e0a6..b719759 100644 (file)
@@ -1,5 +1,19 @@
 2014-09-29  Christophe Dumez  <cdumez@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  <cdumez@apple.com>
+
         Make is<>() / downcast<>() work for HTMLDocument and its subclasses
         https://bugs.webkit.org/show_bug.cgi?id=137169
 
index 504b2be..d91e812 100644 (file)
 
 - (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