Changeset 89952 in webkit


Ignore:
Timestamp:
Jun 28, 2011 1:07:31 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-06-28 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

Stop instantiating Position with PositionIsOffsetInAnchor in various files
https://bugs.webkit.org/show_bug.cgi?id=63384

Refactoring.

Removed many if conditions that compared the anchor type to Position::PositionIsOffsetInAnchor
because there were also checking that containerNode is a text node.

Also added Position::containerText() to avoid manually casting containerNode().

  • dom/Position.cpp: (WebCore::Position::Position): Added an assertion to ensure BeforeChildren/AfterChildren anchor type won't be used for a node whose contents is ignored by editing. (WebCore::Position::containerText): Added.
  • dom/Position.h:
  • editing/ApplyBlockElementCommand.cpp: (WebCore::isNewLineAtPosition): Removed a redundant comparison of anchor type. (WebCore::ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded): Since containerNode is always a text node when renderStyleOfEnclosingTextNode returns a render style, use new Position constructor that takes Text* and offset. (WebCore::ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfNeeded): Removed redundant comparison of anchor type and use new Position constructor that takes Text* and offset.
  • editing/ApplyStyleCommand.cpp: (WebCore::ApplyStyleCommand::splitTextAtStart): Replaced an assertion that compared anchor type by an assertion that the container node is a text node; use new constructor. (WebCore::ApplyStyleCommand::splitTextAtEnd): Ditto; also added early exits in the case script modified DOM. (WebCore::ApplyStyleCommand::splitTextElementAtStart): Ditto. (WebCore::ApplyStyleCommand::splitTextElementAtEnd): Ditto. (WebCore::ApplyStyleCommand::joinChildTextNodes): Use new constructor.
  • editing/CompositeEditCommand.cpp: (WebCore::Editor::replaceSelectedTextInNode): Calls containerText instead of manually casting containerNode.
  • editing/Editor.cpp: (WebCore::Editor::canDeleteRange): Call Range::startPosition instead of manually instantiating Position by calling startContainer and startOffset.
  • editing/FrameSelection.cpp: (WebCore::FrameSelection::setSelectedRange): Ditto.
  • editing/InsertTextCommand.cpp: (WebCore::InsertTextCommand::input): Calls containerText instead of manually casting containerNode.
  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::doApply): Calls containerText instead of manually casting containerNode.
  • editing/VisiblePosition.cpp: (WebCore::VisiblePosition::characterAfter): Removed a redundant anchor type comparison. (WebCore::startVisiblePosition): Call Range::startPosition instead of startContainer and startOffset. (WebCore::endVisiblePosition): Call Range::endPosition instead of endContainer and endOffset.
  • editing/htmlediting.cpp: (WebCore::firstInSpecialElement): Call containerNode() to address <rdar://problem/5027702>. (WebCore::lastInSpecialElement): Ditto; use new constructor.
  • editing/visible_units.cpp: (WebCore::endPositionForLine): Use new constructor. (WebCore::startOfParagraph): Ditto. (WebCore::endOfParagraph): Ditto.
Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r89951 r89952  
     12011-06-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Stop instantiating Position with PositionIsOffsetInAnchor in various files
     6        https://bugs.webkit.org/show_bug.cgi?id=63384
     7
     8        Refactoring.
     9
     10        Removed many if conditions that compared the anchor type to Position::PositionIsOffsetInAnchor
     11        because there were also checking that containerNode is a text node.
     12
     13        Also added Position::containerText() to avoid manually casting containerNode().
     14
     15        * dom/Position.cpp:
     16        (WebCore::Position::Position): Added an assertion to ensure BeforeChildren/AfterChildren
     17        anchor type won't be used for a node whose contents is ignored by editing.
     18        (WebCore::Position::containerText): Added.
     19        * dom/Position.h:
     20        * editing/ApplyBlockElementCommand.cpp:
     21        (WebCore::isNewLineAtPosition): Removed a redundant comparison of anchor type.
     22        (WebCore::ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded): Since containerNode
     23        is always a text node when renderStyleOfEnclosingTextNode returns a render style, use new Position
     24        constructor that takes Text* and offset.
     25        (WebCore::ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfNeeded): Removed redundant
     26        comparison of anchor type and use new Position constructor that takes Text* and offset.
     27        * editing/ApplyStyleCommand.cpp:
     28        (WebCore::ApplyStyleCommand::splitTextAtStart): Replaced an assertion that compared anchor type by
     29        an assertion that the container node is a text node; use new constructor.
     30        (WebCore::ApplyStyleCommand::splitTextAtEnd): Ditto; also added early exits in the case script
     31        modified DOM.
     32        (WebCore::ApplyStyleCommand::splitTextElementAtStart): Ditto.
     33        (WebCore::ApplyStyleCommand::splitTextElementAtEnd): Ditto.
     34        (WebCore::ApplyStyleCommand::joinChildTextNodes): Use new constructor.
     35        * editing/CompositeEditCommand.cpp:
     36        (WebCore::Editor::replaceSelectedTextInNode): Calls containerText instead of manually casting containerNode.
     37        * editing/Editor.cpp:
     38        (WebCore::Editor::canDeleteRange): Call Range::startPosition instead of manually instantiating Position
     39        by calling startContainer and startOffset.
     40        * editing/FrameSelection.cpp:
     41        (WebCore::FrameSelection::setSelectedRange): Ditto.
     42        * editing/InsertTextCommand.cpp:
     43        (WebCore::InsertTextCommand::input): Calls containerText instead of manually casting containerNode.
     44        * editing/ReplaceSelectionCommand.cpp:
     45        (WebCore::ReplaceSelectionCommand::doApply): Calls containerText instead of manually casting containerNode.
     46        * editing/VisiblePosition.cpp:
     47        (WebCore::VisiblePosition::characterAfter): Removed a redundant anchor type comparison.
     48        (WebCore::startVisiblePosition): Call Range::startPosition instead of startContainer and startOffset.
     49        (WebCore::endVisiblePosition): Call Range::endPosition instead of endContainer and endOffset.
     50        * editing/htmlediting.cpp:
     51        (WebCore::firstInSpecialElement): Call containerNode() to address <rdar://problem/5027702>.
     52        (WebCore::lastInSpecialElement): Ditto; use new constructor.
     53        * editing/visible_units.cpp:
     54        (WebCore::endPositionForLine): Use new constructor.
     55        (WebCore::startOfParagraph): Ditto.
     56        (WebCore::endOfParagraph): Ditto.
     57
    1582011-06-28  Rob Buis  <rbuis@rim.com>
    259
  • trunk/Source/WebCore/dom/Position.cpp

    r89683 r89952  
    9292    ASSERT(!m_anchorNode || !m_anchorNode->isShadowRoot());
    9393    ASSERT(anchorType != PositionIsOffsetInAnchor);
    94     ASSERT(!((anchorType == PositionIsBeforeChildren || anchorType == PositionIsAfterChildren) && m_anchorNode->isTextNode()));
     94    ASSERT(!((anchorType == PositionIsBeforeChildren || anchorType == PositionIsAfterChildren)
     95        && (m_anchorNode->isTextNode() || editingIgnoresContent(m_anchorNode.get()))));
    9596}
    9697
     
    144145    case PositionIsAfterAnchor:
    145146        return m_anchorNode->nonShadowBoundaryParentNode();
     147    }
     148    ASSERT_NOT_REACHED();
     149    return 0;
     150}
     151
     152Text* Position::containerText() const
     153{
     154    switch (anchorType()) {
     155    case PositionIsOffsetInAnchor:
     156        return m_anchorNode && m_anchorNode->isTextNode() ? static_cast<Text*>(m_anchorNode.get()) : 0;
     157    case PositionIsBeforeAnchor:
     158    case PositionIsAfterAnchor:
     159        return 0;
     160    case PositionIsBeforeChildren:
     161    case PositionIsAfterChildren:
     162        ASSERT(!m_anchorNode || !m_anchorNode->isTextNode());
     163        return 0;
    146164    }
    147165    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/dom/Position.h

    r89683 r89952  
    9797    // will return img->parentNode() and img->nodeIndex() from these functions.
    9898    Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent
     99    Text* containerText() const;
     100
    99101    int computeOffsetInContainerNode() const;  // O(n) for before/after-anchored positions, O(1) for parent-anchored positions
    100102    Position parentAnchoredEquivalent() const; // Convenience method for DOM positions that also fixes up some positions for editing
  • trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp

    r86325 r89952  
    151151static bool isNewLineAtPosition(const Position& position)
    152152{
    153     if (position.anchorType() != Position::PositionIsOffsetInAnchor)
    154         return false;
    155 
    156153    Node* textNode = position.containerNode();
    157154    int offset = position.offsetInContainerNode();
     
    182179    end = endOfCurrentParagraph.deepEquivalent();
    183180
    184     RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start);
    185181    bool isStartAndEndOnSameNode = false;
    186     if (startStyle) {
    187         isStartAndEndOnSameNode = renderStyleOfEnclosingTextNode(end) && start.deprecatedNode() == end.deprecatedNode();
    188         bool isStartAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && start.deprecatedNode() == m_endOfLastParagraph.deprecatedNode();
     182    if (RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start)) {
     183        isStartAndEndOnSameNode = renderStyleOfEnclosingTextNode(end) && start.containerNode() == end.containerNode();
     184        bool isStartAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.containerNode();
    189185
    190186        // Avoid obtanining the start of next paragraph for start
     
    195191        if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) {
    196192            int startOffset = start.offsetInContainerNode();
    197             splitTextNode(static_cast<Text*>(start.deprecatedNode()), startOffset);
    198             start = firstPositionInOrBeforeNode(start.deprecatedNode());
     193            Text* startText = start.containerText();
     194            splitTextNode(startText, startOffset);
     195            start = firstPositionInNode(startText);
    199196            if (isStartAndEndOnSameNode) {
    200197                ASSERT(end.offsetInContainerNode() >= startOffset);
    201                 end = Position(end.deprecatedNode(), end.offsetInContainerNode() - startOffset, Position::PositionIsOffsetInAnchor);
     198                end = Position(startText, end.offsetInContainerNode() - startOffset);
    202199            }
    203200            if (isStartAndEndOfLastParagraphOnSameNode) {
    204201                ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffset);
    205                 m_endOfLastParagraph = Position(m_endOfLastParagraph.deprecatedNode(), m_endOfLastParagraph.offsetInContainerNode() - startOffset,
    206                     Position::PositionIsOffsetInAnchor);
     202                m_endOfLastParagraph = Position(startText, m_endOfLastParagraph.offsetInContainerNode() - startOffset);
    207203            }
    208204        }
    209205    }
    210206
    211     RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end);
    212     if (endStyle) {
     207    if (RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end)) {
    213208        bool isEndAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.deprecatedNode();
    214209        // Include \n at the end of line if we're at an empty paragraph
    215         if (endStyle->preserveNewline() && start == end
    216             && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) {
     210        if (endStyle->preserveNewline() && start == end && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) {
    217211            int endOffset = end.offsetInContainerNode();
    218212            if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end))
    219                 end = Position(end.deprecatedNode(), endOffset + 1, Position::PositionIsOffsetInAnchor);
     213                end = Position(end.containerText(), endOffset + 1);
    220214            if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNode() >= m_endOfLastParagraph.offsetInContainerNode())
    221215                m_endOfLastParagraph = end;
     
    223217
    224218        // If end is in the middle of a text node, split.
    225         if (!endStyle->collapseWhiteSpace() && end.offsetInContainerNode()
    226             && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) {
    227             splitTextNode(static_cast<Text*>(end.deprecatedNode()), end.offsetInContainerNode());
     219        if (!endStyle->collapseWhiteSpace() && end.offsetInContainerNode() && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) {
     220            RefPtr<Text> endContainer = end.containerText();
     221            splitTextNode(endContainer, end.offsetInContainerNode());
    228222            if (isStartAndEndOnSameNode)
    229                 start = firstPositionInOrBeforeNode(end.deprecatedNode()->previousSibling());
     223                start = firstPositionInOrBeforeNode(endContainer->previousSibling());
    230224            if (isEndAndEndOfLastParagraphOnSameNode) {
    231225                if (m_endOfLastParagraph.offsetInContainerNode() == end.offsetInContainerNode())
    232                     m_endOfLastParagraph = lastPositionInNode(end.deprecatedNode()->previousSibling());
     226                    m_endOfLastParagraph = lastPositionInOrAfterNode(endContainer->previousSibling());
    233227                else
    234                     m_endOfLastParagraph = Position(end.deprecatedNode(), m_endOfLastParagraph.offsetInContainerNode() - end.offsetInContainerNode(),
    235                                                     Position::PositionIsOffsetInAnchor);
     228                    m_endOfLastParagraph = Position(endContainer, m_endOfLastParagraph.offsetInContainerNode() - end.offsetInContainerNode());
    236229            }
    237             end = lastPositionInNode(end.deprecatedNode()->previousSibling());
     230            end = lastPositionInNode(endContainer->previousSibling());
    238231        }
    239232    }
     
    248241        return endOfNextParagraph;
    249242
    250     RefPtr<Node> containerNode = position.containerNode();
    251     if (!style->preserveNewline() || !position.offsetInContainerNode()
    252         || !isNewLineAtPosition(Position(containerNode.get(), 0, Position::PositionIsOffsetInAnchor)))
     243    RefPtr<Text> text = position.containerText();
     244    if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNewLineAtPosition(firstPositionInNode(text.get())))
    253245        return endOfNextParagraph;
    254246
     
    256248    // If endOfNextParagraph was pointing at this same text node, endOfNextParagraph will be shifted by one paragraph.
    257249    // Avoid this by splitting "\n"
    258     splitTextNode(static_cast<Text*>(containerNode.get()), 1);
    259 
    260     if (start.anchorType() == Position::PositionIsOffsetInAnchor && containerNode.get() == start.containerNode()) {
     250    splitTextNode(text, 1);
     251
     252    if (text == start.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) {
    261253        ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode());
    262         start = Position(containerNode->previousSibling(), start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
    263     }
    264     if (end.anchorType() == Position::PositionIsOffsetInAnchor && containerNode.get() == end.containerNode()) {
     254        start = Position(static_cast<Text*>(text->previousSibling()), start.offsetInContainerNode());
     255    }
     256    if (text == end.containerNode() && text->previousSibling() && text->previousSibling()->isTextNode()) {
    265257        ASSERT(end.offsetInContainerNode() < position.offsetInContainerNode());
    266         end = Position(containerNode->previousSibling(), end.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
    267     }
    268     if (m_endOfLastParagraph.anchorType() == Position::PositionIsOffsetInAnchor && containerNode.get() == m_endOfLastParagraph.containerNode()) {
    269         if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInContainerNode())
    270             m_endOfLastParagraph = Position(containerNode->previousSibling(), m_endOfLastParagraph.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
    271         else
    272             m_endOfLastParagraph = Position(containerNode, m_endOfLastParagraph.offsetInContainerNode() - 1, Position::PositionIsOffsetInAnchor);
    273     }
    274 
    275     return Position(containerNode.get(), position.offsetInContainerNode() - 1, Position::PositionIsOffsetInAnchor);
     258        end = Position(static_cast<Text*>(text->previousSibling()), end.offsetInContainerNode());
     259    }
     260    if (text == m_endOfLastParagraph.containerNode()) {
     261        if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInContainerNode()) {
     262            // We can only fix endOfLastParagraph if the previous node was still text and hasn't been modified by script.
     263            if (text->previousSibling()->isTextNode()
     264                && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= static_cast<Text*>(text->previousSibling())->length())
     265                m_endOfLastParagraph = Position(static_cast<Text*>(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
     266        } else
     267            m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.offsetInContainerNode() - 1);
     268    }
     269
     270    return Position(text.get(), position.offsetInContainerNode() - 1);
    276271}
    277272
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r89283 r89952  
    11181118void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position& end)
    11191119{
    1120     ASSERT(start.anchorType() == Position::PositionIsOffsetInAnchor);
     1120    ASSERT(start.containerNode()->isTextNode());
    11211121
    11221122    Position newEnd;
    11231123    if (end.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode())
    1124         newEnd = Position(end.containerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
     1124        newEnd = Position(end.containerText(), end.offsetInContainerNode() - start.offsetInContainerNode());
    11251125    else
    11261126        newEnd = end;
    11271127
    1128     Text* text = static_cast<Text*>(start.deprecatedNode());
     1128    RefPtr<Text> text = start.containerText();
    11291129    splitTextNode(text, start.offsetInContainerNode());
    1130     updateStartEnd(firstPositionInNode(start.deprecatedNode()), newEnd);
     1130    updateStartEnd(firstPositionInNode(text.get()), newEnd);
    11311131}
    11321132
    11331133void ApplyStyleCommand::splitTextAtEnd(const Position& start, const Position& end)
    11341134{
    1135     ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor);
     1135    ASSERT(end.containerNode()->isTextNode());
    11361136
    11371137    bool shouldUpdateStart = start.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode();
     
    11401140
    11411141    Node* prevNode = text->previousSibling();
    1142     ASSERT(prevNode);
    1143     Position newStart = shouldUpdateStart ? Position(prevNode, start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor) : start;
     1142    if (!prevNode || !prevNode->isTextNode())
     1143        return;
     1144
     1145    Position newStart = shouldUpdateStart ? Position(static_cast<Text*>(prevNode), start.offsetInContainerNode()) : start;
    11441146    updateStartEnd(newStart, lastPositionInNode(prevNode));
    11451147}
     
    11471149void ApplyStyleCommand::splitTextElementAtStart(const Position& start, const Position& end)
    11481150{
    1149     ASSERT(start.anchorType() == Position::PositionIsOffsetInAnchor);
     1151    ASSERT(start.containerNode()->isTextNode());
    11501152
    11511153    Position newEnd;
    1152     if (end.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode())
    1153         newEnd = Position(end.containerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
     1154    if (start.containerNode() == end.containerNode())
     1155        newEnd = Position(end.containerText(), end.offsetInContainerNode() - start.offsetInContainerNode());
    11541156    else
    11551157        newEnd = end;
    11561158
    1157     Text* text = static_cast<Text*>(start.deprecatedNode());
    1158     splitTextNodeContainingElement(text, start.deprecatedEditingOffset());
    1159     updateStartEnd(Position(start.deprecatedNode()->parentNode(), start.deprecatedNode()->nodeIndex(), Position::PositionIsOffsetInAnchor), newEnd);
     1159    splitTextNodeContainingElement(start.containerText(), start.offsetInContainerNode());
     1160    updateStartEnd(positionBeforeNode(start.containerNode()), newEnd);
    11601161}
    11611162
    11621163void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Position& end)
    11631164{
    1164     ASSERT(end.anchorType() == Position::PositionIsOffsetInAnchor);
    1165 
    1166     bool shouldUpdateStart = start.anchorType() == Position::PositionIsOffsetInAnchor && start.containerNode() == end.containerNode();
    1167     Text* text = static_cast<Text*>(end.deprecatedNode());
    1168     splitTextNodeContainingElement(text, end.deprecatedEditingOffset());
    1169 
    1170     Node* prevNode = text->parentNode()->previousSibling()->lastChild();
    1171     ASSERT(prevNode);
    1172     Position newStart = shouldUpdateStart ? Position(prevNode, start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor) : start;
    1173     updateStartEnd(newStart, Position(prevNode->parentNode(), prevNode->nodeIndex() + 1, Position::PositionIsOffsetInAnchor));
     1165    ASSERT(end.containerNode()->isTextNode());
     1166
     1167    bool shouldUpdateStart = start.containerNode() == end.containerNode();
     1168    splitTextNodeContainingElement(end.containerText(), end.offsetInContainerNode());
     1169
     1170    Node* parentElement = end.containerNode()->parentNode();
     1171    if (!parentElement || !parentElement->previousSibling())
     1172        return;
     1173    Node* firstTextNode = parentElement->previousSibling()->lastChild();
     1174    if (!firstTextNode || !firstTextNode->isTextNode())
     1175        return;
     1176
     1177    Position newStart = shouldUpdateStart ? Position(static_cast<Text*>(firstTextNode), start.offsetInContainerNode()) : start;
     1178    updateStartEnd(newStart, positionAfterNode(firstTextNode));
    11741179}
    11751180
     
    14811486            Text* nextText = static_cast<Text *>(next);
    14821487            if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode())
    1483                 newStart = Position(childText, childText->length() + start.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
     1488                newStart = Position(childText, childText->length() + start.offsetInContainerNode());
    14841489            if (end.anchorType() == Position::PositionIsOffsetInAnchor && next == end.containerNode())
    1485                 newEnd = Position(childText, childText->length() + end.offsetInContainerNode(), Position::PositionIsOffsetInAnchor);
     1490                newEnd = Position(childText, childText->length() + end.offsetInContainerNode());
    14861491            String textToMove = nextText->data();
    14871492            insertTextIntoNode(childText, childText->length(), textToMove);
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r89844 r89952  
    321321        return Position();
    322322
    323     RefPtr<Text> textNode = static_cast<Text*>(start.containerNode());
     323    RefPtr<Text> textNode = start.containerText();
    324324    replaceTextInNode(textNode, start.offsetInContainerNode(), end.offsetInContainerNode() - start.offsetInContainerNode(), text);
    325325
  • trunk/Source/WebCore/editing/Editor.cpp

    r88211 r89952  
    267267   
    268268    if (range->collapsed(ec)) {
    269         VisiblePosition start(Position(startContainer, range->startOffset(ec), Position::PositionIsOffsetInAnchor), DOWNSTREAM);
     269        VisiblePosition start(range->startPosition(), DOWNSTREAM);
    270270        VisiblePosition previous = start.previous();
    271271        // FIXME: We sometimes allow deletions at the start of editable roots, like when the caret is in an empty list item.
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r89318 r89952  
    14631463bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool closeTyping)
    14641464{
    1465     if (!range)
    1466         return false;
    1467 
    1468     ExceptionCode ec = 0;
    1469     Node* startContainer = range->startContainer(ec);
    1470     if (ec)
    1471         return false;
    1472 
    1473     Node* endContainer = range->endContainer(ec);
    1474     if (ec)
    1475         return false;
    1476    
    1477     ASSERT(startContainer);
    1478     ASSERT(endContainer);
    1479     ASSERT(startContainer->document() == endContainer->document());
    1480    
     1465    if (!range || !range->startContainer() || !range->endContainer())
     1466        return false;
     1467    ASSERT(range->startContainer()->document() == range->endContainer()->document());
     1468
    14811469    m_frame->document()->updateLayoutIgnorePendingStylesheets();
    14821470
    14831471    // Non-collapsed ranges are not allowed to start at the end of a line that is wrapped,
    14841472    // they start at the beginning of the next line instead
     1473    ExceptionCode ec = 0;
    14851474    bool collapsed = range->collapsed(ec);
    14861475    if (ec)
    14871476        return false;
    1488    
    1489     int startOffset = range->startOffset(ec);
    1490     if (ec)
    1491         return false;
    1492 
    1493     int endOffset = range->endOffset(ec);
    1494     if (ec)
    1495         return false;
    1496    
     1477
    14971478    // FIXME: Can we provide extentAffinity?
    1498     VisiblePosition visibleStart(Position(startContainer, startOffset, Position::PositionIsOffsetInAnchor), collapsed ? affinity : DOWNSTREAM);
    1499     VisiblePosition visibleEnd(Position(endContainer, endOffset, Position::PositionIsOffsetInAnchor), SEL_DEFAULT_AFFINITY);
    1500     SetSelectionOptions options = ClearTypingStyle;
    1501     if (closeTyping)
    1502         options |= CloseTyping;
    1503     setSelection(VisibleSelection(visibleStart, visibleEnd), options);
     1479    VisiblePosition visibleStart(range->startPosition(), collapsed ? affinity : DOWNSTREAM);
     1480    VisiblePosition visibleEnd(range->endPosition(), SEL_DEFAULT_AFFINITY);
     1481    setSelection(VisibleSelection(visibleStart, visibleEnd), ClearTypingStyle | (closeTyping ? CloseTyping : 0));
    15041482    return true;
    15051483}
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r89844 r89952  
    158158        if (placeholder.isNotNull())
    159159            removePlaceholderAt(placeholder);
    160         RefPtr<Text> textNode = static_cast<Text*>(startPosition.containerNode());
     160        RefPtr<Text> textNode = startPosition.containerText();
    161161        const unsigned offset = startPosition.offsetInContainerNode();
    162162
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r89505 r89952  
    940940    if (!m_matchStyle && !enclosingList(insertionPos.containerNode()) && isStyleSpan(fragment.firstChild())) {
    941941        if (insertionPos.containerNode()->isTextNode() && insertionPos.offsetInContainerNode() && !insertionPos.atLastEditingPositionForNode()) {
    942             splitTextNodeContainingElement(static_cast<Text*>(insertionPos.containerNode()), insertionPos.offsetInContainerNode());
     942            splitTextNodeContainingElement(insertionPos.containerText(), insertionPos.offsetInContainerNode());
    943943            insertionPos = firstPositionInNode(insertionPos.containerNode());
    944944        }
  • trunk/Source/WebCore/editing/VisiblePosition.cpp

    r89683 r89952  
    553553        break;
    554554    }
    555     Text* textNode = static_cast<Text*>(pos.containerNode());
    556     unsigned offset = pos.anchorType() == Position::PositionIsOffsetInAnchor ? pos.offsetInContainerNode() : 0;
     555    unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode());
     556    Text* textNode = pos.containerText();
    557557    unsigned length = textNode->length();
    558558    if (offset >= length)
     
    650650VisiblePosition startVisiblePosition(const Range *r, EAffinity affinity)
    651651{
    652     int exception = 0;
    653     return VisiblePosition(Position(r->startContainer(exception), r->startOffset(exception), Position::PositionIsOffsetInAnchor), affinity);
     652    return VisiblePosition(r->startPosition(), affinity);
    654653}
    655654
    656655VisiblePosition endVisiblePosition(const Range *r, EAffinity affinity)
    657656{
    658     int exception = 0;
    659     return VisiblePosition(Position(r->endContainer(exception), r->endOffset(exception), Position::PositionIsOffsetInAnchor), affinity);
     657    return VisiblePosition(r->endPosition(), affinity);
    660658}
    661659
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r89283 r89952  
    403403static Node* firstInSpecialElement(const Position& pos)
    404404{
    405     // FIXME: This begins at pos.deprecatedNode(), which doesn't necessarily contain pos (suppose pos was [img, 0]).  See <rdar://problem/5027702>.
    406     Node* rootEditableElement = pos.deprecatedNode()->rootEditableElement();
     405    Node* rootEditableElement = pos.containerNode()->rootEditableElement();
    407406    for (Node* n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode())
    408407        if (isSpecialElement(n)) {
     
    419418static Node* lastInSpecialElement(const Position& pos)
    420419{
    421     // FIXME: This begins at pos.deprecatedNode(), which doesn't necessarily contain pos (suppose pos was [img, 0]).  See <rdar://problem/5027702>.
    422     Node* rootEditableElement = pos.deprecatedNode()->rootEditableElement();
     420    Node* rootEditableElement = pos.containerNode()->rootEditableElement();
    423421    for (Node* n = pos.deprecatedNode(); n && n->rootEditableElement() == rootEditableElement; n = n->parentNode())
    424422        if (isSpecialElement(n)) {
    425423            VisiblePosition vPos = VisiblePosition(pos, DOWNSTREAM);
    426             VisiblePosition lastInElement = VisiblePosition(Position(n, n->childNodeCount(), Position::PositionIsOffsetInAnchor), DOWNSTREAM);
     424            VisiblePosition lastInElement = VisiblePosition(lastPositionInOrAfterNode(n), DOWNSTREAM);
    427425            if (isTableElement(n) && vPos == lastInElement.previous())
    428426                return n;
  • trunk/Source/WebCore/editing/visible_units.cpp

    r89505 r89952  
    438438    if (endNode->hasTagName(brTag)) {
    439439        pos = positionBeforeNode(endNode);
    440     } else if (endBox->isInlineTextBox()) {
    441         InlineTextBox *endTextBox = static_cast<InlineTextBox *>(endBox);
     440    } else if (endBox->isInlineTextBox() && endNode->isTextNode()) {
     441        InlineTextBox* endTextBox = static_cast<InlineTextBox *>(endBox);
    442442        int endOffset = endTextBox->start();
    443443        if (!endTextBox->isLineBreak())
    444444            endOffset += endTextBox->len();
    445         pos = Position(endNode, endOffset, Position::PositionIsOffsetInAnchor);
     445        pos = Position(static_cast<Text*>(endNode), endOffset);
    446446    } else
    447447        pos = positionAfterNode(endNode);
     
    794794
    795795        if (r->isText() && r->caretMaxRenderedOffset() > 0) {
     796            ASSERT(n->isTextNode());
    796797            type = Position::PositionIsOffsetInAnchor;
    797798            if (style->preserveNewline()) {
     
    801802                if (n == startNode && o < i)
    802803                    i = max(0, o);
    803                 while (--i >= 0)
     804                while (--i >= 0) {
    804805                    if (chars[i] == '\n')
    805                         return VisiblePosition(Position(n, i + 1, Position::PositionIsOffsetInAnchor), DOWNSTREAM);
     806                        return VisiblePosition(Position(static_cast<Text*>(n), i + 1), DOWNSTREAM);
     807                }
    806808            }
    807809            node = n;
     
    816818    }
    817819
    818     if (type == Position::PositionIsOffsetInAnchor)
     820    if (type == Position::PositionIsOffsetInAnchor) {
     821        ASSERT(type != Position::PositionIsOffsetInAnchor || !offset);
    819822        return VisiblePosition(Position(node, offset, type), DOWNSTREAM);
    820    
     823    }
     824
    821825    return VisiblePosition(Position(node, type), DOWNSTREAM);
    822826}
     
    868872        // FIXME: We avoid returning a position where the renderer can't accept the caret.
    869873        if (r->isText() && r->caretMaxRenderedOffset() > 0) {
     874            ASSERT(n->isTextNode());
    870875            int length = toRenderText(r)->textLength();
    871876            type = Position::PositionIsOffsetInAnchor;
     
    873878                const UChar* chars = toRenderText(r)->characters();
    874879                int o = n == startNode ? offset : 0;
    875                 for (int i = o; i < length; ++i)
     880                for (int i = o; i < length; ++i) {
    876881                    if (chars[i] == '\n')
    877                         return VisiblePosition(Position(n, i, Position::PositionIsOffsetInAnchor), DOWNSTREAM);
     882                        return VisiblePosition(Position(static_cast<Text*>(n), i), DOWNSTREAM);
     883                }
    878884            }
    879885            node = n;
Note: See TracChangeset for help on using the changeset viewer.