summaryrefslogtreecommitdiffstats
path: root/cc/layers/scrollbar_layer.h
blob: 7920964b013e173f64cc09451b78ed489a1311d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_LAYERS_SCROLLBAR_LAYER_H_
#define CC_LAYERS_SCROLLBAR_LAYER_H_

#include "cc/base/cc_export.h"
#include "cc/layers/contents_scaling_layer.h"
#include "cc/layers/scrollbar_theme_painter.h"
#include "cc/resources/layer_updater.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGeometry.h"

namespace cc {
class CachingBitmapContentLayerUpdater;
class ResourceUpdateQueue;
class Scrollbar;
class ScrollbarThemeComposite;

class CC_EXPORT ScrollbarLayer : public ContentsScalingLayer {
 public:
  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
      OVERRIDE;

  static scoped_refptr<ScrollbarLayer> Create(
      scoped_ptr<WebKit::WebScrollbar> scrollbar,
      scoped_ptr<ScrollbarThemePainter> painter,
      scoped_ptr<WebKit::WebScrollbarThemeGeometry> geometry,
      int scroll_layer_id);

  int scroll_layer_id() const { return scroll_layer_id_; }
  void SetScrollLayerId(int id);

  virtual bool OpacityCanAnimateOnImplThread() const OVERRIDE;

  WebKit::WebScrollbar::Orientation Orientation() const;

  // Layer interface
  virtual void SetTexturePriorities(const PriorityCalculator& priority_calc)
      OVERRIDE;
  virtual void Update(ResourceUpdateQueue* queue,
                      const OcclusionTracker* occlusion) OVERRIDE;
  virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE;
  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
  virtual void CalculateContentsScale(float ideal_contents_scale,
                                      bool animating_transform_to_screen,
                                      float* contents_scale_x,
                                      float* contents_scale_y,
                                      gfx::Size* content_bounds) OVERRIDE;

  virtual ScrollbarLayer* ToScrollbarLayer() OVERRIDE;

 protected:
  ScrollbarLayer(
      scoped_ptr<WebKit::WebScrollbar> scrollbar,
      scoped_ptr<ScrollbarThemePainter> painter,
      scoped_ptr<WebKit::WebScrollbarThemeGeometry> geometry,
      int scroll_layer_id);
  virtual ~ScrollbarLayer();

 private:
  void UpdatePart(CachingBitmapContentLayerUpdater* painter,
                  LayerUpdater::Resource* resource,
                  gfx::Rect rect,
                  ResourceUpdateQueue* queue);
  void CreateUpdaterIfNeeded();
  gfx::Rect ScrollbarLayerRectToContentRect(gfx::Rect layer_rect) const;

  bool is_dirty() const { return !dirty_rect_.IsEmpty(); }

  int MaxTextureSize();
  float ClampScaleToMaxTextureSize(float scale);

  scoped_ptr<WebKit::WebScrollbar> scrollbar_;
  scoped_ptr<ScrollbarThemePainter> painter_;
  scoped_ptr<WebKit::WebScrollbarThemeGeometry> geometry_;
  gfx::Size thumb_size_;
  int scroll_layer_id_;

  unsigned texture_format_;

  gfx::RectF dirty_rect_;

  scoped_refptr<CachingBitmapContentLayerUpdater> back_track_updater_;
  scoped_refptr<CachingBitmapContentLayerUpdater> fore_track_updater_;
  scoped_refptr<CachingBitmapContentLayerUpdater> thumb_updater_;

  // All the parts of the scrollbar except the thumb
  scoped_ptr<LayerUpdater::Resource> back_track_;
  scoped_ptr<LayerUpdater::Resource> fore_track_;
  scoped_ptr<LayerUpdater::Resource> thumb_;
};

}  // namespace cc

#endif  // CC_LAYERS_SCROLLBAR_LAYER_H_