Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Unified Diff: Source/core/editing/GranularityStrategy.h

Issue 1123563003: Improving direction-based selection strategy. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removing anonymous namespace and marking functions static instead. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/FrameSelectionTest.cpp ('k') | Source/core/editing/GranularityStrategy.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/GranularityStrategy.h
diff --git a/Source/core/editing/GranularityStrategy.h b/Source/core/editing/GranularityStrategy.h
index 9d31bc84eb0ad41f48f7a04ea2fa49f2e994b75c..f77bbe3f4f55923f461b1e3d5cd0c9190afedef3 100644
--- a/Source/core/editing/GranularityStrategy.h
+++ b/Source/core/editing/GranularityStrategy.h
@@ -16,9 +16,9 @@ public:
virtual SelectionStrategy GetType() const = 0;
virtual void Clear() = 0;
- // Calculates and returns the new selection based on the updated user
- // selection extent |extentPosition| and the granularity strategy.
- virtual VisibleSelection updateExtent(const VisiblePosition& extentPosition, const VisibleSelection&) = 0;
+ // Calculates and returns the new selection based on the updated extent
+ // location in absolute coordinates.
+ virtual VisibleSelection updateExtent(const IntPoint&, LocalFrame*) = 0;
protected:
GranularityStrategy();
@@ -33,13 +33,46 @@ public:
// GranularityStrategy:
SelectionStrategy GetType() const final;
void Clear() final;
- VisibleSelection updateExtent(const VisiblePosition& extentPosition, const VisibleSelection&) final;
+ VisibleSelection updateExtent(const IntPoint&, LocalFrame*) final;
};
// "Expand by word, shrink by character" selection strategy.
// Uses character granularity when selection is shrinking. If the selection is
// expanding, granularity doesn't change until a word boundary is passed, after
// which the granularity switches to "word".
+// In word granularity, the word is not selected until the extent point passes
+// the middle of the word.
+//
+// The "offset" feature:
+// The offset is the horizontal distance between the extent point (passed in
+// updateExtent) and the end of the selection. In character granularity the
+// offset is typically zero or near zero, however in word granularity it can be
+// significant. When the offset is positive and the extent point moved to the
+// left, the offset is preserved, i.e. the selection tracks the extent point
+// with the constant offset. When the offset is positive and the extent point
+// is moved to the right, the offset gets reduced. Selection will not grow
+// until the offset is reduced all the way to zero.
+//
+// This behavior is best illustrated by an example:
+//
+// ^ marks base, | marks extent point, > marks selection end:
+// Lorem ip^sum|> dolor sit amet, consectetur
+//
+// Move extent over the middle of "dolor". Granularity should change to word
+// granularity and the selection end should jump to the end of the word.
+// Lorem ip^sum dolo|r> sit amet, consectetur
+//
+// Move extent back one character. Granularity changes to "character". The
+// selection end should move back one character as well. Note an offset between
+// the extent and the selection end.
+// Lorem ip^sum dol|o>r sit amet, consectetur
+//
+// Move extent forward one character. The offset is reduced to 0. Selection end
+// doesn't change.
+// Lorem ip^sum dolo|>r sit amet, consectetur
+//
+// Move forward one character. End moves with extent in character granularity.
+// Lorem ip^sum dolor|> sit amet, consectetur
class DirectionGranularityStrategy final : public GranularityStrategy {
public:
DirectionGranularityStrategy();
@@ -48,23 +81,37 @@ public:
// GranularityStrategy:
SelectionStrategy GetType() const final;
void Clear() final;
- VisibleSelection updateExtent(const VisiblePosition&, const VisibleSelection&) final;
+ VisibleSelection updateExtent(const IntPoint&, LocalFrame*) final;
private:
- enum class BoundAdjust {CurrentPosIfOnBound, NextBoundIfOnBound};
- enum class SearchDirection {SearchBackwards, SearchForward};
+ enum class StrategyState {
+ // Starting state.
+ // Selection was cleared and there were no extent updates since then.
+ // One an update is performed, the strategy goes into the Expanding
+ // state unless the update shrinks the selection without changing
+ // relative base/extent order, in which case the strategy goes into the
+ // Shrinking state.
+ Cleared,
+ // Last time the selection was changed by updateExtent - it was expanded
+ // or the relative base/extent order was changed.
+ Expanding,
+ // Last time the selection was changed by updateExtent - it was shrunk
+ // (without changing relative base/extent order).
+ Shrinking
+ };
- // Returns the next word boundary starting from |pos|. |direction| specifies
- // the direction in which to search for the next bound. nextIfOnBound
- // controls whether |pos| or the next boundary is returned when |pos| is
- // located exactly on word boundary.
- VisiblePosition nextWordBound(const VisiblePosition& /*pos*/, SearchDirection /*direction*/, BoundAdjust /*nextIfOnBound*/);
+ StrategyState m_state;
- // Current selection granularity being used
+ // Current selection granularity being used.
TextGranularity m_granularity;
- // Set to true if the selection was shrunk (without changing relative
- // base/extent order) as a result of the most recent updateExtent call.
- bool m_lastMoveShrunkSelection;
+
+ // Horizontal offset in pixels in absolute coordinates applied to the extent point.
+ int m_offset;
+
+ // This defines location of the offset-adjusted extent point (from the
+ // latest updateExtent call) relative to the location of extent's
+ // VisiblePosition. It is used to detect sub-position extent movement.
+ IntSize m_diffExtentPointFromExtentPosition;
};
} // namespace blink
« no previous file with comments | « Source/core/editing/FrameSelectionTest.cpp ('k') | Source/core/editing/GranularityStrategy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698