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

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

Issue 25629006: Suppress scrolls that begin on fixed-pos layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | content/renderer/gpu/input_handler_proxy.h » ('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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 active_tree_->UpdateDrawProperties(); 1920 active_tree_->UpdateDrawProperties();
1921 return !active_tree_->RenderSurfaceLayerList().empty(); 1921 return !active_tree_->RenderSurfaceLayerList().empty();
1922 } 1922 }
1923 1923
1924 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { 1924 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) {
1925 DCHECK(input_handler_client_ == NULL); 1925 DCHECK(input_handler_client_ == NULL);
1926 input_handler_client_ = client; 1926 input_handler_client_ = client;
1927 } 1927 }
1928 1928
1929 static LayerImpl* NextScrollLayer(LayerImpl* layer) { 1929 static LayerImpl* NextScrollLayer(LayerImpl* layer) {
1930 if (layer->position_constraint().is_fixed_position())
1931 return NULL;
1930 if (LayerImpl* scroll_parent = layer->scroll_parent()) 1932 if (LayerImpl* scroll_parent = layer->scroll_parent())
1931 return scroll_parent; 1933 return scroll_parent;
1932 return layer->parent(); 1934 return layer->parent();
1933 } 1935 }
1934 1936
1935 LayerImpl* LayerTreeHostImpl::FindScrollLayerForViewportPoint( 1937 LayerImpl* LayerTreeHostImpl::FindScrollLayerForViewportPoint(
1936 gfx::Point viewport_point, InputHandler::ScrollInputType type, 1938 gfx::Point viewport_point, InputHandler::ScrollInputType type,
1937 bool* scroll_on_main_thread) { 1939 bool* scroll_on_main_thread) const {
1938 DCHECK(scroll_on_main_thread); 1940 DCHECK(scroll_on_main_thread);
1939 1941
1940 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point, 1942 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point,
1941 device_scale_factor_); 1943 device_scale_factor_);
1942 1944
1943 // First find out which layer was hit from the saved list of visible layers 1945 // First find out which layer was hit from the saved list of visible layers
1944 // in the most recent frame. 1946 // in the most recent frame.
1945 LayerImpl* layer_impl = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 1947 LayerImpl* layer_impl = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
1946 device_viewport_point, active_tree_->RenderSurfaceLayerList()); 1948 device_viewport_point, active_tree_->RenderSurfaceLayerList());
1947 1949
(...skipping 12 matching lines...) Expand all
1960 if (!scroll_layer_impl) 1962 if (!scroll_layer_impl)
1961 continue; 1963 continue;
1962 1964
1963 status = scroll_layer_impl->TryScroll(device_viewport_point, type); 1965 status = scroll_layer_impl->TryScroll(device_viewport_point, type);
1964 // If any layer wants to divert the scroll event to the main thread, abort. 1966 // If any layer wants to divert the scroll event to the main thread, abort.
1965 if (status == ScrollOnMainThread) { 1967 if (status == ScrollOnMainThread) {
1966 *scroll_on_main_thread = true; 1968 *scroll_on_main_thread = true;
1967 return NULL; 1969 return NULL;
1968 } 1970 }
1969 1971
1970 if (status == ScrollStarted && !potentially_scrolling_layer_impl) 1972 if ((layer_impl == RootScrollLayer() || status == ScrollStarted) &&
1971 potentially_scrolling_layer_impl = scroll_layer_impl; 1973 !potentially_scrolling_layer_impl)
1972 } 1974 potentially_scrolling_layer_impl = scroll_layer_impl;
1973
1974 // When hiding top controls is enabled and the controls are hidden or
1975 // overlaying the content, force scrolls to be enabled on the root layer to
1976 // allow bringing the top controls back into view.
1977 if (!potentially_scrolling_layer_impl && top_controls_manager_ &&
1978 top_controls_manager_->content_top_offset() !=
1979 settings_.top_controls_height) {
1980 potentially_scrolling_layer_impl = RootScrollLayer();
1981 } 1975 }
1982 1976
1983 return potentially_scrolling_layer_impl; 1977 return potentially_scrolling_layer_impl;
1984 } 1978 }
1985 1979
1986 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( 1980 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
1987 gfx::Point viewport_point, InputHandler::ScrollInputType type) { 1981 gfx::Point viewport_point, InputHandler::ScrollInputType type) {
1988 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); 1982 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
1989 1983
1990 if (top_controls_manager_) 1984 if (top_controls_manager_)
1991 top_controls_manager_->ScrollBegin(); 1985 top_controls_manager_->ScrollBegin();
1992 1986
1993 DCHECK(!CurrentlyScrollingLayer()); 1987 DCHECK(!CurrentlyScrollingLayer());
1994 ClearCurrentlyScrollingLayer(); 1988 ClearCurrentlyScrollingLayer();
1995 1989
1996 if (!EnsureRenderSurfaceLayerList()) 1990 if (!EnsureRenderSurfaceLayerList())
1997 return ScrollIgnored; 1991 return ScrollIgnored;
1998 1992
1999 bool scroll_on_main_thread = false; 1993 bool scroll_on_main_thread = false;
2000 LayerImpl* potentially_scrolling_layer_impl = FindScrollLayerForViewportPoint( 1994 LayerImpl* potentially_scrolling_layer_impl = FindScrollLayerForViewportPoint(
2001 viewport_point, type, &scroll_on_main_thread); 1995 viewport_point, type, &scroll_on_main_thread);
2002 1996
2003 if (scroll_on_main_thread) { 1997 if (scroll_on_main_thread) {
2004 rendering_stats_instrumentation_->IncrementMainThreadScrolls(); 1998 rendering_stats_instrumentation_->IncrementMainThreadScrolls();
2005 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); 1999 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true);
2006 return ScrollOnMainThread; 2000 return ScrollOnMainThread;
2007 } 2001 }
2008 2002
2009 // If we want to send a DidOverscroll for this scroll it can't be ignored.
2010 if (!potentially_scrolling_layer_impl && settings_.always_overscroll)
2011 potentially_scrolling_layer_impl = RootScrollLayer();
2012
2013 if (potentially_scrolling_layer_impl) { 2003 if (potentially_scrolling_layer_impl) {
2014 active_tree_->SetCurrentlyScrollingLayer( 2004 active_tree_->SetCurrentlyScrollingLayer(
2015 potentially_scrolling_layer_impl); 2005 potentially_scrolling_layer_impl);
2016 should_bubble_scrolls_ = (type != NonBubblingGesture); 2006 should_bubble_scrolls_ = (type != NonBubblingGesture);
2017 wheel_scrolling_ = (type == Wheel); 2007 wheel_scrolling_ = (type == Wheel);
2018 rendering_stats_instrumentation_->IncrementImplThreadScrolls(); 2008 rendering_stats_instrumentation_->IncrementImplThreadScrolls();
2019 client_->RenewTreePriority(); 2009 client_->RenewTreePriority();
2020 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); 2010 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false);
2021 return ScrollStarted; 2011 return ScrollStarted;
2022 } 2012 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2115 gfx::Vector2dF pending_delta = scroll_delta; 2105 gfx::Vector2dF pending_delta = scroll_delta;
2116 gfx::Vector2dF unused_root_delta; 2106 gfx::Vector2dF unused_root_delta;
2117 bool did_scroll_x = false; 2107 bool did_scroll_x = false;
2118 bool did_scroll_y = false; 2108 bool did_scroll_y = false;
2119 bool consume_by_top_controls = top_controls_manager_ && 2109 bool consume_by_top_controls = top_controls_manager_ &&
2120 (CurrentlyScrollingLayer() == RootScrollLayer() || scroll_delta.y() < 0); 2110 (CurrentlyScrollingLayer() == RootScrollLayer() || scroll_delta.y() < 0);
2121 2111
2122 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); 2112 for (LayerImpl* layer_impl = CurrentlyScrollingLayer();
2123 layer_impl; 2113 layer_impl;
2124 layer_impl = layer_impl->parent()) { 2114 layer_impl = layer_impl->parent()) {
2125 if (!layer_impl->scrollable()) 2115 if (!layer_impl->scrollable()) {
2116 if (layer_impl->position_constraint().is_fixed_position()) {
2117 break;
2118 }
2126 continue; 2119 continue;
2120 }
2127 2121
2128 if (layer_impl == RootScrollLayer()) { 2122 if (layer_impl == RootScrollLayer()) {
2129 // Only allow bubble scrolling when the scroll is in the direction to make 2123 // Only allow bubble scrolling when the scroll is in the direction to make
2130 // the top controls visible. 2124 // the top controls visible.
2131 if (consume_by_top_controls && layer_impl == RootScrollLayer()) { 2125 if (consume_by_top_controls && layer_impl == RootScrollLayer()) {
2132 pending_delta = top_controls_manager_->ScrollBy(pending_delta); 2126 pending_delta = top_controls_manager_->ScrollBy(pending_delta);
2133 UpdateMaxScrollOffset(); 2127 UpdateMaxScrollOffset();
2134 } 2128 }
2135 // Track root layer deltas for reporting overscroll. 2129 // Track root layer deltas for reporting overscroll.
2136 unused_root_delta = pending_delta; 2130 unused_root_delta = pending_delta;
(...skipping 14 matching lines...) Expand all
2151 applied_delta = ScrollLayerWithLocalDelta(layer_impl, pending_delta); 2145 applied_delta = ScrollLayerWithLocalDelta(layer_impl, pending_delta);
2152 } 2146 }
2153 2147
2154 // If the layer wasn't able to move, try the next one in the hierarchy. 2148 // If the layer wasn't able to move, try the next one in the hierarchy.
2155 float move_threshold = 0.1f; 2149 float move_threshold = 0.1f;
2156 bool did_move_layer_x = std::abs(applied_delta.x()) > move_threshold; 2150 bool did_move_layer_x = std::abs(applied_delta.x()) > move_threshold;
2157 bool did_move_layer_y = std::abs(applied_delta.y()) > move_threshold; 2151 bool did_move_layer_y = std::abs(applied_delta.y()) > move_threshold;
2158 did_scroll_x |= did_move_layer_x; 2152 did_scroll_x |= did_move_layer_x;
2159 did_scroll_y |= did_move_layer_y; 2153 did_scroll_y |= did_move_layer_y;
2160 if (!did_move_layer_x && !did_move_layer_y) { 2154 if (!did_move_layer_x && !did_move_layer_y) {
2161 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) 2155 if (layer_impl->position_constraint().is_fixed_position())
2156 break;
2157 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) {
2162 continue; 2158 continue;
2163 else 2159 } else {
2164 break; 2160 break;
2161 }
2165 } 2162 }
2166 2163
2167 if (layer_impl == RootScrollLayer()) 2164 if (layer_impl == RootScrollLayer())
2168 unused_root_delta.Subtract(applied_delta); 2165 unused_root_delta.Subtract(applied_delta);
2169 2166
2170 did_lock_scrolling_layer_ = true; 2167 did_lock_scrolling_layer_ = true;
2171 if (!should_bubble_scrolls_) { 2168 if (!should_bubble_scrolls_) {
2172 active_tree_->SetCurrentlyScrollingLayer(layer_impl); 2169 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
2173 break; 2170 break;
2174 } 2171 }
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 std::set<UIResourceId>::iterator found_in_evicted = 2784 std::set<UIResourceId>::iterator found_in_evicted =
2788 evicted_ui_resources_.find(uid); 2785 evicted_ui_resources_.find(uid);
2789 if (found_in_evicted == evicted_ui_resources_.end()) 2786 if (found_in_evicted == evicted_ui_resources_.end())
2790 return; 2787 return;
2791 evicted_ui_resources_.erase(found_in_evicted); 2788 evicted_ui_resources_.erase(found_in_evicted);
2792 if (evicted_ui_resources_.empty()) 2789 if (evicted_ui_resources_.empty())
2793 client_->OnCanDrawStateChanged(CanDraw()); 2790 client_->OnCanDrawStateChanged(CanDraw());
2794 } 2791 }
2795 2792
2796 } // namespace cc 2793 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | content/renderer/gpu/input_handler_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698