Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / layers / painted_scrollbar_layer.h
blob3e376b1959e5b238da074a523b324b0b9fe0afa1
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.
5 #ifndef CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_
6 #define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_
8 #include "cc/base/cc_export.h"
9 #include "cc/input/scrollbar.h"
10 #include "cc/layers/layer.h"
11 #include "cc/layers/scrollbar_layer_interface.h"
12 #include "cc/layers/scrollbar_theme_painter.h"
13 #include "cc/resources/scoped_ui_resource.h"
15 namespace cc {
16 class ScrollbarThemeComposite;
18 class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface,
19 public Layer {
20 public:
21 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
23 static scoped_refptr<PaintedScrollbarLayer> Create(
24 const LayerSettings& settings,
25 scoped_ptr<Scrollbar> scrollbar,
26 int scroll_layer_id);
28 bool OpacityCanAnimateOnImplThread() const override;
29 ScrollbarLayerInterface* ToScrollbarLayer() override;
31 // ScrollbarLayerInterface
32 int ScrollLayerId() const override;
33 void SetScrollLayer(int layer_id) override;
34 void SetClipLayer(int layer_id) override;
36 ScrollbarOrientation orientation() const override;
38 // Layer interface
39 bool Update() override;
40 void SetLayerTreeHost(LayerTreeHost* host) override;
41 void PushPropertiesTo(LayerImpl* layer) override;
42 void PushScrollClipPropertiesTo(LayerImpl* layer) override;
44 const gfx::Size& internal_content_bounds() const {
45 return internal_content_bounds_;
48 protected:
49 PaintedScrollbarLayer(const LayerSettings& settings,
50 scoped_ptr<Scrollbar> scrollbar,
51 int scroll_layer_id);
52 ~PaintedScrollbarLayer() override;
54 // For unit tests
55 UIResourceId track_resource_id() {
56 return track_resource_.get() ? track_resource_->id() : 0;
58 UIResourceId thumb_resource_id() {
59 return thumb_resource_.get() ? thumb_resource_->id() : 0;
61 void UpdateInternalContentScale();
62 void UpdateThumbAndTrackGeometry();
64 private:
65 gfx::Rect ScrollbarLayerRectToContentRect(const gfx::Rect& layer_rect) const;
66 gfx::Rect OriginThumbRect() const;
68 template <typename T>
69 bool UpdateProperty(T value, T* prop) {
70 if (*prop == value)
71 return false;
72 *prop = value;
73 SetNeedsPushProperties();
74 return true;
77 int MaxTextureSize();
78 float ClampScaleToMaxTextureSize(float scale);
80 UIResourceBitmap RasterizeScrollbarPart(const gfx::Rect& layer_rect,
81 const gfx::Rect& content_rect,
82 ScrollbarPart part);
84 scoped_ptr<Scrollbar> scrollbar_;
85 int scroll_layer_id_;
86 int clip_layer_id_;
88 float internal_contents_scale_;
89 gfx::Size internal_content_bounds_;
91 // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in
92 // PushPropertiesTo.
93 int thumb_thickness_;
94 int thumb_length_;
95 gfx::Point location_;
96 gfx::Rect track_rect_;
97 bool is_overlay_;
98 bool has_thumb_;
100 scoped_ptr<ScopedUIResource> track_resource_;
101 scoped_ptr<ScopedUIResource> thumb_resource_;
103 DISALLOW_COPY_AND_ASSIGN(PaintedScrollbarLayer);
106 } // namespace cc
108 #endif // CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_