OLD | NEW |
---|---|
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" |
11 #include "ui/base/accessibility/accessible_view_state.h" | 11 #include "ui/base/accessibility/accessible_view_state.h" |
12 #include "ui/base/dragdrop/drag_drop_types.h" | 12 #include "ui/base/dragdrop/drag_drop_types.h" |
13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
15 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/views/focus/view_storage.h" | 17 #include "ui/views/focus/view_storage.h" |
18 #include "ui/views/layout/fill_layout.h" | 18 #include "ui/views/layout/fill_layout.h" |
19 #include "ui/views/views_switches.h" | 19 #include "ui/views/views_switches.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
22 #include "ui/views/widget/widget_deletion_observer.h" | |
23 | 22 |
24 #if defined(USE_AURA) | 23 #if defined(USE_AURA) |
25 #include "ui/base/cursor/cursor.h" | 24 #include "ui/base/cursor/cursor.h" |
26 #endif | 25 #endif |
27 | 26 |
28 namespace views { | 27 namespace views { |
29 namespace internal { | 28 namespace internal { |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 event->StopPropagation(); | 133 event->StopPropagation(); |
135 return; | 134 return; |
136 } | 135 } |
137 | 136 |
138 DispatchKeyEventStartAt(v, event); | 137 DispatchKeyEventStartAt(v, event); |
139 } | 138 } |
140 | 139 |
141 void RootView::DispatchScrollEvent(ui::ScrollEvent* event) { | 140 void RootView::DispatchScrollEvent(ui::ScrollEvent* event) { |
142 for (View* v = GetEventHandlerForPoint(event->location()); | 141 for (View* v = GetEventHandlerForPoint(event->location()); |
143 v && v != this && !event->stopped_propagation(); v = v->parent()) { | 142 v && v != this && !event->stopped_propagation(); v = v->parent()) { |
144 DispatchEventToTarget(v, event); | 143 ui::EventDispatchDetails dispatch_details = DispatchEventToTarget(v, event); |
144 if (dispatch_details.dispatcher_destroyed) | |
sadrul
2014/02/19 21:26:18
target_destroyed?
| |
145 return; | |
145 } | 146 } |
146 | 147 |
147 if (event->handled() || event->type() != ui::ET_SCROLL) | 148 if (event->handled() || event->type() != ui::ET_SCROLL) |
148 return; | 149 return; |
149 | 150 |
150 // Convert unprocessed scroll events into mouse-wheel events. | 151 // Convert unprocessed scroll events into mouse-wheel events. |
151 ui::MouseWheelEvent wheel(*event); | 152 ui::MouseWheelEvent wheel(*event); |
152 if (OnMouseWheel(wheel)) | 153 if (OnMouseWheel(wheel)) |
153 event->SetHandled(); | 154 event->SetHandled(); |
154 } | 155 } |
155 | 156 |
156 void RootView::DispatchTouchEvent(ui::TouchEvent* event) { | 157 void RootView::DispatchTouchEvent(ui::TouchEvent* event) { |
157 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the | 158 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the |
158 // view and target that view with all touches with the same id until the | 159 // view and target that view with all touches with the same id until the |
159 // release (or keep it if captured). | 160 // release (or keep it if captured). |
160 | 161 |
161 // If touch_pressed_handler_ is non null, we are currently processing | 162 // If touch_pressed_handler_ is non null, we are currently processing |
162 // a touch down on the screen situation. In that case we send the | 163 // a touch down on the screen situation. In that case we send the |
163 // event to touch_pressed_handler_ | 164 // event to touch_pressed_handler_ |
164 | 165 |
165 if (touch_pressed_handler_) { | 166 if (touch_pressed_handler_) { |
166 ui::TouchEvent touch_event(*event, static_cast<View*>(this), | 167 ui::TouchEvent touch_event(*event, static_cast<View*>(this), |
167 touch_pressed_handler_); | 168 touch_pressed_handler_); |
168 DispatchEventToTarget(touch_pressed_handler_, &touch_event); | 169 ui::EventDispatchDetails dispatch_details = |
170 DispatchEventToTarget(touch_pressed_handler_, &touch_event); | |
169 if (touch_event.handled()) | 171 if (touch_event.handled()) |
170 event->SetHandled(); | 172 event->SetHandled(); |
171 if (touch_event.stopped_propagation()) | 173 if (touch_event.stopped_propagation()) |
172 event->StopPropagation(); | 174 event->StopPropagation(); |
175 if (dispatch_details.dispatcher_destroyed) | |
176 return; | |
173 return; | 177 return; |
174 } | 178 } |
175 | 179 |
176 // Walk up the tree until we find a view that wants the touch event. | 180 // Walk up the tree until we find a view that wants the touch event. |
177 for (touch_pressed_handler_ = GetEventHandlerForPoint(event->location()); | 181 for (touch_pressed_handler_ = GetEventHandlerForPoint(event->location()); |
178 touch_pressed_handler_ && (touch_pressed_handler_ != this); | 182 touch_pressed_handler_ && (touch_pressed_handler_ != this); |
179 touch_pressed_handler_ = touch_pressed_handler_->parent()) { | 183 touch_pressed_handler_ = touch_pressed_handler_->parent()) { |
180 if (!touch_pressed_handler_->enabled()) { | 184 if (!touch_pressed_handler_->enabled()) { |
181 // Disabled views eat events but are treated as not handled. | 185 // Disabled views eat events but are treated as not handled. |
182 break; | 186 break; |
183 } | 187 } |
184 | 188 |
185 // See if this view wants to handle the touch | 189 // See if this view wants to handle the touch |
186 ui::TouchEvent touch_event(*event, static_cast<View*>(this), | 190 ui::TouchEvent touch_event(*event, static_cast<View*>(this), |
187 touch_pressed_handler_); | 191 touch_pressed_handler_); |
188 DispatchEventToTarget(touch_pressed_handler_, &touch_event); | 192 ui::EventDispatchDetails dispatch_details = |
193 DispatchEventToTarget(touch_pressed_handler_, &touch_event); | |
189 if (touch_event.handled()) | 194 if (touch_event.handled()) |
190 event->SetHandled(); | 195 event->SetHandled(); |
191 if (touch_event.stopped_propagation()) | 196 if (touch_event.stopped_propagation()) |
192 event->StopPropagation(); | 197 event->StopPropagation(); |
198 if (dispatch_details.dispatcher_destroyed) | |
199 return; | |
193 | 200 |
194 // The view could have removed itself from the tree when handling | 201 // The view could have removed itself from the tree when handling |
195 // OnTouchEvent(). So handle as per OnMousePressed. NB: we | 202 // OnTouchEvent(). So handle as per OnMousePressed. NB: we |
196 // assume that the RootView itself cannot be so removed. | 203 // assume that the RootView itself cannot be so removed. |
197 if (!touch_pressed_handler_) | 204 if (!touch_pressed_handler_) |
198 break; | 205 break; |
199 | 206 |
200 // The touch event wasn't processed. Go up the view hierarchy and dispatch | 207 // The touch event wasn't processed. Go up the view hierarchy and dispatch |
201 // the touch event. | 208 // the touch event. |
202 if (!event->handled()) | 209 if (!event->handled()) |
(...skipping 14 matching lines...) Expand all Loading... | |
217 } | 224 } |
218 | 225 |
219 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { | 226 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { |
220 if (gesture_handler_) { | 227 if (gesture_handler_) { |
221 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during | 228 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during |
222 // processing. | 229 // processing. |
223 View* handler = scroll_gesture_handler_ && | 230 View* handler = scroll_gesture_handler_ && |
224 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? | 231 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? |
225 scroll_gesture_handler_ : gesture_handler_; | 232 scroll_gesture_handler_ : gesture_handler_; |
226 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); | 233 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); |
227 DispatchEventToTarget(handler, &handler_event); | 234 ui::EventDispatchDetails dispatch_details = |
235 DispatchEventToTarget(handler, &handler_event); | |
236 if (dispatch_details.dispatcher_destroyed) | |
237 return; | |
228 | 238 |
229 if (event->type() == ui::ET_GESTURE_END && | 239 if (event->type() == ui::ET_GESTURE_END && |
230 event->details().touch_points() <= 1) { | 240 event->details().touch_points() <= 1) { |
231 // In case a drag was in progress, reset all the handlers. Otherwise, just | 241 // In case a drag was in progress, reset all the handlers. Otherwise, just |
232 // reset the gesture handler. | 242 // reset the gesture handler. |
233 if (gesture_handler_ == mouse_pressed_handler_) | 243 if (gesture_handler_ == mouse_pressed_handler_) |
234 SetMouseHandler(NULL); | 244 SetMouseHandler(NULL); |
235 else | 245 else |
236 gesture_handler_ = NULL; | 246 gesture_handler_ = NULL; |
237 } | 247 } |
(...skipping 16 matching lines...) Expand all Loading... | |
254 !scroll_gesture_handler_) { | 264 !scroll_gesture_handler_) { |
255 // Some view started processing gesture events, however it does not | 265 // Some view started processing gesture events, however it does not |
256 // process scroll-gesture events. In such case, we allow the event to | 266 // process scroll-gesture events. In such case, we allow the event to |
257 // bubble up, and install a different scroll-gesture handler different | 267 // bubble up, and install a different scroll-gesture handler different |
258 // from the default gesture handler. | 268 // from the default gesture handler. |
259 for (scroll_gesture_handler_ = gesture_handler_->parent(); | 269 for (scroll_gesture_handler_ = gesture_handler_->parent(); |
260 scroll_gesture_handler_ && scroll_gesture_handler_ != this; | 270 scroll_gesture_handler_ && scroll_gesture_handler_ != this; |
261 scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { | 271 scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { |
262 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), | 272 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), |
263 scroll_gesture_handler_); | 273 scroll_gesture_handler_); |
264 DispatchEventToTarget(scroll_gesture_handler_, &gesture_event); | 274 ui::EventDispatchDetails dispatch_details = |
275 DispatchEventToTarget(scroll_gesture_handler_, &gesture_event); | |
265 if (gesture_event.stopped_propagation()) { | 276 if (gesture_event.stopped_propagation()) { |
266 event->StopPropagation(); | 277 event->StopPropagation(); |
267 return; | 278 return; |
268 } else if (gesture_event.handled()) { | 279 } else if (gesture_event.handled()) { |
269 event->SetHandled(); | 280 event->SetHandled(); |
270 return; | 281 return; |
282 } else if (dispatch_details.dispatcher_destroyed) { | |
283 return; | |
271 } | 284 } |
272 } | 285 } |
273 scroll_gesture_handler_ = NULL; | 286 scroll_gesture_handler_ = NULL; |
274 } | 287 } |
275 | 288 |
276 return; | 289 return; |
277 } | 290 } |
278 | 291 |
279 // If there was no handler for a SCROLL_BEGIN event, then subsequent scroll | 292 // If there was no handler for a SCROLL_BEGIN event, then subsequent scroll |
280 // events are not dispatched to any views. | 293 // events are not dispatched to any views. |
(...skipping 24 matching lines...) Expand all Loading... | |
305 gesture_handler_ && (gesture_handler_ != this); | 318 gesture_handler_ && (gesture_handler_ != this); |
306 gesture_handler_ = gesture_handler_->parent()) { | 319 gesture_handler_ = gesture_handler_->parent()) { |
307 if (!gesture_handler_->enabled()) { | 320 if (!gesture_handler_->enabled()) { |
308 // Disabled views eat events but are treated as not handled. | 321 // Disabled views eat events but are treated as not handled. |
309 return; | 322 return; |
310 } | 323 } |
311 | 324 |
312 // See if this view wants to handle the Gesture. | 325 // See if this view wants to handle the Gesture. |
313 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), | 326 ui::GestureEvent gesture_event(*event, static_cast<View*>(this), |
314 gesture_handler_); | 327 gesture_handler_); |
315 DispatchEventToTarget(gesture_handler_, &gesture_event); | 328 ui::EventDispatchDetails dispatch_details = |
329 DispatchEventToTarget(gesture_handler_, &gesture_event); | |
330 if (dispatch_details.dispatcher_destroyed) | |
331 return; | |
316 | 332 |
317 // The view could have removed itself from the tree when handling | 333 // The view could have removed itself from the tree when handling |
318 // OnGestureEvent(). So handle as per OnMousePressed. NB: we | 334 // OnGestureEvent(). So handle as per OnMousePressed. NB: we |
319 // assume that the RootView itself cannot be so removed. | 335 // assume that the RootView itself cannot be so removed. |
320 if (!gesture_handler_) | 336 if (!gesture_handler_) |
321 return; | 337 return; |
322 | 338 |
323 if (gesture_event.handled()) { | 339 if (gesture_event.handled()) { |
324 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | 340 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) |
325 scroll_gesture_handler_ = gesture_handler_; | 341 scroll_gesture_handler_ = gesture_handler_; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 UpdateCursor(event); | 428 UpdateCursor(event); |
413 SetMouseLocationAndFlags(event); | 429 SetMouseLocationAndFlags(event); |
414 | 430 |
415 // If mouse_pressed_handler_ is non null, we are currently processing | 431 // If mouse_pressed_handler_ is non null, we are currently processing |
416 // a pressed -> drag -> released session. In that case we send the | 432 // a pressed -> drag -> released session. In that case we send the |
417 // event to mouse_pressed_handler_ | 433 // event to mouse_pressed_handler_ |
418 if (mouse_pressed_handler_) { | 434 if (mouse_pressed_handler_) { |
419 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), | 435 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), |
420 mouse_pressed_handler_); | 436 mouse_pressed_handler_); |
421 drag_info_.Reset(); | 437 drag_info_.Reset(); |
422 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); | 438 ui::EventDispatchDetails dispatch_details = |
439 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); | |
440 if (dispatch_details.dispatcher_destroyed) | |
441 return true; | |
423 return true; | 442 return true; |
424 } | 443 } |
425 DCHECK(!explicit_mouse_handler_); | 444 DCHECK(!explicit_mouse_handler_); |
426 | 445 |
427 bool hit_disabled_view = false; | 446 bool hit_disabled_view = false; |
428 // Walk up the tree until we find a view that wants the mouse event. | 447 // Walk up the tree until we find a view that wants the mouse event. |
429 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location()); | 448 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location()); |
430 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); | 449 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); |
431 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) { | 450 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) { |
432 DVLOG(1) << "OnMousePressed testing " | 451 DVLOG(1) << "OnMousePressed testing " |
433 << mouse_pressed_handler_->GetClassName(); | 452 << mouse_pressed_handler_->GetClassName(); |
434 if (!mouse_pressed_handler_->enabled()) { | 453 if (!mouse_pressed_handler_->enabled()) { |
435 // Disabled views should eat events instead of propagating them upwards. | 454 // Disabled views should eat events instead of propagating them upwards. |
436 hit_disabled_view = true; | 455 hit_disabled_view = true; |
437 break; | 456 break; |
438 } | 457 } |
439 | 458 |
440 // See if this view wants to handle the mouse press. | 459 // See if this view wants to handle the mouse press. |
441 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), | 460 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), |
442 mouse_pressed_handler_); | 461 mouse_pressed_handler_); |
443 | 462 |
444 // Remove the double-click flag if the handler is different than the | 463 // Remove the double-click flag if the handler is different than the |
445 // one which got the first click part of the double-click. | 464 // one which got the first click part of the double-click. |
446 if (mouse_pressed_handler_ != last_click_handler_) | 465 if (mouse_pressed_handler_ != last_click_handler_) |
447 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); | 466 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); |
448 | 467 |
449 drag_info_.Reset(); | 468 drag_info_.Reset(); |
450 { | 469 ui::EventDispatchDetails dispatch_details = |
451 WidgetDeletionObserver widget_deletion_observer(widget_); | 470 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); |
452 DispatchEventToTarget(mouse_pressed_handler_, &mouse_pressed_event); | 471 if (dispatch_details.dispatcher_destroyed) |
453 if (!widget_deletion_observer.IsWidgetAlive()) | 472 return mouse_pressed_event.handled(); |
454 return mouse_pressed_event.handled(); | |
455 } | |
456 | 473 |
457 // The view could have removed itself from the tree when handling | 474 // The view could have removed itself from the tree when handling |
458 // OnMousePressed(). In this case, the removal notification will have | 475 // OnMousePressed(). In this case, the removal notification will have |
459 // reset mouse_pressed_handler_ to NULL out from under us. Detect this | 476 // reset mouse_pressed_handler_ to NULL out from under us. Detect this |
460 // case and stop. (See comments in view.h.) | 477 // case and stop. (See comments in view.h.) |
461 // | 478 // |
462 // NOTE: Don't return true here, because we don't want the frame to | 479 // NOTE: Don't return true here, because we don't want the frame to |
463 // forward future events to us when there's no handler. | 480 // forward future events to us when there's no handler. |
464 if (!mouse_pressed_handler_) | 481 if (!mouse_pressed_handler_) |
465 break; | 482 break; |
(...skipping 22 matching lines...) Expand all Loading... | |
488 last_click_handler_ = NULL; | 505 last_click_handler_ = NULL; |
489 return hit_disabled_view; | 506 return hit_disabled_view; |
490 } | 507 } |
491 | 508 |
492 bool RootView::OnMouseDragged(const ui::MouseEvent& event) { | 509 bool RootView::OnMouseDragged(const ui::MouseEvent& event) { |
493 if (mouse_pressed_handler_) { | 510 if (mouse_pressed_handler_) { |
494 SetMouseLocationAndFlags(event); | 511 SetMouseLocationAndFlags(event); |
495 | 512 |
496 ui::MouseEvent mouse_event(event, static_cast<View*>(this), | 513 ui::MouseEvent mouse_event(event, static_cast<View*>(this), |
497 mouse_pressed_handler_); | 514 mouse_pressed_handler_); |
498 DispatchEventToTarget(mouse_pressed_handler_, &mouse_event); | 515 ui::EventDispatchDetails dispatch_details = |
516 DispatchEventToTarget(mouse_pressed_handler_, &mouse_event); | |
517 if (dispatch_details.dispatcher_destroyed) | |
518 return false; | |
499 } | 519 } |
500 return false; | 520 return false; |
501 } | 521 } |
502 | 522 |
503 void RootView::OnMouseReleased(const ui::MouseEvent& event) { | 523 void RootView::OnMouseReleased(const ui::MouseEvent& event) { |
504 UpdateCursor(event); | 524 UpdateCursor(event); |
505 | 525 |
506 if (mouse_pressed_handler_) { | 526 if (mouse_pressed_handler_) { |
507 ui::MouseEvent mouse_released(event, static_cast<View*>(this), | 527 ui::MouseEvent mouse_released(event, static_cast<View*>(this), |
508 mouse_pressed_handler_); | 528 mouse_pressed_handler_); |
509 // We allow the view to delete us from the event dispatch callback. As such, | 529 // We allow the view to delete us from the event dispatch callback. As such, |
510 // configure state such that we're done first, then call View. | 530 // configure state such that we're done first, then call View. |
511 View* mouse_pressed_handler = mouse_pressed_handler_; | 531 View* mouse_pressed_handler = mouse_pressed_handler_; |
512 SetMouseHandler(NULL); | 532 SetMouseHandler(NULL); |
513 DispatchEventToTarget(mouse_pressed_handler, &mouse_released); | 533 ui::EventDispatchDetails dispatch_details = |
514 // WARNING: we may have been deleted. | 534 DispatchEventToTarget(mouse_pressed_handler, &mouse_released); |
535 if (dispatch_details.dispatcher_destroyed) | |
536 return; | |
515 } | 537 } |
516 } | 538 } |
517 | 539 |
518 void RootView::OnMouseCaptureLost() { | 540 void RootView::OnMouseCaptureLost() { |
519 // TODO: this likely needs to reset touch handler too. | 541 // TODO: this likely needs to reset touch handler too. |
520 | 542 |
521 if (mouse_pressed_handler_ || gesture_handler_) { | 543 if (mouse_pressed_handler_ || gesture_handler_) { |
522 // Synthesize a release event for UpdateCursor. | 544 // Synthesize a release event for UpdateCursor. |
523 if (mouse_pressed_handler_) { | 545 if (mouse_pressed_handler_) { |
524 gfx::Point last_point(last_mouse_event_x_, last_mouse_event_y_); | 546 gfx::Point last_point(last_mouse_event_x_, last_mouse_event_y_); |
(...skipping 23 matching lines...) Expand all Loading... | |
548 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED | 570 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED |
549 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. | 571 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. |
550 while (v && !v->enabled() && (v != mouse_move_handler_)) | 572 while (v && !v->enabled() && (v != mouse_move_handler_)) |
551 v = v->parent(); | 573 v = v->parent(); |
552 if (v && v != this) { | 574 if (v && v != this) { |
553 if (v != mouse_move_handler_) { | 575 if (v != mouse_move_handler_) { |
554 if (mouse_move_handler_ != NULL && | 576 if (mouse_move_handler_ != NULL && |
555 (!mouse_move_handler_->notify_enter_exit_on_child() || | 577 (!mouse_move_handler_->notify_enter_exit_on_child() || |
556 !mouse_move_handler_->Contains(v))) { | 578 !mouse_move_handler_->Contains(v))) { |
557 MouseEnterExitEvent exit(event, ui::ET_MOUSE_EXITED); | 579 MouseEnterExitEvent exit(event, ui::ET_MOUSE_EXITED); |
558 DispatchEventToTarget(mouse_move_handler_, &exit); | 580 ui::EventDispatchDetails dispatch_details = |
581 DispatchEventToTarget(mouse_move_handler_, &exit); | |
582 if (dispatch_details.dispatcher_destroyed) | |
583 return; | |
559 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | 584 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, |
560 mouse_move_handler_, v); | 585 mouse_move_handler_, v); |
561 } | 586 } |
562 View* old_handler = mouse_move_handler_; | 587 View* old_handler = mouse_move_handler_; |
563 mouse_move_handler_ = v; | 588 mouse_move_handler_ = v; |
564 if (!mouse_move_handler_->notify_enter_exit_on_child() || | 589 if (!mouse_move_handler_->notify_enter_exit_on_child() || |
565 !mouse_move_handler_->Contains(old_handler)) { | 590 !mouse_move_handler_->Contains(old_handler)) { |
566 MouseEnterExitEvent entered(event, ui::ET_MOUSE_ENTERED); | 591 MouseEnterExitEvent entered(event, ui::ET_MOUSE_ENTERED); |
567 entered.ConvertLocationToTarget(static_cast<View*>(this), | 592 entered.ConvertLocationToTarget(static_cast<View*>(this), |
568 mouse_move_handler_); | 593 mouse_move_handler_); |
569 DispatchEventToTarget(mouse_move_handler_, &entered); | 594 ui::EventDispatchDetails dispatch_details = |
595 DispatchEventToTarget(mouse_move_handler_, &entered); | |
596 if (dispatch_details.dispatcher_destroyed) | |
597 return; | |
570 NotifyEnterExitOfDescendant(entered, ui::ET_MOUSE_ENTERED, v, | 598 NotifyEnterExitOfDescendant(entered, ui::ET_MOUSE_ENTERED, v, |
571 old_handler); | 599 old_handler); |
572 } | 600 } |
573 } | 601 } |
574 ui::MouseEvent moved_event(event, static_cast<View*>(this), | 602 ui::MouseEvent moved_event(event, static_cast<View*>(this), |
575 mouse_move_handler_); | 603 mouse_move_handler_); |
576 mouse_move_handler_->OnMouseMoved(moved_event); | 604 mouse_move_handler_->OnMouseMoved(moved_event); |
577 if (!(moved_event.flags() & ui::EF_IS_NON_CLIENT)) | 605 if (!(moved_event.flags() & ui::EF_IS_NON_CLIENT)) |
578 widget_->SetCursor(mouse_move_handler_->GetCursor(moved_event)); | 606 widget_->SetCursor(mouse_move_handler_->GetCursor(moved_event)); |
579 } else if (mouse_move_handler_ != NULL) { | 607 } else if (mouse_move_handler_ != NULL) { |
580 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); | 608 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); |
581 DispatchEventToTarget(mouse_move_handler_, &exited); | 609 ui::EventDispatchDetails dispatch_details = |
610 DispatchEventToTarget(mouse_move_handler_, &exited); | |
611 if (dispatch_details.dispatcher_destroyed) | |
612 return; | |
582 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | 613 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, |
583 mouse_move_handler_, v); | 614 mouse_move_handler_, v); |
584 // On Aura the non-client area extends slightly outside the root view for | 615 // On Aura the non-client area extends slightly outside the root view for |
585 // some windows. Let the non-client cursor handling code set the cursor | 616 // some windows. Let the non-client cursor handling code set the cursor |
586 // as we do above. | 617 // as we do above. |
587 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | 618 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
588 widget_->SetCursor(gfx::kNullCursor); | 619 widget_->SetCursor(gfx::kNullCursor); |
589 mouse_move_handler_ = NULL; | 620 mouse_move_handler_ = NULL; |
590 } | 621 } |
591 } | 622 } |
592 | 623 |
593 void RootView::OnMouseExited(const ui::MouseEvent& event) { | 624 void RootView::OnMouseExited(const ui::MouseEvent& event) { |
594 if (mouse_move_handler_ != NULL) { | 625 if (mouse_move_handler_ != NULL) { |
595 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); | 626 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); |
596 DispatchEventToTarget(mouse_move_handler_, &exited); | 627 ui::EventDispatchDetails dispatch_details = |
628 DispatchEventToTarget(mouse_move_handler_, &exited); | |
629 if (dispatch_details.dispatcher_destroyed) | |
630 return; | |
597 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | 631 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, |
598 mouse_move_handler_, NULL); | 632 mouse_move_handler_, NULL); |
599 mouse_move_handler_ = NULL; | 633 mouse_move_handler_ = NULL; |
600 } | 634 } |
601 } | 635 } |
602 | 636 |
603 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 637 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
604 for (View* v = GetEventHandlerForPoint(event.location()); | 638 for (View* v = GetEventHandlerForPoint(event.location()); |
605 v && v != this && !event.handled(); v = v->parent()) | 639 v && v != this && !event.handled(); v = v->parent()) { |
606 DispatchEventToTarget(v, const_cast<ui::MouseWheelEvent*>(&event)); | 640 ui::EventDispatchDetails dispatch_details = |
641 DispatchEventToTarget(v, const_cast<ui::MouseWheelEvent*>(&event)); | |
642 if (dispatch_details.dispatcher_destroyed) | |
sadrul
2014/02/19 21:26:18
target_destroyed?
| |
643 return event.handled(); | |
644 } | |
607 return event.handled(); | 645 return event.handled(); |
608 } | 646 } |
609 | 647 |
610 void RootView::SetMouseHandler(View* new_mh) { | 648 void RootView::SetMouseHandler(View* new_mh) { |
611 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. | 649 // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. |
612 explicit_mouse_handler_ = (new_mh != NULL); | 650 explicit_mouse_handler_ = (new_mh != NULL); |
613 mouse_pressed_handler_ = new_mh; | 651 mouse_pressed_handler_ = new_mh; |
614 gesture_handler_ = new_mh; | 652 gesture_handler_ = new_mh; |
615 scroll_gesture_handler_ = new_mh; | 653 scroll_gesture_handler_ = new_mh; |
616 drag_info_.Reset(); | 654 drag_info_.Reset(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 widget_->SetCursor(v->GetCursor(me)); | 733 widget_->SetCursor(v->GetCursor(me)); |
696 } | 734 } |
697 } | 735 } |
698 | 736 |
699 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { | 737 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { |
700 last_mouse_event_flags_ = event.flags(); | 738 last_mouse_event_flags_ = event.flags(); |
701 last_mouse_event_x_ = event.x(); | 739 last_mouse_event_x_ = event.x(); |
702 last_mouse_event_y_ = event.y(); | 740 last_mouse_event_y_ = event.y(); |
703 } | 741 } |
704 | 742 |
705 void RootView::DispatchEventToTarget(View* target, ui::Event* event) { | 743 ui::EventDispatchDetails RootView::DispatchEventToTarget(View* target, |
744 ui::Event* event) { | |
706 View* old_target = event_dispatch_target_; | 745 View* old_target = event_dispatch_target_; |
707 event_dispatch_target_ = target; | 746 event_dispatch_target_ = target; |
708 ui::EventDispatchDetails details = DispatchEvent(target, event); | 747 ui::EventDispatchDetails details = DispatchEvent(target, event); |
709 if (!details.dispatcher_destroyed) | 748 if (!details.dispatcher_destroyed) |
710 event_dispatch_target_ = old_target; | 749 event_dispatch_target_ = old_target; |
750 return details; | |
711 } | 751 } |
712 | 752 |
713 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, | 753 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, |
714 ui::EventType type, | 754 ui::EventType type, |
715 View* view, | 755 View* view, |
716 View* sibling) { | 756 View* sibling) { |
717 for (View* p = view->parent(); p; p = p->parent()) { | 757 for (View* p = view->parent(); p; p = p->parent()) { |
718 if (!p->notify_enter_exit_on_child()) | 758 if (!p->notify_enter_exit_on_child()) |
719 continue; | 759 continue; |
720 if (sibling && p->Contains(sibling)) | 760 if (sibling && p->Contains(sibling)) |
721 break; | 761 break; |
722 // It is necessary to recreate the notify-event for each dispatch, since one | 762 // It is necessary to recreate the notify-event for each dispatch, since one |
723 // of the callbacks can mark the event as handled, and that would cause | 763 // of the callbacks can mark the event as handled, and that would cause |
724 // incorrect event dispatch. | 764 // incorrect event dispatch. |
725 MouseEnterExitEvent notify_event(event, type); | 765 MouseEnterExitEvent notify_event(event, type); |
726 DispatchEventToTarget(p, ¬ify_event); | 766 ui::EventDispatchDetails dispatch_details = |
767 DispatchEventToTarget(p, ¬ify_event); | |
768 if (dispatch_details.dispatcher_destroyed) | |
sadrul
2014/02/19 21:26:18
check target_destroyed here too?
| |
769 return; | |
727 } | 770 } |
728 } | 771 } |
729 | 772 |
730 | 773 |
731 void RootView::DispatchKeyEventStartAt(View* view, ui::KeyEvent* event) { | 774 void RootView::DispatchKeyEventStartAt(View* view, ui::KeyEvent* event) { |
732 if (event->handled() || !view) | 775 for (; view && view != this && !event->handled(); view = view->parent()) { |
733 return; | 776 ui::EventDispatchDetails dispatch_details = |
734 | 777 DispatchEventToTarget(view, event); |
735 for (; view && view != this; view = view->parent()) { | 778 if (dispatch_details.dispatcher_destroyed || |
736 DispatchEventToTarget(view, event); | 779 dispatch_details.target_destroyed) { |
737 // Do this check here rather than in the if as |view| may have been deleted. | |
738 if (event->handled()) | |
739 return; | 780 return; |
781 } | |
740 } | 782 } |
741 } | 783 } |
742 | 784 |
743 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { | 785 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { |
744 return event_dispatch_target_ == target; | 786 return event_dispatch_target_ == target; |
745 } | 787 } |
746 | 788 |
747 } // namespace internal | 789 } // namespace internal |
748 } // namespace views | 790 } // namespace views |
OLD | NEW |