summaryrefslogtreecommitdiffstats
path: root/cc/layers/scrollbar_layer_impl.h
blob: ffc758f21d6d24c1abf16b1c1ce68f1c18652d3f (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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_IMPL_H_
#define CC_LAYERS_SCROLLBAR_LAYER_IMPL_H_

#include "cc/base/cc_export.h"
#include "cc/input/scrollbar.h"
#include "cc/layers/layer_impl.h"
#include "cc/resources/ui_resource_client.h"

namespace cc {

class LayerTreeImpl;
class ScrollView;

class CC_EXPORT ScrollbarLayerImpl : public LayerImpl {
 public:
  static scoped_ptr<ScrollbarLayerImpl> Create(
      LayerTreeImpl* tree_impl,
      int id,
      ScrollbarOrientation orientation);
  virtual ~ScrollbarLayerImpl();

  // LayerImpl implementation.
  virtual ScrollbarLayerImpl* ToScrollbarLayer() OVERRIDE;
  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
      OVERRIDE;
  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;

  virtual bool WillDraw(DrawMode draw_mode,
                        ResourceProvider* resource_provider) OVERRIDE;
  virtual void AppendQuads(QuadSink* quad_sink,
                           AppendQuadsData* append_quads_data) OVERRIDE;

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

  ScrollbarOrientation Orientation() const;
  float CurrentPos() const;
  int Maximum() const;

  void set_thumb_thickness(int thumb_thickness) {
    thumb_thickness_ = thumb_thickness;
  }
  int thumb_thickness() const { return thumb_thickness_; }
  void set_thumb_length(int thumb_length) {
    thumb_length_ = thumb_length;
  }
  void set_track_start(int track_start) {
    track_start_ = track_start;
  }
  void set_track_length(int track_length) {
    track_length_ = track_length;
  }
  void set_vertical_adjust(float vertical_adjust) {
    vertical_adjust_ = vertical_adjust;
  }
  void set_track_ui_resource_id(UIResourceId uid) {
    track_ui_resource_id_ = uid;
  }
  void set_thumb_ui_resource_id(UIResourceId uid) {
    thumb_ui_resource_id_ = uid;
  }
  void set_visible_to_total_length_ratio(float ratio) {
    visible_to_total_length_ratio_ = ratio;
  }
  void set_is_overlay_scrollbar(bool is_overlay_scrollbar) {
    is_overlay_scrollbar_ = is_overlay_scrollbar;
  }
  bool is_overlay_scrollbar() const { return is_overlay_scrollbar_; }

  void SetCurrentPos(float current_pos) { current_pos_ = current_pos; }
  void SetMaximum(int maximum) { maximum_ = maximum; }

  gfx::Rect ComputeThumbQuadRect() const;

 protected:
  ScrollbarLayerImpl(LayerTreeImpl* tree_impl,
                     int id,
                     ScrollbarOrientation orientation);

 private:
  virtual const char* LayerTypeAsString() const OVERRIDE;

  gfx::Rect ScrollbarLayerRectToContentRect(gfx::RectF layer_rect) const;

  UIResourceId track_ui_resource_id_;
  UIResourceId thumb_ui_resource_id_;

  float current_pos_;
  int maximum_;
  int thumb_thickness_;
  int thumb_length_;
  int track_start_;
  int track_length_;
  ScrollbarOrientation orientation_;

  // Difference between the clip layer's height and the visible viewport
  // height (which may differ in the presence of top-controls hiding).
  float vertical_adjust_;

  float visible_to_total_length_ratio_;

  int scroll_layer_id_;

  bool is_overlay_scrollbar_;

  DISALLOW_COPY_AND_ASSIGN(ScrollbarLayerImpl);
};

}  // namespace cc
#endif  // CC_LAYERS_SCROLLBAR_LAYER_IMPL_H_