scrollbar.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2013 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 CC_INPUT_SCROLLBAR_H_
  5. #define CC_INPUT_SCROLLBAR_H_
  6. #include "base/memory/ref_counted.h"
  7. #include "cc/cc_export.h"
  8. #include "cc/paint/paint_canvas.h"
  9. #include "ui/gfx/geometry/point.h"
  10. #include "ui/gfx/geometry/rect.h"
  11. // Autoscrolling (on the main thread) happens by applying a delta every 50ms.
  12. // Hence, pixels per second for a autoscroll cc animation can be calculated as:
  13. // autoscroll velocity = delta / 0.05 sec = delta x 20
  14. static constexpr float kAutoscrollMultiplier = 20.f;
  15. static constexpr base::TimeDelta kInitialAutoscrollTimerDelay =
  16. base::Milliseconds(250);
  17. // Constants used to figure the how far out in the non-scrolling direction
  18. // should trigger the thumb to snap back to its origin. These calculations are
  19. // based on observing the behavior of the MSVC8 main window scrollbar + some
  20. // guessing/extrapolation.
  21. static constexpr int kOffSideMultiplier = 8;
  22. static constexpr int kDefaultWinScrollbarThickness = 17;
  23. namespace cc {
  24. enum class ScrollbarOrientation { HORIZONTAL, VERTICAL };
  25. enum class ScrollbarPart {
  26. THUMB,
  27. TRACK_BUTTONS_TICKMARKS, // for PartNeedsRepaint() and PaintPart() only.
  28. BACK_BUTTON,
  29. FORWARD_BUTTON,
  30. BACK_TRACK,
  31. FORWARD_TRACK,
  32. NO_PART,
  33. };
  34. class Scrollbar : public base::RefCounted<Scrollbar> {
  35. public:
  36. // Check if this scrollbar and the other scrollbar are backed with the same
  37. // source scrollbar (e.g. blink::Scrollbar).
  38. virtual bool IsSame(const Scrollbar&) const = 0;
  39. virtual ScrollbarOrientation Orientation() const = 0;
  40. virtual bool IsLeftSideVerticalScrollbar() const = 0;
  41. virtual bool IsSolidColor() const = 0;
  42. virtual bool IsOverlay() const = 0;
  43. virtual bool HasThumb() const = 0;
  44. virtual bool SupportsDragSnapBack() const = 0;
  45. virtual bool JumpOnTrackClick() const = 0;
  46. // The following rects are all relative to the scrollbar's origin.
  47. // The location of ThumbRect reflects scroll offset, but cc will ignore it
  48. // because the compositor thread will compute thumb location from scroll
  49. // offset.
  50. virtual gfx::Rect ThumbRect() const = 0;
  51. virtual gfx::Rect TrackRect() const = 0;
  52. virtual gfx::Rect BackButtonRect() const = 0;
  53. virtual gfx::Rect ForwardButtonRect() const = 0;
  54. virtual float Opacity() const = 0;
  55. virtual bool HasTickmarks() const = 0;
  56. // Whether we need to repaint the part. Only THUMB and TRACK_BUTTONS_TICKMARKS
  57. // are supported.
  58. virtual bool NeedsRepaintPart(ScrollbarPart part) const = 0;
  59. // Paints the part in the given rect. The implementation should paint
  60. // relative to the rect, and doesn't need to know the current coordinate
  61. // space of |canvas|. Only THUMB, TRACK_BUTTONS_TICKMARKS are supported.
  62. virtual void PaintPart(PaintCanvas* canvas,
  63. ScrollbarPart part,
  64. const gfx::Rect& rect) = 0;
  65. virtual bool UsesNinePatchThumbResource() const = 0;
  66. virtual gfx::Size NinePatchThumbCanvasSize() const = 0;
  67. virtual gfx::Rect NinePatchThumbAperture() const = 0;
  68. protected:
  69. friend class base::RefCounted<Scrollbar>;
  70. virtual ~Scrollbar() {}
  71. };
  72. } // namespace cc
  73. #endif // CC_INPUT_SCROLLBAR_H_