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() {
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,
size_t caret_pos,
bool update_popup,
......@@ -1554,11 +1563,7 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
const bool command = event.IsCommandDown();
switch (event.key_code()) {
case ui::VKEY_RETURN:
if (model()->popup_model()->selected_line_state() ==
OmniboxPopupModel::BUTTON_FOCUSED) {
popup_view_->OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB,
event.time_stamp());
} else {
if (!MaybeSwitchToTab(event)) {
if (alt || (shift && command)) {
model()->AcceptInput(WindowOpenDisposition::NEW_FOREGROUND_TAB,
event.time_stamp());
......@@ -1702,15 +1707,9 @@ bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
break;
case ui::VKEY_SPACE:
if (!(control || alt || shift)) {
if (SelectionAtEnd() &&
model()->popup_model()->selected_line_state() ==
OmniboxPopupModel::BUTTON_FOCUSED) {
popup_view_->OpenMatch(WindowOpenDisposition::SWITCH_TO_TAB,
event.time_stamp());
if (!control && !alt && !shift && SelectionAtEnd() &&
MaybeSwitchToTab(event))
return true;
}
}
break;
default:
......
......@@ -213,6 +213,10 @@ class OmniboxViewViews : public OmniboxView,
bool MaybeFocusTabButton();
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:
void SetCaretPos(size_t caret_pos) 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