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 "views/controls/menu/menu_controller.h" | 5 #include "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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 // Set state such that we exit. | 707 // Set state such that we exit. |
708 showing_ = false; | 708 showing_ = false; |
709 exit_type_ = EXIT_ALL; | 709 exit_type_ = EXIT_ALL; |
710 | 710 |
711 if (!IsBlockingRun()) | 711 if (!IsBlockingRun()) |
712 item->GetRootMenuItem()->DropMenuClosed(false); | 712 item->GetRootMenuItem()->DropMenuClosed(false); |
713 | 713 |
714 // WARNING: the call to MenuClosed deletes us. | 714 // WARNING: the call to MenuClosed deletes us. |
715 | 715 |
716 // If over an empty menu item, drop occurs on the parent. | 716 // If over an empty menu item, drop occurs on the parent. |
717 if (drop_target->GetID() == MenuItemView::kEmptyMenuItemViewID) | 717 if (drop_target->id() == MenuItemView::kEmptyMenuItemViewID) |
718 drop_target = drop_target->GetParentMenuItem(); | 718 drop_target = drop_target->GetParentMenuItem(); |
719 | 719 |
720 return drop_target->GetDelegate()->OnPerformDrop( | 720 return drop_target->GetDelegate()->OnPerformDrop( |
721 drop_target, drop_position, event); | 721 drop_target, drop_position, event); |
722 } | 722 } |
723 | 723 |
724 void MenuController::OnDragEnteredScrollButton(SubmenuView* source, | 724 void MenuController::OnDragEnteredScrollButton(SubmenuView* source, |
725 bool is_up) { | 725 bool is_up) { |
726 MenuPart part; | 726 MenuPart part; |
727 part.type = is_up ? MenuPart::SCROLL_UP : MenuPart::SCROLL_DOWN; | 727 part.type = is_up ? MenuPart::SCROLL_UP : MenuPart::SCROLL_DOWN; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 } | 1116 } |
1117 i->submenu_open = false; | 1117 i->submenu_open = false; |
1118 i->item = last_item; | 1118 i->item = last_item; |
1119 } | 1119 } |
1120 } | 1120 } |
1121 | 1121 |
1122 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { | 1122 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { |
1123 // Walk the view hierarchy until we find a menu item (or the root). | 1123 // Walk the view hierarchy until we find a menu item (or the root). |
1124 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); | 1124 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); |
1125 while (child_under_mouse && | 1125 while (child_under_mouse && |
1126 child_under_mouse->GetID() != MenuItemView::kMenuItemViewID) { | 1126 child_under_mouse->id() != MenuItemView::kMenuItemViewID) { |
1127 child_under_mouse = child_under_mouse->parent(); | 1127 child_under_mouse = child_under_mouse->parent(); |
1128 } | 1128 } |
1129 if (child_under_mouse && child_under_mouse->IsEnabled() && | 1129 if (child_under_mouse && child_under_mouse->IsEnabled() && |
1130 child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) { | 1130 child_under_mouse->id() == MenuItemView::kMenuItemViewID) { |
1131 return static_cast<MenuItemView*>(child_under_mouse); | 1131 return static_cast<MenuItemView*>(child_under_mouse); |
1132 } | 1132 } |
1133 return NULL; | 1133 return NULL; |
1134 } | 1134 } |
1135 | 1135 |
1136 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { | 1136 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { |
1137 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); | 1137 View* child_under_mouse = source->GetEventHandlerForPoint(gfx::Point(x, y)); |
1138 if (child_under_mouse && | 1138 if (child_under_mouse && |
1139 child_under_mouse->GetID() == MenuItemView::kEmptyMenuItemViewID) { | 1139 child_under_mouse->id() == MenuItemView::kEmptyMenuItemViewID) { |
1140 return static_cast<MenuItemView*>(child_under_mouse); | 1140 return static_cast<MenuItemView*>(child_under_mouse); |
1141 } | 1141 } |
1142 return NULL; | 1142 return NULL; |
1143 } | 1143 } |
1144 | 1144 |
1145 bool MenuController::IsScrollButtonAt(SubmenuView* source, | 1145 bool MenuController::IsScrollButtonAt(SubmenuView* source, |
1146 int x, | 1146 int x, |
1147 int y, | 1147 int y, |
1148 MenuPart::Type* part) { | 1148 MenuPart::Type* part) { |
1149 MenuScrollViewContainer* scroll_view = source->GetScrollViewContainer(); | 1149 MenuScrollViewContainer* scroll_view = source->GetScrollViewContainer(); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 int delta) { | 1572 int delta) { |
1573 int start_index = index; | 1573 int start_index = index; |
1574 int parent_count = parent->GetSubmenu()->GetMenuItemCount(); | 1574 int parent_count = parent->GetSubmenu()->GetMenuItemCount(); |
1575 // Loop through the menu items skipping any invisible menus. The loop stops | 1575 // Loop through the menu items skipping any invisible menus. The loop stops |
1576 // when we wrap or find a visible child. | 1576 // when we wrap or find a visible child. |
1577 do { | 1577 do { |
1578 index = (index + delta + parent_count) % parent_count; | 1578 index = (index + delta + parent_count) % parent_count; |
1579 if (index == start_index) | 1579 if (index == start_index) |
1580 return NULL; | 1580 return NULL; |
1581 MenuItemView* child = parent->GetSubmenu()->GetMenuItemAt(index); | 1581 MenuItemView* child = parent->GetSubmenu()->GetMenuItemAt(index); |
1582 if (child->IsVisible()) | 1582 if (child->visible()) |
1583 return child; | 1583 return child; |
1584 } while (index != start_index); | 1584 } while (index != start_index); |
1585 return NULL; | 1585 return NULL; |
1586 } | 1586 } |
1587 | 1587 |
1588 void MenuController::OpenSubmenuChangeSelectionIfCan() { | 1588 void MenuController::OpenSubmenuChangeSelectionIfCan() { |
1589 MenuItemView* item = pending_state_.item; | 1589 MenuItemView* item = pending_state_.item; |
1590 if (item->HasSubmenu()) { | 1590 if (item->HasSubmenu()) { |
1591 if (item->GetSubmenu()->GetMenuItemCount() > 0) { | 1591 if (item->GetSubmenu()->GetMenuItemCount() > 0) { |
1592 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), | 1592 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), |
(...skipping 21 matching lines...) Expand all Loading... |
1614 MenuItemView* parent, | 1614 MenuItemView* parent, |
1615 char16 key, | 1615 char16 key, |
1616 bool (*match_function)(MenuItemView* menu, char16 mnemonic)) { | 1616 bool (*match_function)(MenuItemView* menu, char16 mnemonic)) { |
1617 SubmenuView* submenu = parent->GetSubmenu(); | 1617 SubmenuView* submenu = parent->GetSubmenu(); |
1618 DCHECK(submenu); | 1618 DCHECK(submenu); |
1619 SelectByCharDetails details; | 1619 SelectByCharDetails details; |
1620 | 1620 |
1621 for (int i = 0, menu_item_count = submenu->GetMenuItemCount(); | 1621 for (int i = 0, menu_item_count = submenu->GetMenuItemCount(); |
1622 i < menu_item_count; ++i) { | 1622 i < menu_item_count; ++i) { |
1623 MenuItemView* child = submenu->GetMenuItemAt(i); | 1623 MenuItemView* child = submenu->GetMenuItemAt(i); |
1624 if (child->IsEnabled() && child->IsVisible()) { | 1624 if (child->IsEnabled() && child->visible()) { |
1625 if (child == pending_state_.item) | 1625 if (child == pending_state_.item) |
1626 details.index_of_item = i; | 1626 details.index_of_item = i; |
1627 if (match_function(child, key)) { | 1627 if (match_function(child, key)) { |
1628 if (details.first_match == -1) | 1628 if (details.first_match == -1) |
1629 details.first_match = i; | 1629 details.first_match = i; |
1630 else | 1630 else |
1631 details.has_multiple = true; | 1631 details.has_multiple = true; |
1632 if (details.next_match == -1 && details.index_of_item != -1 && | 1632 if (details.next_match == -1 && details.index_of_item != -1 && |
1633 i > details.index_of_item) | 1633 i > details.index_of_item) |
1634 details.next_match = i; | 1634 details.next_match = i; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 return; | 1862 return; |
1863 | 1863 |
1864 // Reset the active_mouse_view_ before sending mouse capture lost. That way if | 1864 // Reset the active_mouse_view_ before sending mouse capture lost. That way if |
1865 // it calls back to us, we aren't in a weird state. | 1865 // it calls back to us, we aren't in a weird state. |
1866 View* active_view = active_mouse_view_; | 1866 View* active_view = active_mouse_view_; |
1867 active_mouse_view_ = NULL; | 1867 active_mouse_view_ = NULL; |
1868 active_view->OnMouseCaptureLost(); | 1868 active_view->OnMouseCaptureLost(); |
1869 } | 1869 } |
1870 | 1870 |
1871 } // namespace views | 1871 } // namespace views |
OLD | NEW |