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

Side by Side Diff: views/controls/button/menu_button.cc

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.h ('k') | views/controls/menu/menu_controller.h » ('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 #include "views/controls/button/menu_button.h" 5 #include "views/controls/button/menu_button.h"
6 6
7 #include "app/drag_drop_types.h" 7 #include "app/drag_drop_types.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "gfx/canvas.h" 10 #include "gfx/canvas.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 MenuButton::MenuButton(ButtonListener* listener, 43 MenuButton::MenuButton(ButtonListener* listener,
44 const std::wstring& text, 44 const std::wstring& text,
45 ViewMenuDelegate* menu_delegate, 45 ViewMenuDelegate* menu_delegate,
46 bool show_menu_marker) 46 bool show_menu_marker)
47 : TextButton(listener, text), 47 : TextButton(listener, text),
48 menu_visible_(false), 48 menu_visible_(false),
49 menu_delegate_(menu_delegate), 49 menu_delegate_(menu_delegate),
50 show_menu_marker_(show_menu_marker), 50 show_menu_marker_(show_menu_marker),
51 menu_marker_(ResourceBundle::GetSharedInstance().GetBitmapNamed( 51 menu_marker_(ResourceBundle::GetSharedInstance().GetBitmapNamed(
52 IDR_MENU_DROPARROW)) { 52 IDR_MENU_DROPARROW)),
53 destroyed_flag_(NULL) {
53 set_alignment(TextButton::ALIGN_LEFT); 54 set_alignment(TextButton::ALIGN_LEFT);
54 } 55 }
55 56
56 MenuButton::~MenuButton() { 57 MenuButton::~MenuButton() {
58 if (destroyed_flag_)
59 *destroyed_flag_ = true;
57 } 60 }
58 61
59 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
60 // 63 //
61 // MenuButton - Public APIs 64 // MenuButton - Public APIs
62 // 65 //
63 //////////////////////////////////////////////////////////////////////////////// 66 ////////////////////////////////////////////////////////////////////////////////
64 67
65 gfx::Size MenuButton::GetPreferredSize() { 68 gfx::Size MenuButton::GetPreferredSize() {
66 gfx::Size prefsize = TextButton::GetPreferredSize(); 69 gfx::Size prefsize = TextButton::GetPreferredSize();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // We're about to show the menu from a mouse press. By showing from the 141 // We're about to show the menu from a mouse press. By showing from the
139 // mouse press event we block RootView in mouse dispatching. This also 142 // mouse press event we block RootView in mouse dispatching. This also
140 // appears to cause RootView to get a mouse pressed BEFORE the mouse 143 // appears to cause RootView to get a mouse pressed BEFORE the mouse
141 // release is seen, which means RootView sends us another mouse press no 144 // release is seen, which means RootView sends us another mouse press no
142 // matter where the user pressed. To force RootView to recalculate the 145 // matter where the user pressed. To force RootView to recalculate the
143 // mouse target during the mouse press we explicitly set the mouse handler 146 // mouse target during the mouse press we explicitly set the mouse handler
144 // to NULL. 147 // to NULL.
145 GetRootView()->SetMouseHandler(NULL); 148 GetRootView()->SetMouseHandler(NULL);
146 149
147 menu_visible_ = true; 150 menu_visible_ = true;
151
152 bool destroyed = false;
153 destroyed_flag_ = &destroyed;
154
148 menu_delegate_->RunMenu(this, menu_position); 155 menu_delegate_->RunMenu(this, menu_position);
156
157 if (destroyed) {
158 // The menu was deleted while showing. Don't attempt any processing.
159 return false;
160 }
161
149 menu_visible_ = false; 162 menu_visible_ = false;
150 menu_closed_time_ = Time::Now(); 163 menu_closed_time_ = Time::Now();
151 164
152 // Now that the menu has closed, we need to manually reset state to 165 // Now that the menu has closed, we need to manually reset state to
153 // "normal" since the menu modal loop will have prevented normal 166 // "normal" since the menu modal loop will have prevented normal
154 // mouse move messages from getting to this View. We set "normal" 167 // mouse move messages from getting to this View. We set "normal"
155 // and not "hot" because the likelihood is that the mouse is now 168 // and not "hot" because the likelihood is that the mouse is now
156 // somewhere else (user clicked elsewhere on screen to close the menu 169 // somewhere else (user clicked elsewhere on screen to close the menu
157 // or selected an item) and we will inevitably refresh the hot state 170 // or selected an item) and we will inevitably refresh the hot state
158 // in the event the mouse _is_ over the view. 171 // in the event the mouse _is_ over the view.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 260
248 *state = AccessibilityTypes::STATE_HASPOPUP; 261 *state = AccessibilityTypes::STATE_HASPOPUP;
249 return true; 262 return true;
250 } 263 }
251 264
252 std::string MenuButton::GetClassName() const { 265 std::string MenuButton::GetClassName() const {
253 return kViewClassName; 266 return kViewClassName;
254 } 267 }
255 268
256 } // namespace views 269 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/menu_button.h ('k') | views/controls/menu/menu_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698