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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "ui/base/dragdrop/drag_utils.h" | 11 #include "ui/base/dragdrop/drag_utils.h" |
12 #include "ui/base/dragdrop/os_exchange_data.h" | 12 #include "ui/base/dragdrop/os_exchange_data.h" |
13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
14 #include "ui/events/event_utils.h" | 14 #include "ui/events/event_utils.h" |
| 15 #include "ui/events/keycodes/keyboard_code_conversion.h" |
15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
17 #include "ui/gfx/geometry/vector2d.h" | 18 #include "ui/gfx/geometry/vector2d.h" |
18 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
19 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
20 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
21 #include "ui/views/controls/button/menu_button.h" | 22 #include "ui/views/controls/button/menu_button.h" |
22 #include "ui/views/controls/menu/menu_config.h" | 23 #include "ui/views/controls/menu/menu_config.h" |
23 #include "ui/views/controls/menu/menu_controller_delegate.h" | 24 #include "ui/views/controls/menu/menu_controller_delegate.h" |
24 #include "ui/views/controls/menu/menu_host_root_view.h" | 25 #include "ui/views/controls/menu/menu_host_root_view.h" |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 | 798 |
798 void MenuController::OnDragComplete(bool should_close) { | 799 void MenuController::OnDragComplete(bool should_close) { |
799 DCHECK(drag_in_progress_); | 800 DCHECK(drag_in_progress_); |
800 drag_in_progress_ = false; | 801 drag_in_progress_ = false; |
801 if (showing_ && should_close && GetActiveInstance() == this) { | 802 if (showing_ && should_close && GetActiveInstance() == this) { |
802 CloseAllNestedMenus(); | 803 CloseAllNestedMenus(); |
803 Cancel(EXIT_ALL); | 804 Cancel(EXIT_ALL); |
804 } | 805 } |
805 } | 806 } |
806 | 807 |
| 808 ui::PostDispatchAction MenuController::OnWillDispatchEvent( |
| 809 const ui::Event& event) { |
| 810 if (exit_type() == MenuController::EXIT_ALL || |
| 811 exit_type() == MenuController::EXIT_DESTROYED) { |
| 812 TerminateNestedMessageLoop(); |
| 813 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 814 } |
| 815 |
| 816 bool should_quit = false; |
| 817 bool should_perform_default = true; |
| 818 switch (event.type()) { |
| 819 case ui::ET_KEY_PRESSED: { |
| 820 const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event); |
| 821 if (!OnKeyDown(key_event.key_code())) { |
| 822 should_quit = true; |
| 823 should_perform_default = false; |
| 824 break; |
| 825 } |
| 826 |
| 827 // Do not check mnemonics if the Alt or Ctrl modifiers are pressed. |
| 828 int flags = key_event.flags(); |
| 829 if ((flags & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) == 0) { |
| 830 char c = ui::GetCharacterFromKeyCode(key_event.key_code(), flags); |
| 831 if (SelectByChar(c)) { |
| 832 should_quit = true; |
| 833 should_perform_default = false; |
| 834 break; |
| 835 } |
| 836 } |
| 837 should_quit = false; |
| 838 should_perform_default = false; |
| 839 break; |
| 840 } |
| 841 case ui::ET_KEY_RELEASED: |
| 842 should_quit = false; |
| 843 should_perform_default = false; |
| 844 break; |
| 845 default: |
| 846 break; |
| 847 } |
| 848 |
| 849 if (should_quit || exit_type() != MenuController::EXIT_NONE) |
| 850 TerminateNestedMessageLoop(); |
| 851 |
| 852 return should_perform_default ? ui::POST_DISPATCH_PERFORM_DEFAULT |
| 853 : ui::POST_DISPATCH_NONE; |
| 854 } |
| 855 |
807 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { | 856 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { |
808 if (submenu->IsShowing()) { | 857 if (submenu->IsShowing()) { |
809 gfx::Point point = GetScreen()->GetCursorScreenPoint(); | 858 gfx::Point point = GetScreen()->GetCursorScreenPoint(); |
810 const SubmenuView* root_submenu = | 859 const SubmenuView* root_submenu = |
811 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); | 860 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); |
812 View::ConvertPointFromScreen( | 861 View::ConvertPointFromScreen( |
813 root_submenu->GetWidget()->GetRootView(), &point); | 862 root_submenu->GetWidget()->GetRootView(), &point); |
814 HandleMouseLocation(submenu, point); | 863 HandleMouseLocation(submenu, point); |
815 } | 864 } |
816 } | 865 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 OpenSubmenuChangeSelectionIfCan(); | 1070 OpenSubmenuChangeSelectionIfCan(); |
1022 break; | 1071 break; |
1023 | 1072 |
1024 case ui::VKEY_LEFT: | 1073 case ui::VKEY_LEFT: |
1025 if (base::i18n::IsRTL()) | 1074 if (base::i18n::IsRTL()) |
1026 OpenSubmenuChangeSelectionIfCan(); | 1075 OpenSubmenuChangeSelectionIfCan(); |
1027 else | 1076 else |
1028 CloseSubmenu(); | 1077 CloseSubmenu(); |
1029 break; | 1078 break; |
1030 | 1079 |
| 1080 // On Mac, treat space the same as return. |
| 1081 #if !defined(OS_MACOSX) |
1031 case ui::VKEY_SPACE: | 1082 case ui::VKEY_SPACE: |
1032 if (SendAcceleratorToHotTrackedView() == ACCELERATOR_PROCESSED_EXIT) | 1083 if (SendAcceleratorToHotTrackedView() == ACCELERATOR_PROCESSED_EXIT) |
1033 return false; | 1084 return false; |
1034 break; | 1085 break; |
| 1086 #endif |
1035 | 1087 |
1036 case ui::VKEY_F4: | 1088 case ui::VKEY_F4: |
1037 if (!is_combobox_) | 1089 if (!is_combobox_) |
1038 break; | 1090 break; |
1039 // Fallthrough to accept or dismiss combobox menus on F4, like windows. | 1091 // Fallthrough to accept or dismiss combobox menus on F4, like windows. |
1040 case ui::VKEY_RETURN: | 1092 case ui::VKEY_RETURN: |
| 1093 #if defined(OS_MACOSX) |
| 1094 case ui::VKEY_SPACE: |
| 1095 #endif |
1041 if (pending_state_.item) { | 1096 if (pending_state_.item) { |
1042 if (pending_state_.item->HasSubmenu()) { | 1097 if (pending_state_.item->HasSubmenu()) { |
1043 if (key_code == ui::VKEY_F4 && | 1098 if (key_code == ui::VKEY_F4 && |
1044 pending_state_.item->GetSubmenu()->IsShowing()) | 1099 pending_state_.item->GetSubmenu()->IsShowing()) |
1045 return false; | 1100 return false; |
1046 else | 1101 else |
1047 OpenSubmenuChangeSelectionIfCan(); | 1102 OpenSubmenuChangeSelectionIfCan(); |
1048 } else { | 1103 } else { |
1049 SendAcceleratorResultType result = SendAcceleratorToHotTrackedView(); | 1104 SendAcceleratorResultType result = SendAcceleratorToHotTrackedView(); |
1050 if (result == ACCELERATOR_NOT_PROCESSED && | 1105 if (result == ACCELERATOR_NOT_PROCESSED && |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 } | 2361 } |
2307 } | 2362 } |
2308 | 2363 |
2309 gfx::Screen* MenuController::GetScreen() { | 2364 gfx::Screen* MenuController::GetScreen() { |
2310 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; | 2365 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; |
2311 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) | 2366 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) |
2312 : gfx::Screen::GetNativeScreen(); | 2367 : gfx::Screen::GetNativeScreen(); |
2313 } | 2368 } |
2314 | 2369 |
2315 } // namespace views | 2370 } // namespace views |
OLD | NEW |