painted_scrollbar_layer.h revision 58537e28ecd584eab876aee8be7156509866d23a
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
16namespace cc {
17class ScrollbarThemeComposite;
18
19class 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 SetScrollLayerId(int id) OVERRIDE;
35
36  virtual ScrollbarOrientation orientation() const OVERRIDE;
37
38  // Layer interface
39  virtual bool Update(ResourceUpdateQueue* queue,
40                      const OcclusionTracker* occlusion) OVERRIDE;
41  virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE;
42  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
43  virtual void CalculateContentsScale(float ideal_contents_scale,
44                                      float device_scale_factor,
45                                      float page_scale_factor,
46                                      bool animating_transform_to_screen,
47                                      float* contents_scale_x,
48                                      float* contents_scale_y,
49                                      gfx::Size* content_bounds) OVERRIDE;
50
51 protected:
52  PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, int scroll_layer_id);
53  virtual ~PaintedScrollbarLayer();
54
55  // For unit tests
56  UIResourceId track_resource_id() {
57    return track_resource_.get() ? track_resource_->id() : 0;
58  }
59  UIResourceId thumb_resource_id() {
60    return thumb_resource_.get() ? thumb_resource_->id() : 0;
61  }
62  void UpdateThumbAndTrackGeometry();
63
64 private:
65  gfx::Rect ScrollbarLayerRectToContentRect(gfx::Rect layer_rect) const;
66  gfx::Rect OriginThumbRect() const;
67
68  int MaxTextureSize();
69  float ClampScaleToMaxTextureSize(float scale);
70
71  UIResourceBitmap RasterizeScrollbarPart(gfx::Rect rect,
72                                          ScrollbarPart part);
73
74  scoped_ptr<Scrollbar> scrollbar_;
75  int scroll_layer_id_;
76
77  // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in
78  // PushPropertiesTo.
79  int thumb_thickness_;
80  int thumb_length_;
81  gfx::Point location_;
82  gfx::Rect track_rect_;
83
84  scoped_ptr<ScopedUIResource> track_resource_;
85  scoped_ptr<ScopedUIResource> thumb_resource_;
86
87  DISALLOW_COPY_AND_ASSIGN(PaintedScrollbarLayer);
88};
89
90}  // namespace cc
91
92#endif  // CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_
93