Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_runner.h" | 5 #include "ui/views/controls/menu/menu_runner.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "ui/views/controls/button/menu_button.h" | 9 #include "ui/views/controls/button/menu_button.h" |
| 10 #include "ui/views/controls/menu/menu_controller.h" | 10 #include "ui/views/controls/menu/menu_controller.h" |
| 11 #include "ui/views/controls/menu/menu_controller_delegate.h" | 11 #include "ui/views/controls/menu/menu_controller_delegate.h" |
| 12 #include "ui/views/controls/menu/menu_delegate.h" | 12 #include "ui/views/controls/menu/menu_delegate.h" |
| 13 #include "ui/views/widget/widget.h" | |
| 13 | 14 |
| 14 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 15 #include "base/win/win_util.h" | 16 #include "base/win/win_util.h" |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 19 namespace { | |
| 20 // If a context menu is invoked by touch, we shift the menu by this offset so | |
| 21 // that the finger does not obscure the menu. | |
| 22 const int kCenteredContextMenuYOffset = -15; | |
| 23 } // namespace | |
| 24 | |
| 18 namespace views { | 25 namespace views { |
| 19 | 26 |
| 20 namespace internal { | 27 namespace internal { |
| 21 | 28 |
| 22 // Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release() | 29 // Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release() |
| 23 // deletes immediately if the menu isn't showing. If the menu is showing | 30 // deletes immediately if the menu isn't showing. If the menu is showing |
| 24 // Release() cancels the menu and when the nested RunMenuAt() call returns | 31 // Release() cancels the menu and when the nested RunMenuAt() call returns |
| 25 // deletes itself and the menu. | 32 // deletes itself and the menu. |
| 26 class MenuRunnerImpl : public internal::MenuControllerDelegate { | 33 class MenuRunnerImpl : public internal::MenuControllerDelegate { |
| 27 public: | 34 public: |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 const gfx::Rect& bounds, | 284 const gfx::Rect& bounds, |
| 278 MenuItemView::AnchorPosition anchor, | 285 MenuItemView::AnchorPosition anchor, |
| 279 int32 types) { | 286 int32 types) { |
| 280 // The parent of the nested menu will have created a DisplayChangeListener, so | 287 // The parent of the nested menu will have created a DisplayChangeListener, so |
| 281 // we avoid creating a DisplayChangeListener if nested. Drop menus are | 288 // we avoid creating a DisplayChangeListener if nested. Drop menus are |
| 282 // transient, so we don't cancel in that case. | 289 // transient, so we don't cancel in that case. |
| 283 if ((types & (IS_NESTED | FOR_DROP)) == 0) { | 290 if ((types & (IS_NESTED | FOR_DROP)) == 0) { |
| 284 display_change_listener_.reset( | 291 display_change_listener_.reset( |
| 285 internal::DisplayChangeListener::Create(parent, this)); | 292 internal::DisplayChangeListener::Create(parent, this)); |
| 286 } | 293 } |
| 287 return holder_->RunMenuAt(parent, button, bounds, anchor, types); | 294 if ((types & MenuRunner::CONTEXT_MENU) && parent->GetCurrentEvent()) |
| 295 anchor = parent->GetCurrentEvent()->IsGestureEvent() ? | |
| 296 MenuItemView::BOTTOMCENTER : MenuItemView::TOPLEFT; | |
| 297 gfx::Rect menu_bounds = bounds; | |
| 298 if (anchor == MenuItemView::BOTTOMCENTER) | |
|
sky
2012/09/14 17:19:57
Can this be moved to UpdateInitialLocation?
varunjain
2012/09/14 18:46:06
Done.
| |
| 299 menu_bounds.Offset(0, kCenteredContextMenuYOffset); | |
| 300 | |
| 301 return holder_->RunMenuAt(parent, button, menu_bounds, anchor, types); | |
| 288 } | 302 } |
| 289 | 303 |
| 290 bool MenuRunner::IsRunning() const { | 304 bool MenuRunner::IsRunning() const { |
| 291 return holder_->running(); | 305 return holder_->running(); |
| 292 } | 306 } |
| 293 | 307 |
| 294 void MenuRunner::Cancel() { | 308 void MenuRunner::Cancel() { |
| 295 holder_->Cancel(); | 309 holder_->Cancel(); |
| 296 } | 310 } |
| 297 | 311 |
| 298 } // namespace views | 312 } // namespace views |
| OLD | NEW |