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