[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198

commit-queue at webkit.org commit-queue at webkit.org
Sun Feb 20 23:14:32 UTC 2011


The following commit has been merged in the webkit-1.3 branch:
commit c56f5de7abfd666067f5632cc496a9cc6e9009b9
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jan 19 09:32:09 2011 +0000

    2011-01-19  Levi Weintraub  <leviw at google.com>
    
            Reviewed by Ryosuke Niwa.
    
            Replaced rangeCompliantEquivalent with Position::parentAnchoredEquivalent
            and simplified the logic a bit. Unfortunately, Tables and some legacy
            editing positions still need to be handled specifically.
    
            remove rangeCompliantEquivalent and replace it with Position methods
            https://bugs.webkit.org/show_bug.cgi?id=25057
    
            No new tests as this is a refactor that doesn't change behavior.
    
            * WebCore.exp.in:
            * dom/Document.cpp:
            (WebCore::Document::caretRangeFromPoint):
            * dom/Position.cpp:
            (WebCore::Position::parentAnchoredEquivalent):
            * dom/Position.h:
            * editing/ApplyStyleCommand.cpp:
            (WebCore::ApplyStyleCommand::applyBlockStyle):
            * editing/CompositeEditCommand.cpp:
            (WebCore::CompositeEditCommand::insertNodeAt):
            (WebCore::CompositeEditCommand::moveParagraphs):
            * editing/DeleteSelectionCommand.cpp:
            (WebCore::DeleteSelectionCommand::initializePositionData):
            (WebCore::DeleteSelectionCommand::mergeParagraphs):
            * editing/Editor.cpp:
            (WebCore::Editor::textDirectionForSelection):
            (WebCore::Editor::advanceToNextMisspelling):
            * editing/InsertLineBreakCommand.cpp:
            (WebCore::InsertLineBreakCommand::shouldUseBreakElement):
            * editing/InsertParagraphSeparatorCommand.cpp:
            (WebCore::InsertParagraphSeparatorCommand::doApply):
            * editing/ReplaceSelectionCommand.cpp:
            (WebCore::handleStyleSpansBeforeInsertion):
            * editing/VisiblePosition.cpp:
            (WebCore::makeRange):
            (WebCore::setStart):
            (WebCore::setEnd):
            * editing/VisibleSelection.cpp:
            (WebCore::VisibleSelection::firstRange):
            (WebCore::VisibleSelection::toNormalizedRange):
            (WebCore::makeSearchRange):
            * editing/htmlediting.cpp:
            (WebCore::indexForVisiblePosition):
            * editing/htmlediting.h:
            * editing/visible_units.cpp:
            (WebCore::previousBoundary):
            (WebCore::nextBoundary):
            * page/DOMSelection.cpp:
            (WebCore::anchorPosition):
            (WebCore::focusPosition):
            (WebCore::basePosition):
            (WebCore::extentPosition):
    2011-01-19  Levi Weintraub  <leviw at google.com>
    
            Reviewed by Ryosuke Niwa.
    
            Updating to use Position::parentAnchoredEquivalent instead of
            the old htmlediting rangeCompliantEquivalent.
    
            remove rangeCompliantEquivalent and replace it with Position methods
            https://bugs.webkit.org/show_bug.cgi?id=25057
    
            * WebView/WebFrame.mm:
            (-[WebFrame _smartDeleteRangeForProposedRange:]):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76107 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index c1cab40..cd1b927 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,59 @@
+2011-01-19  Levi Weintraub  <leviw at google.com>
+
+        Reviewed by Ryosuke Niwa.
+
+        Replaced rangeCompliantEquivalent with Position::parentAnchoredEquivalent
+        and simplified the logic a bit. Unfortunately, Tables and some legacy
+        editing positions still need to be handled specifically.
+
+        remove rangeCompliantEquivalent and replace it with Position methods
+        https://bugs.webkit.org/show_bug.cgi?id=25057
+
+        No new tests as this is a refactor that doesn't change behavior.
+
+        * WebCore.exp.in:
+        * dom/Document.cpp:
+        (WebCore::Document::caretRangeFromPoint):
+        * dom/Position.cpp:
+        (WebCore::Position::parentAnchoredEquivalent):
+        * dom/Position.h:
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::applyBlockStyle):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::insertNodeAt):
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::initializePositionData):
+        (WebCore::DeleteSelectionCommand::mergeParagraphs):
+        * editing/Editor.cpp:
+        (WebCore::Editor::textDirectionForSelection):
+        (WebCore::Editor::advanceToNextMisspelling):
+        * editing/InsertLineBreakCommand.cpp:
+        (WebCore::InsertLineBreakCommand::shouldUseBreakElement):
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::doApply):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::handleStyleSpansBeforeInsertion):
+        * editing/VisiblePosition.cpp:
+        (WebCore::makeRange):
+        (WebCore::setStart):
+        (WebCore::setEnd):
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::firstRange):
+        (WebCore::VisibleSelection::toNormalizedRange):
+        (WebCore::makeSearchRange):
+        * editing/htmlediting.cpp:
+        (WebCore::indexForVisiblePosition):
+        * editing/htmlediting.h:
+        * editing/visible_units.cpp:
+        (WebCore::previousBoundary):
+        (WebCore::nextBoundary):
+        * page/DOMSelection.cpp:
+        (WebCore::anchorPosition):
+        (WebCore::focusPosition):
+        (WebCore::basePosition):
+        (WebCore::extentPosition):
+
 2011-01-19  Peter Rybin  <peter.rybin at gmail.com>
 
         Reviewed by Yury Semikhatsky.
diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in
index a3132f5..a10d63e 100644
--- a/Source/WebCore/WebCore.exp.in
+++ b/Source/WebCore/WebCore.exp.in
@@ -545,7 +545,6 @@ __ZN7WebCore24createFragmentFromMarkupEPNS_8DocumentERKN3WTF6StringES5_NS_27Frag
 __ZN7WebCore24decodeURLEscapeSequencesERKN3WTF6StringE
 __ZN7WebCore24fileSystemRepresentationERKN3WTF6StringE
 __ZN7WebCore24notifyHistoryItemChangedE
-__ZN7WebCore24rangeCompliantEquivalentERKNS_8PositionE
 __ZN7WebCore25HistoryPropertyListWriter11releaseDataEv
 __ZN7WebCore25HistoryPropertyListWriter12writeObjectsERNS_30BinaryPropertyListObjectStreamE
 __ZN7WebCore25HistoryPropertyListWriter16writeHistoryItemERNS_30BinaryPropertyListObjectStreamEPNS_11HistoryItemE
@@ -1195,6 +1194,7 @@ __ZNK7WebCore8Document6domainEv
 __ZNK7WebCore8IntPointcv7CGPointEv
 __ZNK7WebCore8IntPointcv8_NSPointEv
 __ZNK7WebCore8Position10downstreamENS_27EditingBoundaryCrossingRuleE
+__ZNK7WebCore8Position24parentAnchoredEquivalentEv
 __ZNK7WebCore8Position25leadingWhitespacePositionENS_9EAffinityEb
 __ZNK7WebCore8Position26trailingWhitespacePositionENS_9EAffinityEb
 __ZNK7WebCore8Position8upstreamENS_27EditingBoundaryCrossingRuleE
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 3b84716..ce05a09 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -1301,7 +1301,7 @@ PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
     if (visiblePosition.isNull())
         return 0;
 
-    Position rangeCompliantPosition = rangeCompliantEquivalent(visiblePosition);
+    Position rangeCompliantPosition = visiblePosition.deepEquivalent().parentAnchoredEquivalent();
     return Range::create(this, rangeCompliantPosition, rangeCompliantPosition);
 }
 
diff --git a/Source/WebCore/dom/Position.cpp b/Source/WebCore/dom/Position.cpp
index be175aa..6749ca9 100644
--- a/Source/WebCore/dom/Position.cpp
+++ b/Source/WebCore/dom/Position.cpp
@@ -146,6 +146,27 @@ int Position::computeOffsetInContainerNode() const
     return 0;
 }
 
