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:]):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174068 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index a68e6a4..72aaa80 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -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
diff --git a/Source/WebCore/accessibility/AccessibilityNodeObject.cpp b/Source/WebCore/accessibility/AccessibilityNodeObject.cpp
index cf80b7b..b721d37 100644
--- a/Source/WebCore/accessibility/AccessibilityNodeObject.cpp
+++ b/Source/WebCore/accessibility/AccessibilityNodeObject.cpp
@@ -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
diff --git a/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp b/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
index 825dfac..a4643e3 100644
--- a/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
+++ b/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
@@ -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:
diff --git a/Source/WebCore/css/SelectorChecker.cpp b/Source/WebCore/css/SelectorChecker.cpp
index c3c1b39..5387d4f 100644
--- a/Source/WebCore/css/SelectorChecker.cpp
+++ b/Source/WebCore/css/SelectorChecker.cpp
@@ -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;
}
diff --git a/Source/WebCore/dom/CharacterData.cpp b/Source/WebCore/dom/CharacterData.cpp
index c3c9cc4..31a5943 100644
--- a/Source/WebCore/dom/CharacterData.cpp
+++ b/Source/WebCore/dom/CharacterData.cpp
@@ -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();
diff --git a/Source/WebCore/dom/ContainerNode.cpp b/Source/WebCore/dom/ContainerNode.cpp
index ae855ec..b17b09f 100644
--- a/Source/WebCore/dom/ContainerNode.cpp
+++ b/Source/WebCore/dom/ContainerNode.cpp
@@ -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)
diff --git a/Source/WebCore/dom/Node.cpp b/Source/WebCore/dom/Node.cpp
index 3ec5bca..9a49e91 100644
--- a/Source/WebCore/dom/Node.cpp
+++ b/Source/WebCore/dom/Node.cpp
@@ -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()) {
diff --git a/Source/WebCore/dom/Position.cpp b/Source/WebCore/dom/Position.cpp
index 676d1c7..39a4784 100644
--- a/Source/WebCore/dom/Position.cpp
+++ b/Source/WebCore/dom/Position.cpp
@@ -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))
diff --git a/Source/WebCore/dom/Range.cpp b/Source/WebCore/dom/Range.cpp
index 5a6c754..292fa5a 100644
--- a/Source/WebCore/dom/Range.cpp
+++ b/Source/WebCore/dom/Range.cpp
@@ -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;
diff --git a/Source/WebCore/dom/Text.cpp b/Source/WebCore/dom/Text.cpp
index 40533c3..c2b3be6 100644
--- a/Source/WebCore/dom/Text.cpp
+++ b/Source/WebCore/dom/Text.cpp
@@ -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;
}
diff --git a/Source/WebCore/dom/Text.h b/Source/WebCore/dom/Text.h
index 186ae64..8b848ab 100644
--- a/Source/WebCore/dom/Text.h
+++ b/Source/WebCore/dom/Text.h
@@ -74,11 +74,9 @@
#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
diff --git a/Source/WebCore/dom/TextNodeTraversal.cpp b/Source/WebCore/dom/TextNodeTraversal.cpp
index 1f30afe..658988a4 100644
--- a/Source/WebCore/dom/TextNodeTraversal.cpp
+++ b/Source/WebCore/dom/TextNodeTraversal.cpp
@@ -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();
diff --git a/Source/WebCore/dom/TextNodeTraversal.h b/Source/WebCore/dom/TextNodeTraversal.h
index f97493e..b84a023 100644
--- a/Source/WebCore/dom/TextNodeTraversal.h
+++ b/Source/WebCore/dom/TextNodeTraversal.h
@@ -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);
}
}
diff --git a/Source/WebCore/editing/ApplyBlockElementCommand.cpp b/Source/WebCore/editing/ApplyBlockElementCommand.cpp
index b6938e4..a2cc5c9 100644
--- a/Source/WebCore/editing/ApplyBlockElementCommand.cpp
+++ b/Source/WebCore/editing/ApplyBlockElementCommand.cpp
@@ -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);
}
diff --git a/Source/WebCore/editing/ApplyStyleCommand.cpp b/Source/WebCore/editing/ApplyStyleCommand.cpp
index e90249c..a3ef549 100644
--- a/Source/WebCore/editing/ApplyStyleCommand.cpp
+++ b/Source/WebCore/editing/ApplyStyleCommand.cpp
@@ -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.
diff --git a/Source/WebCore/editing/BreakBlockquoteCommand.cpp b/Source/WebCore/editing/BreakBlockquoteCommand.cpp
index 5548705..f61711a 100644
--- a/Source/WebCore/editing/BreakBlockquoteCommand.cpp
+++ b/Source/WebCore/editing/BreakBlockquoteCommand.cpp
@@ -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);
diff --git a/Source/WebCore/editing/CompositeEditCommand.cpp b/Source/WebCore/editing/CompositeEditCommand.cpp
index 1d8a7fb..5dd4c30 100644
--- a/Source/WebCore/editing/CompositeEditCommand.cpp
+++ b/Source/WebCore/editing/CompositeEditCommand.cpp
@@ -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);
}
diff --git a/Source/WebCore/editing/DeleteSelectionCommand.cpp b/Source/WebCore/editing/DeleteSelectionCommand.cpp
index 3a57931..be376ff 100644
--- a/Source/WebCore/editing/DeleteSelectionCommand.cpp
+++ b/Source/WebCore/editing/DeleteSelectionCommand.cpp
@@ -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)
diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp
index 99a1a9f..cd64ae9 100644
--- a/Source/WebCore/editing/Editor.cpp
+++ b/Source/WebCore/editing/Editor.cpp
@@ -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;
diff --git a/Source/WebCore/editing/InsertLineBreakCommand.cpp b/Source/WebCore/editing/InsertLineBreakCommand.cpp
index 11a0747..4336c5c 100644
--- a/Source/WebCore/editing/InsertLineBreakCommand.cpp
+++ b/Source/WebCore/editing/InsertLineBreakCommand.cpp
@@ -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);
diff --git a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
index 499dad9..2bfc107 100644
--- a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
+++ b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
@@ -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());
}
}
diff --git a/Source/WebCore/editing/InsertTextCommand.cpp b/Source/WebCore/editing/InsertTextCommand.cpp
index 27e8934..a701f89 100644
--- a/Source/WebCore/editing/InsertTextCommand.cpp
+++ b/Source/WebCore/editing/InsertTextCommand.cpp
@@ -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 {
diff --git a/Source/WebCore/editing/MarkupAccumulator.cpp b/Source/WebCore/editing/MarkupAccumulator.cpp
index e4d9ada..dbe9688 100644
--- a/Source/WebCore/editing/MarkupAccumulator.cpp
+++ b/Source/WebCore/editing/MarkupAccumulator.cpp
@@ -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());
diff --git a/Source/WebCore/editing/ReplaceSelectionCommand.cpp b/Source/WebCore/editing/ReplaceSelectionCommand.cpp
index 07f1c50..418d658 100644
--- a/Source/WebCore/editing/ReplaceSelectionCommand.cpp
+++ b/Source/WebCore/editing/ReplaceSelectionCommand.cpp
@@ -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;
diff --git a/Source/WebCore/editing/TextIterator.cpp b/Source/WebCore/editing/TextIterator.cpp
index 9163b0a..257f4b4 100644
--- a/Source/WebCore/editing/TextIterator.cpp
+++ b/Source/WebCore/editing/TextIterator.cpp
@@ -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;
diff --git a/Source/WebCore/editing/VisibleUnits.cpp b/Source/WebCore/editing/VisibleUnits.cpp
index ed000fa..9100056 100644
--- a/Source/WebCore/editing/VisibleUnits.cpp
+++ b/Source/WebCore/editing/VisibleUnits.cpp
@@ -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;
diff --git a/Source/WebCore/editing/htmlediting.cpp b/Source/WebCore/editing/htmlediting.cpp
index 244da80..d10b11b 100644
--- a/Source/WebCore/editing/htmlediting.cpp
+++ b/Source/WebCore/editing/htmlediting.cpp
@@ -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
diff --git a/Source/WebCore/editing/markup.cpp b/Source/WebCore/editing/markup.cpp
index 097e32b..8add90c 100644
--- a/Source/WebCore/editing/markup.cpp
+++ b/Source/WebCore/editing/markup.cpp
@@ -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;
}
diff --git a/Source/WebCore/html/HTMLElement.cpp b/Source/WebCore/html/HTMLElement.cpp
index 43f57a6..bcd267d 100644
--- a/Source/WebCore/html/HTMLElement.cpp
+++ b/Source/WebCore/html/HTMLElement.cpp
@@ -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)
diff --git a/Source/WebCore/html/HTMLObjectElement.cpp b/Source/WebCore/html/HTMLObjectElement.cpp
index 6040ad8..8da943f 100644
--- a/Source/WebCore/html/HTMLObjectElement.cpp
+++ b/Source/WebCore/html/HTMLObjectElement.cpp
@@ -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;
diff --git a/Source/WebCore/html/HTMLOptionElement.cpp b/Source/WebCore/html/HTMLOptionElement.cpp
index 7e9c9d1..4f75916 100644
--- a/Source/WebCore/html/HTMLOptionElement.cpp
+++ b/Source/WebCore/html/HTMLOptionElement.cpp
@@ -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);
diff --git a/Source/WebCore/html/HTMLScriptElement.cpp b/Source/WebCore/html/HTMLScriptElement.cpp
index 578cd39..1c275c1 100644
--- a/Source/WebCore/html/HTMLScriptElement.cpp
+++ b/Source/WebCore/html/HTMLScriptElement.cpp
@@ -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;
}
diff --git a/Source/WebCore/html/HTMLTextFormControlElement.cpp b/Source/WebCore/html/HTMLTextFormControlElement.cpp
index c041e6e..d459ea7 100644
--- a/Source/WebCore/html/HTMLTextFormControlElement.cpp
+++ b/Source/WebCore/html/HTMLTextFormControlElement.cpp
@@ -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 = 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) {
diff --git a/Source/WebCore/html/HTMLTitleElement.cpp b/Source/WebCore/html/HTMLTitleElement.cpp
index 00e67b3..8e81825 100644
--- a/Source/WebCore/html/HTMLTitleElement.cpp
+++ b/Source/WebCore/html/HTMLTitleElement.cpp
@@ -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,
diff --git a/Source/WebCore/html/parser/HTMLConstructionSite.cpp b/Source/WebCore/html/parser/HTMLConstructionSite.cpp
index 90396ff..a9f0f8d 100644
--- a/Source/WebCore/html/parser/HTMLConstructionSite.cpp
+++ b/Source/WebCore/html/parser/HTMLConstructionSite.cpp
@@ -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()) {
diff --git a/Source/WebCore/inspector/InspectorDOMAgent.cpp b/Source/WebCore/inspector/InspectorDOMAgent.cpp
index d6b5da0..bc3744d 100644
--- a/Source/WebCore/inspector/InspectorDOMAgent.cpp
+++ b/Source/WebCore/inspector/InspectorDOMAgent.cpp
@@ -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)
diff --git a/Source/WebCore/rendering/RenderCombineText.h b/Source/WebCore/rendering/RenderCombineText.h
index d76066a..3963b30 100644
--- a/Source/WebCore/rendering/RenderCombineText.h
+++ b/Source/WebCore/rendering/RenderCombineText.h
@@ -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;
diff --git a/Source/WebCore/rendering/RenderNamedFlowThread.cpp b/Source/WebCore/rendering/RenderNamedFlowThread.cpp
index 7057cad..6fe8ab9 100644
--- a/Source/WebCore/rendering/RenderNamedFlowThread.cpp
+++ b/Source/WebCore/rendering/RenderNamedFlowThread.cpp
@@ -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;
diff --git a/Source/WebCore/rendering/RenderText.cpp b/Source/WebCore/rendering/RenderText.cpp
index 409ad6b..39012f2 100644
--- a/Source/WebCore/rendering/RenderText.cpp
+++ b/Source/WebCore/rendering/RenderText.cpp
@@ -201,7 +201,7 @@
Text* RenderText::textNode() const
{
- return toText(RenderObject::node());
+ return downcast<Text>(RenderObject::node());
}
bool RenderText::isTextFragment() const
diff --git a/Source/WebCore/rendering/svg/RenderSVGInlineText.h b/Source/WebCore/rendering/svg/RenderSVGInlineText.h
index 17d5128..ba0d492 100644
--- a/Source/WebCore/rendering/svg/RenderSVGInlineText.h
+++ b/Source/WebCore/rendering/svg/RenderSVGInlineText.h
@@ -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; }
diff --git a/Source/WebCore/style/StyleResolveTree.cpp b/Source/WebCore/style/StyleResolveTree.cpp
index 0889dfc..8a86a95 100644
--- a/Source/WebCore/style/StyleResolveTree.cpp
+++ b/Source/WebCore/style/StyleResolveTree.cpp
@@ -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())