painted_scrollbar_layer.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_LAYERS_PAINTED_SCROLLBAR_LAYER_H_
  5. #define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_
  6. #include <memory>
  7. #include "cc/cc_export.h"
  8. #include "cc/input/scrollbar.h"
  9. #include "cc/layers/layer.h"
  10. #include "cc/layers/scrollbar_layer_base.h"
  11. #include "cc/resources/scoped_ui_resource.h"
  12. namespace cc {
  13. // Generic scrollbar layer for cases not covered by PaintedOverlayScrollbarLayer
  14. // or SolidColorScrollbarLayer. This is not used for CSS-styled scrollbars. In
  15. // practice, this is used for overlay and non-overlay scrollbars on MacOS, as
  16. // well as non-overlay scrollbars on Win/Linux.
  17. class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase {
  18. public:
  19. std::unique_ptr<LayerImpl> CreateLayerImpl(
  20. LayerTreeImpl* tree_impl) const override;
  21. static scoped_refptr<PaintedScrollbarLayer> CreateOrReuse(
  22. scoped_refptr<Scrollbar> scrollbar,
  23. PaintedScrollbarLayer* existing_layer);
  24. static scoped_refptr<PaintedScrollbarLayer> Create(
  25. scoped_refptr<Scrollbar> scrollbar);
  26. PaintedScrollbarLayer(const PaintedScrollbarLayer&) = delete;
  27. PaintedScrollbarLayer& operator=(const PaintedScrollbarLayer&) = delete;
  28. bool OpacityCanAnimateOnImplThread() const override;
  29. bool Update() override;
  30. void SetLayerTreeHost(LayerTreeHost* host) override;
  31. void PushPropertiesTo(LayerImpl* layer,
  32. const CommitState& commit_state,
  33. const ThreadUnsafeCommitState& unsafe_state) override;
  34. const gfx::Size& internal_content_bounds() const {
  35. return internal_content_bounds_.Read(*this);
  36. }
  37. ScrollbarLayerType GetScrollbarLayerType() const override;
  38. protected:
  39. explicit PaintedScrollbarLayer(scoped_refptr<Scrollbar> scrollbar);
  40. ~PaintedScrollbarLayer() override;
  41. // For unit tests
  42. UIResourceId track_resource_id() {
  43. if (const auto* track_resource = track_resource_.Read(*this))
  44. return track_resource->id();
  45. return 0;
  46. }
  47. UIResourceId thumb_resource_id() {
  48. if (const auto* thumb_resource = thumb_resource_.Read(*this))
  49. return thumb_resource->id();
  50. return 0;
  51. }
  52. bool UpdateInternalContentScale();
  53. bool UpdateThumbAndTrackGeometry();
  54. private:
  55. gfx::Size LayerSizeToContentSize(const gfx::Size& layer_size) const;
  56. template <typename T>
  57. bool UpdateProperty(T value, T* prop) {
  58. if (*prop == value)
  59. return false;
  60. *prop = value;
  61. SetNeedsPushProperties();
  62. return true;
  63. }
  64. UIResourceBitmap RasterizeScrollbarPart(
  65. const gfx::Size& size,
  66. const gfx::Size& requested_content_size,
  67. ScrollbarPart part);
  68. ProtectedSequenceForbidden<scoped_refptr<Scrollbar>> scrollbar_;
  69. ProtectedSequenceReadable<ElementId> scroll_element_id_;
  70. ProtectedSequenceReadable<float> internal_contents_scale_;
  71. ProtectedSequenceReadable<gfx::Size> internal_content_bounds_;
  72. // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in
  73. // PushPropertiesTo.
  74. ProtectedSequenceReadable<gfx::Size> thumb_size_;
  75. ProtectedSequenceReadable<gfx::Rect> track_rect_;
  76. ProtectedSequenceReadable<gfx::Rect> back_button_rect_;
  77. ProtectedSequenceReadable<gfx::Rect> forward_button_rect_;
  78. ProtectedSequenceReadable<float> painted_opacity_;
  79. ProtectedSequenceReadable<bool> has_thumb_;
  80. ProtectedSequenceReadable<bool> jump_on_track_click_;
  81. const bool supports_drag_snap_back_;
  82. const bool is_overlay_;
  83. ProtectedSequenceReadable<std::unique_ptr<ScopedUIResource>> track_resource_;
  84. ProtectedSequenceReadable<std::unique_ptr<ScopedUIResource>> thumb_resource_;
  85. };
  86. } // namespace cc
  87. #endif // CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_