OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 | 978 |
979 case ui::VKEY_SPACE: | 979 case ui::VKEY_SPACE: |
980 SendAcceleratorToHotTrackedView(); | 980 SendAcceleratorToHotTrackedView(); |
981 break; | 981 break; |
982 | 982 |
983 case ui::VKEY_RETURN: | 983 case ui::VKEY_RETURN: |
984 if (pending_state_.item) { | 984 if (pending_state_.item) { |
985 if (pending_state_.item->HasSubmenu()) { | 985 if (pending_state_.item->HasSubmenu()) { |
986 OpenSubmenuChangeSelectionIfCan(); | 986 OpenSubmenuChangeSelectionIfCan(); |
987 } else if (!SendAcceleratorToHotTrackedView() && | 987 } else if (!SendAcceleratorToHotTrackedView() && |
988 pending_state_.item->IsEnabled()) { | 988 pending_state_.item->enabled()) { |
989 Accept(pending_state_.item, 0); | 989 Accept(pending_state_.item, 0); |
990 return false; | 990 return false; |
991 } | 991 } |
992 } | 992 } |
993 break; | 993 break; |
994 | 994 |
995 case ui::VKEY_ESCAPE: | 995 case ui::VKEY_ESCAPE: |
996 if (!state_.item->GetParentMenuItem() || | 996 if (!state_.item->GetParentMenuItem() || |
997 (!state_.item->GetParentMenuItem()->GetParentMenuItem() && | 997 (!state_.item->GetParentMenuItem()->GetParentMenuItem() && |
998 (!state_.item->HasSubmenu() || | 998 (!state_.item->HasSubmenu() || |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 } | 1170 } |
1171 } | 1171 } |
1172 | 1172 |
1173 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { | 1173 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { |
1174 // Walk the view hierarchy until we find a menu item (or the root). | 1174 // Walk the view hierarchy until we find a menu item (or the root). |
1175 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); | 1175 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); |
1176 while (child_under_mouse && | 1176 while (child_under_mouse && |
1177 child_under_mouse->id() != MenuItemView::kMenuItemViewID) { | 1177 child_under_mouse->id() != MenuItemView::kMenuItemViewID) { |
1178 child_under_mouse = child_under_mouse->parent(); | 1178 child_under_mouse = child_under_mouse->parent(); |
1179 } | 1179 } |
1180 if (child_under_mouse && child_under_mouse->IsEnabled() && | 1180 if (child_under_mouse && child_under_mouse->enabled() && |
1181 child_under_mouse->id() == MenuItemView::kMenuItemViewID) { | 1181 child_under_mouse->id() == MenuItemView::kMenuItemViewID) { |
1182 return static_cast<MenuItemView*>(child_under_mouse); | 1182 return static_cast<MenuItemView*>(child_under_mouse); |
1183 } | 1183 } |
1184 return NULL; | 1184 return NULL; |
1185 } | 1185 } |
1186 | 1186 |
1187 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { | 1187 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { |
1188 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); | 1188 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); |
1189 if (child_under_mouse && | 1189 if (child_under_mouse && |
1190 child_under_mouse->id() == MenuItemView::kEmptyMenuItemViewID) { | 1190 child_under_mouse->id() == MenuItemView::kEmptyMenuItemViewID) { |
1191 return static_cast<MenuItemView*>(child_under_mouse); | 1191 return static_cast<MenuItemView*>(child_under_mouse); |
1192 } | 1192 } |
1193 return NULL; | 1193 return NULL; |
1194 } | 1194 } |
1195 | 1195 |
1196 bool MenuController::IsScrollButtonAt(SubmenuView* source, | 1196 bool MenuController::IsScrollButtonAt(SubmenuView* source, |
1197 int x, | 1197 int x, |
1198 int y, | 1198 int y, |
1199 MenuPart::Type* part) { | 1199 MenuPart::Type* part) { |
1200 MenuScrollViewContainer* scroll_view = source->GetScrollViewContainer(); | 1200 MenuScrollViewContainer* scroll_view = source->GetScrollViewContainer(); |
1201 View* child_under_mouse = | 1201 View* child_under_mouse = |
1202 scroll_view->GetEventHandlerForPoint(gfx::Point(x, y)); | 1202 scroll_view->GetEventHandlerForPoint(gfx::Point(x, y)); |
1203 if (child_under_mouse && child_under_mouse->IsEnabled()) { | 1203 if (child_under_mouse && child_under_mouse->enabled()) { |
1204 if (child_under_mouse == scroll_view->scroll_up_button()) { | 1204 if (child_under_mouse == scroll_view->scroll_up_button()) { |
1205 *part = MenuPart::SCROLL_UP; | 1205 *part = MenuPart::SCROLL_UP; |
1206 return true; | 1206 return true; |
1207 } | 1207 } |
1208 if (child_under_mouse == scroll_view->scroll_down_button()) { | 1208 if (child_under_mouse == scroll_view->scroll_down_button()) { |
1209 *part = MenuPart::SCROLL_DOWN; | 1209 *part = MenuPart::SCROLL_DOWN; |
1210 return true; | 1210 return true; |
1211 } | 1211 } |
1212 } | 1212 } |
1213 return false; | 1213 return false; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 return NULL; | 1652 return NULL; |
1653 MenuItemView* child = parent->GetSubmenu()->GetMenuItemAt(index); | 1653 MenuItemView* child = parent->GetSubmenu()->GetMenuItemAt(index); |
1654 if (child->IsVisible()) | 1654 if (child->IsVisible()) |
1655 return child; | 1655 return child; |
1656 } while (index != start_index); | 1656 } while (index != start_index); |
1657 return NULL; | 1657 return NULL; |
1658 } | 1658 } |
1659 | 1659 |
1660 void MenuController::OpenSubmenuChangeSelectionIfCan() { | 1660 void MenuController::OpenSubmenuChangeSelectionIfCan() { |
1661 MenuItemView* item = pending_state_.item; | 1661 MenuItemView* item = pending_state_.item; |
1662 if (item->HasSubmenu() && item->IsEnabled()) { | 1662 if (item->HasSubmenu() && item->enabled()) { |
1663 if (item->GetSubmenu()->GetMenuItemCount() > 0) { | 1663 if (item->GetSubmenu()->GetMenuItemCount() > 0) { |
1664 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), | 1664 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), |
1665 SELECTION_UPDATE_IMMEDIATELY); | 1665 SELECTION_UPDATE_IMMEDIATELY); |
1666 } else { | 1666 } else { |
1667 // No menu items, just show the sub-menu. | 1667 // No menu items, just show the sub-menu. |
1668 SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); | 1668 SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); |
1669 } | 1669 } |
1670 } | 1670 } |
1671 } | 1671 } |
1672 | 1672 |
(...skipping 12 matching lines...) Expand all Loading... |
1685 MenuItemView* parent, | 1685 MenuItemView* parent, |
1686 char16 key, | 1686 char16 key, |
1687 bool (*match_function)(MenuItemView* menu, char16 mnemonic)) { | 1687 bool (*match_function)(MenuItemView* menu, char16 mnemonic)) { |
1688 SubmenuView* submenu = parent->GetSubmenu(); | 1688 SubmenuView* submenu = parent->GetSubmenu(); |
1689 DCHECK(submenu); | 1689 DCHECK(submenu); |
1690 SelectByCharDetails details; | 1690 SelectByCharDetails details; |
1691 | 1691 |
1692 for (int i = 0, menu_item_count = submenu->GetMenuItemCount(); | 1692 for (int i = 0, menu_item_count = submenu->GetMenuItemCount(); |
1693 i < menu_item_count; ++i) { | 1693 i < menu_item_count; ++i) { |
1694 MenuItemView* child = submenu->GetMenuItemAt(i); | 1694 MenuItemView* child = submenu->GetMenuItemAt(i); |
1695 if (child->IsEnabled() && child->IsVisible()) { | 1695 if (child->enabled() && child->IsVisible()) { |
1696 if (child == pending_state_.item) | 1696 if (child == pending_state_.item) |
1697 details.index_of_item = i; | 1697 details.index_of_item = i; |
1698 if (match_function(child, key)) { | 1698 if (match_function(child, key)) { |
1699 if (details.first_match == -1) | 1699 if (details.first_match == -1) |
1700 details.first_match = i; | 1700 details.first_match = i; |
1701 else | 1701 else |
1702 details.has_multiple = true; | 1702 details.has_multiple = true; |
1703 if (details.next_match == -1 && details.index_of_item != -1 && | 1703 if (details.next_match == -1 && details.index_of_item != -1 && |
1704 i > details.index_of_item) | 1704 i > details.index_of_item) |
1705 details.next_match = i; | 1705 details.next_match = i; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 gfx::Point target_menu_loc(event.location()); | 1873 gfx::Point target_menu_loc(event.location()); |
1874 if (target_menu && target_menu->has_children()) { | 1874 if (target_menu && target_menu->has_children()) { |
1875 // Locate the deepest child view to send events to. This code assumes we | 1875 // Locate the deepest child view to send events to. This code assumes we |
1876 // don't have to walk up the tree to find a view interested in events. This | 1876 // don't have to walk up the tree to find a view interested in events. This |
1877 // is currently true for the cases we are embedding views, but if we embed | 1877 // is currently true for the cases we are embedding views, but if we embed |
1878 // more complex hierarchies it'll need to change. | 1878 // more complex hierarchies it'll need to change. |
1879 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), | 1879 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), |
1880 &target_menu_loc); | 1880 &target_menu_loc); |
1881 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); | 1881 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); |
1882 target = target_menu->GetEventHandlerForPoint(target_menu_loc); | 1882 target = target_menu->GetEventHandlerForPoint(target_menu_loc); |
1883 if (target == target_menu || !target->IsEnabled()) | 1883 if (target == target_menu || !target->enabled()) |
1884 target = NULL; | 1884 target = NULL; |
1885 } | 1885 } |
1886 if (target != active_mouse_view_) { | 1886 if (target != active_mouse_view_) { |
1887 SendMouseCaptureLostToActiveView(); | 1887 SendMouseCaptureLostToActiveView(); |
1888 active_mouse_view_ = target; | 1888 active_mouse_view_ = target; |
1889 if (active_mouse_view_) { | 1889 if (active_mouse_view_) { |
1890 gfx::Point target_point(target_menu_loc); | 1890 gfx::Point target_point(target_menu_loc); |
1891 View::ConvertPointToView(target_menu, active_mouse_view_, &target_point); | 1891 View::ConvertPointToView(target_menu, active_mouse_view_, &target_point); |
1892 MouseEvent mouse_entered_event(ui::ET_MOUSE_ENTERED, | 1892 MouseEvent mouse_entered_event(ui::ET_MOUSE_ENTERED, |
1893 target_point.x(), target_point.y(), 0); | 1893 target_point.x(), target_point.y(), 0); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 // is necessary to exit from nested loop (See Dispatch methods). | 1946 // is necessary to exit from nested loop (See Dispatch methods). |
1947 // Send non-op event so that Dispatch method will always be called. | 1947 // Send non-op event so that Dispatch method will always be called. |
1948 // crbug.com/104684. | 1948 // crbug.com/104684. |
1949 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) | 1949 if (exit_type_ == EXIT_ALL || exit_type_ == EXIT_DESTROYED) |
1950 aura::RootWindow::GetInstance()->PostNativeEvent(ui::CreateNoopEvent()); | 1950 aura::RootWindow::GetInstance()->PostNativeEvent(ui::CreateNoopEvent()); |
1951 #endif | 1951 #endif |
1952 } | 1952 } |
1953 | 1953 |
1954 | 1954 |
1955 } // namespace views | 1955 } // namespace views |
OLD | NEW |