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

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

Issue 10829176: Update drop down menu look & feel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up includes 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Period of the scroll timer (in milliseconds). 43 // Period of the scroll timer (in milliseconds).
44 static const int kScrollTimerMS = 30; 44 static const int kScrollTimerMS = 30;
45 45
46 // Delay, in ms, between when menus are selected are moused over and the menu 46 // Delay, in ms, between when menus are selected are moused over and the menu
47 // appears. 47 // appears.
48 static const int kShowDelay = 400; 48 static const int kShowDelay = 400;
49 49
50 // Amount of time from when the drop exits the menu and the menu is hidden. 50 // Amount of time from when the drop exits the menu and the menu is hidden.
51 static const int kCloseOnExitTime = 1200; 51 static const int kCloseOnExitTime = 1200;
52 52
53 // Border width of the menu shadow (used to align drop down position/bounds)
54 static const int kMenuBorderOffsetY = 2;
55 static const int kMenuBorderOffsetX = 1;
56
53 namespace views { 57 namespace views {
54 58
55 namespace { 59 namespace {
56 60
57 // Returns true if the mnemonic of |menu| matches key. 61 // Returns true if the mnemonic of |menu| matches key.
58 bool MatchesMnemonic(MenuItemView* menu, char16 key) { 62 bool MatchesMnemonic(MenuItemView* menu, char16 key) {
59 return menu->GetMnemonic() == key; 63 return menu->GetMnemonic() == key;
60 } 64 }
61 65
62 // Returns true if |menu| doesn't have a mnemonic and first character of the its 66 // Returns true if |menu| doesn't have a mnemonic and first character of the its
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, 1551 gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item,
1548 bool prefer_leading, 1552 bool prefer_leading,
1549 bool* is_leading) { 1553 bool* is_leading) {
1550 DCHECK(item); 1554 DCHECK(item);
1551 1555
1552 SubmenuView* submenu = item->GetSubmenu(); 1556 SubmenuView* submenu = item->GetSubmenu();
1553 DCHECK(submenu); 1557 DCHECK(submenu);
1554 1558
1555 gfx::Size pref = submenu->GetScrollViewContainer()->GetPreferredSize(); 1559 gfx::Size pref = submenu->GetScrollViewContainer()->GetPreferredSize();
1556 1560
1561 pref.set_width(pref.width() - (2 * kMenuBorderOffsetX));
1562
1557 // Don't let the menu go too wide. 1563 // Don't let the menu go too wide.
1558 if (item->actual_menu_position() != MenuItemView::POSITION_OVER_BOUNDS) 1564 if (item->actual_menu_position() != MenuItemView::POSITION_OVER_BOUNDS)
1559 pref.set_width(std::min(pref.width(), 1565 pref.set_width(std::min(pref.width(),
1560 item->GetDelegate()->GetMaxWidthForMenu(item))); 1566 item->GetDelegate()->GetMaxWidthForMenu(item)));
1561 if (!state_.monitor_bounds.IsEmpty()) 1567 if (!state_.monitor_bounds.IsEmpty())
1562 pref.set_width(std::min(pref.width(), state_.monitor_bounds.width())); 1568 pref.set_width(std::min(pref.width(), state_.monitor_bounds.width()));
1563 1569
1564 // Assume we can honor prefer_leading. 1570 // Assume we can honor prefer_leading.
1565 *is_leading = prefer_leading; 1571 *is_leading = prefer_leading;
1566 1572
1567 int x, y; 1573 int x, y;
1568 1574
1569 if (!item->GetParentMenuItem()) { 1575 if (!item->GetParentMenuItem()) {
1570 // First item, position relative to initial location. 1576 // First item, position relative to initial location.
1571 x = state_.initial_bounds.x(); 1577 x = state_.initial_bounds.x() + kMenuBorderOffsetX;
1572 if (item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS) 1578 if (item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS)
1573 y = state_.initial_bounds.y(); 1579 y = state_.initial_bounds.y();
1574 else 1580 else
1575 y = state_.initial_bounds.bottom(); 1581 y = state_.initial_bounds.bottom() + kMenuBorderOffsetY;
1576 if (state_.anchor == MenuItemView::TOPRIGHT) 1582 if (state_.anchor == MenuItemView::TOPRIGHT)
1577 x = x + state_.initial_bounds.width() - pref.width(); 1583 x = x + state_.initial_bounds.width() - pref.width();
1578 1584
1579 if (!state_.monitor_bounds.IsEmpty() && 1585 if (!state_.monitor_bounds.IsEmpty() &&
1580 pref.height() > state_.monitor_bounds.height() && 1586 pref.height() > state_.monitor_bounds.height() &&
1581 item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS) { 1587 item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS) {
1582 // Handle very tall menus. 1588 // Handle very tall menus.
1583 pref.set_height(state_.monitor_bounds.height()); 1589 pref.set_height(state_.monitor_bounds.height());
1584 y = state_.monitor_bounds.y(); 1590 y = state_.monitor_bounds.y();
1585 } else if (!state_.monitor_bounds.IsEmpty() && 1591 } else if (!state_.monitor_bounds.IsEmpty() &&
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 2146
2141 #if defined(USE_AURA) 2147 #if defined(USE_AURA)
2142 void MenuController::OnWindowActivated(aura::Window* active, 2148 void MenuController::OnWindowActivated(aura::Window* active,
2143 aura::Window* old_active) { 2149 aura::Window* old_active) {
2144 if (!drag_in_progress_) 2150 if (!drag_in_progress_)
2145 Cancel(EXIT_ALL); 2151 Cancel(EXIT_ALL);
2146 } 2152 }
2147 #endif 2153 #endif
2148 2154
2149 } // namespace views 2155 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698