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

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

Issue 1365343002: Ensure the viewport is always represented by the inner viewport layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more tests. Created 5 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
« no previous file with comments | « cc/trees/layer_tree_host.cc ('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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 void LayerTreeHostImpl::SetNeedsAnimateInput() { 492 void LayerTreeHostImpl::SetNeedsAnimateInput() {
493 DCHECK_IMPLIES(IsCurrentlyScrollingRoot(), 493 DCHECK_IMPLIES(IsCurrentlyScrollingRoot(),
494 !settings_.ignore_root_layer_flings); 494 !settings_.ignore_root_layer_flings);
495 SetNeedsAnimate(); 495 SetNeedsAnimate();
496 } 496 }
497 497
498 bool LayerTreeHostImpl::IsCurrentlyScrollingRoot() const { 498 bool LayerTreeHostImpl::IsCurrentlyScrollingRoot() const {
499 LayerImpl* scrolling_layer = CurrentlyScrollingLayer(); 499 LayerImpl* scrolling_layer = CurrentlyScrollingLayer();
500 if (!scrolling_layer) 500 if (!scrolling_layer)
501 return false; 501 return false;
502 return scrolling_layer == InnerViewportScrollLayer() || 502 return scrolling_layer == InnerViewportScrollLayer();
503 scrolling_layer == OuterViewportScrollLayer();
504 } 503 }
505 504
506 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( 505 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt(
507 const gfx::Point& viewport_point, 506 const gfx::Point& viewport_point,
508 InputHandler::ScrollInputType type) const { 507 InputHandler::ScrollInputType type) const {
509 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); 508 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer();
510 if (!scrolling_layer_impl) 509 if (!scrolling_layer_impl)
511 return false; 510 return false;
512 511
513 gfx::PointF device_viewport_point = 512 gfx::PointF device_viewport_point =
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 *optional_has_ancestor_scroll_handler = true; 2365 *optional_has_ancestor_scroll_handler = true;
2367 2366
2368 if (status == SCROLL_STARTED && !potentially_scrolling_layer_impl) 2367 if (status == SCROLL_STARTED && !potentially_scrolling_layer_impl)
2369 potentially_scrolling_layer_impl = scroll_layer_impl; 2368 potentially_scrolling_layer_impl = scroll_layer_impl;
2370 } 2369 }
2371 2370
2372 // Falling back to the root scroll layer ensures generation of root overscroll 2371 // Falling back to the root scroll layer ensures generation of root overscroll
2373 // notifications while preventing scroll updates from being unintentionally 2372 // notifications while preventing scroll updates from being unintentionally
2374 // forwarded to the main thread. 2373 // forwarded to the main thread.
2375 if (!potentially_scrolling_layer_impl) 2374 if (!potentially_scrolling_layer_impl)
2376 potentially_scrolling_layer_impl = OuterViewportScrollLayer() 2375 potentially_scrolling_layer_impl = InnerViewportScrollLayer();
2377 ? OuterViewportScrollLayer() 2376
2378 : InnerViewportScrollLayer(); 2377 // The inner viewport layer represents the viewport.
2378 if (potentially_scrolling_layer_impl == OuterViewportScrollLayer())
2379 potentially_scrolling_layer_impl = InnerViewportScrollLayer();
2379 2380
2380 return potentially_scrolling_layer_impl; 2381 return potentially_scrolling_layer_impl;
2381 } 2382 }
2382 2383
2383 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents. 2384 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents.
2384 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) { 2385 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) {
2385 DCHECK(scroll_ancestor); 2386 DCHECK(scroll_ancestor);
2386 for (LayerImpl* ancestor = child; ancestor; 2387 for (LayerImpl* ancestor = child; ancestor;
2387 ancestor = NextLayerInScrollOrder(ancestor)) { 2388 ancestor = NextLayerInScrollOrder(ancestor)) {
2388 if (ancestor->scrollable()) 2389 if (ancestor->scrollable())
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 ? SCROLL_STARTED 2460 ? SCROLL_STARTED
2460 : SCROLL_IGNORED; 2461 : SCROLL_IGNORED;
2461 } 2462 }
2462 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling 2463 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling
2463 // behavior as ScrollBy to determine which layer to animate, but we do not 2464 // behavior as ScrollBy to determine which layer to animate, but we do not
2464 // do the Android-specific things in ScrollBy like showing top controls. 2465 // do the Android-specific things in ScrollBy like showing top controls.
2465 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL); 2466 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL);
2466 if (scroll_status == SCROLL_STARTED) { 2467 if (scroll_status == SCROLL_STARTED) {
2467 gfx::Vector2dF pending_delta = scroll_delta; 2468 gfx::Vector2dF pending_delta = scroll_delta;
2468 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; 2469 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
2469 layer_impl = layer_impl->parent()) { 2470 layer_impl = NextLayerInScrollOrder(layer_impl)) {
2470 if (!layer_impl->scrollable()) 2471 // The inner viewport layer represents the viewport.
2472 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer())
2471 continue; 2473 continue;
2472 2474
2473 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); 2475 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset();
2474 gfx::ScrollOffset target_offset = 2476 gfx::ScrollOffset target_offset =
2475 ScrollOffsetWithDelta(current_offset, pending_delta); 2477 ScrollOffsetWithDelta(current_offset, pending_delta);
2476 target_offset.SetToMax(gfx::ScrollOffset()); 2478 target_offset.SetToMax(gfx::ScrollOffset());
2477 target_offset.SetToMin(layer_impl->MaxScrollOffset()); 2479 target_offset.SetToMin(layer_impl->MaxScrollOffset());
2478 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); 2480 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset);
2479 2481
2480 const float kEpsilon = 0.1f; 2482 const float kEpsilon = 0.1f;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2736 return scroll_result; 2738 return scroll_result;
2737 } 2739 }
2738 2740
2739 // This implements scrolling by page as described here: 2741 // This implements scrolling by page as described here:
2740 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel 2742 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel
2741 // for events with WHEEL_PAGESCROLL set. 2743 // for events with WHEEL_PAGESCROLL set.
2742 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, 2744 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point,
2743 ScrollDirection direction) { 2745 ScrollDirection direction) {
2744 DCHECK(wheel_scrolling_); 2746 DCHECK(wheel_scrolling_);
2745 2747
2746 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); 2748 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
2747 layer_impl; 2749 layer_impl = NextLayerInScrollOrder(layer_impl)) {
2748 layer_impl = layer_impl->parent()) { 2750 // The inner viewport layer represents the viewport.
2749 if (!layer_impl->scrollable()) 2751 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer())
2750 continue; 2752 continue;
2751 2753
2752 if (!layer_impl->HasScrollbar(VERTICAL)) 2754 if (!layer_impl->HasScrollbar(VERTICAL))
2753 continue; 2755 continue;
2754 2756
2755 float height = layer_impl->clip_height(); 2757 float height = layer_impl->clip_height();
2756 2758
2757 // These magical values match WebKit and are designed to scroll nearly the 2759 // These magical values match WebKit and are designed to scroll nearly the
2758 // entire visible content height but leave a bit of overlap. 2760 // entire visible content height but leave a bit of overlap.
2759 float page = std::max(height * 0.875f, 1.f); 2761 float page = std::max(height * 0.875f, 1.f);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 void LayerTreeHostImpl::ScrollEnd() { 2805 void LayerTreeHostImpl::ScrollEnd() {
2804 top_controls_manager_->ScrollEnd(); 2806 top_controls_manager_->ScrollEnd();
2805 ClearCurrentlyScrollingLayer(); 2807 ClearCurrentlyScrollingLayer();
2806 } 2808 }
2807 2809
2808 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { 2810 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
2809 if (!CurrentlyScrollingLayer()) 2811 if (!CurrentlyScrollingLayer())
2810 return SCROLL_IGNORED; 2812 return SCROLL_IGNORED;
2811 2813
2812 bool currently_scrolling_viewport = 2814 bool currently_scrolling_viewport =
2813 CurrentlyScrollingLayer() == OuterViewportScrollLayer() ||
2814 CurrentlyScrollingLayer() == InnerViewportScrollLayer(); 2815 CurrentlyScrollingLayer() == InnerViewportScrollLayer();
2815 if (!wheel_scrolling_ && !currently_scrolling_viewport) { 2816 if (!wheel_scrolling_ && !currently_scrolling_viewport) {
2816 // Allow the fling to lock to the first layer that moves after the initial 2817 // Allow the fling to lock to the first layer that moves after the initial
2817 // fling |ScrollBy()| event, unless we're already scrolling the viewport. 2818 // fling |ScrollBy()| event, unless we're already scrolling the viewport.
2818 did_lock_scrolling_layer_ = false; 2819 did_lock_scrolling_layer_ = false;
2819 should_bubble_scrolls_ = false; 2820 should_bubble_scrolls_ = false;
2820 } 2821 }
2821 2822
2822 return SCROLL_STARTED; 2823 return SCROLL_STARTED;
2823 } 2824 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2901 return true; 2902 return true;
2902 } 2903 }
2903 2904
2904 return false; 2905 return false;
2905 } 2906 }
2906 2907
2907 void LayerTreeHostImpl::PinchGestureBegin() { 2908 void LayerTreeHostImpl::PinchGestureBegin() {
2908 pinch_gesture_active_ = true; 2909 pinch_gesture_active_ = true;
2909 client_->RenewTreePriority(); 2910 client_->RenewTreePriority();
2910 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); 2911 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer();
2911 if (active_tree_->OuterViewportScrollLayer()) { 2912 active_tree_->SetCurrentlyScrollingLayer(
2912 active_tree_->SetCurrentlyScrollingLayer( 2913 active_tree_->InnerViewportScrollLayer());
2913 active_tree_->OuterViewportScrollLayer());
2914 } else {
2915 active_tree_->SetCurrentlyScrollingLayer(
2916 active_tree_->InnerViewportScrollLayer());
2917 }
2918 top_controls_manager_->PinchBegin(); 2914 top_controls_manager_->PinchBegin();
2919 } 2915 }
2920 2916
2921 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, 2917 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
2922 const gfx::Point& anchor) { 2918 const gfx::Point& anchor) {
2923 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); 2919 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate");
2924 if (!InnerViewportScrollLayer()) 2920 if (!InnerViewportScrollLayer())
2925 return; 2921 return;
2926 viewport()->PinchUpdate(magnify_delta, anchor); 2922 viewport()->PinchUpdate(magnify_delta, anchor);
2927 client_->SetNeedsCommitOnImplThread(); 2923 client_->SetNeedsCommitOnImplThread();
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 if (active_tree()) { 3610 if (active_tree()) {
3615 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); 3611 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id);
3616 if (layer) 3612 if (layer)
3617 return layer->ScrollOffsetForAnimation(); 3613 return layer->ScrollOffsetForAnimation();
3618 } 3614 }
3619 3615
3620 return gfx::ScrollOffset(); 3616 return gfx::ScrollOffset();
3621 } 3617 }
3622 3618
3623 } // namespace cc 3619 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698