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
3 // found in the LICENSE file.
5 #include "ui/views/controls/menu/menu_runner.h"
7 #include "ui/views/controls/menu/menu_runner_handler.h"
8 #include "ui/views/controls/menu/menu_runner_impl.h"
12 MenuRunner::MenuRunner(ui::MenuModel
* menu_model
, int32 run_types
)
13 : run_types_(run_types
),
14 impl_(internal::MenuRunnerImplInterface::Create(menu_model
, run_types
)) {
17 MenuRunner::MenuRunner(MenuItemView
* menu_view
, int32 run_types
)
18 : run_types_(run_types
), impl_(new internal::MenuRunnerImpl(menu_view
)) {
21 MenuRunner::~MenuRunner() {
25 MenuRunner::RunResult
MenuRunner::RunMenuAt(Widget
* parent
,
27 const gfx::Rect
& bounds
,
28 MenuAnchorPosition anchor
,
29 ui::MenuSourceType source_type
) {
30 if (runner_handler_
.get()) {
31 return runner_handler_
->RunMenuAt(
32 parent
, button
, bounds
, anchor
, source_type
, run_types_
);
35 // The parent of the nested menu will have created a DisplayChangeListener, so
36 // we avoid creating a DisplayChangeListener if nested. Drop menus are
37 // transient, so we don't cancel in that case.
38 if ((run_types_
& (IS_NESTED
| FOR_DROP
)) == 0 && parent
) {
39 display_change_listener_
.reset(
40 internal::DisplayChangeListener::Create(parent
, this));
43 if (run_types_
& CONTEXT_MENU
) {
44 switch (source_type
) {
45 case ui::MENU_SOURCE_NONE
:
46 case ui::MENU_SOURCE_KEYBOARD
:
47 case ui::MENU_SOURCE_MOUSE
:
48 anchor
= MENU_ANCHOR_TOPLEFT
;
50 case ui::MENU_SOURCE_TOUCH
:
51 case ui::MENU_SOURCE_TOUCH_EDIT_MENU
:
52 anchor
= MENU_ANCHOR_BOTTOMCENTER
;
59 return impl_
->RunMenuAt(parent
, button
, bounds
, anchor
, run_types_
);
62 bool MenuRunner::IsRunning() const {
63 return impl_
->IsRunning();
66 void MenuRunner::Cancel() {
70 base::TimeDelta
MenuRunner::closing_event_time() const {
71 return impl_
->GetClosingEventTime();
74 void MenuRunner::SetRunnerHandler(
75 scoped_ptr
<MenuRunnerHandler
> runner_handler
) {
76 runner_handler_
= runner_handler
.Pass();