OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "views/focus/accelerator_handler.h" | |
6 | |
7 #include "ui/base/keycodes/keyboard_codes.h" | |
8 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | |
9 #include "views/events/event.h" | |
10 #include "views/focus/focus_manager.h" | |
11 #include "views/widget/widget.h" | |
12 | |
13 namespace views { | |
14 | |
15 AcceleratorHandler::AcceleratorHandler() { | |
16 } | |
17 | |
18 bool AcceleratorHandler::Dispatch(const MSG& msg) { | |
19 bool process_message = true; | |
20 | |
21 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { | |
22 Widget* widget = Widget::GetTopLevelWidgetForNativeView(msg.hwnd); | |
23 FocusManager* focus_manager = widget ? widget->GetFocusManager() : NULL; | |
24 if (focus_manager) { | |
25 switch (msg.message) { | |
26 case WM_KEYDOWN: | |
27 case WM_SYSKEYDOWN: { | |
28 KeyEvent event(msg); | |
29 process_message = focus_manager->OnKeyEvent(event); | |
30 if (!process_message) { | |
31 // Record that this key is pressed so we can remember not to | |
32 // translate and dispatch the associated WM_KEYUP. | |
33 pressed_keys_.insert(msg.wParam); | |
34 } | |
35 break; | |
36 } | |
37 case WM_KEYUP: | |
38 case WM_SYSKEYUP: { | |
39 std::set<WPARAM>::iterator iter = pressed_keys_.find(msg.wParam); | |
40 if (iter != pressed_keys_.end()) { | |
41 // Don't translate/dispatch the KEYUP since we have eaten the | |
42 // associated KEYDOWN. | |
43 pressed_keys_.erase(iter); | |
44 return true; | |
45 } | |
46 break; | |
47 } | |
48 } | |
49 } | |
50 } | |
51 | |
52 if (process_message) { | |
53 TranslateMessage(&msg); | |
54 DispatchMessage(&msg); | |
55 } | |
56 | |
57 return true; | |
58 } | |
59 | |
60 } // namespace views | |
OLD | NEW |