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

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

Issue 2029733003: Views: Replace resource ids with ui::TextEditCommand enum for text editing commands in Textfield. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: === 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') | components/arc/ime/arc_ime_service.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 0481adf279e14aa5e9d4240f18aaeffaea86fa46..f8643e646298566b2f3fe3db1cd0f7ac49b384e2 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -42,6 +42,7 @@
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/ime/input_method.h"
+#include "ui/base/ime/text_edit_commands.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/l10n/l10n_util.h"
@@ -365,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();
+ ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
return;
default:
if (Textfield::IsCommandIdEnabled(command_id)) {
@@ -747,14 +744,14 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
model()->popup_model()->TryDeletingCurrentItem();
break;
case ui::VKEY_UP:
- if (!read_only()) {
- model()->OnUpOrDownKeyPressed(-1);
+ if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_UP)) {
+ ExecuteTextEditCommand(ui::TextEditCommand::MOVE_UP);
return true;
}
break;
case ui::VKEY_DOWN:
- if (!read_only()) {
- model()->OnUpOrDownKeyPressed(1);
+ if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_DOWN)) {
+ ExecuteTextEditCommand(ui::TextEditCommand::MOVE_DOWN);
return true;
}
break;
@@ -769,14 +766,16 @@ 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 &&
+ IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
+ ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
return true;
}
break;
case ui::VKEY_INSERT:
- if (shift && !control && !read_only()) {
- ExecuteCommand(IDS_APP_PASTE, 0);
+ if (shift && !control &&
+ IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
+ ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
return true;
}
break;
@@ -897,8 +896,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);
}
@@ -914,6 +912,44 @@ void OmniboxViewViews::DoInsertChar(base::char16 ch) {
Textfield::DoInsertChar(ch);
}
+bool OmniboxViewViews::IsTextEditCommandEnabled(
+ ui::TextEditCommand command) const {
+ switch (command) {
+ case ui::TextEditCommand::MOVE_UP:
+ case ui::TextEditCommand::MOVE_DOWN:
+ return !read_only();
+ case ui::TextEditCommand::PASTE:
+ return !read_only() && !GetClipboardText().empty();
+ default:
+ return Textfield::IsTextEditCommandEnabled(command);
+ }
+}
+
+void OmniboxViewViews::ExecuteTextEditCommand(ui::TextEditCommand command) {
+ // 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 (!IsTextEditCommandEnabled(command))
+ return;
+
+ switch (command) {
+ case ui::TextEditCommand::MOVE_UP:
+ model()->OnUpOrDownKeyPressed(-1);
+ break;
+ case ui::TextEditCommand::MOVE_DOWN:
+ model()->OnUpOrDownKeyPressed(1);
+ break;
+ case ui::TextEditCommand::PASTE:
+ OnPaste();
+ break;
+ default:
+ Textfield::ExecuteTextEditCommand(command);
+ 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') | components/arc/ime/arc_ime_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698