Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: cc/layer_tree_host_impl.cc

Issue 11377068: ui: Make gfx::Size::Scale() mutate the class. Add gfx::ScaleSize() similar to Rect/Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseTOGO Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/contents_scaling_layer.cc ('k') | cc/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 292
293 void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetPosition, bo ol anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta dura tion) 293 void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetPosition, bo ol anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta dura tion)
294 { 294 {
295 if (!m_rootScrollLayerImpl) 295 if (!m_rootScrollLayerImpl)
296 return; 296 return;
297 297
298 gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootS crollLayerImpl->scrollDelta(); 298 gfx::Vector2dF scrollTotal = m_rootScrollLayerImpl->scrollOffset() + m_rootS crollLayerImpl->scrollDelta();
299 gfx::SizeF scaledContentSize = contentSize(); 299 gfx::SizeF scaledContentSize = contentSize();
300 if (!Settings::pageScalePinchZoomEnabled()) { 300 if (!Settings::pageScalePinchZoomEnabled()) {
301 scrollTotal.Scale(1 / m_pinchZoomViewport.pageScaleFactor()); 301 scrollTotal.Scale(1 / m_pinchZoomViewport.pageScaleFactor());
302 scaledContentSize = scaledContentSize.Scale(1 / m_pinchZoomViewport.page ScaleFactor()); 302 scaledContentSize.Scale(1 / m_pinchZoomViewport.pageScaleFactor());
303 } 303 }
304 gfx::SizeF viewportSize = m_deviceViewportSize; 304 gfx::SizeF viewportSize = gfx::ScaleSize(m_deviceViewportSize, 1 / m_deviceS caleFactor);
305 viewportSize = viewportSize.Scale(1 / m_deviceScaleFactor);
306 305
307 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); 306 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF();
308 m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, m_pinchZoomVi ewport.totalPageScaleFactor(), viewportSize, scaledContentSize, startTimeSeconds ); 307 m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, m_pinchZoomVi ewport.totalPageScaleFactor(), viewportSize, scaledContentSize, startTimeSeconds );
309 308
310 if (anchorPoint) { 309 if (anchorPoint) {
311 gfx::Vector2dF anchor(targetPosition); 310 gfx::Vector2dF anchor(targetPosition);
312 if (!Settings::pageScalePinchZoomEnabled()) 311 if (!Settings::pageScalePinchZoomEnabled())
313 anchor.Scale(1 / pageScale); 312 anchor.Scale(1 / pageScale);
314 m_pageScaleAnimation->zoomWithAnchor(anchor, pageScale, duration.InSecon dsF()); 313 m_pageScaleAnimation->zoomWithAnchor(anchor, pageScale, duration.InSecon dsF());
315 } else { 314 } else {
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } 977 }
979 978
980 void LayerTreeHostImpl::updateMaxScrollOffset() 979 void LayerTreeHostImpl::updateMaxScrollOffset()
981 { 980 {
982 if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size()) 981 if (!m_rootScrollLayerImpl || !m_rootScrollLayerImpl->children().size())
983 return; 982 return;
984 983
985 gfx::SizeF viewBounds = m_deviceViewportSize; 984 gfx::SizeF viewBounds = m_deviceViewportSize;
986 if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) { 985 if (LayerImpl* clipLayer = m_rootScrollLayerImpl->parent()) {
987 // Compensate for non-overlay scrollbars. 986 // Compensate for non-overlay scrollbars.
988 if (clipLayer->masksToBounds()) { 987 if (clipLayer->masksToBounds())
989 viewBounds = clipLayer->bounds(); 988 viewBounds = gfx::ScaleSize(clipLayer->bounds(), m_deviceScaleFactor );
990 viewBounds = viewBounds.Scale(m_deviceScaleFactor);
991 }
992 } 989 }
993 990
994 gfx::Size contentBounds = contentSize(); 991 gfx::Size contentBounds = contentSize();
995 if (Settings::pageScalePinchZoomEnabled()) { 992 if (Settings::pageScalePinchZoomEnabled()) {
996 // Pinch with pageScale scrolls entirely in layout space. contentSize 993 // Pinch with pageScale scrolls entirely in layout space. contentSize
997 // returns the bounds including the page scale factor, so calculate the 994 // returns the bounds including the page scale factor, so calculate the
998 // pre page-scale layout size here. 995 // pre page-scale layout size here.
999 float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor(); 996 float pageScaleFactor = m_pinchZoomViewport.pageScaleFactor();
1000 contentBounds.set_width(contentBounds.width() / pageScaleFactor); 997 contentBounds.set_width(contentBounds.width() / pageScaleFactor);
1001 contentBounds.set_height(contentBounds.height() / pageScaleFactor); 998 contentBounds.set_height(contentBounds.height() / pageScaleFactor);
1002 } else { 999 } else {
1003 viewBounds = viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta()); 1000 viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta());
1004 } 1001 }
1005 1002
1006 gfx::Vector2dF maxScroll = BottomRight(gfx::Rect(contentBounds)) - BottomRig ht(gfx::RectF(viewBounds)); 1003 gfx::Vector2dF maxScroll = BottomRight(gfx::Rect(contentBounds)) - BottomRig ht(gfx::RectF(viewBounds));
1007 maxScroll.Scale(1 / m_deviceScaleFactor); 1004 maxScroll.Scale(1 / m_deviceScaleFactor);
1008 1005
1009 // The viewport may be larger than the contents in some cases, such as 1006 // The viewport may be larger than the contents in some cases, such as
1010 // having a vertical scrollbar but no horizontal overflow. 1007 // having a vertical scrollbar but no horizontal overflow.
1011 maxScroll.ClampToMin(gfx::Vector2dF()); 1008 maxScroll.ClampToMin(gfx::Vector2dF());
1012 1009
1013 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll)) ; 1010 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll)) ;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 const float pinchZoomOutSensitivity = 0.95f; 1280 const float pinchZoomOutSensitivity = 0.95f;
1284 if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity) 1281 if (m_pinchZoomViewport.pageScaleDelta() > pinchZoomOutSensitivity)
1285 return; 1282 return;
1286 1283
1287 // Compute where the scroll offset/page scale would be if fully pinch-zoomed 1284 // Compute where the scroll offset/page scale would be if fully pinch-zoomed
1288 // out from the anchor point. 1285 // out from the anchor point.
1289 gfx::Vector2dF scrollBegin = m_rootScrollLayerImpl->scrollOffset() + m_rootS crollLayerImpl->scrollDelta(); 1286 gfx::Vector2dF scrollBegin = m_rootScrollLayerImpl->scrollOffset() + m_rootS crollLayerImpl->scrollDelta();
1290 scrollBegin.Scale(m_pinchZoomViewport.pageScaleDelta()); 1287 scrollBegin.Scale(m_pinchZoomViewport.pageScaleDelta());
1291 float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor(); 1288 float scaleBegin = m_pinchZoomViewport.totalPageScaleFactor();
1292 float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pi nchZoomViewport.pageScaleFactor(); 1289 float pageScaleDeltaToSend = m_pinchZoomViewport.minPageScaleFactor() / m_pi nchZoomViewport.pageScaleFactor();
1293 gfx::SizeF scaledContentsSize = contentSize().Scale(pageScaleDeltaToSend); 1290 gfx::SizeF scaledContentsSize = gfx::ScaleSize(contentSize(), pageScaleDelta ToSend);
1294 1291
1295 gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin(); 1292 gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin();
1296 gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset; 1293 gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset;
1297 scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin); 1294 scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin);
1298 scrollEnd -= anchorOffset; 1295 scrollEnd -= anchorOffset;
1299 scrollEnd.ClampToMax(BottomRight(gfx::RectF(scaledContentsSize)) - BottomRig ht(gfx::Rect(m_deviceViewportSize))); 1296 scrollEnd.ClampToMax(BottomRight(gfx::RectF(scaledContentsSize)) - BottomRig ht(gfx::Rect(m_deviceViewportSize)));
1300 scrollEnd.ClampToMin(gfx::Vector2d()); 1297 scrollEnd.ClampToMin(gfx::Vector2d());
1301 scrollEnd.Scale(1 / pageScaleDeltaToSend); 1298 scrollEnd.Scale(1 / pageScaleDeltaToSend);
1302 scrollEnd.Scale(m_deviceScaleFactor); 1299 scrollEnd.Scale(m_deviceScaleFactor);
1303 1300
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1490 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1494 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1491 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1495 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1492 if (scrollbarController && scrollbarController->animate(monotonicTime))
1496 m_client->setNeedsRedrawOnImplThread(); 1493 m_client->setNeedsRedrawOnImplThread();
1497 1494
1498 for (size_t i = 0; i < layer->children().size(); ++i) 1495 for (size_t i = 0; i < layer->children().size(); ++i)
1499 animateScrollbarsRecursive(layer->children()[i], time); 1496 animateScrollbarsRecursive(layer->children()[i], time);
1500 } 1497 }
1501 1498
1502 } // namespace cc 1499 } // namespace cc
OLDNEW
« no previous file with comments | « cc/contents_scaling_layer.cc ('k') | cc/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698