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

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

Issue 2745953002: ash: Add basic prediction code to the laser pointer. (Closed)
Patch Set: more tests and nits Created 3 years, 9 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
« no previous file with comments | « ash/laser/laser_pointer_controller_unittest.cc ('k') | ash/laser/laser_pointer_points.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef ASH_LASER_LASER_POINTER_POINTS_H_ 5 #ifndef ASH_LASER_LASER_POINTER_POINTS_H_
6 #define ASH_LASER_LASER_POINTER_POINTS_H_ 6 #define ASH_LASER_LASER_POINTER_POINTS_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <memory> 9 #include <memory>
10 10
11 #include "ash/ash_export.h" 11 #include "ash/ash_export.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "ui/gfx/geometry/point_f.h" 14 #include "ui/gfx/geometry/point_f.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 16
17 namespace ash { 17 namespace ash {
18 18
19 // LaserPointerPoints is a helper class used for displaying the palette tool 19 // LaserPointerPoints is a helper class used for displaying the palette tool
20 // laser pointer. It keeps track of the points needed to render the laser 20 // laser pointer. It keeps track of the points needed to render the laser
21 // pointer and its tail. 21 // pointer and its tail.
22 class ASH_EXPORT LaserPointerPoints { 22 class ASH_EXPORT LaserPointerPoints {
23 public: 23 public:
24 // Struct to describe each point. 24 // Struct to describe each point.
25 struct LaserPoint { 25 struct LaserPoint {
26 gfx::PointF location; 26 gfx::PointF location;
27 base::TimeTicks time;
27 // age is a value between [0,1] where 0 means the point was just added and 1 28 // age is a value between [0,1] where 0 means the point was just added and 1
28 // means that the point is just about to be removed. 29 // means that the point is just about to be removed.
29 float age = 0.0f; 30 float age = 0.0f;
30 }; 31 };
31 32
32 // Constructor with a parameter to choose the fade out time of the points in 33 // Constructor with a parameter to choose the fade out time of the points in
33 // the collection. 34 // the collection.
34 explicit LaserPointerPoints(base::TimeDelta life_duration); 35 explicit LaserPointerPoints(base::TimeDelta life_duration);
35 ~LaserPointerPoints(); 36 ~LaserPointerPoints();
36 37
37 // Adds a point. Automatically clears points that are too old. 38 // Adds a point. Automatically clears points that are too old.
38 void AddPoint(const gfx::PointF& point); 39 void AddPoint(const gfx::PointF& point, const base::TimeTicks& time);
39 // Updates the collection latest time. Automatically clears points that are 40 // Updates the collection latest time. Automatically clears points that are
40 // too old. 41 // too old.
41 void MoveForwardToTime(const base::Time& latest_time); 42 void MoveForwardToTime(const base::TimeTicks& latest_time);
42 // Removes all points. 43 // Removes all points.
43 void Clear(); 44 void Clear();
44 // Gets the bounding box of the points. 45 // Gets the bounding box of the points.
45 gfx::Rect GetBoundingBox(); 46 gfx::Rect GetBoundingBox();
46 // Returns the oldest point in the collection. 47 // Returns the oldest point in the collection.
47 LaserPoint GetOldest() const; 48 LaserPoint GetOldest() const;
48 // Returns the newest point in the collection. 49 // Returns the newest point in the collection.
49 LaserPoint GetNewest() const; 50 LaserPoint GetNewest() const;
50 // Returns the number of points in the collection. 51 // Returns the number of points in the collection.
51 int GetNumberOfPoints() const; 52 int GetNumberOfPoints() const;
52 // Whether there are any points or not. 53 // Whether there are any points or not.
53 bool IsEmpty() const; 54 bool IsEmpty() const;
54 // Expose the collection so callers can work with the points. 55 // Expose the collection so callers can work with the points.
55 const std::deque<LaserPoint>& laser_points(); 56 const std::deque<LaserPoint>& laser_points() const;
56 57
57 private: 58 private:
58 friend class LaserPointerPointsTestApi; 59 friend class LaserPointerPointsTestApi;
59 60
60 base::TimeDelta life_duration_; 61 base::TimeDelta life_duration_;
61 std::deque<LaserPoint> points_; 62 std::deque<LaserPoint> points_;
62 // The latest time of the collection of points. This gets updated when new 63 // The latest time of the collection of points. This gets updated when new
63 // points are added or when MoveForwardInTime is called. 64 // points are added or when MoveForwardInTime is called.
64 base::Time collection_latest_time_; 65 base::TimeTicks collection_latest_time_;
65 66
66 DISALLOW_COPY_AND_ASSIGN(LaserPointerPoints); 67 DISALLOW_COPY_AND_ASSIGN(LaserPointerPoints);
67 }; 68 };
68 69
69 } // namespace ash 70 } // namespace ash
70 71
71 #endif // ASH_LASER_LASER_POINTER_POINTS_H_ 72 #endif // ASH_LASER_LASER_POINTER_POINTS_H_
OLDNEW
« no previous file with comments | « ash/laser/laser_pointer_controller_unittest.cc ('k') | ash/laser/laser_pointer_points.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698