From d74ad51826c0672b72e807de580cb97c3b29a8bb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 1 Jun 2021 10:48:52 +0900 Subject: [PATCH] fix: correctly handle Alt+Key shortcuts (#29328) --- shell/browser/ui/views/menu_bar.cc | 2 ++ shell/browser/ui/views/root_view.cc | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/shell/browser/ui/views/menu_bar.cc b/shell/browser/ui/views/menu_bar.cc index d4304403393e..6ebb3931520c 100644 --- a/shell/browser/ui/views/menu_bar.cc +++ b/shell/browser/ui/views/menu_bar.cc @@ -56,6 +56,8 @@ void MenuBar::SetAcceleratorVisibility(bool visible) { } MenuBar::View* MenuBar::FindAccelChild(char16_t key) { + if (key == 0) + return nullptr; for (auto* child : GetChildrenInZOrder()) { if (static_cast(child)->accelerator() == key) return child; diff --git a/shell/browser/ui/views/root_view.cc b/shell/browser/ui/views/root_view.cc index 04d93338780f..64728f55a6c0 100644 --- a/shell/browser/ui/views/root_view.cc +++ b/shell/browser/ui/views/root_view.cc @@ -119,18 +119,18 @@ void RootView::HandleKeyEvent(const content::NativeWebKeyboardEvent& event) { // Show the submenu when "Alt+Key" is pressed. if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown && - !IsAltKey(event) && IsAltModifier(event)) { - if (menu_bar_->HasAccelerator(event.windows_key_code)) { - if (!menu_bar_visible_) { - SetMenuBarVisibility(true); + event.windows_key_code >= ui::VKEY_A && + event.windows_key_code <= ui::VKEY_Z && IsAltModifier(event) && + menu_bar_->HasAccelerator(event.windows_key_code)) { + if (!menu_bar_visible_) { + SetMenuBarVisibility(true); - View* focused_view = GetFocusManager()->GetFocusedView(); - last_focused_view_tracker_->SetView(focused_view); - menu_bar_->RequestFocus(); - } - - menu_bar_->ActivateAccelerator(event.windows_key_code); + View* focused_view = GetFocusManager()->GetFocusedView(); + last_focused_view_tracker_->SetView(focused_view); + menu_bar_->RequestFocus(); } + + menu_bar_->ActivateAccelerator(event.windows_key_code); return; }