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 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 } | 578 } |
579 } | 579 } |
580 return gestures.release(); | 580 return gestures.release(); |
581 } | 581 } |
582 | 582 |
583 void GestureSequence::RecreateBoundingBox() { | 583 void GestureSequence::RecreateBoundingBox() { |
584 // TODO(sad): Recreating the bounding box at every touch-event is not very | 584 // TODO(sad): Recreating the bounding box at every touch-event is not very |
585 // efficient. This should be made better. | 585 // efficient. This should be made better. |
586 if (point_count_ == 1) { | 586 if (point_count_ == 1) { |
587 bounding_box_ = GetPointByPointId(0)->enclosing_rectangle(); | 587 bounding_box_ = GetPointByPointId(0)->enclosing_rectangle(); |
588 } else { | 588 } else { |
sadrul
2012/11/12 01:28:02
You can set bounding_box_ to empty when point_coun
danakj
2012/11/12 05:45:56
Done.
| |
589 int left = INT_MAX / 20, top = INT_MAX / 20; | 589 int left = INT_MAX / 20, top = INT_MAX / 20; |
590 int right = INT_MIN / 20, bottom = INT_MIN / 20; | 590 int right = INT_MIN / 20, bottom = INT_MIN / 20; |
591 bool empty_box = true; | |
591 for (int i = 0; i < kMaxGesturePoints; ++i) { | 592 for (int i = 0; i < kMaxGesturePoints; ++i) { |
592 if (!points_[i].in_use()) | 593 if (!points_[i].in_use()) |
593 continue; | 594 continue; |
594 // Using the |enclosing_rectangle()| for the touch-points would be ideal. | 595 // Using the |enclosing_rectangle()| for the touch-points would be ideal. |
595 // However, this becomes brittle especially when a finger is in motion | 596 // However, this becomes brittle especially when a finger is in motion |
596 // because the change in radius can overshadow the actual change in | 597 // because the change in radius can overshadow the actual change in |
597 // position. So the actual position of the point is used instead. | 598 // position. So the actual position of the point is used instead. |
598 const gfx::Point& point = points_[i].last_touch_position(); | 599 const gfx::Point& point = points_[i].last_touch_position(); |
599 left = std::min(left, point.x()); | 600 left = std::min(left, point.x()); |
600 right = std::max(right, point.x()); | 601 right = std::max(right, point.x()); |
601 top = std::min(top, point.y()); | 602 top = std::min(top, point.y()); |
602 bottom = std::max(bottom, point.y()); | 603 bottom = std::max(bottom, point.y()); |
604 empty_box = false; | |
603 } | 605 } |
604 bounding_box_.SetRect(left, top, right - left, bottom - top); | 606 if (empty_box) |
607 bounding_box_.SetRect(0, 0, 0, 0); | |
608 else | |
609 bounding_box_.SetRect(left, top, right - left, bottom - top); | |
605 } | 610 } |
606 } | 611 } |
607 | 612 |
608 void GestureSequence::ResetVelocities() { | 613 void GestureSequence::ResetVelocities() { |
609 for (int i = 0; i < kMaxGesturePoints; ++i) { | 614 for (int i = 0; i < kMaxGesturePoints; ++i) { |
610 if (points_[i].in_use()) | 615 if (points_[i].in_use()) |
611 points_[i].ResetVelocity(); | 616 points_[i].ResetVelocity(); |
612 } | 617 } |
613 } | 618 } |
614 | 619 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 return; | 1176 return; |
1172 | 1177 |
1173 // Since long press timer has been started, there should be a non-NULL point. | 1178 // Since long press timer has been started, there should be a non-NULL point. |
1174 const GesturePoint* point = GetPointByPointId(0); | 1179 const GesturePoint* point = GetPointByPointId(0); |
1175 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), | 1180 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), |
1176 event.location())) | 1181 event.location())) |
1177 GetLongPressTimer()->Stop(); | 1182 GetLongPressTimer()->Stop(); |
1178 } | 1183 } |
1179 | 1184 |
1180 } // namespace ui | 1185 } // namespace ui |
OLD | NEW |