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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 &memory_used_bytes); | 386 &memory_used_bytes); |
387 SendManagedMemoryStats(memory_required_bytes, | 387 SendManagedMemoryStats(memory_required_bytes, |
388 memory_nice_to_have_bytes, | 388 memory_nice_to_have_bytes, |
389 memory_used_bytes); | 389 memory_used_bytes); |
390 } | 390 } |
391 | 391 |
392 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, | 392 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, |
393 bool anchor_point, | 393 bool anchor_point, |
394 float page_scale, | 394 float page_scale, |
395 base::TimeDelta duration) { | 395 base::TimeDelta duration) { |
396 if (!RootScrollLayer()) | 396 if (!InnerViewportScrollLayer()) |
397 return; | 397 return; |
398 | 398 |
399 // Should we attempt to set to OuterViewportScrollingLayer if it's available? | |
400 active_tree_->SetCurrentlyScrollingLayer(InnerViewportScrollLayer()); | |
enne (OOO)
2013/11/14 22:59:01
Why do you need to set the currently scrolling lay
wjmaclean
2013/12/24 21:03:49
It might not be needed ... I'll try to verify this
| |
401 | |
399 gfx::Vector2dF scroll_total = | 402 gfx::Vector2dF scroll_total = |
400 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); | 403 active_tree_->TotalScrollOffset() + active_tree_->TotalScrollDelta(); |
401 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 404 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
402 gfx::SizeF viewport_size = UnscaledScrollableViewportSize(); | 405 gfx::SizeF viewport_size = UnscaledScrollableViewportSize(); |
403 | 406 |
404 // Easing constants experimentally determined. | 407 // Easing constants experimentally determined. |
405 scoped_ptr<TimingFunction> timing_function = | 408 scoped_ptr<TimingFunction> timing_function = |
406 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); | 409 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); |
407 | 410 |
408 page_scale_animation_ = | 411 page_scale_animation_ = |
409 PageScaleAnimation::Create(scroll_total, | 412 PageScaleAnimation::Create(scroll_total, |
410 active_tree_->total_page_scale_factor(), | 413 active_tree_->total_page_scale_factor(), |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); | 1251 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); |
1249 metadata.latency_info = active_tree_->GetLatencyInfo(); | 1252 metadata.latency_info = active_tree_->GetLatencyInfo(); |
1250 if (top_controls_manager_) { | 1253 if (top_controls_manager_) { |
1251 metadata.location_bar_offset = | 1254 metadata.location_bar_offset = |
1252 gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset()); | 1255 gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset()); |
1253 metadata.location_bar_content_translation = | 1256 metadata.location_bar_content_translation = |
1254 gfx::Vector2dF(0.f, top_controls_manager_->content_top_offset()); | 1257 gfx::Vector2dF(0.f, top_controls_manager_->content_top_offset()); |
1255 metadata.overdraw_bottom_height = overdraw_bottom_height_; | 1258 metadata.overdraw_bottom_height = overdraw_bottom_height_; |
1256 } | 1259 } |
1257 | 1260 |
1258 if (!RootScrollLayer()) | 1261 if (!InnerViewportScrollLayer()) |
1259 return metadata; | 1262 return metadata; |
1260 | 1263 |
1261 metadata.root_scroll_offset = RootScrollLayer()->TotalScrollOffset(); | 1264 metadata.root_scroll_offset = active_tree_->TotalScrollOffset(); |
1262 | 1265 |
1263 return metadata; | 1266 return metadata; |
1264 } | 1267 } |
1265 | 1268 |
1266 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { | 1269 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { |
1267 layer->DidBeginTracing(); | 1270 layer->DidBeginTracing(); |
1268 } | 1271 } |
1269 | 1272 |
1270 void LayerTreeHostImpl::DrawLayers(FrameData* frame, | 1273 void LayerTreeHostImpl::DrawLayers(FrameData* frame, |
1271 base::TimeTicks frame_begin_time) { | 1274 base::TimeTicks frame_begin_time) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1439 client_->DidLoseOutputSurfaceOnImplThread(); | 1442 client_->DidLoseOutputSurfaceOnImplThread(); |
1440 } | 1443 } |
1441 | 1444 |
1442 void LayerTreeHostImpl::Readback(void* pixels, | 1445 void LayerTreeHostImpl::Readback(void* pixels, |
1443 gfx::Rect rect_in_device_viewport) { | 1446 gfx::Rect rect_in_device_viewport) { |
1444 DCHECK(renderer_); | 1447 DCHECK(renderer_); |
1445 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); | 1448 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); |
1446 } | 1449 } |
1447 | 1450 |
1448 bool LayerTreeHostImpl::HaveRootScrollLayer() const { | 1451 bool LayerTreeHostImpl::HaveRootScrollLayer() const { |
1449 return !!RootScrollLayer(); | 1452 return !!InnerViewportScrollLayer(); |
1450 } | 1453 } |
1451 | 1454 |
1452 LayerImpl* LayerTreeHostImpl::RootLayer() const { | 1455 LayerImpl* LayerTreeHostImpl::RootLayer() const { |
1453 return active_tree_->root_layer(); | 1456 return active_tree_->root_layer(); |
1454 } | 1457 } |
1455 | 1458 |
1456 LayerImpl* LayerTreeHostImpl::RootScrollLayer() const { | 1459 LayerImpl* LayerTreeHostImpl::InnerViewportScrollLayer() const { |
1457 return active_tree_->RootScrollLayer(); | 1460 return active_tree_->InnerViewportScrollLayer(); |
1461 } | |
1462 | |
1463 LayerImpl* LayerTreeHostImpl::OuterViewportScrollLayer() const { | |
1464 return active_tree_->OuterViewportScrollLayer(); | |
1458 } | 1465 } |
1459 | 1466 |
1460 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { | 1467 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { |
1461 return active_tree_->CurrentlyScrollingLayer(); | 1468 return active_tree_->CurrentlyScrollingLayer(); |
1462 } | 1469 } |
1463 | 1470 |
1464 bool LayerTreeHostImpl::IsCurrentlyScrolling() const { | 1471 bool LayerTreeHostImpl::IsCurrentlyScrolling() const { |
1465 return CurrentlyScrollingLayer() || | 1472 return CurrentlyScrollingLayer() || |
1466 (RootScrollLayer() && RootScrollLayer()->IsExternalFlingActive()); | 1473 (InnerViewportScrollLayer() && |
1474 InnerViewportScrollLayer()->IsExternalFlingActive()) || | |
1475 (OuterViewportScrollLayer() && | |
1476 OuterViewportScrollLayer()->IsExternalFlingActive()); | |
1467 } | 1477 } |
1468 | 1478 |
1469 // Content layers can be either directly scrollable or contained in an outer | 1479 // Content layers can be either directly scrollable or contained in an outer |
1470 // scrolling layer which applies the scroll transform. Given a content layer, | 1480 // scrolling layer which applies the scroll transform. Given a content layer, |
1471 // this function returns the associated scroll layer if any. | 1481 // this function returns the associated scroll layer if any. |
1472 static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { | 1482 static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { |
1473 if (!layer_impl) | 1483 if (!layer_impl) |
1474 return NULL; | 1484 return NULL; |
1475 | 1485 |
1476 if (layer_impl->scrollable()) | 1486 if (layer_impl->scrollable()) |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1823 | 1833 |
1824 void LayerTreeHostImpl::SetViewportSize(gfx::Size device_viewport_size) { | 1834 void LayerTreeHostImpl::SetViewportSize(gfx::Size device_viewport_size) { |
1825 if (device_viewport_size == device_viewport_size_) | 1835 if (device_viewport_size == device_viewport_size_) |
1826 return; | 1836 return; |
1827 | 1837 |
1828 if (pending_tree_) | 1838 if (pending_tree_) |
1829 active_tree_->SetViewportSizeInvalid(); | 1839 active_tree_->SetViewportSizeInvalid(); |
1830 | 1840 |
1831 device_viewport_size_ = device_viewport_size; | 1841 device_viewport_size_ = device_viewport_size; |
1832 | 1842 |
1833 UpdateMaxScrollOffset(); | |
1834 | |
1835 if (renderer_) | 1843 if (renderer_) |
1836 renderer_->ViewportChanged(); | 1844 renderer_->ViewportChanged(); |
1837 | 1845 |
1838 client_->OnCanDrawStateChanged(CanDraw()); | 1846 client_->OnCanDrawStateChanged(CanDraw()); |
1839 SetFullRootLayerDamage(); | 1847 SetFullRootLayerDamage(); |
1840 } | 1848 } |
1841 | 1849 |
1842 void LayerTreeHostImpl::SetOverdrawBottomHeight(float overdraw_bottom_height) { | 1850 void LayerTreeHostImpl::SetOverdrawBottomHeight(float overdraw_bottom_height) { |
1843 if (overdraw_bottom_height == overdraw_bottom_height_) | 1851 if (overdraw_bottom_height == overdraw_bottom_height_) |
1844 return; | 1852 return; |
1845 overdraw_bottom_height_ = overdraw_bottom_height; | 1853 overdraw_bottom_height_ = overdraw_bottom_height; |
1846 | 1854 |
1847 UpdateMaxScrollOffset(); | |
1848 SetFullRootLayerDamage(); | 1855 SetFullRootLayerDamage(); |
1849 } | 1856 } |
1850 | 1857 |
1851 void LayerTreeHostImpl::SetOverhangUIResource( | 1858 void LayerTreeHostImpl::SetOverhangUIResource( |
1852 UIResourceId overhang_ui_resource_id, | 1859 UIResourceId overhang_ui_resource_id, |
1853 gfx::Size overhang_ui_resource_size) { | 1860 gfx::Size overhang_ui_resource_size) { |
1854 overhang_ui_resource_id_ = overhang_ui_resource_id; | 1861 overhang_ui_resource_id_ = overhang_ui_resource_id; |
1855 overhang_ui_resource_size_ = overhang_ui_resource_size; | 1862 overhang_ui_resource_size_ = overhang_ui_resource_size; |
1856 } | 1863 } |
1857 | 1864 |
1858 void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) { | 1865 void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) { |
1859 if (device_scale_factor == device_scale_factor_) | 1866 if (device_scale_factor == device_scale_factor_) |
1860 return; | 1867 return; |
1861 device_scale_factor_ = device_scale_factor; | 1868 device_scale_factor_ = device_scale_factor; |
1862 | 1869 |
1863 if (renderer_) | 1870 if (renderer_) |
1864 renderer_->ViewportChanged(); | 1871 renderer_->ViewportChanged(); |
1865 | 1872 |
1866 UpdateMaxScrollOffset(); | |
1867 SetFullRootLayerDamage(); | 1873 SetFullRootLayerDamage(); |
1868 } | 1874 } |
1869 | 1875 |
1870 gfx::Size LayerTreeHostImpl::DrawViewportSize() const { | 1876 gfx::Size LayerTreeHostImpl::DrawViewportSize() const { |
1871 return DeviceViewport().size(); | 1877 return DeviceViewport().size(); |
1872 } | 1878 } |
1873 | 1879 |
1874 gfx::Rect LayerTreeHostImpl::DeviceViewport() const { | 1880 gfx::Rect LayerTreeHostImpl::DeviceViewport() const { |
1875 if (external_viewport_.IsEmpty()) | 1881 if (external_viewport_.IsEmpty()) |
1876 return gfx::Rect(device_viewport_size_); | 1882 return gfx::Rect(device_viewport_size_); |
1877 | 1883 |
1878 return external_viewport_; | 1884 return external_viewport_; |
1879 } | 1885 } |
1880 | 1886 |
1881 gfx::Rect LayerTreeHostImpl::DeviceClip() const { | 1887 gfx::Rect LayerTreeHostImpl::DeviceClip() const { |
1882 if (external_clip_.IsEmpty()) | 1888 if (external_clip_.IsEmpty()) |
1883 return DeviceViewport(); | 1889 return DeviceViewport(); |
1884 | 1890 |
1885 return external_clip_; | 1891 return external_clip_; |
1886 } | 1892 } |
1887 | 1893 |
1888 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { | 1894 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { |
1889 return external_transform_; | 1895 return external_transform_; |
1890 } | 1896 } |
1891 | 1897 |
1892 void LayerTreeHostImpl::UpdateMaxScrollOffset() { | |
1893 active_tree_->UpdateMaxScrollOffset(); | |
1894 } | |
1895 | |
1896 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 1898 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
1897 client_->SetNeedsRedrawOnImplThread(); | 1899 client_->SetNeedsRedrawOnImplThread(); |
1898 active_tree_->set_needs_update_draw_properties(); | 1900 active_tree_->set_needs_update_draw_properties(); |
1899 SetFullRootLayerDamage(); | 1901 SetFullRootLayerDamage(); |
1900 } | 1902 } |
1901 | 1903 |
1902 bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { | 1904 bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { |
1903 active_tree_->UpdateDrawProperties(); | 1905 active_tree_->UpdateDrawProperties(); |
1904 return !active_tree_->RenderSurfaceLayerList().empty(); | 1906 return !active_tree_->RenderSurfaceLayerList().empty(); |
1905 } | 1907 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 if (status == ScrollStarted && !potentially_scrolling_layer_impl) | 1947 if (status == ScrollStarted && !potentially_scrolling_layer_impl) |
1946 potentially_scrolling_layer_impl = scroll_layer_impl; | 1948 potentially_scrolling_layer_impl = scroll_layer_impl; |
1947 } | 1949 } |
1948 | 1950 |
1949 // When hiding top controls is enabled and the controls are hidden or | 1951 // When hiding top controls is enabled and the controls are hidden or |
1950 // overlaying the content, force scrolls to be enabled on the root layer to | 1952 // overlaying the content, force scrolls to be enabled on the root layer to |
1951 // allow bringing the top controls back into view. | 1953 // allow bringing the top controls back into view. |
1952 if (!potentially_scrolling_layer_impl && top_controls_manager_ && | 1954 if (!potentially_scrolling_layer_impl && top_controls_manager_ && |
1953 top_controls_manager_->content_top_offset() != | 1955 top_controls_manager_->content_top_offset() != |
1954 settings_.top_controls_height) { | 1956 settings_.top_controls_height) { |
1955 potentially_scrolling_layer_impl = RootScrollLayer(); | 1957 potentially_scrolling_layer_impl = |
1958 OuterViewportScrollLayer() ? OuterViewportScrollLayer() | |
1959 : InnerViewportScrollLayer(); | |
1956 } | 1960 } |
1957 | 1961 |
1958 return potentially_scrolling_layer_impl; | 1962 return potentially_scrolling_layer_impl; |
1959 } | 1963 } |
1960 | 1964 |
1961 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 1965 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
1962 gfx::Point viewport_point, InputHandler::ScrollInputType type) { | 1966 gfx::Point viewport_point, InputHandler::ScrollInputType type) { |
1963 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 1967 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
1964 | 1968 |
1965 if (top_controls_manager_) | 1969 if (top_controls_manager_) |
(...skipping 15 matching lines...) Expand all Loading... | |
1981 FindScrollLayerForDeviceViewportPoint(device_viewport_point, type, | 1985 FindScrollLayerForDeviceViewportPoint(device_viewport_point, type, |
1982 layer_impl, &scroll_on_main_thread); | 1986 layer_impl, &scroll_on_main_thread); |
1983 | 1987 |
1984 if (scroll_on_main_thread) { | 1988 if (scroll_on_main_thread) { |
1985 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); | 1989 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); |
1986 return ScrollOnMainThread; | 1990 return ScrollOnMainThread; |
1987 } | 1991 } |
1988 | 1992 |
1989 // If we want to send a DidOverscroll for this scroll it can't be ignored. | 1993 // If we want to send a DidOverscroll for this scroll it can't be ignored. |
1990 if (!potentially_scrolling_layer_impl && settings_.always_overscroll) | 1994 if (!potentially_scrolling_layer_impl && settings_.always_overscroll) |
1991 potentially_scrolling_layer_impl = RootScrollLayer(); | 1995 potentially_scrolling_layer_impl = |
1996 OuterViewportScrollLayer() ? OuterViewportScrollLayer() | |
1997 : InnerViewportScrollLayer(); | |
1992 | 1998 |
1993 if (potentially_scrolling_layer_impl) { | 1999 if (potentially_scrolling_layer_impl) { |
1994 active_tree_->SetCurrentlyScrollingLayer( | 2000 active_tree_->SetCurrentlyScrollingLayer( |
1995 potentially_scrolling_layer_impl); | 2001 potentially_scrolling_layer_impl); |
1996 should_bubble_scrolls_ = (type != NonBubblingGesture); | 2002 should_bubble_scrolls_ = (type != NonBubblingGesture); |
1997 last_scroll_did_bubble_ = false; | 2003 last_scroll_did_bubble_ = false; |
1998 wheel_scrolling_ = (type == Wheel); | 2004 wheel_scrolling_ = (type == Wheel); |
1999 client_->RenewTreePriority(); | 2005 client_->RenewTreePriority(); |
2000 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); | 2006 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
2001 return ScrollStarted; | 2007 return ScrollStarted; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2089 bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point, | 2095 bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point, |
2090 gfx::Vector2dF scroll_delta) { | 2096 gfx::Vector2dF scroll_delta) { |
2091 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 2097 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
2092 if (!CurrentlyScrollingLayer()) | 2098 if (!CurrentlyScrollingLayer()) |
2093 return false; | 2099 return false; |
2094 | 2100 |
2095 gfx::Vector2dF pending_delta = scroll_delta; | 2101 gfx::Vector2dF pending_delta = scroll_delta; |
2096 gfx::Vector2dF unused_root_delta; | 2102 gfx::Vector2dF unused_root_delta; |
2097 bool did_scroll_x = false; | 2103 bool did_scroll_x = false; |
2098 bool did_scroll_y = false; | 2104 bool did_scroll_y = false; |
2099 bool consume_by_top_controls = top_controls_manager_ && | 2105 bool consume_by_top_controls = |
2100 (CurrentlyScrollingLayer() == RootScrollLayer() || scroll_delta.y() < 0); | 2106 top_controls_manager_ && |
2107 (CurrentlyScrollingLayer() == InnerViewportScrollLayer() || | |
2108 scroll_delta.y() < 0); | |
2101 last_scroll_did_bubble_ = false; | 2109 last_scroll_did_bubble_ = false; |
2102 | 2110 |
2103 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2111 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2104 layer_impl; | 2112 layer_impl; |
2105 layer_impl = layer_impl->parent()) { | 2113 layer_impl = layer_impl->parent()) { |
2106 if (!layer_impl->scrollable()) | 2114 if (!layer_impl->scrollable()) |
2107 continue; | 2115 continue; |
2108 | 2116 |
2109 if (layer_impl == RootScrollLayer()) { | 2117 if (layer_impl == InnerViewportScrollLayer()) { |
2110 // Only allow bubble scrolling when the scroll is in the direction to make | 2118 // Only allow bubble scrolling when the scroll is in the direction to make |
2111 // the top controls visible. | 2119 // the top controls visible. |
2112 if (consume_by_top_controls && layer_impl == RootScrollLayer()) { | 2120 if (consume_by_top_controls && layer_impl == InnerViewportScrollLayer()) |
2113 pending_delta = top_controls_manager_->ScrollBy(pending_delta); | 2121 pending_delta = top_controls_manager_->ScrollBy(pending_delta); |
2114 UpdateMaxScrollOffset(); | |
2115 } | |
2116 // Track root layer deltas for reporting overscroll. | 2122 // Track root layer deltas for reporting overscroll. |
2117 unused_root_delta = pending_delta; | 2123 unused_root_delta = pending_delta; |
2118 } | 2124 } |
2119 | 2125 |
2120 gfx::Vector2dF applied_delta; | 2126 gfx::Vector2dF applied_delta; |
2121 // Gesture events need to be transformed from viewport coordinates to local | 2127 // Gesture events need to be transformed from viewport coordinates to local |
2122 // layer coordinates so that the scrolling contents exactly follow the | 2128 // layer coordinates so that the scrolling contents exactly follow the |
2123 // user's finger. In contrast, wheel events represent a fixed amount of | 2129 // user's finger. In contrast, wheel events represent a fixed amount of |
2124 // scrolling so we can just apply them directly. | 2130 // scrolling so we can just apply them directly. |
2125 if (!wheel_scrolling_) { | 2131 if (!wheel_scrolling_) { |
(...skipping 17 matching lines...) Expand all Loading... | |
2143 continue; | 2149 continue; |
2144 | 2150 |
2145 if (should_bubble_scrolls_) { | 2151 if (should_bubble_scrolls_) { |
2146 last_scroll_did_bubble_ = true; | 2152 last_scroll_did_bubble_ = true; |
2147 continue; | 2153 continue; |
2148 } | 2154 } |
2149 | 2155 |
2150 break; | 2156 break; |
2151 } | 2157 } |
2152 | 2158 |
2153 if (layer_impl == RootScrollLayer()) | 2159 if (layer_impl == InnerViewportScrollLayer() || |
2160 layer_impl == OuterViewportScrollLayer()) | |
2154 unused_root_delta.Subtract(applied_delta); | 2161 unused_root_delta.Subtract(applied_delta); |
2155 | 2162 |
2156 did_lock_scrolling_layer_ = true; | 2163 did_lock_scrolling_layer_ = true; |
2157 if (!should_bubble_scrolls_) { | 2164 if (!should_bubble_scrolls_) { |
2158 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2165 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2159 break; | 2166 break; |
2160 } | 2167 } |
2161 | 2168 |
2162 // If the applied delta is within 45 degrees of the input delta, bail out to | 2169 // If the applied delta is within 45 degrees of the input delta, bail out to |
2163 // make it easier to scroll just one layer in one direction without | 2170 // make it easier to scroll just one layer in one direction without |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2210 bool LayerTreeHostImpl::ScrollVerticallyByPage(gfx::Point viewport_point, | 2217 bool LayerTreeHostImpl::ScrollVerticallyByPage(gfx::Point viewport_point, |
2211 ScrollDirection direction) { | 2218 ScrollDirection direction) { |
2212 DCHECK(wheel_scrolling_); | 2219 DCHECK(wheel_scrolling_); |
2213 | 2220 |
2214 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2221 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2215 layer_impl; | 2222 layer_impl; |
2216 layer_impl = layer_impl->parent()) { | 2223 layer_impl = layer_impl->parent()) { |
2217 if (!layer_impl->scrollable()) | 2224 if (!layer_impl->scrollable()) |
2218 continue; | 2225 continue; |
2219 | 2226 |
2220 if (!layer_impl->vertical_scrollbar_layer()) | 2227 if (!layer_impl->HasScrollbar(VERTICAL)) |
2221 continue; | 2228 continue; |
2222 | 2229 |
2223 float height = layer_impl->vertical_scrollbar_layer()->bounds().height(); | 2230 float height = layer_impl->clip_height(); |
2224 | 2231 |
2225 // These magical values match WebKit and are designed to scroll nearly the | 2232 // These magical values match WebKit and are designed to scroll nearly the |
2226 // entire visible content height but leave a bit of overlap. | 2233 // entire visible content height but leave a bit of overlap. |
2227 float page = std::max(height * 0.875f, 1.f); | 2234 float page = std::max(height * 0.875f, 1.f); |
2228 if (direction == SCROLL_BACKWARD) | 2235 if (direction == SCROLL_BACKWARD) |
2229 page = -page; | 2236 page = -page; |
2230 | 2237 |
2231 gfx::Vector2dF delta = gfx::Vector2dF(0.f, page); | 2238 gfx::Vector2dF delta = gfx::Vector2dF(0.f, page); |
2232 | 2239 |
2233 gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta); | 2240 gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2269 top_controls_manager_->ScrollEnd(); | 2276 top_controls_manager_->ScrollEnd(); |
2270 ClearCurrentlyScrollingLayer(); | 2277 ClearCurrentlyScrollingLayer(); |
2271 StartScrollbarAnimation(); | 2278 StartScrollbarAnimation(); |
2272 } | 2279 } |
2273 | 2280 |
2274 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { | 2281 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
2275 if (!active_tree_->CurrentlyScrollingLayer()) | 2282 if (!active_tree_->CurrentlyScrollingLayer()) |
2276 return ScrollIgnored; | 2283 return ScrollIgnored; |
2277 | 2284 |
2278 if (settings_.ignore_root_layer_flings && | 2285 if (settings_.ignore_root_layer_flings && |
2279 active_tree_->CurrentlyScrollingLayer() == | 2286 (active_tree_->CurrentlyScrollingLayer() == InnerViewportScrollLayer() || |
2280 active_tree_->RootScrollLayer()) { | 2287 active_tree_->CurrentlyScrollingLayer() == OuterViewportScrollLayer())) { |
2281 ClearCurrentlyScrollingLayer(); | 2288 ClearCurrentlyScrollingLayer(); |
2282 return ScrollIgnored; | 2289 return ScrollIgnored; |
2283 } | 2290 } |
2284 | 2291 |
2285 if (!wheel_scrolling_) | 2292 if (!wheel_scrolling_) |
2286 should_bubble_scrolls_ = last_scroll_did_bubble_; | 2293 should_bubble_scrolls_ = last_scroll_did_bubble_; |
2287 | 2294 |
2288 return ScrollStarted; | 2295 return ScrollStarted; |
2289 } | 2296 } |
2290 | 2297 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2341 device_viewport_point, InputHandler::Gesture, layer_impl, | 2348 device_viewport_point, InputHandler::Gesture, layer_impl, |
2342 &scroll_on_main_thread); | 2349 &scroll_on_main_thread); |
2343 if (scroll_on_main_thread || !scroll_layer_impl) | 2350 if (scroll_on_main_thread || !scroll_layer_impl) |
2344 return; | 2351 return; |
2345 | 2352 |
2346 ScrollbarAnimationController* animation_controller = | 2353 ScrollbarAnimationController* animation_controller = |
2347 scroll_layer_impl->scrollbar_animation_controller(); | 2354 scroll_layer_impl->scrollbar_animation_controller(); |
2348 if (!animation_controller) | 2355 if (!animation_controller) |
2349 return; | 2356 return; |
2350 | 2357 |
2351 float distance_to_scrollbar = std::min( | 2358 // TODO(wjmaclean) Is it ok to choose distance from more than two scrollbars? |
enne (OOO)
2013/11/19 19:30:22
Ask tony@ what's desired here.
wjmaclean
2013/12/24 21:03:49
I have asked Tony, will report back when I hear.
tony
2013/12/26 21:06:50
This is fine for now. The old code would animate
| |
2352 DeviceSpaceDistanceToLayer(device_viewport_point, | 2359 float distance_to_scrollbar = std::numeric_limits<float>::max(); |
2353 scroll_layer_impl->horizontal_scrollbar_layer()), | 2360 for (LayerImpl::ScrollbarSet::iterator it = |
2354 DeviceSpaceDistanceToLayer(device_viewport_point, | 2361 scroll_layer_impl->scrollbars()->begin(); |
2355 scroll_layer_impl->vertical_scrollbar_layer())); | 2362 it != scroll_layer_impl->scrollbars()->end(); |
2363 ++it) | |
2364 distance_to_scrollbar = std::min(distance_to_scrollbar, | |
2365 DeviceSpaceDistanceToLayer(device_viewport_point, *it)); | |
2356 | 2366 |
2357 bool should_animate = animation_controller->DidMouseMoveNear( | 2367 bool should_animate = animation_controller->DidMouseMoveNear( |
2358 CurrentPhysicalTimeTicks(), distance_to_scrollbar / device_scale_factor_); | 2368 CurrentPhysicalTimeTicks(), distance_to_scrollbar / device_scale_factor_); |
2359 if (should_animate) | 2369 if (should_animate) |
2360 StartScrollbarAnimation(); | 2370 StartScrollbarAnimation(); |
2361 } | 2371 } |
2362 | 2372 |
2363 bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl, | 2373 bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl, |
2364 gfx::PointF device_viewport_point) { | 2374 gfx::PointF device_viewport_point) { |
2365 if (layer_impl && layer_impl->ToScrollbarLayer()) { | 2375 if (layer_impl && layer_impl->ToScrollbarLayer()) { |
(...skipping 14 matching lines...) Expand all Loading... | |
2380 } | 2390 } |
2381 | 2391 |
2382 return false; | 2392 return false; |
2383 } | 2393 } |
2384 | 2394 |
2385 void LayerTreeHostImpl::PinchGestureBegin() { | 2395 void LayerTreeHostImpl::PinchGestureBegin() { |
2386 pinch_gesture_active_ = true; | 2396 pinch_gesture_active_ = true; |
2387 previous_pinch_anchor_ = gfx::Point(); | 2397 previous_pinch_anchor_ = gfx::Point(); |
2388 client_->RenewTreePriority(); | 2398 client_->RenewTreePriority(); |
2389 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); | 2399 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); |
2390 active_tree_->SetCurrentlyScrollingLayer(RootScrollLayer()); | 2400 if (active_tree_->OuterViewportScrollLayer()) { |
2401 active_tree_->SetCurrentlyScrollingLayer( | |
2402 active_tree_->OuterViewportScrollLayer()); | |
2403 } else { | |
2404 active_tree_->SetCurrentlyScrollingLayer( | |
2405 active_tree_->InnerViewportScrollLayer()); | |
2406 } | |
2391 if (top_controls_manager_) | 2407 if (top_controls_manager_) |
2392 top_controls_manager_->PinchBegin(); | 2408 top_controls_manager_->PinchBegin(); |
2393 } | 2409 } |
2394 | 2410 |
2395 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, | 2411 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, |
2396 gfx::Point anchor) { | 2412 gfx::Point anchor) { |
2397 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); | 2413 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); |
2398 | 2414 |
2399 if (!RootScrollLayer()) | 2415 LayerImpl* pinch_scroll_layer = CurrentlyScrollingLayer(); |
2416 if (!pinch_scroll_layer) | |
2417 pinch_scroll_layer = InnerViewportScrollLayer(); | |
2418 | |
2419 if (!pinch_scroll_layer) | |
2400 return; | 2420 return; |
2401 | 2421 |
2402 // Keep the center-of-pinch anchor specified by (x, y) in a stable | 2422 // Keep the center-of-pinch anchor specified by (x, y) in a stable |
2403 // position over the course of the magnify. | 2423 // position over the course of the magnify. |
2404 float page_scale_delta = active_tree_->page_scale_delta(); | 2424 float page_scale_delta = active_tree_->page_scale_delta(); |
2405 gfx::PointF previous_scale_anchor = | 2425 gfx::PointF previous_scale_anchor = |
2406 gfx::ScalePoint(anchor, 1.f / page_scale_delta); | 2426 gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
2407 active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta); | 2427 active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta); |
2408 page_scale_delta = active_tree_->page_scale_delta(); | 2428 page_scale_delta = active_tree_->page_scale_delta(); |
2409 gfx::PointF new_scale_anchor = | 2429 gfx::PointF new_scale_anchor = |
2410 gfx::ScalePoint(anchor, 1.f / page_scale_delta); | 2430 gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
2411 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; | 2431 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; |
2412 | 2432 |
2413 previous_pinch_anchor_ = anchor; | 2433 previous_pinch_anchor_ = anchor; |
2414 | 2434 |
2415 move.Scale(1 / active_tree_->page_scale_factor()); | 2435 move.Scale(1 / active_tree_->page_scale_factor()); |
2436 // When shrinking the page, the current scroll offset of the inner viewport | |
2437 // scroll layer may need to be adjusted so that it doesn't exceed its maximum | |
2438 // at the new page scale factor. | |
2439 if (magnify_delta < 1.f) { | |
2440 // If clamping the inner viewport scroll offset causes a change, it should | |
2441 // be accounted for from the intended move. | |
2442 move -= InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset(); | |
2443 } | |
2416 | 2444 |
2417 RootScrollLayer()->ScrollBy(move); | 2445 // We manually manage the bubbling behaviour here as it is different to that |
enne (OOO)
2013/11/14 22:59:01
Huh! I had hoped we wouldn't have to special case
enne (OOO)
2013/11/19 19:30:22
These changes in LayerTreeHostImpl about handling
wjmaclean
2013/12/24 21:03:49
Since we only have multiple viewports when the fla
wjmaclean
2013/12/24 21:03:49
Agreed!
| |
2446 // implemented in LayerTreeHostImpl::ScrollBy(). Specifically: | |
2447 // 1) we want to explicit limit the bubbling to the outer/inner viewports, | |
2448 // 2) we don't want the directional limitations on the unused parts that | |
2449 // ScrollBy() implements, and | |
2450 // 3) pinching should not engage the top controls manager. | |
2451 gfx::Vector2dF unused = pinch_scroll_layer->ScrollBy(move); | |
2452 | |
2453 if (!unused.IsZero() && pinch_scroll_layer == OuterViewportScrollLayer()) { | |
2454 InnerViewportScrollLayer()->ScrollBy(unused); | |
2455 InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset(); | |
2456 active_tree_->SetCurrentlyScrollingLayer( | |
2457 active_tree_->InnerViewportScrollLayer()); | |
2458 } | |
2418 | 2459 |
2419 client_->SetNeedsCommitOnImplThread(); | 2460 client_->SetNeedsCommitOnImplThread(); |
2420 client_->SetNeedsRedrawOnImplThread(); | 2461 client_->SetNeedsRedrawOnImplThread(); |
2421 client_->RenewTreePriority(); | 2462 client_->RenewTreePriority(); |
2422 } | 2463 } |
2423 | 2464 |
2424 void LayerTreeHostImpl::PinchGestureEnd() { | 2465 void LayerTreeHostImpl::PinchGestureEnd() { |
2425 pinch_gesture_active_ = false; | 2466 pinch_gesture_active_ = false; |
2426 if (pinch_gesture_end_should_clear_scrolling_layer_) { | 2467 if (pinch_gesture_end_should_clear_scrolling_layer_) { |
2427 pinch_gesture_end_should_clear_scrolling_layer_ = false; | 2468 pinch_gesture_end_should_clear_scrolling_layer_ = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2459 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); | 2500 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); |
2460 | 2501 |
2461 return scroll_info.Pass(); | 2502 return scroll_info.Pass(); |
2462 } | 2503 } |
2463 | 2504 |
2464 void LayerTreeHostImpl::SetFullRootLayerDamage() { | 2505 void LayerTreeHostImpl::SetFullRootLayerDamage() { |
2465 SetViewportDamage(gfx::Rect(DrawViewportSize())); | 2506 SetViewportDamage(gfx::Rect(DrawViewportSize())); |
2466 } | 2507 } |
2467 | 2508 |
2468 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { | 2509 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { |
2469 if (!page_scale_animation_ || !RootScrollLayer()) | 2510 if (!page_scale_animation_) |
2470 return; | 2511 return; |
2471 | 2512 |
2472 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); | 2513 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); |
2473 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + | 2514 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); |
2474 RootScrollLayer()->ScrollDelta(); | |
2475 | 2515 |
2476 if (!page_scale_animation_->IsAnimationStarted()) | 2516 if (!page_scale_animation_->IsAnimationStarted()) |
2477 page_scale_animation_->StartAnimation(monotonic_time); | 2517 page_scale_animation_->StartAnimation(monotonic_time); |
2478 | 2518 |
2479 active_tree_->SetPageScaleDelta( | 2519 active_tree_->SetPageScaleDelta( |
2480 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2520 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
2481 active_tree_->page_scale_factor()); | 2521 active_tree_->page_scale_factor()); |
2482 gfx::Vector2dF next_scroll = | 2522 gfx::Vector2dF next_scroll = |
2483 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2523 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); |
2484 | 2524 |
2485 RootScrollLayer()->ScrollBy(next_scroll - scroll_total); | 2525 ScrollBy(gfx::Point(), next_scroll - scroll_total); |
2486 client_->SetNeedsRedrawOnImplThread(); | 2526 client_->SetNeedsRedrawOnImplThread(); |
2487 | 2527 |
2488 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2528 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
2489 page_scale_animation_.reset(); | 2529 page_scale_animation_.reset(); |
2490 client_->SetNeedsCommitOnImplThread(); | 2530 client_->SetNeedsCommitOnImplThread(); |
2491 client_->RenewTreePriority(); | 2531 client_->RenewTreePriority(); |
2492 } | 2532 } |
2493 } | 2533 } |
2494 | 2534 |
2495 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { | 2535 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
2496 if (!top_controls_manager_ || !RootScrollLayer()) | 2536 if (!top_controls_manager_) |
2497 return; | 2537 return; |
2498 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); | 2538 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); |
2499 UpdateMaxScrollOffset(); | 2539 if (active_tree_->TotalScrollOffset().y() == 0.f) |
2500 if (RootScrollLayer()->TotalScrollOffset().y() == 0.f) | |
2501 return; | 2540 return; |
2502 RootScrollLayer()->ScrollBy(gfx::ScaleVector2d( | 2541 ScrollBy(gfx::Point(), |
2503 scroll, 1.f / active_tree_->total_page_scale_factor())); | 2542 gfx::ScaleVector2d(scroll, |
2543 1.f / active_tree_->total_page_scale_factor())); | |
2504 } | 2544 } |
2505 | 2545 |
2506 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time, | 2546 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time, |
2507 base::Time wall_clock_time) { | 2547 base::Time wall_clock_time) { |
2508 if (!settings_.accelerated_animation_enabled || | 2548 if (!settings_.accelerated_animation_enabled || |
2509 animation_registrar_->active_animation_controllers().empty() || | 2549 animation_registrar_->active_animation_controllers().empty() || |
2510 !active_tree_->root_layer()) | 2550 !active_tree_->root_layer()) |
2511 return; | 2551 return; |
2512 | 2552 |
2513 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); | 2553 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2835 std::set<UIResourceId>::iterator found_in_evicted = | 2875 std::set<UIResourceId>::iterator found_in_evicted = |
2836 evicted_ui_resources_.find(uid); | 2876 evicted_ui_resources_.find(uid); |
2837 if (found_in_evicted == evicted_ui_resources_.end()) | 2877 if (found_in_evicted == evicted_ui_resources_.end()) |
2838 return; | 2878 return; |
2839 evicted_ui_resources_.erase(found_in_evicted); | 2879 evicted_ui_resources_.erase(found_in_evicted); |
2840 if (evicted_ui_resources_.empty()) | 2880 if (evicted_ui_resources_.empty()) |
2841 client_->OnCanDrawStateChanged(CanDraw()); | 2881 client_->OnCanDrawStateChanged(CanDraw()); |
2842 } | 2882 } |
2843 | 2883 |
2844 } // namespace cc | 2884 } // namespace cc |
OLD | NEW |