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