1 // Copyright 2016 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.
4 
5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_PRE_TARGET_HANDLER_AURA_H_
6 #define UI_VIEWS_CONTROLS_MENU_MENU_PRE_TARGET_HANDLER_AURA_H_
7 
8 #include "ui/aura/window_observer.h"
9 #include "ui/events/event_handler.h"
10 #include "ui/views/controls/menu/menu_pre_target_handler.h"
11 #include "ui/views/views_export.h"
12 #include "ui/wm/public/activation_change_observer.h"
13 
14 namespace aura {
15 class Window;
16 }  // namespace aura
17 
18 namespace views {
19 
20 class MenuController;
21 class Widget;
22 
23 // MenuPreTargetHandlerAura is used to observe activation changes, cancel
24 // events, and root window destruction, to shutdown the menu.
25 //
26 // Additionally handles key events to provide accelerator support to menus.
27 class VIEWS_EXPORT MenuPreTargetHandlerAura
28     : public wm::ActivationChangeObserver,
29       public aura::WindowObserver,
30       public ui::EventHandler,
31       public MenuPreTargetHandler {
32  public:
33   MenuPreTargetHandlerAura(MenuController* controller, Widget* owner);
34   ~MenuPreTargetHandlerAura() override;
35 
36   // aura::client:ActivationChangeObserver:
37   void OnWindowActivated(wm::ActivationChangeObserver::ActivationReason reason,
38                          aura::Window* gained_active,
39                          aura::Window* lost_active) override;
40 
41   // aura::WindowObserver:
42   void OnWindowDestroying(aura::Window* window) override;
43 
44   // ui::EventHandler:
45   void OnCancelMode(ui::CancelModeEvent* event) override;
46   void OnKeyEvent(ui::KeyEvent* event) override;
47 
48  private:
49   void Cleanup();
50 
51   MenuController* controller_;
52   aura::Window* root_;
53 
54   DISALLOW_COPY_AND_ASSIGN(MenuPreTargetHandlerAura);
55 };
56 
57 }  // namespace views
58 
59 #endif  // UI_VIEWS_CONTROLS_MENU_MENU_PRE_TARGET_HANDLER_AURA_H_
60