+// Neighbor-anchored positions are invalid DOM positions, so they need to be
+// fixed up before handing them off to the Range object.
+Position Position::parentAnchoredEquivalent() const
+{
+    if (!m_anchorNode)
+        return Position();
+    
+    // FIXME: This should only be necessary for legacy positions, but is also needed for positions before and after Tables
+    if (m_offset <= 0) {
+        if (m_anchorNode->parentNode() && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get())))
+            return positionInParentBeforeNode(m_anchorNode.get());
+        return Position(m_anchorNode, 0, PositionIsOffsetInAnchor);
+    }
+    if (!m_anchorNode->offsetInCharacters() && static_cast<unsigned>(m_offset) == m_anchorNode->childNodeCount()
+        && (editingIgnoresContent(m_anchorNode.get()) || isTableElement(m_anchorNode.get()))) {
+        return positionInParentAfterNode(m_anchorNode.get());
+    }
+
+    return Position(containerNode(), computeOffsetInContainerNode(), PositionIsOffsetInAnchor);
+}
+
 Node* Position::computeNodeBeforePosition() const
 {
     if (!m_anchorNode)
diff --git a/Source/WebCore/dom/Position.h b/Source/WebCore/dom/Position.h
index 4d3b5fe..8b41736 100644
--- a/Source/WebCore/dom/Position.h
+++ b/Source/WebCore/dom/Position.h
@@ -80,6 +80,7 @@ public:
     // will return img->parentNode() and img->nodeIndex() from these functions.
     Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent
     int computeOffsetInContainerNode() const;  // O(n) for before/after-anchored positions, O(1) for parent-anchored positions
+    Position parentAnchoredEquivalent() const; // Convenience method for DOM positions that also fixes up some positions for editing
 
     // Inline O(1) access for Positions which callers know to be parent-anchored
     int offsetInContainerNode() const
@@ -179,7 +180,7 @@ private:
     RefPtr<Node> m_anchorNode;
     // m_offset can be the offset inside m_anchorNode, or if editingIgnoresContent(m_anchorNode)
     // returns true, then other places in editing will treat m_offset == 0 as "before the anchor"
-    // and m_offset > 0 as "after the anchor node".  See rangeCompliantEquivalent for more info.
+    // and m_offset > 0 as "after the anchor node".  See parentAnchoredEquivalent for more info.
     int m_offset;
     unsigned m_anchorType : 2;
     bool m_isLegacyEditingPosition : 1;
diff --git a/Source/WebCore/editing/ApplyStyleCommand.cpp b/Source/WebCore/editing/ApplyStyleCommand.cpp
index 7227d7b..39350b9 100644
--- a/Source/WebCore/editing/ApplyStyleCommand.cpp
+++ b/Source/WebCore/editing/ApplyStyleCommand.cpp
@@ -569,8 +569,8 @@ void ApplyStyleCommand::applyBlockStyle(CSSMutableStyleDeclaration *style)
     // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoints.
     // Calculate start and end indices from the start of the tree that they're in.
     Node* scope = highestAncestor(visibleStart.deepEquivalent().node());
-    RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(scope), rangeCompliantEquivalent(visibleStart.deepEquivalent()));
-    RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope), rangeCompliantEquivalent(visibleEnd.deepEquivalent()));
+    RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
+    RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
     int startIndex = TextIterator::rangeLength(startRange.get(), true);
     int endIndex = TextIterator::rangeLength(endRange.get(), true);
 
