Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: cc/layers/scrollbar_layer_impl_base.cc

Issue 18341009: Refactor cc scrollbar layers to separate solid-color vs desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased patch as it's sat for a while. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "cc/layers/scrollbar_layer_impl_base.h"
6
7 #include "cc/layers/layer.h"
8 #include "ui/gfx/rect_conversions.h"
9
10 namespace cc {
11
12 ScrollbarLayerImplBase::ScrollbarLayerImplBase(LayerTreeImpl* tree_impl,
13 int id,
14 ScrollbarOrientation orientation)
15 : LayerImpl(tree_impl, id),
16 scroll_layer_id_(Layer::INVALID_ID),
17 current_pos_(0.f),
18 maximum_(0),
19 orientation_(orientation),
20 visible_to_total_length_ratio_(1.f),
21 vertical_adjust_(0.f) {}
22
23 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) {
24 LayerImpl::PushPropertiesTo(layer);
25 }
26
27 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayerBase() {
28 return this;
29 }
30
31 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect(
32 gfx::RectF layer_rect) const {
33 // Don't intersect with the bounds as in layerRectToContentRect() because
34 // layer_rect here might be in coordinates of the containing layer.
35 gfx::RectF content_rect = gfx::ScaleRect(layer_rect,
36 contents_scale_x(),
37 contents_scale_y());
38 return gfx::ToEnclosingRect(content_rect);
39 }
40
41 gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const {
42 // Thumb extent is the length of the thumb in the scrolling direction, thumb
43 // thickness is in the perpendicular direction. Here's an example of a
44 // horizontal scrollbar - inputs are above the scrollbar, computed values
45 // below:
46 //
47 // |<------------------- track_length_ ------------------->|
48 //
49 // |--| <-- start_offset
50 //
51 // +--+----------------------------+------------------+-------+--+
52 // |<|| |##################| ||>|
53 // +--+----------------------------+------------------+-------+--+
54 //
55 // |<- thumb_length ->|
56 //
57 // |<------- thumb_offset -------->|
58 //
59 // For painted, scrollbars, the length is fixed. For solid color scrollbars we
60 // have to compute it. The ratio of the thumb's length to the track's length
61 // is the same as that of the visible viewport to the total viewport, unless
62 // that would make the thumb's length less than its thickness.
63 //
64 // vertical_adjust_ is used when the layer geometry from the main thread is
65 // not in sync with what the user sees. For instance on Android scrolling the
66 // top bar controls out of view reveals more of the page content. We want the
67 // root layer scrollbars to reflect what the user sees even if we haven't
68 // received new layer geometry from the main thread. If the user has scrolled
69 // down by 50px and the initial viewport size was 950px the geometry would
70 // look something like this:
71 //
72 // vertical_adjust_ = 50, scroll position 0, visible ratios 99%
73 // Layer geometry: Desired thumb positions:
74 // +--------------------+-+ +----------------------+ <-- 0px
75 // | |v| | #|
76 // | |e| | #|
77 // | |r| | #|
78 // | |t| | #|
79 // | |i| | #|
80 // | |c| | #|
81 // | |a| | #|
82 // | |l| | #|
83 // | | | | #|
84 // | |l| | #|
85 // | |a| | #|
86 // | |y| | #|
87 // | |e| | #|
88 // | |r| | #|
89 // +--------------------+-+ | #|
90 // | horizontal layer | | | #|
91 // +--------------------+-+ | #| <-- 950px
92 // | | | #|
93 // | | |##################### |
94 // +----------------------+ +----------------------+ <-- 1000px
95 //
96 // The layer geometry is set up for a 950px tall viewport, but the user can
97 // actually see down to 1000px. Thus we have to move the quad for the
98 // horizontal scrollbar down by the vertical_adjust_ factor and lay the
99 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This
100 // means the quads may extend outside the layer's bounds.
101
102 // With the length known, we can compute the thumb's position.
103 float track_length = TrackLength();
104 int thumb_length = ThumbLength();
105 int thumb_thickness = ThumbThickness();
106
107 float ratio = current_pos_ / maximum_;
108 float max_offset = track_length - thumb_length;
109 int thumb_offset = static_cast<int>(ratio * max_offset) + TrackStart();
110
111 gfx::RectF thumb_rect;
112 if (orientation() == HORIZONTAL) {
113 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_,
114 thumb_length, thumb_thickness);
115 } else {
116 thumb_rect = gfx::RectF(0.f, thumb_offset,
117 thumb_thickness, thumb_length);
118 }
119
120 return ScrollbarLayerRectToContentRect(thumb_rect);
121 }
122
123 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698