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

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

Issue 2031913002: Remove ui::TextEditCommand::DELETE_SELECTION. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor5_text_input_client_api
Patch Set: Rebase. Created 4 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 | « ui/base/ime/text_edit_commands.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index b8bfaf2d72c00a89a2ef6de60a4dc87703f1566c..a7617faa04667fe3b38425fcca7ce883b01f881b 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -275,8 +275,10 @@ const gfx::FontList& GetDefaultFontList() {
}
// Returns the ui::TextEditCommand corresponding to the |command_id| menu
-// action. Keep in sync with UpdateContextMenu.
-ui::TextEditCommand GetTextEditCommandFromMenuCommand(int command_id) {
+// action. |has_selection| is true if the textfield has an active selection.
+// Keep in sync with UpdateContextMenu.
+ui::TextEditCommand GetTextEditCommandFromMenuCommand(int command_id,
+ bool has_selection) {
switch (command_id) {
case IDS_APP_UNDO:
return ui::TextEditCommand::UNDO;
@@ -287,12 +289,14 @@ ui::TextEditCommand GetTextEditCommandFromMenuCommand(int command_id) {
case IDS_APP_PASTE:
return ui::TextEditCommand::PASTE;
case IDS_APP_DELETE:
- return ui::TextEditCommand::DELETE_SELECTION;
+ // The DELETE menu action only works in case of an active selection.
+ if (has_selection)
+ return ui::TextEditCommand::DELETE_FORWARD;
+ break;
case IDS_APP_SELECT_ALL:
return ui::TextEditCommand::SELECT_ALL;
- default:
- return ui::TextEditCommand::INVALID_COMMAND;
}
+ return ui::TextEditCommand::INVALID_COMMAND;
}
} // namespace
@@ -1272,7 +1276,7 @@ bool Textfield::IsCommandIdChecked(int command_id) const {
bool Textfield::IsCommandIdEnabled(int command_id) const {
return Textfield::IsTextEditCommandEnabled(
- GetTextEditCommandFromMenuCommand(command_id));
+ GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
}
bool Textfield::GetAcceleratorForCommandId(int command_id,
@@ -1305,7 +1309,7 @@ bool Textfield::GetAcceleratorForCommandId(int command_id,
void Textfield::ExecuteCommand(int command_id, int event_flags) {
Textfield::ExecuteTextEditCommand(
- GetTextEditCommandFromMenuCommand(command_id));
+ GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
}
////////////////////////////////////////////////////////////////////////////////
@@ -1546,8 +1550,6 @@ bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
ui::Clipboard::GetForCurrentThread()->ReadText(
ui::CLIPBOARD_TYPE_COPY_PASTE, &result);
return editable && !result.empty();
- case ui::TextEditCommand::DELETE_SELECTION:
- return editable && model_->HasSelection();
case ui::TextEditCommand::SELECT_ALL:
return !text().empty();
case ui::TextEditCommand::DELETE_FORWARD:
@@ -1659,9 +1661,6 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
case ui::TextEditCommand::PASTE:
text_changed = cursor_changed = Paste();
break;
- case ui::TextEditCommand::DELETE_SELECTION:
- text_changed = cursor_changed = model_->Delete();
- break;
case ui::TextEditCommand::SELECT_ALL:
SelectAll(false);
break;
« no previous file with comments | « ui/base/ime/text_edit_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698