diff --git a/Source/WebCore/editing/CompositeEditCommand.cpp b/Source/WebCore/editing/CompositeEditCommand.cpp
index 9e1dfca..552ed79 100644
--- a/Source/WebCore/editing/CompositeEditCommand.cpp
+++ b/Source/WebCore/editing/CompositeEditCommand.cpp
@@ -159,7 +159,7 @@ void CompositeEditCommand::insertNodeAt(PassRefPtr<Node> insertChild, const Posi
     ASSERT(isEditablePosition(editingPosition));
     // For editing positions like [table, 0], insert before the table,
     // likewise for replaced elements, brs, etc.
-    Position p = rangeCompliantEquivalent(editingPosition);
+    Position p = editingPosition.parentAnchoredEquivalent();
     Node* refChild = p.node();
     int offset = p.deprecatedEditingOffset();
     
@@ -905,13 +905,13 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
             
             startIndex = 0;
             if (startInParagraph) {
-                RefPtr<Range> startRange = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleStart.deepEquivalent()));
+                RefPtr<Range> startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquivalent().parentAnchoredEquivalent());
                 startIndex = TextIterator::rangeLength(startRange.get(), true);
             }
 
             endIndex = 0;
             if (endInParagraph) {
-                RefPtr<Range> endRange = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(visibleEnd.deepEquivalent()));
+                RefPtr<Range> endRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
                 endIndex = TextIterator::rangeLength(endRange.get(), true);
             }
         }
@@ -926,8 +926,8 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
     Position end = endOfParagraphToMove.deepEquivalent().upstream();
     
     // start and end can't be used directly to create a Range; they are "editing positions"
-    Position startRangeCompliant = rangeCompliantEquivalent(start);
-    Position endRangeCompliant = rangeCompliantEquivalent(end);
+    Position startRangeCompliant = start.parentAnchoredEquivalent();
+    Position endRangeCompliant = end.parentAnchoredEquivalent();
     RefPtr<Range> range = Range::create(document(), startRangeCompliant.node(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.node(), endRangeCompliant.deprecatedEditingOffset());
 
     // FIXME: This is an inefficient way to preserve style on nodes in the paragraph to move. It
@@ -974,7 +974,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
         updateLayout();
     }
 
-    RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document()->documentElement()), rangeCompliantEquivalent(destination.deepEquivalent())));
+    RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document()->documentElement()), destination.deepEquivalent().parentAnchoredEquivalent()));
     destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true);
 
     setEndingSelection(destination);
diff --git a/Source/WebCore/editing/DeleteSelectionCommand.cpp b/Source/WebCore/editing/DeleteSelectionCommand.cpp
index 5e6fd47..3ba5ae9 100644
--- a/Source/WebCore/editing/DeleteSelectionCommand.cpp
+++ b/Source/WebCore/editing/DeleteSelectionCommand.cpp
@@ -256,14 +256,14 @@ void DeleteSelectionCommand::initializePositionData()
         }
     }
     
-    // We must pass the positions through rangeCompliantEquivalent, since some editing positions
+    // We must pass call parentAnchoredEquivalent on the positions since some editing positions
     // that appear inside their nodes aren't really inside them.  [hr, 0] is one example.
-    // FIXME: rangeComplaintEquivalent should eventually be moved into enclosing element getters
+    // FIXME: parentAnchoredEquivalent should eventually be moved into enclosing element getters
     // like the one below, since editing functions should obviously accept editing positions.
     // FIXME: Passing false to enclosingNodeOfType tells it that it's OK to return a non-editable
     // node.  This was done to match existing behavior, but it seems wrong.
-    m_startBlock = enclosingNodeOfType(rangeCompliantEquivalent(m_downstreamStart), &isBlock, false);
-    m_endBlock = enclosingNodeOfType(rangeCompliantEquivalent(m_upstreamEnd), &isBlock, false);
+    m_startBlock = enclosingNodeOfType(m_downstreamStart.parentAnchoredEquivalent(), &isBlock, false);
+    m_endBlock = enclosingNodeOfType(m_upstreamEnd.parentAnchoredEquivalent(), &isBlock, false);
 }
 
 void DeleteSelectionCommand::saveTypingStyleState()
@@ -623,8 +623,8 @@ void DeleteSelectionCommand::mergeParagraphs()
         return;
     }
     
