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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "ui/base/dragdrop/drag_utils.h" | 16 #include "ui/base/dragdrop/drag_utils.h" |
17 #include "ui/base/dragdrop/os_exchange_data.h" | 17 #include "ui/base/dragdrop/os_exchange_data.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
20 #include "ui/events/event_utils.h" | 20 #include "ui/events/event_utils.h" |
| 21 #include "ui/events/keycodes/keyboard_code_conversion.h" |
21 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
22 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
24 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
25 #include "ui/gfx/vector2d.h" | 26 #include "ui/gfx/vector2d.h" |
26 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
27 #include "ui/views/controls/button/menu_button.h" | 28 #include "ui/views/controls/button/menu_button.h" |
28 #include "ui/views/controls/menu/menu_config.h" | 29 #include "ui/views/controls/menu/menu_config.h" |
29 #include "ui/views/controls/menu/menu_controller_delegate.h" | 30 #include "ui/views/controls/menu/menu_controller_delegate.h" |
30 #include "ui/views/controls/menu/menu_host_root_view.h" | 31 #include "ui/views/controls/menu/menu_host_root_view.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const int kBubbleTipSizeLeftRight = 12; | 82 const int kBubbleTipSizeLeftRight = 12; |
82 const int kBubbleTipSizeTopBottom = 11; | 83 const int kBubbleTipSizeTopBottom = 11; |
83 | 84 |
84 // The maximum distance (in DIPS) that the mouse can be moved before it should | 85 // The maximum distance (in DIPS) that the mouse can be moved before it should |
85 // trigger a mouse menu item activation (regardless of how long the menu has | 86 // trigger a mouse menu item activation (regardless of how long the menu has |
86 // been showing). | 87 // been showing). |
87 const float kMaximumLengthMovedToActivate = 4.0f; | 88 const float kMaximumLengthMovedToActivate = 4.0f; |
88 | 89 |
89 // Returns true if the mnemonic of |menu| matches key. | 90 // Returns true if the mnemonic of |menu| matches key. |
90 bool MatchesMnemonic(MenuItemView* menu, base::char16 key) { | 91 bool MatchesMnemonic(MenuItemView* menu, base::char16 key) { |
91 return menu->GetMnemonic() == key; | 92 return key != 0 && menu->GetMnemonic() == key; |
92 } | 93 } |
93 | 94 |
94 // Returns true if |menu| doesn't have a mnemonic and first character of the its | 95 // Returns true if |menu| doesn't have a mnemonic and first character of the its |
95 // title is |key|. | 96 // title is |key|. |
96 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { | 97 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { |
97 if (menu->GetMnemonic()) | 98 if (menu->GetMnemonic()) |
98 return false; | 99 return false; |
99 | 100 |
100 base::string16 lower_title = base::i18n::ToLower(menu->title()); | 101 base::string16 lower_title = base::i18n::ToLower(menu->title()); |
101 return !lower_title.empty() && lower_title[0] == key; | 102 return !lower_title.empty() && lower_title[0] == key; |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 // Activates mnemonics only when it it pressed without modifiers except for | 1065 // Activates mnemonics only when it it pressed without modifiers except for |
1065 // caps and shift. | 1066 // caps and shift. |
1066 int flags = ui::EventFlagsFromNative(event) & | 1067 int flags = ui::EventFlagsFromNative(event) & |
1067 ~ui::EF_CAPS_LOCK_DOWN & ~ui::EF_SHIFT_DOWN; | 1068 ~ui::EF_CAPS_LOCK_DOWN & ~ui::EF_SHIFT_DOWN; |
1068 if (flags == ui::EF_NONE) { | 1069 if (flags == ui::EF_NONE) { |
1069 switch (ui::EventTypeFromNative(event)) { | 1070 switch (ui::EventTypeFromNative(event)) { |
1070 case ui::ET_KEY_PRESSED: { | 1071 case ui::ET_KEY_PRESSED: { |
1071 if (!OnKeyDown(ui::KeyboardCodeFromNative(event))) | 1072 if (!OnKeyDown(ui::KeyboardCodeFromNative(event))) |
1072 return POST_DISPATCH_QUIT_LOOP; | 1073 return POST_DISPATCH_QUIT_LOOP; |
1073 | 1074 |
1074 bool should_exit = SelectByChar(ui::KeyboardCodeFromNative(event)); | 1075 char c = ui::GetCharacterFromKeyCode( |
| 1076 ui::KeyboardCodeFromNative(event), flags); |
| 1077 bool should_exit = SelectByChar(c); |
1075 return should_exit ? POST_DISPATCH_QUIT_LOOP : POST_DISPATCH_NONE; | 1078 return should_exit ? POST_DISPATCH_QUIT_LOOP : POST_DISPATCH_NONE; |
1076 } | 1079 } |
1077 case ui::ET_KEY_RELEASED: | 1080 case ui::ET_KEY_RELEASED: |
1078 return POST_DISPATCH_NONE; | 1081 return POST_DISPATCH_NONE; |
1079 default: | 1082 default: |
1080 break; | 1083 break; |
1081 } | 1084 } |
1082 } | 1085 } |
1083 | 1086 |
1084 return POST_DISPATCH_PERFORM_DEFAULT | | 1087 return POST_DISPATCH_PERFORM_DEFAULT | |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2336 (!pending_state_.item->HasSubmenu() || | 2339 (!pending_state_.item->HasSubmenu() || |
2337 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2340 !pending_state_.item->GetSubmenu()->IsShowing())) { |
2338 // On exit if the user hasn't selected an item with a submenu, move the | 2341 // On exit if the user hasn't selected an item with a submenu, move the |
2339 // selection back to the parent menu item. | 2342 // selection back to the parent menu item. |
2340 SetSelection(pending_state_.item->GetParentMenuItem(), | 2343 SetSelection(pending_state_.item->GetParentMenuItem(), |
2341 SELECTION_OPEN_SUBMENU); | 2344 SELECTION_OPEN_SUBMENU); |
2342 } | 2345 } |
2343 } | 2346 } |
2344 | 2347 |
2345 } // namespace views | 2348 } // namespace views |
OLD | NEW |