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 "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "ui/base/models/menu_model.h" | 10 #include "ui/base/models/menu_model.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 326 } |
327 | 327 |
328 MenuItemView* MenuRunner::GetMenu() { | 328 MenuItemView* MenuRunner::GetMenu() { |
329 return holder_->menu(); | 329 return holder_->menu(); |
330 } | 330 } |
331 | 331 |
332 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, | 332 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
333 MenuButton* button, | 333 MenuButton* button, |
334 const gfx::Rect& bounds, | 334 const gfx::Rect& bounds, |
335 MenuItemView::AnchorPosition anchor, | 335 MenuItemView::AnchorPosition anchor, |
| 336 ui::MenuSourceType source_type, |
336 int32 types) { | 337 int32 types) { |
337 // The parent of the nested menu will have created a DisplayChangeListener, so | 338 // The parent of the nested menu will have created a DisplayChangeListener, so |
338 // we avoid creating a DisplayChangeListener if nested. Drop menus are | 339 // we avoid creating a DisplayChangeListener if nested. Drop menus are |
339 // transient, so we don't cancel in that case. | 340 // transient, so we don't cancel in that case. |
340 if ((types & (IS_NESTED | FOR_DROP)) == 0 && parent) { | 341 if ((types & (IS_NESTED | FOR_DROP)) == 0 && parent) { |
341 display_change_listener_.reset( | 342 display_change_listener_.reset( |
342 internal::DisplayChangeListener::Create(parent, this)); | 343 internal::DisplayChangeListener::Create(parent, this)); |
343 } | 344 } |
344 if ((types & MenuRunner::CONTEXT_MENU) && | 345 |
345 parent && | 346 if (types & CONTEXT_MENU) { |
346 parent->GetCurrentEvent() && | 347 switch (source_type) { |
347 !MenuItemView::IsBubble(anchor)) | 348 case ui::MENU_SOURCE_NONE: |
348 anchor = parent->GetCurrentEvent()->IsGestureEvent() ? | 349 case ui::MENU_SOURCE_KEYBOARD: |
349 MenuItemView::BOTTOMCENTER : MenuItemView::TOPLEFT; | 350 case ui::MENU_SOURCE_MOUSE: |
| 351 anchor = MenuItemView::TOPLEFT; |
| 352 break; |
| 353 case ui::MENU_SOURCE_TOUCH: |
| 354 case ui::MENU_SOURCE_TOUCH_EDIT_MENU: |
| 355 anchor = MenuItemView::BOTTOMCENTER; |
| 356 break; |
| 357 default: |
| 358 break; |
| 359 } |
| 360 } |
350 | 361 |
351 return holder_->RunMenuAt(parent, button, bounds, anchor, types); | 362 return holder_->RunMenuAt(parent, button, bounds, anchor, types); |
352 } | 363 } |
353 | 364 |
354 bool MenuRunner::IsRunning() const { | 365 bool MenuRunner::IsRunning() const { |
355 return holder_->running(); | 366 return holder_->running(); |
356 } | 367 } |
357 | 368 |
358 void MenuRunner::Cancel() { | 369 void MenuRunner::Cancel() { |
359 holder_->Cancel(); | 370 holder_->Cancel(); |
360 } | 371 } |
361 | 372 |
362 base::TimeDelta MenuRunner::closing_event_time() const { | 373 base::TimeDelta MenuRunner::closing_event_time() const { |
363 return holder_->closing_event_time(); | 374 return holder_->closing_event_time(); |
364 } | 375 } |
365 | 376 |
366 } // namespace views | 377 } // namespace views |
OLD | NEW |