painted_overlay_scrollbar_layer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 CC_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_H_
  5. #define CC_LAYERS_PAINTED_OVERLAY_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. // For composited overlay scrollbars with nine-patch thumb. For overlay
  14. // scrollbars whose thumb is not nine-patch, use PaintedScrollbarLayer or
  15. // SolidColorScrollbarLayer. In practice, this is used for non-custom
  16. // overlay scrollbars on Win/Linux.
  17. class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase {
  18. public:
  19. std::unique_ptr<LayerImpl> CreateLayerImpl(
  20. LayerTreeImpl* tree_impl) const override;
  21. static scoped_refptr<PaintedOverlayScrollbarLayer> CreateOrReuse(
  22. scoped_refptr<Scrollbar> scrollbar,
  23. PaintedOverlayScrollbarLayer* existing_layer);
  24. static scoped_refptr<PaintedOverlayScrollbarLayer> Create(
  25. scoped_refptr<Scrollbar> scrollbar);
  26. PaintedOverlayScrollbarLayer(const PaintedOverlayScrollbarLayer&) = delete;
  27. PaintedOverlayScrollbarLayer& operator=(const PaintedOverlayScrollbarLayer&) =
  28. delete;
  29. bool OpacityCanAnimateOnImplThread() const override;
  30. bool Update() override;
  31. void SetLayerTreeHost(LayerTreeHost* host) override;
  32. void PushPropertiesTo(LayerImpl* layer,
  33. const CommitState& commit_state,
  34. const ThreadUnsafeCommitState& unsafe_state) override;
  35. ScrollbarLayerType GetScrollbarLayerType() const override;
  36. protected:
  37. explicit PaintedOverlayScrollbarLayer(scoped_refptr<Scrollbar> scrollbar);
  38. ~PaintedOverlayScrollbarLayer() override;
  39. private:
  40. template <typename T>
  41. bool UpdateProperty(const T value, T* prop) {
  42. if (*prop == value)
  43. return false;
  44. *prop = value;
  45. SetNeedsPushProperties();
  46. return true;
  47. }
  48. bool PaintThumbIfNeeded();
  49. bool PaintTickmarks();
  50. ProtectedSequenceForbidden<scoped_refptr<Scrollbar>> scrollbar_;
  51. ProtectedSequenceReadable<gfx::Size> thumb_size_;
  52. ProtectedSequenceReadable<gfx::Rect> track_rect_;
  53. ProtectedSequenceReadable<gfx::Rect> aperture_;
  54. ProtectedSequenceReadable<std::unique_ptr<ScopedUIResource>> thumb_resource_;
  55. ProtectedSequenceReadable<std::unique_ptr<ScopedUIResource>> track_resource_;
  56. };
  57. } // namespace cc
  58. #endif // CC_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_H_