summaryrefslogtreecommitdiffstats
path: root/ui/views/controls
diff options
context:
space:
mode:
authorsaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 23:22:58 +0000
committersaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 23:22:58 +0000
commit8483fa27a468c05940adc3175c36ca359a974e6e (patch)
tree84a380b832ffa6e2d1ae41a140d49f79d3d330a1 /ui/views/controls
parent4909ecaf28e4b3bbc6171814548cf51e249ad45a (diff)
downloadchromium_src-8483fa27a468c05940adc3175c36ca359a974e6e.zip
chromium_src-8483fa27a468c05940adc3175c36ca359a974e6e.tar.gz
chromium_src-8483fa27a468c05940adc3175c36ca359a974e6e.tar.bz2
Create a new menu type centered vertically over the bounds.
This will be used by the comboxbox. BUG=100663 TEST=none Review URL: http://codereview.chromium.org/9110048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/controls')
-rw-r--r--ui/views/controls/combobox/native_combobox_views.cc8
-rw-r--r--ui/views/controls/menu/menu_controller.cc31
-rw-r--r--ui/views/controls/menu/menu_item_view.h5
3 files changed, 34 insertions, 10 deletions
diff --git a/ui/views/controls/combobox/native_combobox_views.cc b/ui/views/controls/combobox/native_combobox_views.cc
index 008cc29..5cfd1b4 100644
--- a/ui/views/controls/combobox/native_combobox_views.cc
+++ b/ui/views/controls/combobox/native_combobox_views.cc
@@ -314,9 +314,15 @@ void NativeComboboxViews::ShowDropDownMenu() {
UpdateFromModel();
// Extend the menu to the width of the combobox.
- SubmenuView* submenu = dropdown_list_menu_runner_->GetMenu()->CreateSubmenu();
+ MenuItemView* menu = dropdown_list_menu_runner_->GetMenu();
+ SubmenuView* submenu = menu->CreateSubmenu();
submenu->set_minimum_preferred_width(size().width());
+#if defined(USE_AURA)
+ // Aura style is to have the menu over the bounds. Below bounds is default.
+ menu->set_menu_position(views::MenuItemView::POSITION_OVER_BOUNDS);
+#endif
+
gfx::Rect lb = GetLocalBounds();
gfx::Point menu_position(lb.origin());
View::ConvertPointToScreen(this, &menu_position);
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index bb40b61..43a37b6 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -1484,7 +1484,7 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item,
gfx::Size pref = submenu->GetScrollViewContainer()->GetPreferredSize();
- // Don't let the menu go to wide.
+ // Don't let the menu go too wide.
pref.set_width(std::min(pref.width(),
item->GetDelegate()->GetMaxWidthForMenu(item)));
if (!state_.monitor_bounds.IsEmpty())
@@ -1498,11 +1498,22 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item,
if (!item->GetParentMenuItem()) {
// First item, position relative to initial location.
x = state_.initial_bounds.x();
- y = state_.initial_bounds.bottom();
+ if (item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS)
+ y = state_.initial_bounds.y();
+ else
+ y = state_.initial_bounds.bottom();
if (state_.anchor == MenuItemView::TOPRIGHT)
x = x + state_.initial_bounds.width() - pref.width();
+
if (!state_.monitor_bounds.IsEmpty() &&
- y + pref.height() > state_.monitor_bounds.bottom()) {
+ pref.height() > state_.monitor_bounds.height() &&
+ item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS) {
+ // Handle very tall menus.
+ pref.set_height(state_.monitor_bounds.height());
+ y = state_.monitor_bounds.y();
+ } else if (!state_.monitor_bounds.IsEmpty() &&
+ y + pref.height() > state_.monitor_bounds.bottom() &&
+ item->actual_menu_position() != MenuItemView::POSITION_OVER_BOUNDS) {
// The menu doesn't fit on screen. The menu position with
// respect to the bounds will be preserved if it has already
// been drawn. On the first drawing if the first location is
@@ -1525,12 +1536,18 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item,
}
} else if (item->actual_menu_position() ==
MenuItemView::POSITION_ABOVE_BOUNDS) {
- // The menu would fit below the bounds, but it has already been
- // drawn above so keep it there.
pref.set_height(std::min(pref.height(),
state_.initial_bounds.y() - state_.monitor_bounds.y()));
y = state_.initial_bounds.y() - pref.height();
- item->set_actual_menu_position(MenuItemView::POSITION_ABOVE_BOUNDS);
+ } else if (item->actual_menu_position() ==
+ MenuItemView::POSITION_OVER_BOUNDS) {
+ // Center vertically assuming all items have the same height.
+ int middle = state_.initial_bounds.y() - pref.height() / 2;
+ if (submenu->GetMenuItemCount() > 0)
+ middle += submenu->GetMenuItemAt(0)->GetPreferredSize().height() / 2;
+ y = std::max(state_.monitor_bounds.y(), middle);
+ if (y + pref.height() > state_.monitor_bounds.bottom())
+ y = state_.monitor_bounds.bottom() - pref.height();
} else {
item->set_actual_menu_position(MenuItemView::POSITION_BELOW_BOUNDS);
}
diff --git a/ui/views/controls/menu/menu_item_view.h b/ui/views/controls/menu/menu_item_view.h
index 91da31b..99cfc53 100644
--- a/ui/views/controls/menu/menu_item_view.h
+++ b/ui/views/controls/menu/menu_item_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -101,7 +101,8 @@ class VIEWS_EXPORT MenuItemView : public View {
enum MenuPosition {
POSITION_BEST_FIT,
POSITION_ABOVE_BOUNDS,
- POSITION_BELOW_BOUNDS
+ POSITION_BELOW_BOUNDS,
+ POSITION_OVER_BOUNDS
};
// Constructor for use with the top level menu item. This menu is never