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 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class SubmenuView; | 44 class SubmenuView; |
45 class View; | 45 class View; |
46 | 46 |
47 namespace internal { | 47 namespace internal { |
48 class MenuControllerDelegate; | 48 class MenuControllerDelegate; |
49 class MenuEventDispatcher; | 49 class MenuEventDispatcher; |
50 class MenuMessagePumpDispatcher; | 50 class MenuMessagePumpDispatcher; |
51 class MenuRunnerImpl; | 51 class MenuRunnerImpl; |
52 } | 52 } |
53 | 53 |
| 54 namespace test { |
| 55 class MenuControllerTest; |
| 56 } |
| 57 |
54 // MenuController ------------------------------------------------------------- | 58 // MenuController ------------------------------------------------------------- |
55 | 59 |
56 // MenuController is used internally by the various menu classes to manage | 60 // MenuController is used internally by the various menu classes to manage |
57 // showing, selecting and drag/drop for menus. All relevant events are | 61 // showing, selecting and drag/drop for menus. All relevant events are |
58 // forwarded to the MenuController from SubmenuView and MenuHost. | 62 // forwarded to the MenuController from SubmenuView and MenuHost. |
59 class VIEWS_EXPORT MenuController : public WidgetObserver { | 63 class VIEWS_EXPORT MenuController : public WidgetObserver { |
60 public: | 64 public: |
61 // Enumeration of how the menu should exit. | 65 // Enumeration of how the menu should exit. |
62 enum ExitType { | 66 enum ExitType { |
63 // Don't exit. | 67 // Don't exit. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // Only used for testing. | 180 // Only used for testing. |
177 bool IsCancelAllTimerRunningForTest(); | 181 bool IsCancelAllTimerRunningForTest(); |
178 | 182 |
179 // Only used for testing. | 183 // Only used for testing. |
180 static void TurnOffMenuSelectionHoldForTest(); | 184 static void TurnOffMenuSelectionHoldForTest(); |
181 | 185 |
182 private: | 186 private: |
183 friend class internal::MenuEventDispatcher; | 187 friend class internal::MenuEventDispatcher; |
184 friend class internal::MenuMessagePumpDispatcher; | 188 friend class internal::MenuMessagePumpDispatcher; |
185 friend class internal::MenuRunnerImpl; | 189 friend class internal::MenuRunnerImpl; |
186 friend class MenuControllerTest; | 190 friend class test::MenuControllerTest; |
187 friend class MenuHostRootView; | 191 friend class MenuHostRootView; |
188 friend class MenuItemView; | 192 friend class MenuItemView; |
189 friend class SubmenuView; | 193 friend class SubmenuView; |
190 | 194 |
191 class MenuScrollTask; | 195 class MenuScrollTask; |
192 | 196 |
193 struct SelectByCharDetails; | 197 struct SelectByCharDetails; |
194 | 198 |
195 // Values supplied to SetSelection. | 199 // Values supplied to SetSelection. |
196 enum SetSelectionTypes { | 200 enum SetSelectionTypes { |
(...skipping 16 matching lines...) Expand all Loading... |
213 // Accelerator is not sent because of no hot tracked views. | 217 // Accelerator is not sent because of no hot tracked views. |
214 ACCELERATOR_NOT_PROCESSED, | 218 ACCELERATOR_NOT_PROCESSED, |
215 | 219 |
216 // Accelerator is sent to the hot tracked views. | 220 // Accelerator is sent to the hot tracked views. |
217 ACCELERATOR_PROCESSED, | 221 ACCELERATOR_PROCESSED, |
218 | 222 |
219 // Same as above and the accelerator causes the exit of the menu. | 223 // Same as above and the accelerator causes the exit of the menu. |
220 ACCELERATOR_PROCESSED_EXIT | 224 ACCELERATOR_PROCESSED_EXIT |
221 }; | 225 }; |
222 | 226 |
| 227 // Direction for IncrementSelection and FindInitialSelectableMenuItem. |
| 228 enum SelectionIncrementDirectionType { |
| 229 // Navigate the menu up. |
| 230 INCREMENT_SELECTION_UP, |
| 231 |
| 232 // Navigate the menu down. |
| 233 INCREMENT_SELECTION_DOWN, |
| 234 }; |
| 235 |
223 // Tracks selection information. | 236 // Tracks selection information. |
224 struct State { | 237 struct State { |
225 State(); | 238 State(); |
226 ~State(); | 239 ~State(); |
227 | 240 |
228 // The selected menu item. | 241 // The selected menu item. |
229 MenuItemView* item; | 242 MenuItemView* item; |
230 | 243 |
231 // If item has a submenu this indicates if the submenu is showing. | 244 // If item has a submenu this indicates if the submenu is showing. |
232 bool submenu_open; | 245 bool submenu_open; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 438 |
426 // Calculates the bubble bounds of the menu to show. is_leading is set to | 439 // Calculates the bubble bounds of the menu to show. is_leading is set to |
427 // match the direction the menu opened in. | 440 // match the direction the menu opened in. |
428 gfx::Rect CalculateBubbleMenuBounds(MenuItemView* item, | 441 gfx::Rect CalculateBubbleMenuBounds(MenuItemView* item, |
429 bool prefer_leading, | 442 bool prefer_leading, |
430 bool* is_leading); | 443 bool* is_leading); |
431 | 444 |
432 // Returns the depth of the menu. | 445 // Returns the depth of the menu. |
433 static int MenuDepth(MenuItemView* item); | 446 static int MenuDepth(MenuItemView* item); |
434 | 447 |
435 // Selects the next/previous menu item. | 448 // Selects the next or previous (depending on |direction|) menu item. |
436 void IncrementSelection(int delta); | 449 void IncrementSelection(SelectionIncrementDirectionType direction); |
437 | 450 |
438 // Returns the first selectable child menu item of |parent|. If there are no | 451 // Returns the first (|direction| == NAVIGATE_SELECTION_DOWN) or the last |
439 // selectable menu items NULL is returned. | 452 // (|direction| == INCREMENT_SELECTION_UP) selectable child menu item of |
440 MenuItemView* FindFirstSelectableMenuItem(MenuItemView* parent); | 453 // |parent|. If there are no selectable items returns NULL. |
| 454 MenuItemView* FindInitialSelectableMenuItem( |
| 455 MenuItemView* parent, |
| 456 SelectionIncrementDirectionType direction); |
441 | 457 |
442 // Returns the next selectable child menu item of |parent| starting at |index| | 458 // Returns the next or previous selectable child menu item of |parent| |
443 // and incrementing index by |delta|. If there are no more selectable menu | 459 // starting at |index| and incrementing or decrementing index by 1 depending |
444 // items NULL is returned. | 460 // on |direction|. If there are no more selectable items NULL is returned. |
445 MenuItemView* FindNextSelectableMenuItem(MenuItemView* parent, | 461 MenuItemView* FindNextSelectableMenuItem( |
446 int index, | 462 MenuItemView* parent, |
447 int delta); | 463 int index, |
| 464 SelectionIncrementDirectionType direction); |
448 | 465 |
449 // If the selected item has a submenu and it isn't currently open, the | 466 // If the selected item has a submenu and it isn't currently open, the |
450 // the selection is changed such that the menu opens immediately. | 467 // the selection is changed such that the menu opens immediately. |
451 void OpenSubmenuChangeSelectionIfCan(); | 468 void OpenSubmenuChangeSelectionIfCan(); |
452 | 469 |
453 // If possible, closes the submenu. | 470 // If possible, closes the submenu. |
454 void CloseSubmenu(); | 471 void CloseSubmenu(); |
455 | 472 |
456 // Returns details about which menu items match the mnemonic |key|. | 473 // Returns details about which menu items match the mnemonic |key|. |
457 // |match_function| is used to determine which menus match. | 474 // |match_function| is used to determine which menus match. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 bool item_selected_by_touch_; | 657 bool item_selected_by_touch_; |
641 | 658 |
642 scoped_ptr<MenuMessageLoop> message_loop_; | 659 scoped_ptr<MenuMessageLoop> message_loop_; |
643 | 660 |
644 DISALLOW_COPY_AND_ASSIGN(MenuController); | 661 DISALLOW_COPY_AND_ASSIGN(MenuController); |
645 }; | 662 }; |
646 | 663 |
647 } // namespace views | 664 } // namespace views |
648 | 665 |
649 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 666 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
OLD | NEW |