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 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // The spacing offset for the bubble tip. | 80 // The spacing offset for the bubble tip. |
81 const int kBubbleTipSizeLeftRight = 12; | 81 const int kBubbleTipSizeLeftRight = 12; |
82 const int kBubbleTipSizeTopBottom = 11; | 82 const int kBubbleTipSizeTopBottom = 11; |
83 | 83 |
84 // The maximum distance (in DIPS) that the mouse can be moved before it should | 84 // 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 | 85 // trigger a mouse menu item activation (regardless of how long the menu has |
86 // been showing). | 86 // been showing). |
87 const float kMaximumLengthMovedToActivate = 4.0f; | 87 const float kMaximumLengthMovedToActivate = 4.0f; |
88 | 88 |
89 // Returns true if the mnemonic of |menu| matches key. | 89 // Returns true if the mnemonic of |menu| matches key. |
90 bool MatchesMnemonic(MenuItemView* menu, char16 key) { | 90 bool MatchesMnemonic(MenuItemView* menu, base::char16 key) { |
91 return menu->GetMnemonic() == key; | 91 return menu->GetMnemonic() == key; |
92 } | 92 } |
93 | 93 |
94 // Returns true if |menu| doesn't have a mnemonic and first character of the its | 94 // Returns true if |menu| doesn't have a mnemonic and first character of the its |
95 // title is |key|. | 95 // title is |key|. |
96 bool TitleMatchesMnemonic(MenuItemView* menu, char16 key) { | 96 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { |
97 if (menu->GetMnemonic()) | 97 if (menu->GetMnemonic()) |
98 return false; | 98 return false; |
99 | 99 |
100 base::string16 lower_title = base::i18n::ToLower(menu->title()); | 100 base::string16 lower_title = base::i18n::ToLower(menu->title()); |
101 return !lower_title.empty() && lower_title[0] == key; | 101 return !lower_title.empty() && lower_title[0] == key; |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 // Returns the first descendant of |view| that is hot tracked. | 106 // Returns the first descendant of |view| that is hot tracked. |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 } | 1031 } |
1032 | 1032 |
1033 // NOTE: focus wasn't changed when the menu was shown. As such, don't | 1033 // NOTE: focus wasn't changed when the menu was shown. As such, don't |
1034 // dispatch key events otherwise the focused window will get the events. | 1034 // dispatch key events otherwise the focused window will get the events. |
1035 case WM_KEYDOWN: { | 1035 case WM_KEYDOWN: { |
1036 bool result = OnKeyDown(ui::KeyboardCodeFromNative(msg)); | 1036 bool result = OnKeyDown(ui::KeyboardCodeFromNative(msg)); |
1037 TranslateMessage(&msg); | 1037 TranslateMessage(&msg); |
1038 return result; | 1038 return result; |
1039 } | 1039 } |
1040 case WM_CHAR: | 1040 case WM_CHAR: |
1041 return !SelectByChar(static_cast<char16>(msg.wParam)); | 1041 return !SelectByChar(static_cast<base::char16>(msg.wParam)); |
1042 case WM_KEYUP: | 1042 case WM_KEYUP: |
1043 return true; | 1043 return true; |
1044 | 1044 |
1045 case WM_SYSKEYUP: | 1045 case WM_SYSKEYUP: |
1046 // We may have been shown on a system key, as such don't do anything | 1046 // We may have been shown on a system key, as such don't do anything |
1047 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and | 1047 // here. If another system key is pushed we'll get a WM_SYSKEYDOWN and |
1048 // close the menu. | 1048 // close the menu. |
1049 return true; | 1049 return true; |
1050 | 1050 |
1051 case WM_CANCELMODE: | 1051 case WM_CANCELMODE: |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 if (!item->GetParentMenuItem()) | 2039 if (!item->GetParentMenuItem()) |
2040 return; | 2040 return; |
2041 if (item->HasSubmenu() && item->GetSubmenu()->IsShowing()) | 2041 if (item->HasSubmenu() && item->GetSubmenu()->IsShowing()) |
2042 SetSelection(item, SELECTION_UPDATE_IMMEDIATELY); | 2042 SetSelection(item, SELECTION_UPDATE_IMMEDIATELY); |
2043 else if (item->GetParentMenuItem()->GetParentMenuItem()) | 2043 else if (item->GetParentMenuItem()->GetParentMenuItem()) |
2044 SetSelection(item->GetParentMenuItem(), SELECTION_UPDATE_IMMEDIATELY); | 2044 SetSelection(item->GetParentMenuItem(), SELECTION_UPDATE_IMMEDIATELY); |
2045 } | 2045 } |
2046 | 2046 |
2047 MenuController::SelectByCharDetails MenuController::FindChildForMnemonic( | 2047 MenuController::SelectByCharDetails MenuController::FindChildForMnemonic( |
2048 MenuItemView* parent, | 2048 MenuItemView* parent, |
2049 char16 key, | 2049 base::char16 key, |
2050 bool (*match_function)(MenuItemView* menu, char16 mnemonic)) { | 2050 bool (*match_function)(MenuItemView* menu, base::char16 mnemonic)) { |
2051 SubmenuView* submenu = parent->GetSubmenu(); | 2051 SubmenuView* submenu = parent->GetSubmenu(); |
2052 DCHECK(submenu); | 2052 DCHECK(submenu); |
2053 SelectByCharDetails details; | 2053 SelectByCharDetails details; |
2054 | 2054 |
2055 for (int i = 0, menu_item_count = submenu->GetMenuItemCount(); | 2055 for (int i = 0, menu_item_count = submenu->GetMenuItemCount(); |
2056 i < menu_item_count; ++i) { | 2056 i < menu_item_count; ++i) { |
2057 MenuItemView* child = submenu->GetMenuItemAt(i); | 2057 MenuItemView* child = submenu->GetMenuItemAt(i); |
2058 if (child->enabled() && child->visible()) { | 2058 if (child->enabled() && child->visible()) { |
2059 if (child == pending_state_.item) | 2059 if (child == pending_state_.item) |
2060 details.index_of_item = i; | 2060 details.index_of_item = i; |
(...skipping 30 matching lines...) Expand all Loading... |
2091 } else if (details.index_of_item == -1 || details.next_match == -1) { | 2091 } else if (details.index_of_item == -1 || details.next_match == -1) { |
2092 SetSelection(submenu->GetMenuItemAt(details.first_match), | 2092 SetSelection(submenu->GetMenuItemAt(details.first_match), |
2093 SELECTION_DEFAULT); | 2093 SELECTION_DEFAULT); |
2094 } else { | 2094 } else { |
2095 SetSelection(submenu->GetMenuItemAt(details.next_match), | 2095 SetSelection(submenu->GetMenuItemAt(details.next_match), |
2096 SELECTION_DEFAULT); | 2096 SELECTION_DEFAULT); |
2097 } | 2097 } |
2098 return false; | 2098 return false; |
2099 } | 2099 } |
2100 | 2100 |
2101 bool MenuController::SelectByChar(char16 character) { | 2101 bool MenuController::SelectByChar(base::char16 character) { |
2102 char16 char_array[] = { character, 0 }; | 2102 base::char16 char_array[] = { character, 0 }; |
2103 char16 key = base::i18n::ToLower(char_array)[0]; | 2103 base::char16 key = base::i18n::ToLower(char_array)[0]; |
2104 MenuItemView* item = pending_state_.item; | 2104 MenuItemView* item = pending_state_.item; |
2105 if (!item->HasSubmenu() || !item->GetSubmenu()->IsShowing()) | 2105 if (!item->HasSubmenu() || !item->GetSubmenu()->IsShowing()) |
2106 item = item->GetParentMenuItem(); | 2106 item = item->GetParentMenuItem(); |
2107 DCHECK(item); | 2107 DCHECK(item); |
2108 DCHECK(item->HasSubmenu()); | 2108 DCHECK(item->HasSubmenu()); |
2109 DCHECK(item->GetSubmenu()); | 2109 DCHECK(item->GetSubmenu()); |
2110 if (item->GetSubmenu()->GetMenuItemCount() == 0) | 2110 if (item->GetSubmenu()->GetMenuItemCount() == 0) |
2111 return false; | 2111 return false; |
2112 | 2112 |
2113 // Look for matches based on mnemonic first. | 2113 // Look for matches based on mnemonic first. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2337 (!pending_state_.item->HasSubmenu() || | 2337 (!pending_state_.item->HasSubmenu() || |
2338 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2338 !pending_state_.item->GetSubmenu()->IsShowing())) { |
2339 // On exit if the user hasn't selected an item with a submenu, move the | 2339 // On exit if the user hasn't selected an item with a submenu, move the |
2340 // selection back to the parent menu item. | 2340 // selection back to the parent menu item. |
2341 SetSelection(pending_state_.item->GetParentMenuItem(), | 2341 SetSelection(pending_state_.item->GetParentMenuItem(), |
2342 SELECTION_OPEN_SUBMENU); | 2342 SELECTION_OPEN_SUBMENU); |
2343 } | 2343 } |
2344 } | 2344 } |
2345 | 2345 |
2346 } // namespace views | 2346 } // namespace views |
OLD | NEW |