Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: ui/views/controls/menu/menu_controller.cc

Issue 10832360: Change to address default selection of menu item (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // going to get any events. 1177 // going to get any events.
1178 did_capture_ = false; 1178 did_capture_ = false;
1179 gfx::Point screen_menu_loc; 1179 gfx::Point screen_menu_loc;
1180 View::ConvertPointToScreen(button, &screen_menu_loc); 1180 View::ConvertPointToScreen(button, &screen_menu_loc);
1181 // Subtract 1 from the height to make the popup flush with the button border. 1181 // Subtract 1 from the height to make the popup flush with the button border.
1182 UpdateInitialLocation(gfx::Rect(screen_menu_loc.x(), screen_menu_loc.y(), 1182 UpdateInitialLocation(gfx::Rect(screen_menu_loc.x(), screen_menu_loc.y(),
1183 button->width(), button->height() - 1), 1183 button->width(), button->height() - 1),
1184 anchor); 1184 anchor);
1185 alt_menu->PrepareForRun( 1185 alt_menu->PrepareForRun(
1186 has_mnemonics, 1186 has_mnemonics,
1187 source->GetMenuItem()->GetRootMenuItem()->show_mnemonics_); 1187 source->GetMenuItem()->GetRootMenuItem()->show_mnemonics_,
1188 false);
1188 alt_menu->controller_ = this; 1189 alt_menu->controller_ = this;
1189 SetSelection(alt_menu, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); 1190 SetSelection(alt_menu, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
1190 return true; 1191 return true;
1191 } 1192 }
1192 1193
1193 bool MenuController::ShowContextMenu(MenuItemView* menu_item, 1194 bool MenuController::ShowContextMenu(MenuItemView* menu_item,
1194 SubmenuView* source, 1195 SubmenuView* source,
1195 const ui::LocatedEvent& event) { 1196 const ui::LocatedEvent& event) {
1196 // Set the selection immediately, making sure the submenu is only open 1197 // Set the selection immediately, making sure the submenu is only open
1197 // if it already was. 1198 // if it already was.
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 pref.set_width(std::min(pref.width(), state_.monitor_bounds.width())); 1544 pref.set_width(std::min(pref.width(), state_.monitor_bounds.width()));
1544 1545
1545 // Assume we can honor prefer_leading. 1546 // Assume we can honor prefer_leading.
1546 *is_leading = prefer_leading; 1547 *is_leading = prefer_leading;
1547 1548
1548 int x, y; 1549 int x, y;
1549 1550
1550 if (!item->GetParentMenuItem()) { 1551 if (!item->GetParentMenuItem()) {
1551 // First item, position relative to initial location. 1552 // First item, position relative to initial location.
1552 x = state_.initial_bounds.x(); 1553 x = state_.initial_bounds.x();
1554 // Offsets for context menu prevent menu items being selected by
1555 // simply opening the menu (bug 142992)
1556 if(item->is_root_context_menu())
1557 x += 1;
1553 y = state_.initial_bounds.bottom(); 1558 y = state_.initial_bounds.bottom();
1554 if (state_.anchor == MenuItemView::TOPRIGHT) 1559 if (state_.anchor == MenuItemView::TOPRIGHT) {
1555 x = x + state_.initial_bounds.width() - pref.width(); 1560 x = x + state_.initial_bounds.width() - pref.width();
1561 if(item->is_root_context_menu())
1562 x -= 1;
1563 }
1556 1564
1557 if (!state_.monitor_bounds.IsEmpty() && 1565 if (!state_.monitor_bounds.IsEmpty() &&
1558 y + pref.height() > state_.monitor_bounds.bottom()) { 1566 y + pref.height() > state_.monitor_bounds.bottom()) {
1559 // The menu doesn't fit fully below the button on the screen. The menu 1567 // The menu doesn't fit fully below the button on the screen. The menu
1560 // position with respect to the bounds will be preserved if it has 1568 // position with respect to the bounds will be preserved if it has
1561 // already been drawn. When the requested positioning is below the bounds 1569 // already been drawn. When the requested positioning is below the bounds
1562 // it will shrink the menu to make it fit below. 1570 // it will shrink the menu to make it fit below.
1563 // If the requested positioning is best fit, it will first try to fit the 1571 // If the requested positioning is best fit, it will first try to fit the
1564 // menu below. If that does not fit it will try to place it above. If 1572 // menu below. If that does not fit it will try to place it above. If
1565 // that will not fit it will place it at the bottom of the work area and 1573 // that will not fit it will place it at the bottom of the work area and
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 if (state_.monitor_bounds.width() != 0) { 1670 if (state_.monitor_bounds.width() != 0) {
1663 pref.set_height(std::min(pref.height(), state_.monitor_bounds.height())); 1671 pref.set_height(std::min(pref.height(), state_.monitor_bounds.height()));
1664 if (y + pref.height() > state_.monitor_bounds.bottom()) 1672 if (y + pref.height() > state_.monitor_bounds.bottom())
1665 y = state_.monitor_bounds.bottom() - pref.height(); 1673 y = state_.monitor_bounds.bottom() - pref.height();
1666 if (y < state_.monitor_bounds.y()) 1674 if (y < state_.monitor_bounds.y())
1667 y = state_.monitor_bounds.y(); 1675 y = state_.monitor_bounds.y();
1668 } 1676 }
1669 } 1677 }
1670 1678
1671 if (state_.monitor_bounds.width() != 0) { 1679 if (state_.monitor_bounds.width() != 0) {
1672 if (x + pref.width() > state_.monitor_bounds.right()) 1680 if (x + pref.width() > state_.monitor_bounds.right()) {
1673 x = state_.monitor_bounds.right() - pref.width(); 1681 if(item->is_root_context_menu())
1674 if (x < state_.monitor_bounds.x()) 1682 x -= pref.width() + 1;
1675 x = state_.monitor_bounds.x(); 1683 else
1684 x = state_.monitor_bounds.right() - pref.width();
1685 }
1686 if (x < state_.monitor_bounds.x()) {
1687 int temp_loc = state_.initial_bounds.x() + 1;
1688 if(item->is_root_context_menu() && temp_loc >= state_.monitor_bounds.x()
1689 && temp_loc + pref.width() < state_.monitor_bounds.right())
1690 x = temp_loc;
1691 else
1692 x = state_.monitor_bounds.x();
1693 }
1676 } 1694 }
1677 return gfx::Rect(x, y, pref.width(), pref.height()); 1695 return gfx::Rect(x, y, pref.width(), pref.height());
1678 } 1696 }
1679 1697
1680 // static 1698 // static
1681 int MenuController::MenuDepth(MenuItemView* item) { 1699 int MenuController::MenuDepth(MenuItemView* item) {
1682 return item ? (MenuDepth(item->GetParentMenuItem()) + 1) : 0; 1700 return item ? (MenuDepth(item->GetParentMenuItem()) + 1) : 0;
1683 } 1701 }
1684 1702
1685 void MenuController::IncrementSelection(int delta) { 1703 void MenuController::IncrementSelection(int delta) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 2123
2106 #if defined(USE_AURA) 2124 #if defined(USE_AURA)
2107 void MenuController::OnWindowActivated(aura::Window* active, 2125 void MenuController::OnWindowActivated(aura::Window* active,
2108 aura::Window* old_active) { 2126 aura::Window* old_active) {
2109 if (!drag_in_progress_) 2127 if (!drag_in_progress_)
2110 Cancel(EXIT_ALL); 2128 Cancel(EXIT_ALL);
2111 } 2129 }
2112 #endif 2130 #endif
2113 2131
2114 } // namespace views 2132 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698