Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 1866583002: Connect LTHI::ScrollAnimated to cc::Viewport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 // notifications while preventing scroll updates from being unintentionally 2552 // notifications while preventing scroll updates from being unintentionally
2553 // forwarded to the main thread. The inner viewport layer represents the 2553 // forwarded to the main thread. The inner viewport layer represents the
2554 // viewport during scrolling. 2554 // viewport during scrolling.
2555 if (!potentially_scrolling_layer_impl) 2555 if (!potentially_scrolling_layer_impl)
2556 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); 2556 potentially_scrolling_layer_impl = InnerViewportScrollLayer();
2557 2557
2558 // The inner viewport layer represents the viewport. 2558 // The inner viewport layer represents the viewport.
2559 if (potentially_scrolling_layer_impl == OuterViewportScrollLayer()) 2559 if (potentially_scrolling_layer_impl == OuterViewportScrollLayer())
2560 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); 2560 potentially_scrolling_layer_impl = InnerViewportScrollLayer();
2561 2561
2562 // Animated wheel scrolls need to scroll the outer viewport layer, and do not
2563 // go through Viewport::ScrollBy which would normally handle the distribution.
2564 // NOTE: This will need refactoring if we want smooth scrolling on Android.
2565 if (type == ANIMATED_WHEEL &&
2566 potentially_scrolling_layer_impl == InnerViewportScrollLayer()) {
2567 potentially_scrolling_layer_impl = OuterViewportScrollLayer();
2568 }
2569
2570 return potentially_scrolling_layer_impl; 2562 return potentially_scrolling_layer_impl;
2571 } 2563 }
2572 2564
2573 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents. 2565 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents.
2574 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) { 2566 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) {
2575 DCHECK(scroll_ancestor); 2567 DCHECK(scroll_ancestor);
2576 if (!child) 2568 if (!child)
2577 return false; 2569 return false;
2578 ScrollTree& scroll_tree = 2570 ScrollTree& scroll_tree =
2579 child->layer_tree_impl()->property_trees()->scroll_tree; 2571 child->layer_tree_impl()->property_trees()->scroll_tree;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 scroll_node = scroll_tree.CurrentlyScrollingNode(); 2707 scroll_node = scroll_tree.CurrentlyScrollingNode();
2716 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { 2708 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) {
2717 ScrollStateData scroll_state_end_data; 2709 ScrollStateData scroll_state_end_data;
2718 scroll_state_end_data.is_ending = true; 2710 scroll_state_end_data.is_ending = true;
2719 ScrollState scroll_state_end(scroll_state_end_data); 2711 ScrollState scroll_state_end(scroll_state_end_data);
2720 ScrollEnd(&scroll_state_end); 2712 ScrollEnd(&scroll_state_end);
2721 } 2713 }
2722 return scroll_status; 2714 return scroll_status;
2723 } 2715 }
2724 2716
2717 LayerTreeHostImpl::ScrollAmount LayerTreeHostImpl::ComputeScrollDelta(
2718 ScrollNode* scroll_node,
2719 const gfx::Vector2dF& delta) {
2720 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree;
2721 float scale_factor = active_tree()->current_page_scale_factor();
2722
2723 gfx::Vector2dF adjusted_scroll(delta);
2724 adjusted_scroll.Scale(1.f / scale_factor);
2725 if (!scroll_node->data.user_scrollable_horizontal)
2726 adjusted_scroll.set_x(0);
2727 if (!scroll_node->data.user_scrollable_vertical)
2728 adjusted_scroll.set_y(0);
2729
2730 gfx::ScrollOffset old_offset =
2731 scroll_tree.current_scroll_offset(scroll_node->owner_id);
2732 gfx::ScrollOffset new_offset = scroll_tree.ClampScrollOffsetToLimits(
2733 old_offset + gfx::ScrollOffset(adjusted_scroll), scroll_node);
2734
2735 gfx::ScrollOffset scrolled = new_offset - old_offset;
2736 return ScrollAmount(gfx::Vector2dF(scrolled.x(), scrolled.y()), new_offset);
2737 }
2738
2739 bool LayerTreeHostImpl::ScrollAnimationCreate(
2740 ScrollNode* scroll_node,
2741 const LayerTreeHostImpl::ScrollAmount& amount) {
2742 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2743
2744 const float kEpsilon = 0.1f;
bokan 2016/04/06 13:35:52 Can you make sure this epsilon doesn't already exi
ymalik 2016/04/06 15:33:45 I don't think this will be used anywhere else so p
bokan 2016/04/06 19:38:23 Ok, don't make it static though.
2745 bool scroll_animated = (std::abs(amount.delta.x()) > kEpsilon ||
2746 std::abs(amount.delta.y()) > kEpsilon);
2747 if (!scroll_animated) {
2748 scroll_tree.ScrollBy(scroll_node, amount.delta, active_tree());
2749 return false;
2750 }
2751
2752 scroll_tree.set_currently_scrolling_node(scroll_node->id);
2753
2754 gfx::ScrollOffset current_offset =
2755 scroll_tree.current_scroll_offset(scroll_node->owner_id);
2756 animation_host_->ImplOnlyScrollAnimationCreate(
2757 scroll_node->owner_id, amount.target_offset, current_offset);
2758
2759 SetNeedsOneBeginImplFrame();
2760
2761 return true;
2762 }
2763
2725 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( 2764 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
2726 const gfx::Point& viewport_point, 2765 const gfx::Point& viewport_point,
2727 const gfx::Vector2dF& scroll_delta) { 2766 const gfx::Vector2dF& scroll_delta) {
2728 InputHandler::ScrollStatus scroll_status; 2767 InputHandler::ScrollStatus scroll_status;
2729 scroll_status.main_thread_scrolling_reasons = 2768 scroll_status.main_thread_scrolling_reasons =
2730 MainThreadScrollingReason::kNotScrollingOnMain; 2769 MainThreadScrollingReason::kNotScrollingOnMain;
2731 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2770 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2732 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 2771 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
2733 if (scroll_node) { 2772 if (scroll_node) {
2734 gfx::Vector2dF delta = scroll_delta; 2773 gfx::Vector2dF delta = scroll_delta;
(...skipping 22 matching lines...) Expand all
2757 // that can scroll and set up an animation of its scroll offset. Note that 2796 // that can scroll and set up an animation of its scroll offset. Note that
2758 // this does not currently go through the scroll customization and viewport 2797 // this does not currently go through the scroll customization and viewport
2759 // machinery that ScrollBy uses for non-animated wheel scrolls. 2798 // machinery that ScrollBy uses for non-animated wheel scrolls.
2760 scroll_status = ScrollBegin(&scroll_state, ANIMATED_WHEEL); 2799 scroll_status = ScrollBegin(&scroll_state, ANIMATED_WHEEL);
2761 scroll_node = scroll_tree.CurrentlyScrollingNode(); 2800 scroll_node = scroll_tree.CurrentlyScrollingNode();
2762 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { 2801 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) {
2763 gfx::Vector2dF pending_delta = scroll_delta; 2802 gfx::Vector2dF pending_delta = scroll_delta;
2764 if (scroll_node) { 2803 if (scroll_node) {
2765 for (; scroll_tree.parent(scroll_node); 2804 for (; scroll_tree.parent(scroll_node);
2766 scroll_node = scroll_tree.parent(scroll_node)) { 2805 scroll_node = scroll_tree.parent(scroll_node)) {
2767 if (!scroll_node->data.scrollable) 2806 if (!scroll_node->data.scrollable ||
2807 scroll_node->data.is_outer_viewport_scroll_layer)
2768 continue; 2808 continue;
2769 2809
2770 gfx::ScrollOffset current_offset = 2810 if (scroll_node->data.is_inner_viewport_scroll_layer) {
2771 scroll_tree.current_scroll_offset(scroll_node->owner_id); 2811 gfx::Vector2dF scrolled = viewport()->ScrollAnimated(pending_delta);
2772 gfx::ScrollOffset target_offset = 2812 // Viewport::ScrollAnimated returns pending_delta as long as it
2773 ScrollOffsetWithDelta(current_offset, pending_delta); 2813 // starts an animation.
2774 target_offset.SetToMax(gfx::ScrollOffset()); 2814 if (scrolled == pending_delta)
2775 target_offset.SetToMin(scroll_tree.MaxScrollOffset(scroll_node->id)); 2815 return scroll_status;
2776 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); 2816 pending_delta -= scrolled;
2777
2778 if (!scroll_node->data.user_scrollable_horizontal) {
2779 actual_delta.set_x(0);
2780 target_offset.set_x(current_offset.x());
2781 }
2782 if (!scroll_node->data.user_scrollable_vertical) {
2783 actual_delta.set_y(0);
2784 target_offset.set_y(current_offset.y());
2785 }
2786
2787 const float kEpsilon = 0.1f;
2788 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon ||
2789 std::abs(actual_delta.y()) > kEpsilon);
2790
2791 if (!can_layer_scroll) {
2792 scroll_tree.ScrollBy(scroll_node, actual_delta, active_tree());
2793 pending_delta -= actual_delta;
2794 continue; 2817 continue;
2795 } 2818 }
2796 2819
2797 scroll_tree.set_currently_scrolling_node(scroll_node->id); 2820 LayerTreeHostImpl::ScrollAmount scroll_amount =
2821 ComputeScrollDelta(scroll_node, pending_delta);
2822 if (ScrollAnimationCreate(scroll_node, scroll_amount))
2823 return scroll_status;
2798 2824
2799 ScrollAnimationCreate(scroll_node, target_offset, current_offset); 2825 pending_delta -= scroll_amount.delta;
2800
2801 SetNeedsOneBeginImplFrame();
2802 return scroll_status;
2803 } 2826 }
2804 } 2827 }
2805 } 2828 }
2806 scroll_state.set_is_ending(true); 2829 scroll_state.set_is_ending(true);
2807 ScrollEnd(&scroll_state); 2830 ScrollEnd(&scroll_state);
2808 return scroll_status; 2831 return scroll_status;
2809 } 2832 }
2810 2833
2811 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta( 2834 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta(
2812 ScrollNode* scroll_node, 2835 ScrollNode* scroll_node,
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 active_tree_->TotalScrollOffset(), active_tree_->TotalMaxScrollOffset(), 3754 active_tree_->TotalScrollOffset(), active_tree_->TotalMaxScrollOffset(),
3732 active_tree_->ScrollableSize(), active_tree_->current_page_scale_factor(), 3755 active_tree_->ScrollableSize(), active_tree_->current_page_scale_factor(),
3733 active_tree_->min_page_scale_factor(), 3756 active_tree_->min_page_scale_factor(),
3734 active_tree_->max_page_scale_factor()); 3757 active_tree_->max_page_scale_factor());
3735 } 3758 }
3736 3759
3737 void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) { 3760 void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) {
3738 return animation_host_->ScrollAnimationAbort(false /* needs_completion */); 3761 return animation_host_->ScrollAnimationAbort(false /* needs_completion */);
3739 } 3762 }
3740 3763
3741 void LayerTreeHostImpl::ScrollAnimationCreate(
3742 ScrollNode* scroll_node,
3743 const gfx::ScrollOffset& target_offset,
3744 const gfx::ScrollOffset& current_offset) {
3745 return animation_host_->ImplOnlyScrollAnimationCreate(
3746 scroll_node->owner_id, target_offset, current_offset);
3747 }
3748
3749 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( 3764 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget(
3750 ScrollNode* scroll_node, 3765 ScrollNode* scroll_node,
3751 const gfx::Vector2dF& scroll_delta) { 3766 const gfx::Vector2dF& scroll_delta) {
3752 return animation_host_->ImplOnlyScrollAnimationUpdateTarget( 3767 return animation_host_->ImplOnlyScrollAnimationUpdateTarget(
3753 scroll_node->owner_id, scroll_delta, 3768 scroll_node->owner_id, scroll_delta,
3754 active_tree_->property_trees()->scroll_tree.MaxScrollOffset( 3769 active_tree_->property_trees()->scroll_tree.MaxScrollOffset(
3755 scroll_node->id), 3770 scroll_node->id),
3756 CurrentBeginFrameArgs().frame_time); 3771 CurrentBeginFrameArgs().frame_time);
3757 } 3772 }
3758 3773
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3921 return task_runner_provider_->HasImplThread(); 3936 return task_runner_provider_->HasImplThread();
3922 } 3937 }
3923 3938
3924 bool LayerTreeHostImpl::CommitToActiveTree() const { 3939 bool LayerTreeHostImpl::CommitToActiveTree() const {
3925 // In single threaded mode we skip the pending tree and commit directly to the 3940 // In single threaded mode we skip the pending tree and commit directly to the
3926 // active tree. 3941 // active tree.
3927 return !task_runner_provider_->HasImplThread(); 3942 return !task_runner_provider_->HasImplThread();
3928 } 3943 }
3929 3944
3930 } // namespace cc 3945 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698