| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 current_mouse_event_target_ = nullptr; | 1016 current_mouse_event_target_ = nullptr; |
| 1017 if (showing_ && should_close && GetActiveInstance() == this) { | 1017 if (showing_ && should_close && GetActiveInstance() == this) { |
| 1018 CloseAllNestedMenus(); | 1018 CloseAllNestedMenus(); |
| 1019 Cancel(EXIT_ALL); | 1019 Cancel(EXIT_ALL); |
| 1020 } else if (async_run_) { | 1020 } else if (async_run_) { |
| 1021 ExitAsyncRun(); | 1021 ExitAsyncRun(); |
| 1022 } | 1022 } |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 ui::PostDispatchAction MenuController::OnWillDispatchKeyEvent( | 1025 ui::PostDispatchAction MenuController::OnWillDispatchKeyEvent( |
| 1026 base::char16 character, | 1026 ui::KeyEvent* event) { |
| 1027 ui::KeyboardCode key_code) { | 1027 if (exit_type() == EXIT_ALL || exit_type() == EXIT_DESTROYED) { |
| 1028 if (exit_type() == MenuController::EXIT_ALL || | 1028 // If the event has arrived after the menu's exit type had changed but |
| 1029 exit_type() == MenuController::EXIT_DESTROYED) { | 1029 // before its message loop terminated, the event will continue its normal |
| 1030 // propagation for the following reason: |
| 1031 // If the user accepts a menu item in a nested menu, the menu item action is |
| 1032 // run after the base::RunLoop for the innermost menu has quit but before |
| 1033 // the base::RunLoop for the outermost menu has quit. If the menu item |
| 1034 // action starts a base::RunLoop, the outermost menu's base::RunLoop will |
| 1035 // not quit till the action's base::RunLoop ends. IDC_BOOKMARK_BAR_OPEN_ALL |
| 1036 // sometimes opens a modal dialog. The modal dialog starts a base::RunLoop |
| 1037 // and keeps the base::RunLoop running for the duration of its lifetime. |
| 1030 TerminateNestedMessageLoopIfNecessary(); | 1038 TerminateNestedMessageLoopIfNecessary(); |
| 1031 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 1039 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 1032 } | 1040 } |
| 1033 | 1041 |
| 1034 if (character) | 1042 event->StopPropagation(); |
| 1035 SelectByChar(character); | |
| 1036 else | |
| 1037 OnKeyDown(key_code); | |
| 1038 | 1043 |
| 1039 // MenuController may have been deleted, so check for an active instance | 1044 if (event->type() == ui::ET_KEY_PRESSED) { |
| 1040 // before accessing member variables. | 1045 OnKeyDown(event->key_code()); |
| 1041 if (GetActiveInstance()) | 1046 // Menu controller might have been deleted. |
| 1042 TerminateNestedMessageLoopIfNecessary(); | 1047 if (!GetActiveInstance()) |
| 1048 return ui::POST_DISPATCH_NONE; |
| 1043 | 1049 |
| 1050 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. For |
| 1051 // example Ctrl+<T> is an accelerator, but <T> only is a mnemonic. |
| 1052 const int kKeyFlagsMask = ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN; |
| 1053 const int flags = event->flags(); |
| 1054 if (exit_type() == EXIT_NONE && (flags & kKeyFlagsMask) == 0) { |
| 1055 base::char16 c = event->GetCharacter(); |
| 1056 SelectByChar(c); |
| 1057 // Menu controller might have been deleted. |
| 1058 if (!GetActiveInstance()) |
| 1059 return ui::POST_DISPATCH_NONE; |
| 1060 } |
| 1061 } |
| 1062 |
| 1063 if (!TerminateNestedMessageLoopIfNecessary()) { |
| 1064 ui::Accelerator accelerator(*event); |
| 1065 ViewsDelegate::ProcessMenuAcceleratorResult result = |
| 1066 ViewsDelegate::GetInstance()->ProcessAcceleratorWhileMenuShowing( |
| 1067 accelerator); |
| 1068 if (result == ViewsDelegate::ProcessMenuAcceleratorResult::CLOSE_MENU) |
| 1069 CancelAll(); |
| 1070 } |
| 1044 return ui::POST_DISPATCH_NONE; | 1071 return ui::POST_DISPATCH_NONE; |
| 1045 } | 1072 } |
| 1046 | 1073 |
| 1047 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { | 1074 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { |
| 1048 if (submenu->IsShowing()) { | 1075 if (submenu->IsShowing()) { |
| 1049 gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint(); | 1076 gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 1050 const SubmenuView* root_submenu = | 1077 const SubmenuView* root_submenu = |
| 1051 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); | 1078 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); |
| 1052 View::ConvertPointFromScreen( | 1079 View::ConvertPointFromScreen( |
| 1053 root_submenu->GetWidget()->GetRootView(), &point); | 1080 root_submenu->GetWidget()->GetRootView(), &point); |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 if (hot_button_) | 2705 if (hot_button_) |
| 2679 hot_button_->SetHotTracked(false); | 2706 hot_button_->SetHotTracked(false); |
| 2680 hot_button_ = hot_button; | 2707 hot_button_ = hot_button; |
| 2681 if (hot_button) { | 2708 if (hot_button) { |
| 2682 hot_button->SetHotTracked(true); | 2709 hot_button->SetHotTracked(true); |
| 2683 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); | 2710 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); |
| 2684 } | 2711 } |
| 2685 } | 2712 } |
| 2686 | 2713 |
| 2687 } // namespace views | 2714 } // namespace views |
| OLD | NEW |