touch_calibrator_view.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #ifndef ASH_DISPLAY_TOUCH_CALIBRATOR_VIEW_H_
  5. #define ASH_DISPLAY_TOUCH_CALIBRATOR_VIEW_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "cc/paint/paint_flags.h"
  9. #include "ui/compositor/layer_animation_observer.h"
  10. #include "ui/display/display.h"
  11. #include "ui/gfx/animation/linear_animation.h"
  12. #include "ui/views/animation/animation_delegate_views.h"
  13. #include "ui/views/view.h"
  14. #include "ui/views/widget/unique_widget_ptr.h"
  15. namespace views {
  16. class Label;
  17. } // namespace views
  18. namespace gfx {
  19. class Animation;
  20. } // namespace gfx
  21. namespace ui {
  22. class LayerAnimationSequence;
  23. } // namespace ui
  24. namespace ash {
  25. class CircularThrobberView;
  26. class HintBox;
  27. // An overlay view used during touch calibration. This view is responsible for
  28. // all animations and UX during touch calibration on all displays currently
  29. // active on the device. The view on the display being calibrated is the primary
  30. // touch calibration view.
  31. // |TouchCalibratorView| acts as a state machine and has an API to toggle its
  32. // state or get the current state.
  33. class ASH_EXPORT TouchCalibratorView : public views::View,
  34. public views::AnimationDelegateViews,
  35. public ui::LayerAnimationObserver {
  36. public:
  37. // Different states of |TouchCalibratorView| in order.
  38. enum State {
  39. UNKNOWN = 0,
  40. BACKGROUND_FADING_IN, // Transition state where the background is fading
  41. // in.
  42. DISPLAY_POINT_1, // Static state where the touch point is at its first
  43. // location.
  44. ANIMATING_1_TO_2, // Transition state when the touch point is being moved
  45. // from one location to another.
  46. DISPLAY_POINT_2, // Static state where the touch point is at its second
  47. // location.
  48. ANIMATING_2_TO_3,
  49. DISPLAY_POINT_3, // Static state where the touch point is at its third
  50. // location.
  51. ANIMATING_3_TO_4,
  52. DISPLAY_POINT_4, // Static state where the touch point is at its final
  53. // location.
  54. ANIMATING_FINAL_MESSAGE, // Transition state when the calibration complete
  55. // message is being transitioned into view.
  56. CALIBRATION_COMPLETE, // Static state when the calibration complete message
  57. // is displayed to the user.
  58. BACKGROUND_FADING_OUT // Transition state where the background is fading
  59. // out
  60. };
  61. // Only use this function to construct. This ensures a Widget is properly
  62. // constructed and is set as the content view.
  63. static views::UniqueWidgetPtr Create(const display::Display& target_display,
  64. bool is_primary_view);
  65. ~TouchCalibratorView() override;
  66. // views::View:
  67. void OnPaint(gfx::Canvas* canvas) override;
  68. void OnPaintBackground(gfx::Canvas* canvas) override;
  69. // views::AnimationDelegateViews:
  70. void AnimationEnded(const gfx::Animation* animation) override;
  71. void AnimationProgressed(const gfx::Animation* animation) override;
  72. void AnimationCanceled(const gfx::Animation* animation) override;
  73. // ui::LayerAnimationObserver
  74. void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override;
  75. void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
  76. void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
  77. void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) override;
  78. // Moves the touch calibrator view to its next state.
  79. void AdvanceToNextState();
  80. // Skips to the final state. Should be used to cancel calibration and hide all
  81. // views from the screen with a smooth transition out animation.
  82. void SkipToFinalState();
  83. // Returns true if |location| is set by the end of this function call. If set,
  84. // |location| will point to the center of the circle that the user sees during
  85. // the touch calibration UX.
  86. bool GetDisplayPointLocation(gfx::Point* location);
  87. // Skips/cancels any ongoing animation to its end.
  88. void SkipCurrentAnimation();
  89. // Returns the current state of the view.
  90. State state() { return state_; }
  91. private:
  92. TouchCalibratorView(const display::Display& target_display,
  93. bool is_primary_view);
  94. TouchCalibratorView(const TouchCalibratorView&) = delete;
  95. TouchCalibratorView& operator=(const TouchCalibratorView&) = delete;
  96. void InitViewContents();
  97. // The target display on which this view is rendered on.
  98. const display::Display display_;
  99. // True if this view is on the display that is being calibrated.
  100. bool is_primary_view_;
  101. cc::PaintFlags flags_;
  102. // Defines the bounds for the background animation.
  103. gfx::RectF background_rect_;
  104. // Text label indicating how to exit the touch calibration.
  105. views::Label* exit_label_ = nullptr;
  106. // Text label indicating the significance of the touch point on screen.
  107. views::Label* tap_label_ = nullptr;
  108. // Start and end opacity values used during the fade animation. This is set
  109. // before the animation begins.
  110. float start_opacity_value_ = 0.0f;
  111. float end_opacity_value_ = 0.0f;
  112. // Linear animation used for various aniations including fade-in, fade out,
  113. // and view translation.
  114. std::unique_ptr<gfx::LinearAnimation> animator_;
  115. // View responsible for displaying the animated circular icon that the user
  116. // touches to calibrate the screen.
  117. CircularThrobberView* throbber_circle_ = nullptr;
  118. // A hint box displayed next to the first touch point to assist user with
  119. // information about the next step.
  120. HintBox* hint_box_view_ = nullptr;
  121. // Final view containing the calibration complete message along with an icon.
  122. views::View* completion_message_view_ = nullptr;
  123. // View that contains the animated throbber circle and a text label informing
  124. // the user to tap the circle to continue calibration.
  125. views::View* touch_point_view_ = nullptr;
  126. State state_ = UNKNOWN;
  127. };
  128. } // namespace ash
  129. #endif // ASH_DISPLAY_TOUCH_CALIBRATOR_VIEW_H_