Index: ui/views/controls/menu/menu_controller.cc |
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc |
index d5747bd35ed2aebb197151f817d80d76819bf797..35e325edfa30791b2d1f0fb3b31366d26640d1d7 100644 |
--- a/ui/views/controls/menu/menu_controller.cc |
+++ b/ui/views/controls/menu/menu_controller.cc |
@@ -50,6 +50,10 @@ static const int kShowDelay = 400; |
// Amount of time from when the drop exits the menu and the menu is hidden. |
static const int kCloseOnExitTime = 1200; |
+// Border width of the menu shadow (used to align drop down position/bounds) |
+static const int kMenuBorderOffsetY = 2; |
sky
2012/08/07 00:31:57
This should be moved into menu_config and you'll w
Harry McCleave
2012/08/07 01:26:36
Done.
|
+static const int kMenuBorderOffsetX = 1; |
+ |
namespace views { |
namespace { |
@@ -277,11 +281,6 @@ MenuItemView* MenuController::Run(Widget* parent, |
possible_drag_ = false; |
drag_in_progress_ = false; |
- // We need to drop the first mouse release event when the menu has been |
- // layed out over the bounds. |
- drop_first_release_event_ = |
- root->GetRequestedMenuPosition() == MenuItemView::POSITION_OVER_BOUNDS; |
- |
bool nested_menu = showing_; |
if (showing_) { |
// Only support nesting of blocking_run menus, nesting of |
@@ -473,18 +472,6 @@ void MenuController::OnMouseReleased(SubmenuView* source, |
if (!blocking_run_) |
return; |
- // We must ignore the first release event when it occured within the original |
- // bounds. |
- if (drop_first_release_event_ && (event.flags() & ui::EF_LEFT_MOUSE_BUTTON)) { |
- drop_first_release_event_ = false; |
- gfx::Point loc(event.location()); |
- View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); |
- DCHECK(!state_.initial_bounds.IsEmpty()); |
- if (state_.initial_bounds.Contains(loc)) |
- return; |
- } |
- drop_first_release_event_ = false; |
- |
DCHECK(state_.item); |
possible_drag_ = false; |
DCHECK(blocking_run_); |
@@ -792,7 +779,6 @@ void MenuController::SetSelectionOnPointerDown(SubmenuView* source, |
const LocatedEvent& event) { |
if (!blocking_run_) |
return; |
- drop_first_release_event_ = false; |
DCHECK(!active_mouse_view_); |
@@ -1049,7 +1035,6 @@ MenuController::MenuController(bool blocking, |
internal::MenuControllerDelegate* delegate) |
: blocking_run_(blocking), |
showing_(false), |
- drop_first_release_event_(false), |
exit_type_(EXIT_NONE), |
did_capture_(false), |
result_(NULL), |
@@ -1554,9 +1539,10 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, |
gfx::Size pref = submenu->GetScrollViewContainer()->GetPreferredSize(); |
+ pref.set_width(pref.width() - (2 * kMenuBorderOffsetX)); |
sky
2012/08/07 00:31:57
Move this into 1545.
Harry McCleave
2012/08/07 01:26:36
Done.
|
+ |
// Don't let the menu go too wide. |
- if (item->actual_menu_position() != MenuItemView::POSITION_OVER_BOUNDS) |
- pref.set_width(std::min(pref.width(), |
+ pref.set_width(std::min(pref.width(), |
item->GetDelegate()->GetMaxWidthForMenu(item))); |
if (!state_.monitor_bounds.IsEmpty()) |
pref.set_width(std::min(pref.width(), state_.monitor_bounds.width())); |
@@ -1568,23 +1554,13 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, |
if (!item->GetParentMenuItem()) { |
// First item, position relative to initial location. |
- x = state_.initial_bounds.x(); |
- if (item->actual_menu_position() == MenuItemView::POSITION_OVER_BOUNDS) |
- y = state_.initial_bounds.y(); |
- else |
- y = state_.initial_bounds.bottom(); |
+ x = state_.initial_bounds.x() + kMenuBorderOffsetX; |
+ y = state_.initial_bounds.bottom() + kMenuBorderOffsetY; |
if (state_.anchor == MenuItemView::TOPRIGHT) |
x = x + state_.initial_bounds.width() - pref.width(); |
if (!state_.monitor_bounds.IsEmpty() && |
- 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) { |
+ y + pref.height() > state_.monitor_bounds.bottom()) { |
// The menu doesn't fit fully below the button on the screen. The menu |
// position with respect to the bounds will be preserved if it has |
// already been drawn. When the requested positioning is below the bounds |
@@ -1595,10 +1571,10 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, |
// moving it off the initial_bounds region to avoid overlap. |
// In all other requested position styles it will be flipped above and |
// the height will be shrunken to the usable height. |
- if (item->actual_menu_position() == MenuItemView::POSITION_BELOW_BOUNDS) { |
+ if (item->menu_position() == MenuItemView::POSITION_BELOW_BOUNDS) { |
pref.set_height(std::min(pref.height(), |
state_.monitor_bounds.bottom() - y)); |
- } else if (item->actual_menu_position() == |
+ } else if (item->menu_position() == |
MenuItemView::POSITION_BEST_FIT) { |
MenuItemView::MenuPosition orientation = |
MenuItemView::POSITION_BELOW_BOUNDS; |
@@ -1637,29 +1613,20 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, |
x = state_.initial_bounds.x() - pref.width(); // Move left. |
} |
} |
- item->set_actual_menu_position(orientation); |
+ item->set_menu_position(orientation); |
} else { |
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); |
+ item->set_menu_position(MenuItemView::POSITION_ABOVE_BOUNDS); |
} |
- } else if (item->actual_menu_position() == |
+ } else if (item->menu_position() == |
MenuItemView::POSITION_ABOVE_BOUNDS) { |
pref.set_height(std::min(pref.height(), |
state_.initial_bounds.y() - state_.monitor_bounds.y())); |
y = state_.initial_bounds.y() - pref.height(); |
- } 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); |
+ item->set_menu_position(MenuItemView::POSITION_BELOW_BOUNDS); |
} |
} else { |
// Not the first menu; position it relative to the bounds of the menu |