| Index: Source/core/editing/Position.cpp
|
| diff --git a/Source/core/editing/Position.cpp b/Source/core/editing/Position.cpp
|
| index 0718146c035f72df0748125b610b3c1a9a8b933b..0f108c1f930349d51c83b3c2d61be6cdb82eef1f 100644
|
| --- a/Source/core/editing/Position.cpp
|
| +++ b/Source/core/editing/Position.cpp
|
| @@ -299,78 +299,102 @@ int PositionAlgorithm<Strategy>::compareTo(const PositionAlgorithm<Strategy>& ot
|
| return comparePositions(*this, other);
|
| }
|
|
|
| +// TODO(yosin) We should move |uncheckedPreviousOffsetForBackwardDeletion()|
|
| +// to "EditingUtilities.cpp" with |previousPositionOf()|.
|
| // TODO(yosin) To avoid forward declaration, we should move implementation of
|
| // |uncheckedPreviousOffsetForBackwardDeletion()| here.
|
| static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int current);
|
|
|
| template <typename Strategy>
|
| -PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveType moveType) const
|
| +PositionAlgorithm<Strategy> previousPositionOfAlgorithm(const PositionAlgorithm<Strategy>& position, PositionMoveType moveType)
|
| {
|
| - Node* node = anchorNode();
|
| + Node* const node = position.anchorNode();
|
| if (!node)
|
| - return PositionAlgorithm<Strategy>(*this);
|
| + return position;
|
|
|
| - int offset = computeEditingOffset();
|
| + const int offset = position.computeEditingOffset();
|
|
|
| if (offset > 0) {
|
| if (editingIgnoresContent(node))
|
| - return beforeNode(node);
|
| + return PositionAlgorithm<Strategy>::beforeNode(node);
|
| if (Node* child = Strategy::childAt(*node, offset - 1))
|
| - return lastPositionInOrAfterNode(child);
|
| + return PositionAlgorithm<Strategy>::lastPositionInOrAfterNode(child);
|
|
|
| // There are two reasons child might be 0:
|
| - // 1) The node is node like a text node that is not an element, and therefore has no children.
|
| - // Going backward one character at a time is correct.
|
| - // 2) The old offset was a bogus offset like (<br>, 1), and there is no child.
|
| - // Going from 1 to 0 is correct.
|
| + // 1) The node is node like a text node that is not an element, and
|
| + // therefore has no children. Going backward one character at a
|
| + // time is correct.
|
| + // 2) The old offset was a bogus offset like (<br>, 1), and there is
|
| + // no child. Going from 1 to 0 is correct.
|
| switch (moveType) {
|
| - case CodePoint:
|
| + case PositionMoveType::CodePoint:
|
| return PositionAlgorithm<Strategy>(node, offset - 1);
|
| - case Character:
|
| + case PositionMoveType::Character:
|
| return PositionAlgorithm<Strategy>(node, uncheckedPreviousOffset(node, offset));
|
| - case BackwardDeletion:
|
| + case PositionMoveType::BackwardDeletion:
|
| return PositionAlgorithm<Strategy>(node, uncheckedPreviousOffsetForBackwardDeletion(node, offset));
|
| }
|
| }
|
|
|
| if (ContainerNode* parent = Strategy::parent(*node)) {
|
| if (editingIgnoresContent(parent))
|
| - return beforeNode(parent);
|
| + return PositionAlgorithm<Strategy>::beforeNode(parent);
|
| // TODO(yosin) We should use |Strategy::index(Node&)| instead of
|
| // |Node::nodeIndex()|.
|
| return PositionAlgorithm<Strategy>(parent, node->nodeIndex());
|
| }
|
| - return PositionAlgorithm<Strategy>(*this);
|
| + return position;
|
| +}
|
| +
|
| +Position previousPositionOf(const Position& position, PositionMoveType moveType)
|
| +{
|
| + return previousPositionOfAlgorithm<EditingStrategy>(position, moveType);
|
| +}
|
| +
|
| +PositionInComposedTree previousPositionOf(const PositionInComposedTree& position, PositionMoveType moveType)
|
| +{
|
| + return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(position, moveType);
|
| }
|
|
|
| template <typename Strategy>
|
| -PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::next(PositionMoveType moveType) const
|
| +PositionAlgorithm<Strategy> nextPositionOfAlgorithm(const PositionAlgorithm<Strategy>& position, PositionMoveType moveType)
|
| {
|
| - ASSERT(moveType != BackwardDeletion);
|
| + ASSERT(moveType != PositionMoveType::BackwardDeletion);
|
|
|
| - Node* node = anchorNode();
|
| + Node* node = position.anchorNode();
|
| if (!node)
|
| - return PositionAlgorithm<Strategy>(*this);
|
| + return position;
|
|
|
| - int offset = computeEditingOffset();
|
| + const int offset = position.computeEditingOffset();
|
|
|
| if (Node* child = Strategy::childAt(*node, offset))
|
| - return firstPositionInOrBeforeNode(child);
|
| + return PositionAlgorithm<Strategy>::firstPositionInOrBeforeNode(child);
|
|
|
| // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of
|
| // DOM tree version.
|
| if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetForEditing(node)) {
|
| // There are two reasons child might be 0:
|
| - // 1) The node is node like a text node that is not an element, and therefore has no children.
|
| - // Going forward one character at a time is correct.
|
| - // 2) The new offset is a bogus offset like (<br>, 1), and there is no child.
|
| - // Going from 0 to 1 is correct.
|
| - return editingPositionOf(node, (moveType == Character) ? uncheckedNextOffset(node, offset) : offset + 1);
|
| + // 1) The node is node like a text node that is not an element, and
|
| + // therefore has no children. Going forward one character at a time
|
| + // is correct.
|
| + // 2) The new offset is a bogus offset like (<br>, 1), and there is no
|
| + // child. Going from 0 to 1 is correct.
|
| + return PositionAlgorithm<Strategy>::editingPositionOf(node, (moveType == PositionMoveType::Character) ? uncheckedNextOffset(node, offset) : offset + 1);
|
| }
|
|
|
| if (ContainerNode* parent = Strategy::parent(*node))
|
| - return editingPositionOf(parent, Strategy::index(*node) + 1);
|
| - return PositionAlgorithm<Strategy>(*this);
|
| + return PositionAlgorithm<Strategy>::editingPositionOf(parent, Strategy::index(*node) + 1);
|
| + return position;
|
| +}
|
| +
|
| +Position nextPositionOf(const Position& position, PositionMoveType moveType)
|
| +{
|
| + return nextPositionOfAlgorithm<EditingStrategy>(position, moveType);
|
| +}
|
| +
|
| +PositionInComposedTree nextPositionOf(const PositionInComposedTree& position, PositionMoveType moveType)
|
| +{
|
| + return nextPositionOfAlgorithm<EditingInComposedTreeStrategy>(position, moveType);
|
| }
|
|
|
| int uncheckedPreviousOffset(const Node* n, int current)
|
|
|