| 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 scrolling_layer == OuterViewportScrollLayer(); | 502 scrolling_layer == OuterViewportScrollLayer(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( | 505 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( |
| 506 const gfx::Point& viewport_point, | 506 const gfx::Point& viewport_point, |
| 507 InputHandler::ScrollInputType type) const { | 507 InputHandler::ScrollInputType type) const { |
| 508 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); | 508 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); |
| 509 if (!scrolling_layer_impl) | 509 if (!scrolling_layer_impl) |
| 510 return false; | 510 return false; |
| 511 | 511 |
| 512 gfx::PointF device_viewport_point = | 512 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 513 gfx::ScalePoint(viewport_point, active_tree_->device_scale_factor()); | 513 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 514 | 514 |
| 515 LayerImpl* layer_impl = | 515 LayerImpl* layer_impl = |
| 516 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 516 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 517 | 517 |
| 518 bool scroll_on_main_thread = false; | 518 bool scroll_on_main_thread = false; |
| 519 LayerImpl* test_layer_impl = FindScrollLayerForDeviceViewportPoint( | 519 LayerImpl* test_layer_impl = FindScrollLayerForDeviceViewportPoint( |
| 520 device_viewport_point, type, layer_impl, &scroll_on_main_thread, NULL); | 520 device_viewport_point, type, layer_impl, &scroll_on_main_thread, NULL); |
| 521 | 521 |
| 522 if (!test_layer_impl) | 522 if (!test_layer_impl) |
| 523 return false; | 523 return false; |
| 524 | 524 |
| 525 if (scrolling_layer_impl == test_layer_impl) | 525 if (scrolling_layer_impl == test_layer_impl) |
| 526 return true; | 526 return true; |
| 527 | 527 |
| 528 // For active scrolling state treat the inner/outer viewports interchangeably. | 528 // For active scrolling state treat the inner/outer viewports interchangeably. |
| 529 if ((scrolling_layer_impl == InnerViewportScrollLayer() && | 529 if ((scrolling_layer_impl == InnerViewportScrollLayer() && |
| 530 test_layer_impl == OuterViewportScrollLayer()) || | 530 test_layer_impl == OuterViewportScrollLayer()) || |
| 531 (scrolling_layer_impl == OuterViewportScrollLayer() && | 531 (scrolling_layer_impl == OuterViewportScrollLayer() && |
| 532 test_layer_impl == InnerViewportScrollLayer())) { | 532 test_layer_impl == InnerViewportScrollLayer())) { |
| 533 return true; | 533 return true; |
| 534 } | 534 } |
| 535 | 535 |
| 536 return false; | 536 return false; |
| 537 } | 537 } |
| 538 | 538 |
| 539 bool LayerTreeHostImpl::HaveWheelEventHandlersAt( | 539 bool LayerTreeHostImpl::HaveWheelEventHandlersAt( |
| 540 const gfx::Point& viewport_point) { | 540 const gfx::Point& viewport_point) { |
| 541 gfx::PointF device_viewport_point = | 541 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 542 gfx::ScalePoint(viewport_point, active_tree_->device_scale_factor()); | 542 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 543 | 543 |
| 544 LayerImpl* layer_impl = | 544 LayerImpl* layer_impl = |
| 545 active_tree_->FindLayerWithWheelHandlerThatIsHitByPoint( | 545 active_tree_->FindLayerWithWheelHandlerThatIsHitByPoint( |
| 546 device_viewport_point); | 546 device_viewport_point); |
| 547 | 547 |
| 548 return layer_impl != NULL; | 548 return layer_impl != NULL; |
| 549 } | 549 } |
| 550 | 550 |
| 551 static LayerImpl* NextLayerInScrollOrder(LayerImpl* layer) { | 551 static LayerImpl* NextLayerInScrollOrder(LayerImpl* layer) { |
| 552 if (layer->scroll_parent()) | 552 if (layer->scroll_parent()) |
| 553 return layer->scroll_parent(); | 553 return layer->scroll_parent(); |
| 554 | 554 |
| 555 return layer->parent(); | 555 return layer->parent(); |
| 556 } | 556 } |
| 557 | 557 |
| 558 static ScrollBlocksOn EffectiveScrollBlocksOn(LayerImpl* layer) { | 558 static ScrollBlocksOn EffectiveScrollBlocksOn(LayerImpl* layer) { |
| 559 ScrollBlocksOn blocks = SCROLL_BLOCKS_ON_NONE; | 559 ScrollBlocksOn blocks = SCROLL_BLOCKS_ON_NONE; |
| 560 for (; layer; layer = NextLayerInScrollOrder(layer)) { | 560 for (; layer; layer = NextLayerInScrollOrder(layer)) { |
| 561 blocks |= layer->scroll_blocks_on(); | 561 blocks |= layer->scroll_blocks_on(); |
| 562 } | 562 } |
| 563 return blocks; | 563 return blocks; |
| 564 } | 564 } |
| 565 | 565 |
| 566 bool LayerTreeHostImpl::DoTouchEventsBlockScrollAt( | 566 bool LayerTreeHostImpl::DoTouchEventsBlockScrollAt( |
| 567 const gfx::Point& viewport_point) { | 567 const gfx::Point& viewport_point) { |
| 568 gfx::PointF device_viewport_point = | 568 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 569 gfx::ScalePoint(viewport_point, active_tree_->device_scale_factor()); | 569 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 570 | 570 |
| 571 // First check if scrolling at this point is required to block on any | 571 // First check if scrolling at this point is required to block on any |
| 572 // touch event handlers. Note that we must start at the innermost layer | 572 // touch event handlers. Note that we must start at the innermost layer |
| 573 // (as opposed to only the layer found to contain a touch handler region | 573 // (as opposed to only the layer found to contain a touch handler region |
| 574 // below) to ensure all relevant scroll-blocks-on values are applied. | 574 // below) to ensure all relevant scroll-blocks-on values are applied. |
| 575 LayerImpl* layer_impl = | 575 LayerImpl* layer_impl = |
| 576 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 576 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 577 ScrollBlocksOn blocking = EffectiveScrollBlocksOn(layer_impl); | 577 ScrollBlocksOn blocking = EffectiveScrollBlocksOn(layer_impl); |
| 578 if (!(blocking & SCROLL_BLOCKS_ON_START_TOUCH)) | 578 if (!(blocking & SCROLL_BLOCKS_ON_START_TOUCH)) |
| 579 return false; | 579 return false; |
| (...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2419 } | 2419 } |
| 2420 | 2420 |
| 2421 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 2421 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
| 2422 const gfx::Point& viewport_point, | 2422 const gfx::Point& viewport_point, |
| 2423 InputHandler::ScrollInputType type) { | 2423 InputHandler::ScrollInputType type) { |
| 2424 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2424 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
| 2425 | 2425 |
| 2426 DCHECK(!CurrentlyScrollingLayer()); | 2426 DCHECK(!CurrentlyScrollingLayer()); |
| 2427 ClearCurrentlyScrollingLayer(); | 2427 ClearCurrentlyScrollingLayer(); |
| 2428 | 2428 |
| 2429 gfx::PointF device_viewport_point = | 2429 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 2430 gfx::ScalePoint(viewport_point, active_tree_->device_scale_factor()); | 2430 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 2431 LayerImpl* layer_impl = | 2431 LayerImpl* layer_impl = |
| 2432 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 2432 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 2433 | 2433 |
| 2434 if (layer_impl) { | 2434 if (layer_impl) { |
| 2435 LayerImpl* scroll_layer_impl = | 2435 LayerImpl* scroll_layer_impl = |
| 2436 active_tree_->FindFirstScrollingLayerThatIsHitByPoint( | 2436 active_tree_->FindFirstScrollingLayerThatIsHitByPoint( |
| 2437 device_viewport_point); | 2437 device_viewport_point); |
| 2438 if (scroll_layer_impl && !HasScrollAncestor(layer_impl, scroll_layer_impl)) | 2438 if (scroll_layer_impl && !HasScrollAncestor(layer_impl, scroll_layer_impl)) |
| 2439 return SCROLL_UNKNOWN; | 2439 return SCROLL_UNKNOWN; |
| 2440 } | 2440 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2575 delta.Scale(1.f / page_scale_factor); | 2575 delta.Scale(1.f / page_scale_factor); |
| 2576 layer_impl->ScrollBy(delta); | 2576 layer_impl->ScrollBy(delta); |
| 2577 gfx::ScrollOffset scrolled = | 2577 gfx::ScrollOffset scrolled = |
| 2578 layer_impl->CurrentScrollOffset() - previous_offset; | 2578 layer_impl->CurrentScrollOffset() - previous_offset; |
| 2579 gfx::Vector2dF consumed_scroll(scrolled.x(), scrolled.y()); | 2579 gfx::Vector2dF consumed_scroll(scrolled.x(), scrolled.y()); |
| 2580 consumed_scroll.Scale(page_scale_factor); | 2580 consumed_scroll.Scale(page_scale_factor); |
| 2581 | 2581 |
| 2582 return consumed_scroll; | 2582 return consumed_scroll; |
| 2583 } | 2583 } |
| 2584 | 2584 |
| 2585 // TODO(danakj): Make this into two functions, one with delta, one with |
| 2586 // viewport_point, no bool required. |
| 2585 gfx::Vector2dF LayerTreeHostImpl::ScrollLayer(LayerImpl* layer_impl, | 2587 gfx::Vector2dF LayerTreeHostImpl::ScrollLayer(LayerImpl* layer_impl, |
| 2586 const gfx::Vector2dF& delta, | 2588 const gfx::Vector2dF& delta, |
| 2587 const gfx::Point& viewport_point, | 2589 const gfx::Point& viewport_point, |
| 2588 bool is_direct_manipulation) { | 2590 bool is_direct_manipulation) { |
| 2589 // Events representing direct manipulation of the screen (such as gesture | 2591 // Events representing direct manipulation of the screen (such as gesture |
| 2590 // events) need to be transformed from viewport coordinates to local layer | 2592 // events) need to be transformed from viewport coordinates to local layer |
| 2591 // coordinates so that the scrolling contents exactly follow the user's | 2593 // coordinates so that the scrolling contents exactly follow the user's |
| 2592 // finger. In contrast, events not representing direct manipulation of the | 2594 // finger. In contrast, events not representing direct manipulation of the |
| 2593 // screen (such as wheel events) represent a fixed amount of scrolling so we | 2595 // screen (such as wheel events) represent a fixed amount of scrolling so we |
| 2594 // can just apply them directly, but the page scale factor is applied to the | 2596 // can just apply them directly, but the page scale factor is applied to the |
| 2595 // scroll delta. | 2597 // scroll delta. |
| 2596 if (is_direct_manipulation) | 2598 if (is_direct_manipulation) { |
| 2597 return ScrollLayerWithViewportSpaceDelta(layer_impl, viewport_point, delta); | 2599 return ScrollLayerWithViewportSpaceDelta( |
| 2600 layer_impl, gfx::PointF(viewport_point), delta); |
| 2601 } |
| 2598 float scale_factor = active_tree()->current_page_scale_factor(); | 2602 float scale_factor = active_tree()->current_page_scale_factor(); |
| 2599 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor); | 2603 return ScrollLayerWithLocalDelta(layer_impl, delta, scale_factor); |
| 2600 } | 2604 } |
| 2601 | 2605 |
| 2602 void LayerTreeHostImpl::ApplyScroll(LayerImpl* layer, | 2606 void LayerTreeHostImpl::ApplyScroll(LayerImpl* layer, |
| 2603 ScrollState* scroll_state) { | 2607 ScrollState* scroll_state) { |
| 2604 DCHECK(scroll_state); | 2608 DCHECK(scroll_state); |
| 2605 gfx::Point viewport_point(scroll_state->start_position_x(), | 2609 gfx::Point viewport_point(scroll_state->start_position_x(), |
| 2606 scroll_state->start_position_y()); | 2610 scroll_state->start_position_y()); |
| 2607 const gfx::Vector2dF delta(scroll_state->delta_x(), scroll_state->delta_y()); | 2611 const gfx::Vector2dF delta(scroll_state->delta_x(), scroll_state->delta_y()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2833 gfx::Rect layer_impl_bounds(layer_impl->bounds()); | 2837 gfx::Rect layer_impl_bounds(layer_impl->bounds()); |
| 2834 | 2838 |
| 2835 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect( | 2839 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect( |
| 2836 layer_impl->screen_space_transform(), gfx::RectF(layer_impl_bounds)); | 2840 layer_impl->screen_space_transform(), gfx::RectF(layer_impl_bounds)); |
| 2837 | 2841 |
| 2838 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint( | 2842 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint( |
| 2839 device_viewport_point); | 2843 device_viewport_point); |
| 2840 } | 2844 } |
| 2841 | 2845 |
| 2842 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) { | 2846 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) { |
| 2843 gfx::PointF device_viewport_point = | 2847 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 2844 gfx::ScalePoint(viewport_point, active_tree_->device_scale_factor()); | 2848 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 2845 LayerImpl* layer_impl = | 2849 LayerImpl* layer_impl = |
| 2846 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 2850 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 2847 if (HandleMouseOverScrollbar(layer_impl, device_viewport_point)) | 2851 if (HandleMouseOverScrollbar(layer_impl, device_viewport_point)) |
| 2848 return; | 2852 return; |
| 2849 | 2853 |
| 2850 if (scroll_layer_id_when_mouse_over_scrollbar_) { | 2854 if (scroll_layer_id_when_mouse_over_scrollbar_) { |
| 2851 LayerImpl* scroll_layer_impl = active_tree_->LayerById( | 2855 LayerImpl* scroll_layer_impl = active_tree_->LayerById( |
| 2852 scroll_layer_id_when_mouse_over_scrollbar_); | 2856 scroll_layer_id_when_mouse_over_scrollbar_); |
| 2853 | 2857 |
| 2854 // The check for a null scroll_layer_impl below was added to see if it will | 2858 // The check for a null scroll_layer_impl below was added to see if it will |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3616 if (active_tree()) { | 3620 if (active_tree()) { |
| 3617 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3621 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
| 3618 if (layer) | 3622 if (layer) |
| 3619 return layer->ScrollOffsetForAnimation(); | 3623 return layer->ScrollOffsetForAnimation(); |
| 3620 } | 3624 } |
| 3621 | 3625 |
| 3622 return gfx::ScrollOffset(); | 3626 return gfx::ScrollOffset(); |
| 3623 } | 3627 } |
| 3624 | 3628 |
| 3625 } // namespace cc | 3629 } // namespace cc |
| OLD | NEW |