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

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: Address tfarina@'s comments. Created 7 years, 5 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 2012 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 #include "ui/gfx/rect_conversions.h"
7
8 namespace cc {
9
10 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) {
11 LayerImpl::PushPropertiesTo(layer);
12 }
13
14 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayerBase() {
15 return this;
16 }
17
18 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect(
19 gfx::RectF layer_rect) const {
20 // Don't intersect with the bounds as in layerRectToContentRect() because
21 // layer_rect here might be in coordinates of the containing layer.
22 gfx::RectF content_rect = gfx::ScaleRect(layer_rect,
23 contents_scale_x(),
24 contents_scale_y());
25 return gfx::ToEnclosingRect(content_rect);
26 }
27
28 gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRectInternal(
29 int thumb_length,
30 float track_length,
31 int track_start,
32 int thumb_thickness) const {
33 // Thumb extent is the length of the thumb in the scrolling direction, thumb
34 // thickness is in the perpendicular direction. Here's an example of a
35 // horizontal scrollbar - inputs are above the scrollbar, computed values
36 // below:
37 //
38 // |<------------------- track_length_ ------------------->|
39 //
40 // |--| <-- start_offset
41 //
42 // +--+----------------------------+------------------+-------+--+
43 // |<|| |##################| ||>|
44 // +--+----------------------------+------------------+-------+--+
45 //
46 // |<- thumb_length ->|
47 //
48 // |<------- thumb_offset -------->|
49 //
50 // For painted, scrollbars, the length is fixed. For solid color scrollbars we
51 // have to compute it. The ratio of the thumb's length to the track's length
52 // is the same as that of the visible viewport to the total viewport, unless
53 // that would make the thumb's length less than its thickness.
54 //
55 // vertical_adjust_ is used when the layer geometry from the main thread is
56 // not in sync with what the user sees. For instance on Android scrolling the
57 // top bar controls out of view reveals more of the page content. We want the
58 // root layer scrollbars to reflect what the user sees even if we haven't
59 // received new layer geometry from the main thread. If the user has scrolled
60 // down by 50px and the initial viewport size was 950px the geometry would
61 // look something like this:
62 //
63 // vertical_adjust_ = 50, scroll position 0, visible ratios 99%
64 // Layer geometry: Desired thumb positions:
65 // +--------------------+-+ +----------------------+ <-- 0px
66 // | |v| | #|
67 // | |e| | #|
68 // | |r| | #|
69 // | |t| | #|
70 // | |i| | #|
71 // | |c| | #|
72 // | |a| | #|
73 // | |l| | #|
74 // | | | | #|
75 // | |l| | #|
76 // | |a| | #|
77 // | |y| | #|
78 // | |e| | #|
79 // | |r| | #|
80 // +--------------------+-+ | #|
81 // | horizontal layer | | | #|
82 // +--------------------+-+ | #| <-- 950px
83 // | | | #|
84 // | | |##################### |
85 // +----------------------+ +----------------------+ <-- 1000px
86 //
87 // The layer geometry is set up for a 950px tall viewport, but the user can
88 // actually see down to 1000px. Thus we have to move the quad for the
89 // horizontal scrollbar down by the vertical_adjust_ factor and lay the
90 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This
91 // means the quads may extend outside the layer's bounds.
92
93 // With the length known, we can compute the thumb's position.
94 float ratio = current_pos_ / maximum_;
95 float max_offset = track_length - thumb_length;
96 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start;
97
98 gfx::RectF thumb_rect;
99 if (orientation_ == HORIZONTAL) {
100 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_,
101 thumb_length, thumb_thickness);
102 } else {
103 thumb_rect = gfx::RectF(0.f, thumb_offset,
104 thumb_thickness, thumb_length);
105 }
106
107 return ScrollbarLayerRectToContentRect(thumb_rect);
108 }
109
110 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698