| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 432 } |
| 433 | 433 |
| 434 void LayerTreeHostImpl::StartPageScaleAnimation( | 434 void LayerTreeHostImpl::StartPageScaleAnimation( |
| 435 const gfx::Vector2d& target_offset, | 435 const gfx::Vector2d& target_offset, |
| 436 bool anchor_point, | 436 bool anchor_point, |
| 437 float page_scale, | 437 float page_scale, |
| 438 base::TimeDelta duration) { | 438 base::TimeDelta duration) { |
| 439 if (!InnerViewportScrollLayer()) | 439 if (!InnerViewportScrollLayer()) |
| 440 return; | 440 return; |
| 441 | 441 |
| 442 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 442 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); |
| 443 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 443 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
| 444 gfx::SizeF viewport_size = | 444 gfx::SizeF viewport_size = |
| 445 active_tree_->InnerViewportContainerLayer()->bounds(); | 445 active_tree_->InnerViewportContainerLayer()->bounds(); |
| 446 | 446 |
| 447 // Easing constants experimentally determined. | 447 // Easing constants experimentally determined. |
| 448 scoped_ptr<TimingFunction> timing_function = | 448 scoped_ptr<TimingFunction> timing_function = |
| 449 CubicBezierTimingFunction::Create(.8, 0, .3, .9); | 449 CubicBezierTimingFunction::Create(.8, 0, .3, .9); |
| 450 | 450 |
| 451 // TODO(miletus) : Pass in ScrollOffset. |
| 451 page_scale_animation_ = | 452 page_scale_animation_ = |
| 452 PageScaleAnimation::Create(scroll_total, | 453 PageScaleAnimation::Create(ScrollOffsetToVector2dF(scroll_total), |
| 453 active_tree_->total_page_scale_factor(), | 454 active_tree_->total_page_scale_factor(), |
| 454 viewport_size, | 455 viewport_size, |
| 455 scaled_scrollable_size, | 456 scaled_scrollable_size, |
| 456 timing_function.Pass()); | 457 timing_function.Pass()); |
| 457 | 458 |
| 458 if (anchor_point) { | 459 if (anchor_point) { |
| 459 gfx::Vector2dF anchor(target_offset); | 460 gfx::Vector2dF anchor(target_offset); |
| 460 page_scale_animation_->ZoomWithAnchor(anchor, | 461 page_scale_animation_->ZoomWithAnchor(anchor, |
| 461 page_scale, | 462 page_scale, |
| 462 duration.InSecondsF()); | 463 duration.InSecondsF()); |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 metadata.location_bar_content_translation = | 1485 metadata.location_bar_content_translation = |
| 1485 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); | 1486 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); |
| 1486 } | 1487 } |
| 1487 | 1488 |
| 1488 active_tree_->GetViewportSelection(&metadata.selection_start, | 1489 active_tree_->GetViewportSelection(&metadata.selection_start, |
| 1489 &metadata.selection_end); | 1490 &metadata.selection_end); |
| 1490 | 1491 |
| 1491 if (!InnerViewportScrollLayer()) | 1492 if (!InnerViewportScrollLayer()) |
| 1492 return metadata; | 1493 return metadata; |
| 1493 | 1494 |
| 1494 metadata.root_scroll_offset = active_tree_->TotalScrollOffset(); | 1495 // TODO(miletus) : Change the metadata to hold ScrollOffset. |
| 1496 metadata.root_scroll_offset = gfx::ScrollOffsetToVector2dF( |
| 1497 active_tree_->TotalScrollOffset()); |
| 1495 | 1498 |
| 1496 return metadata; | 1499 return metadata; |
| 1497 } | 1500 } |
| 1498 | 1501 |
| 1499 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { | 1502 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { |
| 1500 layer->DidBeginTracing(); | 1503 layer->DidBeginTracing(); |
| 1501 } | 1504 } |
| 1502 | 1505 |
| 1503 void LayerTreeHostImpl::DrawLayers(FrameData* frame, | 1506 void LayerTreeHostImpl::DrawLayers(FrameData* frame, |
| 1504 base::TimeTicks frame_begin_time) { | 1507 base::TimeTicks frame_begin_time) { |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2376 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { | 2379 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { |
| 2377 Animation* animation = | 2380 Animation* animation = |
| 2378 layer_impl->layer_animation_controller()->GetAnimation( | 2381 layer_impl->layer_animation_controller()->GetAnimation( |
| 2379 Animation::ScrollOffset); | 2382 Animation::ScrollOffset); |
| 2380 if (!animation) | 2383 if (!animation) |
| 2381 return ScrollIgnored; | 2384 return ScrollIgnored; |
| 2382 | 2385 |
| 2383 ScrollOffsetAnimationCurve* curve = | 2386 ScrollOffsetAnimationCurve* curve = |
| 2384 animation->curve()->ToScrollOffsetAnimationCurve(); | 2387 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 2385 | 2388 |
| 2386 gfx::Vector2dF new_target = curve->target_value() + scroll_delta; | 2389 gfx::ScrollOffset new_target = |
| 2387 new_target.SetToMax(gfx::Vector2dF()); | 2390 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); |
| 2391 new_target.SetToMax(gfx::ScrollOffset()); |
| 2388 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 2392 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
| 2389 | 2393 |
| 2390 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( | 2394 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( |
| 2391 CurrentBeginFrameArgs().frame_time), | 2395 CurrentBeginFrameArgs().frame_time), |
| 2392 new_target); | 2396 new_target); |
| 2393 | 2397 |
| 2394 return ScrollStarted; | 2398 return ScrollStarted; |
| 2395 } | 2399 } |
| 2396 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2400 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling |
| 2397 // behavior as ScrollBy to determine which layer to animate, but we do not | 2401 // behavior as ScrollBy to determine which layer to animate, but we do not |
| 2398 // do the Android-specific things in ScrollBy like showing top controls. | 2402 // do the Android-specific things in ScrollBy like showing top controls. |
| 2399 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); | 2403 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
| 2400 if (scroll_status == ScrollStarted) { | 2404 if (scroll_status == ScrollStarted) { |
| 2401 gfx::Vector2dF pending_delta = scroll_delta; | 2405 gfx::Vector2dF pending_delta = scroll_delta; |
| 2402 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2406 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
| 2403 layer_impl = layer_impl->parent()) { | 2407 layer_impl = layer_impl->parent()) { |
| 2404 if (!layer_impl->scrollable()) | 2408 if (!layer_impl->scrollable()) |
| 2405 continue; | 2409 continue; |
| 2406 | 2410 |
| 2407 gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset(); | 2411 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); |
| 2408 gfx::Vector2dF target_offset = current_offset + pending_delta; | 2412 gfx::ScrollOffset target_offset = |
| 2409 target_offset.SetToMax(gfx::Vector2dF()); | 2413 ScrollOffsetWithDelta(current_offset, pending_delta); |
| 2414 target_offset.SetToMax(gfx::ScrollOffset()); |
| 2410 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2415 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
| 2411 gfx::Vector2dF actual_delta = target_offset - current_offset; | 2416 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); |
| 2412 | 2417 |
| 2413 const float kEpsilon = 0.1f; | 2418 const float kEpsilon = 0.1f; |
| 2414 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || | 2419 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || |
| 2415 std::abs(actual_delta.y()) > kEpsilon); | 2420 std::abs(actual_delta.y()) > kEpsilon); |
| 2416 | 2421 |
| 2417 if (!can_layer_scroll) { | 2422 if (!can_layer_scroll) { |
| 2418 layer_impl->ScrollBy(actual_delta); | 2423 layer_impl->ScrollBy(actual_delta); |
| 2419 pending_delta -= actual_delta; | 2424 pending_delta -= actual_delta; |
| 2420 continue; | 2425 continue; |
| 2421 } | 2426 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2622 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2627 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
| 2623 break; | 2628 break; |
| 2624 } | 2629 } |
| 2625 | 2630 |
| 2626 // If the applied delta is within 45 degrees of the input delta, bail out to | 2631 // If the applied delta is within 45 degrees of the input delta, bail out to |
| 2627 // make it easier to scroll just one layer in one direction without | 2632 // make it easier to scroll just one layer in one direction without |
| 2628 // affecting any of its parents. | 2633 // affecting any of its parents. |
| 2629 float angle_threshold = 45; | 2634 float angle_threshold = 45; |
| 2630 if (MathUtil::SmallestAngleBetweenVectors( | 2635 if (MathUtil::SmallestAngleBetweenVectors( |
| 2631 applied_delta, pending_delta) < angle_threshold) { | 2636 applied_delta, pending_delta) < angle_threshold) { |
| 2632 pending_delta = gfx::Vector2d(); | 2637 pending_delta = gfx::Vector2dF(); |
| 2633 break; | 2638 break; |
| 2634 } | 2639 } |
| 2635 | 2640 |
| 2636 // Allow further movement only on an axis perpendicular to the direction in | 2641 // Allow further movement only on an axis perpendicular to the direction in |
| 2637 // which the layer moved. | 2642 // which the layer moved. |
| 2638 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); | 2643 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); |
| 2639 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); | 2644 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); |
| 2640 | 2645 |
| 2641 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) | 2646 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
| 2642 break; | 2647 break; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2979 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); | 2984 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); |
| 2980 | 2985 |
| 2981 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) | 2986 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) |
| 2982 InnerViewportScrollLayer()->ScrollBy(unused_delta); | 2987 InnerViewportScrollLayer()->ScrollBy(unused_delta); |
| 2983 } | 2988 } |
| 2984 | 2989 |
| 2985 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { | 2990 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { |
| 2986 if (!page_scale_animation_) | 2991 if (!page_scale_animation_) |
| 2987 return; | 2992 return; |
| 2988 | 2993 |
| 2989 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 2994 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset(); |
| 2990 | 2995 |
| 2991 if (!page_scale_animation_->IsAnimationStarted()) | 2996 if (!page_scale_animation_->IsAnimationStarted()) |
| 2992 page_scale_animation_->StartAnimation(monotonic_time); | 2997 page_scale_animation_->StartAnimation(monotonic_time); |
| 2993 | 2998 |
| 2994 active_tree_->SetPageScaleDelta( | 2999 active_tree_->SetPageScaleDelta( |
| 2995 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 3000 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
| 2996 active_tree_->page_scale_factor()); | 3001 active_tree_->page_scale_factor()); |
| 2997 gfx::Vector2dF next_scroll = | 3002 gfx::ScrollOffset next_scroll = gfx::ScrollOffset( |
| 2998 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 3003 page_scale_animation_->ScrollOffsetAtTime(monotonic_time)); |
| 2999 | 3004 |
| 3000 ScrollViewportInnerFirst(next_scroll - scroll_total); | 3005 ScrollViewportInnerFirst(next_scroll.DeltaFrom(scroll_total)); |
| 3001 SetNeedsRedraw(); | 3006 SetNeedsRedraw(); |
| 3002 | 3007 |
| 3003 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 3008 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
| 3004 page_scale_animation_ = nullptr; | 3009 page_scale_animation_ = nullptr; |
| 3005 client_->SetNeedsCommitOnImplThread(); | 3010 client_->SetNeedsCommitOnImplThread(); |
| 3006 client_->RenewTreePriority(); | 3011 client_->RenewTreePriority(); |
| 3007 } else { | 3012 } else { |
| 3008 SetNeedsAnimate(); | 3013 SetNeedsAnimate(); |
| 3009 } | 3014 } |
| 3010 } | 3015 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3400 } | 3405 } |
| 3401 | 3406 |
| 3402 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3407 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 3403 std::vector<PictureLayerImpl*>::iterator it = | 3408 std::vector<PictureLayerImpl*>::iterator it = |
| 3404 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3409 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
| 3405 DCHECK(it != picture_layers_.end()); | 3410 DCHECK(it != picture_layers_.end()); |
| 3406 picture_layers_.erase(it); | 3411 picture_layers_.erase(it); |
| 3407 } | 3412 } |
| 3408 | 3413 |
| 3409 } // namespace cc | 3414 } // namespace cc |
| OLD | NEW |