Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / controls / menu / menu_runner_impl.h
blob9df132a798ae488ade163b07ac9bc177cd511d18
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"
10 #include <set>
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "ui/views/controls/menu/menu_controller_delegate.h"
16 namespace views {
18 class MenuController;
19 class MenuDelegate;
20 class MenuItemView;
22 namespace internal {
24 // A menu runner implementation that uses views::MenuItemView to show a menu.
25 class MenuRunnerImpl : public MenuRunnerImplInterface,
26 public MenuControllerDelegate {
27 public:
28 explicit MenuRunnerImpl(MenuItemView* menu);
30 virtual bool IsRunning() const OVERRIDE;
31 virtual void Release() OVERRIDE;
32 virtual MenuRunner::RunResult RunMenuAt(Widget* parent,
33 MenuButton* button,
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;
44 private:
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.
56 MenuItemView* menu_;
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?
68 bool running_;
70 // Set if |running_| and Release() has been invoked.
71 bool delete_after_run_;
73 // Are we running for a drop?
74 bool for_drop_;
76 // The controller.
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
92 } // namespace views
94 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_