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

Unified Diff: ui/views/controls/textfield/textfield.cc

Issue 2228833002: MacViews: Fix behavior of move and select commands when selection direction changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_text_commands
Patch Set: Created 4 years, 4 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/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index be796b27549a59f49444ee6261134903192ac70b..be38f7e0d6669c3382e62159eeb7d6ff3fb30f4b 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -1467,6 +1467,8 @@ bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION:
+ case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION:
+ case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_WORD_BACKWARD:
case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_WORD_FORWARD:
@@ -1503,6 +1505,13 @@ bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_UP:
case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
+// On Mac, the textfield should respond to Up/Down arrows keys and
+// PageUp/PageDown.
+#if defined(OS_MACOSX)
+ return true;
+#else
+ return false;
+#endif
case ui::TextEditCommand::INSERT_TEXT:
case ui::TextEditCommand::SET_MARK:
case ui::TextEditCommand::UNSELECT:
@@ -1630,6 +1639,8 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT:
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE:
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH:
+ case ui::TextEditCommand::MOVE_UP:
+ case ui::TextEditCommand::MOVE_PAGE_UP:
model_->MoveCursor(gfx::LINE_BREAK, begin, false);
break;
case ui::TextEditCommand::
@@ -1637,41 +1648,65 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
case ui::TextEditCommand::
MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION:
- model_->MoveCursor(gfx::LINE_BREAK, begin, true);
+ model_->MoveCursor(gfx::LINE_BREAK, begin, true,
+ PlatformStyle::kLineSelectionBehavior);
msw 2016/08/11 23:46:37 I'd like to avoid the behavior enum if possible. C
karandeepb 2016/08/12 01:26:31 For CHARACTER_BREAK, the enum is not really releva
+ break;
+ case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
+ case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
+ model_->MoveCursor(gfx::LINE_BREAK, begin, true,
+ gfx::SelectionReversedBehavior::SELECTION_START_NEW);
tapted 2016/08/11 03:44:08 nit: `::SelectionReversedBehavior` not needed, mor
msw 2016/08/11 23:46:38 Shouldn't these also extend the selection on mac?
karandeepb 2016/08/12 01:26:31 Nope, try yourself with Shift+Up/Down. And the Bli
karandeepb 2016/08/16 10:24:52 Done.
break;
case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT:
case ui::TextEditCommand::MOVE_TO_END_OF_LINE:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH:
+ case ui::TextEditCommand::MOVE_DOWN:
+ case ui::TextEditCommand::MOVE_PAGE_DOWN:
model_->MoveCursor(gfx::LINE_BREAK, end, false);
break;
case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION:
- model_->MoveCursor(gfx::LINE_BREAK, end, true);
+ model_->MoveCursor(gfx::LINE_BREAK, end, true,
+ PlatformStyle::kLineSelectionBehavior);
msw 2016/08/11 23:46:38 Can you define the platform-specific constants her
karandeepb 2016/08/12 01:26:31 Will do!
+ break;
+ case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
+ case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
+ model_->MoveCursor(gfx::LINE_BREAK, end, true,
+ gfx::SelectionReversedBehavior::SELECTION_START_NEW);
msw 2016/08/11 23:46:38 Shouldn't these also extend the selection on mac?
karandeepb 2016/08/12 01:26:31 Nope, try yourself with Shift+Up/Down.
msw 2016/08/12 21:58:30 Wow, Mac's behavior is so odd; we definitely need
karandeepb 2016/08/16 10:24:52 Done.
+ break;
+ case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION:
+ model_->MoveCursor(gfx::LINE_BREAK, begin, true, gfx::SELECTION_CARET);
msw 2016/08/11 23:46:38 ditto: Why don't these (para fwd/back) extend the
karandeepb 2016/08/12 01:26:31 This is how Cocoa does it. Try with Alt+Shift+Up/D
+ break;
+ case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION:
+ model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_CARET);
break;
case ui::TextEditCommand::MOVE_WORD_BACKWARD:
model_->MoveCursor(gfx::WORD_BREAK, begin, false);
break;
case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION:
- model_->MoveCursor(gfx::WORD_BREAK, begin, true);
+ model_->MoveCursor(gfx::WORD_BREAK, begin, true,
+ PlatformStyle::kWordSelectionBehavior);
break;
case ui::TextEditCommand::MOVE_WORD_FORWARD:
model_->MoveCursor(gfx::WORD_BREAK, end, false);
break;
case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION:
- model_->MoveCursor(gfx::WORD_BREAK, end, true);
+ model_->MoveCursor(gfx::WORD_BREAK, end, true,
+ PlatformStyle::kWordSelectionBehavior);
break;
case ui::TextEditCommand::MOVE_WORD_LEFT:
model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false);
break;
case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION:
- model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
+ model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true,
+ PlatformStyle::kWordSelectionBehavior);
break;
case ui::TextEditCommand::MOVE_WORD_RIGHT:
model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false);
break;
case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION:
- model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
+ model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true,
+ PlatformStyle::kWordSelectionBehavior);
break;
case ui::TextEditCommand::UNDO:
text_changed = cursor_changed = model_->Undo();
@@ -1697,14 +1732,6 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
case ui::TextEditCommand::YANK:
text_changed = cursor_changed = model_->Yank();
break;
- case ui::TextEditCommand::MOVE_DOWN:
- case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
- case ui::TextEditCommand::MOVE_PAGE_DOWN:
- case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
- case ui::TextEditCommand::MOVE_PAGE_UP:
- case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
- case ui::TextEditCommand::MOVE_UP:
- case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
case ui::TextEditCommand::INSERT_TEXT:
case ui::TextEditCommand::SET_MARK:
case ui::TextEditCommand::UNSELECT:

Powered by Google App Engine
This is Rietveld 408576698