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

Unified Diff: ui/gfx/render_text.cc

Issue 1989143002: MacViews: Correct behavior of move and select commands when selection direction changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_commands
Patch Set: Created 4 years, 7 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
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index f2f691ee9e283f214f5606dc22edb72a7ecd425d..ee6b91000cf8aeeca39a84d0b18ae9634b7f6cc2 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -205,6 +205,18 @@ void RestoreBreakList(RenderText* render_text, BreakList<T>* break_list) {
}
}
+// Merges |range1| and |range2|, with the directionality of the result same as
+// |range2|. |range1| and |range2| must at least share a point.
+gfx::Range MergeRangesWithDirection(const Range& range1, const Range& range2) {
+ DCHECK(!(range1.GetMax() < range2.GetMin() ||
+ range2.GetMax() < range1.GetMin()));
+ const uint32_t min = std::min(range1.GetMin(), range2.GetMin());
+ const uint32_t max = std::max(range1.GetMax(), range2.GetMax());
+ bool reversed =
+ range2.is_empty() ? !range1.is_reversed() : range2.is_reversed();
+ return reversed ? Range(max, min) : Range(min, max);
+}
+
} // namespace
namespace internal {
@@ -604,7 +616,16 @@ void RenderText::SetCursorPosition(size_t position) {
void RenderText::MoveCursor(BreakType break_type,
VisualCursorDirection direction,
- bool select) {
+ bool select,
+ SelectionReversedBehavior select_behavior) {
+ // |select_behavior| is not relevant for CHARACTER_BREAK. Verify
+ // |select_behavior| has the default value for this case.
+ if (break_type == CHARACTER_BREAK)
+ DCHECK_EQ(SELECTION_DEFAULT, select_behavior);
+
+ if (break_type == WORD_BREAK)
+ DCHECK_NE(SELECTION_EXTEND, select_behavior);
+
SelectionModel cursor(cursor_position(), selection_model_.caret_affinity());
// Cancelling a selection moves to the edge of the selection.
if (break_type != LINE_BREAK && !selection().is_empty() && !select) {
@@ -624,8 +645,24 @@ void RenderText::MoveCursor(BreakType break_type,
} else {
cursor = GetAdjacentSelectionModel(cursor, break_type, direction);
}
- if (select)
+ if (select) {
cursor.set_selection_start(selection().start());
+
+ // cursor now corresponds to the new selection. Take |select_behavior| into
+ // account.
+ bool selection_direction_changed =
+ !selection().is_empty() && !cursor.selection().is_empty() &&
+ selection().is_reversed() != cursor.selection().is_reversed();
+
+ if (select_behavior == SELECTION_EXTEND)
tapted 2016/05/20 06:47:36 nit: needs curlies
karandeepb 2016/05/24 07:47:14 Done.
+ cursor = SelectionModel(
+ MergeRangesWithDirection(selection(), cursor.selection()),
+ selection_model_.caret_affinity());
+ else if (selection_direction_changed && select_behavior == SELECTION_CARET)
+ cursor = SelectionModel(selection().start(),
+ selection_model_.caret_affinity());
+ }
+
MoveCursorTo(cursor);
}
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/text_constants.h » ('j') | ui/gfx/text_constants.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698