| 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/base/gestures/gesture_sequence.h" | 5 #include "ui/base/gestures/gesture_sequence.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 point_count_ = 0; | 486 point_count_ = 0; |
| 487 } | 487 } |
| 488 | 488 |
| 489 void GestureSequence::RecreateBoundingBox() { | 489 void GestureSequence::RecreateBoundingBox() { |
| 490 // TODO(sad): Recreating the bounding box at every touch-event is not very | 490 // TODO(sad): Recreating the bounding box at every touch-event is not very |
| 491 // efficient. This should be made better. | 491 // efficient. This should be made better. |
| 492 int left = INT_MAX, top = INT_MAX, right = INT_MIN, bottom = INT_MIN; | 492 int left = INT_MAX, top = INT_MAX, right = INT_MIN, bottom = INT_MIN; |
| 493 for (int i = 0; i < kMaxGesturePoints; ++i) { | 493 for (int i = 0; i < kMaxGesturePoints; ++i) { |
| 494 if (!points_[i].in_use()) | 494 if (!points_[i].in_use()) |
| 495 continue; | 495 continue; |
| 496 if (left > points_[i].x()) | 496 gfx::Rect rect = points_[i].enclosing_rectangle(); |
| 497 left = points_[i].x(); | 497 if (left > rect.x()) |
| 498 if (right < points_[i].x()) | 498 left = rect.x(); |
| 499 right = points_[i].x(); | 499 if (right < rect.right()) |
| 500 if (top > points_[i].y()) | 500 right = rect.right(); |
| 501 top = points_[i].y(); | 501 if (top > rect.y()) |
| 502 if (bottom < points_[i].y()) | 502 top = rect.y(); |
| 503 bottom = points_[i].y(); | 503 if (bottom < rect.bottom()) |
| 504 bottom = rect.bottom(); |
| 504 } | 505 } |
| 505 bounding_box_last_center_ = bounding_box_.CenterPoint(); | 506 bounding_box_last_center_ = bounding_box_.CenterPoint(); |
| 506 bounding_box_.SetRect(left, top, right - left, bottom - top); | 507 bounding_box_.SetRect(left, top, right - left, bottom - top); |
| 507 } | 508 } |
| 508 | 509 |
| 509 void GestureSequence::ResetVelocities() { | 510 void GestureSequence::ResetVelocities() { |
| 510 for (int i = 0; i < kMaxGesturePoints; ++i) { | 511 for (int i = 0; i < kMaxGesturePoints; ++i) { |
| 511 if (points_[i].in_use()) | 512 if (points_[i].in_use()) |
| 512 points_[i].ResetVelocity(); | 513 points_[i].ResetVelocity(); |
| 513 } | 514 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 553 } |
| 553 | 554 |
| 554 GestureEvent* GestureSequence::CreateGestureEvent( | 555 GestureEvent* GestureSequence::CreateGestureEvent( |
| 555 const GestureEventDetails& details, | 556 const GestureEventDetails& details, |
| 556 const gfx::Point& location, | 557 const gfx::Point& location, |
| 557 int flags, | 558 int flags, |
| 558 base::Time timestamp, | 559 base::Time timestamp, |
| 559 unsigned int touch_id_bitmask) { | 560 unsigned int touch_id_bitmask) { |
| 560 GestureEventDetails gesture_details(details); | 561 GestureEventDetails gesture_details(details); |
| 561 gesture_details.set_touch_points(point_count_); | 562 gesture_details.set_touch_points(point_count_); |
| 563 gesture_details.set_bounding_box(bounding_box_); |
| 562 return helper_->CreateGestureEvent(gesture_details, location, flags, | 564 return helper_->CreateGestureEvent(gesture_details, location, flags, |
| 563 timestamp, touch_id_bitmask); | 565 timestamp, touch_id_bitmask); |
| 564 } | 566 } |
| 565 | 567 |
| 566 void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point, | 568 void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point, |
| 567 Gestures* gestures) { | 569 Gestures* gestures) { |
| 568 gestures->push_back(CreateGestureEvent( | 570 gestures->push_back(CreateGestureEvent( |
| 569 GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0), | 571 GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0), |
| 570 point.first_touch_position(), | 572 point.first_touch_position(), |
| 571 flags_, | 573 flags_, |
| 572 base::Time::FromDoubleT(point.last_touch_time()), | 574 base::Time::FromDoubleT(point.last_touch_time()), |
| 573 1 << point.touch_id())); | 575 1 << point.touch_id())); |
| 574 } | 576 } |
| 575 | 577 |
| 576 void GestureSequence::AppendBeginGestureEvent(const GesturePoint& point, | 578 void GestureSequence::AppendBeginGestureEvent(const GesturePoint& point, |
| 577 Gestures* gestures) { | 579 Gestures* gestures) { |
| 578 gestures->push_back(CreateGestureEvent( | 580 gestures->push_back(CreateGestureEvent( |
| 579 GestureEventDetails(ui::ET_GESTURE_BEGIN, point_count_, 0), | 581 GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), |
| 580 point.first_touch_position(), | 582 point.first_touch_position(), |
| 581 flags_, | 583 flags_, |
| 582 base::Time::FromDoubleT(point.last_touch_time()), | 584 base::Time::FromDoubleT(point.last_touch_time()), |
| 583 1 << point.touch_id())); | 585 1 << point.touch_id())); |
| 584 } | 586 } |
| 585 | 587 |
| 586 void GestureSequence::AppendEndGestureEvent(const GesturePoint& point, | 588 void GestureSequence::AppendEndGestureEvent(const GesturePoint& point, |
| 587 Gestures* gestures) { | 589 Gestures* gestures) { |
| 588 gestures->push_back(CreateGestureEvent( | 590 gestures->push_back(CreateGestureEvent( |
| 589 GestureEventDetails(ui::ET_GESTURE_END, point_count_, 0), | 591 GestureEventDetails(ui::ET_GESTURE_END, 0, 0), |
| 590 point.first_touch_position(), | 592 point.first_touch_position(), |
| 591 flags_, | 593 flags_, |
| 592 base::Time::FromDoubleT(point.last_touch_time()), | 594 base::Time::FromDoubleT(point.last_touch_time()), |
| 593 1 << point.touch_id())); | 595 1 << point.touch_id())); |
| 594 } | 596 } |
| 595 | 597 |
| 596 void GestureSequence::AppendClickGestureEvent(const GesturePoint& point, | 598 void GestureSequence::AppendClickGestureEvent(const GesturePoint& point, |
| 597 Gestures* gestures) { | 599 Gestures* gestures) { |
| 598 gfx::Rect er = point.enclosing_rectangle(); | 600 gfx::Rect er = point.enclosing_rectangle(); |
| 599 gfx::Point center = er.CenterPoint(); | 601 gfx::Point center = er.CenterPoint(); |
| 600 gestures->push_back(CreateGestureEvent( | 602 gestures->push_back(CreateGestureEvent( |
| 601 GestureEventDetails(ui::ET_GESTURE_TAP, er.width() / 2, er.height() / 2), | 603 GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0), |
| 602 center, | 604 center, |
| 603 flags_, | 605 flags_, |
| 604 base::Time::FromDoubleT(point.last_touch_time()), | 606 base::Time::FromDoubleT(point.last_touch_time()), |
| 605 1 << point.touch_id())); | 607 1 << point.touch_id())); |
| 606 } | 608 } |
| 607 | 609 |
| 608 void GestureSequence::AppendDoubleClickGestureEvent(const GesturePoint& point, | 610 void GestureSequence::AppendDoubleClickGestureEvent(const GesturePoint& point, |
| 609 Gestures* gestures) { | 611 Gestures* gestures) { |
| 610 gestures->push_back(CreateGestureEvent( | 612 gestures->push_back(CreateGestureEvent( |
| 611 GestureEventDetails(ui::ET_GESTURE_DOUBLE_TAP, 0, 0), | 613 GestureEventDetails(ui::ET_GESTURE_DOUBLE_TAP, 0, 0), |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 return; | 1009 return; |
| 1008 | 1010 |
| 1009 // Since long press timer has been started, there should be a non-NULL point. | 1011 // Since long press timer has been started, there should be a non-NULL point. |
| 1010 const GesturePoint* point = GetPointByPointId(0); | 1012 const GesturePoint* point = GetPointByPointId(0); |
| 1011 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), | 1013 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), |
| 1012 event.GetLocation())) | 1014 event.GetLocation())) |
| 1013 long_press_timer_->Stop(); | 1015 long_press_timer_->Stop(); |
| 1014 } | 1016 } |
| 1015 | 1017 |
| 1016 } // namespace ui | 1018 } // namespace ui |
| OLD | NEW |