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