Chromium Code Reviews| 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 return status; | 445 return status; |
| 446 } | 446 } |
| 447 | 447 |
| 448 // Reset touch_pressed_handler_ to indicate that no processing is occurring. | 448 // Reset touch_pressed_handler_ to indicate that no processing is occurring. |
| 449 touch_pressed_handler_ = NULL; | 449 touch_pressed_handler_ = NULL; |
| 450 | 450 |
| 451 return status; | 451 return status; |
| 452 } | 452 } |
| 453 | 453 |
| 454 ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) { | 454 ui::GestureStatus RootView::OnGestureEvent(const GestureEvent& event) { |
| 455 GestureEvent e(event, this); | |
|
sadrul
2012/07/18 23:42:31
This creates an event to take RootView's transform
tdanderson
2012/07/25 23:08:57
Okay, I will put |e| back in for this CL.
| |
| 456 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; | 455 ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN; |
| 457 | 456 |
| 457 // TODO(tdanderson): Store radius values for a ui::ET_GESTURE_LONG_PRESS | |
| 458 // event so that fuzzing may also be used for a long press. | |
| 459 if (event.type() == ui::ET_GESTURE_TAP) { | |
| 460 float radius = event.details().radius_x(); | |
| 461 gfx::Point adjusted_loc(event.x() - radius, event.y() - radius); | |
| 462 ConvertPointToScreen(this, &adjusted_loc); | |
| 463 gfx::Rect touch_rect(adjusted_loc.x(), | |
| 464 adjusted_loc.y(), | |
| 465 radius * 2, | |
| 466 radius * 2); | |
| 467 | |
| 468 // If |new_gesture_handler| is not NULL, it should handle the tap event. | |
| 469 // Screen coordinates are used to eliminate the overhead of switching | |
| 470 // between parent/child coordinate systems in View::GetEventHandlerForRect. | |
| 471 View* new_gesture_handler = GetEventHandlerForRect(touch_rect); | |
| 472 if (new_gesture_handler) { | |
| 473 if (!gesture_handler_) | |
|
sadrul
2012/07/18 23:42:31
brace
tdanderson
2012/07/25 23:08:57
Done.
| |
| 474 gesture_handler_ = new_gesture_handler; | |
| 475 else if (gesture_handler_ != new_gesture_handler) { | |
| 476 // Send an ET_GESTURE_END event to the original handler | |
| 477 GestureEvent end_event(ui::ET_GESTURE_END, | |
| 478 event.x(), | |
| 479 event.y(), | |
| 480 event.flags()); | |
| 481 gesture_handler_->ProcessGestureEvent(end_event); | |
| 482 | |
| 483 // Send ET_GESTURE_BEGIN and ET_GESTURE_TAP_DOWN events to the new | |
| 484 // handler before processing the ET_GESTURE_TAP event. | |
| 485 gfx::Rect new_handler_bounds(new_gesture_handler->GetScreenBounds()); | |
| 486 gfx::Point new_center(new_handler_bounds.CenterPoint()); | |
| 487 ConvertPointFromScreen(this, &new_center); | |
| 488 GestureEvent begin_event(ui::ET_GESTURE_BEGIN, | |
|
tdanderson
2012/07/18 22:35:42
sadrul@: you mentioned that I should make sure the
sadrul
2012/07/18 23:42:31
Yes. You need to update GestureEvent::details_ to
tdanderson
2012/07/25 23:08:57
This will no longer be relevant in the next CL.
| |
| 489 new_center.x(), | |
| 490 new_center.y(), | |
| 491 event.flags()); | |
| 492 new_gesture_handler->ProcessGestureEvent(begin_event); | |
| 493 GestureEvent tap_down_event(ui::ET_GESTURE_TAP_DOWN, | |
| 494 new_center.x(), | |
| 495 new_center.y(), | |
| 496 event.flags()); | |
| 497 new_gesture_handler->ProcessGestureEvent(tap_down_event); | |
| 498 | |
| 499 gesture_handler_ = new_gesture_handler; | |
| 500 } | |
| 501 } | |
| 502 } | |
| 503 | |
| 458 if (gesture_handler_) { | 504 if (gesture_handler_) { |
| 459 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during | 505 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during |
| 460 // processing. | 506 // processing. |
| 461 View* handler = event.IsScrollGestureEvent() && scroll_gesture_handler_ ? | 507 View* handler = event.IsScrollGestureEvent() && scroll_gesture_handler_ ? |
| 462 scroll_gesture_handler_ : gesture_handler_; | 508 scroll_gesture_handler_ : gesture_handler_; |
| 463 GestureEvent handler_event(event, this, handler); | 509 GestureEvent handler_event(event, this, handler); |
| 464 | 510 |
| 465 ui::GestureStatus status = handler->ProcessGestureEvent(handler_event); | 511 ui::GestureStatus status = handler->ProcessGestureEvent(handler_event); |
| 466 | 512 |
| 467 if (event.type() == ui::ET_GESTURE_END && | 513 if (event.type() == ui::ET_GESTURE_END && |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 478 | 524 |
| 479 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN && | 525 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN && |
| 480 !scroll_gesture_handler_) { | 526 !scroll_gesture_handler_) { |
| 481 // Some view started processing gesture events, however it does not | 527 // Some view started processing gesture events, however it does not |
| 482 // process scroll-gesture events. In such case, we allow the event to | 528 // process scroll-gesture events. In such case, we allow the event to |
| 483 // bubble up, and install a different scroll-gesture handler different | 529 // bubble up, and install a different scroll-gesture handler different |
| 484 // from the default gesture handler. | 530 // from the default gesture handler. |
| 485 for (scroll_gesture_handler_ = gesture_handler_->parent(); | 531 for (scroll_gesture_handler_ = gesture_handler_->parent(); |
| 486 scroll_gesture_handler_ && scroll_gesture_handler_ != this; | 532 scroll_gesture_handler_ && scroll_gesture_handler_ != this; |
| 487 scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { | 533 scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { |
| 488 GestureEvent gesture_event(e, this, scroll_gesture_handler_); | 534 GestureEvent gesture_event(event, this, scroll_gesture_handler_); |
| 489 status = scroll_gesture_handler_->ProcessGestureEvent(gesture_event); | 535 status = scroll_gesture_handler_->ProcessGestureEvent(gesture_event); |
| 490 if (status == ui::GESTURE_STATUS_CONSUMED) | 536 if (status == ui::GESTURE_STATUS_CONSUMED) |
| 491 return status; | 537 return status; |
| 492 } | 538 } |
| 493 scroll_gesture_handler_ = NULL; | 539 scroll_gesture_handler_ = NULL; |
| 494 } | 540 } |
| 495 | 541 |
| 496 return ui::GESTURE_STATUS_UNKNOWN; | 542 return ui::GESTURE_STATUS_UNKNOWN; |
| 543 | |
|
sadrul
2012/07/18 23:42:31
-
tdanderson
2012/07/25 23:08:57
Done.
| |
| 497 } | 544 } |
| 498 | 545 |
| 499 // Walk up the tree until we find a view that wants the gesture event. | 546 // Walk up the tree until we find a view that wants the gesture event. |
| 500 for (gesture_handler_ = GetEventHandlerForPoint(e.location()); | 547 for (gesture_handler_ = GetEventHandlerForPoint(event.location()); |
| 501 gesture_handler_ && (gesture_handler_ != this); | 548 gesture_handler_ && (gesture_handler_ != this); |
| 502 gesture_handler_ = gesture_handler_->parent()) { | 549 gesture_handler_ = gesture_handler_->parent()) { |
| 503 if (!gesture_handler_->enabled()) { | 550 if (!gesture_handler_->enabled()) { |
| 504 // Disabled views eat events but are treated as not handled. | 551 // Disabled views eat events but are treated as not handled. |
| 505 return ui::GESTURE_STATUS_UNKNOWN; | 552 return ui::GESTURE_STATUS_UNKNOWN; |
| 506 } | 553 } |
| 507 | 554 |
| 508 // See if this view wants to handle the Gesture. | 555 // See if this view wants to handle the Gesture. |
| 509 GestureEvent gesture_event(e, this, gesture_handler_); | 556 GestureEvent gesture_event(event, this, gesture_handler_); |
| 510 status = gesture_handler_->ProcessGestureEvent(gesture_event); | 557 status = gesture_handler_->ProcessGestureEvent(gesture_event); |
| 511 | 558 |
| 512 // The view could have removed itself from the tree when handling | 559 // The view could have removed itself from the tree when handling |
| 513 // OnGestureEvent(). So handle as per OnMousePressed. NB: we | 560 // OnGestureEvent(). So handle as per OnMousePressed. NB: we |
| 514 // assume that the RootView itself cannot be so removed. | 561 // assume that the RootView itself cannot be so removed. |
| 515 if (!gesture_handler_) | 562 if (!gesture_handler_) |
| 516 return ui::GESTURE_STATUS_UNKNOWN; | 563 return ui::GESTURE_STATUS_UNKNOWN; |
| 517 | 564 |
| 518 if (status == ui::GESTURE_STATUS_CONSUMED) { | 565 if (status == ui::GESTURE_STATUS_CONSUMED) { |
| 519 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | 566 if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 } | 646 } |
| 600 | 647 |
| 601 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { | 648 void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { |
| 602 last_mouse_event_flags_ = event.flags(); | 649 last_mouse_event_flags_ = event.flags(); |
| 603 last_mouse_event_x_ = event.x(); | 650 last_mouse_event_x_ = event.x(); |
| 604 last_mouse_event_y_ = event.y(); | 651 last_mouse_event_y_ = event.y(); |
| 605 } | 652 } |
| 606 | 653 |
| 607 } // namespace internal | 654 } // namespace internal |
| 608 } // namespace views | 655 } // namespace views |
| OLD | NEW |