Changeset 76560 in webkit
- Timestamp:
- Jan 24, 2011 6:21:49 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r76557 r76560 1 2011-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 1 38 2011-01-24 Peter Kasting <pkasting@google.com> 2 39 -
trunk/Source/WebCore/editing/InsertTextCommand.cpp
r76482 r76560 62 62 RefPtr<Node> textNode = document()->createEditingTextNode(""); 63 63 insertNodeAt(textNode.get(), pos); 64 return Position(textNode.get(), 0);64 return firstPositionInNode(textNode.get()); 65 65 } 66 66 … … 68 68 RefPtr<Node> textNode = document()->createEditingTextNode(""); 69 69 insertNodeAtTabSpanPosition(textNode.get(), pos); 70 return Position(textNode.get(), 0);70 return firstPositionInNode(textNode.get()); 71 71 } 72 72 … … 84 84 return false; 85 85 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())) 90 92 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 96 98 // We could have inserted a part of composed character sequence, 97 99 // so we are basically treating ending selection as a range to avoid validation. … … 100 102 forcedEndingSelection.setWithoutValidation(start, endPosition); 101 103 setEndingSelection(forcedEndingSelection); 102 104 103 105 if (!selectInsertedText) 104 106 setEndingSelection(VisibleSelection(endingSelection().visibleEnd())); … … 171 173 172 174 insertTextIntoNode(textNode, offset, text); 173 endPosition = Position(textNode, offset + text.length() );175 endPosition = Position(textNode, offset + text.length(), Position::PositionIsOffsetInAnchor); 174 176 175 177 if (whitespaceRebalance == RebalanceLeadingAndTrailingWhitespaces) { … … 214 216 if (isTabSpanTextNode(node)) { 215 217 insertTextIntoNode(static_cast<Text *>(node), offset, "\t"); 216 return Position(node, offset + 1 );218 return Position(node, offset + 1, Position::PositionIsOffsetInAnchor); 217 219 } 218 220 … … 237 239 } 238 240 } 239 241 240 242 // return the position following the new tab 241 return Position(spanNode->lastChild(), caretMaxOffset(spanNode->lastChild()));243 return lastPositionInNode(spanNode.get()); 242 244 } 243 245 -
trunk/Source/WebCore/editing/MoveSelectionCommand.cpp
r66032 r76560 40 40 void MoveSelectionCommand::doApply() 41 41 { 42 VisibleSelection selection = endingSelection(); 43 ASSERT(selection.isNonOrphanedRange()); 42 ASSERT(endingSelection().isNonOrphanedRange()); 44 43 45 44 Position pos = m_position; 46 45 if (pos.isNull()) 47 46 return; 48 47 49 48 // 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()); 61 57 } 62 58 … … 71 67 72 68 setEndingSelection(VisibleSelection(pos, endingSelection().affinity())); 73 if (!pos itionNode->inDocument()) {69 if (!pos.anchorNode()->inDocument()) { 74 70 // Document was modified out from under us. 75 71 return; 76 72 } 77 applyCommandToComposite(ReplaceSelectionCommand::create( positionNode->document(), m_fragment, true, m_smartInsert));73 applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragment, true, m_smartInsert)); 78 74 } 79 75 -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r76248 r76560 497 497 { 498 498 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)) { 503 503 if (m_firstNodeInserted == m_lastLeafInserted) { 504 504 removeNode(m_lastLeafInserted.get()); … … 744 744 RefPtr<Node> placeholder = createBreakElement(document()); 745 745 insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().node()); 746 destination = VisiblePosition( Position(placeholder.get(), 0));746 destination = VisiblePosition(positionBeforeNode(placeholder.get())); 747 747 } 748 748 … … 1046 1046 RefPtr<Node> newListItem = createListItemElement(document()); 1047 1047 insertNodeAfter(newListItem, enclosingNode); 1048 setEndingSelection(VisiblePosition( Position(newListItem, 0)));1048 setEndingSelection(VisiblePosition(firstPositionInNode(newListItem.get()))); 1049 1049 } else 1050 1050 // Use a default paragraph element (a plain div) for the empty paragraph, using the last paragraph … … 1125 1125 return false; 1126 1126 1127 VisiblePosition visiblePos( Position(endBR, 0));1127 VisiblePosition visiblePos(positionBeforeNode(endBR)); 1128 1128 1129 1129 // Don't remove the br if nothing was inserted. … … 1262 1262 if (!fragment.firstChild() || fragment.firstChild() != fragment.lastChild() || !fragment.firstChild()->isTextNode()) 1263 1263 return false; 1264 1264 1265 1265 // FIXME: Would be nice to handle smart replace in the fast path. 1266 1266 if (m_smartReplace || fragment.hasInterchangeNewlineAtStart() || fragment.hasInterchangeNewlineAtEnd()) … … 1271 1271 String text(textNode->data()); 1272 1272 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()) 1277 1279 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 1283 1285 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, end); 1284 1286 1285 1287 setEndingSelection(selectionAfterReplace); 1286 1288 1287 1289 return true; 1288 1290 } -
trunk/Source/WebCore/editing/SelectionController.cpp
r76315 r76560 1775 1775 node = node->traverseNextNode(); 1776 1776 if (node) 1777 setSelection(VisibleSelection( Position(node, 0), DOWNSTREAM));1777 setSelection(VisibleSelection(firstPositionInOrBeforeNode(node), DOWNSTREAM)); 1778 1778 } 1779 1779 -
trunk/Source/WebCore/editing/SpellChecker.cpp
r73886 r76560 142 142 143 143 int startOffset = 0; 144 PositionIterator start = Position(m_requestNode, 0);144 PositionIterator start = firstPositionInOrBeforeNode(m_requestNode.get()); 145 145 for (size_t i = 0; i < results.size(); ++i) { 146 146 if (results[i].type() != DocumentMarker::Spelling && results[i].type() != DocumentMarker::Grammar) -
trunk/Source/WebCore/editing/TypingCommand.cpp
r76482 r76560 437 437 438 438 addBlockPlaceholderIfNeeded(root); 439 setEndingSelection(VisibleSelection( Position(root, 0), DOWNSTREAM));439 setEndingSelection(VisibleSelection(firstPositionInNode(root), DOWNSTREAM)); 440 440 441 441 return true; … … 496 496 // If the caret is just after a table, select the table and don't delete anything. 497 497 } else if (Node* table = isFirstPositionAfterTable(visibleStart)) { 498 setEndingSelection(VisibleSelection( Position(table, 0), endingSelection().start(), DOWNSTREAM));498 setEndingSelection(VisibleSelection(positionAfterNode(table), endingSelection().start(), DOWNSTREAM)); 499 499 typingAddedToOpenCommand(DeleteKey); 500 500 return; … … 597 597 else 598 598 extraCharacters = selectionToDelete.end().deprecatedEditingOffset(); 599 extent = Position(extent.node(), extent.deprecatedEditingOffset() + extraCharacters );599 extent = Position(extent.node(), extent.deprecatedEditingOffset() + extraCharacters, Position::PositionIsOffsetInAnchor); 600 600 } 601 601 selectionAfterUndo.setWithoutValidation(startingSelection().start(), extent); -
trunk/Source/WebCore/editing/markup.cpp
r72259 r76560 195 195 } 196 196 197 bool useRenderedText = !enclosingNodeWithTag( Position(text, 0), selectTag);197 bool useRenderedText = !enclosingNodeWithTag(firstPositionInNode(text), selectTag); 198 198 String content = useRenderedText ? renderedText(text, m_range) : stringValueForRange(text, m_range); 199 199 Vector<UChar> buffer; … … 338 338 continue; 339 339 340 if (!n->renderer() && !enclosingNodeWithTag( Position(n, 0), selectTag)) {340 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode(n), selectTag)) { 341 341 next = n->traverseNextSibling(); 342 342 // Don't skip over pastEnd. … … 496 496 Node* checkAncestor = specialCommonAncestor ? specialCommonAncestor : commonAncestor; 497 497 if (checkAncestor->renderer()) { 498 Node* newSpecialCommonAncestor = highestEnclosingNodeOfType( Position(checkAncestor, 0), &isElementPresentational);498 Node* newSpecialCommonAncestor = highestEnclosingNodeOfType(firstPositionInNode(checkAncestor), &isElementPresentational); 499 499 if (newSpecialCommonAncestor) 500 500 specialCommonAncestor = newSpecialCommonAncestor; … … 510 510 specialCommonAncestor = commonAncestor; 511 511 512 if (Node *enclosingAnchor = enclosingNodeWithTag( Position(specialCommonAncestor ? specialCommonAncestor : commonAncestor, 0), aTag))512 if (Node *enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : commonAncestor), aTag)) 513 513 specialCommonAncestor = enclosingAnchor; 514 514 … … 580 580 } 581 581 582 Node* body = enclosingNodeWithTag( Position(commonAncestor, 0), bodyTag);582 Node* body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyTag); 583 583 Node* fullySelectedRoot = 0; 584 584 // FIXME: Do this for all fully selected blocks, not just the body.
Note: See TracChangeset
for help on using the changeset viewer.