Chromium Code Reviews| Index: Source/core/editing/VisiblePosition.cpp |
| diff --git a/Source/core/editing/VisiblePosition.cpp b/Source/core/editing/VisiblePosition.cpp |
| index 00dda8dea9cd59b332a7f09fb5681d51cfab22cf..f38bdc5aae98413b5502f1ceaeacb9d86a0b5c59 100644 |
| --- a/Source/core/editing/VisiblePosition.cpp |
| +++ b/Source/core/editing/VisiblePosition.cpp |
| @@ -69,21 +69,20 @@ void VisiblePosition::init(const Position& position, EAffinity affinity) |
| VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const |
| { |
| - // FIXME: Support CanSkipEditingBoundary |
| - ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary); |
| VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affinity); |
| - if (rule == CanCrossEditingBoundary) |
| + switch (rule) { |
| + case CanCrossEditingBoundary: |
| return next; |
| - |
| - return honorEditingBoundaryAtOrAfter(next); |
| + case CannotCrossEditingBoundary: |
| + return honorEditingBoundaryAtOrAfter(next); |
| + case CanSkipOverEditingBoundary: |
| + return skipToEndOfEditingBoundary(next); |
| + } |
| } |
|
yosin_UTC9
2013/09/06 01:31:15
Please fix compilation error, visibleposition.cpp(
|
| VisiblePosition VisiblePosition::previous(EditingBoundaryCrossingRule rule) const |
| { |
| - // FIXME: Support CanSkipEditingBoundary |
| - ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary); |
| - // find first previous DOM position that is visible |
| Position pos = previousVisuallyDistinctCandidate(m_deepPosition); |
| // return null visible position if there is no previous visible position |
| @@ -103,10 +102,14 @@ VisiblePosition VisiblePosition::previous(EditingBoundaryCrossingRule rule) cons |
| } |
| #endif |
| - if (rule == CanCrossEditingBoundary) |
| + switch (rule) { |
| + case CanCrossEditingBoundary: |
| return prev; |
| - |
| - return honorEditingBoundaryAtOrBefore(prev); |
| + case CannotCrossEditingBoundary: |
| + return honorEditingBoundaryAtOrBefore(prev); |
| + case CanSkipOverEditingBoundary: |
| + return skipToStartOfEditingBoundary(prev); |
| + } |
|
yosin_UTC9
2013/09/06 01:31:15
Please fix compilation error: visibleposition.cpp(
dmazzoni
2013/09/06 07:29:26
Done, added assert_not_reached and same below.
|
| } |
| Position VisiblePosition::leftVisuallyDistinctCandidate() const |
| @@ -494,6 +497,46 @@ VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi |
| return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot); |
| } |
| +VisiblePosition VisiblePosition::skipToStartOfEditingBoundary(const VisiblePosition &pos) const |
| +{ |
| + if (pos.isNull()) |
| + return pos; |
| + |
| + Node* highestRoot = highestEditableRoot(deepEquivalent()); |
| + Node* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); |
| + |
| + // Return pos itself if the two are from the very same editable region, or both are non-editable. |
| + if (highestRootOfPos == highestRoot) |
| + return pos; |
| + |
| + // If |pos| has an editable root, skip to the start |
| + if (highestRootOfPos) |
| + return previousVisuallyDistinctCandidate(Position(highestRootOfPos, Position::PositionIsBeforeAnchor).parentAnchoredEquivalent()); |
| + |
| + // That must mean that |pos| is not editable. Return the last position before pos that is in the same editable region as this position |
| + return lastEditablePositionBeforePositionInRoot(pos.deepEquivalent(), highestRoot); |
| +} |
| + |
| +VisiblePosition VisiblePosition::skipToEndOfEditingBoundary(const VisiblePosition &pos) const |
| +{ |
| + if (pos.isNull()) |
| + return pos; |
| + |
| + Node* highestRoot = highestEditableRoot(deepEquivalent()); |
| + Node* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); |
| + |
| + // Return pos itself if the two are from the very same editable region, or both are non-editable. |
| + if (highestRootOfPos == highestRoot) |
| + return pos; |
| + |
| + // If |pos| has an editable root, skip to the end |
| + if (highestRootOfPos) |
| + return Position(highestRootOfPos, Position::PositionIsAfterAnchor).parentAnchoredEquivalent(); |
| + |
| + // That must mean that |pos| is not editable. Return the next position after pos that is in the same editable region as this position |
| + return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot); |
| +} |
| + |
| static Position canonicalizeCandidate(const Position& candidate) |
| { |
| if (candidate.isNull()) |