| 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_; |
| 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 ScopedCurrentMessage current_message(msg, ¤t_messages_); |
| 46 |
| 18 bool process_message = true; | 47 bool process_message = true; |
| 19 | 48 |
| 20 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { | 49 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { |
| 21 FocusManager* focus_manager = | 50 FocusManager* focus_manager = |
| 22 FocusManager::GetFocusManagerForNativeView(msg.hwnd); | 51 FocusManager::GetFocusManagerForNativeView(msg.hwnd); |
| 23 if (focus_manager) { | 52 if (focus_manager) { |
| 24 switch (msg.message) { | 53 switch (msg.message) { |
| 25 case WM_KEYDOWN: | 54 case WM_KEYDOWN: |
| 26 case WM_SYSKEYDOWN: { | 55 case WM_SYSKEYDOWN: { |
| 27 KeyEvent event(ui::ET_KEY_PRESSED, | 56 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); | 57 process_message = focus_manager->OnKeyEvent(event); |
| 33 if (!process_message) { | 58 if (!process_message) { |
| 34 // Record that this key is pressed so we can remember not to | 59 // Record that this key is pressed so we can remember not to |
| 35 // translate and dispatch the associated WM_KEYUP. | 60 // translate and dispatch the associated WM_KEYUP. |
| 36 pressed_keys_.insert(msg.wParam); | 61 pressed_keys_.insert(msg.wParam); |
| 37 } | 62 } |
| 38 break; | 63 break; |
| 39 } | 64 } |
| 40 case WM_KEYUP: | 65 case WM_KEYUP: |
| 41 case WM_SYSKEYUP: { | 66 case WM_SYSKEYUP: { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 54 | 79 |
| 55 if (process_message) { | 80 if (process_message) { |
| 56 TranslateMessage(&msg); | 81 TranslateMessage(&msg); |
| 57 DispatchMessage(&msg); | 82 DispatchMessage(&msg); |
| 58 } | 83 } |
| 59 | 84 |
| 60 return true; | 85 return true; |
| 61 } | 86 } |
| 62 | 87 |
| 63 } // namespace views | 88 } // namespace views |
| OLD | NEW |