edge_effect.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2014 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 UI_ANDROID_EDGE_EFFECT_H_
  5. #define UI_ANDROID_EDGE_EFFECT_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "base/time/time.h"
  9. #include "ui/android/ui_android_export.h"
  10. #include "ui/gfx/geometry/rect_f.h"
  11. #include "ui/gfx/geometry/size.h"
  12. #include "ui/gfx/geometry/size_f.h"
  13. #include "ui/gfx/geometry/transform.h"
  14. namespace cc {
  15. class Layer;
  16. class UIResourceLayer;
  17. }
  18. namespace ui {
  19. class ResourceManager;
  20. }
  21. namespace ui {
  22. // A base class for overscroll-related Android effects.
  23. class UI_ANDROID_EXPORT EdgeEffect {
  24. public:
  25. enum State {
  26. STATE_IDLE = 0,
  27. STATE_PULL,
  28. STATE_ABSORB,
  29. STATE_RECEDE,
  30. STATE_PULL_DECAY
  31. };
  32. enum Edge { EDGE_TOP, EDGE_LEFT, EDGE_BOTTOM, EDGE_RIGHT, EDGE_COUNT };
  33. explicit EdgeEffect(ui::ResourceManager* resource_manager);
  34. EdgeEffect(const EdgeEffect&) = delete;
  35. EdgeEffect& operator=(const EdgeEffect&) = delete;
  36. ~EdgeEffect();
  37. void Pull(base::TimeTicks current_time,
  38. float delta_distance,
  39. float displacement);
  40. void Absorb(base::TimeTicks current_time, float velocity);
  41. bool Update(base::TimeTicks current_time);
  42. void Release(base::TimeTicks current_time);
  43. void Finish();
  44. bool IsFinished() const;
  45. float GetAlpha() const;
  46. void ApplyToLayers(Edge edge, const gfx::SizeF& viewport_size, float offset);
  47. void SetParent(cc::Layer* parent);
  48. private:
  49. const raw_ptr<ui::ResourceManager> resource_manager_;
  50. scoped_refptr<cc::UIResourceLayer> glow_;
  51. float glow_alpha_;
  52. float glow_scale_y_;
  53. float glow_alpha_start_;
  54. float glow_alpha_finish_;
  55. float glow_scale_y_start_;
  56. float glow_scale_y_finish_;
  57. gfx::RectF arc_rect_;
  58. gfx::Size bounds_;
  59. float displacement_;
  60. float target_displacement_;
  61. base::TimeTicks start_time_;
  62. base::TimeDelta duration_;
  63. State state_;
  64. float pull_distance_;
  65. };
  66. } // namespace ui
  67. #endif // UI_ANDROID_EDGE_EFFECT_H_