| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/laser/laser_pointer_points.h" | 5 #include "ash/laser/laser_pointer_points.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "ui/gfx/geometry/rect_conversions.h" |
| 11 |
| 10 namespace ash { | 12 namespace ash { |
| 11 | 13 |
| 12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) | 14 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) |
| 13 : life_duration_(life_duration) {} | 15 : life_duration_(life_duration) {} |
| 14 | 16 |
| 15 LaserPointerPoints::~LaserPointerPoints() {} | 17 LaserPointerPoints::~LaserPointerPoints() {} |
| 16 | 18 |
| 17 void LaserPointerPoints::AddPoint(const gfx::Point& point) { | 19 void LaserPointerPoints::AddPoint(const gfx::PointF& point) { |
| 18 MoveForwardToTime(base::Time::Now()); | 20 MoveForwardToTime(base::Time::Now()); |
| 19 | 21 |
| 20 LaserPoint new_point; | 22 LaserPoint new_point; |
| 21 new_point.location = point; | 23 new_point.location = point; |
| 22 points_.push_back(new_point); | 24 points_.push_back(new_point); |
| 23 } | 25 } |
| 24 | 26 |
| 25 void LaserPointerPoints::MoveForwardToTime(const base::Time& latest_time) { | 27 void LaserPointerPoints::MoveForwardToTime(const base::Time& latest_time) { |
| 26 if (!points_.empty()) { | 28 if (!points_.empty()) { |
| 27 DCHECK(!collection_latest_time_.is_null()); | 29 DCHECK(!collection_latest_time_.is_null()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 } | 45 } |
| 44 | 46 |
| 45 void LaserPointerPoints::Clear() { | 47 void LaserPointerPoints::Clear() { |
| 46 points_.clear(); | 48 points_.clear(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 gfx::Rect LaserPointerPoints::GetBoundingBox() { | 51 gfx::Rect LaserPointerPoints::GetBoundingBox() { |
| 50 if (IsEmpty()) | 52 if (IsEmpty()) |
| 51 return gfx::Rect(); | 53 return gfx::Rect(); |
| 52 | 54 |
| 53 gfx::Point min_point = GetOldest().location; | 55 gfx::PointF min_point = GetOldest().location; |
| 54 gfx::Point max_point = GetOldest().location; | 56 gfx::PointF max_point = GetOldest().location; |
| 55 for (const LaserPoint& point : points_) { | 57 for (const LaserPoint& point : points_) { |
| 56 min_point.SetToMin(point.location); | 58 min_point.SetToMin(point.location); |
| 57 max_point.SetToMax(point.location); | 59 max_point.SetToMax(point.location); |
| 58 } | 60 } |
| 59 return gfx::BoundingRect(min_point, max_point); | 61 return gfx::ToEnclosingRect(gfx::BoundingRect(min_point, max_point)); |
| 60 } | 62 } |
| 61 | 63 |
| 62 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const { | 64 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const { |
| 63 DCHECK(!IsEmpty()); | 65 DCHECK(!IsEmpty()); |
| 64 return points_.front(); | 66 return points_.front(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { | 69 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { |
| 68 DCHECK(!IsEmpty()); | 70 DCHECK(!IsEmpty()); |
| 69 return points_.back(); | 71 return points_.back(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool LaserPointerPoints::IsEmpty() const { | 74 bool LaserPointerPoints::IsEmpty() const { |
| 73 return points_.empty(); | 75 return points_.empty(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 int LaserPointerPoints::GetNumberOfPoints() const { | 78 int LaserPointerPoints::GetNumberOfPoints() const { |
| 77 return points_.size(); | 79 return points_.size(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 const std::deque<LaserPointerPoints::LaserPoint>& | 82 const std::deque<LaserPointerPoints::LaserPoint>& |
| 81 LaserPointerPoints::laser_points() { | 83 LaserPointerPoints::laser_points() { |
| 82 return points_; | 84 return points_; |
| 83 } | 85 } |
| 84 } // namespace ash | 86 } // namespace ash |
| OLD | NEW |