-    RefPtr<Range> range = Range::create(document(), rangeCompliantEquivalent(startOfParagraphToMove.deepEquivalent()), rangeCompliantEquivalent(endOfParagraphToMove.deepEquivalent()));
-    RefPtr<Range> rangeToBeReplaced = Range::create(document(), rangeCompliantEquivalent(mergeDestination.deepEquivalent()), rangeCompliantEquivalent(mergeDestination.deepEquivalent()));
+    RefPtr<Range> range = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
+    RefPtr<Range> rangeToBeReplaced = Range::create(document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
     if (!document()->frame()->editor()->client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
         return;
     
diff --git a/Source/WebCore/editing/Editor.cpp b/Source/WebCore/editing/Editor.cpp
index bea74d9..23b41ce 100644
--- a/Source/WebCore/editing/Editor.cpp
+++ b/Source/WebCore/editing/Editor.cpp
@@ -643,7 +643,7 @@ WritingDirection Editor::textDirectionForSelection(bool& hasNestedOrMultipleEmbe
     if (m_frame->selection()->isRange()) {
         end = m_frame->selection()->selection().end().upstream();
 
-        Node* pastLast = Range::create(m_frame->document(), rangeCompliantEquivalent(position), rangeCompliantEquivalent(end))->pastLastNode();
+        Node* pastLast = Range::create(m_frame->document(), position.parentAnchoredEquivalent(), end.parentAnchoredEquivalent())->pastLastNode();
         for (Node* n = node; n && n != pastLast; n = n->traverseNextNode()) {
             if (!n->isStyledElement())
                 continue;
@@ -1783,7 +1783,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
         if (position.isNull())
             return;
         
-        Position rangeCompliantPosition = rangeCompliantEquivalent(position);
+        Position rangeCompliantPosition = position.parentAnchoredEquivalent();
         spellingSearchRange->setStart(rangeCompliantPosition.node(), rangeCompliantPosition.deprecatedEditingOffset(), ec);
         startedWithSelection = false; // won't need to wrap
     }
diff --git a/Source/WebCore/editing/InsertLineBreakCommand.cpp b/Source/WebCore/editing/InsertLineBreakCommand.cpp
index 1194024..af8f2fc 100644
--- a/Source/WebCore/editing/InsertLineBreakCommand.cpp
+++ b/Source/WebCore/editing/InsertLineBreakCommand.cpp
@@ -82,7 +82,7 @@ bool InsertLineBreakCommand::shouldUseBreakElement(const Position& insertionPos)
     // An editing position like [input, 0] actually refers to the position before
     // the input element, and in that case we need to check the input element's
     // parent's renderer.
-    Position p(rangeCompliantEquivalent(insertionPos));
+    Position p(insertionPos.parentAnchoredEquivalent());
     return p.node()->renderer() && !p.node()->renderer()->style()->preserveNewline();
 }
 
diff --git a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
index 325ce47..1d50851 100644
--- a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
+++ b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
@@ -159,8 +159,8 @@ void InsertParagraphSeparatorCommand::doApply()
         affinity = endingSelection().affinity();
     }
     
-    // FIXME: The rangeCompliantEquivalent conversion needs to be moved into enclosingBlock.
-    Node* startBlockNode = enclosingBlock(rangeCompliantEquivalent(insertionPosition).node());
+    // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enclosingBlock.
+    Node* startBlockNode = enclosingBlock(insertionPosition.parentAnchoredEquivalent().containerNode());
     Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent();
     Element* startBlock = static_cast<Element*>(startBlockNode);
     if (!startBlockNode
diff --git a/Source/WebCore/editing/ReplaceSelectionCommand.cpp b/Source/WebCore/editing/ReplaceSelectionCommand.cpp
index 044ce63..24cfa41 100644
--- a/Source/WebCore/editing/ReplaceSelectionCommand.cpp
+++ b/Source/WebCore/editing/ReplaceSelectionCommand.cpp
@@ -568,7 +568,7 @@ static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const
     Node* sourceDocumentStyleSpan = topNode;
     RefPtr<Node> copiedRangeStyleSpan = sourceDocumentStyleSpan->firstChild();
 
-    RefPtr<EditingStyle> styleAtInsertionPos = EditingStyle::create(rangeCompliantEquivalent(insertionPos));
+    RefPtr<EditingStyle> styleAtInsertionPos = EditingStyle::create(insertionPos.parentAnchoredEquivalent());
     String styleText = styleAtInsertionPos->style()->cssText();
 
     // FIXME: This string comparison is a naive way of comparing two styles.
diff --git a/Source/WebCore/editing/VisiblePosition.cpp b/Source/WebCore/editing/VisiblePosition.cpp
index adfead1..5999fa6 100644
--- a/Source/WebCore/editing/VisiblePosition.cpp
+++ b/Source/WebCore/editing/VisiblePosition.cpp
@@ -597,8 +597,8 @@ PassRefPtr<Range> makeRange(const VisiblePosition &start, const VisiblePosition
     if (start.isNull() || end.isNull())
         return 0;
     
-    Position s = rangeCompliantEquivalent(start);
-    Position e = rangeCompliantEquivalent(end);
+    Position s = start.deepEquivalent().parentAnchoredEquivalent();
+    Position e = end.deepEquivalent().parentAnchoredEquivalent();
     return Range::create(s.node()->document(), s.node(), s.deprecatedEditingOffset(), e.node(), e.deprecatedEditingOffset());
 }
 
@@ -618,7 +618,7 @@ bool setStart(Range *r, const VisiblePosition &visiblePosition)
 {
     if (!r)
         return false;
-    Position p = rangeCompliantEquivalent(visiblePosition);
+    Position p = visiblePosition.deepEquivalent().parentAnchoredEquivalent();
     int code = 0;
     r->setStart(p.node(), p.deprecatedEditingOffset(), code);
     return code == 0;
@@ -628,7 +628,7 @@ bool setEnd(Range *r, const VisiblePosition &visiblePosition)
 {
     if (!r)
         return false;
-    Position p = rangeCompliantEquivalent(visiblePosition);
+    Position p = visiblePosition.deepEquivalent().parentAnchoredEquivalent();
     int code = 0;
     r->setEnd(p.node(), p.deprecatedEditingOffset(), code);
     return code == 0;
diff --git a/Source/WebCore/editing/VisibleSelection.cpp b/Source/WebCore/editing/VisibleSelection.cpp
index 4037670..035afb8 100644
--- a/Source/WebCore/editing/VisibleSelection.cpp
+++ b/Source/WebCore/editing/VisibleSelection.cpp
@@ -121,8 +121,8 @@ PassRefPtr<Range> VisibleSelection::firstRange() const
 {
     if (isNone())
         return 0;
-    Position start = rangeCompliantEquivalent(m_start);
-    Position end = rangeCompliantEquivalent(m_end);
+    Position start = m_start.parentAnchoredEquivalent();
+    Position end = m_end.parentAnchoredEquivalent();
     return Range::create(start.node()->document(), start, end);
 }
 
@@ -146,7 +146,7 @@ PassRefPtr<Range> VisibleSelection::toNormalizedRange() const
         // If the selection is a caret, move the range start upstream. This helps us match
         // the conventions of text editors tested, which make style determinations based
         // on the character before the caret, if any. 
-        s = rangeCompliantEquivalent(m_start.upstream());
+        s = m_start.upstream().parentAnchoredEquivalent();
         e = s;
     } else {
         // If the selection is a range, select the minimum range that encompasses the selection.
@@ -170,8 +170,8 @@ PassRefPtr<Range> VisibleSelection::toNormalizedRange() const
             s = e;
             e = tmp;
         }
-        s = rangeCompliantEquivalent(s);
-        e = rangeCompliantEquivalent(e);
+        s = s.parentAnchoredEquivalent();
+        e = e.parentAnchoredEquivalent();
     }
 
     // VisibleSelections are supposed to always be valid.  This constructor will ASSERT
@@ -204,7 +204,7 @@ static PassRefPtr<Range> makeSearchRange(const Position& pos)
     RefPtr<Range> searchRange(Range::create(d));
     ExceptionCode ec = 0;
 
-    Position start(rangeCompliantEquivalent(pos));
+    Position start(pos.parentAnchoredEquivalent());
     searchRange->selectNodeContents(boundary, ec);
     searchRange->setStart(start.node(), start.deprecatedEditingOffset(), ec);
 
diff --git a/Source/WebCore/editing/htmlediting.cpp b/Source/WebCore/editing/htmlediting.cpp
index cb4fd43..90db3ef 100644
--- a/Source/WebCore/editing/htmlediting.cpp
+++ b/Source/WebCore/editing/htmlediting.cpp
@@ -332,57 +332,9 @@ Node* enclosingBlock(Node* node)
     return static_cast<Element*>(enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock));
 }
 
-// Internally editing uses "invalid" positions for historical reasons.  For
-// example, in <div><img /></div>, Editing might use (img, 1) for the position
-// after <img>, but we have to convert that to (div, 1) before handing the
-// position to a Range object.  Ideally all internal positions should
-// be "range compliant" for simplicity.
-Position rangeCompliantEquivalent(const Position& pos)
-{
-    if (pos.isNull())
-        return Position();
-
-    Node* node = pos.node();
-
-    if (pos.deprecatedEditingOffset() <= 0) {
-        if (node->parentNode() && (editingIgnoresContent(node) || isTableElement(node)))
-            return positionInParentBeforeNode(node);
-        return Position(node, 0);
-    }
-
-    if (node->offsetInCharacters())
-        return Position(node, min(node->maxCharacterOffset(), pos.deprecatedEditingOffset()));
-
-    int maxCompliantOffset = node->childNodeCount();
-    if (pos.deprecatedEditingOffset() > maxCompliantOffset) {
-        if (node->parentNode())
-            return positionInParentAfterNode(node);
-
-        // there is no other option at this point than to
-        // use the highest allowed position in the node
-        return Position(node, maxCompliantOffset);
-    } 
-
-    // Editing should never generate positions like this.
-    if ((pos.deprecatedEditingOffset() < maxCompliantOffset) && editingIgnoresContent(node)) {
-        ASSERT_NOT_REACHED();
-        return node->parentNode() ? positionInParentBeforeNode(node) : Position(node, 0);
-    }
-    
-    if (pos.deprecatedEditingOffset() == maxCompliantOffset && (editingIgnoresContent(node) || isTableElement(node)))
-        return positionInParentAfterNode(node);
-    
-    return Position(pos);
-}
-
-Position rangeCompliantEquivalent(const VisiblePosition& vpos)
-{
-    return rangeCompliantEquivalent(vpos.deepEquivalent());
-}
-
 // This method is used to create positions in the DOM. It returns the maximum valid offset
 // in a node.  It returns 1 for some elements even though they do not have children, which
-// creates technically invalid DOM Positions.  Be sure to call rangeCompliantEquivalent
+// creates technically invalid DOM Positions.  Be sure to call parentAnchoredEquivalent
 // on a Position before using it to create a DOM Range, or an exception will be thrown.
 int lastOffsetForEditing(const Node* node)
 {
@@ -1082,7 +1034,7 @@ int indexForVisiblePosition(const VisiblePosition& visiblePosition)
         return 0;
     Position p(visiblePosition.deepEquivalent());
     RefPtr<Range> range = Range::create(p.node()->document(), firstPositionInNode(p.anchorNode()->document()->documentElement()),
-                                        rangeCompliantEquivalent(p));
+                                        p.parentAnchoredEquivalent());
     return TextIterator::rangeLength(range.get(), true);
 }
 
