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

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: review comments 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 gfx::Vector2dF 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 gfx::Vector2dF(scrolled.x(), scrolled.y());
2737 }
2738
2739 bool LayerTreeHostImpl::ScrollAnimationCreate(ScrollNode* scroll_node,
2740 const gfx::Vector2dF& delta) {
2741 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2742
2743 const float kEpsilon = 0.1f;
2744 bool scroll_animated =
2745 (std::abs(delta.x()) > kEpsilon || std::abs(delta.y()) > kEpsilon);
2746 if (!scroll_animated) {
2747 scroll_tree.ScrollBy(scroll_node, delta, active_tree());
2748 return false;
2749 }
2750
2751 scroll_tree.set_currently_scrolling_node(scroll_node->id);
2752
2753 gfx::ScrollOffset current_offset =
2754 scroll_tree.current_scroll_offset(scroll_node->owner_id);
2755 gfx::ScrollOffset target_offset = scroll_tree.ClampScrollOffsetToLimits(
2756 current_offset + gfx::ScrollOffset(delta), scroll_node);
2757 animation_host_->ImplOnlyScrollAnimationCreate(scroll_node->owner_id,
2758 target_offset, current_offset);
2759
2760 SetNeedsOneBeginImplFrame();
2761
2762 return true;
2763 }
2764
2725 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( 2765 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
2726 const gfx::Point& viewport_point, 2766 const gfx::Point& viewport_point,
2727 const gfx::Vector2dF& scroll_delta) { 2767 const gfx::Vector2dF& scroll_delta) {
2728 InputHandler::ScrollStatus scroll_status; 2768 InputHandler::ScrollStatus scroll_status;
2729 scroll_status.main_thread_scrolling_reasons = 2769 scroll_status.main_thread_scrolling_reasons =
2730 MainThreadScrollingReason::kNotScrollingOnMain; 2770 MainThreadScrollingReason::kNotScrollingOnMain;
2731 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; 2771 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree;
2732 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); 2772 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode();
2733 if (scroll_node) { 2773 if (scroll_node) {
2734 gfx::Vector2dF delta = scroll_delta; 2774 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 2797 // 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 2798 // this does not currently go through the scroll customization and viewport
2759 // machinery that ScrollBy uses for non-animated wheel scrolls. 2799 // machinery that ScrollBy uses for non-animated wheel scrolls.
2760 scroll_status = ScrollBegin(&scroll_state, ANIMATED_WHEEL); 2800 scroll_status = ScrollBegin(&scroll_state, ANIMATED_WHEEL);
2761 scroll_node = scroll_tree.CurrentlyScrollingNode(); 2801 scroll_node = scroll_tree.CurrentlyScrollingNode();
2762 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { 2802 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) {
2763 gfx::Vector2dF pending_delta = scroll_delta; 2803 gfx::Vector2dF pending_delta = scroll_delta;
2764 if (scroll_node) { 2804 if (scroll_node) {
2765 for (; scroll_tree.parent(scroll_node); 2805 for (; scroll_tree.parent(scroll_node);
2766 scroll_node = scroll_tree.parent(scroll_node)) { 2806 scroll_node = scroll_tree.parent(scroll_node)) {
2767 if (!scroll_node->data.scrollable) 2807 if (!scroll_node->data.scrollable ||
2808 scroll_node->data.is_outer_viewport_scroll_layer)
2768 continue; 2809 continue;
2769 2810
2770 gfx::ScrollOffset current_offset = 2811 if (scroll_node->data.is_inner_viewport_scroll_layer) {
2771 scroll_tree.current_scroll_offset(scroll_node->owner_id); 2812 gfx::Vector2dF scrolled = viewport()->ScrollAnimated(pending_delta);
2772 gfx::ScrollOffset target_offset = 2813 // Viewport::ScrollAnimated returns pending_delta as long as it
2773 ScrollOffsetWithDelta(current_offset, pending_delta); 2814 // starts an animation.
2774 target_offset.SetToMax(gfx::ScrollOffset()); 2815 if (scrolled == pending_delta)
2775 target_offset.SetToMin(scroll_tree.MaxScrollOffset(scroll_node->id)); 2816 return scroll_status;
2776 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); 2817 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; 2818 continue;
2795 } 2819 }
2796 2820
2797 scroll_tree.set_currently_scrolling_node(scroll_node->id); 2821 gfx::Vector2dF scroll_delta =
2822 ComputeScrollDelta(scroll_node, pending_delta);
2823 if (ScrollAnimationCreate(scroll_node, scroll_delta))
2824 return scroll_status;
2798 2825
2799 ScrollAnimationCreate(scroll_node, target_offset, current_offset); 2826 pending_delta -= scroll_delta;
2800
2801 SetNeedsOneBeginImplFrame();
2802 return scroll_status;
2803 } 2827 }
2804 } 2828 }
2805 } 2829 }
2806 scroll_state.set_is_ending(true); 2830 scroll_state.set_is_ending(true);
2807 ScrollEnd(&scroll_state); 2831 ScrollEnd(&scroll_state);
2808 return scroll_status; 2832 return scroll_status;
2809 } 2833 }
2810 2834
2811 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta( 2835 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta(
2812 ScrollNode* scroll_node, 2836 ScrollNode* scroll_node,
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 active_tree_->TotalScrollOffset(), active_tree_->TotalMaxScrollOffset(), 3755 active_tree_->TotalScrollOffset(), active_tree_->TotalMaxScrollOffset(),
3732 active_tree_->ScrollableSize(), active_tree_->current_page_scale_factor(), 3756 active_tree_->ScrollableSize(), active_tree_->current_page_scale_factor(),
3733 active_tree_->min_page_scale_factor(), 3757 active_tree_->min_page_scale_factor(),
3734 active_tree_->max_page_scale_factor()); 3758 active_tree_->max_page_scale_factor());
3735 } 3759 }
3736 3760
3737 void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) { 3761 void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) {
3738 return animation_host_->ScrollAnimationAbort(false /* needs_completion */); 3762 return animation_host_->ScrollAnimationAbort(false /* needs_completion */);
3739 } 3763 }
3740 3764
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( 3765 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget(
3750 ScrollNode* scroll_node, 3766 ScrollNode* scroll_node,
3751 const gfx::Vector2dF& scroll_delta) { 3767 const gfx::Vector2dF& scroll_delta) {
3752 return animation_host_->ImplOnlyScrollAnimationUpdateTarget( 3768 return animation_host_->ImplOnlyScrollAnimationUpdateTarget(
3753 scroll_node->owner_id, scroll_delta, 3769 scroll_node->owner_id, scroll_delta,
3754 active_tree_->property_trees()->scroll_tree.MaxScrollOffset( 3770 active_tree_->property_trees()->scroll_tree.MaxScrollOffset(
3755 scroll_node->id), 3771 scroll_node->id),
3756 CurrentBeginFrameArgs().frame_time); 3772 CurrentBeginFrameArgs().frame_time);
3757 } 3773 }
3758 3774
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3921 return task_runner_provider_->HasImplThread(); 3937 return task_runner_provider_->HasImplThread();
3922 } 3938 }
3923 3939
3924 bool LayerTreeHostImpl::CommitToActiveTree() const { 3940 bool LayerTreeHostImpl::CommitToActiveTree() const {
3925 // In single threaded mode we skip the pending tree and commit directly to the 3941 // In single threaded mode we skip the pending tree and commit directly to the
3926 // active tree. 3942 // active tree.
3927 return !task_runner_provider_->HasImplThread(); 3943 return !task_runner_provider_->HasImplThread();
3928 } 3944 }
3929 3945
3930 } // namespace cc 3946 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698