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

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

Issue 11088037: Revert 160886 - Added MenuConfig setter to MenuItemView, updated rest of the code to use set MenuCo… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « ui/views/controls/menu/menu_config_win.cc ('k') | ui/views/controls/menu/menu_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 pref.set_width(std::min(pref.width(), 1549 pref.set_width(std::min(pref.width(),
1550 item->GetDelegate()->GetMaxWidthForMenu(item))); 1550 item->GetDelegate()->GetMaxWidthForMenu(item)));
1551 if (!state_.monitor_bounds.IsEmpty()) 1551 if (!state_.monitor_bounds.IsEmpty())
1552 pref.set_width(std::min(pref.width(), state_.monitor_bounds.width())); 1552 pref.set_width(std::min(pref.width(), state_.monitor_bounds.width()));
1553 1553
1554 // Assume we can honor prefer_leading. 1554 // Assume we can honor prefer_leading.
1555 *is_leading = prefer_leading; 1555 *is_leading = prefer_leading;
1556 1556
1557 int x, y; 1557 int x, y;
1558 1558
1559 const MenuConfig& menu_config = item->GetMenuConfig();
1560
1561 if (!item->GetParentMenuItem()) { 1559 if (!item->GetParentMenuItem()) {
1562 // First item, position relative to initial location. 1560 // First item, position relative to initial location.
1563 x = state_.initial_bounds.x(); 1561 x = state_.initial_bounds.x();
1564 1562
1565 // Offsets for context menu prevent menu items being selected by 1563 // Offsets for context menu prevent menu items being selected by
1566 // simply opening the menu (bug 142992). 1564 // simply opening the menu (bug 142992).
1567 if (menu_config.offset_context_menus && state_.context_menu) 1565 if (MenuConfig::instance().offset_context_menus && state_.context_menu)
1568 x += 1; 1566 x += 1;
1569 1567
1570 y = state_.initial_bounds.bottom(); 1568 y = state_.initial_bounds.bottom();
1571 if (state_.anchor == MenuItemView::TOPRIGHT) { 1569 if (state_.anchor == MenuItemView::TOPRIGHT) {
1572 x = x + state_.initial_bounds.width() - pref.width(); 1570 x = x + state_.initial_bounds.width() - pref.width();
1573 if (menu_config.offset_context_menus && state_.context_menu) 1571 if (MenuConfig::instance().offset_context_menus && state_.context_menu)
1574 x -= 1; 1572 x -= 1;
1575 } else if (state_.anchor == MenuItemView::BOTTOMCENTER) { 1573 } else if (state_.anchor == MenuItemView::BOTTOMCENTER) {
1576 x = x - (pref.width() - state_.initial_bounds.width()) / 2; 1574 x = x - (pref.width() - state_.initial_bounds.width()) / 2;
1577 y = std::max(0, state_.initial_bounds.y() - pref.height()); 1575 y = std::max(0, state_.initial_bounds.y() - pref.height());
1578 } 1576 }
1579 1577
1580 if (!state_.monitor_bounds.IsEmpty() && 1578 if (!state_.monitor_bounds.IsEmpty() &&
1581 y + pref.height() > state_.monitor_bounds.bottom()) { 1579 y + pref.height() > state_.monitor_bounds.bottom()) {
1582 // The menu doesn't fit fully below the button on the screen. The menu 1580 // The menu doesn't fit fully below the button on the screen. The menu
1583 // position with respect to the bounds will be preserved if it has 1581 // position with respect to the bounds will be preserved if it has
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 } 1638 }
1641 } else if (item->actual_menu_position() == 1639 } else if (item->actual_menu_position() ==
1642 MenuItemView::POSITION_ABOVE_BOUNDS) { 1640 MenuItemView::POSITION_ABOVE_BOUNDS) {
1643 pref.set_height(std::min(pref.height(), 1641 pref.set_height(std::min(pref.height(),
1644 state_.initial_bounds.y() - state_.monitor_bounds.y())); 1642 state_.initial_bounds.y() - state_.monitor_bounds.y()));
1645 y = state_.initial_bounds.y() - pref.height(); 1643 y = state_.initial_bounds.y() - pref.height();
1646 } else { 1644 } else {
1647 item->set_actual_menu_position(MenuItemView::POSITION_BELOW_BOUNDS); 1645 item->set_actual_menu_position(MenuItemView::POSITION_BELOW_BOUNDS);
1648 } 1646 }
1649 if (state_.monitor_bounds.width() != 0 && 1647 if (state_.monitor_bounds.width() != 0 &&
1650 menu_config.offset_context_menus && state_.context_menu) { 1648 MenuConfig::instance().offset_context_menus && state_.context_menu) {
1651 if (x + pref.width() > state_.monitor_bounds.right()) 1649 if (x + pref.width() > state_.monitor_bounds.right())
1652 x = state_.initial_bounds.x() - pref.width() - 1; 1650 x = state_.initial_bounds.x() - pref.width() - 1;
1653 if (x < state_.monitor_bounds.x()) 1651 if (x < state_.monitor_bounds.x())
1654 x = state_.monitor_bounds.x(); 1652 x = state_.monitor_bounds.x();
1655 } 1653 }
1656 } else { 1654 } else {
1657 // Not the first menu; position it relative to the bounds of the menu 1655 // Not the first menu; position it relative to the bounds of the menu
1658 // item. 1656 // item.
1659 gfx::Point item_loc; 1657 gfx::Point item_loc;
1660 View::ConvertPointToScreen(item, &item_loc); 1658 View::ConvertPointToScreen(item, &item_loc);
1661 1659
1662 // We must make sure we take into account the UI layout. If the layout is 1660 // We must make sure we take into account the UI layout. If the layout is
1663 // RTL, then a 'leading' menu is positioned to the left of the parent menu 1661 // RTL, then a 'leading' menu is positioned to the left of the parent menu
1664 // item and not to the right. 1662 // item and not to the right.
1665 bool layout_is_rtl = base::i18n::IsRTL(); 1663 bool layout_is_rtl = base::i18n::IsRTL();
1666 bool create_on_the_right = (prefer_leading && !layout_is_rtl) || 1664 bool create_on_the_right = (prefer_leading && !layout_is_rtl) ||
1667 (!prefer_leading && layout_is_rtl); 1665 (!prefer_leading && layout_is_rtl);
1668 int submenu_horizontal_inset = menu_config.submenu_horizontal_inset; 1666 int submenu_horizontal_inset =
1667 MenuConfig::instance().submenu_horizontal_inset;
1669 1668
1670 if (create_on_the_right) { 1669 if (create_on_the_right) {
1671 x = item_loc.x() + item->width() - submenu_horizontal_inset; 1670 x = item_loc.x() + item->width() - submenu_horizontal_inset;
1672 if (state_.monitor_bounds.width() != 0 && 1671 if (state_.monitor_bounds.width() != 0 &&
1673 x + pref.width() > state_.monitor_bounds.right()) { 1672 x + pref.width() > state_.monitor_bounds.right()) {
1674 if (layout_is_rtl) 1673 if (layout_is_rtl)
1675 *is_leading = true; 1674 *is_leading = true;
1676 else 1675 else
1677 *is_leading = false; 1676 *is_leading = false;
1678 x = item_loc.x() - pref.width() + submenu_horizontal_inset; 1677 x = item_loc.x() - pref.width() + submenu_horizontal_inset;
1679 } 1678 }
1680 } else { 1679 } else {
1681 x = item_loc.x() - pref.width() + submenu_horizontal_inset; 1680 x = item_loc.x() - pref.width() + submenu_horizontal_inset;
1682 if (state_.monitor_bounds.width() != 0 && x < state_.monitor_bounds.x()) { 1681 if (state_.monitor_bounds.width() != 0 && x < state_.monitor_bounds.x()) {
1683 if (layout_is_rtl) 1682 if (layout_is_rtl)
1684 *is_leading = false; 1683 *is_leading = false;
1685 else 1684 else
1686 *is_leading = true; 1685 *is_leading = true;
1687 x = item_loc.x() + item->width() - submenu_horizontal_inset; 1686 x = item_loc.x() + item->width() - submenu_horizontal_inset;
1688 } 1687 }
1689 } 1688 }
1690 y = item_loc.y() - menu_config.submenu_vertical_margin_size; 1689 y = item_loc.y() - MenuConfig::instance().submenu_vertical_margin_size;
1691 if (state_.monitor_bounds.width() != 0) { 1690 if (state_.monitor_bounds.width() != 0) {
1692 pref.set_height(std::min(pref.height(), state_.monitor_bounds.height())); 1691 pref.set_height(std::min(pref.height(), state_.monitor_bounds.height()));
1693 if (y + pref.height() > state_.monitor_bounds.bottom()) 1692 if (y + pref.height() > state_.monitor_bounds.bottom())
1694 y = state_.monitor_bounds.bottom() - pref.height(); 1693 y = state_.monitor_bounds.bottom() - pref.height();
1695 if (y < state_.monitor_bounds.y()) 1694 if (y < state_.monitor_bounds.y())
1696 y = state_.monitor_bounds.y(); 1695 y = state_.monitor_bounds.y();
1697 } 1696 }
1698 } 1697 }
1699 1698
1700 if (state_.monitor_bounds.width() != 0) { 1699 if (state_.monitor_bounds.width() != 0) {
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 2128
2130 #if defined(USE_AURA) 2129 #if defined(USE_AURA)
2131 void MenuController::OnWindowActivated(aura::Window* active, 2130 void MenuController::OnWindowActivated(aura::Window* active,
2132 aura::Window* old_active) { 2131 aura::Window* old_active) {
2133 if (!drag_in_progress_) 2132 if (!drag_in_progress_)
2134 Cancel(EXIT_ALL); 2133 Cancel(EXIT_ALL);
2135 } 2134 }
2136 #endif 2135 #endif
2137 2136
2138 } // namespace views 2137 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_config_win.cc ('k') | ui/views/controls/menu/menu_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698