diff --git a/Source/WebCore/editing/htmlediting.h b/Source/WebCore/editing/htmlediting.h
index 1f6b986..0208dfb 100644
--- a/Source/WebCore/editing/htmlediting.h
+++ b/Source/WebCore/editing/htmlediting.h
@@ -101,9 +101,6 @@ bool isNodeInTextFormControl(Node* node);
     
 // Functions returning Position
     
-Position rangeCompliantEquivalent(const Position&);
-Position rangeCompliantEquivalent(const VisiblePosition&);
-    
 Position nextCandidate(const Position&);
 Position previousCandidate(const Position&);
     
diff --git a/Source/WebCore/editing/visible_units.cpp b/Source/WebCore/editing/visible_units.cpp
index 1a554b7..3582aa9 100644
--- a/Source/WebCore/editing/visible_units.cpp
+++ b/Source/WebCore/editing/visible_units.cpp
@@ -57,8 +57,8 @@ static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
         return VisiblePosition();
 
     Document* d = boundary->document();
-    Position start = rangeCompliantEquivalent(Position(boundary, 0));
-    Position end = rangeCompliantEquivalent(pos);
+    Position start = Position(boundary, 0).parentAnchoredEquivalent();
+    Position end = pos.parentAnchoredEquivalent();
     RefPtr<Range> searchRange = Range::create(d);
     
     Vector<UChar, 1024> string;
