Commit 44927900 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

[omnibox] Cleanup: Use lambda for common code.

Bug: none
Change-Id: I5497cc4084bb4240c8fae6a8bb5476c9d775bdd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900174Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713458}
parent b667d0ce
...@@ -732,6 +732,15 @@ bool OmniboxViewViews::MaybeUnfocusTabButton() { ...@@ -732,6 +732,15 @@ bool OmniboxViewViews::MaybeUnfocusTabButton() {
return false; return false;
} }
bool OmniboxViewViews::MaybeSwitchToTab(const ui::KeyEvent& event) {
if (model()->popup_model()->selected_line_state() !=
OmniboxPopupModel::BUTTON_FOCUSED)
return false;
popup_view_->OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB,
event.time_stamp());
return true;
}
void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
size_t caret_pos, size_t caret_pos,
bool update_popup, bool update_popup,
...@@ -1554,11 +1563,7 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, ...@@ -1554,11 +1563,7 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
const bool command = event.IsCommandDown(); const bool command = event.IsCommandDown();
switch (event.key_code()) { switch (event.key_code()) {
case ui::VKEY_RETURN: case ui::VKEY_RETURN:
if (model()->popup_model()->selected_line_state() == if (!MaybeSwitchToTab(event)) {
OmniboxPopupModel::BUTTON_FOCUSED) {
popup_view_->OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB,
event.time_stamp());
} else {
if (alt || (shift && command)) { if (alt || (shift && command)) {
model()->AcceptInput(WindowOpenDisposition::NEW_FOREGROUND_TAB, model()->AcceptInput(WindowOpenDisposition::NEW_FOREGROUND_TAB,
event.time_stamp()); event.time_stamp());
...@@ -1702,15 +1707,9 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, ...@@ -1702,15 +1707,9 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
break; break;
case ui::VKEY_SPACE: case ui::VKEY_SPACE:
if (!(control || alt || shift)) { if (!control && !alt && !shift && SelectionAtEnd() &&
if (SelectionAtEnd() && MaybeSwitchToTab(event))
model()->popup_model()->selected_line_state() == return true;
OmniboxPopupModel::BUTTON_FOCUSED) {
popup_view_->OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB,
event.time_stamp());
return true;
}
}
break; break;
default: default:
......
...@@ -213,6 +213,10 @@ class OmniboxViewViews : public OmniboxView, ...@@ -213,6 +213,10 @@ class OmniboxViewViews : public OmniboxView,
bool MaybeFocusTabButton(); bool MaybeFocusTabButton();
bool MaybeUnfocusTabButton(); bool MaybeUnfocusTabButton();
// If the tab switch button is focused, switches to the relevant tab. Returns
// whether the switch was attempted.
bool MaybeSwitchToTab(const ui::KeyEvent& event);
// OmniboxView: // OmniboxView:
void SetCaretPos(size_t caret_pos) override; void SetCaretPos(size_t caret_pos) override;
void UpdatePopup() override; void UpdatePopup() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment