1 // Copyright 2014 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 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_
6 #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_
8 #include "ui/views/controls/menu/menu_runner_impl_interface.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "ui/views/controls/menu/menu_controller_delegate.h"
24 // A menu runner implementation that uses views::MenuItemView to show a menu.
25 class MenuRunnerImpl
: public MenuRunnerImplInterface
,
26 public MenuControllerDelegate
{
28 explicit MenuRunnerImpl(MenuItemView
* menu
);
30 virtual bool IsRunning() const OVERRIDE
;
31 virtual void Release() OVERRIDE
;
32 virtual MenuRunner::RunResult
RunMenuAt(Widget
* parent
,
34 const gfx::Rect
& bounds
,
35 MenuAnchorPosition anchor
,
36 int32 run_types
) OVERRIDE
;
37 virtual void Cancel() OVERRIDE
;
38 virtual base::TimeDelta
GetClosingEventTime() const OVERRIDE
;
40 // MenuControllerDelegate:
41 virtual void DropMenuClosed(NotifyType type
, MenuItemView
* menu
) OVERRIDE
;
42 virtual void SiblingMenuCreated(MenuItemView
* menu
) OVERRIDE
;
45 virtual ~MenuRunnerImpl();
47 // Cleans up after the menu is no longer showing. |result| is the menu that
48 // the user selected, or NULL if nothing was selected.
49 MenuRunner::RunResult
MenuDone(MenuItemView
* result
, int mouse_event_flags
);
51 // Returns true if mnemonics should be shown in the menu.
52 bool ShouldShowMnemonics(MenuButton
* button
);
54 // The menu. We own this. We don't use scoped_ptr as the destructor is
55 // protected and we're a friend.
58 // Any sibling menus. Does not include |menu_|. We own these too.
59 std::set
<MenuItemView
*> sibling_menus_
;
61 // Created and set as the delegate of the MenuItemView if Release() is
62 // invoked. This is done to make sure the delegate isn't notified after
63 // Release() is invoked. We do this as we assume the delegate is no longer
64 // valid if MenuRunner has been deleted.
65 scoped_ptr
<MenuDelegate
> empty_delegate_
;
67 // Are we in run waiting for it to return?
70 // Set if |running_| and Release() has been invoked.
71 bool delete_after_run_
;
73 // Are we running for a drop?
77 MenuController
* controller_
;
79 // Do we own the controller?
80 bool owns_controller_
;
82 // The timestamp of the event which closed the menu - or 0.
83 base::TimeDelta closing_event_time_
;
85 // Used to detect deletion of |this| when notifying delegate of success.
86 base::WeakPtrFactory
<MenuRunnerImpl
> weak_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(MenuRunnerImpl
);
91 } // namespace internal
94 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_