@@ -138,7 +138,7 @@ static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
 
     Document* d = boundary->document();
     RefPtr<Range> searchRange(d->createRange());
-    Position start(rangeCompliantEquivalent(pos));
+    Position start(pos.parentAnchoredEquivalent());
 
     Vector<UChar, 1024> string;
     unsigned prefixLength = 0;
diff --git a/Source/WebCore/page/DOMSelection.cpp b/Source/WebCore/page/DOMSelection.cpp
index 7691da4..dbb0944 100644
--- a/Source/WebCore/page/DOMSelection.cpp
+++ b/Source/WebCore/page/DOMSelection.cpp
@@ -76,23 +76,23 @@ const VisibleSelection& DOMSelection::visibleSelection() const
 static Position anchorPosition(const VisibleSelection& selection)
 {
     Position anchor = selection.isBaseFirst() ? selection.start() : selection.end();
-    return rangeCompliantEquivalent(anchor);
+    return anchor.parentAnchoredEquivalent();
 }
 
 static Position focusPosition(const VisibleSelection& selection)
 {
     Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
-    return rangeCompliantEquivalent(focus);
+    return focus.parentAnchoredEquivalent();
 }
 
 static Position basePosition(const VisibleSelection& selection)
 {
-    return rangeCompliantEquivalent(selection.base());
+    return selection.base().parentAnchoredEquivalent();
 }
 
 static Position extentPosition(const VisibleSelection& selection)
 {
-    return rangeCompliantEquivalent(selection.extent());
+    return selection.extent().parentAnchoredEquivalent();
 }
 
 Node* DOMSelection::anchorNode() const
