Changeset 76107 in webkit
- Timestamp:
- Jan 19, 2011 1:32:09 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r76106 r76107 1 2011-01-19 Levi Weintraub <leviw@google.com> 2 3 Reviewed by Ryosuke Niwa. 4 5 Replaced rangeCompliantEquivalent with Position::parentAnchoredEquivalent 6 and simplified the logic a bit. Unfortunately, Tables and some legacy 7 editing positions still need to be handled specifically. 8 9 remove rangeCompliantEquivalent and replace it with Position methods 10 https://bugs.webkit.org/show_bug.cgi?id=25057 11 12 No new tests as this is a refactor that doesn't change behavior. 13 14 * WebCore.exp.in: 15 * dom/Document.cpp: 16 (WebCore::Document::caretRangeFromPoint): 17 * dom/Position.cpp: 18 (WebCore::Position::parentAnchoredEquivalent): 19 * dom/Position.h: 20 * editing/ApplyStyleCommand.cpp: 21 (WebCore::ApplyStyleCommand::applyBlockStyle): 22 * editing/CompositeEditCommand.cpp: 23 (WebCore::CompositeEditCommand::insertNodeAt): 24 (WebCore::CompositeEditCommand::moveParagraphs): 25 * editing/DeleteSelectionCommand.cpp: 26 (WebCore::DeleteSelectionCommand::initializePositionData): 27 (WebCore::DeleteSelectionCommand::mergeParagraphs): 28 * editing/Editor.cpp: 29 (WebCore::Editor::textDirectionForSelection): 30 (WebCore::Editor::advanceToNextMisspelling): 31 * editing/InsertLineBreakCommand.cpp: 32 (WebCore::InsertLineBreakCommand::shouldUseBreakElement): 33 * editing/InsertParagraphSeparatorCommand.cpp: 34 (WebCore::InsertParagraphSeparatorCommand::doApply): 35 * editing/ReplaceSelectionCommand.cpp: 36 (WebCore::handleStyleSpansBeforeInsertion): 37 * editing/VisiblePosition.cpp: 38 (WebCore::makeRange): 39 (WebCore::setStart): 40 (WebCore::setEnd): 41 * editing/VisibleSelection.cpp: 42 (WebCore::VisibleSelection::firstRange): 43 (WebCore::VisibleSelection::toNormalizedRange): 44 (WebCore::makeSearchRange): 45 * editing/htmlediting.cpp: 46 (WebCore::indexForVisiblePosition): 47 * editing/htmlediting.h: 48 * editing/visible_units.cpp: 49 (WebCore::previousBoundary): 50 (WebCore::nextBoundary): 51 * page/DOMSelection.cpp: 52 (WebCore::anchorPosition): 53 (WebCore::focusPosition): 54 (WebCore::basePosition): 55 (WebCore::extentPosition): 56 1 57 2011-01-19 Peter Rybin <peter.rybin@gmail.com> 2 58 -
trunk/Source/WebCore/WebCore.exp.in
r75976 r76107 546 546 __ZN7WebCore24fileSystemRepresentationERKN3WTF6StringE 547 547 __ZN7WebCore24notifyHistoryItemChangedE 548 __ZN7WebCore24rangeCompliantEquivalentERKNS_8PositionE549 548 __ZN7WebCore25HistoryPropertyListWriter11releaseDataEv 550 549 __ZN7WebCore25HistoryPropertyListWriter12writeObjectsERNS_30BinaryPropertyListObjectStreamE … … 1196 1195 __ZNK7WebCore8IntPointcv8_NSPointEv 1197 1196 __ZNK7WebCore8Position10downstreamENS_27EditingBoundaryCrossingRuleE 1197 __ZNK7WebCore8Position24parentAnchoredEquivalentEv 1198 1198 __ZNK7WebCore8Position25leadingWhitespacePositionENS_9EAffinityEb 1199 1199 __ZNK7WebCore8Position26trailingWhitespacePositionENS_9EAffinityEb -
trunk/Source/WebCore/dom/Document.cpp
r75932 r76107 1302 1302 return 0; 1303 1303 1304 Position rangeCompliantPosition = rangeCompliantEquivalent(visiblePosition);1304 Position rangeCompliantPosition = visiblePosition.deepEquivalent().parentAnchoredEquivalent(); 1305 1305 return Range::create(this, rangeCompliantPosition, rangeCompliantPosition); 1306 1306 } -
trunk/Source/WebCore/dom/Position.cpp
r72777 r76107 147 147 } 148 148 149 // Neighbor-anchored positions are invalid DOM positions, so they need to be 150 // fixed up before handing them off to the Range object. 151 Position Position::parentAnchoredEquivalent() const 152 { 153 if (!m_anchorNode) 154 return Position(); 155 156 // FIXME: This should only be necessary for legacy positions, but is also needed for positions before and after Tables 157 if (m_offset <= 0) { 158 if (m_anchorNode->parentNode() && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get()))) 159 return positionInParentBeforeNode(m_anchorNode.get()); 160 return Position(m_anchorNode, 0, PositionIsOffsetInAnchor); 161 } 162 if (!m_anchorNode->offsetInCharacters() && static_cast<unsigned>(m_offset) == m_anchorNode->childNodeCount() 163 && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get()))) { 164 return positionInParentAfterNode(m_anchorNode.get()); 165 } 166 167 return Position(containerNode(), computeOffsetInContainerNode(), PositionIsOffsetInAnchor); 168 } 169 149 170 Node* Position::computeNodeBeforePosition() const 150 171 { -
trunk/Source/WebCore/dom/Position.h
r72777 r76107 81 81 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent 82 82 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions 83 Position parentAnchoredEquivalent() const; // Convenience method for DOM positions that also fixes up some positions for editing 83 84 84 85 // Inline O(1) access for Positions which callers know to be parent-anchored … … 180 181 // m_offset can be the offset inside m_anchorNode, or if editingIgnoresContent(m_anchorNode) 181 182 // returns true, then other places in editing will treat m_offset == 0 as "before the anchor" 182 // and m_offset > 0 as "after the anchor node". See rangeCompliantEquivalent for more info.183 // and m_offset > 0 as "after the anchor node". See parentAnchoredEquivalent for more info. 183 184 int m_offset; 184 185 unsigned m_anchorType : 2; -
trunk/Source/WebCore/editing/ApplyStyleCommand.cpp
r75843 r76107 570 570 // Calculate start and end indices from the start of the tree that they're in. 571 571 Node* scope = highestAncestor(visibleStart.deepEquivalent().node()); 572 RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(scope), rangeCompliantEquivalent(visibleStart.deepEquivalent()));573 RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope), rangeCompliantEquivalent(visibleEnd.deepEquivalent()));572 RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 573 RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 574 574 int startIndex = TextIterator::rangeLength(startRange.get(), true); 575 575 int endIndex = TextIterator::rangeLength(endRange.get(), true); -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r75835 r76107 160 160 // For editing positions like [table, 0], insert before the table, 161 161 // likewise for replaced elements, brs, etc. 162 Position p = rangeCompliantEquivalent(editingPosition);162 Position p = editingPosition.parentAnchoredEquivalent(); 163 163 Node* refChild = p.node(); 164 164 int offset = p.deprecatedEditingOffset(); … … 906 906 startIndex = 0; 907 907 if (startInParagraph) { 908 RefPtr<Range> startRange = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleStart.deepEquivalent()));908 RefPtr<Range> startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 909 909 startIndex = TextIterator::rangeLength(startRange.get(), true); 910 910 } … … 912 912 endIndex = 0; 913 913 if (endInParagraph) { 914 RefPtr<Range> endRange = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleEnd.deepEquivalent()));914 RefPtr<Range> endRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 915 915 endIndex = TextIterator::rangeLength(endRange.get(), true); 916 916 } … … 927 927 928 928 // start and end can't be used directly to create a Range; they are "editing positions" 929 Position startRangeCompliant = rangeCompliantEquivalent(start);930 Position endRangeCompliant = rangeCompliantEquivalent(end);929 Position startRangeCompliant = start.parentAnchoredEquivalent(); 930 Position endRangeCompliant = end.parentAnchoredEquivalent(); 931 931 RefPtr<Range> range = Range::create(document(), startRangeCompliant.node(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.node(), endRangeCompliant.deprecatedEditingOffset()); 932 932 … … 975 975 } 976 976 977 RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document()->documentElement()), rangeCompliantEquivalent(destination.deepEquivalent())));977 RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document()->documentElement()), destination.deepEquivalent().parentAnchoredEquivalent())); 978 978 destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true); 979 979 -
trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp
r76057 r76107 257 257 } 258 258 259 // We must pass the positions through rangeCompliantEquivalent,since some editing positions259 // We must pass call parentAnchoredEquivalent on the positions since some editing positions 260 260 // that appear inside their nodes aren't really inside them. [hr, 0] is one example. 261 // FIXME: rangeComplaintEquivalent should eventually be moved into enclosing element getters261 // FIXME: parentAnchoredEquivalent should eventually be moved into enclosing element getters 262 262 // like the one below, since editing functions should obviously accept editing positions. 263 263 // FIXME: Passing false to enclosingNodeOfType tells it that it's OK to return a non-editable 264 264 // node. This was done to match existing behavior, but it seems wrong. 265 m_startBlock = enclosingNodeOfType( rangeCompliantEquivalent(m_downstreamStart), &isBlock, false);266 m_endBlock = enclosingNodeOfType( rangeCompliantEquivalent(m_upstreamEnd), &isBlock, false);265 m_startBlock = enclosingNodeOfType(m_downstreamStart.parentAnchoredEquivalent(), &isBlock, false); 266 m_endBlock = enclosingNodeOfType(m_upstreamEnd.parentAnchoredEquivalent(), &isBlock, false); 267 267 } 268 268 … … 624 624 } 625 625 626 RefPtr<Range> range = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(endOfParagraphToMove.deepEquivalent()));627 RefPtr<Range> rangeToBeReplaced = Range::create(document(), rangeCompliantEquivalent(mergeDestination.deepEquivalent()), rangeCompliantEquivalent(mergeDestination.deepEquivalent()));626 RefPtr<Range> range = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent()); 627 RefPtr<Range> rangeToBeReplaced = Range::create(document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent()); 628 628 if (!document()->frame()->editor()->client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get())) 629 629 return; -
trunk/Source/WebCore/editing/Editor.cpp
r75861 r76107 644 644 end = m_frame->selection()->selection().end().upstream(); 645 645 646 Node* pastLast = Range::create(m_frame->document(), rangeCompliantEquivalent(position), rangeCompliantEquivalent(end))->pastLastNode();646 Node* pastLast = Range::create(m_frame->document(), position.parentAnchoredEquivalent(), end.parentAnchoredEquivalent())->pastLastNode(); 647 647 for (Node* n = node; n && n != pastLast; n = n->traverseNextNode()) { 648 648 if (!n->isStyledElement()) … … 1784 1784 return; 1785 1785 1786 Position rangeCompliantPosition = rangeCompliantEquivalent(position);1786 Position rangeCompliantPosition = position.parentAnchoredEquivalent(); 1787 1787 spellingSearchRange->setStart(rangeCompliantPosition.node(), rangeCompliantPosition.deprecatedEditingOffset(), ec); 1788 1788 startedWithSelection = false; // won't need to wrap -
trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp
r76057 r76107 83 83 // the input element, and in that case we need to check the input element's 84 84 // parent's renderer. 85 Position p( rangeCompliantEquivalent(insertionPos));85 Position p(insertionPos.parentAnchoredEquivalent()); 86 86 return p.node()->renderer() && !p.node()->renderer()->style()->preserveNewline(); 87 87 } -
trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
r76057 r76107 160 160 } 161 161 162 // FIXME: The rangeCompliantEquivalent conversion needs to be moved into enclosingBlock.163 Node* startBlockNode = enclosingBlock( rangeCompliantEquivalent(insertionPosition).node());162 // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enclosingBlock. 163 Node* startBlockNode = enclosingBlock(insertionPosition.parentAnchoredEquivalent().containerNode()); 164 164 Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent(); 165 165 Element* startBlock = static_cast<Element*>(startBlockNode); -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r73801 r76107 569 569 RefPtr<Node> copiedRangeStyleSpan = sourceDocumentStyleSpan->firstChild(); 570 570 571 RefPtr<EditingStyle> styleAtInsertionPos = EditingStyle::create( rangeCompliantEquivalent(insertionPos));571 RefPtr<EditingStyle> styleAtInsertionPos = EditingStyle::create(insertionPos.parentAnchoredEquivalent()); 572 572 String styleText = styleAtInsertionPos->style()->cssText(); 573 573 -
trunk/Source/WebCore/editing/VisiblePosition.cpp
r74385 r76107 598 598 return 0; 599 599 600 Position s = rangeCompliantEquivalent(start);601 Position e = rangeCompliantEquivalent(end);600 Position s = start.deepEquivalent().parentAnchoredEquivalent(); 601 Position e = end.deepEquivalent().parentAnchoredEquivalent(); 602 602 return Range::create(s.node()->document(), s.node(), s.deprecatedEditingOffset(), e.node(), e.deprecatedEditingOffset()); 603 603 } … … 619 619 if (!r) 620 620 return false; 621 Position p = rangeCompliantEquivalent(visiblePosition);621 Position p = visiblePosition.deepEquivalent().parentAnchoredEquivalent(); 622 622 int code = 0; 623 623 r->setStart(p.node(), p.deprecatedEditingOffset(), code); … … 629 629 if (!r) 630 630 return false; 631 Position p = rangeCompliantEquivalent(visiblePosition);631 Position p = visiblePosition.deepEquivalent().parentAnchoredEquivalent(); 632 632 int code = 0; 633 633 r->setEnd(p.node(), p.deprecatedEditingOffset(), code); -
trunk/Source/WebCore/editing/VisibleSelection.cpp
r58564 r76107 122 122 if (isNone()) 123 123 return 0; 124 Position start = rangeCompliantEquivalent(m_start);125 Position end = rangeCompliantEquivalent(m_end);124 Position start = m_start.parentAnchoredEquivalent(); 125 Position end = m_end.parentAnchoredEquivalent(); 126 126 return Range::create(start.node()->document(), start, end); 127 127 } … … 147 147 // the conventions of text editors tested, which make style determinations based 148 148 // on the character before the caret, if any. 149 s = rangeCompliantEquivalent(m_start.upstream());149 s = m_start.upstream().parentAnchoredEquivalent(); 150 150 e = s; 151 151 } else { … … 171 171 e = tmp; 172 172 } 173 s = rangeCompliantEquivalent(s);174 e = rangeCompliantEquivalent(e);173 s = s.parentAnchoredEquivalent(); 174 e = e.parentAnchoredEquivalent(); 175 175 } 176 176 … … 205 205 ExceptionCode ec = 0; 206 206 207 Position start( rangeCompliantEquivalent(pos));207 Position start(pos.parentAnchoredEquivalent()); 208 208 searchRange->selectNodeContents(boundary, ec); 209 209 searchRange->setStart(start.node(), start.deprecatedEditingOffset(), ec); -
trunk/Source/WebCore/editing/htmlediting.cpp
r76057 r76107 333 333 } 334 334 335 // Internally editing uses "invalid" positions for historical reasons. For336 // example, in <div><img /></div>, Editing might use (img, 1) for the position337 // after <img>, but we have to convert that to (div, 1) before handing the338 // position to a Range object. Ideally all internal positions should339 // be "range compliant" for simplicity.340 Position rangeCompliantEquivalent(const Position& pos)341 {342 if (pos.isNull())343 return Position();344 345 Node* node = pos.node();346 347 if (pos.deprecatedEditingOffset() <= 0) {348 if (node->parentNode() && (editingIgnoresContent(node) || isTableElement(node)))349 return positionInParentBeforeNode(node);350 return Position(node, 0);351 }352 353 if (node->offsetInCharacters())354 return Position(node, min(node->maxCharacterOffset(), pos.deprecatedEditingOffset()));355 356 int maxCompliantOffset = node->childNodeCount();357 if (pos.deprecatedEditingOffset() > maxCompliantOffset) {358 if (node->parentNode())359 return positionInParentAfterNode(node);360 361 // there is no other option at this point than to362 // use the highest allowed position in the node363 return Position(node, maxCompliantOffset);364 }365 366 // Editing should never generate positions like this.367 if ((pos.deprecatedEditingOffset() < maxCompliantOffset) && editingIgnoresContent(node)) {368 ASSERT_NOT_REACHED();369 return node->parentNode() ? positionInParentBeforeNode(node) : Position(node, 0);370 }371 372 if (pos.deprecatedEditingOffset() == maxCompliantOffset && (editingIgnoresContent(node) || isTableElement(node)))373 return positionInParentAfterNode(node);374 375 return Position(pos);376 }377 378 Position rangeCompliantEquivalent(const VisiblePosition& vpos)379 {380 return rangeCompliantEquivalent(vpos.deepEquivalent());381 }382 383 335 // This method is used to create positions in the DOM. It returns the maximum valid offset 384 336 // in a node. It returns 1 for some elements even though they do not have children, which 385 // creates technically invalid DOM Positions. Be sure to call rangeCompliantEquivalent337 // creates technically invalid DOM Positions. Be sure to call parentAnchoredEquivalent 386 338 // on a Position before using it to create a DOM Range, or an exception will be thrown. 387 339 int lastOffsetForEditing(const Node* node) … … 1083 1035 Position p(visiblePosition.deepEquivalent()); 1084 1036 RefPtr<Range> range = Range::create(p.node()->document(), firstPositionInNode(p.anchorNode()->document()->documentElement()), 1085 rangeCompliantEquivalent(p));1037 p.parentAnchoredEquivalent()); 1086 1038 return TextIterator::rangeLength(range.get(), true); 1087 1039 } -
trunk/Source/WebCore/editing/htmlediting.h
r75835 r76107 102 102 // Functions returning Position 103 103 104 Position rangeCompliantEquivalent(const Position&);105 Position rangeCompliantEquivalent(const VisiblePosition&);106 107 104 Position nextCandidate(const Position&); 108 105 Position previousCandidate(const Position&); -
trunk/Source/WebCore/editing/visible_units.cpp
r76053 r76107 58 58 59 59 Document* d = boundary->document(); 60 Position start = rangeCompliantEquivalent(Position(boundary, 0));61 Position end = rangeCompliantEquivalent(pos);60 Position start = Position(boundary, 0).parentAnchoredEquivalent(); 61 Position end = pos.parentAnchoredEquivalent(); 62 62 RefPtr<Range> searchRange = Range::create(d); 63 63 … … 139 139 Document* d = boundary->document(); 140 140 RefPtr<Range> searchRange(d->createRange()); 141 Position start( rangeCompliantEquivalent(pos));141 Position start(pos.parentAnchoredEquivalent()); 142 142 143 143 Vector<UChar, 1024> string; -
trunk/Source/WebCore/page/DOMSelection.cpp
r74566 r76107 77 77 { 78 78 Position anchor = selection.isBaseFirst() ? selection.start() : selection.end(); 79 return rangeCompliantEquivalent(anchor);79 return anchor.parentAnchoredEquivalent(); 80 80 } 81 81 … … 83 83 { 84 84 Position focus = selection.isBaseFirst() ? selection.end() : selection.start(); 85 return rangeCompliantEquivalent(focus);85 return focus.parentAnchoredEquivalent(); 86 86 } 87 87 88 88 static Position basePosition(const VisibleSelection& selection) 89 89 { 90 return rangeCompliantEquivalent(selection.base());90 return selection.base().parentAnchoredEquivalent(); 91 91 } 92 92 93 93 static Position extentPosition(const VisibleSelection& selection) 94 94 { 95 return rangeCompliantEquivalent(selection.extent());95 return selection.extent().parentAnchoredEquivalent(); 96 96 } 97 97 -
trunk/Source/WebKit/mac/ChangeLog
r76044 r76107 1 2011-01-19 Levi Weintraub <leviw@google.com> 2 3 Reviewed by Ryosuke Niwa. 4 5 Updating to use Position::parentAnchoredEquivalent instead of 6 the old htmlediting rangeCompliantEquivalent. 7 8 remove rangeCompliantEquivalent and replace it with Position methods 9 https://bugs.webkit.org/show_bug.cgi?id=25057 10 11 * WebView/WebFrame.mm: 12 (-[WebFrame _smartDeleteRangeForProposedRange:]): 13 1 14 2011-01-18 Chris Fleizach <cfleizach@apple.com> 2 15 -
trunk/Source/WebKit/mac/WebView/WebFrame.mm
r75377 r76107 803 803 newEnd = end; 804 804 805 newStart = rangeCompliantEquivalent(newStart);806 newEnd = rangeCompliantEquivalent(newEnd);805 newStart = newStart.parentAnchoredEquivalent(); 806 newEnd = newEnd.parentAnchoredEquivalent(); 807 807 808 808 RefPtr<Range> range = _private->coreFrame->document()->createRange();
Note: See TracChangeset
for help on using the changeset viewer.