| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 "ui/views/controls/menu/menu_message_pump_dispatcher_win.h" | |
| 6 | |
| 7 #include <windowsx.h> | |
| 8 | |
| 9 #include "ui/events/event_utils.h" | |
| 10 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | |
| 12 #include "ui/views/controls/menu/menu_controller.h" | |
| 13 #include "ui/views/controls/menu/menu_item_view.h" | |
| 14 | |
| 15 namespace views { | |
| 16 namespace internal { | |
| 17 | |
| 18 MenuMessagePumpDispatcher::MenuMessagePumpDispatcher(MenuController* controller) | |
| 19 : menu_controller_(controller) {} | |
| 20 | |
| 21 MenuMessagePumpDispatcher::~MenuMessagePumpDispatcher() {} | |
| 22 | |
| 23 uint32_t MenuMessagePumpDispatcher::Dispatch(const MSG& msg) { | |
| 24 DCHECK(menu_controller_->IsBlockingRun()); | |
| 25 | |
| 26 bool should_perform_default = true; | |
| 27 if (menu_controller_->exit_type() != MenuController::EXIT_ALL && | |
| 28 menu_controller_->exit_type() != MenuController::EXIT_DESTROYED) { | |
| 29 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here. | |
| 30 switch (msg.message) { | |
| 31 // NOTE: focus wasn't changed when the menu was shown. As such, don't | |
| 32 // dispatch key events otherwise the focused window will get the events. | |
| 33 case WM_KEYDOWN: { | |
| 34 menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(msg)); | |
| 35 TranslateMessage(&msg); | |
| 36 should_perform_default = false; | |
| 37 break; | |
| 38 } | |
| 39 case WM_CHAR: { | |
| 40 menu_controller_->SelectByChar(static_cast<base::char16>(msg.wParam)); | |
| 41 should_perform_default = false; | |
| 42 break; | |
| 43 } | |
| 44 case WM_KEYUP: | |
| 45 case WM_SYSKEYUP: | |
| 46 // We may have been shown on a system key, as such don't do anything | |
| 47 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and | |
| 48 // close the menu. | |
| 49 should_perform_default = false; | |
| 50 break; | |
| 51 | |
| 52 case WM_CANCELMODE: | |
| 53 case WM_SYSKEYDOWN: | |
| 54 // Exit immediately on system keys. | |
| 55 menu_controller_->Cancel(MenuController::EXIT_ALL); | |
| 56 should_perform_default = false; | |
| 57 break; | |
| 58 | |
| 59 default: | |
| 60 break; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 menu_controller_->TerminateNestedMessageLoopIfNecessary(); | |
| 65 return should_perform_default ? POST_DISPATCH_PERFORM_DEFAULT | |
| 66 : POST_DISPATCH_NONE; | |
| 67 } | |
| 68 | |
| 69 } // namespace internal | |
| 70 } // namespace views | |
| OLD | NEW |