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 <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 m_minPageScaleFactor = minPageScaleFactor; | 94 m_minPageScaleFactor = minPageScaleFactor; |
95 m_maxPageScaleFactor = maxPageScaleFactor; | 95 m_maxPageScaleFactor = maxPageScaleFactor; |
96 | 96 |
97 m_pageScaleFactor = pageScaleFactor; | 97 m_pageScaleFactor = pageScaleFactor; |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 gfx::RectF PinchZoomViewport::bounds() const | 101 gfx::RectF PinchZoomViewport::bounds() const |
102 { | 102 { |
103 gfx::SizeF scaledViewportSize = m_layoutViewportSize; | 103 gfx::RectF bounds(gfx::PointF(), m_layoutViewportSize); |
104 scaledViewportSize = scaledViewportSize.Scale(1 / totalPageScaleFactor()); | 104 bounds.Scale(1 / totalPageScaleFactor()); |
105 | |
106 gfx::RectF bounds(gfx::PointF(), scaledViewportSize); | |
107 bounds.Offset(m_pinchViewportScrollDelta); | 105 bounds.Offset(m_pinchViewportScrollDelta); |
108 | |
109 return bounds; | 106 return bounds; |
110 } | 107 } |
111 | 108 |
112 gfx::Vector2dF PinchZoomViewport::applyScroll(const gfx::Vector2dF& delta) | 109 gfx::Vector2dF PinchZoomViewport::applyScroll(const gfx::Vector2dF& delta) |
113 { | 110 { |
114 gfx::Vector2dF overflow; | 111 gfx::Vector2dF overflow; |
115 gfx::RectF pinchedBounds = bounds(); | 112 gfx::RectF pinchedBounds = bounds(); |
116 | 113 |
117 pinchedBounds.Offset(delta); | 114 pinchedBounds.Offset(delta); |
118 if (pinchedBounds.x() < 0) { | 115 if (pinchedBounds.x() < 0) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 292 } |
296 | 293 |
297 void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetOffset, bool
anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta durati
on) | 294 void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetOffset, bool
anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta durati
on) |
298 { | 295 { |
299 if (!m_rootScrollLayerImpl) | 296 if (!m_rootScrollLayerImpl) |
300 return; | 297 return; |
301 | 298 |
302 gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); | 299 gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); |
303 scrollTotal.Scale(m_pinchZoomViewport.pageScaleDelta()); | 300 scrollTotal.Scale(m_pinchZoomViewport.pageScaleDelta()); |
304 float scaleTotal = m_pinchZoomViewport.totalPageScaleFactor(); | 301 float scaleTotal = m_pinchZoomViewport.totalPageScaleFactor(); |
305 gfx::Size scaledContentSize = gfx::ToFlooredSize(contentSize().Scale(m_pinch
ZoomViewport.pageScaleDelta())); | 302 gfx::Size scaledContentSize = gfx::ToFlooredSize(gfx::ScaleSize(contentSize(
), m_pinchZoomViewport.pageScaleDelta())); |
306 | 303 |
307 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); | 304 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); |
308 m_pageScaleAnimation = PageScaleAnimation::create(gfx::ToFlooredVector2d(scr
ollTotal), scaleTotal, m_deviceViewportSize, scaledContentSize, startTimeSeconds
); | 305 m_pageScaleAnimation = PageScaleAnimation::create(gfx::ToFlooredVector2d(scr
ollTotal), scaleTotal, m_deviceViewportSize, scaledContentSize, startTimeSeconds
); |
309 | 306 |
310 if (anchorPoint) { | 307 if (anchorPoint) { |
311 gfx::Vector2dF windowAnchor = targetOffset; | 308 gfx::Vector2dF windowAnchor = targetOffset; |
312 windowAnchor.Scale(scaleTotal / pageScale); | 309 windowAnchor.Scale(scaleTotal / pageScale); |
313 windowAnchor -= scrollTotal; | 310 windowAnchor -= scrollTotal; |
314 m_pageScaleAnimation->zoomWithAnchor(gfx::ToFlooredVector2d(windowAnchor
), pageScale, duration.InSecondsF()); | 311 m_pageScaleAnimation->zoomWithAnchor(gfx::ToFlooredVector2d(windowAnchor
), pageScale, duration.InSecondsF()); |
315 } else | 312 } else |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 } | 971 } |
975 | 972 |
976 void LayerTreeHostImpl::updateMaxScrollOffset() | 973 void LayerTreeHostImpl::updateMaxScrollOffset() |
977 { | 974 { |
978 if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size()) | 975 if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size()) |
979 return; | 976 return; |
980 | 977 |
981 gfx::SizeF viewBounds = m_deviceViewportSize; | 978 gfx::SizeF viewBounds = m_deviceViewportSize; |
982 if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) { | 979 if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) { |
983 // Compensate for non-overlay scrollbars. | 980 // Compensate for non-overlay scrollbars. |
984 if (clipLayer->masksToBounds()) { | 981 if (clipLayer->masksToBounds()) |
985 viewBounds = clipLayer->bounds(); | 982 viewBounds = gfx::ScaleSize(clipLayer->bounds(), m_deviceScaleFactor
); |
986 viewBounds = viewBounds.Scale(m_deviceScaleFactor); | |
987 } | |
988 } | 983 } |
989 | 984 |
990 gfx::Size contentBounds = contentSize(); | 985 gfx::Size contentBounds = contentSize(); |
991 if (Settings::pageScalePinchZoomEnabled()) { | 986 if (Settings::pageScalePinchZoomEnabled()) { |
992 // Pinch with pageScale scrolls entirely in layout space. contentSize | 987 // Pinch with pageScale scrolls entirely in layout space. contentSize |
993 // returns the bounds including the page scale factor, so calculate the | 988 // returns the bounds including the page scale factor, so calculate the |
994 // pre page-scale layout size here. | 989 // pre page-scale layout size here. |
995 float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); | 990 float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); |
996 contentBounds.set_width(contentBounds.width() / pageScaleFactor); | 991 contentBounds.set_width(contentBounds.width() / pageScaleFactor); |
997 contentBounds.set_height(contentBounds.height() / pageScaleFactor); | 992 contentBounds.set_height(contentBounds.height() / pageScaleFactor); |
998 } else { | 993 } else { |
999 viewBounds = viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); | 994 viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); |
1000 } | 995 } |
1001 | 996 |
1002 gfx::Vector2dF maxScroll = BottomRight(gfx::Rect(contentBounds)) - BottomRig
ht(gfx::RectF(viewBounds)); | 997 gfx::Vector2dF maxScroll = BottomRight(gfx::Rect(contentBounds)) - BottomRig
ht(gfx::RectF(viewBounds)); |
1003 maxScroll.Scale(1 / m_deviceScaleFactor); | 998 maxScroll.Scale(1 / m_deviceScaleFactor); |
1004 | 999 |
1005 // The viewport may be larger than the contents in some cases, such as | 1000 // The viewport may be larger than the contents in some cases, such as |
1006 // having a vertical scrollbar but no horizontal overflow. | 1001 // having a vertical scrollbar but no horizontal overflow. |
1007 maxScroll = ClampFromBelow(maxScroll, gfx::Vector2dF()); | 1002 maxScroll = ClampFromBelow(maxScroll, gfx::Vector2dF()); |
1008 | 1003 |
1009 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll))
; | 1004 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll))
; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 const float pinchZoomOutSensitivity = 0.95f; | 1274 const float pinchZoomOutSensitivity = 0.95f; |
1280 if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity) | 1275 if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity) |
1281 return; | 1276 return; |
1282 | 1277 |
1283 // Compute where the scroll offset/page scale would be if fully pinch-zoomed | 1278 // Compute where the scroll offset/page scale would be if fully pinch-zoomed |
1284 // out from the anchor point. | 1279 // out from the anchor point. |
1285 gfx::Vector2dF scrollBegin = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); | 1280 gfx::Vector2dF scrollBegin = m_rootScrollLayerImpl->scrollOffset() + m_rootS
crollLayerImpl->scrollDelta(); |
1286 scrollBegin.Scale(m_pinchZoomViewport.pageScaleDelta()); | 1281 scrollBegin.Scale(m_pinchZoomViewport.pageScaleDelta()); |
1287 float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor(); | 1282 float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor(); |
1288 float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pi
nchZoomViewport.pageScaleFactor(); | 1283 float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pi
nchZoomViewport.pageScaleFactor(); |
1289 gfx::SizeF scaledContentsSize = contentSize().Scale(pageScaleDeltaToSend); | 1284 gfx::SizeF scaledContentsSize = gfx::ScaleSize(contentSize(), pageScaleDelta
ToSend); |
1290 | 1285 |
1291 gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin(); | 1286 gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin(); |
1292 gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset; | 1287 gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset; |
1293 scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin); | 1288 scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin); |
1294 scrollEnd -= anchorOffset; | 1289 scrollEnd -= anchorOffset; |
1295 scrollEnd = ClampFromAbove(scrollEnd, BottomRight(gfx::RectF(scaledContentsS
ize)) - BottomRight(gfx::Rect(m_deviceViewportSize))); | 1290 scrollEnd = ClampFromAbove(scrollEnd, BottomRight(gfx::RectF(scaledContentsS
ize)) - BottomRight(gfx::Rect(m_deviceViewportSize))); |
1296 scrollEnd = ClampFromBelow(scrollEnd, gfx::Vector2d()); | 1291 scrollEnd = ClampFromBelow(scrollEnd, gfx::Vector2d()); |
1297 scrollEnd.Scale(1 / pageScaleDeltaToSend); | 1292 scrollEnd.Scale(1 / pageScaleDeltaToSend); |
1298 scrollEnd.Scale(m_deviceScaleFactor); | 1293 scrollEnd.Scale(m_deviceScaleFactor); |
1299 | 1294 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); | 1484 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); |
1490 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1485 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
1491 if (scrollbarController && scrollbarController->animate(monotonicTime)) | 1486 if (scrollbarController && scrollbarController->animate(monotonicTime)) |
1492 m_client->setNeedsRedrawOnImplThread(); | 1487 m_client->setNeedsRedrawOnImplThread(); |
1493 | 1488 |
1494 for (size_t i = 0; i < layer->children().size(); ++i) | 1489 for (size_t i = 0; i < layer->children().size(); ++i) |
1495 animateScrollbarsRecursive(layer->children()[i], time); | 1490 animateScrollbarsRecursive(layer->children()[i], time); |
1496 } | 1491 } |
1497 | 1492 |
1498 } // namespace cc | 1493 } // namespace cc |
OLD | NEW |