Chromium Code Reviews| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 const int kCloseOnExitTime = 1200; | 69 const int kCloseOnExitTime = 1200; |
| 70 | 70 |
| 71 // If a context menu is invoked by touch, we shift the menu by this offset so | 71 // If a context menu is invoked by touch, we shift the menu by this offset so |
| 72 // that the finger does not obscure the menu. | 72 // that the finger does not obscure the menu. |
| 73 const int kCenteredContextMenuYOffset = -15; | 73 const int kCenteredContextMenuYOffset = -15; |
| 74 | 74 |
| 75 // The spacing offset for the bubble tip. | 75 // The spacing offset for the bubble tip. |
| 76 const int kBubbleTipSizeLeftRight = 12; | 76 const int kBubbleTipSizeLeftRight = 12; |
| 77 const int kBubbleTipSizeTopBottom = 11; | 77 const int kBubbleTipSizeTopBottom = 11; |
| 78 | 78 |
| 79 const int kKeyFlagsMask = ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN; | |
|
tapted
2016/06/07 01:23:28
Since this file is bigger, there should be a comme
karandeepb
2016/06/07 04:13:46
All the character events we are passing currently
| |
| 80 | |
| 79 // The maximum distance (in DIPS) that the mouse can be moved before it should | 81 // The maximum distance (in DIPS) that the mouse can be moved before it should |
| 80 // trigger a mouse menu item activation (regardless of how long the menu has | 82 // trigger a mouse menu item activation (regardless of how long the menu has |
| 81 // been showing). | 83 // been showing). |
| 82 const float kMaximumLengthMovedToActivate = 4.0f; | 84 const float kMaximumLengthMovedToActivate = 4.0f; |
| 83 | 85 |
| 84 // Returns true if the mnemonic of |menu| matches key. | 86 // Returns true if the mnemonic of |menu| matches key. |
| 85 bool MatchesMnemonic(MenuItemView* menu, base::char16 key) { | 87 bool MatchesMnemonic(MenuItemView* menu, base::char16 key) { |
| 86 return key != 0 && menu->GetMnemonic() == key; | 88 return key != 0 && menu->GetMnemonic() == key; |
| 87 } | 89 } |
| 88 | 90 |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 current_mouse_event_target_ = nullptr; | 1018 current_mouse_event_target_ = nullptr; |
| 1017 if (showing_ && should_close && GetActiveInstance() == this) { | 1019 if (showing_ && should_close && GetActiveInstance() == this) { |
| 1018 CloseAllNestedMenus(); | 1020 CloseAllNestedMenus(); |
| 1019 Cancel(EXIT_ALL); | 1021 Cancel(EXIT_ALL); |
| 1020 } else if (async_run_) { | 1022 } else if (async_run_) { |
| 1021 ExitAsyncRun(); | 1023 ExitAsyncRun(); |
| 1022 } | 1024 } |
| 1023 } | 1025 } |
| 1024 | 1026 |
| 1025 ui::PostDispatchAction MenuController::OnWillDispatchKeyEvent( | 1027 ui::PostDispatchAction MenuController::OnWillDispatchKeyEvent( |
| 1026 base::char16 character, | 1028 ui::KeyEvent* event) { |
| 1027 ui::KeyboardCode key_code) { | |
| 1028 if (exit_type() == MenuController::EXIT_ALL || | 1029 if (exit_type() == MenuController::EXIT_ALL || |
| 1029 exit_type() == MenuController::EXIT_DESTROYED) { | 1030 exit_type() == MenuController::EXIT_DESTROYED) { |
| 1031 // If the event has arrived after the menu's exit type had changed but | |
| 1032 // before its message loop terminated, the event will continue its normal | |
| 1033 // propagation for the following reason: | |
| 1034 // If the user accepts a menu item in a nested menu, the menu item action is | |
| 1035 // run after the base::RunLoop for the innermost menu has quit but before | |
| 1036 // the base::RunLoop for the outermost menu has quit. If the menu item | |
| 1037 // action starts a base::RunLoop, the outermost menu's base::RunLoop will | |
| 1038 // not quit till the action's base::RunLoop ends. IDC_BOOKMARK_BAR_OPEN_ALL | |
| 1039 // sometimes opens a modal dialog. The modal dialog starts a base::RunLoop | |
| 1040 // and keeps the base::RunLoop running for the duration of its lifetime. | |
| 1030 TerminateNestedMessageLoopIfNecessary(); | 1041 TerminateNestedMessageLoopIfNecessary(); |
| 1031 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 1042 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 1032 } | 1043 } |
| 1033 | 1044 |
| 1034 if (character) | 1045 event->StopPropagation(); |
| 1035 SelectByChar(character); | |
| 1036 else | |
| 1037 OnKeyDown(key_code); | |
| 1038 | 1046 |
| 1039 // MenuController may have been deleted, so check for an active instance | 1047 if (event->type() == ui::ET_KEY_PRESSED) { |
| 1040 // before accessing member variables. | 1048 OnKeyDown(event->key_code()); |
| 1041 if (GetActiveInstance()) | 1049 // Menu controller might have been deleted. |
| 1042 TerminateNestedMessageLoopIfNecessary(); | 1050 if (!MenuController::GetActiveInstance()) |
|
tapted
2016/06/07 01:23:28
Convention in the rest of this file is to omit the
karandeepb
2016/06/07 04:13:46
Done.
| |
| 1051 return ui::POST_DISPATCH_NONE; | |
| 1043 | 1052 |
| 1053 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. For | |
| 1054 // example Ctrl+<T> is an accelerator, but <T> only is a mnemonic. | |
| 1055 const int flags = event->flags(); | |
| 1056 if (exit_type() == MenuController::EXIT_NONE && | |
| 1057 (flags & kKeyFlagsMask) == 0) { | |
| 1058 base::char16 c = event->GetCharacter(); | |
| 1059 SelectByChar(c); | |
| 1060 // Menu controller might have been deleted. | |
| 1061 if (!MenuController::GetActiveInstance()) | |
| 1062 return ui::POST_DISPATCH_NONE; | |
| 1063 } | |
| 1064 } | |
| 1065 | |
| 1066 if (!TerminateNestedMessageLoopIfNecessary()) { | |
| 1067 ui::Accelerator accelerator(*event); | |
| 1068 ViewsDelegate::ProcessMenuAcceleratorResult result = | |
| 1069 ViewsDelegate::GetInstance()->ProcessAcceleratorWhileMenuShowing( | |
| 1070 accelerator); | |
| 1071 if (result == ViewsDelegate::ProcessMenuAcceleratorResult::CLOSE_MENU) | |
| 1072 CancelAll(); | |
| 1073 } | |
| 1044 return ui::POST_DISPATCH_NONE; | 1074 return ui::POST_DISPATCH_NONE; |
| 1045 } | 1075 } |
| 1046 | 1076 |
| 1047 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { | 1077 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { |
| 1048 if (submenu->IsShowing()) { | 1078 if (submenu->IsShowing()) { |
| 1049 gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint(); | 1079 gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 1050 const SubmenuView* root_submenu = | 1080 const SubmenuView* root_submenu = |
| 1051 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); | 1081 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); |
| 1052 View::ConvertPointFromScreen( | 1082 View::ConvertPointFromScreen( |
| 1053 root_submenu->GetWidget()->GetRootView(), &point); | 1083 root_submenu->GetWidget()->GetRootView(), &point); |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2678 if (hot_button_) | 2708 if (hot_button_) |
| 2679 hot_button_->SetHotTracked(false); | 2709 hot_button_->SetHotTracked(false); |
| 2680 hot_button_ = hot_button; | 2710 hot_button_ = hot_button; |
| 2681 if (hot_button) { | 2711 if (hot_button) { |
| 2682 hot_button->SetHotTracked(true); | 2712 hot_button->SetHotTracked(true); |
| 2683 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); | 2713 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); |
| 2684 } | 2714 } |
| 2685 } | 2715 } |
| 2686 | 2716 |
| 2687 } // namespace views | 2717 } // namespace views |
| OLD | NEW |