views: Pressing "Alt+Key" should bring up the menu bar.
This commit is contained in:
parent
ba41634ad6
commit
a230daa998
3 changed files with 25 additions and 9 deletions
|
@ -572,16 +572,22 @@ void NativeWindowViews::HandleKeyboardEvent(
|
|||
const content::NativeWebKeyboardEvent& event) {
|
||||
keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager());
|
||||
|
||||
if (menu_bar_ && menu_bar_visible_) {
|
||||
if (menu_bar_) {
|
||||
// Toggle accelerator when "Alt" is pressed.
|
||||
if (IsAltKey(event))
|
||||
if (menu_bar_visible_ && IsAltKey(event))
|
||||
menu_bar_->SetAcceleratorVisibility(
|
||||
event.type == blink::WebInputEvent::RawKeyDown);
|
||||
|
||||
// Show the submenu when "Alt+Key" is pressed.
|
||||
if (event.type == blink::WebInputEvent::RawKeyDown && !IsAltKey(event) &&
|
||||
IsAltModifier(event))
|
||||
IsAltModifier(event)) {
|
||||
if (!menu_bar_visible_ &&
|
||||
(menu_bar_->GetAcceleratorIndex(event.windowsKeyCode) != -1)) {
|
||||
SetMenuBarVisibility(true);
|
||||
Layout();
|
||||
}
|
||||
menu_bar_->ActivateAccelerator(event.windowsKeyCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (!menu_bar_autohide_)
|
||||
|
|
|
@ -90,14 +90,20 @@ void MenuBar::SetAcceleratorVisibility(bool visible) {
|
|||
static_cast<SubmenuButton*>(child_at(i))->SetAcceleratorVisibility(visible);
|
||||
}
|
||||
|
||||
void MenuBar::ActivateAccelerator(base::char16 key) {
|
||||
int MenuBar::GetAcceleratorIndex(base::char16 key) {
|
||||
for (int i = 0; i < child_count(); ++i) {
|
||||
SubmenuButton* button = static_cast<SubmenuButton*>(child_at(i));
|
||||
if (button->accelerator() == key) {
|
||||
SetAcceleratorVisibility(false);
|
||||
button->Activate();
|
||||
return;
|
||||
}
|
||||
if (button->accelerator() == key)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void MenuBar::ActivateAccelerator(base::char16 key) {
|
||||
int i = GetAcceleratorIndex(key);
|
||||
if (i != -1) {
|
||||
SetAcceleratorVisibility(false);
|
||||
static_cast<SubmenuButton*>(child_at(i))->Activate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,10 @@ class MenuBar : public views::View,
|
|||
// Shows underline under accelerators.
|
||||
void SetAcceleratorVisibility(bool visible);
|
||||
|
||||
// Returns which submenu has accelerator |key|, -1 would be returned when
|
||||
// there is no matching submenu.
|
||||
int GetAcceleratorIndex(base::char16 key);
|
||||
|
||||
// Shows the submenu whose accelerator is |key|.
|
||||
void ActivateAccelerator(base::char16 key);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue