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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 429 } |
430 | 430 |
431 void LayerTreeHostImpl::StartPageScaleAnimation( | 431 void LayerTreeHostImpl::StartPageScaleAnimation( |
432 const gfx::Vector2d& target_offset, | 432 const gfx::Vector2d& target_offset, |
433 bool anchor_point, | 433 bool anchor_point, |
434 float page_scale, | 434 float page_scale, |
435 base::TimeDelta duration) { | 435 base::TimeDelta duration) { |
436 if (!InnerViewportScrollLayer()) | 436 if (!InnerViewportScrollLayer()) |
437 return; | 437 return; |
438 | 438 |
439 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 439 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); |
440 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 440 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
441 gfx::SizeF viewport_size = | 441 gfx::SizeF viewport_size = |
442 active_tree_->InnerViewportContainerLayer()->bounds(); | 442 active_tree_->InnerViewportContainerLayer()->bounds(); |
443 | 443 |
444 // Easing constants experimentally determined. | 444 // Easing constants experimentally determined. |
445 scoped_ptr<TimingFunction> timing_function = | 445 scoped_ptr<TimingFunction> timing_function = |
446 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); | 446 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); |
447 | 447 |
| 448 // TODO(miletus) : Pass in ScrollOffset. |
448 page_scale_animation_ = | 449 page_scale_animation_ = |
449 PageScaleAnimation::Create(scroll_total, | 450 PageScaleAnimation::Create(ScrollOffsetToVector2dF(scroll_total), |
450 active_tree_->total_page_scale_factor(), | 451 active_tree_->total_page_scale_factor(), |
451 viewport_size, | 452 viewport_size, |
452 scaled_scrollable_size, | 453 scaled_scrollable_size, |
453 timing_function.Pass()); | 454 timing_function.Pass()); |
454 | 455 |
455 if (anchor_point) { | 456 if (anchor_point) { |
456 gfx::Vector2dF anchor(target_offset); | 457 gfx::Vector2dF anchor(target_offset); |
457 page_scale_animation_->ZoomWithAnchor(anchor, | 458 page_scale_animation_->ZoomWithAnchor(anchor, |
458 page_scale, | 459 page_scale, |
459 duration.InSecondsF()); | 460 duration.InSecondsF()); |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 metadata.location_bar_content_translation = | 1481 metadata.location_bar_content_translation = |
1481 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); | 1482 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); |
1482 } | 1483 } |
1483 | 1484 |
1484 active_tree_->GetViewportSelection(&metadata.selection_start, | 1485 active_tree_->GetViewportSelection(&metadata.selection_start, |
1485 &metadata.selection_end); | 1486 &metadata.selection_end); |
1486 | 1487 |
1487 if (!InnerViewportScrollLayer()) | 1488 if (!InnerViewportScrollLayer()) |
1488 return metadata; | 1489 return metadata; |
1489 | 1490 |
1490 metadata.root_scroll_offset = active_tree_->TotalScrollOffset(); | 1491 // TODO(miletus) : Change the metadata to hold ScrollOffset. |
| 1492 metadata.root_scroll_offset = gfx::ScrollOffsetToVector2dF( |
| 1493 active_tree_->TotalScrollOffset()); |
1491 | 1494 |
1492 return metadata; | 1495 return metadata; |
1493 } | 1496 } |
1494 | 1497 |
1495 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { | 1498 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { |
1496 layer->DidBeginTracing(); | 1499 layer->DidBeginTracing(); |
1497 } | 1500 } |
1498 | 1501 |
1499 void LayerTreeHostImpl::DrawLayers(FrameData* frame, | 1502 void LayerTreeHostImpl::DrawLayers(FrameData* frame, |
1500 base::TimeTicks frame_begin_time) { | 1503 base::TimeTicks frame_begin_time) { |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { | 2371 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { |
2369 Animation* animation = | 2372 Animation* animation = |
2370 layer_impl->layer_animation_controller()->GetAnimation( | 2373 layer_impl->layer_animation_controller()->GetAnimation( |
2371 Animation::ScrollOffset); | 2374 Animation::ScrollOffset); |
2372 if (!animation) | 2375 if (!animation) |
2373 return ScrollIgnored; | 2376 return ScrollIgnored; |
2374 | 2377 |
2375 ScrollOffsetAnimationCurve* curve = | 2378 ScrollOffsetAnimationCurve* curve = |
2376 animation->curve()->ToScrollOffsetAnimationCurve(); | 2379 animation->curve()->ToScrollOffsetAnimationCurve(); |
2377 | 2380 |
2378 gfx::Vector2dF new_target = curve->target_value() + scroll_delta; | 2381 gfx::ScrollOffset new_target = |
2379 new_target.SetToMax(gfx::Vector2dF()); | 2382 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); |
| 2383 new_target.SetToMax(gfx::ScrollOffset()); |
2380 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 2384 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
2381 | 2385 |
2382 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( | 2386 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( |
2383 CurrentBeginFrameArgs().frame_time), | 2387 CurrentBeginFrameArgs().frame_time), |
2384 new_target); | 2388 new_target); |
2385 | 2389 |
2386 return ScrollStarted; | 2390 return ScrollStarted; |
2387 } | 2391 } |
2388 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2392 // 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 | 2393 // 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. | 2394 // do the Android-specific things in ScrollBy like showing top controls. |
2391 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); | 2395 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
2392 if (scroll_status == ScrollStarted) { | 2396 if (scroll_status == ScrollStarted) { |
2393 gfx::Vector2dF pending_delta = scroll_delta; | 2397 gfx::Vector2dF pending_delta = scroll_delta; |
2394 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2398 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
2395 layer_impl = layer_impl->parent()) { | 2399 layer_impl = layer_impl->parent()) { |
2396 if (!layer_impl->scrollable()) | 2400 if (!layer_impl->scrollable()) |
2397 continue; | 2401 continue; |
2398 | 2402 |
2399 gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset(); | 2403 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); |
2400 gfx::Vector2dF target_offset = current_offset + pending_delta; | 2404 gfx::ScrollOffset target_offset = |
2401 target_offset.SetToMax(gfx::Vector2dF()); | 2405 ScrollOffsetWithDelta(current_offset, pending_delta); |
| 2406 target_offset.SetToMax(gfx::ScrollOffset()); |
2402 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2407 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
2403 gfx::Vector2dF actual_delta = target_offset - current_offset; | 2408 gfx::Vector2dF actual_delta = |
| 2409 gfx::ScrollOffsetToVector2dF(target_offset - current_offset); |
2404 | 2410 |
2405 const float kEpsilon = 0.1f; | 2411 const float kEpsilon = 0.1f; |
2406 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || | 2412 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || |
2407 std::abs(actual_delta.y()) > kEpsilon); | 2413 std::abs(actual_delta.y()) > kEpsilon); |
2408 | 2414 |
2409 if (!can_layer_scroll) { | 2415 if (!can_layer_scroll) { |
2410 layer_impl->ScrollBy(actual_delta); | 2416 layer_impl->ScrollBy(actual_delta); |
2411 pending_delta -= actual_delta; | 2417 pending_delta -= actual_delta; |
2412 continue; | 2418 continue; |
2413 } | 2419 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2614 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2620 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2615 break; | 2621 break; |
2616 } | 2622 } |
2617 | 2623 |
2618 // If the applied delta is within 45 degrees of the input delta, bail out to | 2624 // 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 | 2625 // make it easier to scroll just one layer in one direction without |
2620 // affecting any of its parents. | 2626 // affecting any of its parents. |
2621 float angle_threshold = 45; | 2627 float angle_threshold = 45; |
2622 if (MathUtil::SmallestAngleBetweenVectors( | 2628 if (MathUtil::SmallestAngleBetweenVectors( |
2623 applied_delta, pending_delta) < angle_threshold) { | 2629 applied_delta, pending_delta) < angle_threshold) { |
2624 pending_delta = gfx::Vector2d(); | 2630 pending_delta = gfx::Vector2dF(); |
2625 break; | 2631 break; |
2626 } | 2632 } |
2627 | 2633 |
2628 // Allow further movement only on an axis perpendicular to the direction in | 2634 // Allow further movement only on an axis perpendicular to the direction in |
2629 // which the layer moved. | 2635 // which the layer moved. |
2630 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); | 2636 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); |
2631 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); | 2637 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); |
2632 | 2638 |
2633 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) | 2639 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
2634 break; | 2640 break; |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2962 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); | 2968 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); |
2963 | 2969 |
2964 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) | 2970 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) |
2965 InnerViewportScrollLayer()->ScrollBy(unused_delta); | 2971 InnerViewportScrollLayer()->ScrollBy(unused_delta); |
2966 } | 2972 } |
2967 | 2973 |
2968 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { | 2974 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { |
2969 if (!page_scale_animation_) | 2975 if (!page_scale_animation_) |
2970 return; | 2976 return; |
2971 | 2977 |
2972 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 2978 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); |
2973 | 2979 |
2974 if (!page_scale_animation_->IsAnimationStarted()) | 2980 if (!page_scale_animation_->IsAnimationStarted()) |
2975 page_scale_animation_->StartAnimation(monotonic_time); | 2981 page_scale_animation_->StartAnimation(monotonic_time); |
2976 | 2982 |
2977 active_tree_->SetPageScaleDelta( | 2983 active_tree_->SetPageScaleDelta( |
2978 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2984 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
2979 active_tree_->page_scale_factor()); | 2985 active_tree_->page_scale_factor()); |
2980 gfx::Vector2dF next_scroll = | 2986 gfx::ScrollOffset next_scroll = gfx::ScrollOffset( |
2981 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2987 page_scale_animation_->ScrollOffsetAtTime(monotonic_time)); |
2982 | 2988 |
2983 ScrollViewportBy(next_scroll - scroll_total); | 2989 ScrollViewportBy(ScrollOffsetToVector2dF(next_scroll - scroll_total)); |
2984 SetNeedsRedraw(); | 2990 SetNeedsRedraw(); |
2985 | 2991 |
2986 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2992 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
2987 page_scale_animation_.reset(); | 2993 page_scale_animation_.reset(); |
2988 client_->SetNeedsCommitOnImplThread(); | 2994 client_->SetNeedsCommitOnImplThread(); |
2989 client_->RenewTreePriority(); | 2995 client_->RenewTreePriority(); |
2990 } else { | 2996 } else { |
2991 SetNeedsAnimate(); | 2997 SetNeedsAnimate(); |
2992 } | 2998 } |
2993 } | 2999 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 } | 3389 } |
3384 | 3390 |
3385 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3391 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3386 std::vector<PictureLayerImpl*>::iterator it = | 3392 std::vector<PictureLayerImpl*>::iterator it = |
3387 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3393 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3388 DCHECK(it != picture_layers_.end()); | 3394 DCHECK(it != picture_layers_.end()); |
3389 picture_layers_.erase(it); | 3395 picture_layers_.erase(it); |
3390 } | 3396 } |
3391 | 3397 |
3392 } // namespace cc | 3398 } // namespace cc |
OLD | NEW |