highlighter_view.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2017 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. #ifndef ASH_HIGHLIGHTER_HIGHLIGHTER_VIEW_H_
  5. #define ASH_HIGHLIGHTER_HIGHLIGHTER_VIEW_H_
  6. #include <vector>
  7. #include "ash/fast_ink/fast_ink_points.h"
  8. #include "ash/fast_ink/fast_ink_view.h"
  9. #include "base/time/time.h"
  10. #include "ui/views/widget/unique_widget_ptr.h"
  11. namespace aura {
  12. class Window;
  13. }
  14. namespace base {
  15. class OneShotTimer;
  16. }
  17. namespace gfx {
  18. class PointF;
  19. }
  20. namespace ash {
  21. enum class HighlighterGestureType;
  22. // HighlighterView displays the highlighter palette tool. It draws the
  23. // highlighter stroke which consists of a series of thick lines connecting
  24. // touch points.
  25. class HighlighterView : public fast_ink::FastInkView {
  26. public:
  27. static const gfx::SizeF kPenTipSize;
  28. HighlighterView(const HighlighterView&) = delete;
  29. HighlighterView& operator=(const HighlighterView&) = delete;
  30. ~HighlighterView() override;
  31. // Function to create a container Widget, initialize |highlighter_view| and
  32. // pass ownership as the contents view to the Widget.
  33. static views::UniqueWidgetPtr Create(const base::TimeDelta presentation_delay,
  34. aura::Window* container);
  35. const fast_ink::FastInkPoints& points() const { return points_; }
  36. bool animating() const { return animation_timer_.get(); }
  37. void ChangeColor(SkColor color);
  38. void AddNewPoint(const gfx::PointF& new_point, const base::TimeTicks& time);
  39. void AddGap();
  40. void Animate(const gfx::PointF& pivot,
  41. HighlighterGestureType gesture_type,
  42. base::OnceClosure done);
  43. // Deletes the last stroke.
  44. void UndoLastStroke();
  45. private:
  46. friend class HighlighterControllerTestApi;
  47. friend class MarkerControllerTestApi;
  48. explicit HighlighterView(const base::TimeDelta presentation_delay);
  49. void FadeOut(const gfx::PointF& pivot,
  50. HighlighterGestureType gesture_type,
  51. base::OnceClosure done);
  52. void ScheduleUpdateBuffer();
  53. void UpdateBuffer();
  54. void Draw(gfx::Canvas& canvas);
  55. fast_ink::FastInkPoints points_;
  56. fast_ink::FastInkPoints predicted_points_;
  57. const base::TimeDelta presentation_delay_;
  58. std::unique_ptr<base::OneShotTimer> animation_timer_;
  59. gfx::Rect highlighter_damage_rect_;
  60. bool pending_update_buffer_ = false;
  61. SkColor pen_color_ = fast_ink::FastInkPoints::kDefaultColor;
  62. base::WeakPtrFactory<HighlighterView> weak_ptr_factory_{this};
  63. };
  64. } // namespace ash
  65. #endif // ASH_HIGHLIGHTER_HIGHLIGHTER_VIEW_H_