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