OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/scrollbar_layer_impl_base.h" | 5 #include "cc/layers/scrollbar_layer_impl_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "cc/trees/effect_node.h" | 8 #include "cc/trees/effect_node.h" |
9 #include "cc/trees/layer_tree_impl.h" | 9 #include "cc/trees/layer_tree_impl.h" |
10 #include "ui/gfx/geometry/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 } | 100 } |
101 | 101 |
102 bool ScrollbarLayerImplBase::SetThumbThicknessScaleFactor(float factor) { | 102 bool ScrollbarLayerImplBase::SetThumbThicknessScaleFactor(float factor) { |
103 if (thumb_thickness_scale_factor_ == factor) | 103 if (thumb_thickness_scale_factor_ == factor) |
104 return false; | 104 return false; |
105 thumb_thickness_scale_factor_ = factor; | 105 thumb_thickness_scale_factor_ = factor; |
106 NoteLayerPropertyChanged(); | 106 NoteLayerPropertyChanged(); |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 gfx::Rect ScrollbarLayerImplBase::ComputeExpandedThumbQuadRect() const { | |
111 DCHECK(is_overlay_scrollbar()); | |
112 float track_length = TrackLength(); | |
113 int thumb_length = ThumbLength(); | |
114 int thumb_thickness = ThumbThickness(); | |
115 float maximum = scroll_layer_length_ - clip_layer_length_; | |
116 | |
117 // With the length known, we can compute the thumb's position. | |
118 float clamped_current_pos = std::min(std::max(current_pos_, 0.f), maximum); | |
119 | |
120 int thumb_offset = TrackStart(); | |
121 if (maximum > 0) { | |
122 float ratio = clamped_current_pos / maximum; | |
123 float max_offset = track_length - thumb_length; | |
124 thumb_offset += static_cast<int>(ratio * max_offset); | |
125 } | |
126 | |
127 gfx::RectF thumb_rect; | |
128 if (orientation_ == HORIZONTAL) { | |
129 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_, thumb_length, | |
130 thumb_thickness); | |
131 } else { | |
132 thumb_rect = gfx::RectF(is_left_side_vertical_scrollbar_ | |
133 ? bounds().width() - thumb_thickness | |
134 : 0, | |
135 thumb_offset, thumb_thickness, thumb_length); | |
136 } | |
137 | |
138 return gfx::ToEnclosingRect(thumb_rect); | |
139 } | |
140 | |
110 gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const { | 141 gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const { |
111 // Thumb extent is the length of the thumb in the scrolling direction, thumb | 142 // Thumb extent is the length of the thumb in the scrolling direction, thumb |
112 // thickness is in the perpendicular direction. Here's an example of a | 143 // thickness is in the perpendicular direction. Here's an example of a |
113 // horizontal scrollbar - inputs are above the scrollbar, computed values | 144 // horizontal scrollbar - inputs are above the scrollbar, computed values |
114 // below: | 145 // below: |
115 // | 146 // |
116 // |<------------------- track_length_ ------------------->| | 147 // |<------------------- track_length_ ------------------->| |
117 // | 148 // |
118 // |--| <-- start_offset | 149 // |--| <-- start_offset |
119 // | 150 // |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // With the length known, we can compute the thumb's position. | 208 // With the length known, we can compute the thumb's position. |
178 float clamped_current_pos = std::min(std::max(current_pos_, 0.f), maximum); | 209 float clamped_current_pos = std::min(std::max(current_pos_, 0.f), maximum); |
179 | 210 |
180 int thumb_offset = TrackStart(); | 211 int thumb_offset = TrackStart(); |
181 if (maximum > 0) { | 212 if (maximum > 0) { |
182 float ratio = clamped_current_pos / maximum; | 213 float ratio = clamped_current_pos / maximum; |
183 float max_offset = track_length - thumb_length; | 214 float max_offset = track_length - thumb_length; |
184 thumb_offset += static_cast<int>(ratio * max_offset); | 215 thumb_offset += static_cast<int>(ratio * max_offset); |
185 } | 216 } |
186 | 217 |
187 float thumb_thickness_adjustment = | 218 float thumb_thickness_adjustment = |
bokan
2017/04/25 19:36:21
This method should just call the new one above and
| |
188 thumb_thickness * (1.f - thumb_thickness_scale_factor_); | 219 thumb_thickness * (1.f - thumb_thickness_scale_factor_); |
189 | 220 |
190 gfx::RectF thumb_rect; | 221 gfx::RectF thumb_rect; |
191 if (orientation_ == HORIZONTAL) { | 222 if (orientation_ == HORIZONTAL) { |
192 thumb_rect = gfx::RectF(thumb_offset, | 223 thumb_rect = gfx::RectF(thumb_offset, |
193 vertical_adjust_ + thumb_thickness_adjustment, | 224 vertical_adjust_ + thumb_thickness_adjustment, |
194 thumb_length, | 225 thumb_length, |
195 thumb_thickness - thumb_thickness_adjustment); | 226 thumb_thickness - thumb_thickness_adjustment); |
196 } else { | 227 } else { |
197 thumb_rect = gfx::RectF( | 228 thumb_rect = gfx::RectF( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); | 262 layer_tree_impl()->AddToOpacityAnimationsMap(id(), opacity); |
232 | 263 |
233 node->opacity = opacity; | 264 node->opacity = opacity; |
234 node->effect_changed = true; | 265 node->effect_changed = true; |
235 property_trees->changed = true; | 266 property_trees->changed = true; |
236 property_trees->effect_tree.set_needs_update(true); | 267 property_trees->effect_tree.set_needs_update(true); |
237 layer_tree_impl()->set_needs_update_draw_properties(); | 268 layer_tree_impl()->set_needs_update_draw_properties(); |
238 } | 269 } |
239 | 270 |
240 } // namespace cc | 271 } // namespace cc |
OLD | NEW |