diff --git a/Source/WebKit/mac/ChangeLog b/Source/WebKit/mac/ChangeLog
index c072537..f0f9020 100644
--- a/Source/WebKit/mac/ChangeLog
+++ b/Source/WebKit/mac/ChangeLog
@@ -1,3 +1,16 @@
+2011-01-19  Levi Weintraub  <leviw at google.com>
+
+        Reviewed by Ryosuke Niwa.
+
+        Updating to use Position::parentAnchoredEquivalent instead of
+        the old htmlediting rangeCompliantEquivalent.
+
+        remove rangeCompliantEquivalent and replace it with Position methods
+        https://bugs.webkit.org/show_bug.cgi?id=25057
+
+        * WebView/WebFrame.mm:
+        (-[WebFrame _smartDeleteRangeForProposedRange:]):
+
 2011-01-18  Chris Fleizach  <cfleizach at apple.com>
 
         Reviewed by Darin Adler.
diff --git a/Source/WebKit/mac/WebView/WebFrame.mm b/Source/WebKit/mac/WebView/WebFrame.mm
index 3dde06f..154156a 100644
--- a/Source/WebKit/mac/WebView/WebFrame.mm
+++ b/Source/WebKit/mac/WebView/WebFrame.mm
@@ -802,8 +802,8 @@ static inline WebDataSource *dataSource(DocumentLoader* loader)
     if (newEnd.isNull())
         newEnd = end;
 
-    newStart = rangeCompliantEquivalent(newStart);
-    newEnd = rangeCompliantEquivalent(newEnd);
+    newStart = newStart.parentAnchoredEquivalent();
+    newEnd = newEnd.parentAnchoredEquivalent();
 
     RefPtr<Range> range = _private->coreFrame->document()->createRange();
     int exception = 0;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list