Chromium Code Reviews| 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 5364b83da55b3c6fe23fe56fc1c580795fee83be..73328d01090a9df9d39d0643e94678cbe61cf34d 100644 |
| --- a/ui/views/controls/menu/menu_controller.cc |
| +++ b/ui/views/controls/menu/menu_controller.cc |
| @@ -253,7 +253,8 @@ struct MenuController::SelectByCharDetails { |
| MenuController::State::State() |
| : item(NULL), |
| submenu_open(false), |
| - anchor(views::MenuItemView::TOPLEFT) {} |
| + anchor(views::MenuItemView::TOPLEFT), |
| + context_menu(false) {} |
| MenuController::State::~State() {} |
| @@ -272,6 +273,7 @@ MenuItemView* MenuController::Run(Widget* parent, |
| MenuItemView* root, |
| const gfx::Rect& bounds, |
| MenuItemView::AnchorPosition position, |
| + bool context_menu, |
| int* result_mouse_event_flags) { |
| exit_type_ = EXIT_NONE; |
| possible_drag_ = false; |
| @@ -295,7 +297,7 @@ MenuItemView* MenuController::Run(Widget* parent, |
| // Reset current state. |
| pending_state_ = State(); |
| state_ = State(); |
| - UpdateInitialLocation(bounds, position); |
| + UpdateInitialLocation(bounds, position, context_menu); |
| owner_ = parent; |
| @@ -1080,7 +1082,9 @@ MenuController::SendAcceleratorResultType |
| void MenuController::UpdateInitialLocation( |
| const gfx::Rect& bounds, |
| - MenuItemView::AnchorPosition position) { |
| + MenuItemView::AnchorPosition position, |
| + bool context_menu) { |
| + pending_state_.context_menu = context_menu; |
| pending_state_.initial_bounds = bounds; |
| if (bounds.height() > 1) { |
| // Inset the bounds slightly, otherwise drag coordinates don't line up |
| @@ -1181,10 +1185,9 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source, |
| // Subtract 1 from the height to make the popup flush with the button border. |
| UpdateInitialLocation(gfx::Rect(screen_menu_loc.x(), screen_menu_loc.y(), |
| button->width(), button->height() - 1), |
| - anchor); |
| + anchor, state_.context_menu); |
| alt_menu->PrepareForRun( |
| - has_mnemonics, |
| - source->GetMenuItem()->GetRootMenuItem()->show_mnemonics_); |
| + has_mnemonics, source->GetMenuItem()->GetRootMenuItem()->show_mnemonics_); |
| alt_menu->controller_ = this; |
| SetSelection(alt_menu, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); |
| return true; |
| @@ -1550,9 +1553,16 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, |
| if (!item->GetParentMenuItem()) { |
| // First item, position relative to initial location. |
| x = state_.initial_bounds.x(); |
| + // Offsets for context menu prevent menu items being selected by |
| + // simply opening the menu (bug 142992) |
|
sky
2012/08/21 15:40:43
End with a '.'.
Harry McCleave
2012/08/21 18:38:35
Done.
Harry McCleave
2012/08/21 18:38:35
Done.
|
| + if(state_.context_menu) |
|
sky
2012/08/21 15:40:43
Do we really want to do this every where, or only
Harry McCleave
2012/08/21 18:38:35
Done.
|
| + x += 1; |
| y = state_.initial_bounds.bottom(); |
| - if (state_.anchor == MenuItemView::TOPRIGHT) |
| + if (state_.anchor == MenuItemView::TOPRIGHT) { |
| x = x + state_.initial_bounds.width() - pref.width(); |
| + if(state_.context_menu) |
|
sky
2012/08/21 15:40:43
nit: spacing.
Harry McCleave
2012/08/21 18:38:35
Done.
|
| + x -= 1; |
| + } |
| if (!state_.monitor_bounds.IsEmpty() && |
| y + pref.height() > state_.monitor_bounds.bottom()) { |
| @@ -1669,10 +1679,21 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, |
| } |
| if (state_.monitor_bounds.width() != 0) { |
|
sky
2012/08/21 15:40:43
I think this wholoe block should be moved inside t
Harry McCleave
2012/08/21 18:38:35
Done.
|
| - if (x + pref.width() > state_.monitor_bounds.right()) |
| - x = state_.monitor_bounds.right() - pref.width(); |
| - if (x < state_.monitor_bounds.x()) |
| - x = state_.monitor_bounds.x(); |
| + if (x + pref.width() > state_.monitor_bounds.right()) { |
| + if(state_.context_menu && !item->GetParentMenuItem()) |
|
sky
2012/08/21 15:40:43
nit: spacing
Harry McCleave
2012/08/21 18:38:35
Done.
|
| + x -= pref.width() + 1; |
| + else |
| + x = state_.monitor_bounds.right() - pref.width(); |
| + } |
| + if (x < state_.monitor_bounds.x()) { |
| + int temp_loc = state_.initial_bounds.x() + 1; |
| + if(state_.context_menu && !item->GetParentMenuItem() && |
| + temp_loc >= state_.monitor_bounds.x() && |
| + temp_loc + pref.width() < state_.monitor_bounds.right()) |
| + x = temp_loc; |
| + else |
| + x = state_.monitor_bounds.x(); |
| + } |
| } |
| return gfx::Rect(x, y, pref.width(), pref.height()); |
| } |