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