| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ | 5 #ifndef CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ |
| 6 #define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ | 6 #define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ |
| 7 | 7 |
| 8 #include "cc/base/cc_export.h" | 8 #include "cc/base/cc_export.h" |
| 9 #include "cc/input/scrollbar.h" | 9 #include "cc/input/scrollbar.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/contents_scaling_layer.h" |
| 11 #include "cc/layers/scrollbar_layer_interface.h" | 11 #include "cc/layers/scrollbar_layer_interface.h" |
| 12 #include "cc/layers/scrollbar_theme_painter.h" | 12 #include "cc/layers/scrollbar_theme_painter.h" |
| 13 #include "cc/resources/layer_updater.h" | 13 #include "cc/resources/layer_updater.h" |
| 14 #include "cc/resources/scoped_ui_resource.h" | 14 #include "cc/resources/scoped_ui_resource.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 class ScrollbarThemeComposite; | 17 class ScrollbarThemeComposite; |
| 18 | 18 |
| 19 class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface, | 19 class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerInterface, |
| 20 public Layer { | 20 public ContentsScalingLayer { |
| 21 public: | 21 public: |
| 22 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; | 22 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; |
| 23 | 23 |
| 24 static scoped_refptr<PaintedScrollbarLayer> Create( | 24 static scoped_refptr<PaintedScrollbarLayer> Create( |
| 25 scoped_ptr<Scrollbar> scrollbar, | 25 scoped_ptr<Scrollbar> scrollbar, |
| 26 int scroll_layer_id); | 26 int scroll_layer_id); |
| 27 | 27 |
| 28 bool OpacityCanAnimateOnImplThread() const override; | 28 bool OpacityCanAnimateOnImplThread() const override; |
| 29 ScrollbarLayerInterface* ToScrollbarLayer() override; | 29 ScrollbarLayerInterface* ToScrollbarLayer() override; |
| 30 | 30 |
| 31 // ScrollbarLayerInterface | 31 // ScrollbarLayerInterface |
| 32 int ScrollLayerId() const override; | 32 int ScrollLayerId() const override; |
| 33 void SetScrollLayer(int layer_id) override; | 33 void SetScrollLayer(int layer_id) override; |
| 34 void SetClipLayer(int layer_id) override; | 34 void SetClipLayer(int layer_id) override; |
| 35 | 35 |
| 36 ScrollbarOrientation orientation() const override; | 36 ScrollbarOrientation orientation() const override; |
| 37 | 37 |
| 38 // Layer interface | 38 // Layer interface |
| 39 bool Update(ResourceUpdateQueue* queue, | 39 bool Update(ResourceUpdateQueue* queue, |
| 40 const OcclusionTracker<Layer>* occlusion) override; | 40 const OcclusionTracker<Layer>* occlusion) override; |
| 41 void SetLayerTreeHost(LayerTreeHost* host) override; | 41 void SetLayerTreeHost(LayerTreeHost* host) override; |
| 42 void PushPropertiesTo(LayerImpl* layer) override; | 42 void PushPropertiesTo(LayerImpl* layer) override; |
| 43 void PushScrollClipPropertiesTo(LayerImpl* layer) override; | 43 void PushScrollClipPropertiesTo(LayerImpl* layer) override; |
| 44 | 44 void CalculateContentsScale(float ideal_contents_scale, |
| 45 const gfx::Size& internal_content_bounds() const { | 45 float* contents_scale_x, |
| 46 return internal_content_bounds_; | 46 float* contents_scale_y, |
| 47 } | 47 gfx::Size* content_bounds) override; |
| 48 | 48 |
| 49 protected: | 49 protected: |
| 50 PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, int scroll_layer_id); | 50 PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, int scroll_layer_id); |
| 51 ~PaintedScrollbarLayer() override; | 51 ~PaintedScrollbarLayer() override; |
| 52 | 52 |
| 53 // For unit tests | 53 // For unit tests |
| 54 UIResourceId track_resource_id() { | 54 UIResourceId track_resource_id() { |
| 55 return track_resource_.get() ? track_resource_->id() : 0; | 55 return track_resource_.get() ? track_resource_->id() : 0; |
| 56 } | 56 } |
| 57 UIResourceId thumb_resource_id() { | 57 UIResourceId thumb_resource_id() { |
| 58 return thumb_resource_.get() ? thumb_resource_->id() : 0; | 58 return thumb_resource_.get() ? thumb_resource_->id() : 0; |
| 59 } | 59 } |
| 60 void UpdateInternalContentScale(); | |
| 61 void UpdateThumbAndTrackGeometry(); | 60 void UpdateThumbAndTrackGeometry(); |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 gfx::Rect ScrollbarLayerRectToContentRect(const gfx::Rect& layer_rect) const; | 63 gfx::Rect ScrollbarLayerRectToContentRect(const gfx::Rect& layer_rect) const; |
| 65 gfx::Rect OriginThumbRect() const; | 64 gfx::Rect OriginThumbRect() const; |
| 66 | 65 |
| 67 template <typename T> | 66 template<typename T> void UpdateProperty(T value, T* prop) { |
| 68 bool UpdateProperty(T value, T* prop) { | |
| 69 if (*prop == value) | 67 if (*prop == value) |
| 70 return false; | 68 return; |
| 71 *prop = value; | 69 *prop = value; |
| 72 SetNeedsPushProperties(); | 70 SetNeedsPushProperties(); |
| 73 return true; | |
| 74 } | 71 } |
| 75 | 72 |
| 76 int MaxTextureSize(); | 73 int MaxTextureSize(); |
| 77 float ClampScaleToMaxTextureSize(float scale); | 74 float ClampScaleToMaxTextureSize(float scale); |
| 78 | 75 |
| 79 UIResourceBitmap RasterizeScrollbarPart(const gfx::Rect& layer_rect, | 76 UIResourceBitmap RasterizeScrollbarPart(const gfx::Rect& layer_rect, |
| 80 const gfx::Rect& content_rect, | 77 const gfx::Rect& content_rect, |
| 81 ScrollbarPart part); | 78 ScrollbarPart part); |
| 82 | 79 |
| 83 scoped_ptr<Scrollbar> scrollbar_; | 80 scoped_ptr<Scrollbar> scrollbar_; |
| 84 int scroll_layer_id_; | 81 int scroll_layer_id_; |
| 85 int clip_layer_id_; | 82 int clip_layer_id_; |
| 86 | 83 |
| 87 float internal_contents_scale_; | |
| 88 gfx::Size internal_content_bounds_; | |
| 89 | |
| 90 // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in | 84 // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in |
| 91 // PushPropertiesTo. | 85 // PushPropertiesTo. |
| 92 int thumb_thickness_; | 86 int thumb_thickness_; |
| 93 int thumb_length_; | 87 int thumb_length_; |
| 94 gfx::Point location_; | 88 gfx::Point location_; |
| 95 gfx::Rect track_rect_; | 89 gfx::Rect track_rect_; |
| 96 bool is_overlay_; | 90 bool is_overlay_; |
| 97 bool has_thumb_; | 91 bool has_thumb_; |
| 98 | 92 |
| 99 scoped_ptr<ScopedUIResource> track_resource_; | 93 scoped_ptr<ScopedUIResource> track_resource_; |
| 100 scoped_ptr<ScopedUIResource> thumb_resource_; | 94 scoped_ptr<ScopedUIResource> thumb_resource_; |
| 101 | 95 |
| 102 DISALLOW_COPY_AND_ASSIGN(PaintedScrollbarLayer); | 96 DISALLOW_COPY_AND_ASSIGN(PaintedScrollbarLayer); |
| 103 }; | 97 }; |
| 104 | 98 |
| 105 } // namespace cc | 99 } // namespace cc |
| 106 | 100 |
| 107 #endif // CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ | 101 #endif // CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ |
| OLD | NEW |