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" |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 } | 426 } |
427 | 427 |
428 void LayerTreeHostImpl::StartPageScaleAnimation( | 428 void LayerTreeHostImpl::StartPageScaleAnimation( |
429 const gfx::Vector2d& target_offset, | 429 const gfx::Vector2d& target_offset, |
430 bool anchor_point, | 430 bool anchor_point, |
431 float page_scale, | 431 float page_scale, |
432 base::TimeDelta duration) { | 432 base::TimeDelta duration) { |
433 if (!InnerViewportScrollLayer()) | 433 if (!InnerViewportScrollLayer()) |
434 return; | 434 return; |
435 | 435 |
436 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 436 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); |
437 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 437 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
438 gfx::SizeF viewport_size = | 438 gfx::SizeF viewport_size = |
439 active_tree_->InnerViewportContainerLayer()->bounds(); | 439 active_tree_->InnerViewportContainerLayer()->bounds(); |
440 | 440 |
441 // Easing constants experimentally determined. | 441 // Easing constants experimentally determined. |
442 scoped_ptr<TimingFunction> timing_function = | 442 scoped_ptr<TimingFunction> timing_function = |
443 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); | 443 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); |
444 | 444 |
445 page_scale_animation_ = | 445 page_scale_animation_ = |
446 PageScaleAnimation::Create(scroll_total, | 446 PageScaleAnimation::Create(scroll_total.ToVector2dF(), |
danakj
2014/09/25 22:01:27
TODO to pass a ScrollOffset?
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
447 active_tree_->total_page_scale_factor(), | 447 active_tree_->total_page_scale_factor(), |
448 viewport_size, | 448 viewport_size, |
449 scaled_scrollable_size, | 449 scaled_scrollable_size, |
450 timing_function.Pass()); | 450 timing_function.Pass()); |
451 | 451 |
452 if (anchor_point) { | 452 if (anchor_point) { |
453 gfx::Vector2dF anchor(target_offset); | 453 gfx::Vector2dF anchor(target_offset); |
454 page_scale_animation_->ZoomWithAnchor(anchor, | 454 page_scale_animation_->ZoomWithAnchor(anchor, |
455 page_scale, | 455 page_scale, |
456 duration.InSecondsF()); | 456 duration.InSecondsF()); |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1476 metadata.location_bar_content_translation = | 1476 metadata.location_bar_content_translation = |
1477 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); | 1477 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); |
1478 } | 1478 } |
1479 | 1479 |
1480 active_tree_->GetViewportSelection(&metadata.selection_start, | 1480 active_tree_->GetViewportSelection(&metadata.selection_start, |
1481 &metadata.selection_end); | 1481 &metadata.selection_end); |
1482 | 1482 |
1483 if (!InnerViewportScrollLayer()) | 1483 if (!InnerViewportScrollLayer()) |
1484 return metadata; | 1484 return metadata; |
1485 | 1485 |
1486 metadata.root_scroll_offset = active_tree_->TotalScrollOffset(); | 1486 metadata.root_scroll_offset = active_tree_->TotalScrollOffset().ToVector2dF(); |
danakj
2014/09/25 22:01:27
TODO to change the IPC to hold a ScrollOffset?
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
1487 | 1487 |
1488 return metadata; | 1488 return metadata; |
1489 } | 1489 } |
1490 | 1490 |
1491 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { | 1491 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { |
1492 layer->DidBeginTracing(); | 1492 layer->DidBeginTracing(); |
1493 } | 1493 } |
1494 | 1494 |
1495 void LayerTreeHostImpl::DrawLayers(FrameData* frame, | 1495 void LayerTreeHostImpl::DrawLayers(FrameData* frame, |
1496 base::TimeTicks frame_begin_time) { | 1496 base::TimeTicks frame_begin_time) { |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2368 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { | 2368 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { |
2369 Animation* animation = | 2369 Animation* animation = |
2370 layer_impl->layer_animation_controller()->GetAnimation( | 2370 layer_impl->layer_animation_controller()->GetAnimation( |
2371 Animation::ScrollOffset); | 2371 Animation::ScrollOffset); |
2372 if (!animation) | 2372 if (!animation) |
2373 return ScrollIgnored; | 2373 return ScrollIgnored; |
2374 | 2374 |
2375 ScrollOffsetAnimationCurve* curve = | 2375 ScrollOffsetAnimationCurve* curve = |
2376 animation->curve()->ToScrollOffsetAnimationCurve(); | 2376 animation->curve()->ToScrollOffsetAnimationCurve(); |
2377 | 2377 |
2378 gfx::Vector2dF new_target = curve->target_value() + scroll_delta; | 2378 gfx::Vector2dF new_target = curve->target_value() + scroll_delta; |
danakj
2014/09/25 22:01:27
target_value should be a ScrollOffset? So a bunch
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
2379 new_target.SetToMax(gfx::Vector2dF()); | 2379 new_target.SetToMax(gfx::Vector2dF()); |
2380 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 2380 new_target.SetToMin(layer_impl->MaxScrollOffset().ToVector2dF()); |
2381 | 2381 |
2382 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( | 2382 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( |
2383 CurrentBeginFrameArgs().frame_time), | 2383 CurrentBeginFrameArgs().frame_time), |
2384 new_target); | 2384 new_target); |
danakj
2014/09/25 22:01:27
UpdateTarget should be a ScrollOffset?
Yufeng Shen (Slow to review)
2014/09/26 20:19:07
Done.
| |
2385 | 2385 |
2386 return ScrollStarted; | 2386 return ScrollStarted; |
2387 } | 2387 } |
2388 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2388 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling |
2389 // behavior as ScrollBy to determine which layer to animate, but we do not | 2389 // behavior as ScrollBy to determine which layer to animate, but we do not |
2390 // do the Android-specific things in ScrollBy like showing top controls. | 2390 // do the Android-specific things in ScrollBy like showing top controls. |
2391 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); | 2391 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
2392 if (scroll_status == ScrollStarted) { | 2392 if (scroll_status == ScrollStarted) { |
2393 gfx::Vector2dF pending_delta = scroll_delta; | 2393 gfx::Vector2dF pending_delta = scroll_delta; |
2394 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2394 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
2395 layer_impl = layer_impl->parent()) { | 2395 layer_impl = layer_impl->parent()) { |
2396 if (!layer_impl->scrollable()) | 2396 if (!layer_impl->scrollable()) |
2397 continue; | 2397 continue; |
2398 | 2398 |
2399 gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset(); | 2399 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); |
2400 gfx::Vector2dF target_offset = current_offset + pending_delta; | 2400 gfx::ScrollOffset target_offset = |
2401 target_offset.SetToMax(gfx::Vector2dF()); | 2401 current_offset + gfx::ScrollOffset(pending_delta); |
2402 target_offset.SetToMax(gfx::ScrollOffset()); | |
2402 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2403 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
2403 gfx::Vector2dF actual_delta = target_offset - current_offset; | 2404 gfx::Vector2dF actual_delta = |
2405 (target_offset - current_offset).ToVector2dF(); | |
2404 | 2406 |
2405 const float kEpsilon = 0.1f; | 2407 const float kEpsilon = 0.1f; |
2406 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || | 2408 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || |
2407 std::abs(actual_delta.y()) > kEpsilon); | 2409 std::abs(actual_delta.y()) > kEpsilon); |
2408 | 2410 |
2409 if (!can_layer_scroll) { | 2411 if (!can_layer_scroll) { |
2410 layer_impl->ScrollBy(actual_delta); | 2412 layer_impl->ScrollBy(actual_delta); |
2411 pending_delta -= actual_delta; | 2413 pending_delta -= actual_delta; |
2412 continue; | 2414 continue; |
2413 } | 2415 } |
2414 | 2416 |
2415 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2417 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2416 | 2418 |
2417 scoped_ptr<ScrollOffsetAnimationCurve> curve = | 2419 scoped_ptr<ScrollOffsetAnimationCurve> curve = |
2418 ScrollOffsetAnimationCurve::Create(target_offset, | 2420 ScrollOffsetAnimationCurve::Create(target_offset.ToVector2dF(), |
danakj
2014/09/25 22:01:26
should just pass a ScrollOffset?
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
2419 EaseInOutTimingFunction::Create()); | 2421 EaseInOutTimingFunction::Create()); |
2420 curve->SetInitialValue(current_offset); | 2422 curve->SetInitialValue(current_offset.ToVector2dF()); |
danakj
2014/09/25 22:01:27
and here?
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
2421 | 2423 |
2422 scoped_ptr<Animation> animation = | 2424 scoped_ptr<Animation> animation = |
2423 Animation::Create(curve.PassAs<AnimationCurve>(), | 2425 Animation::Create(curve.PassAs<AnimationCurve>(), |
2424 AnimationIdProvider::NextAnimationId(), | 2426 AnimationIdProvider::NextAnimationId(), |
2425 AnimationIdProvider::NextGroupId(), | 2427 AnimationIdProvider::NextGroupId(), |
2426 Animation::ScrollOffset); | 2428 Animation::ScrollOffset); |
2427 animation->set_is_impl_only(true); | 2429 animation->set_is_impl_only(true); |
2428 | 2430 |
2429 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); | 2431 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); |
2430 | 2432 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2614 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2616 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2615 break; | 2617 break; |
2616 } | 2618 } |
2617 | 2619 |
2618 // If the applied delta is within 45 degrees of the input delta, bail out to | 2620 // If the applied delta is within 45 degrees of the input delta, bail out to |
2619 // make it easier to scroll just one layer in one direction without | 2621 // make it easier to scroll just one layer in one direction without |
2620 // affecting any of its parents. | 2622 // affecting any of its parents. |
2621 float angle_threshold = 45; | 2623 float angle_threshold = 45; |
2622 if (MathUtil::SmallestAngleBetweenVectors( | 2624 if (MathUtil::SmallestAngleBetweenVectors( |
2623 applied_delta, pending_delta) < angle_threshold) { | 2625 applied_delta, pending_delta) < angle_threshold) { |
2624 pending_delta = gfx::Vector2d(); | 2626 pending_delta = gfx::Vector2dF(); |
2625 break; | 2627 break; |
2626 } | 2628 } |
2627 | 2629 |
2628 // Allow further movement only on an axis perpendicular to the direction in | 2630 // Allow further movement only on an axis perpendicular to the direction in |
2629 // which the layer moved. | 2631 // which the layer moved. |
2630 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); | 2632 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); |
2631 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); | 2633 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); |
2632 | 2634 |
2633 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) | 2635 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
2634 break; | 2636 break; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2874 page_scale_delta = active_tree_->page_scale_delta(); | 2876 page_scale_delta = active_tree_->page_scale_delta(); |
2875 gfx::PointF new_scale_anchor = | 2877 gfx::PointF new_scale_anchor = |
2876 gfx::ScalePoint(anchor, 1.f / page_scale_delta); | 2878 gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
2877 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; | 2879 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; |
2878 | 2880 |
2879 previous_pinch_anchor_ = anchor; | 2881 previous_pinch_anchor_ = anchor; |
2880 | 2882 |
2881 move.Scale(1 / active_tree_->page_scale_factor()); | 2883 move.Scale(1 / active_tree_->page_scale_factor()); |
2882 // If clamping the inner viewport scroll offset causes a change, it should | 2884 // If clamping the inner viewport scroll offset causes a change, it should |
2883 // be accounted for from the intended move. | 2885 // be accounted for from the intended move. |
2884 move -= InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset(); | 2886 gfx::ScrollOffset max_offset = |
danakj
2014/09/25 22:01:26
This would become Vector2dF based on other comment
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
2887 InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset(); | |
2888 move -= max_offset.ToVector2dF(); | |
2885 | 2889 |
2886 // We manually manage the bubbling behaviour here as it is different to that | 2890 // We manually manage the bubbling behaviour here as it is different to that |
2887 // implemented in LayerTreeHostImpl::ScrollBy(). Specifically: | 2891 // implemented in LayerTreeHostImpl::ScrollBy(). Specifically: |
2888 // 1) we want to explicit limit the bubbling to the outer/inner viewports, | 2892 // 1) we want to explicit limit the bubbling to the outer/inner viewports, |
2889 // 2) we don't want the directional limitations on the unused parts that | 2893 // 2) we don't want the directional limitations on the unused parts that |
2890 // ScrollBy() implements, and | 2894 // ScrollBy() implements, and |
2891 // 3) pinching should not engage the top controls manager. | 2895 // 3) pinching should not engage the top controls manager. |
2892 gfx::Vector2dF unused = OuterViewportScrollLayer() | 2896 gfx::Vector2dF unused = OuterViewportScrollLayer() |
2893 ? OuterViewportScrollLayer()->ScrollBy(move) | 2897 ? OuterViewportScrollLayer()->ScrollBy(move) |
2894 : move; | 2898 : move; |
(...skipping 20 matching lines...) Expand all Loading... | |
2915 if (top_controls_manager_) | 2919 if (top_controls_manager_) |
2916 top_controls_manager_->PinchEnd(); | 2920 top_controls_manager_->PinchEnd(); |
2917 client_->SetNeedsCommitOnImplThread(); | 2921 client_->SetNeedsCommitOnImplThread(); |
2918 } | 2922 } |
2919 | 2923 |
2920 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, | 2924 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, |
2921 LayerImpl* layer_impl) { | 2925 LayerImpl* layer_impl) { |
2922 if (!layer_impl) | 2926 if (!layer_impl) |
2923 return; | 2927 return; |
2924 | 2928 |
2925 gfx::Vector2d scroll_delta = | 2929 gfx::Vector2dF scroll_delta = layer_impl->ScrollDelta(); |
2926 gfx::ToFlooredVector2d(layer_impl->ScrollDelta()); | |
2927 if (!scroll_delta.IsZero()) { | 2930 if (!scroll_delta.IsZero()) { |
2928 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 2931 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
2929 scroll.layer_id = layer_impl->id(); | 2932 scroll.layer_id = layer_impl->id(); |
2930 scroll.scroll_delta = scroll_delta; | 2933 scroll.scroll_delta = scroll_delta; |
2931 scroll_info->scrolls.push_back(scroll); | 2934 scroll_info->scrolls.push_back(scroll); |
2932 layer_impl->SetSentScrollDelta(scroll_delta); | 2935 layer_impl->SetSentScrollDelta(scroll_delta); |
2933 } | 2936 } |
2934 | 2937 |
2935 for (size_t i = 0; i < layer_impl->children().size(); ++i) | 2938 for (size_t i = 0; i < layer_impl->children().size(); ++i) |
2936 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); | 2939 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); |
(...skipping 25 matching lines...) Expand all Loading... | |
2962 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); | 2965 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); |
2963 | 2966 |
2964 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) | 2967 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) |
2965 InnerViewportScrollLayer()->ScrollBy(unused_delta); | 2968 InnerViewportScrollLayer()->ScrollBy(unused_delta); |
2966 } | 2969 } |
2967 | 2970 |
2968 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { | 2971 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { |
2969 if (!page_scale_animation_) | 2972 if (!page_scale_animation_) |
2970 return; | 2973 return; |
2971 | 2974 |
2972 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 2975 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); |
2973 | 2976 |
2974 if (!page_scale_animation_->IsAnimationStarted()) | 2977 if (!page_scale_animation_->IsAnimationStarted()) |
2975 page_scale_animation_->StartAnimation(monotonic_time); | 2978 page_scale_animation_->StartAnimation(monotonic_time); |
2976 | 2979 |
2977 active_tree_->SetPageScaleDelta( | 2980 active_tree_->SetPageScaleDelta( |
2978 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2981 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
2979 active_tree_->page_scale_factor()); | 2982 active_tree_->page_scale_factor()); |
2980 gfx::Vector2dF next_scroll = | 2983 gfx::Vector2dF next_scroll = |
danakj
2014/09/25 22:01:27
ScrollOffset
Yufeng Shen (Slow to review)
2014/09/26 20:19:07
Done.
| |
2981 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2984 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); |
2982 | 2985 |
2983 ScrollViewportBy(next_scroll - scroll_total); | 2986 ScrollViewportBy(next_scroll - scroll_total.ToVector2dF()); |
danakj
2014/09/25 22:01:26
convert after subtracting
Yufeng Shen (Slow to review)
2014/09/26 20:19:08
Done.
| |
2984 SetNeedsRedraw(); | 2987 SetNeedsRedraw(); |
2985 | 2988 |
2986 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2989 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
2987 page_scale_animation_.reset(); | 2990 page_scale_animation_.reset(); |
2988 client_->SetNeedsCommitOnImplThread(); | 2991 client_->SetNeedsCommitOnImplThread(); |
2989 client_->RenewTreePriority(); | 2992 client_->RenewTreePriority(); |
2990 } else { | 2993 } else { |
2991 SetNeedsAnimate(); | 2994 SetNeedsAnimate(); |
2992 } | 2995 } |
2993 } | 2996 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3383 } | 3386 } |
3384 | 3387 |
3385 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3388 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3386 std::vector<PictureLayerImpl*>::iterator it = | 3389 std::vector<PictureLayerImpl*>::iterator it = |
3387 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3390 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3388 DCHECK(it != picture_layers_.end()); | 3391 DCHECK(it != picture_layers_.end()); |
3389 picture_layers_.erase(it); | 3392 picture_layers_.erase(it); |
3390 } | 3393 } |
3391 | 3394 |
3392 } // namespace cc | 3395 } // namespace cc |
OLD | NEW |