| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host_impl.h" | 7 #include "cc/layer_tree_host_impl.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "cc/append_quads_data.h" | 11 #include "cc/append_quads_data.h" |
| 12 #include "cc/damage_tracker.h" | 12 #include "cc/damage_tracker.h" |
| 13 #include "cc/debug_rect_history.h" | 13 #include "cc/debug_rect_history.h" |
| 14 #include "cc/delay_based_time_source.h" | 14 #include "cc/delay_based_time_source.h" |
| 15 #include "cc/font_atlas.h" | 15 #include "cc/font_atlas.h" |
| 16 #include "cc/frame_rate_counter.h" | 16 #include "cc/frame_rate_counter.h" |
| 17 #include "cc/geometry.h" |
| 17 #include "cc/gl_renderer.h" | 18 #include "cc/gl_renderer.h" |
| 18 #include "cc/heads_up_display_layer_impl.h" | 19 #include "cc/heads_up_display_layer_impl.h" |
| 19 #include "cc/layer_iterator.h" | 20 #include "cc/layer_iterator.h" |
| 20 #include "cc/layer_tree_host.h" | 21 #include "cc/layer_tree_host.h" |
| 21 #include "cc/layer_tree_host_common.h" | 22 #include "cc/layer_tree_host_common.h" |
| 22 #include "cc/math_util.h" | 23 #include "cc/math_util.h" |
| 23 #include "cc/overdraw_metrics.h" | 24 #include "cc/overdraw_metrics.h" |
| 24 #include "cc/page_scale_animation.h" | 25 #include "cc/page_scale_animation.h" |
| 25 #include "cc/prioritized_texture_manager.h" | 26 #include "cc/prioritized_texture_manager.h" |
| 26 #include "cc/render_pass_draw_quad.h" | 27 #include "cc/render_pass_draw_quad.h" |
| 27 #include "cc/rendering_stats.h" | 28 #include "cc/rendering_stats.h" |
| 28 #include "cc/scrollbar_animation_controller.h" | 29 #include "cc/scrollbar_animation_controller.h" |
| 29 #include "cc/scrollbar_layer_impl.h" | 30 #include "cc/scrollbar_layer_impl.h" |
| 30 #include "cc/settings.h" | 31 #include "cc/settings.h" |
| 31 #include "cc/single_thread_proxy.h" | 32 #include "cc/single_thread_proxy.h" |
| 32 #include "cc/software_renderer.h" | 33 #include "cc/software_renderer.h" |
| 33 #include "cc/texture_uploader.h" | 34 #include "cc/texture_uploader.h" |
| 34 #include "ui/gfx/size_conversions.h" | 35 #include "ui/gfx/size_conversions.h" |
| 36 #include "ui/gfx/vector2d_conversions.h" |
| 35 #include <algorithm> | 37 #include <algorithm> |
| 36 | 38 |
| 37 using WebKit::WebTransformationMatrix; | 39 using WebKit::WebTransformationMatrix; |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) | 43 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) |
| 42 { | 44 { |
| 43 if (visible) { | 45 if (visible) { |
| 44 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); | 46 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 m_pageScaleFactor = pageScaleFactor; | 96 m_pageScaleFactor = pageScaleFactor; |
| 95 return true; | 97 return true; |
| 96 } | 98 } |
| 97 | 99 |
| 98 gfx::RectF PinchZoomViewport::bounds() const | 100 gfx::RectF PinchZoomViewport::bounds() const |
| 99 { | 101 { |
| 100 gfx::SizeF scaledViewportSize = m_layoutViewportSize; | 102 gfx::SizeF scaledViewportSize = m_layoutViewportSize; |
| 101 scaledViewportSize = scaledViewportSize.Scale(1 / totalPageScaleFactor()); | 103 scaledViewportSize = scaledViewportSize.Scale(1 / totalPageScaleFactor()); |
| 102 | 104 |
| 103 gfx::RectF bounds(gfx::PointF(), scaledViewportSize); | 105 gfx::RectF bounds(gfx::PointF(), scaledViewportSize); |
| 104 bounds.set_origin(m_pinchViewportScrollDelta); | 106 bounds.Offset(m_pinchViewportScrollDelta); |
| 105 | 107 |
| 106 return bounds; | 108 return bounds; |
| 107 } | 109 } |
| 108 | 110 |
| 109 FloatSize PinchZoomViewport::applyScroll(const gfx::Vector2dF& delta) | 111 gfx::Vector2dF PinchZoomViewport::applyScroll(const gfx::Vector2dF& delta) |
| 110 { | 112 { |
| 111 gfx::Vector2dF overflow; | 113 gfx::Vector2dF overflow; |
| 112 gfx::RectF pinchedBounds = bounds(); | 114 gfx::RectF pinchedBounds = bounds(); |
| 113 | 115 |
| 114 pinchedBounds.Offset(delta); | 116 pinchedBounds.Offset(delta); |
| 115 if (pinchedBounds.x() < 0) { | 117 if (pinchedBounds.x() < 0) { |
| 116 overflow.set_x(pinchedBounds.x()); | 118 overflow.set_x(pinchedBounds.x()); |
| 117 pinchedBounds.set_x(0); | 119 pinchedBounds.set_x(0); |
| 118 } | 120 } |
| 119 | 121 |
| 120 if (pinchedBounds.y() < 0) { | 122 if (pinchedBounds.y() < 0) { |
| 121 overflow.set_y(pinchedBounds.y()); | 123 overflow.set_y(pinchedBounds.y()); |
| 122 pinchedBounds.set_y(0); | 124 pinchedBounds.set_y(0); |
| 123 } | 125 } |
| 124 | 126 |
| 125 if (pinchedBounds.right() > m_layoutViewportSize.width()) { | 127 if (pinchedBounds.right() > m_layoutViewportSize.width()) { |
| 126 overflow.set_x(pinchedBounds.right() - m_layoutViewportSize.width()); | 128 overflow.set_x(pinchedBounds.right() - m_layoutViewportSize.width()); |
| 127 pinchedBounds.Offset(m_layoutViewportSize.width() - pinchedBounds.right(
), 0); | 129 pinchedBounds.Offset(m_layoutViewportSize.width() - pinchedBounds.right(
), 0); |
| 128 } | 130 } |
| 129 | 131 |
| 130 if (pinchedBounds.bottom() > m_layoutViewportSize.height()) { | 132 if (pinchedBounds.bottom() > m_layoutViewportSize.height()) { |
| 131 overflow.set_y(pinchedBounds.bottom() - m_layoutViewportSize.height()); | 133 overflow.set_y(pinchedBounds.bottom() - m_layoutViewportSize.height()); |
| 132 pinchedBounds.Offset(0, m_layoutViewportSize.height() - pinchedBounds.bo
ttom()); | 134 pinchedBounds.Offset(0, m_layoutViewportSize.height() - pinchedBounds.bo
ttom()); |
| 133 } | 135 } |
| 134 m_pinchViewportScrollDelta = cc::FloatPoint(pinchedBounds.origin()); | 136 m_pinchViewportScrollDelta = pinchedBounds.OffsetFromOrigin(); |
| 135 | 137 |
| 136 return cc::FloatSize(overflow); | 138 return overflow; |
| 137 } | 139 } |
| 138 | 140 |
| 139 WebTransformationMatrix PinchZoomViewport::implTransform() const | 141 WebTransformationMatrix PinchZoomViewport::implTransform() const |
| 140 { | 142 { |
| 141 WebTransformationMatrix transform; | 143 WebTransformationMatrix transform; |
| 142 transform.scale(m_pageScaleDelta); | 144 transform.scale(m_pageScaleDelta); |
| 143 | 145 |
| 144 // If the pinch state is applied in the impl, then push it to the | 146 // If the pinch state is applied in the impl, then push it to the |
| 145 // impl transform, otherwise the scale is handled by WebCore. | 147 // impl transform, otherwise the scale is handled by WebCore. |
| 146 if (Settings::pageScalePinchZoomEnabled()) { | 148 if (Settings::pageScalePinchZoomEnabled()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 244 |
| 243 void LayerTreeHostImpl::beginCommit() | 245 void LayerTreeHostImpl::beginCommit() |
| 244 { | 246 { |
| 245 } | 247 } |
| 246 | 248 |
| 247 void LayerTreeHostImpl::commitComplete() | 249 void LayerTreeHostImpl::commitComplete() |
| 248 { | 250 { |
| 249 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); | 251 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); |
| 250 // Recompute max scroll position; must be after layer content bounds are | 252 // Recompute max scroll position; must be after layer content bounds are |
| 251 // updated. | 253 // updated. |
| 252 updateMaxScrollPosition(); | 254 updateMaxScrollOffset(); |
| 253 m_client->sendManagedMemoryStats(); | 255 m_client->sendManagedMemoryStats(); |
| 254 } | 256 } |
| 255 | 257 |
| 256 bool LayerTreeHostImpl::canDraw() | 258 bool LayerTreeHostImpl::canDraw() |
| 257 { | 259 { |
| 258 // Note: If you are changing this function or any other function that might | 260 // Note: If you are changing this function or any other function that might |
| 259 // affect the result of canDraw, make sure to call m_client->onCanDrawStateC
hanged | 261 // affect the result of canDraw, make sure to call m_client->onCanDrawStateC
hanged |
| 260 // in the proper places and update the notifyIfCanDrawChanged test. | 262 // in the proper places and update the notifyIfCanDrawChanged test. |
| 261 | 263 |
| 262 if (!m_rootLayerImpl) { | 264 if (!m_rootLayerImpl) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 283 return m_context.get(); | 285 return m_context.get(); |
| 284 } | 286 } |
| 285 | 287 |
| 286 void LayerTreeHostImpl::animate(base::TimeTicks monotonicTime, base::Time wallCl
ockTime) | 288 void LayerTreeHostImpl::animate(base::TimeTicks monotonicTime, base::Time wallCl
ockTime) |
| 287 { | 289 { |
| 288 animatePageScale(monotonicTime); | 290 animatePageScale(monotonicTime); |
| 289 animateLayers(monotonicTime, wallClockTime); | 291 animateLayers(monotonicTime, wallClockTime); |
| 290 animateScrollbars(monotonicTime); | 292 animateScrollbars(monotonicTime); |
| 291 } | 293 } |
| 292 | 294 |
| 293 void LayerTreeHostImpl::startPageScaleAnimation(const IntSize& targetPosition, b
ool anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta dur
ation) | 295 void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetOffset, bool
anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta durati
on) |
| 294 { | 296 { |
| 295 if (!m_rootScrollLayerImpl) | 297 if (!m_rootScrollLayerImpl) |
| 296 return; | 298 return; |
| 297 | 299 |
| 298 IntSize scrollTotal = flooredIntSize(m_rootScrollLayerImpl->scrollPosition()
+ m_rootScrollLayerImpl->scrollDelta()); | 300 gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); |
| 299 scrollTotal.scale(m_pinchZoomViewport.pageScaleDelta()); | 301 scrollTotal.Scale(m_pinchZoomViewport.pageScaleDelta()); |
| 300 float scaleTotal = m_pinchZoomViewport.totalPageScaleFactor(); | 302 float scaleTotal = m_pinchZoomViewport.totalPageScaleFactor(); |
| 301 gfx::Size scaledContentSize = gfx::ToFlooredSize(contentSize().Scale(m_pinch
ZoomViewport.pageScaleDelta())); | 303 gfx::Size scaledContentSize = gfx::ToFlooredSize(contentSize().Scale(m_pinch
ZoomViewport.pageScaleDelta())); |
| 302 | 304 |
| 303 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); | 305 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); |
| 304 m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, scaleTotal, c
c::IntSize(m_deviceViewportSize), scaledContentSize, startTimeSeconds); | 306 m_pageScaleAnimation = PageScaleAnimation::create(gfx::ToFlooredVector2d(scr
ollTotal), scaleTotal, m_deviceViewportSize, scaledContentSize, startTimeSeconds
); |
| 305 | 307 |
| 306 if (anchorPoint) { | 308 if (anchorPoint) { |
| 307 IntSize windowAnchor(targetPosition); | 309 gfx::Vector2dF windowAnchor = targetOffset; |
| 308 windowAnchor.scale(scaleTotal / pageScale); | 310 windowAnchor.Scale(scaleTotal / pageScale); |
| 309 windowAnchor -= scrollTotal; | 311 windowAnchor -= scrollTotal; |
| 310 m_pageScaleAnimation->zoomWithAnchor(windowAnchor, pageScale, duration.I
nSecondsF()); | 312 m_pageScaleAnimation->zoomWithAnchor(gfx::ToFlooredVector2d(windowAnchor
), pageScale, duration.InSecondsF()); |
| 311 } else | 313 } else |
| 312 m_pageScaleAnimation->zoomTo(targetPosition, pageScale, duration.InSecon
dsF()); | 314 m_pageScaleAnimation->zoomTo(targetOffset, pageScale, duration.InSeconds
F()); |
| 313 | 315 |
| 314 m_client->setNeedsRedrawOnImplThread(); | 316 m_client->setNeedsRedrawOnImplThread(); |
| 315 m_client->setNeedsCommitOnImplThread(); | 317 m_client->setNeedsCommitOnImplThread(); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void LayerTreeHostImpl::scheduleAnimation() | 320 void LayerTreeHostImpl::scheduleAnimation() |
| 319 { | 321 { |
| 320 m_client->setNeedsRedrawOnImplThread(); | 322 m_client->setNeedsRedrawOnImplThread(); |
| 321 } | 323 } |
| 322 | 324 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 } | 885 } |
| 884 | 886 |
| 885 void LayerTreeHostImpl::setViewportSize(const gfx::Size& layoutViewportSize, con
st gfx::Size& deviceViewportSize) | 887 void LayerTreeHostImpl::setViewportSize(const gfx::Size& layoutViewportSize, con
st gfx::Size& deviceViewportSize) |
| 886 { | 888 { |
| 887 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de
viceViewportSize) | 889 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de
viceViewportSize) |
| 888 return; | 890 return; |
| 889 | 891 |
| 890 m_layoutViewportSize = layoutViewportSize; | 892 m_layoutViewportSize = layoutViewportSize; |
| 891 m_deviceViewportSize = deviceViewportSize; | 893 m_deviceViewportSize = deviceViewportSize; |
| 892 | 894 |
| 893 m_pinchZoomViewport.setLayoutViewportSize(FloatSize(layoutViewportSize)); | 895 m_pinchZoomViewport.setLayoutViewportSize(layoutViewportSize); |
| 894 | 896 |
| 895 updateMaxScrollPosition(); | 897 updateMaxScrollOffset(); |
| 896 | 898 |
| 897 if (m_renderer) | 899 if (m_renderer) |
| 898 m_renderer->viewportChanged(); | 900 m_renderer->viewportChanged(); |
| 899 | 901 |
| 900 m_client->onCanDrawStateChanged(canDraw()); | 902 m_client->onCanDrawStateChanged(canDraw()); |
| 901 } | 903 } |
| 902 | 904 |
| 903 static void adjustScrollsForPageScaleChange(LayerImpl* layerImpl, float pageScal
eChange) | 905 static void adjustScrollsForPageScaleChange(LayerImpl* layerImpl, float pageScal
eChange) |
| 904 { | 906 { |
| 905 if (!layerImpl) | 907 if (!layerImpl) |
| 906 return; | 908 return; |
| 907 | 909 |
| 908 if (layerImpl->scrollable()) { | 910 if (layerImpl->scrollable()) { |
| 909 // We need to convert impl-side scroll deltas to pageScale space. | 911 // We need to convert impl-side scroll deltas to pageScale space. |
| 910 FloatSize scrollDelta = layerImpl->scrollDelta(); | 912 gfx::Vector2dF scrollDelta = layerImpl->scrollDelta(); |
| 911 scrollDelta.scale(pageScaleChange); | 913 scrollDelta.Scale(pageScaleChange); |
| 912 layerImpl->setScrollDelta(scrollDelta); | 914 layerImpl->setScrollDelta(scrollDelta); |
| 913 } | 915 } |
| 914 | 916 |
| 915 for (size_t i = 0; i < layerImpl->children().size(); ++i) | 917 for (size_t i = 0; i < layerImpl->children().size(); ++i) |
| 916 adjustScrollsForPageScaleChange(layerImpl->children()[i], pageScaleChang
e); | 918 adjustScrollsForPageScaleChange(layerImpl->children()[i], pageScaleChang
e); |
| 917 } | 919 } |
| 918 | 920 |
| 919 void LayerTreeHostImpl::setDeviceScaleFactor(float deviceScaleFactor) | 921 void LayerTreeHostImpl::setDeviceScaleFactor(float deviceScaleFactor) |
| 920 { | 922 { |
| 921 if (deviceScaleFactor == m_deviceScaleFactor) | 923 if (deviceScaleFactor == m_deviceScaleFactor) |
| 922 return; | 924 return; |
| 923 m_deviceScaleFactor = deviceScaleFactor; | 925 m_deviceScaleFactor = deviceScaleFactor; |
| 924 | 926 |
| 925 updateMaxScrollPosition(); | 927 updateMaxScrollOffset(); |
| 926 } | 928 } |
| 927 | 929 |
| 928 float LayerTreeHostImpl::pageScaleFactor() const | 930 float LayerTreeHostImpl::pageScaleFactor() const |
| 929 { | 931 { |
| 930 return m_pinchZoomViewport.pageScaleFactor(); | 932 return m_pinchZoomViewport.pageScaleFactor(); |
| 931 } | 933 } |
| 932 | 934 |
| 933 void LayerTreeHostImpl::setPageScaleFactorAndLimits(float pageScaleFactor, float
minPageScaleFactor, float maxPageScaleFactor) | 935 void LayerTreeHostImpl::setPageScaleFactorAndLimits(float pageScaleFactor, float
minPageScaleFactor, float maxPageScaleFactor) |
| 934 { | 936 { |
| 935 if (!pageScaleFactor) | 937 if (!pageScaleFactor) |
| 936 return; | 938 return; |
| 937 | 939 |
| 938 float pageScaleChange = pageScaleFactor / m_pinchZoomViewport.pageScaleFacto
r(); | 940 float pageScaleChange = pageScaleFactor / m_pinchZoomViewport.pageScaleFacto
r(); |
| 939 m_pinchZoomViewport.setPageScaleFactorAndLimits(pageScaleFactor, minPageScal
eFactor, maxPageScaleFactor); | 941 m_pinchZoomViewport.setPageScaleFactorAndLimits(pageScaleFactor, minPageScal
eFactor, maxPageScaleFactor); |
| 940 | 942 |
| 941 if (!Settings::pageScalePinchZoomEnabled()) { | 943 if (!Settings::pageScalePinchZoomEnabled()) { |
| 942 if (pageScaleChange != 1) | 944 if (pageScaleChange != 1) |
| 943 adjustScrollsForPageScaleChange(m_rootScrollLayerImpl, pageScaleChan
ge); | 945 adjustScrollsForPageScaleChange(m_rootScrollLayerImpl, pageScaleChan
ge); |
| 944 } | 946 } |
| 945 | 947 |
| 946 // Clamp delta to limits and refresh display matrix. | 948 // Clamp delta to limits and refresh display matrix. |
| 947 setPageScaleDelta(m_pinchZoomViewport.pageScaleDelta() / m_pinchZoomViewport
.sentPageScaleDelta()); | 949 setPageScaleDelta(m_pinchZoomViewport.pageScaleDelta() / m_pinchZoomViewport
.sentPageScaleDelta()); |
| 948 m_pinchZoomViewport.setSentPageScaleDelta(1); | 950 m_pinchZoomViewport.setSentPageScaleDelta(1); |
| 949 } | 951 } |
| 950 | 952 |
| 951 void LayerTreeHostImpl::setPageScaleDelta(float delta) | 953 void LayerTreeHostImpl::setPageScaleDelta(float delta) |
| 952 { | 954 { |
| 953 m_pinchZoomViewport.setPageScaleDelta(delta); | 955 m_pinchZoomViewport.setPageScaleDelta(delta); |
| 954 | 956 |
| 955 updateMaxScrollPosition(); | 957 updateMaxScrollOffset(); |
| 956 } | 958 } |
| 957 | 959 |
| 958 void LayerTreeHostImpl::updateMaxScrollPosition() | 960 void LayerTreeHostImpl::updateMaxScrollOffset() |
| 959 { | 961 { |
| 960 if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size()) | 962 if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size()) |
| 961 return; | 963 return; |
| 962 | 964 |
| 963 gfx::SizeF viewBounds = m_deviceViewportSize; | 965 gfx::SizeF viewBounds = m_deviceViewportSize; |
| 964 if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) { | 966 if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) { |
| 965 // Compensate for non-overlay scrollbars. | 967 // Compensate for non-overlay scrollbars. |
| 966 if (clipLayer->masksToBounds()) { | 968 if (clipLayer->masksToBounds()) { |
| 967 viewBounds = clipLayer->bounds(); | 969 viewBounds = clipLayer->bounds(); |
| 968 viewBounds = viewBounds.Scale(m_deviceScaleFactor); | 970 viewBounds = viewBounds.Scale(m_deviceScaleFactor); |
| 969 } | 971 } |
| 970 } | 972 } |
| 971 | 973 |
| 972 gfx::Size contentBounds = contentSize(); | 974 gfx::Size contentBounds = contentSize(); |
| 973 if (Settings::pageScalePinchZoomEnabled()) { | 975 if (Settings::pageScalePinchZoomEnabled()) { |
| 974 // Pinch with pageScale scrolls entirely in layout space. contentSize | 976 // Pinch with pageScale scrolls entirely in layout space. contentSize |
| 975 // returns the bounds including the page scale factor, so calculate the | 977 // returns the bounds including the page scale factor, so calculate the |
| 976 // pre page-scale layout size here. | 978 // pre page-scale layout size here. |
| 977 float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); | 979 float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); |
| 978 contentBounds.set_width(contentBounds.width() / pageScaleFactor); | 980 contentBounds.set_width(contentBounds.width() / pageScaleFactor); |
| 979 contentBounds.set_height(contentBounds.height() / pageScaleFactor); | 981 contentBounds.set_height(contentBounds.height() / pageScaleFactor); |
| 980 } else { | 982 } else { |
| 981 viewBounds = viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); | 983 viewBounds = viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); |
| 982 } | 984 } |
| 983 | 985 |
| 984 IntSize maxScroll = cc::IntSize(contentBounds) - expandedIntSize(cc::FloatSi
ze(viewBounds)); | 986 gfx::Vector2dF maxScroll = BottomRight(gfx::Rect(contentBounds)) - BottomRig
ht(gfx::RectF(viewBounds)); |
| 985 maxScroll.scale(1 / m_deviceScaleFactor); | 987 maxScroll.Scale(1 / m_deviceScaleFactor); |
| 986 | 988 |
| 987 // The viewport may be larger than the contents in some cases, such as | 989 // The viewport may be larger than the contents in some cases, such as |
| 988 // having a vertical scrollbar but no horizontal overflow. | 990 // having a vertical scrollbar but no horizontal overflow. |
| 989 maxScroll.clampNegativeToZero(); | 991 maxScroll = ClampFromBelow(maxScroll, gfx::Vector2dF()); |
| 990 | 992 |
| 991 m_rootScrollLayerImpl->setMaxScrollPosition(maxScroll); | 993 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll))
; |
| 992 } | 994 } |
| 993 | 995 |
| 994 void LayerTreeHostImpl::setNeedsRedraw() | 996 void LayerTreeHostImpl::setNeedsRedraw() |
| 995 { | 997 { |
| 996 m_client->setNeedsRedrawOnImplThread(); | 998 m_client->setNeedsRedrawOnImplThread(); |
| 997 } | 999 } |
| 998 | 1000 |
| 999 bool LayerTreeHostImpl::ensureRenderSurfaceLayerList() | 1001 bool LayerTreeHostImpl::ensureRenderSurfaceLayerList() |
| 1000 { | 1002 { |
| 1001 if (!m_rootLayerImpl) | 1003 if (!m_rootLayerImpl) |
| 1002 return false; | 1004 return false; |
| 1003 if (!m_renderer) | 1005 if (!m_renderer) |
| 1004 return false; | 1006 return false; |
| 1005 | 1007 |
| 1006 // We need both a non-empty render surface layer list and a root render | 1008 // We need both a non-empty render surface layer list and a root render |
| 1007 // surface to be able to iterate over the visible layers. | 1009 // surface to be able to iterate over the visible layers. |
| 1008 if (m_renderSurfaceLayerList.size() && m_rootLayerImpl->renderSurface()) | 1010 if (m_renderSurfaceLayerList.size() && m_rootLayerImpl->renderSurface()) |
| 1009 return true; | 1011 return true; |
| 1010 | 1012 |
| 1011 // If we are called after setRootLayer() but before prepareToDraw(), we need | 1013 // If we are called after setRootLayer() but before prepareToDraw(), we need |
| 1012 // to recalculate the visible layers. This prevents being unable to scroll | 1014 // to recalculate the visible layers. This prevents being unable to scroll |
| 1013 // during part of a commit. | 1015 // during part of a commit. |
| 1014 m_renderSurfaceLayerList.clear(); | 1016 m_renderSurfaceLayerList.clear(); |
| 1015 calculateRenderSurfaceLayerList(m_renderSurfaceLayerList); | 1017 calculateRenderSurfaceLayerList(m_renderSurfaceLayerList); |
| 1016 | 1018 |
| 1017 return m_renderSurfaceLayerList.size(); | 1019 return m_renderSurfaceLayerList.size(); |
| 1018 } | 1020 } |
| 1019 | 1021 |
| 1020 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(const gfx::Point
& viewportPoint, InputHandlerClient::ScrollInputType type) | 1022 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewp
ortPoint, InputHandlerClient::ScrollInputType type) |
| 1021 { | 1023 { |
| 1022 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); | 1024 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); |
| 1023 | 1025 |
| 1024 DCHECK(!m_currentlyScrollingLayerImpl); | 1026 DCHECK(!m_currentlyScrollingLayerImpl); |
| 1025 clearCurrentlyScrollingLayer(); | 1027 clearCurrentlyScrollingLayer(); |
| 1026 | 1028 |
| 1027 if (!ensureRenderSurfaceLayerList()) | 1029 if (!ensureRenderSurfaceLayerList()) |
| 1028 return ScrollIgnored; | 1030 return ScrollIgnored; |
| 1029 | 1031 |
| 1030 gfx::PointF deviceViewportPoint = viewportPoint.Scale(m_deviceScaleFactor); | 1032 gfx::PointF deviceViewportPoint = viewportPoint.Scale(m_deviceScaleFactor); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 // Gesture events need to be transformed from viewport coordinates to lo
cal layer coordinates | 1065 // Gesture events need to be transformed from viewport coordinates to lo
cal layer coordinates |
| 1064 // so that the scrolling contents exactly follow the user's finger. In c
ontrast, wheel | 1066 // so that the scrolling contents exactly follow the user's finger. In c
ontrast, wheel |
| 1065 // events are already in local layer coordinates so we can just apply th
em directly. | 1067 // events are already in local layer coordinates so we can just apply th
em directly. |
| 1066 m_scrollDeltaIsInViewportSpace = (type == Gesture); | 1068 m_scrollDeltaIsInViewportSpace = (type == Gesture); |
| 1067 m_numImplThreadScrolls++; | 1069 m_numImplThreadScrolls++; |
| 1068 return ScrollStarted; | 1070 return ScrollStarted; |
| 1069 } | 1071 } |
| 1070 return ScrollIgnored; | 1072 return ScrollIgnored; |
| 1071 } | 1073 } |
| 1072 | 1074 |
| 1073 static FloatSize scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewport,
LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, const gfx::PointF& v
iewportPoint, const FloatSize& viewportDelta) | 1075 static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewp
ort, LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, gfx::PointF vie
wportPoint, gfx::Vector2dF viewportDelta) |
| 1074 { | 1076 { |
| 1075 // Layers with non-invertible screen space transforms should not have passed
the scroll hit | 1077 // Layers with non-invertible screen space transforms should not have passed
the scroll hit |
| 1076 // test in the first place. | 1078 // test in the first place. |
| 1077 DCHECK(layerImpl.screenSpaceTransform().isInvertible()); | 1079 DCHECK(layerImpl.screenSpaceTransform().isInvertible()); |
| 1078 WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceT
ransform().inverse(); | 1080 WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceT
ransform().inverse(); |
| 1079 | 1081 |
| 1080 gfx::PointF screenSpacePoint = viewportPoint.Scale(scaleFromViewportToScreen
Space); | 1082 gfx::PointF screenSpacePoint = viewportPoint.Scale(scaleFromViewportToScreen
Space); |
| 1081 | 1083 |
| 1082 FloatSize screenSpaceDelta = viewportDelta; | 1084 gfx::Vector2dF screenSpaceDelta = viewportDelta; |
| 1083 screenSpaceDelta.scale(scaleFromViewportToScreenSpace, scaleFromViewportToSc
reenSpace); | 1085 screenSpaceDelta.Scale(scaleFromViewportToScreenSpace); |
| 1084 | 1086 |
| 1085 // First project the scroll start and end points to local layer space to fin
d the scroll delta | 1087 // First project the scroll start and end points to local layer space to fin
d the scroll delta |
| 1086 // in layer coordinates. | 1088 // in layer coordinates. |
| 1087 bool startClipped, endClipped; | 1089 bool startClipped, endClipped; |
| 1088 gfx::PointF screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta; | 1090 gfx::PointF screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta; |
| 1089 gfx::PointF localStartPoint = MathUtil::projectPoint(inverseScreenSpaceTrans
form, screenSpacePoint, startClipped); | 1091 gfx::PointF localStartPoint = MathUtil::projectPoint(inverseScreenSpaceTrans
form, screenSpacePoint, startClipped); |
| 1090 gfx::PointF localEndPoint = MathUtil::projectPoint(inverseScreenSpaceTransfo
rm, screenSpaceEndPoint, endClipped); | 1092 gfx::PointF localEndPoint = MathUtil::projectPoint(inverseScreenSpaceTransfo
rm, screenSpaceEndPoint, endClipped); |
| 1091 | 1093 |
| 1092 // In general scroll point coordinates should not get clipped. | 1094 // In general scroll point coordinates should not get clipped. |
| 1093 DCHECK(!startClipped); | 1095 DCHECK(!startClipped); |
| 1094 DCHECK(!endClipped); | 1096 DCHECK(!endClipped); |
| 1095 if (startClipped || endClipped) | 1097 if (startClipped || endClipped) |
| 1096 return FloatSize(); | 1098 return gfx::Vector2dF(); |
| 1097 | 1099 |
| 1098 // localStartPoint and localEndPoint are in content space but we want to mov
e them to layer space for scrolling. | 1100 // localStartPoint and localEndPoint are in content space but we want to mov
e them to layer space for scrolling. |
| 1099 float widthScale = 1 / layerImpl.contentsScaleX(); | 1101 float widthScale = 1 / layerImpl.contentsScaleX(); |
| 1100 float heightScale = 1 / layerImpl.contentsScaleY(); | 1102 float heightScale = 1 / layerImpl.contentsScaleY(); |
| 1101 localStartPoint = localStartPoint.Scale(widthScale, heightScale); | 1103 localStartPoint = localStartPoint.Scale(widthScale, heightScale); |
| 1102 localEndPoint = localEndPoint.Scale(widthScale, heightScale); | 1104 localEndPoint = localEndPoint.Scale(widthScale, heightScale); |
| 1103 | 1105 |
| 1104 // Apply the scroll delta. | 1106 // Apply the scroll delta. |
| 1105 FloatSize previousDelta(layerImpl.scrollDelta()); | 1107 gfx::Vector2dF previousDelta = layerImpl.scrollDelta(); |
| 1106 FloatSize unscrolled = layerImpl.scrollBy(cc::FloatSize(localEndPoint - loca
lStartPoint)); | 1108 gfx::Vector2dF unscrolled = layerImpl.scrollBy(localEndPoint - localStartPoi
nt); |
| 1107 | 1109 |
| 1108 if (viewport) | 1110 if (viewport) |
| 1109 viewport->applyScroll(unscrolled); | 1111 viewport->applyScroll(unscrolled); |
| 1110 | 1112 |
| 1111 // Get the end point in the layer's content space so we can apply its screen
SpaceTransform. | 1113 // Get the end point in the layer's content space so we can apply its screen
SpaceTransform. |
| 1112 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta()
- previousDelta; | 1114 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta()
- previousDelta; |
| 1113 gfx::PointF actualLocalContentEndPoint = actualLocalEndPoint.Scale(1 / width
Scale, 1 / heightScale); | 1115 gfx::PointF actualLocalContentEndPoint = actualLocalEndPoint.Scale(1 / width
Scale, 1 / heightScale); |
| 1114 | 1116 |
| 1115 // Calculate the applied scroll delta in viewport space coordinates. | 1117 // Calculate the applied scroll delta in viewport space coordinates. |
| 1116 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS
paceTransform(), actualLocalContentEndPoint, endClipped); | 1118 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS
paceTransform(), actualLocalContentEndPoint, endClipped); |
| 1117 DCHECK(!endClipped); | 1119 DCHECK(!endClipped); |
| 1118 if (endClipped) | 1120 if (endClipped) |
| 1119 return FloatSize(); | 1121 return gfx::Vector2dF(); |
| 1120 gfx::PointF actualViewportEndPoint = actualScreenSpaceEndPoint.Scale(1 / sca
leFromViewportToScreenSpace); | 1122 gfx::PointF actualViewportEndPoint = actualScreenSpaceEndPoint.Scale(1 / sca
leFromViewportToScreenSpace); |
| 1121 return cc::FloatSize(actualViewportEndPoint - viewportPoint); | 1123 return actualViewportEndPoint - viewportPoint; |
| 1122 } | 1124 } |
| 1123 | 1125 |
| 1124 static FloatSize scrollLayerWithLocalDelta(LayerImpl& layerImpl, const FloatSize
& localDelta) | 1126 static gfx::Vector2dF scrollLayerWithLocalDelta(LayerImpl& layerImpl, gfx::Vecto
r2dF localDelta) |
| 1125 { | 1127 { |
| 1126 FloatSize previousDelta(layerImpl.scrollDelta()); | 1128 gfx::Vector2dF previousDelta(layerImpl.scrollDelta()); |
| 1127 layerImpl.scrollBy(localDelta); | 1129 layerImpl.scrollBy(localDelta); |
| 1128 return layerImpl.scrollDelta() - previousDelta; | 1130 return layerImpl.scrollDelta() - previousDelta; |
| 1129 } | 1131 } |
| 1130 | 1132 |
| 1131 void LayerTreeHostImpl::scrollBy(const gfx::Point& viewportPoint, const IntSize&
scrollDelta) | 1133 void LayerTreeHostImpl::scrollBy(gfx::Point viewportPoint, gfx::Vector2d scrollD
elta) |
| 1132 { | 1134 { |
| 1133 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBy"); | 1135 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBy"); |
| 1134 if (!m_currentlyScrollingLayerImpl) | 1136 if (!m_currentlyScrollingLayerImpl) |
| 1135 return; | 1137 return; |
| 1136 | 1138 |
| 1137 FloatSize pendingDelta(scrollDelta); | 1139 gfx::Vector2dF pendingDelta = scrollDelta; |
| 1138 | 1140 |
| 1139 for (LayerImpl* layerImpl = m_currentlyScrollingLayerImpl; layerImpl; layerI
mpl = layerImpl->parent()) { | 1141 for (LayerImpl* layerImpl = m_currentlyScrollingLayerImpl; layerImpl; layerI
mpl = layerImpl->parent()) { |
| 1140 if (!layerImpl->scrollable()) | 1142 if (!layerImpl->scrollable()) |
| 1141 continue; | 1143 continue; |
| 1142 | 1144 |
| 1143 PinchZoomViewport* viewport = layerImpl == m_rootScrollLayerImpl ? &m_pi
nchZoomViewport : 0; | 1145 PinchZoomViewport* viewport = layerImpl == m_rootScrollLayerImpl ? &m_pi
nchZoomViewport : 0; |
| 1144 FloatSize appliedDelta; | 1146 gfx::Vector2dF appliedDelta; |
| 1145 if (m_scrollDeltaIsInViewportSpace) { | 1147 if (m_scrollDeltaIsInViewportSpace) { |
| 1146 float scaleFromViewportToScreenSpace = m_deviceScaleFactor; | 1148 float scaleFromViewportToScreenSpace = m_deviceScaleFactor; |
| 1147 appliedDelta = scrollLayerWithViewportSpaceDelta(viewport, *layerImp
l, scaleFromViewportToScreenSpace, viewportPoint, pendingDelta); | 1149 appliedDelta = scrollLayerWithViewportSpaceDelta(viewport, *layerImp
l, scaleFromViewportToScreenSpace, viewportPoint, pendingDelta); |
| 1148 } else | 1150 } else |
| 1149 appliedDelta = scrollLayerWithLocalDelta(*layerImpl, pendingDelta); | 1151 appliedDelta = scrollLayerWithLocalDelta(*layerImpl, pendingDelta); |
| 1150 | 1152 |
| 1151 // If the layer wasn't able to move, try the next one in the hierarchy. | 1153 // If the layer wasn't able to move, try the next one in the hierarchy. |
| 1152 float moveThresholdSquared = 0.1f * 0.1f; | 1154 float moveThresholdSquared = 0.1f * 0.1f; |
| 1153 if (appliedDelta.diagonalLengthSquared() < moveThresholdSquared) | 1155 if (appliedDelta.LengthSquared() < moveThresholdSquared) |
| 1154 continue; | 1156 continue; |
| 1155 | 1157 |
| 1156 // If the applied delta is within 45 degrees of the input delta, bail ou
t to make it easier | 1158 // If the applied delta is within 45 degrees of the input delta, bail ou
t to make it easier |
| 1157 // to scroll just one layer in one direction without affecting any of it
s parents. | 1159 // to scroll just one layer in one direction without affecting any of it
s parents. |
| 1158 float angleThreshold = 45; | 1160 float angleThreshold = 45; |
| 1159 if (MathUtil::smallestAngleBetweenVectors(appliedDelta, pendingDelta) <
angleThreshold) { | 1161 if (MathUtil::smallestAngleBetweenVectors(appliedDelta, pendingDelta) <
angleThreshold) { |
| 1160 pendingDelta = FloatSize(); | 1162 pendingDelta = gfx::Vector2d(); |
| 1161 break; | 1163 break; |
| 1162 } | 1164 } |
| 1163 | 1165 |
| 1164 // Allow further movement only on an axis perpendicular to the direction
in which the layer | 1166 // Allow further movement only on an axis perpendicular to the direction
in which the layer |
| 1165 // moved. | 1167 // moved. |
| 1166 FloatSize perpendicularAxis(-appliedDelta.height(), appliedDelta.width()
); | 1168 gfx::Vector2dF perpendicularAxis(-appliedDelta.y(), appliedDelta.x()); |
| 1167 pendingDelta = MathUtil::projectVector(pendingDelta, perpendicularAxis); | 1169 pendingDelta = MathUtil::projectVector(pendingDelta, perpendicularAxis); |
| 1168 | 1170 |
| 1169 if (flooredIntSize(pendingDelta).isZero()) | 1171 if (gfx::ToFlooredVector2d(pendingDelta).IsZero()) |
| 1170 break; | 1172 break; |
| 1171 } | 1173 } |
| 1172 | 1174 |
| 1173 if (!scrollDelta.isZero() && flooredIntSize(pendingDelta).isEmpty()) { | 1175 if (!scrollDelta.IsZero() && gfx::ToFlooredVector2d(pendingDelta).IsZero())
{ |
| 1174 m_client->setNeedsCommitOnImplThread(); | 1176 m_client->setNeedsCommitOnImplThread(); |
| 1175 m_client->setNeedsRedrawOnImplThread(); | 1177 m_client->setNeedsRedrawOnImplThread(); |
| 1176 } | 1178 } |
| 1177 } | 1179 } |
| 1178 | 1180 |
| 1179 void LayerTreeHostImpl::clearCurrentlyScrollingLayer() | 1181 void LayerTreeHostImpl::clearCurrentlyScrollingLayer() |
| 1180 { | 1182 { |
| 1181 m_currentlyScrollingLayerImpl = 0; | 1183 m_currentlyScrollingLayerImpl = 0; |
| 1182 m_scrollingLayerIdFromPreviousTree = -1; | 1184 m_scrollingLayerIdFromPreviousTree = -1; |
| 1183 } | 1185 } |
| 1184 | 1186 |
| 1185 void LayerTreeHostImpl::scrollEnd() | 1187 void LayerTreeHostImpl::scrollEnd() |
| 1186 { | 1188 { |
| 1187 clearCurrentlyScrollingLayer(); | 1189 clearCurrentlyScrollingLayer(); |
| 1188 } | 1190 } |
| 1189 | 1191 |
| 1190 void LayerTreeHostImpl::pinchGestureBegin() | 1192 void LayerTreeHostImpl::pinchGestureBegin() |
| 1191 { | 1193 { |
| 1192 m_pinchGestureActive = true; | 1194 m_pinchGestureActive = true; |
| 1193 m_previousPinchAnchor = IntPoint(); | 1195 m_previousPinchAnchor = gfx::Point(); |
| 1194 | 1196 |
| 1195 if (m_rootScrollLayerImpl && m_rootScrollLayerImpl->scrollbarAnimationContro
ller()) | 1197 if (m_rootScrollLayerImpl && m_rootScrollLayerImpl->scrollbarAnimationContro
ller()) |
| 1196 m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureBe
gin(); | 1198 m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureBe
gin(); |
| 1197 } | 1199 } |
| 1198 | 1200 |
| 1199 void LayerTreeHostImpl::pinchGestureUpdate(float magnifyDelta, | 1201 void LayerTreeHostImpl::pinchGestureUpdate(float magnifyDelta, gfx::Point anchor
) |
| 1200 const IntPoint& anchor) | |
| 1201 { | 1202 { |
| 1202 TRACE_EVENT0("cc", "LayerTreeHostImpl::pinchGestureUpdate"); | 1203 TRACE_EVENT0("cc", "LayerTreeHostImpl::pinchGestureUpdate"); |
| 1203 | 1204 |
| 1204 if (!m_rootScrollLayerImpl) | 1205 if (!m_rootScrollLayerImpl) |
| 1205 return; | 1206 return; |
| 1206 | 1207 |
| 1207 if (m_previousPinchAnchor == IntPoint::zero()) | 1208 if (m_previousPinchAnchor == gfx::Point()) |
| 1208 m_previousPinchAnchor = anchor; | 1209 m_previousPinchAnchor = anchor; |
| 1209 | 1210 |
| 1210 // Keep the center-of-pinch anchor specified by (x, y) in a stable | 1211 // Keep the center-of-pinch anchor specified by (x, y) in a stable |
| 1211 // position over the course of the magnify. | 1212 // position over the course of the magnify. |
| 1212 float pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); | 1213 float pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); |
| 1213 FloatPoint previousScaleAnchor(m_previousPinchAnchor.x() / pageScaleDelta, | 1214 gfx::PointF previousScaleAnchor = m_previousPinchAnchor.Scale(1 / pageScaleD
elta); |
| 1214 m_previousPinchAnchor.y() / pageScaleDelta); | |
| 1215 setPageScaleDelta(pageScaleDelta * magnifyDelta); | 1215 setPageScaleDelta(pageScaleDelta * magnifyDelta); |
| 1216 pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); | 1216 pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); |
| 1217 FloatPoint newScaleAnchor(anchor.x() / pageScaleDelta, anchor.y() / pageScal
eDelta); | 1217 gfx::PointF newScaleAnchor = anchor.Scale(1 / pageScaleDelta); |
| 1218 FloatSize move = previousScaleAnchor - newScaleAnchor; | 1218 gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor; |
| 1219 | 1219 |
| 1220 m_previousPinchAnchor = anchor; | 1220 m_previousPinchAnchor = anchor; |
| 1221 | 1221 |
| 1222 if (Settings::pageScalePinchZoomEnabled()) { | 1222 if (Settings::pageScalePinchZoomEnabled()) { |
| 1223 // Compute the application of the delta with respect to the current page
zoom of the page. | 1223 // Compute the application of the delta with respect to the current page
zoom of the page. |
| 1224 move.scale(1 / (m_pinchZoomViewport.pageScaleFactor() * m_deviceScaleFac
tor)); | 1224 move.Scale(1 / (m_pinchZoomViewport.pageScaleFactor() * m_deviceScaleFac
tor)); |
| 1225 } | 1225 } |
| 1226 | 1226 |
| 1227 FloatSize scrollOverflow = Settings::pageScalePinchZoomEnabled() ? m_pinchZo
omViewport.applyScroll(move) : move; | 1227 gfx::Vector2dF scrollOverflow = Settings::pageScalePinchZoomEnabled() ? m_pi
nchZoomViewport.applyScroll(move) : move; |
| 1228 m_rootScrollLayerImpl->scrollBy(roundedIntSize(scrollOverflow)); | 1228 m_rootScrollLayerImpl->scrollBy(scrollOverflow); |
| 1229 | 1229 |
| 1230 if (m_rootScrollLayerImpl->scrollbarAnimationController()) | 1230 if (m_rootScrollLayerImpl->scrollbarAnimationController()) |
| 1231 m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureUp
date(); | 1231 m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureUp
date(); |
| 1232 | 1232 |
| 1233 m_client->setNeedsCommitOnImplThread(); | 1233 m_client->setNeedsCommitOnImplThread(); |
| 1234 m_client->setNeedsRedrawOnImplThread(); | 1234 m_client->setNeedsRedrawOnImplThread(); |
| 1235 } | 1235 } |
| 1236 | 1236 |
| 1237 void LayerTreeHostImpl::pinchGestureEnd() | 1237 void LayerTreeHostImpl::pinchGestureEnd() |
| 1238 { | 1238 { |
| 1239 m_pinchGestureActive = false; | 1239 m_pinchGestureActive = false; |
| 1240 | 1240 |
| 1241 if (m_rootScrollLayerImpl && m_rootScrollLayerImpl->scrollbarAnimationContro
ller()) | 1241 if (m_rootScrollLayerImpl && m_rootScrollLayerImpl->scrollbarAnimationContro
ller()) |
| 1242 m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureEn
d(); | 1242 m_rootScrollLayerImpl->scrollbarAnimationController()->didPinchGestureEn
d(); |
| 1243 | 1243 |
| 1244 m_client->setNeedsCommitOnImplThread(); | 1244 m_client->setNeedsCommitOnImplThread(); |
| 1245 } | 1245 } |
| 1246 | 1246 |
| 1247 void LayerTreeHostImpl::computeDoubleTapZoomDeltas(ScrollAndScaleSet* scrollInfo
) | 1247 void LayerTreeHostImpl::computeDoubleTapZoomDeltas(ScrollAndScaleSet* scrollInfo
) |
| 1248 { | 1248 { |
| 1249 float pageScale = m_pageScaleAnimation->finalPageScale(); | 1249 float pageScale = m_pageScaleAnimation->finalPageScale(); |
| 1250 IntSize scrollOffset = m_pageScaleAnimation->finalScrollOffset(); | 1250 gfx::Vector2dF scrollOffset = m_pageScaleAnimation->finalScrollOffset(); |
| 1251 scrollOffset.scale(m_pinchZoomViewport.pageScaleFactor() / pageScale); | 1251 scrollOffset.Scale(m_pinchZoomViewport.pageScaleFactor() / pageScale); |
| 1252 makeScrollAndScaleSet(scrollInfo, scrollOffset, pageScale); | 1252 makeScrollAndScaleSet(scrollInfo, gfx::ToRoundedVector2d(scrollOffset), page
Scale); |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 void LayerTreeHostImpl::computePinchZoomDeltas(ScrollAndScaleSet* scrollInfo) | 1255 void LayerTreeHostImpl::computePinchZoomDeltas(ScrollAndScaleSet* scrollInfo) |
| 1256 { | 1256 { |
| 1257 if (!m_rootScrollLayerImpl) | 1257 if (!m_rootScrollLayerImpl) |
| 1258 return; | 1258 return; |
| 1259 | 1259 |
| 1260 // Only send fake scroll/zoom deltas if we're pinch zooming out by a | 1260 // Only send fake scroll/zoom deltas if we're pinch zooming out by a |
| 1261 // significant amount. This also ensures only one fake delta set will be | 1261 // significant amount. This also ensures only one fake delta set will be |
| 1262 // sent. | 1262 // sent. |
| 1263 const float pinchZoomOutSensitivity = 0.95f; | 1263 const float pinchZoomOutSensitivity = 0.95f; |
| 1264 if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity) | 1264 if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity) |
| 1265 return; | 1265 return; |
| 1266 | 1266 |
| 1267 // Compute where the scroll offset/page scale would be if fully pinch-zoomed | 1267 // Compute where the scroll offset/page scale would be if fully pinch-zoomed |
| 1268 // out from the anchor point. | 1268 // out from the anchor point. |
| 1269 IntSize scrollBegin = flooredIntSize(m_rootScrollLayerImpl->scrollPosition()
+ m_rootScrollLayerImpl->scrollDelta()); | 1269 gfx::Vector2dF scrollBegin = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); |
| 1270 scrollBegin.scale(m_pinchZoomViewport.pageScaleDelta()); | 1270 scrollBegin.Scale(m_pinchZoomViewport.pageScaleDelta()); |
| 1271 float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor(); | 1271 float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor(); |
| 1272 float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pi
nchZoomViewport.pageScaleFactor(); | 1272 float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pi
nchZoomViewport.pageScaleFactor(); |
| 1273 gfx::SizeF scaledContentsSize = contentSize().Scale(pageScaleDeltaToSend); | 1273 gfx::SizeF scaledContentsSize = contentSize().Scale(pageScaleDeltaToSend); |
| 1274 | 1274 |
| 1275 FloatSize anchor = toSize(m_previousPinchAnchor); | 1275 gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin(); |
| 1276 FloatSize scrollEnd = scrollBegin + anchor; | 1276 gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset; |
| 1277 scrollEnd.scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin); | 1277 scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin); |
| 1278 scrollEnd -= anchor; | 1278 scrollEnd -= anchorOffset; |
| 1279 scrollEnd = scrollEnd.shrunkTo(roundedIntSize(cc::FloatSize(scaledContentsSi
ze) - cc::IntSize(m_deviceViewportSize))).expandedTo(FloatSize(0, 0)); | 1279 scrollEnd = ClampFromAbove(scrollEnd, BottomRight(gfx::RectF(scaledContentsS
ize)) - BottomRight(gfx::Rect(m_deviceViewportSize))); |
| 1280 scrollEnd.scale(1 / pageScaleDeltaToSend); | 1280 scrollEnd = ClampFromBelow(scrollEnd, gfx::Vector2d()); |
| 1281 scrollEnd.scale(m_deviceScaleFactor); | 1281 scrollEnd.Scale(1 / pageScaleDeltaToSend); |
| 1282 scrollEnd.Scale(m_deviceScaleFactor); |
| 1282 | 1283 |
| 1283 makeScrollAndScaleSet(scrollInfo, roundedIntSize(scrollEnd), m_pinchZoomView
port.minPageScaleFactor()); | 1284 makeScrollAndScaleSet(scrollInfo, gfx::ToRoundedVector2d(scrollEnd), m_pinch
ZoomViewport.minPageScaleFactor()); |
| 1284 } | 1285 } |
| 1285 | 1286 |
| 1286 void LayerTreeHostImpl::makeScrollAndScaleSet(ScrollAndScaleSet* scrollInfo, con
st IntSize& scrollOffset, float pageScale) | 1287 void LayerTreeHostImpl::makeScrollAndScaleSet(ScrollAndScaleSet* scrollInfo, gfx
::Vector2d scrollOffset, float pageScale) |
| 1287 { | 1288 { |
| 1288 if (!m_rootScrollLayerImpl) | 1289 if (!m_rootScrollLayerImpl) |
| 1289 return; | 1290 return; |
| 1290 | 1291 |
| 1291 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 1292 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 1292 scroll.layerId = m_rootScrollLayerImpl->id(); | 1293 scroll.layerId = m_rootScrollLayerImpl->id(); |
| 1293 scroll.scrollDelta = scrollOffset - toSize(m_rootScrollLayerImpl->scrollPosi
tion()); | 1294 scroll.scrollDelta = scrollOffset - m_rootScrollLayerImpl->scrollOffset(); |
| 1294 scrollInfo->scrolls.push_back(scroll); | 1295 scrollInfo->scrolls.push_back(scroll); |
| 1295 m_rootScrollLayerImpl->setSentScrollDelta(scroll.scrollDelta); | 1296 m_rootScrollLayerImpl->setSentScrollDelta(scroll.scrollDelta); |
| 1296 scrollInfo->pageScaleDelta = pageScale / m_pinchZoomViewport.pageScaleFactor
(); | 1297 scrollInfo->pageScaleDelta = pageScale / m_pinchZoomViewport.pageScaleFactor
(); |
| 1297 m_pinchZoomViewport.setSentPageScaleDelta(scrollInfo->pageScaleDelta); | 1298 m_pinchZoomViewport.setSentPageScaleDelta(scrollInfo->pageScaleDelta); |
| 1298 } | 1299 } |
| 1299 | 1300 |
| 1300 static void collectScrollDeltas(ScrollAndScaleSet* scrollInfo, LayerImpl* layerI
mpl) | 1301 static void collectScrollDeltas(ScrollAndScaleSet* scrollInfo, LayerImpl* layerI
mpl) |
| 1301 { | 1302 { |
| 1302 if (!layerImpl) | 1303 if (!layerImpl) |
| 1303 return; | 1304 return; |
| 1304 | 1305 |
| 1305 if (!layerImpl->scrollDelta().isZero()) { | 1306 if (!layerImpl->scrollDelta().IsZero()) { |
| 1306 IntSize scrollDelta = flooredIntSize(layerImpl->scrollDelta()); | 1307 gfx::Vector2d scrollDelta = gfx::ToFlooredVector2d(layerImpl->scrollDelt
a()); |
| 1307 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 1308 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 1308 scroll.layerId = layerImpl->id(); | 1309 scroll.layerId = layerImpl->id(); |
| 1309 scroll.scrollDelta = scrollDelta; | 1310 scroll.scrollDelta = scrollDelta; |
| 1310 scrollInfo->scrolls.push_back(scroll); | 1311 scrollInfo->scrolls.push_back(scroll); |
| 1311 layerImpl->setSentScrollDelta(scrollDelta); | 1312 layerImpl->setSentScrollDelta(scrollDelta); |
| 1312 } | 1313 } |
| 1313 | 1314 |
| 1314 for (size_t i = 0; i < layerImpl->children().size(); ++i) | 1315 for (size_t i = 0; i < layerImpl->children().size(); ++i) |
| 1315 collectScrollDeltas(scrollInfo, layerImpl->children()[i]); | 1316 collectScrollDeltas(scrollInfo, layerImpl->children()[i]); |
| 1316 } | 1317 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 renderSurface->damageTracker()->forceFullDamageNextUpdate(); | 1354 renderSurface->damageTracker()->forceFullDamageNextUpdate(); |
| 1354 } | 1355 } |
| 1355 } | 1356 } |
| 1356 | 1357 |
| 1357 void LayerTreeHostImpl::animatePageScale(base::TimeTicks time) | 1358 void LayerTreeHostImpl::animatePageScale(base::TimeTicks time) |
| 1358 { | 1359 { |
| 1359 if (!m_pageScaleAnimation || !m_rootScrollLayerImpl) | 1360 if (!m_pageScaleAnimation || !m_rootScrollLayerImpl) |
| 1360 return; | 1361 return; |
| 1361 | 1362 |
| 1362 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1363 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
| 1363 IntSize scrollTotal = flooredIntSize(m_rootScrollLayerImpl->scrollPosition()
+ m_rootScrollLayerImpl->scrollDelta()); | 1364 gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); |
| 1364 | 1365 |
| 1365 setPageScaleDelta(m_pageScaleAnimation->pageScaleAtTime(monotonicTime) / m_p
inchZoomViewport.pageScaleFactor()); | 1366 setPageScaleDelta(m_pageScaleAnimation->pageScaleAtTime(monotonicTime) / m_p
inchZoomViewport.pageScaleFactor()); |
| 1366 IntSize nextScroll = m_pageScaleAnimation->scrollOffsetAtTime(monotonicTime)
; | 1367 gfx::Vector2dF nextScroll = m_pageScaleAnimation->scrollOffsetAtTime(monoton
icTime); |
| 1367 nextScroll.scale(1 / m_pinchZoomViewport.pageScaleDelta()); | 1368 nextScroll.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); |
| 1368 m_rootScrollLayerImpl->scrollBy(nextScroll - scrollTotal); | 1369 m_rootScrollLayerImpl->scrollBy(nextScroll - scrollTotal); |
| 1369 m_client->setNeedsRedrawOnImplThread(); | 1370 m_client->setNeedsRedrawOnImplThread(); |
| 1370 | 1371 |
| 1371 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { | 1372 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { |
| 1372 m_pageScaleAnimation.reset(); | 1373 m_pageScaleAnimation.reset(); |
| 1373 m_client->setNeedsCommitOnImplThread(); | 1374 m_client->setNeedsCommitOnImplThread(); |
| 1374 } | 1375 } |
| 1375 } | 1376 } |
| 1376 | 1377 |
| 1377 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time
wallClockTime) | 1378 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time
wallClockTime) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); | 1473 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); |
| 1473 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1474 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
| 1474 if (scrollbarController && scrollbarController->animate(monotonicTime)) | 1475 if (scrollbarController && scrollbarController->animate(monotonicTime)) |
| 1475 m_client->setNeedsRedrawOnImplThread(); | 1476 m_client->setNeedsRedrawOnImplThread(); |
| 1476 | 1477 |
| 1477 for (size_t i = 0; i < layer->children().size(); ++i) | 1478 for (size_t i = 0; i < layer->children().size(); ++i) |
| 1478 animateScrollbarsRecursive(layer->children()[i], time); | 1479 animateScrollbarsRecursive(layer->children()[i], time); |
| 1479 } | 1480 } |
| 1480 | 1481 |
| 1481 } // namespace cc | 1482 } // namespace cc |
| OLD | NEW |