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