OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/controls/menu/menu_event_dispatcher_linux.h" | 5 #include "ui/views/controls/menu/menu_event_dispatcher_linux.h" |
6 | 6 |
7 #include "ui/events/event_utils.h" | 7 #include "ui/events/event_utils.h" |
8 #include "ui/events/keycodes/keyboard_code_conversion.h" | 8 #include "ui/events/keycodes/keyboard_code_conversion.h" |
9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
10 #include "ui/views/controls/menu/menu_controller.h" | 10 #include "ui/views/controls/menu/menu_controller.h" |
11 | 11 |
12 namespace views { | 12 namespace views { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller) | 15 MenuEventDispatcher::MenuEventDispatcher(MenuController* controller) |
16 : menu_controller_(controller) {} | 16 : menu_controller_(controller) {} |
17 | 17 |
18 MenuEventDispatcher::~MenuEventDispatcher() {} | 18 MenuEventDispatcher::~MenuEventDispatcher() {} |
19 | 19 |
20 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) { | 20 bool MenuEventDispatcher::CanDispatchEvent(const ui::PlatformEvent& event) { |
21 return true; | 21 return true; |
22 } | 22 } |
23 | 23 |
24 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) { | 24 uint32_t MenuEventDispatcher::DispatchEvent(const ui::PlatformEvent& event) { |
| 25 bool should_quit = false; |
| 26 bool should_perform_default = true; |
25 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || | 27 if (menu_controller_->exit_type() == MenuController::EXIT_ALL || |
26 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) | 28 menu_controller_->exit_type() == MenuController::EXIT_DESTROYED) { |
27 return (ui::POST_DISPATCH_QUIT_LOOP | ui::POST_DISPATCH_PERFORM_DEFAULT); | 29 should_quit = true; |
| 30 } else { |
| 31 switch (ui::EventTypeFromNative(event)) { |
| 32 case ui::ET_KEY_PRESSED: { |
| 33 if (!menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(event))) { |
| 34 should_quit = true; |
| 35 should_perform_default = false; |
| 36 break; |
| 37 } |
28 | 38 |
29 switch (ui::EventTypeFromNative(event)) { | 39 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. |
30 case ui::ET_KEY_PRESSED: { | 40 int flags = ui::EventFlagsFromNative(event); |
31 if (!menu_controller_->OnKeyDown(ui::KeyboardCodeFromNative(event))) | 41 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) { |
32 return ui::POST_DISPATCH_QUIT_LOOP; | 42 char c = ui::GetCharacterFromKeyCode( |
33 | 43 ui::KeyboardCodeFromNative(event), flags); |
34 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. | 44 if (menu_controller_->SelectByChar(c)) { |
35 int flags = ui::EventFlagsFromNative(event); | 45 should_quit = true; |
36 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) { | 46 should_perform_default = false; |
37 char c = ui::GetCharacterFromKeyCode(ui::KeyboardCodeFromNative(event), | 47 break; |
38 flags); | 48 } |
39 if (menu_controller_->SelectByChar(c)) | 49 } |
40 return ui::POST_DISPATCH_QUIT_LOOP; | 50 should_quit = false; |
| 51 should_perform_default = false; |
| 52 break; |
41 } | 53 } |
42 return ui::POST_DISPATCH_NONE; | 54 case ui::ET_KEY_RELEASED: |
| 55 should_quit = false; |
| 56 should_perform_default = false; |
| 57 break; |
| 58 default: |
| 59 break; |
43 } | 60 } |
44 case ui::ET_KEY_RELEASED: | |
45 return ui::POST_DISPATCH_NONE; | |
46 default: | |
47 break; | |
48 } | 61 } |
49 | 62 |
50 return ui::POST_DISPATCH_PERFORM_DEFAULT | | 63 if (should_quit || menu_controller_->exit_type() != MenuController::EXIT_NONE) |
51 (menu_controller_->exit_type() == MenuController::EXIT_NONE | 64 menu_controller_->TerminateNestedMessageLoop(); |
52 ? ui::POST_DISPATCH_NONE | 65 |
53 : ui::POST_DISPATCH_QUIT_LOOP); | 66 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT |
| 67 : ui::POST_DISPATCH_NONE; |
54 } | 68 } |
55 | 69 |
56 } // namespace internal | 70 } // namespace internal |
57 } // namespace views | 71 } // namespace views |
OLD | NEW |