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 3 // found in the LICENSE file. 4 5 #ifndef ASH_FAST_INK_FAST_INK_POINTS_H_ 6 #define ASH_FAST_INK_FAST_INK_POINTS_H_ 7 8 #include <memory> 9 10 #include "ash/ash_export.h" 11 #include "base/containers/circular_deque.h" 12 #include "base/macros.h" 13 #include "base/time/time.h" 14 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect_f.h" 16 17 namespace fast_ink { 18 19 // FastInkPoints is a helper class used for displaying low-latency palette 20 // tools. It contains a collection of points representing one or more 21 // contiguous trajectory segments. 22 class ASH_EXPORT FastInkPoints { 23 public: 24 // Struct to describe each point. 25 struct FastInkPoint { 26 gfx::PointF location; 27 base::TimeTicks time; 28 bool gap_after = false; // True when there is a gap after this point. 29 }; 30 31 // Constructor with a parameter to choose the fade out time of the points in 32 // the collection. Zero means no fadeout. 33 explicit FastInkPoints(base::TimeDelta life_duration); 34 ~FastInkPoints(); 35 36 // Adds a point. 37 void AddPoint(const gfx::PointF& point, const base::TimeTicks& time); 38 // Adds a gap after the most recent point. This is useful for multi-stroke 39 // gesture handling (e.g. strokes going over the bezel). 40 void AddGap(); 41 // Updates the collection latest time. Automatically clears points that are 42 // too old. 43 void MoveForwardToTime(const base::TimeTicks& latest_time); 44 // Removes all points. 45 void Clear(); 46 // Gets the bounding box of the points, int coordinates. 47 gfx::Rect GetBoundingBox() const; 48 // Gets the bounding box of the points, float coordinates. 49 gfx::RectF GetBoundingBoxF() const; 50 // Returns the oldest point in the collection. 51 FastInkPoint GetOldest() const; 52 // Returns the newest point in the collection. 53 FastInkPoint GetNewest() const; 54 // Returns the number of points in the collection. 55 int GetNumberOfPoints() const; 56 // Whether there are any points or not. 57 bool IsEmpty() const; 58 // Expose the collection so callers can work with the points. 59 const base::circular_deque<FastInkPoint>& points() const; 60 // Returns the fadeout factor for a point. This is a value between 0.0 and 61 // 1.0, where 0.0 corresponds to a recently added point, and 1.0 to a point 62 // that is about to expire. Do not call this method if |life_duration_| is 0. 63 float GetFadeoutFactor(int index) const; 64 // Fills the container with predicted points based on |real_points|. 65 void Predict(const FastInkPoints& real_points, 66 const base::TimeTicks& current_time, 67 base::TimeDelta prediction_duration, 68 const gfx::Size& screen_size); 69 70 private: 71 const base::TimeDelta life_duration_; 72 base::circular_deque<FastInkPoint> points_; 73 // The latest time of the collection of points. This gets updated when new 74 // points are added or when MoveForwardToTime is called. 75 base::TimeTicks collection_latest_time_; 76 77 DISALLOW_COPY_AND_ASSIGN(FastInkPoints); 78 }; 79 80 } // namespace fast_ink 81 82 #endif // ASH_FAST_INK_FAST_INK_POINTS_H_ 83