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.h" | 10 #include "base/message_loop.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 371 } |
372 | 372 |
373 void RootView::OnMouseExited(const ui::MouseEvent& event) { | 373 void RootView::OnMouseExited(const ui::MouseEvent& event) { |
374 if (mouse_move_handler_ != NULL) { | 374 if (mouse_move_handler_ != NULL) { |
375 mouse_move_handler_->OnMouseExited(event); | 375 mouse_move_handler_->OnMouseExited(event); |
376 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, NULL); | 376 NotifyEnterExitOfDescendant(event, EVENT_EXIT, mouse_move_handler_, NULL); |
377 mouse_move_handler_ = NULL; | 377 mouse_move_handler_ = NULL; |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 bool RootView::OnMouseWheel(const MouseWheelEvent& event) { | 381 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
382 bool consumed = false; | 382 bool consumed = false; |
383 for (View* v = GetFocusManager()->GetFocusedView(); | 383 for (View* v = GetFocusManager()->GetFocusedView(); |
384 v && v != this && !consumed; v = v->parent()) | 384 v && v != this && !consumed; v = v->parent()) |
385 consumed = v->OnMouseWheel(event); | 385 consumed = v->OnMouseWheel(event); |
386 return consumed; | 386 return consumed; |
387 } | 387 } |
388 | 388 |
389 bool RootView::OnScrollEvent(const ScrollEvent& event) { | 389 bool RootView::OnScrollEvent(const ui::ScrollEvent& event) { |
390 bool consumed = false; | 390 bool consumed = false; |
391 for (View* v = GetEventHandlerForPoint(event.location()); | 391 for (View* v = GetEventHandlerForPoint(event.location()); |
392 v && v != this && !consumed; v = v->parent()) | 392 v && v != this && !consumed; v = v->parent()) |
393 consumed = v->OnScrollEvent(event); | 393 consumed = v->OnScrollEvent(event); |
394 return consumed; | 394 return consumed; |
395 } | 395 } |
396 | 396 |
397 ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) { | 397 ui::TouchStatus RootView::OnTouchEvent(const ui::TouchEvent& event) { |
398 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the | 398 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the |
399 // view and target that view with all touches with the same id until the | 399 // view and target that view with all touches with the same id until the |
400 // release (or keep it if captured). | 400 // release (or keep it if captured). |
401 | 401 |
402 // If touch_pressed_handler_ is non null, we are currently processing | 402 // If touch_pressed_handler_ is non null, we are currently processing |
403 // a touch down on the screen situation. In that case we send the | 403 // a touch down on the screen situation. In that case we send the |
404 // event to touch_pressed_handler_ | 404 // event to touch_pressed_handler_ |
405 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; | 405 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; |
406 | 406 |
407 if (touch_pressed_handler_) { | 407 if (touch_pressed_handler_) { |
408 TouchEvent touch_event(event, this, touch_pressed_handler_); | 408 ui::TouchEvent touch_event(event, static_cast<View*>(this), |
| 409 touch_pressed_handler_); |
409 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); | 410 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); |
410 if (status == ui::TOUCH_STATUS_END) | 411 if (status == ui::TOUCH_STATUS_END) |
411 touch_pressed_handler_ = NULL; | 412 touch_pressed_handler_ = NULL; |
412 return status; | 413 return status; |
413 } | 414 } |
414 | 415 |
415 // Walk up the tree until we find a view that wants the touch event. | 416 // Walk up the tree until we find a view that wants the touch event. |
416 for (touch_pressed_handler_ = GetEventHandlerForPoint(event.location()); | 417 for (touch_pressed_handler_ = GetEventHandlerForPoint(event.location()); |
417 touch_pressed_handler_ && (touch_pressed_handler_ != this); | 418 touch_pressed_handler_ && (touch_pressed_handler_ != this); |
418 touch_pressed_handler_ = touch_pressed_handler_->parent()) { | 419 touch_pressed_handler_ = touch_pressed_handler_->parent()) { |
419 if (!touch_pressed_handler_->enabled()) { | 420 if (!touch_pressed_handler_->enabled()) { |
420 // Disabled views eat events but are treated as not handled. | 421 // Disabled views eat events but are treated as not handled. |
421 status = ui::TOUCH_STATUS_UNKNOWN; | 422 status = ui::TOUCH_STATUS_UNKNOWN; |
422 break; | 423 break; |
423 } | 424 } |
424 | 425 |
425 // See if this view wants to handle the touch | 426 // See if this view wants to handle the touch |
426 TouchEvent touch_event(event, this, touch_pressed_handler_); | 427 ui::TouchEvent touch_event(event, static_cast<View*>(this), |
| 428 touch_pressed_handler_); |
427 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); | 429 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); |
428 | 430 |
429 // The view could have removed itself from the tree when handling | 431 // The view could have removed itself from the tree when handling |
430 // OnTouchEvent(). So handle as per OnMousePressed. NB: we | 432 // OnTouchEvent(). So handle as per OnMousePressed. NB: we |
431 // assume that the RootView itself cannot be so removed. | 433 // assume that the RootView itself cannot be so removed. |
432 if (!touch_pressed_handler_) | 434 if (!touch_pressed_handler_) |
433 break; | 435 break; |
434 | 436 |
435 // The touch event wasn't processed. Go up the view hierarchy and dispatch | 437 // The touch event wasn't processed. Go up the view hierarchy and dispatch |
436 // the touch event. | 438 // the touch event. |
437 if (status == ui::TOUCH_STATUS_UNKNOWN) | 439 if (status == ui::TOUCH_STATUS_UNKNOWN) |
438 continue; | 440 continue; |
439 | 441 |
440 // If the touch didn't initiate a touch-sequence, then reset the touch event | 442 // If the touch didn't initiate a touch-sequence, then reset the touch event |
441 // handler. Otherwise, leave it set so that subsequent touch events are | 443 // handler. Otherwise, leave it set so that subsequent touch events are |
442 // dispatched to the same handler. | 444 // dispatched to the same handler. |
443 if (status != ui::TOUCH_STATUS_START) | 445 if (status != ui::TOUCH_STATUS_START) |
444 touch_pressed_handler_ = NULL; | 446 touch_pressed_handler_ = NULL; |
445 | 447 |
446 return status; | 448 return status; |
447 } | 449 } |
448 | 450 |
449 // Reset touch_pressed_handler_ to indicate that no processing is occurring. | 451 // Reset touch_pressed_handler_ to indicate that no processing is occurring. |
450 touch_pressed_handler_ = NULL; | 452 touch_pressed_handler_ = NULL; |
451 | 453 |
452 return status; | 454 return status; |
453 } | 455 } |
454 | 456 |
455 ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) { | 457 ui::GestureStatus RootView::OnGestureEvent(const ui::GestureEvent& event) { |
456 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; | 458 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; |
457 | 459 |
458 if (gesture_handler_) { | 460 if (gesture_handler_) { |
459 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during | 461 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during |
460 // processing. | 462 // processing. |
461 View* handler = scroll_gesture_handler_ && | 463 View* handler = scroll_gesture_handler_ && |
462 (event.IsScrollGestureEvent() || event.IsFlingScrollEvent()) ? | 464 (event.IsScrollGestureEvent() || event.IsFlingScrollEvent()) ? |
463 scroll_gesture_handler_ : gesture_handler_; | 465 scroll_gesture_handler_ : gesture_handler_; |
464 GestureEvent handler_event(event, this, handler); | 466 ui::GestureEvent handler_event(event, static_cast<View*>(this), handler); |
465 | 467 |
466 ui::GestureStatus status = handler->ProcessGestureEvent(handler_event); | 468 ui::GestureStatus status = handler->ProcessGestureEvent(handler_event); |
467 | 469 |
468 if (event.type() == ui::ET_GESTURE_END && | 470 if (event.type() == ui::ET_GESTURE_END && |
469 event.details().touch_points() <= 1) | 471 event.details().touch_points() <= 1) |
470 gesture_handler_ = NULL; | 472 gesture_handler_ = NULL; |
471 | 473 |
472 if (scroll_gesture_handler_ && (event.type() == ui::ET_GESTURE_SCROLL_END || | 474 if (scroll_gesture_handler_ && (event.type() == ui::ET_GESTURE_SCROLL_END || |
473 event.type() == ui::ET_SCROLL_FLING_START)) | 475 event.type() == ui::ET_SCROLL_FLING_START)) |
474 scroll_gesture_handler_ = NULL; | 476 scroll_gesture_handler_ = NULL; |
475 | 477 |
476 if (status == ui::GESTURE_STATUS_CONSUMED) | 478 if (status == ui::GESTURE_STATUS_CONSUMED) |
477 return status; | 479 return status; |
478 | 480 |
479 DCHECK_EQ(ui::GESTURE_STATUS_UNKNOWN, status); | 481 DCHECK_EQ(ui::GESTURE_STATUS_UNKNOWN, status); |
480 | 482 |
481 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN && | 483 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN && |
482 !scroll_gesture_handler_) { | 484 !scroll_gesture_handler_) { |
483 // Some view started processing gesture events, however it does not | 485 // Some view started processing gesture events, however it does not |
484 // process scroll-gesture events. In such case, we allow the event to | 486 // process scroll-gesture events. In such case, we allow the event to |
485 // bubble up, and install a different scroll-gesture handler different | 487 // bubble up, and install a different scroll-gesture handler different |
486 // from the default gesture handler. | 488 // from the default gesture handler. |
487 for (scroll_gesture_handler_ = gesture_handler_->parent(); | 489 for (scroll_gesture_handler_ = gesture_handler_->parent(); |
488 scroll_gesture_handler_ && scroll_gesture_handler_ != this; | 490 scroll_gesture_handler_ && scroll_gesture_handler_ != this; |
489 scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { | 491 scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { |
490 GestureEvent gesture_event(event, this, scroll_gesture_handler_); | 492 ui::GestureEvent gesture_event(event, static_cast<View*>(this), |
| 493 scroll_gesture_handler_); |
491 status = scroll_gesture_handler_->ProcessGestureEvent(gesture_event); | 494 status = scroll_gesture_handler_->ProcessGestureEvent(gesture_event); |
492 if (status == ui::GESTURE_STATUS_CONSUMED) | 495 if (status == ui::GESTURE_STATUS_CONSUMED) |
493 return status; | 496 return status; |
494 } | 497 } |
495 scroll_gesture_handler_ = NULL; | 498 scroll_gesture_handler_ = NULL; |
496 } | 499 } |
497 | 500 |
498 return ui::GESTURE_STATUS_UNKNOWN; | 501 return ui::GESTURE_STATUS_UNKNOWN; |
499 } | 502 } |
500 | 503 |
501 // Walk up the tree until we find a view that wants the gesture event. | 504 // Walk up the tree until we find a view that wants the gesture event. |
502 for (gesture_handler_ = GetEventHandlerForPoint(event.location()); | 505 for (gesture_handler_ = GetEventHandlerForPoint(event.location()); |
503 gesture_handler_ && (gesture_handler_ != this); | 506 gesture_handler_ && (gesture_handler_ != this); |
504 gesture_handler_ = gesture_handler_->parent()) { | 507 gesture_handler_ = gesture_handler_->parent()) { |
505 if (!gesture_handler_->enabled()) { | 508 if (!gesture_handler_->enabled()) { |
506 // Disabled views eat events but are treated as not handled. | 509 // Disabled views eat events but are treated as not handled. |
507 return ui::GESTURE_STATUS_UNKNOWN; | 510 return ui::GESTURE_STATUS_UNKNOWN; |
508 } | 511 } |
509 | 512 |
510 // See if this view wants to handle the Gesture. | 513 // See if this view wants to handle the Gesture. |
511 GestureEvent gesture_event(event, this, gesture_handler_); | 514 ui::GestureEvent gesture_event(event, static_cast<View*>(this), |
| 515 gesture_handler_); |
512 status = gesture_handler_->ProcessGestureEvent(gesture_event); | 516 status = gesture_handler_->ProcessGestureEvent(gesture_event); |
513 | 517 |
514 // The view could have removed itself from the tree when handling | 518 // The view could have removed itself from the tree when handling |
515 // OnGestureEvent(). So handle as per OnMousePressed. NB: we | 519 // OnGestureEvent(). So handle as per OnMousePressed. NB: we |
516 // assume that the RootView itself cannot be so removed. | 520 // assume that the RootView itself cannot be so removed. |
517 if (!gesture_handler_) | 521 if (!gesture_handler_) |
518 return ui::GESTURE_STATUS_UNKNOWN; | 522 return ui::GESTURE_STATUS_UNKNOWN; |
519 | 523 |
520 if (status == ui::GESTURE_STATUS_CONSUMED) { | 524 if (status == ui::GESTURE_STATUS_CONSUMED) { |
521 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | 525 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 } | 606 } |
603 | 607 |
604 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { | 608 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { |
605 last_mouse_event_flags_ = event.flags(); | 609 last_mouse_event_flags_ = event.flags(); |
606 last_mouse_event_x_ = event.x(); | 610 last_mouse_event_x_ = event.x(); |
607 last_mouse_event_y_ = event.y(); | 611 last_mouse_event_y_ = event.y(); |
608 } | 612 } |
609 | 613 |
610 } // namespace internal | 614 } // namespace internal |
611 } // namespace views | 615 } // namespace views |
OLD | NEW |