| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/views/widget/widget_observer.h" | 26 #include "ui/views/widget/widget_observer.h" |
| 27 | 27 |
| 28 namespace ui { | 28 namespace ui { |
| 29 class OSExchangeData; | 29 class OSExchangeData; |
| 30 } | 30 } |
| 31 namespace views { | 31 namespace views { |
| 32 | 32 |
| 33 class MenuButton; | 33 class MenuButton; |
| 34 class MenuHostRootView; | 34 class MenuHostRootView; |
| 35 class MenuItemView; | 35 class MenuItemView; |
| 36 class MenuMessageLoop; | |
| 37 class MouseEvent; | 36 class MouseEvent; |
| 38 class SubmenuView; | 37 class SubmenuView; |
| 39 class View; | 38 class View; |
| 40 | 39 |
| 41 #if defined(USE_AURA) | 40 #if defined(USE_AURA) |
| 42 class MenuPreTargetHandler; | 41 class MenuPreTargetHandler; |
| 43 #endif | 42 #endif |
| 44 | 43 |
| 45 namespace internal { | 44 namespace internal { |
| 46 class MenuControllerDelegate; | 45 class MenuControllerDelegate; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void Cancel(ExitType type); | 115 void Cancel(ExitType type); |
| 117 | 116 |
| 118 // An alternative to Cancel(EXIT_ALL) that can be used with a OneShotTimer. | 117 // An alternative to Cancel(EXIT_ALL) that can be used with a OneShotTimer. |
| 119 void CancelAll() { Cancel(EXIT_ALL); } | 118 void CancelAll() { Cancel(EXIT_ALL); } |
| 120 | 119 |
| 121 // When is_nested_run() this will add a delegate to the stack. The most recent | 120 // When is_nested_run() this will add a delegate to the stack. The most recent |
| 122 // delegate will be notified. It will be removed upon the exiting of the | 121 // delegate will be notified. It will be removed upon the exiting of the |
| 123 // nested menu. Ownership is not taken. | 122 // nested menu. Ownership is not taken. |
| 124 void AddNestedDelegate(internal::MenuControllerDelegate* delegate); | 123 void AddNestedDelegate(internal::MenuControllerDelegate* delegate); |
| 125 | 124 |
| 126 // Sets whether the subsequent call to Run is asynchronous. When nesting calls | |
| 127 // to Run, if a new MenuControllerDelegate has been nested, the previous | |
| 128 // asynchronous state will be reapplied once nesting has ended. | |
| 129 void SetAsyncRun(bool is_async); | |
| 130 | |
| 131 // Returns the current exit type. This returns a value other than EXIT_NONE if | 125 // Returns the current exit type. This returns a value other than EXIT_NONE if |
| 132 // the menu is being canceled. | 126 // the menu is being canceled. |
| 133 ExitType exit_type() const { return exit_type_; } | 127 ExitType exit_type() const { return exit_type_; } |
| 134 | 128 |
| 135 // Returns the time from the event which closed the menu - or 0. | 129 // Returns the time from the event which closed the menu - or 0. |
| 136 base::TimeTicks closing_event_time() const { return closing_event_time_; } | 130 base::TimeTicks closing_event_time() const { return closing_event_time_; } |
| 137 | 131 |
| 138 void set_is_combobox(bool is_combobox) { is_combobox_ = is_combobox; } | 132 void set_is_combobox(bool is_combobox) { is_combobox_ = is_combobox; } |
| 139 | 133 |
| 140 // Various events, forwarded from the submenu. | 134 // Various events, forwarded from the submenu. |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // it to null. | 525 // it to null. |
| 532 void SendMouseCaptureLostToActiveView(); | 526 void SendMouseCaptureLostToActiveView(); |
| 533 | 527 |
| 534 // Sets/gets the active mouse view. See UpdateActiveMouseView() for details. | 528 // Sets/gets the active mouse view. See UpdateActiveMouseView() for details. |
| 535 void SetActiveMouseView(View* view); | 529 void SetActiveMouseView(View* view); |
| 536 View* GetActiveMouseView(); | 530 View* GetActiveMouseView(); |
| 537 | 531 |
| 538 // Sets exit type. Calling this can terminate the active nested message-loop. | 532 // Sets exit type. Calling this can terminate the active nested message-loop. |
| 539 void SetExitType(ExitType type); | 533 void SetExitType(ExitType type); |
| 540 | 534 |
| 541 // Terminates the current nested message-loop, if there is any. Returns |true| | 535 // Performs the teardown of menus. This will notifiy the |delegate_|. If |
| 542 // if any message loop is terminated. | 536 // |exit_type_| is EXIT_ALL all nested runs will be exited. |
| 543 bool TerminateNestedMessageLoopIfNecessary(); | 537 void ExitMenu(); |
| 544 | |
| 545 // Performs the teardown of menus launched with |async_run_|. This will | |
| 546 // notifiy the |delegate_|. If |exit_type_| is EXIT_ALL all nested | |
| 547 // asynchronous runs will be exited. | |
| 548 void ExitAsyncRun(); | |
| 549 | 538 |
| 550 // Performs the teardown of the menu launched by Run(). The selected item is | 539 // Performs the teardown of the menu launched by Run(). The selected item is |
| 551 // returned. | 540 // returned. |
| 552 MenuItemView* ExitMenuRun(); | 541 MenuItemView* ExitTopMostMenu(); |
| 553 | 542 |
| 554 // Handles the mouse location event on the submenu |source|. | 543 // Handles the mouse location event on the submenu |source|. |
| 555 void HandleMouseLocation(SubmenuView* source, | 544 void HandleMouseLocation(SubmenuView* source, |
| 556 const gfx::Point& mouse_location); | 545 const gfx::Point& mouse_location); |
| 557 | 546 |
| 558 // Sets hot-tracked state to the first focusable descendant view of |item|. | 547 // Sets hot-tracked state to the first focusable descendant view of |item|. |
| 559 void SetInitialHotTrackedView(MenuItemView* item, | 548 void SetInitialHotTrackedView(MenuItemView* item, |
| 560 SelectionIncrementDirectionType direction); | 549 SelectionIncrementDirectionType direction); |
| 561 | 550 |
| 562 // Updates the current |hot_button_| and its hot tracked state. | 551 // Updates the current |hot_button_| and its hot tracked state. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 int accept_event_flags_; | 586 int accept_event_flags_; |
| 598 | 587 |
| 599 // If not empty, it means we're nested. When Run is invoked from within | 588 // If not empty, it means we're nested. When Run is invoked from within |
| 600 // Run, the current state (state_) is pushed onto menu_stack_. This allows | 589 // Run, the current state (state_) is pushed onto menu_stack_. This allows |
| 601 // MenuController to restore the state when the nested run returns. | 590 // MenuController to restore the state when the nested run returns. |
| 602 using NestedState = | 591 using NestedState = |
| 603 std::pair<State, std::unique_ptr<MenuButton::PressedLock>>; | 592 std::pair<State, std::unique_ptr<MenuButton::PressedLock>>; |
| 604 std::list<NestedState> menu_stack_; | 593 std::list<NestedState> menu_stack_; |
| 605 | 594 |
| 606 // When Run is invoked during an active Run, it may be called from a separate | 595 // When Run is invoked during an active Run, it may be called from a separate |
| 607 // MenuControllerDelegate. If not empty is means we are nested, and the | 596 // MenuControllerDelegate. If not empty it means we are nested, and the |
| 608 // stacked delegates should be notified instead of |delegate_|. | 597 // stacked delegates should be notified instead of |delegate_|. |
| 609 typedef std::pair<internal::MenuControllerDelegate*, bool> NestedDelegate; | 598 std::list<internal::MenuControllerDelegate*> delegate_stack_; |
| 610 std::list<NestedDelegate> delegate_stack_; | |
| 611 | 599 |
| 612 // As the mouse moves around submenus are not opened immediately. Instead | 600 // As the mouse moves around submenus are not opened immediately. Instead |
| 613 // they open after this timer fires. | 601 // they open after this timer fires. |
| 614 base::OneShotTimer show_timer_; | 602 base::OneShotTimer show_timer_; |
| 615 | 603 |
| 616 // Used to invoke CancelAll(). This is used during drag and drop to hide the | 604 // Used to invoke CancelAll(). This is used during drag and drop to hide the |
| 617 // menu after the mouse moves out of the of the menu. This is necessitated by | 605 // menu after the mouse moves out of the of the menu. This is necessitated by |
| 618 // the lack of an ability to detect when the drag has completed from the drop | 606 // the lack of an ability to detect when the drag has completed from the drop |
| 619 // side. | 607 // side. |
| 620 base::OneShotTimer cancel_all_timer_; | 608 base::OneShotTimer cancel_all_timer_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 | 647 |
| 660 // ViewStorage id used to store the view mouse drag events are forwarded to. | 648 // ViewStorage id used to store the view mouse drag events are forwarded to. |
| 661 // See UpdateActiveMouseView() for details. | 649 // See UpdateActiveMouseView() for details. |
| 662 const int active_mouse_view_id_; | 650 const int active_mouse_view_id_; |
| 663 | 651 |
| 664 // Current hot tracked child button if any. | 652 // Current hot tracked child button if any. |
| 665 CustomButton* hot_button_; | 653 CustomButton* hot_button_; |
| 666 | 654 |
| 667 internal::MenuControllerDelegate* delegate_; | 655 internal::MenuControllerDelegate* delegate_; |
| 668 | 656 |
| 669 // How deep we are in nested message loops. This should be at most 2 (when | |
| 670 // showing a context menu from a menu). | |
| 671 int message_loop_depth_; | |
| 672 | |
| 673 // The timestamp of the event which closed the menu - or 0 otherwise. | 657 // The timestamp of the event which closed the menu - or 0 otherwise. |
| 674 base::TimeTicks closing_event_time_; | 658 base::TimeTicks closing_event_time_; |
| 675 | 659 |
| 676 // Time when the menu is first shown. | 660 // Time when the menu is first shown. |
| 677 base::TimeTicks menu_start_time_; | 661 base::TimeTicks menu_start_time_; |
| 678 | 662 |
| 679 // If a mouse press triggered this menu, this will have its location (in | 663 // If a mouse press triggered this menu, this will have its location (in |
| 680 // screen coordinates). Otherwise this will be (0, 0). | 664 // screen coordinates). Otherwise this will be (0, 0). |
| 681 gfx::Point menu_start_mouse_press_loc_; | 665 gfx::Point menu_start_mouse_press_loc_; |
| 682 | 666 |
| 683 // Controls behaviour differences between an asynchronous run, and other types | |
| 684 // of run (blocking, drag and drop). | |
| 685 bool async_run_; | |
| 686 | |
| 687 // Controls behavior differences between a combobox and other types of menu | 667 // Controls behavior differences between a combobox and other types of menu |
| 688 // (like a context menu). | 668 // (like a context menu). |
| 689 bool is_combobox_; | 669 bool is_combobox_; |
| 690 | 670 |
| 691 // Set to true if the menu item was selected by touch. | 671 // Set to true if the menu item was selected by touch. |
| 692 bool item_selected_by_touch_; | 672 bool item_selected_by_touch_; |
| 693 | 673 |
| 694 // During mouse event handling, this is the RootView to forward mouse events | 674 // During mouse event handling, this is the RootView to forward mouse events |
| 695 // to. We need this, because if we forward one event to it (e.g., mouse | 675 // to. We need this, because if we forward one event to it (e.g., mouse |
| 696 // pressed), subsequent events (like dragging) should also go to it, even if | 676 // pressed), subsequent events (like dragging) should also go to it, even if |
| 697 // the mouse is no longer over the view. | 677 // the mouse is no longer over the view. |
| 698 MenuHostRootView* current_mouse_event_target_; | 678 MenuHostRootView* current_mouse_event_target_; |
| 699 | 679 |
| 700 // A mask of the EventFlags for the mouse buttons currently pressed. | 680 // A mask of the EventFlags for the mouse buttons currently pressed. |
| 701 int current_mouse_pressed_state_; | 681 int current_mouse_pressed_state_; |
| 702 | 682 |
| 703 std::unique_ptr<MenuMessageLoop> message_loop_; | |
| 704 | |
| 705 #if defined(USE_AURA) | 683 #if defined(USE_AURA) |
| 706 std::unique_ptr<MenuPreTargetHandler> menu_pre_target_handler_; | 684 std::unique_ptr<MenuPreTargetHandler> menu_pre_target_handler_; |
| 707 #endif | 685 #endif |
| 708 | 686 |
| 709 DISALLOW_COPY_AND_ASSIGN(MenuController); | 687 DISALLOW_COPY_AND_ASSIGN(MenuController); |
| 710 }; | 688 }; |
| 711 | 689 |
| 712 } // namespace views | 690 } // namespace views |
| 713 | 691 |
| 714 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 692 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
| OLD | NEW |