Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ui/views/controls/menu/menu_controller.h

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

Powered by Google App Engine
This is Rietveld 408576698