OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/focus/accelerator_handler.h" | 5 #include "views/focus/accelerator_handler.h" |
6 | 6 |
7 #include "ui/base/keycodes/keyboard_codes.h" | 7 #include "ui/base/keycodes/keyboard_codes.h" |
8 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 8 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
9 #include "views/events/event.h" | 9 #include "views/events/event.h" |
10 #include "views/focus/focus_manager.h" | 10 #include "views/focus/focus_manager.h" |
11 | 11 |
12 namespace views { | 12 namespace views { |
13 | 13 |
| 14 namespace { |
| 15 |
| 16 // Since AcceleratorHandler's Dispatch method is called regardless of the level |
| 17 // of MessageLoop nesting, we maintain a stack of MSGs so that code run from |
| 18 // each loop gets the correct MSG. This scoping class handles pushing and |
| 19 // popping before and after calls to DispatchMessage(). |
| 20 class ScopedCurrentMessage { |
| 21 public: |
| 22 ScopedCurrentMessage(const MSG& msg, std::vector<MSG>* msg_stack) |
| 23 : msg_stack_(msg_stack) { |
| 24 msg_stack_->push_back(msg); |
| 25 } |
| 26 ~ScopedCurrentMessage() { |
| 27 msg_stack_->pop_back(); |
| 28 } |
| 29 |
| 30 private: |
| 31 std::vector<MSG>* msg_stack_; |
| 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(ScopedCurrentMessage); |
| 34 }; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 // static |
| 39 std::vector<MSG>* AcceleratorHandler::current_messages_ = NULL; |
| 40 |
14 AcceleratorHandler::AcceleratorHandler() { | 41 AcceleratorHandler::AcceleratorHandler() { |
15 } | 42 } |
16 | 43 |
17 bool AcceleratorHandler::Dispatch(const MSG& msg) { | 44 bool AcceleratorHandler::Dispatch(const MSG& msg) { |
| 45 if (!current_messages_) |
| 46 current_messages_ = new std::vector<MSG>; |
| 47 ScopedCurrentMessage current_message(msg, current_messages_); |
| 48 |
18 bool process_message = true; | 49 bool process_message = true; |
19 | 50 |
20 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { | 51 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { |
21 FocusManager* focus_manager = | 52 FocusManager* focus_manager = |
22 FocusManager::GetFocusManagerForNativeView(msg.hwnd); | 53 FocusManager::GetFocusManagerForNativeView(msg.hwnd); |
23 if (focus_manager) { | 54 if (focus_manager) { |
24 switch (msg.message) { | 55 switch (msg.message) { |
25 case WM_KEYDOWN: | 56 case WM_KEYDOWN: |
26 case WM_SYSKEYDOWN: { | 57 case WM_SYSKEYDOWN: { |
27 KeyEvent event(ui::ET_KEY_PRESSED, | 58 KeyEvent event(msg); |
28 ui::KeyboardCodeForWindowsKeyCode(msg.wParam), | |
29 KeyEvent::GetKeyStateFlags(), | |
30 msg.lParam & 0xFFFF, | |
31 (msg.lParam & 0xFFFF0000) >> 16); | |
32 process_message = focus_manager->OnKeyEvent(event); | 59 process_message = focus_manager->OnKeyEvent(event); |
33 if (!process_message) { | 60 if (!process_message) { |
34 // Record that this key is pressed so we can remember not to | 61 // Record that this key is pressed so we can remember not to |
35 // translate and dispatch the associated WM_KEYUP. | 62 // translate and dispatch the associated WM_KEYUP. |
36 pressed_keys_.insert(msg.wParam); | 63 pressed_keys_.insert(msg.wParam); |
37 } | 64 } |
38 break; | 65 break; |
39 } | 66 } |
40 case WM_KEYUP: | 67 case WM_KEYUP: |
41 case WM_SYSKEYUP: { | 68 case WM_SYSKEYUP: { |
(...skipping 12 matching lines...) Expand all Loading... |
54 | 81 |
55 if (process_message) { | 82 if (process_message) { |
56 TranslateMessage(&msg); | 83 TranslateMessage(&msg); |
57 DispatchMessage(&msg); | 84 DispatchMessage(&msg); |
58 } | 85 } |
59 | 86 |
60 return true; | 87 return true; |
61 } | 88 } |
62 | 89 |
63 } // namespace views | 90 } // namespace views |
OLD | NEW |