Changeset 48235 in webkit


Ignore:
Timestamp:
Sep 9, 2009, 4:25:53 PM (16 years ago)
Author:
eric@webkit.org
Message:

2009-07-30 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Add more position constructors
positionBeforeNode, positionAfterNode
firstPositionInNode, lastPositionInNode
https://bugs.webkit.org/show_bug.cgi?id=25494

I also added a lastOffsetInNode and deployed it to a couple places.

There are no callers to these new constructors yet, but those
will be coming in future patches.

  • dom/Position.cpp: (WebCore::Position::computeOffsetInContainerNode):
  • dom/Position.h: (WebCore::positionBeforeNode): (WebCore::positionAfterNode): (WebCore::lastOffsetInNode): (WebCore::firstPositionInNode): (WebCore::lastPositionInNode):
  • editing/ApplyStyleCommand.cpp:
  • editing/TextIterator.cpp: (WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator):
  • editing/htmlediting.cpp: (WebCore::lastOffsetForEditing):
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r48234 r48235  
    112009-07-30  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Add more position constructors
     6        positionBeforeNode, positionAfterNode
     7        firstPositionInNode, lastPositionInNode
     8        https://bugs.webkit.org/show_bug.cgi?id=25494
     9
     10        I also added a lastOffsetInNode and deployed it to a couple places.
     11
     12        There are no callers to these new constructors yet, but those
     13        will be coming in future patches.
     14
     15        * dom/Position.cpp:
     16        (WebCore::Position::computeOffsetInContainerNode):
     17        * dom/Position.h:
     18        (WebCore::positionBeforeNode):
     19        (WebCore::positionAfterNode):
     20        (WebCore::lastOffsetInNode):
     21        (WebCore::firstPositionInNode):
     22        (WebCore::lastPositionInNode):
     23        * editing/ApplyStyleCommand.cpp:
     24        * editing/TextIterator.cpp:
     25        (WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator):
     26        * editing/htmlediting.cpp:
     27        (WebCore::lastOffsetForEditing):
     28
     292009-04-30  Eric Seidel  <eric@webkit.org>
    230
    331        Reviewed by Adam Barth.
  • trunk/WebCore/dom/Position.cpp

    r48233 r48235  
    139139    switch (anchorType()) {
    140140    case PositionIsOffsetInAnchor:
    141     {
    142         int maximumValidOffset = m_anchorNode->offsetInCharacters() ? m_anchorNode->maxCharacterOffset() : m_anchorNode->childNodeCount();
    143         return std::min(maximumValidOffset, m_offset);
    144     }
     141        return std::min(lastOffsetInNode(m_anchorNode.get()), m_offset);
    145142    case PositionIsBeforeAnchor:
    146143        return m_anchorNode->nodeIndex();
  • trunk/WebCore/dom/Position.h

    r48234 r48235  
    209209}
    210210
     211// positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1)
     212inline Position positionBeforeNode(Node* anchorNode)
     213{
     214    ASSERT(anchorNode);
     215    return Position(anchorNode, Position::PositionIsBeforeAnchor);
     216}
     217
     218inline Position positionAfterNode(Node* anchorNode)
     219{
     220    ASSERT(anchorNode);
     221    return Position(anchorNode, Position::PositionIsAfterAnchor);
     222}
     223
     224inline int lastOffsetInNode(Node* node)
     225{
     226    return node->offsetInCharacters() ? node->maxCharacterOffset() : node->childNodeCount();
     227}
     228
     229// firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to childNodeCount()
     230inline Position firstPositionInNode(Node* anchorNode)
     231{
     232    return Position(anchorNode, 0, Position::PositionIsOffsetInAnchor);
     233}
     234
     235inline Position lastPositionInNode(Node* anchorNode)
     236{
     237    return Position(anchorNode, lastOffsetInNode(anchorNode), Position::PositionIsOffsetInAnchor);
     238}
     239
    211240} // namespace WebCore
    212241
  • trunk/WebCore/editing/ApplyStyleCommand.cpp

    r48234 r48235  
    13801380}
    13811381
     1382// FIXME: Why does this exist?  Callers should either use lastOffsetForEditing or lastOffsetInNode
    13821383static int maxRangeOffset(Node *n)
    13831384{
  • trunk/WebCore/editing/TextIterator.cpp

    r46647 r48235  
    3434#include "htmlediting.h"
    3535#include "InlineTextBox.h"
    36 #include "Position.h"
    3736#include "Range.h"
    3837#include "RenderTableCell.h"
     
    942941        if (endOffset > 0 && endOffset <= static_cast<int>(endNode->childNodeCount())) {
    943942            endNode = endNode->childNode(endOffset - 1);
    944             endOffset = endNode->offsetInCharacters() ? endNode->maxCharacterOffset() : endNode->childNodeCount();
     943            endOffset = lastOffsetInNode(endNode);
    945944        }
    946945    }
  • trunk/WebCore/editing/htmlediting.cpp

    r48234 r48235  
    385385    if (node->offsetInCharacters())
    386386        return node->maxCharacterOffset();
    387        
     387
    388388    if (node->hasChildNodes())
    389389        return node->childNodeCount();
    390    
     390
    391391    // NOTE: This should preempt the childNodeCount for, e.g., select nodes
    392392    if (editingIgnoresContent(node))
Note: See TracChangeset for help on using the changeset viewer.