Changeset 107509 in webkit


Ignore:
Timestamp:
Feb 12, 2012 3:27:56 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add toText and isTextNode helpers in Text class.
https://bugs.webkit.org/show_bug.cgi?id=78140

Source/WebCore:

Added a new helper function toText() in dom/Text.h which does the type casting operation to Text object.
Modified the code to make use of this helper function.

Patch by Joe Thomas <joethomas@motorola.com> on 2012-02-12
Reviewed by Adam Barth.

No new tests.

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::accessibleNameForNode):

  • bindings/v8/custom/V8NodeCustom.cpp:

(WebCore::toV8Slow):

  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::checkOneSelector):

  • dom/Attr.cpp:

(WebCore::Attr::childrenChanged):

  • dom/Element.cpp:

(WebCore::Element::recalcStyle):

  • dom/Node.cpp:

(WebCore::Node::normalize):

  • dom/Position.cpp:

(WebCore::Position::containerText):
(WebCore::Position::leadingWhitespacePosition):

  • dom/Range.cpp:

(WebCore::Range::insertNode):
(WebCore::Range::getBorderAndTextQuads):

  • dom/ScriptElement.cpp:

(WebCore::ScriptElement::scriptContent):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::recalcShadowTreeStyle):

  • dom/Text.h: Added new helper function toText.

(WebCore::toText): new helper function which does the type casting operation to Text object.
(WebCore):

  • 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::breakOutOfEmptyMailBlockquotedParagraph):

  • editing/DeleteSelectionCommand.cpp:

(WebCore::DeleteSelectionCommand::handleGeneralDelete):
(WebCore::DeleteSelectionCommand::fixupWhitespace):

  • 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::insertAsListItems):
(WebCore::ReplaceSelectionCommand::performTrivialReplace):

  • editing/htmlediting.cpp:

(WebCore::lineBreakExistsAtPosition):

  • editing/visible_units.cpp:

(WebCore::startPositionForLine):
(WebCore::endPositionForLine):
(WebCore::startOfParagraph):
(WebCore::endOfParagraph):

  • html/HTMLElement.cpp:

(WebCore::replaceChildrenWithFragment):
(WebCore::replaceChildrenWithText):
(WebCore::mergeWithNextTextNode):

  • html/HTMLObjectElement.cpp:

(WebCore::HTMLObjectElement::hasFallbackContent):
(WebCore::HTMLObjectElement::updateDocNamedItem):

  • html/HTMLOptionElement.cpp:

(WebCore::HTMLOptionElement::setText):

  • html/HTMLScriptElement.cpp:

(WebCore::HTMLScriptElement::setText):

  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::defaultValue):

  • html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::innerTextValue):
(WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks):

  • html/HTMLTitleElement.cpp:

(WebCore::HTMLTitleElement::text):
(WebCore::HTMLTitleElement::setText):

  • inspector/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::setNodeValue):

  • rendering/RenderText.cpp:

(WebCore::RenderText::originalText):

  • rendering/RenderTextFragment.cpp:

(WebCore::RenderTextFragment::originalText):
(WebCore::RenderTextFragment::previousCharacter):

Tools:

Added a style checker to use toText rather than static_cast<Text*>.

Patch by Joe Thomas <joethomas@motorola.com> on 2012-02-12
Reviewed by Adam Barth.

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_language): Style checker for static_cast<Text*>.

Location:
trunk
Files:
37 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107508 r107509  
     12012-02-12  Joe Thomas  <joethomas@motorola.com>
     2
     3        Add toText and isTextNode helpers in Text class.
     4        https://bugs.webkit.org/show_bug.cgi?id=78140
     5
     6        Added a new helper function toText() in dom/Text.h which does the type casting operation to Text object.
     7        Modified the code to make use of this helper function.
     8
     9        Reviewed by Adam Barth.
     10
     11        No new tests.
     12
     13        * accessibility/AccessibilityRenderObject.cpp:
     14        (WebCore::accessibleNameForNode):
     15        * bindings/v8/custom/V8NodeCustom.cpp:
     16        (WebCore::toV8Slow):
     17        * css/SelectorChecker.cpp:
     18        (WebCore::SelectorChecker::checkOneSelector):
     19        * dom/Attr.cpp:
     20        (WebCore::Attr::childrenChanged):
     21        * dom/Element.cpp:
     22        (WebCore::Element::recalcStyle):
     23        * dom/Node.cpp:
     24        (WebCore::Node::normalize):
     25        * dom/Position.cpp:
     26        (WebCore::Position::containerText):
     27        (WebCore::Position::leadingWhitespacePosition):
     28        * dom/Range.cpp:
     29        (WebCore::Range::insertNode):
     30        (WebCore::Range::getBorderAndTextQuads):
     31        * dom/ScriptElement.cpp:
     32        (WebCore::ScriptElement::scriptContent):
     33        * dom/ShadowRoot.cpp:
     34        (WebCore::ShadowRoot::recalcShadowTreeStyle):
     35        * dom/Text.h: Added new helper function toText.
     36        (WebCore::toText): new helper function which does the type casting operation to Text object.
     37        (WebCore):
     38        * editing/ApplyBlockElementCommand.cpp:
     39        (WebCore::isNewLineAtPosition):
     40        (WebCore::ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfNeeded):
     41        * editing/ApplyStyleCommand.cpp:
     42        (WebCore::ApplyStyleCommand::splitTextAtEnd):
     43        (WebCore::ApplyStyleCommand::splitTextElementAtEnd):
     44        (WebCore::ApplyStyleCommand::joinChildTextNodes):
     45        * editing/BreakBlockquoteCommand.cpp:
     46        (WebCore::BreakBlockquoteCommand::doApply):
     47        * editing/CompositeEditCommand.cpp:
     48        (WebCore::CompositeEditCommand::insertNodeAt):
     49        (WebCore::CompositeEditCommand::positionOutsideTabSpan):
     50        (WebCore::CompositeEditCommand::canRebalance):
     51        (WebCore::CompositeEditCommand::rebalanceWhitespaceAt):
     52        (WebCore::CompositeEditCommand::prepareWhitespaceAtPositionForSplit):
     53        (WebCore::CompositeEditCommand::deleteInsignificantText):
     54        (WebCore::CompositeEditCommand::removePlaceholderAt):
     55        (WebCore::CompositeEditCommand::cleanupAfterDeletion):
     56        (WebCore::CompositeEditCommand::breakOutOfEmptyMailBlockquotedParagraph):
     57        * editing/DeleteSelectionCommand.cpp:
     58        (WebCore::DeleteSelectionCommand::handleGeneralDelete):
     59        (WebCore::DeleteSelectionCommand::fixupWhitespace):
     60        * editing/Editor.cpp:
     61        (WebCore::Editor::setComposition):
     62        * editing/InsertLineBreakCommand.cpp:
     63        (WebCore::InsertLineBreakCommand::doApply):
     64        * editing/InsertParagraphSeparatorCommand.cpp:
     65        (WebCore::InsertParagraphSeparatorCommand::doApply):
     66        * editing/InsertTextCommand.cpp:
     67        (WebCore::InsertTextCommand::insertTab):
     68        * editing/MarkupAccumulator.cpp:
     69        (WebCore::MarkupAccumulator::appendStartMarkup):
     70        * editing/ReplaceSelectionCommand.cpp:
     71        (WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds):
     72        (WebCore::ReplaceSelectionCommand::addSpacesForSmartReplace):
     73        (WebCore::ReplaceSelectionCommand::insertAsListItems):
     74        (WebCore::ReplaceSelectionCommand::performTrivialReplace):
     75        * editing/htmlediting.cpp:
     76        (WebCore::lineBreakExistsAtPosition):
     77        * editing/visible_units.cpp:
     78        (WebCore::startPositionForLine):
     79        (WebCore::endPositionForLine):
     80        (WebCore::startOfParagraph):
     81        (WebCore::endOfParagraph):
     82        * html/HTMLElement.cpp:
     83        (WebCore::replaceChildrenWithFragment):
     84        (WebCore::replaceChildrenWithText):
     85        (WebCore::mergeWithNextTextNode):
     86        * html/HTMLObjectElement.cpp:
     87        (WebCore::HTMLObjectElement::hasFallbackContent):
     88        (WebCore::HTMLObjectElement::updateDocNamedItem):
     89        * html/HTMLOptionElement.cpp:
     90        (WebCore::HTMLOptionElement::setText):
     91        * html/HTMLScriptElement.cpp:
     92        (WebCore::HTMLScriptElement::setText):
     93        * html/HTMLTextAreaElement.cpp:
     94        (WebCore::HTMLTextAreaElement::defaultValue):
     95        * html/HTMLTextFormControlElement.cpp:
     96        (WebCore::HTMLTextFormControlElement::innerTextValue):
     97        (WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks):
     98        * html/HTMLTitleElement.cpp:
     99        (WebCore::HTMLTitleElement::text):
     100        (WebCore::HTMLTitleElement::setText):
     101        * inspector/InspectorDOMAgent.cpp:
     102        (WebCore::InspectorDOMAgent::setNodeValue):
     103        * rendering/RenderText.cpp:
     104        (WebCore::RenderText::originalText):
     105        * rendering/RenderTextFragment.cpp:
     106        (WebCore::RenderTextFragment::originalText):
     107        (WebCore::RenderTextFragment::previousCharacter):
     108
    11092012-02-12  Kentaro Hara  <haraken@chromium.org>
    2110
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r107477 r107509  
    12131213{
    12141214    if (node->isTextNode())
    1215         return static_cast<Text*>(node)->data();
     1215        return toText(node)->data();
    12161216
    12171217    if (node->hasTagName(inputTag))
  • trunk/Source/WebCore/bindings/v8/custom/V8NodeCustom.cpp

    r107367 r107509  
    148148        return toV8(static_cast<Attr*>(impl), forceNewObject);
    149149    case Node::TEXT_NODE:
    150         return toV8(static_cast<Text*>(impl), forceNewObject);
     150        return toV8(toText(impl), forceNewObject);
    151151    case Node::CDATA_SECTION_NODE:
    152152        return toV8(static_cast<CDATASection*>(impl), forceNewObject);
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r107212 r107509  
    772772                    }
    773773                    if (n->isTextNode()) {
    774                         Text* textNode = static_cast<Text*>(n);
     774                        Text* textNode = toText(n);
    775775                        if (!textNode->data().isEmpty()) {
    776776                            result = false;
  • trunk/Source/WebCore/dom/Attr.cpp

    r104674 r107509  
    182182    for (Node *n = firstChild(); n; n = n->nextSibling()) {
    183183        if (n->isTextNode())
    184             valueBuilder.append(static_cast<Text*>(n)->data());
     184            valueBuilder.append(toText(n)->data());
    185185    }
    186186
  • trunk/Source/WebCore/dom/Element.cpp

    r107202 r107509  
    11221122    for (Node *n = firstChild(); n; n = n->nextSibling()) {
    11231123        if (n->isTextNode()) {
    1124             static_cast<Text*>(n)->recalcTextStyle(change);
     1124            toText(n)->recalcTextStyle(change);
    11251125            continue;
    11261126        }
  • trunk/Source/WebCore/dom/Node.cpp

    r107479 r107509  
    633633        }
    634634
    635         RefPtr<Text> text = static_cast<Text*>(node.get());
     635        RefPtr<Text> text = toText(node.get());
    636636
    637637        // Remove empty text nodes.
     
    648648            if (nextSibling->nodeType() != TEXT_NODE)
    649649                break;
    650             RefPtr<Text> nextText = static_cast<Text*>(nextSibling);
     650            RefPtr<Text> nextText = toText(nextSibling);
    651651
    652652            // Remove empty text nodes.
  • trunk/Source/WebCore/dom/Position.cpp

    r107407 r107509  
    154154    switch (anchorType()) {
    155155    case PositionIsOffsetInAnchor:
    156         return m_anchorNode && m_anchorNode->isTextNode() ? static_cast<Text*>(m_anchorNode.get()) : 0;
     156        return m_anchorNode && m_anchorNode->isTextNode() ? toText(m_anchorNode.get()) : 0;
    157157    case PositionIsBeforeAnchor:
    158158    case PositionIsAfterAnchor:
     
    10191019    Position prev = previousCharacterPosition(affinity);
    10201020    if (prev != *this && prev.deprecatedNode()->inSameContainingBlockFlowElement(deprecatedNode()) && prev.deprecatedNode()->isTextNode()) {
    1021         String string = static_cast<Text *>(prev.deprecatedNode())->data();
     1021        String string = toText(prev.deprecatedNode())->data();
    10221022        UChar c = string[prev.deprecatedEditingOffset()];
    10231023        if (considerNonCollapsibleWhitespace ? (isSpaceOrNewline(c) || c == noBreakSpace) : isCollapsibleWhitespace(c))
  • trunk/Source/WebCore/dom/Range.cpp

    r107461 r107509  
    10381038    bool collapsed = m_start == m_end;
    10391039    if (startIsText) {
    1040         RefPtr<Text> newText = static_cast<Text*>(m_start.container())->splitText(m_start.offset(), ec);
     1040        RefPtr<Text> newText = toText(m_start.container())->splitText(m_start.offset(), ec);
    10411041        if (ec)
    10421042            return;
     
    20412041            }
    20422042        } else if (node->isTextNode()) {
    2043             if (RenderObject* renderer = static_cast<Text*>(node)->renderer()) {
     2043            if (RenderObject* renderer = toText(node)->renderer()) {
    20442044                RenderText* renderText = toRenderText(renderer);
    20452045                int startOffset = (node == startContainer) ? m_start.offset() : 0;
  • trunk/Source/WebCore/dom/ScriptElement.cpp

    r106043 r107509  
    356356            continue;
    357357
    358         Text* t = static_cast<Text*>(n);
     358        Text* t = toText(n);
    359359        if (foundMultipleTextNodes)
    360360            content.append(t->data());
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r107202 r107509  
    156156                static_cast<Element*>(n)->recalcStyle(change);
    157157            else if (n->isTextNode())
    158                 static_cast<Text*>(n)->recalcTextStyle(change);
     158                toText(n)->recalcTextStyle(change);
    159159        }
    160160    }
  • trunk/Source/WebCore/dom/Text.h

    r94561 r107509  
    7171};
    7272
     73inline Text* toText(Node* node)
     74{
     75    ASSERT(!node || node->isTextNode());
     76    return static_cast<Text*>(node);
     77}
     78
    7379} // namespace WebCore
    7480
  • trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp

    r102833 r107509  
    163163
    164164    ExceptionCode ec = 0;
    165     String textAtPosition = static_cast<Text*>(textNode)->substringData(offset, 1, ec);
     165    String textAtPosition = toText(textNode)->substringData(offset, 1, ec);
    166166    if (ec)
    167167        return false;
     
    258258    if (text == start.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) {
    259259        ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode());
    260         start = Position(static_cast<Text*>(text->previousSibling()), start.offsetInContainerNode());
     260        start = Position(toText(text->previousSibling()), start.offsetInContainerNode());
    261261    }
    262262    if (text == end.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) {
    263263        ASSERT(end.offsetInContainerNode() < position.offsetInContainerNode());
    264         end = Position(static_cast<Text*>(text->previousSibling()), end.offsetInContainerNode());
     264        end = Position(toText(text->previousSibling()), end.offsetInContainerNode());
    265265    }
    266266    if (text == m_endOfLastParagraph.containerNode()) {
     
    268268            // We can only fix endOfLastParagraph if the previous node was still text and hasn't been modified by script.
    269269            if (text->previousSibling()->isTextNode()
    270                 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= static_cast<Text*>(text->previousSibling())->length())
    271                 m_endOfLastParagraph = Position(static_cast<Text*>(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
     270                && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= toText(text->previousSibling())->length())
     271                m_endOfLastParagraph = Position(toText(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
    272272        } else
    273273            m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.offsetInContainerNode() - 1);
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r107407 r107509  
    11241124
    11251125    bool shouldUpdateStart = start.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode();
    1126     Text* text = static_cast<Text *>(end.deprecatedNode());
     1126    Text* text = toText(end.deprecatedNode());
    11271127    splitTextNode(text, end.offsetInContainerNode());
    11281128
     
    11311131        return;
    11321132
    1133     Position newStart = shouldUpdateStart ? Position(static_cast<Text*>(prevNode), start.offsetInContainerNode()) : start;
     1133    Position newStart = shouldUpdateStart ? Position(toText(prevNode), start.offsetInContainerNode()) : start;
    11341134    updateStartEnd(newStart, lastPositionInNode(prevNode));
    11351135}
     
    11631163        return;
    11641164
    1165     Position newStart = shouldUpdateStart ? Position(static_cast<Text*>(firstTextNode), start.offsetInContainerNode()) : start;
     1165    Position newStart = shouldUpdateStart ? Position(toText(firstTextNode), start.offsetInContainerNode()) : start;
    11661166    updateStartEnd(newStart, positionAfterNode(firstTextNode));
    11671167}
     
    14341434        Node* next = child->nextSibling();
    14351435        if (child->isTextNode() && next && next->isTextNode()) {
    1436             Text* childText = static_cast<Text *>(child);
    1437             Text* nextText = static_cast<Text *>(next);
     1436            Text* childText = toText(child);
     1437            Text* nextText = toText(next);
    14381438            if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode())
    14391439                newStart = Position(childText, childText->length() + start.offsetInContainerNode());
  • trunk/Source/WebCore/editing/BreakBlockquoteCommand.cpp

    r93134 r107509  
    108108    // Split at pos if in the middle of a text node.
    109109    if (startNode->isTextNode()) {
    110         Text* textNode = static_cast<Text*>(startNode);
     110        Text* textNode = toText(startNode);
    111111        if ((unsigned)pos.deprecatedEditingOffset() >= textNode->length()) {
    112112            startNode = startNode->traverseNextNode();
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r106515 r107509  
    357357        insertNodeBefore(insertChild, refChild);
    358358    else if (refChild->isTextNode() && caretMaxOffset(refChild) > offset) {
    359         splitTextNode(static_cast<Text *>(refChild), offset);
     359        splitTextNode(toText(refChild), offset);
    360360
    361361        // Mutation events (bug 22634) from the text node insertion may have removed the refChild
     
    533533        return positionInParentAfterNode(tabSpan);
    534534
    535     splitTextNodeContainingElement(static_cast<Text *>(pos.containerNode()), pos.offsetInContainerNode());
     535    splitTextNodeContainingElement(toText(pos.containerNode()), pos.offsetInContainerNode());
    536536    return positionInParentBeforeNode(tabSpan);
    537537}
     
    591591        return false;
    592592
    593     Text* textNode = static_cast<Text*>(node);
     593    Text* textNode = toText(node);
    594594    if (textNode->length() == 0)
    595595        return false;
     
    611611    // If the rebalance is for the single offset, and neither text[offset] nor text[offset - 1] are some form of whitespace, do nothing.
    612612    int offset = position.deprecatedEditingOffset();
    613     String text = static_cast<Text*>(node)->data();
     613    String text = toText(node)->data();
    614614    if (!isWhitespace(text[offset])) {
    615615        offset--;
     
    618618    }
    619619
    620     rebalanceWhitespaceOnTextSubstring(static_cast<Text*>(node), position.offsetInContainerNode(), position.offsetInContainerNode());
     620    rebalanceWhitespaceOnTextSubstring(toText(node), position.offsetInContainerNode(), position.offsetInContainerNode());
    621621}
    622622
     
    660660    if (!node || !node->isTextNode())
    661661        return;
    662     Text* textNode = static_cast<Text*>(node);   
     662    Text* textNode = toText(node);   
    663663   
    664664    if (textNode->length() == 0)
     
    678678   
    679679    if (isCollapsibleWhitespace(previousVisiblePos.characterAfter()) && previous.deprecatedNode()->isTextNode() && !previous.deprecatedNode()->hasTagName(brTag))
    680         replaceTextInNodePreservingMarkers(static_cast<Text*>(previous.deprecatedNode()), previous.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
     680        replaceTextInNodePreservingMarkers(toText(previous.deprecatedNode()), previous.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
    681681    if (isCollapsibleWhitespace(visiblePos.characterAfter()) && position.deprecatedNode()->isTextNode() && !position.deprecatedNode()->hasTagName(brTag))
    682         replaceTextInNodePreservingMarkers(static_cast<Text*>(position.deprecatedNode()), position.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
     682        replaceTextInNodePreservingMarkers(toText(position.deprecatedNode()), position.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
    683683}
    684684
     
    785785        next = node->traverseNextNode();
    786786        if (node->isTextNode()) {
    787             Text* textNode = static_cast<Text*>(node);
     787            Text* textNode = toText(node);
    788788            int startOffset = node == start.deprecatedNode() ? start.deprecatedEditingOffset() : 0;
    789789            int endOffset = node == end.deprecatedNode() ? end.deprecatedEditingOffset() : static_cast<int>(textNode->length());
     
    858858    }
    859859   
    860     deleteTextFromNode(static_cast<Text*>(p.anchorNode()), p.offsetInContainerNode(), 1);
     860    deleteTextFromNode(toText(p.anchorNode()), p.offsetInContainerNode(), 1);
    861861}
    862862
     
    10341034            // There is a preserved '\n' at caretAfterDelete.
    10351035            // We can safely assume this is a text node.
    1036             Text* textNode = static_cast<Text*>(node);
     1036            Text* textNode = toText(node);
    10371037            if (textNode->length() == 1)
    10381038                removeNodeAndPruneAncestors(node);
     
    13271327    else if (caretPos.deprecatedNode()->isTextNode()) {
    13281328        ASSERT(caretPos.deprecatedEditingOffset() == 0);
    1329         Text* textNode = static_cast<Text*>(caretPos.deprecatedNode());
     1329        Text* textNode = toText(caretPos.deprecatedNode());
    13301330        ContainerNode* parentNode = textNode->parentNode();
    13311331        // The preserved newline must be the first thing in the node, since otherwise the previous
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp

    r106380 r107509  
    424424
    425425    if (startOffset >= caretMaxOffset(startNode) && startNode->isTextNode()) {
    426         Text *text = static_cast<Text *>(startNode);
     426        Text* text = toText(startNode);
    427427        if (text->length() > (unsigned)caretMaxOffset(startNode))
    428428            deleteTextFromNode(text, caretMaxOffset(startNode), text->length() - caretMaxOffset(startNode));
     
    442442            if (startNode->isTextNode()) {
    443443                // in a text node that needs to be trimmed
    444                 Text* text = static_cast<Text*>(startNode);
     444                Text* text = toText(startNode);
    445445                deleteTextFromNode(text, startOffset, m_downstreamEnd.deprecatedEditingOffset() - startOffset);
    446446            } else {
     
    462462            if (startNode->isTextNode()) {
    463463                // in a text node that needs to be trimmed
    464                 Text *text = static_cast<Text *>(node.get());
     464                Text* text = toText(node.get());
    465465                deleteTextFromNode(text, startOffset, text->length() - startOffset);
    466466                node = node->traverseNextNode();
     
    469469            }
    470470        } else if (startNode == m_upstreamEnd.deprecatedNode() && startNode->isTextNode()) {
    471             Text* text = static_cast<Text*>(m_upstreamEnd.deprecatedNode());
     471            Text* text = toText(m_upstreamEnd.deprecatedNode());
    472472            deleteTextFromNode(text, 0, m_upstreamEnd.deprecatedEditingOffset());
    473473        }
     
    502502                if (m_downstreamEnd.deprecatedNode()->isTextNode()) {
    503503                    // in a text node that needs to be trimmed
    504                     Text* text = static_cast<Text*>(m_downstreamEnd.deprecatedNode());
     504                    Text* text = toText(m_downstreamEnd.deprecatedNode());
    505505                    if (m_downstreamEnd.deprecatedEditingOffset() > 0) {
    506506                        deleteTextFromNode(text, 0, m_downstreamEnd.deprecatedEditingOffset());
     
    534534    // FIXME: isRenderedCharacter should be removed, and we should use VisiblePosition::characterAfter and VisiblePosition::characterBefore
    535535    if (m_leadingWhitespace.isNotNull() && !m_leadingWhitespace.isRenderedCharacter() && m_leadingWhitespace.deprecatedNode()->isTextNode()) {
    536         Text* textNode = static_cast<Text*>(m_leadingWhitespace.deprecatedNode());
     536        Text* textNode = toText(m_leadingWhitespace.deprecatedNode());
    537537        ASSERT(!textNode->renderer() || textNode->renderer()->style()->collapseWhiteSpace());
    538538        replaceTextInNodePreservingMarkers(textNode, m_leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
    539539    }
    540540    if (m_trailingWhitespace.isNotNull() && !m_trailingWhitespace.isRenderedCharacter() && m_trailingWhitespace.deprecatedNode()->isTextNode()) {
    541         Text* textNode = static_cast<Text*>(m_trailingWhitespace.deprecatedNode());
     541        Text* textNode = toText(m_trailingWhitespace.deprecatedNode());
    542542        ASSERT(!textNode->renderer() ||textNode->renderer()->style()->collapseWhiteSpace());
    543543        replaceTextInNodePreservingMarkers(textNode, m_trailingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
  • trunk/Source/WebCore/editing/Editor.cpp

    r107407 r107509  
    15031503
    15041504        if (baseNode && baseNode == extentNode && baseNode->isTextNode() && baseOffset + text.length() == extentOffset) {
    1505             m_compositionNode = static_cast<Text*>(baseNode);
     1505            m_compositionNode = toText(baseNode);
    15061506            m_compositionStart = baseOffset;
    15071507            m_compositionEnd = extentOffset;
  • trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp

    r102833 r107509  
    138138    } else if (pos.deprecatedNode()->isTextNode()) {
    139139        // Split a text node
    140         Text* textNode = static_cast<Text*>(pos.deprecatedNode());
     140        Text* textNode = toText(pos.deprecatedNode());
    141141        splitTextNode(textNode, pos.deprecatedEditingOffset());
    142142        insertNodeBefore(nodeToInsert, textNode);
  • trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp

    r106833 r107509  
    323323    // after the preserved newline, causing the newline to be turned into a nbsp.
    324324    if (leadingWhitespace.isNotNull() && leadingWhitespace.deprecatedNode()->isTextNode()) {
    325         Text* textNode = static_cast<Text*>(leadingWhitespace.deprecatedNode());
     325        Text* textNode = toText(leadingWhitespace.deprecatedNode());
    326326        ASSERT(!textNode->renderer() || textNode->renderer()->style()->collapseWhiteSpace());
    327327        replaceTextInNodePreservingMarkers(textNode, leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString());
     
    330330    // Split at pos if in the middle of a text node.
    331331    if (insertionPosition.deprecatedNode()->isTextNode()) {
    332         Text* textNode = static_cast<Text*>(insertionPosition.deprecatedNode());
     332        Text* textNode = toText(insertionPosition.deprecatedNode());
    333333        bool atEnd = (unsigned)insertionPosition.deprecatedEditingOffset() >= textNode->length();
    334334        if (insertionPosition.deprecatedEditingOffset() > 0 && !atEnd) {
     
    390390            deleteInsignificantTextDownstream(insertionPosition);
    391391            if (insertionPosition.deprecatedNode()->isTextNode())
    392                 insertTextIntoNode(static_cast<Text*>(insertionPosition.deprecatedNode()), 0, nonBreakingSpaceString());
     392                insertTextIntoNode(toText(insertionPosition.deprecatedNode()), 0, nonBreakingSpaceString());
    393393        }
    394394    }
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r93290 r107509  
    210210    // keep tabs coalesced in tab span
    211211    if (isTabSpanTextNode(node)) {
    212         RefPtr<Text> textNode = static_cast<Text*>(node);
     212        RefPtr<Text> textNode = toText(node);
    213213        insertTextIntoNode(textNode, offset, "\t");
    214214        return Position(textNode.release(), offset + 1);
     
    222222        insertNodeAt(spanNode.get(), insertPos);
    223223    } else {
    224         RefPtr<Text> textNode = static_cast<Text*>(node);
     224        RefPtr<Text> textNode = toText(node);
    225225        if (offset >= textNode->length())
    226226            insertNodeAfter(spanNode, textNode.release());
  • trunk/Source/WebCore/editing/MarkupAccumulator.cpp

    r106833 r107509  
    420420    switch (node->nodeType()) {
    421421    case Node::TEXT_NODE:
    422         appendText(result, static_cast<Text*>(const_cast<Node*>(node)));
     422        appendText(result, toText(const_cast<Node*>(node)));
    423423        break;
    424424    case Node::COMMENT_NODE:
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r106695 r107509  
    598598
    599599    Node* lastLeafInserted = insertedNodes.lastLeafInserted();
    600     if (lastLeafInserted && lastLeafInserted->isTextNode() && !nodeHasVisibleRenderText(static_cast<Text*>(lastLeafInserted))
     600    if (lastLeafInserted && lastLeafInserted->isTextNode() && !nodeHasVisibleRenderText(toText(lastLeafInserted))
    601601        && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), selectTag)
    602602        && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), scriptTag)) {
     
    609609    Node* firstNodeInserted = insertedNodes.firstNodeInserted();
    610610    lastLeafInserted = insertedNodes.lastLeafInserted();
    611     if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleRenderText(static_cast<Text*>(firstNodeInserted))) {
     611    if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleRenderText(toText(firstNodeInserted))) {
    612612        insertedNodes.willRemoveNode(firstNodeInserted);
    613613        removeNode(firstNodeInserted);
     
    11901190        bool collapseWhiteSpace = !endNode->renderer() || endNode->renderer()->style()->collapseWhiteSpace();
    11911191        if (endNode->isTextNode()) {
    1192             Text* text = static_cast<Text*>(endNode);
     1192            Text* text = toText(endNode);
    11931193            // FIXME: we shouldn't always be inserting the space at the end
    11941194            insertTextIntoNode(text, text->length(), collapseWhiteSpace ? nonBreakingSpaceString() : " ");
     
    12141214        bool collapseWhiteSpace = !startNode->renderer() || startNode->renderer()->style()->collapseWhiteSpace();
    12151215        if (startNode->isTextNode()) {
    1216             insertTextIntoNode(static_cast<Text*>(startNode), startOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
     1216            insertTextIntoNode(toText(startNode), startOffset, collapseWhiteSpace ? nonBreakingSpaceString() : " ");
    12171217            if (m_endOfInsertedContent.containerNode() == startNode && m_endOfInsertedContent.offsetInContainerNode())
    12181218                m_endOfInsertedContent.moveToOffset(m_endOfInsertedContent.offsetInContainerNode() + 1);
     
    12801280        int textNodeOffset = insertPos.offsetInContainerNode();
    12811281        if (insertPos.deprecatedNode()->isTextNode() && textNodeOffset > 0)
    1282             splitTextNode(static_cast<Text*>(insertPos.deprecatedNode()), textNodeOffset);
     1282            splitTextNode(toText(insertPos.deprecatedNode()), textNodeOffset);
    12831283        splitTreeToNode(insertPos.deprecatedNode(), lastNode, true);
    12841284    }
     
    13341334
    13351335    Node* nodeAfterInsertionPos = endingSelection().end().downstream().anchorNode();
    1336     Text* textNode = static_cast<Text*>(fragment.firstChild());
     1336    Text* textNode = toText(fragment.firstChild());
    13371337    // Our fragment creation code handles tabs, spaces, and newlines, so we don't have to worry about those here.
    13381338
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r106515 r107509  
    10341034        return false;
    10351035   
    1036     Text* textNode = static_cast<Text*>(position.anchorNode());
     1036    Text* textNode = toText(position.anchorNode());
    10371037    unsigned offset = position.offsetInContainerNode();
    10381038    return offset < textNode->length() && textNode->data()[offset] == '\n';
  • trunk/Source/WebCore/editing/visible_units.cpp

    r106298 r107509  
    362362    }
    363363
    364     return startNode->isTextNode() ? Position(static_cast<Text*>(startNode), toInlineTextBox(startBox)->start())
     364    return startNode->isTextNode() ? Position(toText(startNode), toInlineTextBox(startBox)->start())
    365365        : positionBeforeNode(startNode);
    366366}
     
    442442        if (!endTextBox->isLineBreak())
    443443            endOffset += endTextBox->len();
    444         pos = Position(static_cast<Text*>(endNode), endOffset);
     444        pos = Position(toText(endNode), endOffset);
    445445    } else
    446446        pos = positionAfterNode(endNode);
     
    835835                while (--i >= 0) {
    836836                    if (chars[i] == '\n')
    837                         return VisiblePosition(Position(static_cast<Text*>(n), i + 1), DOWNSTREAM);
     837                        return VisiblePosition(Position(toText(n), i + 1), DOWNSTREAM);
    838838                }
    839839            }
     
    911911                for (int i = o; i < length; ++i) {
    912912                    if (chars[i] == '\n')
    913                         return VisiblePosition(Position(static_cast<Text*>(n), i), DOWNSTREAM);
     913                        return VisiblePosition(Position(toText(n), i), DOWNSTREAM);
    914914                }
    915915            }
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r107484 r107509  
    365365
    366366    if (hasOneTextChild(element) && hasOneTextChild(fragment.get())) {
    367         static_cast<Text*>(element->firstChild())->setData(static_cast<Text*>(fragment->firstChild())->data(), ec);
     367        toText(element->firstChild())->setData(toText(fragment->firstChild())->data(), ec);
    368368        return;
    369369    }
     
    385385
    386386    if (hasOneTextChild(element)) {
    387         static_cast<Text*>(element->firstChild())->setData(text, ec);
     387        toText(element->firstChild())->setData(text, ec);
    388388        return;
    389389    }
     
    434434        return;
    435435   
    436     RefPtr<Text> textNode = static_cast<Text*>(node.get());
    437     RefPtr<Text> textNext = static_cast<Text*>(next);
     436    RefPtr<Text> textNode = toText(node.get());
     437    RefPtr<Text> textNext = toText(next);
    438438    textNode->appendData(textNext->data(), ec);
    439439    if (ec)
  • trunk/Source/WebCore/html/HTMLObjectElement.cpp

    r107484 r107509  
    216216        // Ignore whitespace-only text, and <param> tags, any other content is fallback content.
    217217        if (child->isTextNode()) {
    218             if (!static_cast<Text*>(child)->containsOnlyWhitespace())
     218            if (!toText(child)->containsOnlyWhitespace())
    219219                return true;
    220220        } else if (!child->hasTagName(paramTag))
     
    423423                isNamedItem = false;
    424424        } else if (child->isTextNode()) {
    425             if (!static_cast<Text*>(child)->containsOnlyWhitespace())
     425            if (!toText(child)->containsOnlyWhitespace())
    426426                isNamedItem = false;
    427427        } else
  • trunk/Source/WebCore/html/HTMLOptionElement.cpp

    r106769 r107509  
    148148    Node* child = firstChild();
    149149    if (child && child->isTextNode() && !child->nextSibling())
    150         static_cast<Text *>(child)->setData(text, ec);
     150        toText(child)->setData(text, ec);
    151151    else {
    152152        removeChildren();
  • trunk/Source/WebCore/html/HTMLScriptElement.cpp

    r106769 r107509  
    9292
    9393    if (numChildren == 1 && firstChild()->isTextNode()) {
    94         static_cast<Text*>(firstChild())->setData(value, ec);
     94        toText(firstChild())->setData(value, ec);
    9595        return;
    9696    }
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r107484 r107509  
    368368    for (Node* n = firstChild(); n; n = n->nextSibling()) {
    369369        if (n->isTextNode())
    370             value += static_cast<Text*>(n)->data();
     370            value += toText(n)->data();
    371371    }
    372372
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r106769 r107509  
    494494            result.append(newlineCharacter);
    495495        else if (node->isTextNode())
    496             result.append(static_cast<Text*>(node)->data());
     496            result.append(toText(node)->data());
    497497    }
    498498    return finishText(result);
     
    541541            result.append(newlineCharacter);
    542542        else if (node->isTextNode()) {
    543             String data = static_cast<Text*>(node)->data();
     543            String data = toText(node)->data();
    544544            unsigned length = data.length();
    545545            unsigned position = 0;
  • trunk/Source/WebCore/html/HTMLTitleElement.cpp

    r94659 r107509  
    7171    for (Node *n = firstChild(); n; n = n->nextSibling()) {
    7272        if (n->isTextNode())
    73             val += static_cast<Text*>(n)->data();
     73            val += toText(n)->data();
    7474    }
    7575
     
    9393   
    9494    if (numChildren == 1 && firstChild()->isTextNode())
    95         static_cast<Text*>(firstChild())->setData(value, ec);
     95        toText(firstChild())->setData(value, ec);
    9696    else { 
    9797        // We make a copy here because entity of "value" argument can be Document::m_title,
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp

    r107399 r107509  
    707707    }
    708708
    709     m_domEditor->replaceWholeText(static_cast<Text*>(node), value, errorString);
     709    m_domEditor->replaceWholeText(toText(node), value, errorString);
    710710}
    711711
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r105394 r107509  
    301301{
    302302    Node* e = node();
    303     return (e && e->isTextNode()) ? static_cast<Text*>(e)->dataImpl() : 0;
     303    return (e && e->isTextNode()) ? toText(e)->dataImpl() : 0;
    304304}
    305305
  • trunk/Source/WebCore/rendering/RenderTextFragment.cpp

    r90675 r107509  
    5353{
    5454    Node* e = node();
    55     RefPtr<StringImpl> result = ((e && e->isTextNode()) ? static_cast<Text*>(e)->dataImpl() : contentString());
     55    RefPtr<StringImpl> result = ((e && e->isTextNode()) ? toText(e)->dataImpl() : contentString());
    5656    if (!result)
    5757        return 0;
     
    9696    if (start()) {
    9797        Node* e = node();
    98         StringImpl*  original = ((e && e->isTextNode()) ? static_cast<Text*>(e)->dataImpl() : contentString());
     98        StringImpl* original = ((e && e->isTextNode()) ? toText(e)->dataImpl() : contentString());
    9999        if (original && start() <= original->length())
    100100            return (*original)[start() - 1];
  • trunk/Tools/ChangeLog

    r107504 r107509  
     12012-02-12  Joe Thomas  <joethomas@motorola.com>
     2
     3        Add toText and isTextNode helpers in Text class.
     4        https://bugs.webkit.org/show_bug.cgi?id=78140
     5
     6        Added a style checker to use toText rather than static_cast<Text*>.
     7
     8        Reviewed by Adam Barth.
     9
     10        * Scripts/webkitpy/style/checkers/cpp.py:
     11        (check_language): Style checker for static_cast<Text*>.
     12
    1132012-02-12  Philippe Normand  <pnormand@igalia.com>
    214
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r106838 r107509  
    29812981    check_identifier_name_in_declaration(filename, line_number, line, file_state, error)
    29822982
     2983    # Check that we're not using static_cast<Text*>.
     2984    if search(r'\bstatic_cast<Text\*>', line):
     2985        error(line_number, 'readability/check', 4,
     2986              'Consider using toText helper function in WebCore/dom/Text.h '
     2987              'instead of static_cast<Text*>')
    29832988
    29842989def check_identifier_name_in_declaration(filename, line_number, line, file_state, error):
Note: See TracChangeset for help on using the changeset viewer.