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

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

Issue 2007503002: 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: Added file deleted during rename. 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: 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 78a6608b22d9ba50a3833266589ca81783dc758c..1da55f0742402b3654a8e95f31d83a969f25f821 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -131,6 +131,37 @@ ui::TextInputType DetermineTextInputType() {
return ui::TEXT_INPUT_TYPE_URL;
}
+ui::TextEditCommand GetCommandForKeyEvent(const ui::KeyEvent& event) {
+ const bool shift = event.IsShiftDown();
+ const bool control = event.IsControlDown();
+ const bool alt = event.IsAltDown() || event.IsAltGrDown();
+ switch (event.key_code()) {
+ case ui::VKEY_UP:
+ return ui::TextEditCommand::MOVE_UP;
+ case ui::VKEY_DOWN:
+ return ui::TextEditCommand::MOVE_DOWN;
+ case ui::VKEY_PRIOR:
+ if (!(control || alt || shift))
+ return ui::TextEditCommand::MOVE_PAGE_UP;
+ break;
+ case ui::VKEY_NEXT:
+ if (!(control || alt || shift))
+ return ui::TextEditCommand::MOVE_PAGE_DOWN;
+ break;
+ case ui::VKEY_V:
+ if (control && !alt)
+ return ui::TextEditCommand::PASTE;
+ break;
+ case ui::VKEY_INSERT:
+ if (shift && !control)
+ return ui::TextEditCommand::PASTE;
+ break;
+ default:
+ break;
+ }
+ return ui::TextEditCommand::INVALID_COMMAND;
+}
+
} // namespace
@@ -367,14 +398,9 @@ 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(ui::TextEditCommand::PASTE);
return;
default:
if (Textfield::IsCommandIdEnabled(command_id)) {
@@ -390,6 +416,33 @@ void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
}
}
+void OmniboxViewViews::ExecuteEditCommand(ui::TextEditCommand command) {
+ if (!IsEditCommandEnabled(command))
+ return;
+
+ DestroyTouchSelection();
+ 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;
+ case ui::TextEditCommand::MOVE_PAGE_UP:
+ model()->OnUpOrDownKeyPressed(-1 * model()->result().size());
+ break;
+ case ui::TextEditCommand::MOVE_PAGE_DOWN:
+ model()->OnUpOrDownKeyPressed(model()->result().size());
+ break;
+ default:
+ Textfield::ExecuteEditCommand(command);
+ break;
+ }
+}
+
void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text,
const gfx::Range& range) {
SetText(text);
@@ -445,6 +498,23 @@ void OmniboxViewViews::UpdateSecurityLevel() {
security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
}
+bool OmniboxViewViews::IsEditCommandEnabledInternal(
+ ui::TextEditCommand command) const {
+ switch (command) {
+ case ui::TextEditCommand::MOVE_UP:
+ case ui::TextEditCommand::MOVE_DOWN:
+ case ui::TextEditCommand::PASTE:
+ return !read_only();
+ // Todo shouldn't this also have read_only?
+ case ui::TextEditCommand::MOVE_PAGE_UP:
+ case ui::TextEditCommand::MOVE_PAGE_DOWN:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
size_t caret_pos,
bool update_popup,
@@ -743,7 +813,6 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
return views::Textfield::OnKeyPressed(event);
const bool shift = event.IsShiftDown();
- const bool control = event.IsControlDown();
const bool alt = event.IsAltDown() || event.IsAltGrDown();
switch (event.key_code()) {
case ui::VKEY_RETURN:
@@ -758,44 +827,20 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
if (shift && model()->popup_model()->IsOpen())
model()->popup_model()->TryDeletingCurrentItem();
break;
- case ui::VKEY_UP:
- if (!read_only()) {
- model()->OnUpOrDownKeyPressed(-1);
- return true;
- }
- break;
- case ui::VKEY_DOWN:
- if (!read_only()) {
- model()->OnUpOrDownKeyPressed(1);
- return true;
- }
- break;
- case ui::VKEY_PRIOR:
- if (control || alt || shift)
- return false;
- model()->OnUpOrDownKeyPressed(-1 * model()->result().size());
- return true;
- case ui::VKEY_NEXT:
- if (control || alt || shift)
- return false;
- model()->OnUpOrDownKeyPressed(model()->result().size());
- return true;
- case ui::VKEY_V:
- if (control && !alt && !read_only()) {
- ExecuteCommand(IDS_APP_PASTE, 0);
- return true;
- }
- break;
- case ui::VKEY_INSERT:
- if (shift && !control && !read_only()) {
- ExecuteCommand(IDS_APP_PASTE, 0);
- return true;
- }
- break;
default:
break;
}
+ ui::TextEditCommand command = scheduled_edit_command();
+ if (command == ui::TextEditCommand::INVALID_COMMAND)
+ command = GetCommandForKeyEvent(event);
+
+ if (IsEditCommandEnabledInternal(command)) {
+ reset_scheduled_edit_command();
+ ExecuteEditCommand(command);
+ return true;
+ }
+
return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
}
@@ -909,8 +954,8 @@ 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) ||
+ // What about IDC_EDIT_SEARCH_ENGINES?
tapted 2016/05/31 04:18:16 What's the context for this? I think this is depre
karandeepb 2016/05/31 05:12:32 Edit Search Engines still remains as a context men
+ return Textfield::IsCommandIdEnabled(command_id) ||
location_bar_view_->command_updater()->IsCommandEnabled(command_id);
}
@@ -926,6 +971,11 @@ void OmniboxViewViews::DoInsertChar(base::char16 ch) {
Textfield::DoInsertChar(ch);
}
+bool OmniboxViewViews::IsEditCommandEnabled(ui::TextEditCommand command) const {
+ return IsEditCommandEnabledInternal(command) ||
+ Textfield::IsEditCommandEnabled(command);
+}
+
#if defined(OS_CHROMEOS)
void OmniboxViewViews::CandidateWindowOpened(
chromeos::input_method::InputMethodManager* manager) {

Powered by Google App Engine
This is Rietveld 408576698