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