Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: ui/views/controls/menu/menu_controller.cc

Issue 2033433006: MacViews: Modify insertText handlers to correctly handle space key and simplify menu event dispatch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ||
1028 if (exit_type() == MenuController::EXIT_ALL || 1028 exit_type() == EXIT_DESTROYED) {
1029 exit_type() == MenuController::EXIT_DESTROYED) { 1029 // If the event has arrived after the menu's exit type had changed but
1030 // before its message loop terminated, the event will continue its normal
1031 // propagation for the following reason:
1032 // If the user accepts a menu item in a nested menu, the menu item action is
1033 // run after the base::RunLoop for the innermost menu has quit but before
1034 // the base::RunLoop for the outermost menu has quit. If the menu item
1035 // action starts a base::RunLoop, the outermost menu's base::RunLoop will
1036 // not quit till the action's base::RunLoop ends. IDC_BOOKMARK_BAR_OPEN_ALL
1037 // sometimes opens a modal dialog. The modal dialog starts a base::RunLoop
1038 // and keeps the base::RunLoop running for the duration of its lifetime.
1030 TerminateNestedMessageLoopIfNecessary(); 1039 TerminateNestedMessageLoopIfNecessary();
1031 return ui::POST_DISPATCH_PERFORM_DEFAULT; 1040 return ui::POST_DISPATCH_PERFORM_DEFAULT;
1032 } 1041 }
1033 1042
1034 if (character) 1043 event->StopPropagation();
1035 SelectByChar(character);
1036 else
1037 OnKeyDown(key_code);
1038 1044
1039 // MenuController may have been deleted, so check for an active instance 1045 if (event->type() == ui::ET_KEY_PRESSED) {
1040 // before accessing member variables. 1046 OnKeyDown(event->key_code());
1041 if (GetActiveInstance()) 1047 // Menu controller might have been deleted.
1042 TerminateNestedMessageLoopIfNecessary(); 1048 if (!GetActiveInstance())
1049 return ui::POST_DISPATCH_NONE;
1043 1050
1051 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. For
1052 // example Ctrl+<T> is an accelerator, but <T> only is a mnemonic.
1053 const int kKeyFlagsMask = ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN;
1054 const int flags = event->flags();
1055 if (exit_type() == EXIT_NONE &&
1056 (flags & kKeyFlagsMask) == 0) {
1057 base::char16 c = event->GetCharacter();
1058 SelectByChar(c);
1059 // Menu controller might have been deleted.
1060 if (!GetActiveInstance())
1061 return ui::POST_DISPATCH_NONE;
1062 }
1063 }
1064
1065 if (!TerminateNestedMessageLoopIfNecessary()) {
1066 ui::Accelerator accelerator(*event);
1067 ViewsDelegate::ProcessMenuAcceleratorResult result =
1068 ViewsDelegate::GetInstance()->ProcessAcceleratorWhileMenuShowing(
1069 accelerator);
1070 if (result == ViewsDelegate::ProcessMenuAcceleratorResult::CLOSE_MENU)
1071 CancelAll();
1072 }
1044 return ui::POST_DISPATCH_NONE; 1073 return ui::POST_DISPATCH_NONE;
1045 } 1074 }
1046 1075
1047 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { 1076 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) {
1048 if (submenu->IsShowing()) { 1077 if (submenu->IsShowing()) {
1049 gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint(); 1078 gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint();
1050 const SubmenuView* root_submenu = 1079 const SubmenuView* root_submenu =
1051 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); 1080 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu();
1052 View::ConvertPointFromScreen( 1081 View::ConvertPointFromScreen(
1053 root_submenu->GetWidget()->GetRootView(), &point); 1082 root_submenu->GetWidget()->GetRootView(), &point);
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 if (hot_button_) 2707 if (hot_button_)
2679 hot_button_->SetHotTracked(false); 2708 hot_button_->SetHotTracked(false);
2680 hot_button_ = hot_button; 2709 hot_button_ = hot_button;
2681 if (hot_button) { 2710 if (hot_button) {
2682 hot_button->SetHotTracked(true); 2711 hot_button->SetHotTracked(true);
2683 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); 2712 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
2684 } 2713 }
2685 } 2714 }
2686 2715
2687 } // namespace views 2716 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698