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

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

Issue 2659903002: Change MenuControllerDelegate to provide WeakPtr (Closed)
Patch Set: 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 18 matching lines...) Expand all
29 } 29 }
30 #endif 30 #endif
31 31
32 MenuRunnerImpl::MenuRunnerImpl(MenuItemView* menu) 32 MenuRunnerImpl::MenuRunnerImpl(MenuItemView* menu)
33 : menu_(menu), 33 : menu_(menu),
34 running_(false), 34 running_(false),
35 delete_after_run_(false), 35 delete_after_run_(false),
36 async_(false), 36 async_(false),
37 for_drop_(false), 37 for_drop_(false),
38 controller_(NULL), 38 controller_(NULL),
39 owns_controller_(false), 39 owns_controller_(false) {}
40 weak_factory_(this) {}
41 40
42 bool MenuRunnerImpl::IsRunning() const { 41 bool MenuRunnerImpl::IsRunning() const {
43 return running_; 42 return running_;
44 } 43 }
45 44
46 void MenuRunnerImpl::Release() { 45 void MenuRunnerImpl::Release() {
47 if (running_) { 46 if (running_) {
48 if (delete_after_run_) 47 if (delete_after_run_)
49 return; // We already canceled. 48 return; // We already canceled.
50 49
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Make sure all the windows we created to show the menus have been 194 // Make sure all the windows we created to show the menus have been
196 // destroyed. 195 // destroyed.
197 menu_->DestroyAllMenuHosts(); 196 menu_->DestroyAllMenuHosts();
198 if (delete_after_run_) { 197 if (delete_after_run_) {
199 delete this; 198 delete this;
200 return MenuRunner::MENU_DELETED; 199 return MenuRunner::MENU_DELETED;
201 } 200 }
202 running_ = false; 201 running_ = false;
203 if (menu_->GetDelegate()) { 202 if (menu_->GetDelegate()) {
204 // Executing the command may also delete this. 203 // Executing the command may also delete this.
205 base::WeakPtr<MenuRunnerImpl> ref(weak_factory_.GetWeakPtr()); 204 base::WeakPtr<MenuControllerDelegate> ref(AsWeakPtr());
206 if (result && !for_drop_) { 205 if (result && !for_drop_) {
207 // Do not execute the menu that was dragged/dropped. 206 // Do not execute the menu that was dragged/dropped.
208 menu_->GetDelegate()->ExecuteCommand(result->GetCommand(), 207 menu_->GetDelegate()->ExecuteCommand(result->GetCommand(),
209 mouse_event_flags); 208 mouse_event_flags);
210 } 209 }
211 // Only notify the delegate if it did not delete this. 210 // Only notify the delegate if it did not delete this.
212 if (!ref) 211 if (!ref)
213 return MenuRunner::MENU_DELETED; 212 return MenuRunner::MENU_DELETED;
214 else if (type == NOTIFY_DELEGATE) 213 else if (type == NOTIFY_DELEGATE)
215 menu_->GetDelegate()->OnMenuClosed(result, MenuRunner::NORMAL_EXIT); 214 menu_->GetDelegate()->OnMenuClosed(result, MenuRunner::NORMAL_EXIT);
216 } 215 }
217 return MenuRunner::NORMAL_EXIT; 216 return MenuRunner::NORMAL_EXIT;
218 } 217 }
219 218
220 bool MenuRunnerImpl::ShouldShowMnemonics(MenuButton* button) { 219 bool MenuRunnerImpl::ShouldShowMnemonics(MenuButton* button) {
221 // Show mnemonics if the button has focus or alt is pressed. 220 // Show mnemonics if the button has focus or alt is pressed.
222 bool show_mnemonics = button ? button->HasFocus() : false; 221 bool show_mnemonics = button ? button->HasFocus() : false;
223 #if defined(OS_WIN) 222 #if defined(OS_WIN)
224 // This is only needed on Windows. 223 // This is only needed on Windows.
225 if (!show_mnemonics) 224 if (!show_mnemonics)
226 show_mnemonics = ui::win::IsAltPressed(); 225 show_mnemonics = ui::win::IsAltPressed();
227 #endif 226 #endif
228 return show_mnemonics; 227 return show_mnemonics;
229 } 228 }
230 229
231 } // namespace internal 230 } // namespace internal
232 } // namespace views 231 } // 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