blob: 8f2c8e815c22ae5465fb1b5f6941ca613e88b43a (
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
|
// Copyright (c) 2011 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 "views/focus/accelerator_handler.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/keycodes/keyboard_code_conversion_win.h"
#include "views/events/event.h"
#include "views/focus/focus_manager.h"
#include "views/widget/widget.h"
namespace views {
AcceleratorHandler::AcceleratorHandler() {
}
bool AcceleratorHandler::Dispatch(const MSG& msg) {
bool process_message = true;
if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) {
Widget* widget = Widget::GetTopLevelWidgetForNativeView(msg.hwnd);
FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL;
if (focus_manager) {
switch (msg.message) {
case WM_KEYDOWN:
case WM_SYSKEYDOWN: {
KeyEvent event(msg);
process_message = focus_manager->OnKeyEvent(event);
if (!process_message) {
// Record that this key is pressed so we can remember not to
// translate and dispatch the associated WM_KEYUP.
pressed_keys_.insert(msg.wParam);
}
break;
}
case WM_KEYUP:
case WM_SYSKEYUP: {
std::set<WPARAM>::iterator iter = pressed_keys_.find(msg.wParam);
if (iter != pressed_keys_.end()) {
// Don't translate/dispatch the KEYUP since we have eaten the
// associated KEYDOWN.
pressed_keys_.erase(iter);
return true;
}
break;
}
}
}
}
if (process_message) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return true;
}
} // namespace views
|