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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 &memory_used_bytes); | 423 &memory_used_bytes); |
424 SendManagedMemoryStats(memory_required_bytes, | 424 SendManagedMemoryStats(memory_required_bytes, |
425 memory_nice_to_have_bytes, | 425 memory_nice_to_have_bytes, |
426 memory_used_bytes); | 426 memory_used_bytes); |
427 } | 427 } |
428 | 428 |
429 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, | 429 void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, |
430 bool anchor_point, | 430 bool anchor_point, |
431 float page_scale, | 431 float page_scale, |
432 base::TimeDelta duration) { | 432 base::TimeDelta duration) { |
433 if (!RootScrollLayer()) | 433 if (!InnerViewportScrollLayer()) |
434 return; | 434 return; |
435 | 435 |
436 gfx::Vector2dF scroll_total = | 436 // Should we attempt to set to OuterViewportScrollingLayer if it's available? |
437 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); | 437 active_tree_->SetCurrentlyScrollingLayer(InnerViewportScrollLayer()); |
| 438 |
| 439 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); |
438 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 440 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
439 gfx::SizeF viewport_size = UnscaledScrollableViewportSize(); | 441 gfx::SizeF viewport_size = UnscaledScrollableViewportSize(); |
440 | 442 |
441 // Easing constants experimentally determined. | 443 // Easing constants experimentally determined. |
442 scoped_ptr<TimingFunction> timing_function = | 444 scoped_ptr<TimingFunction> timing_function = |
443 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); | 445 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); |
444 | 446 |
445 page_scale_animation_ = | 447 page_scale_animation_ = |
446 PageScaleAnimation::Create(scroll_total, | 448 PageScaleAnimation::Create(scroll_total, |
447 active_tree_->total_page_scale_factor(), | 449 active_tree_->total_page_scale_factor(), |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); | 1296 metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); |
1295 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); | 1297 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); |
1296 if (top_controls_manager_) { | 1298 if (top_controls_manager_) { |
1297 metadata.location_bar_offset = | 1299 metadata.location_bar_offset = |
1298 gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset()); | 1300 gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset()); |
1299 metadata.location_bar_content_translation = | 1301 metadata.location_bar_content_translation = |
1300 gfx::Vector2dF(0.f, top_controls_manager_->content_top_offset()); | 1302 gfx::Vector2dF(0.f, top_controls_manager_->content_top_offset()); |
1301 metadata.overdraw_bottom_height = overdraw_bottom_height_; | 1303 metadata.overdraw_bottom_height = overdraw_bottom_height_; |
1302 } | 1304 } |
1303 | 1305 |
1304 if (!RootScrollLayer()) | 1306 if (!InnerViewportScrollLayer()) |
1305 return metadata; | 1307 return metadata; |
1306 | 1308 |
1307 metadata.root_scroll_offset = RootScrollLayer()->TotalScrollOffset(); | 1309 metadata.root_scroll_offset = active_tree_->TotalScrollOffset(); |
1308 | 1310 |
1309 return metadata; | 1311 return metadata; |
1310 } | 1312 } |
1311 | 1313 |
1312 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { | 1314 static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { |
1313 layer->DidBeginTracing(); | 1315 layer->DidBeginTracing(); |
1314 } | 1316 } |
1315 | 1317 |
1316 void LayerTreeHostImpl::DrawLayers(FrameData* frame, | 1318 void LayerTreeHostImpl::DrawLayers(FrameData* frame, |
1317 base::TimeTicks frame_begin_time) { | 1319 base::TimeTicks frame_begin_time) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 #endif | 1501 #endif |
1500 } | 1502 } |
1501 | 1503 |
1502 void LayerTreeHostImpl::Readback(void* pixels, | 1504 void LayerTreeHostImpl::Readback(void* pixels, |
1503 gfx::Rect rect_in_device_viewport) { | 1505 gfx::Rect rect_in_device_viewport) { |
1504 DCHECK(renderer_); | 1506 DCHECK(renderer_); |
1505 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); | 1507 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); |
1506 } | 1508 } |
1507 | 1509 |
1508 bool LayerTreeHostImpl::HaveRootScrollLayer() const { | 1510 bool LayerTreeHostImpl::HaveRootScrollLayer() const { |
1509 return !!RootScrollLayer(); | 1511 return !!InnerViewportScrollLayer(); |
1510 } | 1512 } |
1511 | 1513 |
1512 LayerImpl* LayerTreeHostImpl::RootLayer() const { | 1514 LayerImpl* LayerTreeHostImpl::RootLayer() const { |
1513 return active_tree_->root_layer(); | 1515 return active_tree_->root_layer(); |
1514 } | 1516 } |
1515 | 1517 |
1516 LayerImpl* LayerTreeHostImpl::RootScrollLayer() const { | 1518 LayerImpl* LayerTreeHostImpl::InnerViewportScrollLayer() const { |
1517 return active_tree_->RootScrollLayer(); | 1519 return active_tree_->InnerViewportScrollLayer(); |
| 1520 } |
| 1521 |
| 1522 LayerImpl* LayerTreeHostImpl::OuterViewportScrollLayer() const { |
| 1523 return active_tree_->OuterViewportScrollLayer(); |
1518 } | 1524 } |
1519 | 1525 |
1520 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { | 1526 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { |
1521 return active_tree_->CurrentlyScrollingLayer(); | 1527 return active_tree_->CurrentlyScrollingLayer(); |
1522 } | 1528 } |
1523 | 1529 |
1524 bool LayerTreeHostImpl::IsCurrentlyScrolling() const { | 1530 bool LayerTreeHostImpl::IsCurrentlyScrolling() const { |
1525 return CurrentlyScrollingLayer() || | 1531 return CurrentlyScrollingLayer() || |
1526 (RootScrollLayer() && RootScrollLayer()->IsExternalFlingActive()); | 1532 (InnerViewportScrollLayer() && |
| 1533 InnerViewportScrollLayer()->IsExternalFlingActive()) || |
| 1534 (OuterViewportScrollLayer() && |
| 1535 OuterViewportScrollLayer()->IsExternalFlingActive()); |
1527 } | 1536 } |
1528 | 1537 |
1529 // Content layers can be either directly scrollable or contained in an outer | 1538 // Content layers can be either directly scrollable or contained in an outer |
1530 // scrolling layer which applies the scroll transform. Given a content layer, | 1539 // scrolling layer which applies the scroll transform. Given a content layer, |
1531 // this function returns the associated scroll layer if any. | 1540 // this function returns the associated scroll layer if any. |
1532 static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { | 1541 static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { |
1533 if (!layer_impl) | 1542 if (!layer_impl) |
1534 return NULL; | 1543 return NULL; |
1535 | 1544 |
1536 if (layer_impl->scrollable()) | 1545 if (layer_impl->scrollable()) |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 | 1901 |
1893 void LayerTreeHostImpl::SetViewportSize(gfx::Size device_viewport_size) { | 1902 void LayerTreeHostImpl::SetViewportSize(gfx::Size device_viewport_size) { |
1894 if (device_viewport_size == device_viewport_size_) | 1903 if (device_viewport_size == device_viewport_size_) |
1895 return; | 1904 return; |
1896 | 1905 |
1897 if (pending_tree_) | 1906 if (pending_tree_) |
1898 active_tree_->SetViewportSizeInvalid(); | 1907 active_tree_->SetViewportSizeInvalid(); |
1899 | 1908 |
1900 device_viewport_size_ = device_viewport_size; | 1909 device_viewport_size_ = device_viewport_size; |
1901 | 1910 |
1902 UpdateMaxScrollOffset(); | |
1903 | |
1904 client_->OnCanDrawStateChanged(CanDraw()); | 1911 client_->OnCanDrawStateChanged(CanDraw()); |
1905 SetFullRootLayerDamage(); | 1912 SetFullRootLayerDamage(); |
1906 } | 1913 } |
1907 | 1914 |
1908 void LayerTreeHostImpl::SetOverdrawBottomHeight(float overdraw_bottom_height) { | 1915 void LayerTreeHostImpl::SetOverdrawBottomHeight(float overdraw_bottom_height) { |
1909 if (overdraw_bottom_height == overdraw_bottom_height_) | 1916 if (overdraw_bottom_height == overdraw_bottom_height_) |
1910 return; | 1917 return; |
1911 overdraw_bottom_height_ = overdraw_bottom_height; | 1918 overdraw_bottom_height_ = overdraw_bottom_height; |
1912 | 1919 |
1913 UpdateMaxScrollOffset(); | |
1914 SetFullRootLayerDamage(); | 1920 SetFullRootLayerDamage(); |
1915 } | 1921 } |
1916 | 1922 |
1917 void LayerTreeHostImpl::SetOverhangUIResource( | 1923 void LayerTreeHostImpl::SetOverhangUIResource( |
1918 UIResourceId overhang_ui_resource_id, | 1924 UIResourceId overhang_ui_resource_id, |
1919 gfx::Size overhang_ui_resource_size) { | 1925 gfx::Size overhang_ui_resource_size) { |
1920 overhang_ui_resource_id_ = overhang_ui_resource_id; | 1926 overhang_ui_resource_id_ = overhang_ui_resource_id; |
1921 overhang_ui_resource_size_ = overhang_ui_resource_size; | 1927 overhang_ui_resource_size_ = overhang_ui_resource_size; |
1922 } | 1928 } |
1923 | 1929 |
1924 void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) { | 1930 void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) { |
1925 if (device_scale_factor == device_scale_factor_) | 1931 if (device_scale_factor == device_scale_factor_) |
1926 return; | 1932 return; |
1927 device_scale_factor_ = device_scale_factor; | 1933 device_scale_factor_ = device_scale_factor; |
1928 | 1934 |
1929 UpdateMaxScrollOffset(); | |
1930 SetFullRootLayerDamage(); | 1935 SetFullRootLayerDamage(); |
1931 } | 1936 } |
1932 | 1937 |
1933 gfx::Size LayerTreeHostImpl::DrawViewportSize() const { | 1938 gfx::Size LayerTreeHostImpl::DrawViewportSize() const { |
1934 return DeviceViewport().size(); | 1939 return DeviceViewport().size(); |
1935 } | 1940 } |
1936 | 1941 |
1937 gfx::Rect LayerTreeHostImpl::DeviceViewport() const { | 1942 gfx::Rect LayerTreeHostImpl::DeviceViewport() const { |
1938 if (external_viewport_.IsEmpty()) | 1943 if (external_viewport_.IsEmpty()) |
1939 return gfx::Rect(device_viewport_size_); | 1944 return gfx::Rect(device_viewport_size_); |
1940 | 1945 |
1941 return external_viewport_; | 1946 return external_viewport_; |
1942 } | 1947 } |
1943 | 1948 |
1944 gfx::Rect LayerTreeHostImpl::DeviceClip() const { | 1949 gfx::Rect LayerTreeHostImpl::DeviceClip() const { |
1945 if (external_clip_.IsEmpty()) | 1950 if (external_clip_.IsEmpty()) |
1946 return DeviceViewport(); | 1951 return DeviceViewport(); |
1947 | 1952 |
1948 return external_clip_; | 1953 return external_clip_; |
1949 } | 1954 } |
1950 | 1955 |
1951 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { | 1956 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { |
1952 return external_transform_; | 1957 return external_transform_; |
1953 } | 1958 } |
1954 | 1959 |
1955 void LayerTreeHostImpl::UpdateMaxScrollOffset() { | |
1956 active_tree_->UpdateMaxScrollOffset(); | |
1957 } | |
1958 | |
1959 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 1960 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
1960 SetNeedsRedraw(); | 1961 SetNeedsRedraw(); |
1961 active_tree_->set_needs_update_draw_properties(); | 1962 active_tree_->set_needs_update_draw_properties(); |
1962 SetFullRootLayerDamage(); | 1963 SetFullRootLayerDamage(); |
1963 } | 1964 } |
1964 | 1965 |
1965 bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { | 1966 bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { |
1966 active_tree_->UpdateDrawProperties(); | 1967 active_tree_->UpdateDrawProperties(); |
1967 return !active_tree_->RenderSurfaceLayerList().empty(); | 1968 return !active_tree_->RenderSurfaceLayerList().empty(); |
1968 } | 1969 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 if (status == ScrollStarted && !potentially_scrolling_layer_impl) | 2009 if (status == ScrollStarted && !potentially_scrolling_layer_impl) |
2009 potentially_scrolling_layer_impl = scroll_layer_impl; | 2010 potentially_scrolling_layer_impl = scroll_layer_impl; |
2010 } | 2011 } |
2011 | 2012 |
2012 // When hiding top controls is enabled and the controls are hidden or | 2013 // When hiding top controls is enabled and the controls are hidden or |
2013 // overlaying the content, force scrolls to be enabled on the root layer to | 2014 // overlaying the content, force scrolls to be enabled on the root layer to |
2014 // allow bringing the top controls back into view. | 2015 // allow bringing the top controls back into view. |
2015 if (!potentially_scrolling_layer_impl && top_controls_manager_ && | 2016 if (!potentially_scrolling_layer_impl && top_controls_manager_ && |
2016 top_controls_manager_->content_top_offset() != | 2017 top_controls_manager_->content_top_offset() != |
2017 settings_.top_controls_height) { | 2018 settings_.top_controls_height) { |
2018 potentially_scrolling_layer_impl = RootScrollLayer(); | 2019 potentially_scrolling_layer_impl = |
| 2020 OuterViewportScrollLayer() ? OuterViewportScrollLayer() |
| 2021 : InnerViewportScrollLayer(); |
2019 } | 2022 } |
2020 | 2023 |
2021 return potentially_scrolling_layer_impl; | 2024 return potentially_scrolling_layer_impl; |
2022 } | 2025 } |
2023 | 2026 |
2024 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 2027 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
2025 gfx::Point viewport_point, InputHandler::ScrollInputType type) { | 2028 gfx::Point viewport_point, InputHandler::ScrollInputType type) { |
2026 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2029 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
2027 | 2030 |
2028 if (top_controls_manager_) | 2031 if (top_controls_manager_) |
(...skipping 15 matching lines...) Expand all Loading... |
2044 FindScrollLayerForDeviceViewportPoint(device_viewport_point, type, | 2047 FindScrollLayerForDeviceViewportPoint(device_viewport_point, type, |
2045 layer_impl, &scroll_on_main_thread); | 2048 layer_impl, &scroll_on_main_thread); |
2046 | 2049 |
2047 if (scroll_on_main_thread) { | 2050 if (scroll_on_main_thread) { |
2048 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); | 2051 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); |
2049 return ScrollOnMainThread; | 2052 return ScrollOnMainThread; |
2050 } | 2053 } |
2051 | 2054 |
2052 // If we want to send a DidOverscroll for this scroll it can't be ignored. | 2055 // If we want to send a DidOverscroll for this scroll it can't be ignored. |
2053 if (!potentially_scrolling_layer_impl && settings_.always_overscroll) | 2056 if (!potentially_scrolling_layer_impl && settings_.always_overscroll) |
2054 potentially_scrolling_layer_impl = RootScrollLayer(); | 2057 potentially_scrolling_layer_impl = |
| 2058 OuterViewportScrollLayer() ? OuterViewportScrollLayer() |
| 2059 : InnerViewportScrollLayer(); |
2055 | 2060 |
2056 if (potentially_scrolling_layer_impl) { | 2061 if (potentially_scrolling_layer_impl) { |
2057 active_tree_->SetCurrentlyScrollingLayer( | 2062 active_tree_->SetCurrentlyScrollingLayer( |
2058 potentially_scrolling_layer_impl); | 2063 potentially_scrolling_layer_impl); |
2059 should_bubble_scrolls_ = (type != NonBubblingGesture); | 2064 should_bubble_scrolls_ = (type != NonBubblingGesture); |
2060 wheel_scrolling_ = (type == Wheel); | 2065 wheel_scrolling_ = (type == Wheel); |
2061 client_->RenewTreePriority(); | 2066 client_->RenewTreePriority(); |
2062 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); | 2067 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
2063 return ScrollStarted; | 2068 return ScrollStarted; |
2064 } | 2069 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2151 bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point, | 2156 bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point, |
2152 gfx::Vector2dF scroll_delta) { | 2157 gfx::Vector2dF scroll_delta) { |
2153 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 2158 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
2154 if (!CurrentlyScrollingLayer()) | 2159 if (!CurrentlyScrollingLayer()) |
2155 return false; | 2160 return false; |
2156 | 2161 |
2157 gfx::Vector2dF pending_delta = scroll_delta; | 2162 gfx::Vector2dF pending_delta = scroll_delta; |
2158 gfx::Vector2dF unused_root_delta; | 2163 gfx::Vector2dF unused_root_delta; |
2159 bool did_scroll_x = false; | 2164 bool did_scroll_x = false; |
2160 bool did_scroll_y = false; | 2165 bool did_scroll_y = false; |
2161 bool consume_by_top_controls = top_controls_manager_ && | 2166 bool consume_by_top_controls = |
2162 (CurrentlyScrollingLayer() == RootScrollLayer() || scroll_delta.y() < 0); | 2167 top_controls_manager_ && |
| 2168 (CurrentlyScrollingLayer() == InnerViewportScrollLayer() || |
| 2169 scroll_delta.y() < 0); |
2163 | 2170 |
2164 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2171 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2165 layer_impl; | 2172 layer_impl; |
2166 layer_impl = layer_impl->parent()) { | 2173 layer_impl = layer_impl->parent()) { |
2167 if (!layer_impl->scrollable()) | 2174 if (!layer_impl->scrollable()) |
2168 continue; | 2175 continue; |
2169 | 2176 |
2170 if (layer_impl == RootScrollLayer()) { | 2177 if (layer_impl == InnerViewportScrollLayer()) { |
2171 // Only allow bubble scrolling when the scroll is in the direction to make | 2178 // Only allow bubble scrolling when the scroll is in the direction to make |
2172 // the top controls visible. | 2179 // the top controls visible. |
2173 if (consume_by_top_controls && layer_impl == RootScrollLayer()) { | 2180 gfx::Vector2dF applied_delta; |
2174 pending_delta = top_controls_manager_->ScrollBy(pending_delta); | 2181 gfx::Vector2dF excess_delta; |
2175 UpdateMaxScrollOffset(); | 2182 if (consume_by_top_controls && layer_impl == InnerViewportScrollLayer()) { |
| 2183 excess_delta = top_controls_manager_->ScrollBy(pending_delta); |
| 2184 applied_delta = pending_delta - excess_delta; |
| 2185 pending_delta = excess_delta; |
| 2186 // Force updating of vertical adjust values if needed. |
| 2187 if (applied_delta.y() != 0) |
| 2188 layer_impl->ScrollbarParametersDidChange(); |
2176 } | 2189 } |
2177 // Track root layer deltas for reporting overscroll. | 2190 // Track root layer deltas for reporting overscroll. |
2178 unused_root_delta = pending_delta; | 2191 unused_root_delta = pending_delta; |
2179 } | 2192 } |
2180 | 2193 |
2181 gfx::Vector2dF applied_delta; | 2194 gfx::Vector2dF applied_delta; |
2182 // Gesture events need to be transformed from viewport coordinates to local | 2195 // Gesture events need to be transformed from viewport coordinates to local |
2183 // layer coordinates so that the scrolling contents exactly follow the | 2196 // layer coordinates so that the scrolling contents exactly follow the |
2184 // user's finger. In contrast, wheel events represent a fixed amount of | 2197 // user's finger. In contrast, wheel events represent a fixed amount of |
2185 // scrolling so we can just apply them directly. | 2198 // scrolling so we can just apply them directly. |
(...skipping 13 matching lines...) Expand all Loading... |
2199 bool did_move_layer_y = std::abs(applied_delta.y()) > move_threshold; | 2212 bool did_move_layer_y = std::abs(applied_delta.y()) > move_threshold; |
2200 did_scroll_x |= did_move_layer_x; | 2213 did_scroll_x |= did_move_layer_x; |
2201 did_scroll_y |= did_move_layer_y; | 2214 did_scroll_y |= did_move_layer_y; |
2202 if (!did_move_layer_x && !did_move_layer_y) { | 2215 if (!did_move_layer_x && !did_move_layer_y) { |
2203 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) | 2216 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) |
2204 continue; | 2217 continue; |
2205 else | 2218 else |
2206 break; | 2219 break; |
2207 } | 2220 } |
2208 | 2221 |
2209 if (layer_impl == RootScrollLayer()) | 2222 if (layer_impl == InnerViewportScrollLayer() || |
| 2223 layer_impl == OuterViewportScrollLayer()) |
2210 unused_root_delta.Subtract(applied_delta); | 2224 unused_root_delta.Subtract(applied_delta); |
2211 | 2225 |
2212 did_lock_scrolling_layer_ = true; | 2226 did_lock_scrolling_layer_ = true; |
2213 if (!should_bubble_scrolls_) { | 2227 if (!should_bubble_scrolls_) { |
2214 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2228 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2215 break; | 2229 break; |
2216 } | 2230 } |
2217 | 2231 |
2218 // If the applied delta is within 45 degrees of the input delta, bail out to | 2232 // If the applied delta is within 45 degrees of the input delta, bail out to |
2219 // make it easier to scroll just one layer in one direction without | 2233 // 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... |
2266 bool LayerTreeHostImpl::ScrollVerticallyByPage(gfx::Point viewport_point, | 2280 bool LayerTreeHostImpl::ScrollVerticallyByPage(gfx::Point viewport_point, |
2267 ScrollDirection direction) { | 2281 ScrollDirection direction) { |
2268 DCHECK(wheel_scrolling_); | 2282 DCHECK(wheel_scrolling_); |
2269 | 2283 |
2270 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2284 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2271 layer_impl; | 2285 layer_impl; |
2272 layer_impl = layer_impl->parent()) { | 2286 layer_impl = layer_impl->parent()) { |
2273 if (!layer_impl->scrollable()) | 2287 if (!layer_impl->scrollable()) |
2274 continue; | 2288 continue; |
2275 | 2289 |
2276 if (!layer_impl->vertical_scrollbar_layer()) | 2290 if (!layer_impl->HasScrollbar(VERTICAL)) |
2277 continue; | 2291 continue; |
2278 | 2292 |
2279 float height = layer_impl->vertical_scrollbar_layer()->bounds().height(); | 2293 float height = layer_impl->clip_height(); |
2280 | 2294 |
2281 // These magical values match WebKit and are designed to scroll nearly the | 2295 // These magical values match WebKit and are designed to scroll nearly the |
2282 // entire visible content height but leave a bit of overlap. | 2296 // entire visible content height but leave a bit of overlap. |
2283 float page = std::max(height * 0.875f, 1.f); | 2297 float page = std::max(height * 0.875f, 1.f); |
2284 if (direction == SCROLL_BACKWARD) | 2298 if (direction == SCROLL_BACKWARD) |
2285 page = -page; | 2299 page = -page; |
2286 | 2300 |
2287 gfx::Vector2dF delta = gfx::Vector2dF(0.f, page); | 2301 gfx::Vector2dF delta = gfx::Vector2dF(0.f, page); |
2288 | 2302 |
2289 gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta); | 2303 gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 top_controls_manager_->ScrollEnd(); | 2339 top_controls_manager_->ScrollEnd(); |
2326 ClearCurrentlyScrollingLayer(); | 2340 ClearCurrentlyScrollingLayer(); |
2327 StartScrollbarAnimation(); | 2341 StartScrollbarAnimation(); |
2328 } | 2342 } |
2329 | 2343 |
2330 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { | 2344 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
2331 if (!active_tree_->CurrentlyScrollingLayer()) | 2345 if (!active_tree_->CurrentlyScrollingLayer()) |
2332 return ScrollIgnored; | 2346 return ScrollIgnored; |
2333 | 2347 |
2334 if (settings_.ignore_root_layer_flings && | 2348 if (settings_.ignore_root_layer_flings && |
2335 active_tree_->CurrentlyScrollingLayer() == | 2349 (active_tree_->CurrentlyScrollingLayer() == InnerViewportScrollLayer() || |
2336 active_tree_->RootScrollLayer()) { | 2350 active_tree_->CurrentlyScrollingLayer() == OuterViewportScrollLayer())) { |
2337 ClearCurrentlyScrollingLayer(); | 2351 ClearCurrentlyScrollingLayer(); |
2338 return ScrollIgnored; | 2352 return ScrollIgnored; |
2339 } | 2353 } |
2340 | 2354 |
2341 if (!wheel_scrolling_) { | 2355 if (!wheel_scrolling_) { |
2342 // Allow the fling to lock to the first layer that moves after the initial | 2356 // Allow the fling to lock to the first layer that moves after the initial |
2343 // fling |ScrollBy()| event. | 2357 // fling |ScrollBy()| event. |
2344 did_lock_scrolling_layer_ = false; | 2358 did_lock_scrolling_layer_ = false; |
2345 should_bubble_scrolls_ = false; | 2359 should_bubble_scrolls_ = false; |
2346 } | 2360 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 device_viewport_point, InputHandler::Gesture, layer_impl, | 2415 device_viewport_point, InputHandler::Gesture, layer_impl, |
2402 &scroll_on_main_thread); | 2416 &scroll_on_main_thread); |
2403 if (scroll_on_main_thread || !scroll_layer_impl) | 2417 if (scroll_on_main_thread || !scroll_layer_impl) |
2404 return; | 2418 return; |
2405 | 2419 |
2406 ScrollbarAnimationController* animation_controller = | 2420 ScrollbarAnimationController* animation_controller = |
2407 scroll_layer_impl->scrollbar_animation_controller(); | 2421 scroll_layer_impl->scrollbar_animation_controller(); |
2408 if (!animation_controller) | 2422 if (!animation_controller) |
2409 return; | 2423 return; |
2410 | 2424 |
2411 float distance_to_scrollbar = std::min( | 2425 // TODO(wjmaclean) Is it ok to choose distance from more than two scrollbars? |
2412 DeviceSpaceDistanceToLayer(device_viewport_point, | 2426 float distance_to_scrollbar = std::numeric_limits<float>::max(); |
2413 scroll_layer_impl->horizontal_scrollbar_layer()), | 2427 for (LayerImpl::ScrollbarSet::iterator it = |
2414 DeviceSpaceDistanceToLayer(device_viewport_point, | 2428 scroll_layer_impl->scrollbars()->begin(); |
2415 scroll_layer_impl->vertical_scrollbar_layer())); | 2429 it != scroll_layer_impl->scrollbars()->end(); |
| 2430 ++it) |
| 2431 distance_to_scrollbar = std::min(distance_to_scrollbar, |
| 2432 DeviceSpaceDistanceToLayer(device_viewport_point, *it)); |
2416 | 2433 |
2417 bool should_animate = animation_controller->DidMouseMoveNear( | 2434 bool should_animate = animation_controller->DidMouseMoveNear( |
2418 CurrentPhysicalTimeTicks(), distance_to_scrollbar / device_scale_factor_); | 2435 CurrentPhysicalTimeTicks(), distance_to_scrollbar / device_scale_factor_); |
2419 if (should_animate) | 2436 if (should_animate) |
2420 StartScrollbarAnimation(); | 2437 StartScrollbarAnimation(); |
2421 } | 2438 } |
2422 | 2439 |
2423 bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl, | 2440 bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl, |
2424 gfx::PointF device_viewport_point) { | 2441 gfx::PointF device_viewport_point) { |
2425 if (layer_impl && layer_impl->ToScrollbarLayer()) { | 2442 if (layer_impl && layer_impl->ToScrollbarLayer()) { |
(...skipping 14 matching lines...) Expand all Loading... |
2440 } | 2457 } |
2441 | 2458 |
2442 return false; | 2459 return false; |
2443 } | 2460 } |
2444 | 2461 |
2445 void LayerTreeHostImpl::PinchGestureBegin() { | 2462 void LayerTreeHostImpl::PinchGestureBegin() { |
2446 pinch_gesture_active_ = true; | 2463 pinch_gesture_active_ = true; |
2447 previous_pinch_anchor_ = gfx::Point(); | 2464 previous_pinch_anchor_ = gfx::Point(); |
2448 client_->RenewTreePriority(); | 2465 client_->RenewTreePriority(); |
2449 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); | 2466 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); |
2450 active_tree_->SetCurrentlyScrollingLayer(RootScrollLayer()); | 2467 if (active_tree_->OuterViewportScrollLayer()) { |
| 2468 active_tree_->SetCurrentlyScrollingLayer( |
| 2469 active_tree_->OuterViewportScrollLayer()); |
| 2470 } else { |
| 2471 active_tree_->SetCurrentlyScrollingLayer( |
| 2472 active_tree_->InnerViewportScrollLayer()); |
| 2473 } |
2451 if (top_controls_manager_) | 2474 if (top_controls_manager_) |
2452 top_controls_manager_->PinchBegin(); | 2475 top_controls_manager_->PinchBegin(); |
2453 } | 2476 } |
2454 | 2477 |
2455 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, | 2478 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, |
2456 gfx::Point anchor) { | 2479 gfx::Point anchor) { |
2457 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); | 2480 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); |
2458 | 2481 |
2459 if (!RootScrollLayer()) | 2482 LayerImpl* pinch_scroll_layer = CurrentlyScrollingLayer(); |
| 2483 if (!pinch_scroll_layer) |
| 2484 pinch_scroll_layer = InnerViewportScrollLayer(); |
| 2485 |
| 2486 if (!pinch_scroll_layer) |
2460 return; | 2487 return; |
2461 | 2488 |
2462 // Keep the center-of-pinch anchor specified by (x, y) in a stable | 2489 // Keep the center-of-pinch anchor specified by (x, y) in a stable |
2463 // position over the course of the magnify. | 2490 // position over the course of the magnify. |
2464 float page_scale_delta = active_tree_->page_scale_delta(); | 2491 float page_scale_delta = active_tree_->page_scale_delta(); |
2465 gfx::PointF previous_scale_anchor = | 2492 gfx::PointF previous_scale_anchor = |
2466 gfx::ScalePoint(anchor, 1.f / page_scale_delta); | 2493 gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
2467 active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta); | 2494 active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta); |
2468 page_scale_delta = active_tree_->page_scale_delta(); | 2495 page_scale_delta = active_tree_->page_scale_delta(); |
2469 gfx::PointF new_scale_anchor = | 2496 gfx::PointF new_scale_anchor = |
2470 gfx::ScalePoint(anchor, 1.f / page_scale_delta); | 2497 gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
2471 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; | 2498 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; |
2472 | 2499 |
2473 previous_pinch_anchor_ = anchor; | 2500 previous_pinch_anchor_ = anchor; |
2474 | 2501 |
2475 move.Scale(1 / active_tree_->page_scale_factor()); | 2502 move.Scale(1 / active_tree_->page_scale_factor()); |
| 2503 // When shrinking the page, the current scroll offset of the inner viewport |
| 2504 // scroll layer may need to be adjusted so that it doesn't exceed its maximum |
| 2505 // at the new page scale factor. |
| 2506 if (magnify_delta < 1.f) { |
| 2507 // If clamping the inner viewport scroll offset causes a change, it should |
| 2508 // be accounted for from the intended move. |
| 2509 move -= InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset(); |
| 2510 } |
2476 | 2511 |
2477 RootScrollLayer()->ScrollBy(move); | 2512 // We manually manage the bubbling behaviour here as it is different to that |
| 2513 // implemented in LayerTreeHostImpl::ScrollBy(). Specifically: |
| 2514 // 1) we want to explicit limit the bubbling to the outer/inner viewports, |
| 2515 // 2) we don't want the directional limitations on the unused parts that |
| 2516 // ScrollBy() implements, and |
| 2517 // 3) pinching should not engage the top controls manager. |
| 2518 gfx::Vector2dF unused = pinch_scroll_layer->ScrollBy(move); |
| 2519 |
| 2520 if (!unused.IsZero() && pinch_scroll_layer == OuterViewportScrollLayer()) { |
| 2521 InnerViewportScrollLayer()->ScrollBy(unused); |
| 2522 InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset(); |
| 2523 active_tree_->SetCurrentlyScrollingLayer( |
| 2524 active_tree_->InnerViewportScrollLayer()); |
| 2525 } |
2478 | 2526 |
2479 client_->SetNeedsCommitOnImplThread(); | 2527 client_->SetNeedsCommitOnImplThread(); |
2480 SetNeedsRedraw(); | 2528 SetNeedsRedraw(); |
2481 client_->RenewTreePriority(); | 2529 client_->RenewTreePriority(); |
2482 } | 2530 } |
2483 | 2531 |
2484 void LayerTreeHostImpl::PinchGestureEnd() { | 2532 void LayerTreeHostImpl::PinchGestureEnd() { |
2485 pinch_gesture_active_ = false; | 2533 pinch_gesture_active_ = false; |
2486 if (pinch_gesture_end_should_clear_scrolling_layer_) { | 2534 if (pinch_gesture_end_should_clear_scrolling_layer_) { |
2487 pinch_gesture_end_should_clear_scrolling_layer_ = false; | 2535 pinch_gesture_end_should_clear_scrolling_layer_ = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2519 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); | 2567 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); |
2520 | 2568 |
2521 return scroll_info.Pass(); | 2569 return scroll_info.Pass(); |
2522 } | 2570 } |
2523 | 2571 |
2524 void LayerTreeHostImpl::SetFullRootLayerDamage() { | 2572 void LayerTreeHostImpl::SetFullRootLayerDamage() { |
2525 SetViewportDamage(gfx::Rect(DrawViewportSize())); | 2573 SetViewportDamage(gfx::Rect(DrawViewportSize())); |
2526 } | 2574 } |
2527 | 2575 |
2528 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { | 2576 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { |
2529 if (!page_scale_animation_ || !RootScrollLayer()) | 2577 if (!page_scale_animation_) |
2530 return; | 2578 return; |
2531 | 2579 |
2532 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); | 2580 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); |
2533 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + | 2581 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); |
2534 RootScrollLayer()->ScrollDelta(); | |
2535 | 2582 |
2536 if (!page_scale_animation_->IsAnimationStarted()) | 2583 if (!page_scale_animation_->IsAnimationStarted()) |
2537 page_scale_animation_->StartAnimation(monotonic_time); | 2584 page_scale_animation_->StartAnimation(monotonic_time); |
2538 | 2585 |
2539 active_tree_->SetPageScaleDelta( | 2586 active_tree_->SetPageScaleDelta( |
2540 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2587 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
2541 active_tree_->page_scale_factor()); | 2588 active_tree_->page_scale_factor()); |
2542 gfx::Vector2dF next_scroll = | 2589 gfx::Vector2dF next_scroll = |
2543 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2590 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); |
2544 | 2591 |
2545 RootScrollLayer()->ScrollBy(next_scroll - scroll_total); | 2592 ScrollBy(gfx::Point(), next_scroll - scroll_total); |
2546 SetNeedsRedraw(); | 2593 SetNeedsRedraw(); |
2547 | 2594 |
2548 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2595 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
2549 page_scale_animation_.reset(); | 2596 page_scale_animation_.reset(); |
2550 client_->SetNeedsCommitOnImplThread(); | 2597 client_->SetNeedsCommitOnImplThread(); |
2551 client_->RenewTreePriority(); | 2598 client_->RenewTreePriority(); |
2552 } | 2599 } |
2553 } | 2600 } |
2554 | 2601 |
2555 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { | 2602 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
2556 if (!top_controls_manager_ || !RootScrollLayer()) | 2603 if (!top_controls_manager_) |
2557 return; | 2604 return; |
2558 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); | 2605 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); |
2559 UpdateMaxScrollOffset(); | 2606 if (active_tree_->TotalScrollOffset().y() == 0.f) |
2560 if (RootScrollLayer()->TotalScrollOffset().y() == 0.f) | |
2561 return; | 2607 return; |
2562 RootScrollLayer()->ScrollBy(gfx::ScaleVector2d( | 2608 ScrollBy(gfx::Point(), |
2563 scroll, 1.f / active_tree_->total_page_scale_factor())); | 2609 gfx::ScaleVector2d(scroll, |
| 2610 1.f / active_tree_->total_page_scale_factor())); |
2564 } | 2611 } |
2565 | 2612 |
2566 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time, | 2613 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time, |
2567 base::Time wall_clock_time) { | 2614 base::Time wall_clock_time) { |
2568 if (!settings_.accelerated_animation_enabled || | 2615 if (!settings_.accelerated_animation_enabled || |
2569 animation_registrar_->active_animation_controllers().empty() || | 2616 animation_registrar_->active_animation_controllers().empty() || |
2570 !active_tree_->root_layer()) | 2617 !active_tree_->root_layer()) |
2571 return; | 2618 return; |
2572 | 2619 |
2573 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); | 2620 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2914 swap_promise_monitor_.erase(monitor); | 2961 swap_promise_monitor_.erase(monitor); |
2915 } | 2962 } |
2916 | 2963 |
2917 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 2964 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
2918 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 2965 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
2919 for (; it != swap_promise_monitor_.end(); it++) | 2966 for (; it != swap_promise_monitor_.end(); it++) |
2920 (*it)->OnSetNeedsRedrawOnImpl(); | 2967 (*it)->OnSetNeedsRedrawOnImpl(); |
2921 } | 2968 } |
2922 | 2969 |
2923 } // namespace cc | 2970 } // namespace cc |
OLD | NEW |