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

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 2031433002: Views::Textfield: Decouple handling of menu and text editing commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor2_virtual_calls
Patch Set: Address review comments. 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 | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 8852dfe48c57321a8a6cbf13ad68624259255622..5d354645004021fc2cecd6e80130d528a8f4b8e6 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -366,14 +366,10 @@ void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
case IDC_EDIT_SEARCH_ENGINES:
location_bar_view_->command_updater()->ExecuteCommand(command_id);
return;
- case IDS_MOVE_DOWN:
- case IDS_MOVE_UP:
- model()->OnUpOrDownKeyPressed(command_id == IDS_MOVE_DOWN ? 1 : -1);
- return;
// These commands do invoke the popup.
case IDS_APP_PASTE:
- OnPaste();
+ ExecuteEditCommand(IDS_APP_PASTE);
return;
default:
if (Textfield::IsCommandIdEnabled(command_id)) {
@@ -758,14 +754,14 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
model()->popup_model()->TryDeletingCurrentItem();
break;
case ui::VKEY_UP:
- if (!read_only()) {
- model()->OnUpOrDownKeyPressed(-1);
+ if (IsEditCommandEnabled(IDS_MOVE_UP)) {
+ ExecuteEditCommand(IDS_MOVE_UP);
return true;
}
break;
case ui::VKEY_DOWN:
- if (!read_only()) {
- model()->OnUpOrDownKeyPressed(1);
+ if (IsEditCommandEnabled(IDS_MOVE_DOWN)) {
+ ExecuteEditCommand(IDS_MOVE_DOWN);
return true;
}
break;
@@ -780,14 +776,14 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
model()->OnUpOrDownKeyPressed(model()->result().size());
return true;
case ui::VKEY_V:
- if (control && !alt && !read_only()) {
- ExecuteCommand(IDS_APP_PASTE, 0);
+ if (control && !alt && IsEditCommandEnabled(IDS_APP_PASTE)) {
+ ExecuteEditCommand(IDS_APP_PASTE);
return true;
}
break;
case ui::VKEY_INSERT:
- if (shift && !control && !read_only()) {
- ExecuteCommand(IDS_APP_PASTE, 0);
+ if (shift && !control && IsEditCommandEnabled(IDS_APP_PASTE)) {
+ ExecuteEditCommand(IDS_APP_PASTE);
return true;
}
break;
@@ -908,8 +904,7 @@ bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
return !read_only() && model()->CanPasteAndGo(GetClipboardText());
if (command_id == IDS_SHOW_URL)
return controller()->GetToolbarModel()->WouldReplaceURL();
- return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP ||
- Textfield::IsCommandIdEnabled(command_id) ||
+ return Textfield::IsCommandIdEnabled(command_id) ||
location_bar_view_->command_updater()->IsCommandEnabled(command_id);
}
@@ -925,6 +920,43 @@ void OmniboxViewViews::DoInsertChar(base::char16 ch) {
Textfield::DoInsertChar(ch);
}
+bool OmniboxViewViews::IsEditCommandEnabled(int command_id) const {
+ switch (command_id) {
+ case IDS_MOVE_UP:
+ case IDS_MOVE_DOWN:
+ return !read_only();
+ case IDS_APP_PASTE:
+ return !read_only() && !GetClipboardText().empty();
+ default:
+ return Textfield::IsEditCommandEnabled(command_id);
+ }
+}
+
+void OmniboxViewViews::ExecuteEditCommand(int command_id) {
+ // In the base class, touch text selection is deactivated when a command is
+ // executed. Since we are not always calling the base class implementation
+ // here, we need to deactivate touch text selection here, too.
+ DestroyTouchSelection();
+
+ if (!IsEditCommandEnabled(command_id))
+ return;
+
+ switch (command_id) {
+ case IDS_MOVE_UP:
+ model()->OnUpOrDownKeyPressed(-1);
+ break;
+ case IDS_MOVE_DOWN:
+ model()->OnUpOrDownKeyPressed(1);
+ break;
+ case IDS_APP_PASTE:
+ OnPaste();
+ break;
+ default:
+ Textfield::ExecuteEditCommand(command_id);
+ break;
+ }
+}
+
#if defined(OS_CHROMEOS)
void OmniboxViewViews::CandidateWindowOpened(
chromeos::input_method::InputMethodManager* manager) {
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698