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

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

Issue 1664001: Fixes possible crash if the window hosting a menu was closed while the (Closed)
Patch Set: Incorporated review feedback Created 10 years, 8 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 | « views/controls/button/menu_button.cc ('k') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ 5 #ifndef VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_
6 #define VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ 6 #define VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <list> 10 #include <list>
(...skipping 20 matching lines...) Expand all
31 // MenuController ------------------------------------------------------------- 31 // MenuController -------------------------------------------------------------
32 32
33 // MenuController is used internally by the various menu classes to manage 33 // MenuController is used internally by the various menu classes to manage
34 // showing, selecting and drag/drop for menus. All relevant events are 34 // showing, selecting and drag/drop for menus. All relevant events are
35 // forwarded to the MenuController from SubmenuView and MenuHost. 35 // forwarded to the MenuController from SubmenuView and MenuHost.
36 class MenuController : public MessageLoopForUI::Dispatcher { 36 class MenuController : public MessageLoopForUI::Dispatcher {
37 public: 37 public:
38 friend class MenuHostRootView; 38 friend class MenuHostRootView;
39 friend class MenuItemView; 39 friend class MenuItemView;
40 40
41 // Enumeration of how the menu should exit.
42 enum ExitType {
43 // Don't exit.
44 EXIT_NONE,
45
46 // All menus, including nested, should be exited.
47 EXIT_ALL,
48
49 // Only the outermost menu should be exited.
50 EXIT_OUTERMOST,
51
52 // This is set if the menu is being closed as the result of one of the menus
53 // being destroyed.
54 EXIT_DESTROYED
55 };
56
41 // If a menu is currently active, this returns the controller for it. 57 // If a menu is currently active, this returns the controller for it.
42 static MenuController* GetActiveInstance(); 58 static MenuController* GetActiveInstance();
43 59
44 // Runs the menu at the specified location. If the menu was configured to 60 // Runs the menu at the specified location. If the menu was configured to
45 // block, the selected item is returned. If the menu does not block this 61 // block, the selected item is returned. If the menu does not block this
46 // returns NULL immediately. 62 // returns NULL immediately.
47 MenuItemView* Run(gfx::NativeWindow parent, 63 MenuItemView* Run(gfx::NativeWindow parent,
48 MenuButton* button, 64 MenuButton* button,
49 MenuItemView* root, 65 MenuItemView* root,
50 const gfx::Rect& bounds, 66 const gfx::Rect& bounds,
51 MenuItemView::AnchorPosition position, 67 MenuItemView::AnchorPosition position,
52 int* mouse_event_flags); 68 int* mouse_event_flags);
53 69
54 // Whether or not Run blocks. 70 // Whether or not Run blocks.
55 bool IsBlockingRun() const { return blocking_run_; } 71 bool IsBlockingRun() const { return blocking_run_; }
56 72
57 // Sets the selection to menu_item, a value of NULL unselects everything. 73 // Sets the selection to menu_item, a value of NULL unselects everything.
58 // If open_submenu is true and menu_item has a submenu, the submenu is shown. 74 // If open_submenu is true and menu_item has a submenu, the submenu is shown.
59 // If update_immediately is true, submenus are opened immediately, otherwise 75 // If update_immediately is true, submenus are opened immediately, otherwise
60 // submenus are only opened after a timer fires. 76 // submenus are only opened after a timer fires.
61 // 77 //
62 // Internally this updates pending_state_ immediatley, and if 78 // Internally this updates pending_state_ immediatley, and if
63 // update_immediately is true, CommitPendingSelection is invoked to 79 // update_immediately is true, CommitPendingSelection is invoked to
64 // show/hide submenus and update state_. 80 // show/hide submenus and update state_.
65 void SetSelection(MenuItemView* menu_item, 81 void SetSelection(MenuItemView* menu_item,
66 bool open_submenu, 82 bool open_submenu,
67 bool update_immediately); 83 bool update_immediately);
68 84
69 // Cancels the current Run. If all is true, any nested loops are canceled 85 // Cancels the current Run. See ExitType for a description of what happens
70 // as well. This immediately hides all menus. 86 // with the various parameters.
71 void Cancel(bool all); 87 void Cancel(ExitType type);
72 88
73 // An alternative to Cancel(true) that can be used with a OneShotTimer. 89 // An alternative to Cancel(EXIT_ALL) that can be used with a OneShotTimer.
74 void CancelAll() { return Cancel(true); } 90 void CancelAll() { Cancel(EXIT_ALL); }
75 91
76 // Various events, forwarded from the submenu. 92 // Various events, forwarded from the submenu.
77 // 93 //
78 // NOTE: the coordinates of the events are in that of the 94 // NOTE: the coordinates of the events are in that of the
79 // MenuScrollViewContainer. 95 // MenuScrollViewContainer.
80 void OnMousePressed(SubmenuView* source, const MouseEvent& event); 96 void OnMousePressed(SubmenuView* source, const MouseEvent& event);
81 void OnMouseDragged(SubmenuView* source, const MouseEvent& event); 97 void OnMouseDragged(SubmenuView* source, const MouseEvent& event);
82 void OnMouseReleased(SubmenuView* source, const MouseEvent& event); 98 void OnMouseReleased(SubmenuView* source, const MouseEvent& event);
83 void OnMouseMoved(SubmenuView* source, const MouseEvent& event); 99 void OnMouseMoved(SubmenuView* source, const MouseEvent& event);
84 void OnMouseEntered(SubmenuView* source, const MouseEvent& event); 100 void OnMouseEntered(SubmenuView* source, const MouseEvent& event);
85 bool GetDropFormats( 101 bool GetDropFormats(
86 SubmenuView* source, 102 SubmenuView* source,
87 int* formats, 103 int* formats,
88 std::set<OSExchangeData::CustomFormat>* custom_formats); 104 std::set<OSExchangeData::CustomFormat>* custom_formats);
89 bool AreDropTypesRequired(SubmenuView* source); 105 bool AreDropTypesRequired(SubmenuView* source);
90 bool CanDrop(SubmenuView* source, const OSExchangeData& data); 106 bool CanDrop(SubmenuView* source, const OSExchangeData& data);
91 void OnDragEntered(SubmenuView* source, const DropTargetEvent& event); 107 void OnDragEntered(SubmenuView* source, const DropTargetEvent& event);
92 int OnDragUpdated(SubmenuView* source, const DropTargetEvent& event); 108 int OnDragUpdated(SubmenuView* source, const DropTargetEvent& event);
93 void OnDragExited(SubmenuView* source); 109 void OnDragExited(SubmenuView* source);
94 int OnPerformDrop(SubmenuView* source, const DropTargetEvent& event); 110 int OnPerformDrop(SubmenuView* source, const DropTargetEvent& event);
95 111
96 // Invoked from the scroll buttons of the MenuScrollViewContainer. 112 // Invoked from the scroll buttons of the MenuScrollViewContainer.
97 void OnDragEnteredScrollButton(SubmenuView* source, bool is_up); 113 void OnDragEnteredScrollButton(SubmenuView* source, bool is_up);
98 void OnDragExitedScrollButton(SubmenuView* source); 114 void OnDragExitedScrollButton(SubmenuView* source);
99 115
100 private: 116 private:
101 // Enumeration of how the menu should exit.
102 enum ExitType {
103 // Don't exit.
104 EXIT_NONE,
105
106 // All menus, including nested, should be exited.
107 EXIT_ALL,
108
109 // Only the outermost menu should be exited.
110 EXIT_OUTERMOST
111 };
112
113 class MenuScrollTask; 117 class MenuScrollTask;
114 118
115 // Tracks selection information. 119 // Tracks selection information.
116 struct State { 120 struct State {
117 State() : item(NULL), submenu_open(false) {} 121 State() : item(NULL), submenu_open(false) {}
118 122
119 // The selected menu item. 123 // The selected menu item.
120 MenuItemView* item; 124 MenuItemView* item;
121 125
122 // If item has a submenu this indicates if the submenu is showing. 126 // If item has a submenu this indicates if the submenu is showing.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 scoped_ptr<MenuScrollTask> scroll_task_; 406 scoped_ptr<MenuScrollTask> scroll_task_;
403 407
404 MenuButton* menu_button_; 408 MenuButton* menu_button_;
405 409
406 DISALLOW_COPY_AND_ASSIGN(MenuController); 410 DISALLOW_COPY_AND_ASSIGN(MenuController);
407 }; 411 };
408 412
409 } // namespace views 413 } // namespace views
410 414
411 #endif // VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ 415 #endif // VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_
OLDNEW
« no previous file with comments | « views/controls/button/menu_button.cc ('k') | views/controls/menu/menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698