blob: 2fc3438c87aa2499c66810ea1cc63cc4a3c32907 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accelerators/nested_accelerator_delegate.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/shell.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/views/controls/menu/menu_controller.h"
namespace ash {
namespace {
bool IsPossibleAcceleratorNotForMenu(const ui::Accelerator& accelerator) {
// For shortcuts generated by Ctrl or Alt plus a letter, number or
// the tab key, we want to exit the context menu first and then
// repost the event. That allows for the shortcut execution after
// the context menu has exited.
if (accelerator.type() == ui::ET_KEY_PRESSED &&
(accelerator.modifiers() & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN))) {
const ui::KeyboardCode key_code = accelerator.key_code();
if ((key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z) ||
(key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9) ||
(key_code == ui::VKEY_TAB)) {
return true;
}
}
return false;
}
bool ShouldProcessAcceleratorNow(const ui::Accelerator& accelerator) {
if (!IsPossibleAcceleratorNotForMenu(accelerator))
return true;
if (views::MenuController* menu_controller =
views::MenuController::GetActiveInstance()) {
menu_controller->CancelAll();
return false;
}
return true;
}
} // namespace
NestedAcceleratorDelegate::NestedAcceleratorDelegate() {
}
NestedAcceleratorDelegate::~NestedAcceleratorDelegate() {
}
NestedAcceleratorDelegate::Result NestedAcceleratorDelegate::ProcessAccelerator(
const ui::Accelerator& accelerator) {
if (!ShouldProcessAcceleratorNow(accelerator))
return RESULT_PROCESS_LATER;
ash::AcceleratorController* accelerator_controller =
ash::Shell::GetInstance()->accelerator_controller();
if (!accelerator_controller)
return RESULT_NOT_PROCESSED;
return accelerator_controller->Process(accelerator) ? RESULT_PROCESSED
: RESULT_NOT_PROCESSED;
}
} // namespace ash
|