Changeset 76560 in webkit


Ignore:
Timestamp:
Jan 24, 2011 6:21:49 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-01-24 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Eric Seidel.

Stop instantiating legacy editing positions in InsertTextCommand, MoveSelectionCommand,
ReplaceSelectionCommand, SelectionController, SpellChecker, TypingCommand, and markup.cpp
https://bugs.webkit.org/show_bug.cgi?id=52676

Stop instantiating legacy editing positions in the following files.

  • editing/InsertTextCommand.cpp: (WebCore::InsertTextCommand::prepareForTextInsertion): (WebCore::InsertTextCommand::performTrivialReplace): (WebCore::InsertTextCommand::input): (WebCore::InsertTextCommand::insertTab):
  • editing/MoveSelectionCommand.cpp: (WebCore::MoveSelectionCommand::doApply):
  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds): (WebCore::ReplaceSelectionCommand::mergeEndIfNeeded): (WebCore::ReplaceSelectionCommand::doApply): (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR): (WebCore::ReplaceSelectionCommand::performTrivialReplace):
  • editing/SelectionController.cpp: (WebCore::SelectionController::setSelectionFromNone):
  • editing/SpellChecker.cpp: (WebCore::SpellChecker::didCheck):
  • editing/TypingCommand.cpp: (WebCore::TypingCommand::makeEditableRootEmpty): (WebCore::TypingCommand::deleteKeyPressed): (WebCore::TypingCommand::forwardDeleteKeyPressed):
  • editing/markup.cpp: (WebCore::StyledMarkupAccumulator::appendText): (WebCore::StyledMarkupAccumulator::serializeNodes): (WebCore::highestAncestorToWrapMarkup): (WebCore::createMarkup):
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r76557 r76560  
     12011-01-24  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Stop instantiating legacy editing positions in InsertTextCommand, MoveSelectionCommand,
     6        ReplaceSelectionCommand, SelectionController, SpellChecker, TypingCommand, and markup.cpp
     7        https://bugs.webkit.org/show_bug.cgi?id=52676
     8
     9        Stop instantiating legacy editing positions in the following files.
     10
     11        * editing/InsertTextCommand.cpp:
     12        (WebCore::InsertTextCommand::prepareForTextInsertion):
     13        (WebCore::InsertTextCommand::performTrivialReplace):
     14        (WebCore::InsertTextCommand::input):
     15        (WebCore::InsertTextCommand::insertTab):
     16        * editing/MoveSelectionCommand.cpp:
     17        (WebCore::MoveSelectionCommand::doApply):
     18        * editing/ReplaceSelectionCommand.cpp:
     19        (WebCore::ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds):
     20        (WebCore::ReplaceSelectionCommand::mergeEndIfNeeded):
     21        (WebCore::ReplaceSelectionCommand::doApply):
     22        (WebCore::ReplaceSelectionCommand::shouldRemoveEndBR):
     23        (WebCore::ReplaceSelectionCommand::performTrivialReplace):
     24        * editing/SelectionController.cpp:
     25        (WebCore::SelectionController::setSelectionFromNone):
     26        * editing/SpellChecker.cpp:
     27        (WebCore::SpellChecker::didCheck):
     28        * editing/TypingCommand.cpp:
     29        (WebCore::TypingCommand::makeEditableRootEmpty):
     30        (WebCore::TypingCommand::deleteKeyPressed):
     31        (WebCore::TypingCommand::forwardDeleteKeyPressed):
     32        * editing/markup.cpp:
     33        (WebCore::StyledMarkupAccumulator::appendText):
     34        (WebCore::StyledMarkupAccumulator::serializeNodes):
     35        (WebCore::highestAncestorToWrapMarkup):
     36        (WebCore::createMarkup):
     37
    1382011-01-24  Peter Kasting  <pkasting@google.com>
    239
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r76482 r76560  
    6262        RefPtr<Node> textNode = document()->createEditingTextNode("");
    6363        insertNodeAt(textNode.get(), pos);
    64         return Position(textNode.get(), 0);
     64        return firstPositionInNode(textNode.get());
    6565    }
    6666
     
    6868        RefPtr<Node> textNode = document()->createEditingTextNode("");
    6969        insertNodeAtTabSpanPosition(textNode.get(), pos);
    70         return Position(textNode.get(), 0);
     70        return firstPositionInNode(textNode.get());
    7171    }
    7272
     
    8484        return false;
    8585   
    86     Position start = endingSelection().start();
    87     Position end = endingSelection().end();
    88    
    89     if (start.node() != end.node() || !start.node()->isTextNode() || isTabSpanTextNode(start.node()))
     86    Position start = endingSelection().start().parentAnchoredEquivalent();
     87    Position end = endingSelection().end().parentAnchoredEquivalent();
     88    ASSERT(start.anchorType() == Position::PositionIsOffsetInAnchor);
     89    ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor);
     90
     91    if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode() || isTabSpanTextNode(start.containerNode()))
    9092        return false;
    91        
    92     replaceTextInNode(static_cast<Text*>(start.node()), start.deprecatedEditingOffset(), end.deprecatedEditingOffset() - start.deprecatedEditingOffset(), text);
    93    
    94     Position endPosition(start.node(), start.deprecatedEditingOffset() + text.length());
    95    
     93
     94    replaceTextInNode(static_cast<Text*>(start.containerNode()), start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text);
     95
     96    Position endPosition(start.containerNode(), start.offsetInContainerNode() + text.length());
     97
    9698    // We could have inserted a part of composed character sequence,
    9799    // so we are basically treating ending selection as a range to avoid validation.
     
    100102    forcedEndingSelection.setWithoutValidation(start, endPosition);
    101103    setEndingSelection(forcedEndingSelection);
    102    
     104
    103105    if (!selectInsertedText)
    104106        setEndingSelection(VisibleSelection(endingSelection().visibleEnd()));
     
    171173
    172174        insertTextIntoNode(textNode, offset, text);
    173         endPosition = Position(textNode, offset + text.length());
     175        endPosition = Position(textNode, offset + text.length(), Position::PositionIsOffsetInAnchor);
    174176
    175177        if (whitespaceRebalance == RebalanceLeadingAndTrailingWhitespaces) {
     
    214216    if (isTabSpanTextNode(node)) {
    215217        insertTextIntoNode(static_cast<Text *>(node), offset, "\t");
    216         return Position(node, offset + 1);
     218        return Position(node, offset + 1, Position::PositionIsOffsetInAnchor);
    217219    }
    218220   
     
    237239        }
    238240    }
    239    
     241
    240242    // return the position following the new tab
    241     return Position(spanNode->lastChild(), caretMaxOffset(spanNode->lastChild()));
     243    return lastPositionInNode(spanNode.get());
    242244}
    243245
  • trunk/Source/WebCore/editing/MoveSelectionCommand.cpp

    r66032 r76560  
    4040void MoveSelectionCommand::doApply()
    4141{
    42     VisibleSelection selection = endingSelection();
    43     ASSERT(selection.isNonOrphanedRange());
     42    ASSERT(endingSelection().isNonOrphanedRange());
    4443
    4544    Position pos = m_position;
    4645    if (pos.isNull())
    4746        return;
    48        
     47
    4948    // Update the position otherwise it may become invalid after the selection is deleted.
    50     Node *positionNode = m_position.node();
    51     int positionOffset = m_position.deprecatedEditingOffset();
    52     Position selectionEnd = selection.end();
    53     int selectionEndOffset = selectionEnd.deprecatedEditingOffset();
    54     if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) {
    55         positionOffset -= selectionEndOffset;
    56         Position selectionStart = selection.start();
    57         if (selectionStart.node() == positionNode) {
    58             positionOffset += selectionStart.deprecatedEditingOffset();
    59         }
    60         pos = Position(positionNode, positionOffset);
     49    Position selectionEnd = endingSelection().end();
     50    if (pos.anchorType() == Position::PositionIsOffsetInAnchor && selectionEnd.anchorType() == Position::PositionIsOffsetInAnchor
     51        && selectionEnd.containerNode() == pos.containerNode() && selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) {
     52        pos.moveToOffset(pos.offsetInContainerNode() - selectionEnd.offsetInContainerNode());
     53
     54        Position selectionStart = endingSelection().start();
     55        if (selectionStart.anchorType() == Position::PositionIsOffsetInAnchor && selectionStart.containerNode() == pos.containerNode())
     56            pos.moveToOffset(pos.offsetInContainerNode() + selectionStart.offsetInContainerNode());
    6157    }
    6258
     
    7167
    7268    setEndingSelection(VisibleSelection(pos, endingSelection().affinity()));
    73     if (!positionNode->inDocument()) {
     69    if (!pos.anchorNode()->inDocument()) {
    7470        // Document was modified out from under us.
    7571        return;
    7672    }
    77     applyCommandToComposite(ReplaceSelectionCommand::create(positionNode->document(), m_fragment, true, m_smartInsert));
     73    applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragment, true, m_smartInsert));
    7874}
    7975
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r76248 r76560  
    497497{
    498498    document()->updateLayoutIgnorePendingStylesheets();
    499     if (!m_lastLeafInserted->renderer() &&
    500         m_lastLeafInserted->isTextNode() &&
    501         !enclosingNodeWithTag(Position(m_lastLeafInserted.get(), 0), selectTag) &&
    502         !enclosingNodeWithTag(Position(m_lastLeafInserted.get(), 0), scriptTag)) {
     499    if (!m_lastLeafInserted->renderer()
     500        && m_lastLeafInserted->isTextNode()
     501        && !enclosingNodeWithTag(firstPositionInOrBeforeNode(m_lastLeafInserted.get()), selectTag)
     502        && !enclosingNodeWithTag(firstPositionInOrBeforeNode(m_lastLeafInserted.get()), scriptTag)) {
    503503        if (m_firstNodeInserted == m_lastLeafInserted) {
    504504            removeNode(m_lastLeafInserted.get());
     
    744744        RefPtr<Node> placeholder = createBreakElement(document());
    745745        insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().node());
    746         destination = VisiblePosition(Position(placeholder.get(), 0));
     746        destination = VisiblePosition(positionBeforeNode(placeholder.get()));
    747747    }
    748748
     
    10461046                    RefPtr<Node> newListItem = createListItemElement(document());
    10471047                    insertNodeAfter(newListItem, enclosingNode);
    1048                     setEndingSelection(VisiblePosition(Position(newListItem, 0)));
     1048                    setEndingSelection(VisiblePosition(firstPositionInNode(newListItem.get())));
    10491049                } else
    10501050                    // Use a default paragraph element (a plain div) for the empty paragraph, using the last paragraph
     
    11251125        return false;
    11261126       
    1127     VisiblePosition visiblePos(Position(endBR, 0));
     1127    VisiblePosition visiblePos(positionBeforeNode(endBR));
    11281128   
    11291129    // Don't remove the br if nothing was inserted.
     
    12621262    if (!fragment.firstChild() || fragment.firstChild() != fragment.lastChild() || !fragment.firstChild()->isTextNode())
    12631263        return false;
    1264        
     1264
    12651265    // FIXME: Would be nice to handle smart replace in the fast path.
    12661266    if (m_smartReplace || fragment.hasInterchangeNewlineAtStart() || fragment.hasInterchangeNewlineAtEnd())
     
    12711271    String text(textNode->data());
    12721272   
    1273     Position start = endingSelection().start();
    1274     Position end = endingSelection().end();
    1275    
    1276     if (start.anchorNode() != end.anchorNode() || !start.anchorNode()->isTextNode())
     1273    Position start = endingSelection().start().parentAnchoredEquivalent();
     1274    Position end = endingSelection().end().parentAnchoredEquivalent();
     1275    ASSERT(start.anchorType() == Position::PositionIsOffsetInAnchor);
     1276    ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor);
     1277
     1278    if (start.containerNode() != end.containerNode() || !start.containerNode()->isTextNode())
    12771279        return false;
    1278        
    1279     replaceTextInNode(static_cast<Text*>(start.anchorNode()), start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text);
    1280    
    1281     end = Position(start.anchorNode(), start.offsetInContainerNode() + text.length());
    1282    
     1280
     1281    replaceTextInNode(static_cast<Text*>(start.containerNode()), start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text);
     1282
     1283    end = Position(start.containerNode(), start.offsetInContainerNode() + text.length(), Position::PositionIsOffsetInAnchor);
     1284
    12831285    VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, end);
    1284    
     1286
    12851287    setEndingSelection(selectionAfterReplace);
    1286    
     1288
    12871289    return true;
    12881290}
  • trunk/Source/WebCore/editing/SelectionController.cpp

    r76315 r76560  
    17751775        node = node->traverseNextNode();
    17761776    if (node)
    1777         setSelection(VisibleSelection(Position(node, 0), DOWNSTREAM));
     1777        setSelection(VisibleSelection(firstPositionInOrBeforeNode(node), DOWNSTREAM));
    17781778}
    17791779
  • trunk/Source/WebCore/editing/SpellChecker.cpp

    r73886 r76560  
    142142
    143143    int startOffset = 0;
    144     PositionIterator start = Position(m_requestNode, 0);
     144    PositionIterator start = firstPositionInOrBeforeNode(m_requestNode.get());
    145145    for (size_t i = 0; i < results.size(); ++i) {
    146146        if (results[i].type() != DocumentMarker::Spelling && results[i].type() != DocumentMarker::Grammar)
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r76482 r76560  
    437437
    438438    addBlockPlaceholderIfNeeded(root);
    439     setEndingSelection(VisibleSelection(Position(root, 0), DOWNSTREAM));
     439    setEndingSelection(VisibleSelection(firstPositionInNode(root), DOWNSTREAM));
    440440
    441441    return true;
     
    496496        // If the caret is just after a table, select the table and don't delete anything.
    497497        } else if (Node* table = isFirstPositionAfterTable(visibleStart)) {
    498             setEndingSelection(VisibleSelection(Position(table, 0), endingSelection().start(), DOWNSTREAM));
     498            setEndingSelection(VisibleSelection(positionAfterNode(table), endingSelection().start(), DOWNSTREAM));
    499499            typingAddedToOpenCommand(DeleteKey);
    500500            return;
     
    597597                else
    598598                    extraCharacters = selectionToDelete.end().deprecatedEditingOffset();
    599                 extent = Position(extent.node(), extent.deprecatedEditingOffset() + extraCharacters);
     599                extent = Position(extent.node(), extent.deprecatedEditingOffset() + extraCharacters, Position::PositionIsOffsetInAnchor);
    600600            }
    601601            selectionAfterUndo.setWithoutValidation(startingSelection().start(), extent);
  • trunk/Source/WebCore/editing/markup.cpp

    r72259 r76560  
    195195    }
    196196
    197     bool useRenderedText = !enclosingNodeWithTag(Position(text, 0), selectTag);
     197    bool useRenderedText = !enclosingNodeWithTag(firstPositionInNode(text), selectTag);
    198198    String content = useRenderedText ? renderedText(text, m_range) : stringValueForRange(text, m_range);
    199199    Vector<UChar> buffer;
     
    338338            continue;
    339339
    340         if (!n->renderer() && !enclosingNodeWithTag(Position(n, 0), selectTag)) {
     340        if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode(n), selectTag)) {
    341341            next = n->traverseNextSibling();
    342342            // Don't skip over pastEnd.
     
    496496    Node* checkAncestor = specialCommonAncestor ? specialCommonAncestor : commonAncestor;
    497497    if (checkAncestor->renderer()) {
    498         Node* newSpecialCommonAncestor = highestEnclosingNodeOfType(Position(checkAncestor, 0), &isElementPresentational);
     498        Node* newSpecialCommonAncestor = highestEnclosingNodeOfType(firstPositionInNode(checkAncestor), &isElementPresentational);
    499499        if (newSpecialCommonAncestor)
    500500            specialCommonAncestor = newSpecialCommonAncestor;
     
    510510        specialCommonAncestor = commonAncestor;
    511511
    512     if (Node *enclosingAnchor = enclosingNodeWithTag(Position(specialCommonAncestor ? specialCommonAncestor : commonAncestor, 0), aTag))
     512    if (Node *enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : commonAncestor), aTag))
    513513        specialCommonAncestor = enclosingAnchor;
    514514
     
    580580    }
    581581
    582     Node* body = enclosingNodeWithTag(Position(commonAncestor, 0), bodyTag);
     582    Node* body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyTag);
    583583    Node* fullySelectedRoot = 0;
    584584    // FIXME: Do this for all fully selected blocks, not just the body.
Note: See TracChangeset for help on using the changeset viewer.