| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 bool in_nested_run() const { return !menu_stack_.empty(); } | 96 bool in_nested_run() const { return !menu_stack_.empty(); } |
| 97 | 97 |
| 98 // Whether or not drag operation is in progress. | 98 // Whether or not drag operation is in progress. |
| 99 bool drag_in_progress() const { return drag_in_progress_; } | 99 bool drag_in_progress() const { return drag_in_progress_; } |
| 100 | 100 |
| 101 // Whether the MenuController initiated the drag in progress. False if there | 101 // Whether the MenuController initiated the drag in progress. False if there |
| 102 // is no drag in progress. | 102 // is no drag in progress. |
| 103 bool did_initiate_drag() const { return did_initiate_drag_; } | 103 bool did_initiate_drag() const { return did_initiate_drag_; } |
| 104 | 104 |
| 105 bool owner_needs_gesture_events() const { |
| 106 return owner_needs_gesture_events_; |
| 107 } |
| 108 |
| 109 void set_owner_needs_gesture_events(bool owner_needs_gesture_events) { |
| 110 owner_needs_gesture_events_ = owner_needs_gesture_events; |
| 111 } |
| 112 |
| 105 // Returns the owner of child windows. | 113 // Returns the owner of child windows. |
| 106 // WARNING: this may be NULL. | 114 // WARNING: this may be NULL. |
| 107 Widget* owner() { return owner_; } | 115 Widget* owner() { return owner_; } |
| 108 | 116 |
| 109 // Get the anchor position wich is used to show this menu. | 117 // Get the anchor position wich is used to show this menu. |
| 110 MenuAnchorPosition GetAnchorPosition() { return state_.anchor; } | 118 MenuAnchorPosition GetAnchorPosition() { return state_.anchor; } |
| 111 | 119 |
| 112 // Cancels the current Run. See ExitType for a description of what happens | 120 // Cancels the current Run. See ExitType for a description of what happens |
| 113 // with the various parameters. | 121 // with the various parameters. |
| 114 void Cancel(ExitType type); | 122 void Cancel(ExitType type); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // The active instance. | 561 // The active instance. |
| 554 static MenuController* active_instance_; | 562 static MenuController* active_instance_; |
| 555 | 563 |
| 556 // If true, Run blocks. If false, Run doesn't block and this is used for | 564 // If true, Run blocks. If false, Run doesn't block and this is used for |
| 557 // drag and drop. Note that the semantics for drag and drop are slightly | 565 // drag and drop. Note that the semantics for drag and drop are slightly |
| 558 // different: cancel timer is kicked off any time the drag moves outside the | 566 // different: cancel timer is kicked off any time the drag moves outside the |
| 559 // menu, mouse events do nothing... | 567 // menu, mouse events do nothing... |
| 560 bool blocking_run_; | 568 bool blocking_run_; |
| 561 | 569 |
| 562 // If true, we're showing. | 570 // If true, we're showing. |
| 563 bool showing_; | 571 bool showing_ = false; |
| 564 | 572 |
| 565 // Indicates what to exit. | 573 // Indicates what to exit. |
| 566 ExitType exit_type_; | 574 ExitType exit_type_ = EXIT_NONE; |
| 567 | 575 |
| 568 // Whether we did a capture. We do a capture only if we're blocking and | 576 // Whether we did a capture. We do a capture only if we're blocking and |
| 569 // the mouse was down when Run. | 577 // the mouse was down when Run. |
| 570 bool did_capture_; | 578 bool did_capture_ = false; |
| 571 | 579 |
| 572 // As the user drags the mouse around pending_state_ changes immediately. | 580 // As the user drags the mouse around pending_state_ changes immediately. |
| 573 // When the user stops moving/dragging the mouse (or clicks the mouse) | 581 // When the user stops moving/dragging the mouse (or clicks the mouse) |
| 574 // pending_state_ is committed to state_, potentially resulting in | 582 // pending_state_ is committed to state_, potentially resulting in |
| 575 // opening or closing submenus. This gives a slight delayed effect to | 583 // opening or closing submenus. This gives a slight delayed effect to |
| 576 // submenus as the user moves the mouse around. This is done so that as the | 584 // submenus as the user moves the mouse around. This is done so that as the |
| 577 // user moves the mouse all submenus don't immediately pop. | 585 // user moves the mouse all submenus don't immediately pop. |
| 578 State pending_state_; | 586 State pending_state_; |
| 579 State state_; | 587 State state_; |
| 580 | 588 |
| 581 // If the user accepted the selection, this is the result. | 589 // If the user accepted the selection, this is the result. |
| 582 MenuItemView* result_; | 590 MenuItemView* result_ = nullptr; |
| 583 | 591 |
| 584 // The event flags when the user selected the menu. | 592 // The event flags when the user selected the menu. |
| 585 int accept_event_flags_; | 593 int accept_event_flags_ = 0; |
| 586 | 594 |
| 587 // If not empty, it means we're nested. When Run is invoked from within | 595 // If not empty, it means we're nested. When Run is invoked from within |
| 588 // Run, the current state (state_) is pushed onto menu_stack_. This allows | 596 // Run, the current state (state_) is pushed onto menu_stack_. This allows |
| 589 // MenuController to restore the state when the nested run returns. | 597 // MenuController to restore the state when the nested run returns. |
| 590 using NestedState = | 598 using NestedState = |
| 591 std::pair<State, std::unique_ptr<MenuButton::PressedLock>>; | 599 std::pair<State, std::unique_ptr<MenuButton::PressedLock>>; |
| 592 std::list<NestedState> menu_stack_; | 600 std::list<NestedState> menu_stack_; |
| 593 | 601 |
| 594 // When Run is invoked during an active Run, it may be called from a separate | 602 // When Run is invoked during an active Run, it may be called from a separate |
| 595 // MenuControllerDelegate. If not empty it means we are nested, and the | 603 // MenuControllerDelegate. If not empty it means we are nested, and the |
| 596 // stacked delegates should be notified instead of |delegate_|. | 604 // stacked delegates should be notified instead of |delegate_|. |
| 597 std::list<internal::MenuControllerDelegate*> delegate_stack_; | 605 std::list<internal::MenuControllerDelegate*> delegate_stack_; |
| 598 | 606 |
| 599 // As the mouse moves around submenus are not opened immediately. Instead | 607 // As the mouse moves around submenus are not opened immediately. Instead |
| 600 // they open after this timer fires. | 608 // they open after this timer fires. |
| 601 base::OneShotTimer show_timer_; | 609 base::OneShotTimer show_timer_; |
| 602 | 610 |
| 603 // Used to invoke CancelAll(). This is used during drag and drop to hide the | 611 // Used to invoke CancelAll(). This is used during drag and drop to hide the |
| 604 // menu after the mouse moves out of the of the menu. This is necessitated by | 612 // menu after the mouse moves out of the of the menu. This is necessitated by |
| 605 // the lack of an ability to detect when the drag has completed from the drop | 613 // the lack of an ability to detect when the drag has completed from the drop |
| 606 // side. | 614 // side. |
| 607 base::OneShotTimer cancel_all_timer_; | 615 base::OneShotTimer cancel_all_timer_; |
| 608 | 616 |
| 609 // Drop target. | 617 // Drop target. |
| 610 MenuItemView* drop_target_; | 618 MenuItemView* drop_target_ = nullptr; |
| 611 MenuDelegate::DropPosition drop_position_; | 619 MenuDelegate::DropPosition drop_position_ = MenuDelegate::DROP_UNKNOWN; |
| 612 | 620 |
| 613 // Owner of child windows. | 621 // Owner of child windows. |
| 614 // WARNING: this may be NULL. | 622 // WARNING: this may be NULL. |
| 615 Widget* owner_; | 623 Widget* owner_ = nullptr; |
| 616 | 624 |
| 617 // Indicates a possible drag operation. | 625 // Indicates a possible drag operation. |
| 618 bool possible_drag_; | 626 bool possible_drag_ = false; |
| 619 | 627 |
| 620 // True when drag operation is in progress. | 628 // True when drag operation is in progress. |
| 621 bool drag_in_progress_; | 629 bool drag_in_progress_ = false; |
| 622 | 630 |
| 623 // True when the drag operation in progress was initiated by the | 631 // True when the drag operation in progress was initiated by the |
| 624 // MenuController for a child MenuItemView (as opposed to initiated separately | 632 // MenuController for a child MenuItemView (as opposed to initiated separately |
| 625 // by a child View). | 633 // by a child View). |
| 626 bool did_initiate_drag_; | 634 bool did_initiate_drag_ = false; |
| 627 | 635 |
| 628 // Location the mouse was pressed at. Used to detect d&d. | 636 // Location the mouse was pressed at. Used to detect d&d. |
| 629 gfx::Point press_pt_; | 637 gfx::Point press_pt_; |
| 630 | 638 |
| 631 // We get a slew of drag updated messages as the mouse is over us. To avoid | 639 // We get a slew of drag updated messages as the mouse is over us. To avoid |
| 632 // continually processing whether we can drop, we cache the coordinates. | 640 // continually processing whether we can drop, we cache the coordinates. |
| 633 bool valid_drop_coordinates_; | 641 bool valid_drop_coordinates_ = false; |
| 634 gfx::Point drop_pt_; | 642 gfx::Point drop_pt_; |
| 635 int last_drop_operation_; | 643 int last_drop_operation_ = MenuDelegate::DROP_UNKNOWN; |
| 636 | 644 |
| 637 // If true, we're in the middle of invoking ShowAt on a submenu. | 645 // If true, we're in the middle of invoking ShowAt on a submenu. |
| 638 bool showing_submenu_; | 646 bool showing_submenu_ = false; |
| 639 | 647 |
| 640 // Task for scrolling the menu. If non-null indicates a scroll is currently | 648 // Task for scrolling the menu. If non-null indicates a scroll is currently |
| 641 // underway. | 649 // underway. |
| 642 std::unique_ptr<MenuScrollTask> scroll_task_; | 650 std::unique_ptr<MenuScrollTask> scroll_task_; |
| 643 | 651 |
| 644 // The lock to keep the menu button pressed while a menu is visible. | 652 // The lock to keep the menu button pressed while a menu is visible. |
| 645 std::unique_ptr<MenuButton::PressedLock> pressed_lock_; | 653 std::unique_ptr<MenuButton::PressedLock> pressed_lock_; |
| 646 | 654 |
| 647 // ViewStorage id used to store the view mouse drag events are forwarded to. | 655 // ViewStorage id used to store the view mouse drag events are forwarded to. |
| 648 // See UpdateActiveMouseView() for details. | 656 // See UpdateActiveMouseView() for details. |
| 649 const int active_mouse_view_id_; | 657 const int active_mouse_view_id_; |
| 650 | 658 |
| 651 // Current hot tracked child button if any. | 659 // Current hot tracked child button if any. |
| 652 CustomButton* hot_button_; | 660 CustomButton* hot_button_ = nullptr; |
| 653 | 661 |
| 654 internal::MenuControllerDelegate* delegate_; | 662 internal::MenuControllerDelegate* delegate_; |
| 655 | 663 |
| 656 // The timestamp of the event which closed the menu - or 0 otherwise. | 664 // The timestamp of the event which closed the menu - or 0 otherwise. |
| 657 base::TimeTicks closing_event_time_; | 665 base::TimeTicks closing_event_time_; |
| 658 | 666 |
| 659 // Time when the menu is first shown. | 667 // Time when the menu is first shown. |
| 660 base::TimeTicks menu_start_time_; | 668 base::TimeTicks menu_start_time_; |
| 661 | 669 |
| 662 // If a mouse press triggered this menu, this will have its location (in | 670 // If a mouse press triggered this menu, this will have its location (in |
| 663 // screen coordinates). Otherwise this will be (0, 0). | 671 // screen coordinates). Otherwise this will be (0, 0). |
| 664 gfx::Point menu_start_mouse_press_loc_; | 672 gfx::Point menu_start_mouse_press_loc_; |
| 665 | 673 |
| 666 // Controls behavior differences between a combobox and other types of menu | 674 // Controls behavior differences between a combobox and other types of menu |
| 667 // (like a context menu). | 675 // (like a context menu). |
| 668 bool is_combobox_; | 676 bool is_combobox_ = false; |
| 677 |
| 678 // Whether the menu |owner_| needs gesture events. When set to true |
| 679 // MenuController forwards unhandled gesture events to |owner_|. |
| 680 bool owner_needs_gesture_events_ = false; |
| 669 | 681 |
| 670 // Set to true if the menu item was selected by touch. | 682 // Set to true if the menu item was selected by touch. |
| 671 bool item_selected_by_touch_; | 683 bool item_selected_by_touch_ = false; |
| 672 | 684 |
| 673 // During mouse event handling, this is the RootView to forward mouse events | 685 // During mouse event handling, this is the RootView to forward mouse events |
| 674 // to. We need this, because if we forward one event to it (e.g., mouse | 686 // to. We need this, because if we forward one event to it (e.g., mouse |
| 675 // pressed), subsequent events (like dragging) should also go to it, even if | 687 // pressed), subsequent events (like dragging) should also go to it, even if |
| 676 // the mouse is no longer over the view. | 688 // the mouse is no longer over the view. |
| 677 MenuHostRootView* current_mouse_event_target_; | 689 MenuHostRootView* current_mouse_event_target_ = nullptr; |
| 678 | 690 |
| 679 // A mask of the EventFlags for the mouse buttons currently pressed. | 691 // A mask of the EventFlags for the mouse buttons currently pressed. |
| 680 int current_mouse_pressed_state_; | 692 int current_mouse_pressed_state_ = 0; |
| 681 | 693 |
| 682 #if defined(USE_AURA) | 694 #if defined(USE_AURA) |
| 683 std::unique_ptr<MenuPreTargetHandler> menu_pre_target_handler_; | 695 std::unique_ptr<MenuPreTargetHandler> menu_pre_target_handler_; |
| 684 #endif | 696 #endif |
| 685 | 697 |
| 686 DISALLOW_COPY_AND_ASSIGN(MenuController); | 698 DISALLOW_COPY_AND_ASSIGN(MenuController); |
| 687 }; | 699 }; |
| 688 | 700 |
| 689 } // namespace views | 701 } // namespace views |
| 690 | 702 |
| 691 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 703 #endif // UI_VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
| OLD | NEW |