Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: ash/laser/laser_pointer_points.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 namespace ash { 10 namespace ash {
11 11
12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) 12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
13 : life_duration_(life_duration) {} 13 : life_duration_(life_duration) {}
14 14
15 LaserPointerPoints::~LaserPointerPoints() {} 15 LaserPointerPoints::~LaserPointerPoints() {}
16 16
17 void LaserPointerPoints::AddPoint(const gfx::Point& point) { 17 void LaserPointerPoints::AddPoint(const gfx::Point& point) {
18 base::Time current_time = base::Time::Now();
19 // If the collection is empty, set the latest time to the time of the first
20 // added point.
21 if (IsEmpty())
22 collection_latest_time_ = current_time;
jdufault 2016/09/23 23:59:19 We should always be updating collection_latest_tim
sammiequon 2016/09/26 19:30:38 Done.
18 LaserPoint new_point; 23 LaserPoint new_point;
19 new_point.location = point; 24 new_point.location = point;
20 new_point.creation_time = base::Time::Now(); 25 new_point.creation_time = current_time;
21 points_.push_back(new_point); 26 points_.push_back(new_point);
27 MoveForwardInTime(current_time);
28 }
29
30 void LaserPointerPoints::MoveForwardInTime() {
31 collection_latest_time_ = base::Time::Now();
jdufault 2016/09/23 23:59:19 Call MoveFowardInTime(base::Time::Now())
sammiequon 2016/09/26 19:30:38 Done.
22 ClearOldPoints(); 32 ClearOldPoints();
23 } 33 }
24 34
35 void LaserPointerPoints::MoveForwardInTime(const base::Time& new_latest_time) {
jdufault 2016/09/23 23:59:19 Rename one of the MoveForwardInTime methods so the
sammiequon 2016/09/26 19:30:38 Done.
36 collection_latest_time_ = new_latest_time;
37 ClearOldPoints();
38 }
39
25 void LaserPointerPoints::Clear() { 40 void LaserPointerPoints::Clear() {
26 points_.clear(); 41 points_.clear();
27 } 42 }
28 43
29 gfx::Rect LaserPointerPoints::GetBoundingBox() { 44 gfx::Rect LaserPointerPoints::GetBoundingBox() {
30 if (IsEmpty()) 45 if (IsEmpty())
31 return gfx::Rect(); 46 return gfx::Rect();
32 47
33 gfx::Point min_point = GetOldest().location; 48 gfx::Point min_point = GetOldest().location;
34 gfx::Point max_point = GetOldest().location; 49 gfx::Point max_point = GetOldest().location;
35 for (const LaserPoint& point : points_) { 50 for (const LaserPoint& point : points_) {
36 min_point.SetToMin(point.location); 51 min_point.SetToMin(point.location);
37 max_point.SetToMax(point.location); 52 max_point.SetToMax(point.location);
38 } 53 }
39 return gfx::BoundingRect(min_point, max_point); 54 return gfx::BoundingRect(min_point, max_point);
40 } 55 }
41 56
42 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const { 57 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const {
43 DCHECK(!IsEmpty()); 58 DCHECK(!IsEmpty());
44 return points_.front(); 59 return points_.front();
45 } 60 }
46 61
47 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { 62 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const {
48 DCHECK(!IsEmpty()); 63 DCHECK(!IsEmpty());
49 return points_.back(); 64 return points_.back();
50 } 65 }
51 66
67 base::Time LaserPointerPoints::GetCollectionLatestTime() const {
68 return collection_latest_time_;
69 }
70
71 base::Time LaserPointerPoints::GetCollectionEarliestTime() const {
72 return collection_latest_time_ - life_duration_;
73 }
74
52 bool LaserPointerPoints::IsEmpty() const { 75 bool LaserPointerPoints::IsEmpty() const {
53 return points_.empty(); 76 return points_.empty();
54 } 77 }
55 78
56 int LaserPointerPoints::GetNumberOfPoints() const { 79 int LaserPointerPoints::GetNumberOfPoints() const {
57 return points_.size(); 80 return points_.size();
58 } 81 }
59 82
60 const std::deque<LaserPointerPoints::LaserPoint>& 83 const std::deque<LaserPointerPoints::LaserPoint>&
61 LaserPointerPoints::laser_points() { 84 LaserPointerPoints::laser_points() {
62 return points_; 85 return points_;
63 } 86 }
64 87
65 void LaserPointerPoints::ClearOldPoints() { 88 void LaserPointerPoints::ClearOldPoints() {
66 DCHECK(!IsEmpty()); 89 if (IsEmpty())
jdufault 2016/09/23 23:59:19 Why do we need this if?
sammiequon 2016/09/26 19:30:38 Done.
90 return;
91
67 auto first_alive_point = 92 auto first_alive_point =
68 std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) { 93 std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) {
69 return GetNewest().creation_time - p.creation_time < life_duration_; 94 return collection_latest_time_ - p.creation_time < life_duration_;
70 }); 95 });
71 points_.erase(points_.begin(), first_alive_point); 96 points_.erase(points_.begin(), first_alive_point);
72 } 97 }
73 98
74 } // namespace ash 99 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698