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

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

Powered by Google App Engine
This is Rietveld 408576698