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

Side by Side Diff: ui/views/controls/menu/menu_runner_impl.cc

Issue 2654093005: Fix MenuRunner Releasing (Closed)
Patch Set: Clarification and renaming Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/views/controls/menu/menu_runner_impl.h" 5 #include "ui/views/controls/menu/menu_runner_impl.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "ui/native_theme/native_theme.h" 8 #include "ui/native_theme/native_theme.h"
9 #include "ui/views/controls/button/menu_button.h" 9 #include "ui/views/controls/button/menu_button.h"
10 #include "ui/views/controls/menu/menu_controller.h" 10 #include "ui/views/controls/menu/menu_controller.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 delete_after_run_ = true; 55 delete_after_run_ = true;
56 56
57 // Swap in a different delegate. That way we know the original MenuDelegate 57 // Swap in a different delegate. That way we know the original MenuDelegate
58 // won't be notified later on (when it's likely already been deleted). 58 // won't be notified later on (when it's likely already been deleted).
59 if (!empty_delegate_.get()) 59 if (!empty_delegate_.get())
60 empty_delegate_.reset(new MenuDelegate()); 60 empty_delegate_.reset(new MenuDelegate());
61 menu_->set_delegate(empty_delegate_.get()); 61 menu_->set_delegate(empty_delegate_.get());
62 62
63 // Verify that the MenuController is still active. It may have been 63 // Verify that the MenuController is still active. It may have been
64 // destroyed out of order. 64 // destroyed out of order.
65 if (MenuController::GetActiveInstance()) { 65 if (controller_) {
66 DCHECK(controller_);
67 // Release is invoked when MenuRunner is destroyed. Assume this is 66 // Release is invoked when MenuRunner is destroyed. Assume this is
68 // happening because the object referencing the menu has been destroyed 67 // happening because the object referencing the menu has been destroyed
69 // and the menu button is no longer valid. 68 // and the menu button is no longer valid.
70 controller_->Cancel(MenuController::EXIT_DESTROYED); 69 controller_->Cancel(MenuController::EXIT_DESTROYED);
71 return; 70 return;
72 } 71 }
73 } 72 }
74 73
75 delete this; 74 delete this;
76 } 75 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 for_drop_ = (run_types & MenuRunner::FOR_DROP) != 0; 118 for_drop_ = (run_types & MenuRunner::FOR_DROP) != 0;
120 bool has_mnemonics = (run_types & MenuRunner::HAS_MNEMONICS) != 0; 119 bool has_mnemonics = (run_types & MenuRunner::HAS_MNEMONICS) != 0;
121 owns_controller_ = false; 120 owns_controller_ = false;
122 if (!controller) { 121 if (!controller) {
123 // No menus are showing, show one. 122 // No menus are showing, show one.
124 controller = new MenuController(!for_drop_, this); 123 controller = new MenuController(!for_drop_, this);
125 owns_controller_ = true; 124 owns_controller_ = true;
126 } 125 }
127 controller->SetAsyncRun(async_); 126 controller->SetAsyncRun(async_);
128 controller->set_is_combobox((run_types & MenuRunner::COMBOBOX) != 0); 127 controller->set_is_combobox((run_types & MenuRunner::COMBOBOX) != 0);
129 controller_ = controller; 128 controller_ = controller->AsWeakPtr();
130 menu_->set_controller(controller_); 129 menu_->set_controller(controller_.get());
131 menu_->PrepareForRun(owns_controller_, 130 menu_->PrepareForRun(owns_controller_,
132 has_mnemonics, 131 has_mnemonics,
133 !for_drop_ && ShouldShowMnemonics(button)); 132 !for_drop_ && ShouldShowMnemonics(button));
134 133
135 // Run the loop. 134 // Run the loop.
136 int mouse_event_flags = 0; 135 int mouse_event_flags = 0;
137 MenuItemView* result = 136 MenuItemView* result =
138 controller->Run(parent, 137 controller->Run(parent,
139 button, 138 button,
140 menu_, 139 menu_,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ++i) 179 ++i)
181 delete *i; 180 delete *i;
182 } 181 }
183 182
184 MenuRunner::RunResult MenuRunnerImpl::MenuDone(NotifyType type, 183 MenuRunner::RunResult MenuRunnerImpl::MenuDone(NotifyType type,
185 MenuItemView* result, 184 MenuItemView* result,
186 int mouse_event_flags) { 185 int mouse_event_flags) {
187 menu_->RemoveEmptyMenus(); 186 menu_->RemoveEmptyMenus();
188 menu_->set_controller(nullptr); 187 menu_->set_controller(nullptr);
189 188
190 if (owns_controller_) { 189 if (owns_controller_ && controller_) {
191 // We created the controller and need to delete it. 190 // We created the controller and need to delete it.
192 delete controller_; 191 delete controller_.get();
193 owns_controller_ = false; 192 owns_controller_ = false;
194 } 193 }
195 controller_ = nullptr; 194 controller_ = nullptr;
196 // Make sure all the windows we created to show the menus have been 195 // Make sure all the windows we created to show the menus have been
197 // destroyed. 196 // destroyed.
198 menu_->DestroyAllMenuHosts(); 197 menu_->DestroyAllMenuHosts();
199 if (delete_after_run_) { 198 if (delete_after_run_) {
200 delete this; 199 delete this;
201 return MenuRunner::MENU_DELETED; 200 return MenuRunner::MENU_DELETED;
202 } 201 }
(...skipping 21 matching lines...) Expand all
224 #if defined(OS_WIN) 223 #if defined(OS_WIN)
225 // This is only needed on Windows. 224 // This is only needed on Windows.
226 if (!show_mnemonics) 225 if (!show_mnemonics)
227 show_mnemonics = ui::win::IsAltPressed(); 226 show_mnemonics = ui::win::IsAltPressed();
228 #endif 227 #endif
229 return show_mnemonics; 228 return show_mnemonics;
230 } 229 }
231 230
232 } // namespace internal 231 } // namespace internal
233 } // namespace views 232 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl.h ('k') | ui/views/controls/menu/menu_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698