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 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 2592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2603 layer_impl->CurrentScrollOffset() - previous_offset; | 2603 layer_impl->CurrentScrollOffset() - previous_offset; |
2604 gfx::Vector2dF consumed_scroll(scrolled.x(), scrolled.y()); | 2604 gfx::Vector2dF consumed_scroll(scrolled.x(), scrolled.y()); |
2605 consumed_scroll.Scale(page_scale_factor); | 2605 consumed_scroll.Scale(page_scale_factor); |
2606 | 2606 |
2607 return consumed_scroll; | 2607 return consumed_scroll; |
2608 } | 2608 } |
2609 | 2609 |
2610 gfx::Vector2dF LayerTreeHostImpl::ScrollLayer(LayerImpl* layer_impl, | 2610 gfx::Vector2dF LayerTreeHostImpl::ScrollLayer(LayerImpl* layer_impl, |
2611 const gfx::Vector2dF& delta, | 2611 const gfx::Vector2dF& delta, |
2612 const gfx::Point& viewport_point, | 2612 const gfx::Point& viewport_point, |
2613 bool is_wheel_scroll) { | 2613 bool is_direct_manipulation) { |
2614 // Gesture events need to be transformed from viewport coordinates to | 2614 // Events representing direct manipulation of the screen (such as gesture |
2615 // local layer coordinates so that the scrolling contents exactly follow | 2615 // events) need to be transformed from viewport coordinates to local layer |
2616 // the user's finger. In contrast, wheel events represent a fixed amount | 2616 // coordinates so that the scrolling contents exactly follow the user's |
2617 // of scrolling so we can just apply them directly, but the page scale | 2617 // finger. In contrast, events not representing direct manipulation of the |
2618 // factor is applied to the scroll delta. | 2618 // screen (such as wheel events) represent a fixed amount of scrolling so we |
2619 if (is_wheel_scroll) { | 2619 // can just apply them directly, but the page scale factor is applied to the |
2620 float scale_factor = active_tree()->current_page_scale_factor(); | 2620 // scroll delta. |
2621 return ScrollLayerWithLocalDelta(layer_impl, | 2621 if (is_direct_manipulation) |
Ian Vollick
2015/07/06 15:33:16
It looks like there's a real behavior change here.
tdresser
2015/07/06 15:39:29
Nope, no behavior change. With scroll customizatio
| |
2622 delta, | 2622 return ScrollLayerWithViewportSpaceDelta(layer_impl, viewport_point, delta); |
2623 scale_factor); | 2623 float scale_factor = active_tree()->current_page_scale_factor(); |
2624 } | 2624 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor); |
2625 | |
2626 return ScrollLayerWithViewportSpaceDelta(layer_impl, | |
2627 viewport_point, | |
2628 delta); | |
2629 } | 2625 } |
2630 | 2626 |
2631 static LayerImpl* nextLayerInScrollOrder(LayerImpl* layer) { | 2627 static LayerImpl* nextLayerInScrollOrder(LayerImpl* layer) { |
2632 if (layer->scroll_parent()) | 2628 if (layer->scroll_parent()) |
2633 return layer->scroll_parent(); | 2629 return layer->scroll_parent(); |
2634 | 2630 |
2635 return layer->parent(); | 2631 return layer->parent(); |
2636 } | 2632 } |
2637 | 2633 |
2638 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( | 2634 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( |
2639 const gfx::Point& viewport_point, | 2635 const gfx::Point& viewport_point, |
2640 const gfx::Vector2dF& scroll_delta) { | 2636 const gfx::Vector2dF& scroll_delta) { |
2641 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 2637 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
2642 if (!CurrentlyScrollingLayer()) | 2638 if (!CurrentlyScrollingLayer()) |
2643 return InputHandlerScrollResult(); | 2639 return InputHandlerScrollResult(); |
2644 | 2640 |
2645 gfx::Vector2dF pending_delta = scroll_delta; | 2641 gfx::Vector2dF pending_delta = scroll_delta; |
2646 gfx::Vector2dF unused_root_delta; | 2642 gfx::Vector2dF unused_root_delta; |
2647 bool did_scroll_x = false; | 2643 bool did_scroll_x = false; |
2648 bool did_scroll_y = false; | 2644 bool did_scroll_y = false; |
2649 bool did_scroll_top_controls = false; | |
2650 | 2645 |
2651 if (pinch_gesture_active_ && settings().invert_viewport_scroll_order) { | 2646 if (pinch_gesture_active_ && settings().invert_viewport_scroll_order) { |
2652 // Scrolls during a pinch gesture should pan the visual viewport, rather | 2647 // Scrolls during a pinch gesture should pan the visual viewport, rather |
2653 // than a typical bubbling scroll. | 2648 // than a typical bubbling scroll. |
2654 viewport()->Pan(pending_delta); | 2649 viewport()->Pan(pending_delta); |
2655 return InputHandlerScrollResult(); | 2650 return InputHandlerScrollResult(); |
2656 } | 2651 } |
2657 | 2652 |
2658 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2653 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2659 layer_impl; | 2654 layer_impl; |
2660 layer_impl = nextLayerInScrollOrder(layer_impl)) { | 2655 layer_impl = nextLayerInScrollOrder(layer_impl)) { |
2661 // Skip the outer viewport scroll layer so that we try to scroll the | 2656 // Skip the outer viewport scroll layer so that we try to scroll the |
2662 // viewport only once. i.e. The inner viewport layer represents the | 2657 // viewport only once. i.e. The inner viewport layer represents the |
2663 // viewport. | 2658 // viewport. |
2664 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer()) | 2659 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer()) |
2665 continue; | 2660 continue; |
2666 | 2661 |
2667 gfx::Vector2dF applied_delta; | 2662 gfx::Vector2dF applied_delta; |
2668 if (layer_impl == InnerViewportScrollLayer()) { | 2663 if (layer_impl == InnerViewportScrollLayer()) { |
2669 bool affect_top_controls = true; | 2664 bool affect_top_controls = true; |
2670 Viewport::ScrollResult result = viewport()->ScrollBy(pending_delta, | 2665 applied_delta = |
2671 viewport_point, | 2666 viewport()->ScrollBy(pending_delta, viewport_point, !wheel_scrolling_, |
2672 wheel_scrolling_, | 2667 affect_top_controls); |
2673 affect_top_controls); | 2668 unused_root_delta = pending_delta - applied_delta; |
2674 applied_delta = result.applied_delta; | |
2675 unused_root_delta = result.unused_scroll_delta; | |
2676 did_scroll_top_controls = result.top_controls_applied_delta.y() != 0; | |
2677 } else { | 2669 } else { |
2678 applied_delta = ScrollLayer(layer_impl, | 2670 applied_delta = ScrollLayer(layer_impl, pending_delta, viewport_point, |
2679 pending_delta, | 2671 !wheel_scrolling_); |
2680 viewport_point, | |
2681 wheel_scrolling_); | |
2682 } | 2672 } |
2683 | 2673 |
2684 // If the layer wasn't able to move, try the next one in the hierarchy. | 2674 // If the layer wasn't able to move, try the next one in the hierarchy. |
2685 const float kEpsilon = 0.1f; | 2675 const float kEpsilon = 0.1f; |
2686 bool did_move_layer_x = std::abs(applied_delta.x()) > kEpsilon; | 2676 bool did_layer_consume_delta_x = std::abs(applied_delta.x()) > kEpsilon; |
2687 bool did_move_layer_y = std::abs(applied_delta.y()) > kEpsilon; | 2677 bool did_layer_consume_delta_y = std::abs(applied_delta.y()) > kEpsilon; |
2688 did_scroll_x |= did_move_layer_x; | |
2689 did_scroll_y |= did_move_layer_y; | |
2690 | 2678 |
2691 if (did_move_layer_x || did_move_layer_y) { | 2679 did_scroll_x |= did_layer_consume_delta_x; |
2680 did_scroll_y |= did_layer_consume_delta_y; | |
2681 | |
2682 if (did_layer_consume_delta_x || did_layer_consume_delta_y) { | |
2692 did_lock_scrolling_layer_ = true; | 2683 did_lock_scrolling_layer_ = true; |
2693 | 2684 |
2694 // When scrolls are allowed to bubble, it's important that the original | 2685 // When scrolls are allowed to bubble, it's important that the original |
2695 // scrolling layer be preserved. This ensures that, after a scroll | 2686 // scrolling layer be preserved. This ensures that, after a scroll |
2696 // bubbles, the user can reverse scroll directions and immediately resume | 2687 // bubbles, the user can reverse scroll directions and immediately resume |
2697 // scrolling the original layer that scrolled. | 2688 // scrolling the original layer that scrolled. |
2698 if (!should_bubble_scrolls_) { | 2689 if (!should_bubble_scrolls_) { |
2699 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2690 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2700 break; | 2691 break; |
2701 } | 2692 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2735 } | 2726 } |
2736 | 2727 |
2737 // Scrolling along an axis resets accumulated root overscroll for that axis. | 2728 // Scrolling along an axis resets accumulated root overscroll for that axis. |
2738 if (did_scroll_x) | 2729 if (did_scroll_x) |
2739 accumulated_root_overscroll_.set_x(0); | 2730 accumulated_root_overscroll_.set_x(0); |
2740 if (did_scroll_y) | 2731 if (did_scroll_y) |
2741 accumulated_root_overscroll_.set_y(0); | 2732 accumulated_root_overscroll_.set_y(0); |
2742 accumulated_root_overscroll_ += unused_root_delta; | 2733 accumulated_root_overscroll_ += unused_root_delta; |
2743 | 2734 |
2744 InputHandlerScrollResult scroll_result; | 2735 InputHandlerScrollResult scroll_result; |
2745 scroll_result.did_scroll = did_scroll_content || did_scroll_top_controls; | 2736 scroll_result.did_scroll = did_scroll_content; |
2746 scroll_result.did_overscroll_root = !unused_root_delta.IsZero(); | 2737 scroll_result.did_overscroll_root = !unused_root_delta.IsZero(); |
2747 scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_; | 2738 scroll_result.accumulated_root_overscroll = accumulated_root_overscroll_; |
2748 scroll_result.unused_scroll_delta = unused_root_delta; | 2739 scroll_result.unused_scroll_delta = unused_root_delta; |
2749 return scroll_result; | 2740 return scroll_result; |
2750 } | 2741 } |
2751 | 2742 |
2752 // This implements scrolling by page as described here: | 2743 // This implements scrolling by page as described here: |
2753 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel | 2744 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel |
2754 // for events with WHEEL_PAGESCROLL set. | 2745 // for events with WHEEL_PAGESCROLL set. |
2755 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, | 2746 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3435 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 3426 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
3436 | 3427 |
3437 curve->UpdateTarget( | 3428 curve->UpdateTarget( |
3438 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) | 3429 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
3439 .InSecondsF(), | 3430 .InSecondsF(), |
3440 new_target); | 3431 new_target); |
3441 | 3432 |
3442 return true; | 3433 return true; |
3443 } | 3434 } |
3444 } // namespace cc | 3435 } // namespace cc |
OLD | NEW |