OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "cc/animation/animation_id_provider.h" |
| 17 #include "cc/animation/scroll_offset_animation_curve.h" |
16 #include "cc/animation/scrollbar_animation_controller.h" | 18 #include "cc/animation/scrollbar_animation_controller.h" |
17 #include "cc/animation/timing_function.h" | 19 #include "cc/animation/timing_function.h" |
18 #include "cc/base/latency_info_swap_promise_monitor.h" | 20 #include "cc/base/latency_info_swap_promise_monitor.h" |
19 #include "cc/base/math_util.h" | 21 #include "cc/base/math_util.h" |
20 #include "cc/base/util.h" | 22 #include "cc/base/util.h" |
21 #include "cc/debug/benchmark_instrumentation.h" | 23 #include "cc/debug/benchmark_instrumentation.h" |
22 #include "cc/debug/debug_rect_history.h" | 24 #include "cc/debug/debug_rect_history.h" |
23 #include "cc/debug/devtools_instrumentation.h" | 25 #include "cc/debug/devtools_instrumentation.h" |
24 #include "cc/debug/frame_rate_counter.h" | 26 #include "cc/debug/frame_rate_counter.h" |
25 #include "cc/debug/paint_time_counter.h" | 27 #include "cc/debug/paint_time_counter.h" |
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2279 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); | 2281 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); |
2280 should_bubble_scrolls_ = (type != NonBubblingGesture); | 2282 should_bubble_scrolls_ = (type != NonBubblingGesture); |
2281 wheel_scrolling_ = (type == Wheel); | 2283 wheel_scrolling_ = (type == Wheel); |
2282 client_->RenewTreePriority(); | 2284 client_->RenewTreePriority(); |
2283 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); | 2285 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
2284 return ScrollStarted; | 2286 return ScrollStarted; |
2285 } | 2287 } |
2286 return ScrollIgnored; | 2288 return ScrollIgnored; |
2287 } | 2289 } |
2288 | 2290 |
| 2291 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( |
| 2292 const gfx::Point& viewport_point, |
| 2293 const gfx::Vector2dF& scroll_delta) { |
| 2294 if (CurrentlyScrollingLayer()) { |
| 2295 // TODO(skobes): Update the target of the existing animation. |
| 2296 return ScrollIgnored; |
| 2297 } |
| 2298 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling |
| 2299 // behavior as ScrollBy to determine which layer to animate, but we do not |
| 2300 // do the Android-specific things in ScrollBy like showing top controls. |
| 2301 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
| 2302 if (scroll_status == ScrollStarted) { |
| 2303 gfx::Vector2dF pending_delta = scroll_delta; |
| 2304 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
| 2305 layer_impl = layer_impl->parent()) { |
| 2306 if (!layer_impl->scrollable()) |
| 2307 continue; |
| 2308 |
| 2309 gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset(); |
| 2310 gfx::Vector2dF target_offset = current_offset + pending_delta; |
| 2311 target_offset.SetToMax(gfx::Vector2dF()); |
| 2312 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
| 2313 gfx::Vector2dF actual_delta = target_offset - current_offset; |
| 2314 |
| 2315 const float kEpsilon = 0.1f; |
| 2316 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || |
| 2317 std::abs(actual_delta.y()) > kEpsilon); |
| 2318 |
| 2319 if (!can_layer_scroll) { |
| 2320 layer_impl->ScrollBy(actual_delta); |
| 2321 pending_delta -= actual_delta; |
| 2322 continue; |
| 2323 } |
| 2324 |
| 2325 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
| 2326 |
| 2327 scoped_ptr<ScrollOffsetAnimationCurve> curve = |
| 2328 ScrollOffsetAnimationCurve::Create(target_offset, |
| 2329 EaseInOutTimingFunction::Create()); |
| 2330 curve->SetInitialValue(current_offset); |
| 2331 |
| 2332 scoped_ptr<Animation> animation = |
| 2333 Animation::Create(curve->Clone().Pass(), |
| 2334 AnimationIdProvider::NextAnimationId(), |
| 2335 AnimationIdProvider::NextGroupId(), |
| 2336 Animation::ScrollOffset); |
| 2337 animation->set_is_impl_only(true); |
| 2338 |
| 2339 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); |
| 2340 |
| 2341 SetNeedsAnimate(); |
| 2342 return ScrollStarted; |
| 2343 } |
| 2344 } |
| 2345 ScrollEnd(); |
| 2346 return scroll_status; |
| 2347 } |
| 2348 |
2289 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( | 2349 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( |
2290 LayerImpl* layer_impl, | 2350 LayerImpl* layer_impl, |
2291 float scale_from_viewport_to_screen_space, | 2351 float scale_from_viewport_to_screen_space, |
2292 const gfx::PointF& viewport_point, | 2352 const gfx::PointF& viewport_point, |
2293 const gfx::Vector2dF& viewport_delta) { | 2353 const gfx::Vector2dF& viewport_delta) { |
2294 // Layers with non-invertible screen space transforms should not have passed | 2354 // Layers with non-invertible screen space transforms should not have passed |
2295 // the scroll hit test in the first place. | 2355 // the scroll hit test in the first place. |
2296 DCHECK(layer_impl->screen_space_transform().IsInvertible()); | 2356 DCHECK(layer_impl->screen_space_transform().IsInvertible()); |
2297 gfx::Transform inverse_screen_space_transform( | 2357 gfx::Transform inverse_screen_space_transform( |
2298 gfx::Transform::kSkipInitialization); | 2358 gfx::Transform::kSkipInitialization); |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3182 } | 3242 } |
3183 | 3243 |
3184 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3244 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3185 std::vector<PictureLayerImpl*>::iterator it = | 3245 std::vector<PictureLayerImpl*>::iterator it = |
3186 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3246 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3187 DCHECK(it != picture_layers_.end()); | 3247 DCHECK(it != picture_layers_.end()); |
3188 picture_layers_.erase(it); | 3248 picture_layers_.erase(it); |
3189 } | 3249 } |
3190 | 3250 |
3191 } // namespace cc | 3251 } // namespace cc |
OLD | NEW |