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