autoclick_scroll_position_handler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 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_ACCESSIBILITY_AUTOCLICK_AUTOCLICK_SCROLL_POSITION_HANDLER_H_
  5. #define ASH_ACCESSIBILITY_AUTOCLICK_AUTOCLICK_SCROLL_POSITION_HANDLER_H_
  6. #include <memory>
  7. #include "base/time/time.h"
  8. #include "base/timer/timer.h"
  9. #include "ui/gfx/animation/animation_delegate.h"
  10. #include "ui/gfx/animation/linear_animation.h"
  11. #include "ui/gfx/native_widget_types.h"
  12. namespace gfx {
  13. class Point;
  14. } // namespace gfx
  15. namespace views {
  16. class Widget;
  17. } // namespace views
  18. namespace ash {
  19. // AutoclickScrollPositionHandler displays the position at which the next scroll
  20. // event will occur, giving users a sense of which part of the screen will
  21. // receive scroll events. It will display at full opacity for a short time, then
  22. // partially fade out to keep from blocking content.
  23. class AutoclickScrollPositionHandler : public gfx::AnimationDelegate {
  24. public:
  25. explicit AutoclickScrollPositionHandler(
  26. std::unique_ptr<views::Widget> widget);
  27. AutoclickScrollPositionHandler(const AutoclickScrollPositionHandler&) =
  28. delete;
  29. AutoclickScrollPositionHandler& operator=(
  30. const AutoclickScrollPositionHandler&) = delete;
  31. ~AutoclickScrollPositionHandler() override;
  32. gfx::NativeView GetNativeView();
  33. void SetScrollPointCenterInScreen(const gfx::Point& scroll_point_center);
  34. private:
  35. static constexpr auto kOpaqueTime = base::Milliseconds(500);
  36. static constexpr auto kFadeTime = base::Milliseconds(500);
  37. // gfx::AnimationDelegate:
  38. void AnimationProgressed(const gfx::Animation* animation) override;
  39. std::unique_ptr<views::Widget> widget_;
  40. // Animation that fades the scroll indicator from full to partial opacity.
  41. gfx::LinearAnimation animation_{
  42. kFadeTime, gfx::LinearAnimation::kDefaultFrameRate, this};
  43. // Timer that keeps the indicator at full opacity briefly after updating.
  44. base::DelayTimer timer_;
  45. };
  46. } // namespace ash
  47. #endif // ASH_ACCESSIBILITY_AUTOCLICK_AUTOCLICK_SCROLL_POSITION_HANDLER_H_