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