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 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
6 #define UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 #include <set> | 12 #include <set> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/timer.h" | 18 #include "base/timer.h" |
19 #include "ui/base/events.h" | 19 #include "ui/base/events.h" |
20 #include "ui/views/controls/menu/menu_delegate.h" | 20 #include "ui/views/controls/menu/menu_delegate.h" |
21 #include "ui/views/controls/menu/menu_item_view.h" | 21 #include "ui/views/controls/menu/menu_item_view.h" |
22 | 22 |
23 #if defined(USE_AURA) | 23 #if defined(USE_AURA) |
| 24 #include "ui/aura/client/activation_change_observer.h" |
| 25 |
24 namespace aura { | 26 namespace aura { |
25 class RootWindow; | 27 class RootWindow; |
| 28 class Window; |
26 } | 29 } |
27 #endif | 30 #endif |
28 | 31 |
29 namespace ui { | 32 namespace ui { |
30 class OSExchangeData; | 33 class OSExchangeData; |
31 } | 34 } |
32 namespace views { | 35 namespace views { |
33 | 36 |
34 class DropTargetEvent; | 37 class DropTargetEvent; |
35 class MenuButton; | 38 class MenuButton; |
36 class MenuHostRootView; | 39 class MenuHostRootView; |
37 class MouseEvent; | 40 class MouseEvent; |
38 class SubmenuView; | 41 class SubmenuView; |
39 class View; | 42 class View; |
40 | 43 |
41 namespace internal { | 44 namespace internal { |
42 class MenuControllerDelegate; | 45 class MenuControllerDelegate; |
43 class MenuRunnerImpl; | 46 class MenuRunnerImpl; |
44 } | 47 } |
45 | 48 |
46 // MenuController ------------------------------------------------------------- | 49 // MenuController ------------------------------------------------------------- |
47 | 50 |
48 // MenuController is used internally by the various menu classes to manage | 51 // MenuController is used internally by the various menu classes to manage |
49 // showing, selecting and drag/drop for menus. All relevant events are | 52 // showing, selecting and drag/drop for menus. All relevant events are |
50 // forwarded to the MenuController from SubmenuView and MenuHost. | 53 // forwarded to the MenuController from SubmenuView and MenuHost. |
51 class VIEWS_EXPORT MenuController : public MessageLoop::Dispatcher { | 54 class VIEWS_EXPORT MenuController |
| 55 #if defined(USE_AURA) |
| 56 : public MessageLoop::Dispatcher, |
| 57 public aura::client::ActivationChangeObserver { |
| 58 #else |
| 59 : public MessageLoop::Dispatcher { |
| 60 #endif |
| 61 |
52 public: | 62 public: |
53 // Enumeration of how the menu should exit. | 63 // Enumeration of how the menu should exit. |
54 enum ExitType { | 64 enum ExitType { |
55 // Don't exit. | 65 // Don't exit. |
56 EXIT_NONE, | 66 EXIT_NONE, |
57 | 67 |
58 // All menus, including nested, should be exited. | 68 // All menus, including nested, should be exited. |
59 EXIT_ALL, | 69 EXIT_ALL, |
60 | 70 |
61 // Only the outermost menu should be exited. | 71 // Only the outermost menu should be exited. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 bool CanDrop(SubmenuView* source, const ui::OSExchangeData& data); | 129 bool CanDrop(SubmenuView* source, const ui::OSExchangeData& data); |
120 void OnDragEntered(SubmenuView* source, const DropTargetEvent& event); | 130 void OnDragEntered(SubmenuView* source, const DropTargetEvent& event); |
121 int OnDragUpdated(SubmenuView* source, const DropTargetEvent& event); | 131 int OnDragUpdated(SubmenuView* source, const DropTargetEvent& event); |
122 void OnDragExited(SubmenuView* source); | 132 void OnDragExited(SubmenuView* source); |
123 int OnPerformDrop(SubmenuView* source, const DropTargetEvent& event); | 133 int OnPerformDrop(SubmenuView* source, const DropTargetEvent& event); |
124 | 134 |
125 // Invoked from the scroll buttons of the MenuScrollViewContainer. | 135 // Invoked from the scroll buttons of the MenuScrollViewContainer. |
126 void OnDragEnteredScrollButton(SubmenuView* source, bool is_up); | 136 void OnDragEnteredScrollButton(SubmenuView* source, bool is_up); |
127 void OnDragExitedScrollButton(SubmenuView* source); | 137 void OnDragExitedScrollButton(SubmenuView* source); |
128 | 138 |
129 // Invoked once for any Widget activation change. This allows the menu | |
130 // to be canceled if the window manager changes the active window. | |
131 void OnWidgetActivationChanged(); | |
132 | |
133 // Update the submenu's selection based on the current mouse location | 139 // Update the submenu's selection based on the current mouse location |
134 void UpdateSubmenuSelection(SubmenuView* source); | 140 void UpdateSubmenuSelection(SubmenuView* source); |
135 | 141 |
136 private: | 142 private: |
137 friend class internal::MenuRunnerImpl; | 143 friend class internal::MenuRunnerImpl; |
138 friend class MenuHostRootView; | 144 friend class MenuHostRootView; |
139 friend class MenuItemView; | 145 friend class MenuItemView; |
140 friend class SubmenuView; | 146 friend class SubmenuView; |
141 | 147 |
142 class MenuScrollTask; | 148 class MenuScrollTask; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 // sets it to null. | 444 // sets it to null. |
439 void SendMouseCaptureLostToActiveView(); | 445 void SendMouseCaptureLostToActiveView(); |
440 | 446 |
441 // Sets exit type. | 447 // Sets exit type. |
442 void SetExitType(ExitType type); | 448 void SetExitType(ExitType type); |
443 | 449 |
444 // Handles the mouse location event on the submenu |source|. | 450 // Handles the mouse location event on the submenu |source|. |
445 void HandleMouseLocation(SubmenuView* source, | 451 void HandleMouseLocation(SubmenuView* source, |
446 const gfx::Point& mouse_location); | 452 const gfx::Point& mouse_location); |
447 | 453 |
| 454 #if defined(USE_AURA) |
| 455 // aura::client::ActivationChangeObserver overrides: |
| 456 virtual void OnWindowActivated(aura::Window* active, |
| 457 aura::Window* old_active) OVERRIDE; |
| 458 #endif |
| 459 |
448 // The active instance. | 460 // The active instance. |
449 static MenuController* active_instance_; | 461 static MenuController* active_instance_; |
450 | 462 |
451 // If true, Run blocks. If false, Run doesn't block and this is used for | 463 // If true, Run blocks. If false, Run doesn't block and this is used for |
452 // drag and drop. Note that the semantics for drag and drop are slightly | 464 // drag and drop. Note that the semantics for drag and drop are slightly |
453 // different: cancel timer is kicked off any time the drag moves outside the | 465 // different: cancel timer is kicked off any time the drag moves outside the |
454 // menu, mouse events do nothing... | 466 // menu, mouse events do nothing... |
455 bool blocking_run_; | 467 bool blocking_run_; |
456 | 468 |
457 // If true, we're showing. | 469 // If true, we're showing. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 // How deep we are in nested message loops. This should be at most 2 (when | 557 // How deep we are in nested message loops. This should be at most 2 (when |
546 // showing a context menu from a menu). | 558 // showing a context menu from a menu). |
547 int message_loop_depth_; | 559 int message_loop_depth_; |
548 | 560 |
549 DISALLOW_COPY_AND_ASSIGN(MenuController); | 561 DISALLOW_COPY_AND_ASSIGN(MenuController); |
550 }; | 562 }; |
551 | 563 |
552 } // namespace views | 564 } // namespace views |
553 | 565 |
554 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 566 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
OLD | NEW |