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

Side by Side Diff: ui/views/widget/root_view.cc

Issue 169443005: Fix crash which occurs when a widget destroys itself as a result of ET_GESTURE_TAP_DOWN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 #include "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 218
219 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { 219 void RootView::DispatchGestureEvent(ui::GestureEvent* event) {
220 if (gesture_handler_) { 220 if (gesture_handler_) {
221 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during 221 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during
222 // processing. 222 // processing.
223 View* handler = scroll_gesture_handler_ && 223 View* handler = scroll_gesture_handler_ &&
224 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? 224 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ?
225 scroll_gesture_handler_ : gesture_handler_; 225 scroll_gesture_handler_ : gesture_handler_;
226 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); 226 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler);
227 DispatchEventToTarget(handler, &handler_event); 227
228 {
229 WidgetDeletionObserver widget_deletion_observer(widget_);
230 DispatchEventToTarget(handler, &handler_event);
sadrul 2014/02/18 12:53:26 This is also an issue for other kinds of event dis
231 if (!widget_deletion_observer.IsWidgetAlive())
232 return;
233 }
228 234
229 if (event->type() == ui::ET_GESTURE_END && 235 if (event->type() == ui::ET_GESTURE_END &&
230 event->details().touch_points() <= 1) { 236 event->details().touch_points() <= 1) {
231 // In case a drag was in progress, reset all the handlers. Otherwise, just 237 // In case a drag was in progress, reset all the handlers. Otherwise, just
232 // reset the gesture handler. 238 // reset the gesture handler.
233 if (gesture_handler_ == mouse_pressed_handler_) 239 if (gesture_handler_ == mouse_pressed_handler_)
234 SetMouseHandler(NULL); 240 SetMouseHandler(NULL);
235 else 241 else
236 gesture_handler_ = NULL; 242 gesture_handler_ = NULL;
237 } 243 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 gesture_handler_ && (gesture_handler_ != this); 311 gesture_handler_ && (gesture_handler_ != this);
306 gesture_handler_ = gesture_handler_->parent()) { 312 gesture_handler_ = gesture_handler_->parent()) {
307 if (!gesture_handler_->enabled()) { 313 if (!gesture_handler_->enabled()) {
308 // Disabled views eat events but are treated as not handled. 314 // Disabled views eat events but are treated as not handled.
309 return; 315 return;
310 } 316 }
311 317
312 // See if this view wants to handle the Gesture. 318 // See if this view wants to handle the Gesture.
313 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), 319 ui::GestureEvent gesture_event(*event, static_cast<View*>(this),
314 gesture_handler_); 320 gesture_handler_);
315 DispatchEventToTarget(gesture_handler_, &gesture_event); 321
322 {
323 WidgetDeletionObserver widget_deletion_observer(widget_);
324 DispatchEventToTarget(gesture_handler_, &gesture_event);
325 if (!widget_deletion_observer.IsWidgetAlive())
326 return;
327 }
316 328
317 // The view could have removed itself from the tree when handling 329 // The view could have removed itself from the tree when handling
318 // OnGestureEvent(). So handle as per OnMousePressed. NB: we 330 // OnGestureEvent(). So handle as per OnMousePressed. NB: we
319 // assume that the RootView itself cannot be so removed. 331 // assume that the RootView itself cannot be so removed.
320 if (!gesture_handler_) 332 if (!gesture_handler_)
321 return; 333 return;
322 334
323 if (gesture_event.handled()) { 335 if (gesture_event.handled()) {
324 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) 336 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
325 scroll_gesture_handler_ = gesture_handler_; 337 scroll_gesture_handler_ = gesture_handler_;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return; 751 return;
740 } 752 }
741 } 753 }
742 754
743 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { 755 bool RootView::CanDispatchToTarget(ui::EventTarget* target) {
744 return event_dispatch_target_ == target; 756 return event_dispatch_target_ == target;
745 } 757 }
746 758
747 } // namespace internal 759 } // namespace internal
748 } // namespace views 760 } // namespace views
OLDNEW
« no previous file with comments | « ash/wm/caption_buttons/frame_maximize_button_unittest.cc ('k') | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698