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