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

Side by Side Diff: cc/layer_tree_host_impl.cc

Issue 11369144: ui: Make gfx::Point::Scale() mutate the class, similar to gfx::Rect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes for aura 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
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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewp ortPoint, InputHandlerClient::ScrollInputType type) 1038 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewp ortPoint, InputHandlerClient::ScrollInputType type)
1039 { 1039 {
1040 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); 1040 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin");
1041 1041
1042 DCHECK(!m_currentlyScrollingLayerImpl); 1042 DCHECK(!m_currentlyScrollingLayerImpl);
1043 clearCurrentlyScrollingLayer(); 1043 clearCurrentlyScrollingLayer();
1044 1044
1045 if (!ensureRenderSurfaceLayerList()) 1045 if (!ensureRenderSurfaceLayerList())
1046 return ScrollIgnored; 1046 return ScrollIgnored;
1047 1047
1048 gfx::PointF deviceViewportPoint = viewportPoint.Scale(m_deviceScaleFactor); 1048 gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceSca leFactor);
1049 1049
1050 // First find out which layer was hit from the saved list of visible layers 1050 // First find out which layer was hit from the saved list of visible layers
1051 // in the most recent frame. 1051 // in the most recent frame.
1052 LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(device ViewportPoint, m_renderSurfaceLayerList); 1052 LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(device ViewportPoint, m_renderSurfaceLayerList);
1053 1053
1054 // Walk up the hierarchy and look for a scrollable layer. 1054 // Walk up the hierarchy and look for a scrollable layer.
1055 LayerImpl* potentiallyScrollingLayerImpl = 0; 1055 LayerImpl* potentiallyScrollingLayerImpl = 0;
1056 for (; layerImpl; layerImpl = layerImpl->parent()) { 1056 for (; layerImpl; layerImpl = layerImpl->parent()) {
1057 // The content layer can also block attempts to scroll outside the main thread. 1057 // The content layer can also block attempts to scroll outside the main thread.
1058 if (layerImpl->tryScroll(deviceViewportPoint, type) == ScrollOnMainThrea d) { 1058 if (layerImpl->tryScroll(deviceViewportPoint, type) == ScrollOnMainThrea d) {
(...skipping 29 matching lines...) Expand all
1088 return ScrollIgnored; 1088 return ScrollIgnored;
1089 } 1089 }
1090 1090
1091 static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewp ort, LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, gfx::PointF vie wportPoint, gfx::Vector2dF viewportDelta) 1091 static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewp ort, LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, gfx::PointF vie wportPoint, gfx::Vector2dF viewportDelta)
1092 { 1092 {
1093 // Layers with non-invertible screen space transforms should not have passed the scroll hit 1093 // Layers with non-invertible screen space transforms should not have passed the scroll hit
1094 // test in the first place. 1094 // test in the first place.
1095 DCHECK(layerImpl.screenSpaceTransform().isInvertible()); 1095 DCHECK(layerImpl.screenSpaceTransform().isInvertible());
1096 WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceT ransform().inverse(); 1096 WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceT ransform().inverse();
1097 1097
1098 gfx::PointF screenSpacePoint = viewportPoint.Scale(scaleFromViewportToScreen Space); 1098 gfx::PointF screenSpacePoint = gfx::ScalePoint(viewportPoint, scaleFromViewp ortToScreenSpace);
1099 1099
1100 gfx::Vector2dF screenSpaceDelta = viewportDelta; 1100 gfx::Vector2dF screenSpaceDelta = viewportDelta;
1101 screenSpaceDelta.Scale(scaleFromViewportToScreenSpace); 1101 screenSpaceDelta.Scale(scaleFromViewportToScreenSpace);
1102 1102
1103 // First project the scroll start and end points to local layer space to fin d the scroll delta 1103 // First project the scroll start and end points to local layer space to fin d the scroll delta
1104 // in layer coordinates. 1104 // in layer coordinates.
1105 bool startClipped, endClipped; 1105 bool startClipped, endClipped;
1106 gfx::PointF screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta; 1106 gfx::PointF screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta;
1107 gfx::PointF localStartPoint = MathUtil::projectPoint(inverseScreenSpaceTrans form, screenSpacePoint, startClipped); 1107 gfx::PointF localStartPoint = MathUtil::projectPoint(inverseScreenSpaceTrans form, screenSpacePoint, startClipped);
1108 gfx::PointF localEndPoint = MathUtil::projectPoint(inverseScreenSpaceTransfo rm, screenSpaceEndPoint, endClipped); 1108 gfx::PointF localEndPoint = MathUtil::projectPoint(inverseScreenSpaceTransfo rm, screenSpaceEndPoint, endClipped);
1109 1109
1110 // In general scroll point coordinates should not get clipped. 1110 // In general scroll point coordinates should not get clipped.
1111 DCHECK(!startClipped); 1111 DCHECK(!startClipped);
1112 DCHECK(!endClipped); 1112 DCHECK(!endClipped);
1113 if (startClipped || endClipped) 1113 if (startClipped || endClipped)
1114 return gfx::Vector2dF(); 1114 return gfx::Vector2dF();
1115 1115
1116 // localStartPoint and localEndPoint are in content space but we want to mov e them to layer space for scrolling. 1116 // localStartPoint and localEndPoint are in content space but we want to mov e them to layer space for scrolling.
1117 float widthScale = 1 / layerImpl.contentsScaleX(); 1117 float widthScale = 1 / layerImpl.contentsScaleX();
1118 float heightScale = 1 / layerImpl.contentsScaleY(); 1118 float heightScale = 1 / layerImpl.contentsScaleY();
1119 localStartPoint = localStartPoint.Scale(widthScale, heightScale); 1119 localStartPoint.Scale(widthScale, heightScale);
1120 localEndPoint = localEndPoint.Scale(widthScale, heightScale); 1120 localEndPoint.Scale(widthScale, heightScale);
1121 1121
1122 // Apply the scroll delta. 1122 // Apply the scroll delta.
1123 gfx::Vector2dF previousDelta = layerImpl.scrollDelta(); 1123 gfx::Vector2dF previousDelta = layerImpl.scrollDelta();
1124 gfx::Vector2dF unscrolled = layerImpl.scrollBy(localEndPoint - localStartPoi nt); 1124 gfx::Vector2dF unscrolled = layerImpl.scrollBy(localEndPoint - localStartPoi nt);
1125 1125
1126 if (viewport) 1126 if (viewport)
1127 viewport->applyScroll(unscrolled); 1127 viewport->applyScroll(unscrolled);
1128 1128
1129 // Get the end point in the layer's content space so we can apply its screen SpaceTransform. 1129 // Get the end point in the layer's content space so we can apply its screen SpaceTransform.
1130 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() - previousDelta; 1130 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() - previousDelta;
1131 gfx::PointF actualLocalContentEndPoint = actualLocalEndPoint.Scale(1 / width Scale, 1 / heightScale); 1131 gfx::PointF actualLocalContentEndPoint = gfx::ScalePoint(actualLocalEndPoint , 1 / widthScale, 1 / heightScale);
1132 1132
1133 // Calculate the applied scroll delta in viewport space coordinates. 1133 // Calculate the applied scroll delta in viewport space coordinates.
1134 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS paceTransform(), actualLocalContentEndPoint, endClipped); 1134 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS paceTransform(), actualLocalContentEndPoint, endClipped);
1135 DCHECK(!endClipped); 1135 DCHECK(!endClipped);
1136 if (endClipped) 1136 if (endClipped)
1137 return gfx::Vector2dF(); 1137 return gfx::Vector2dF();
1138 gfx::PointF actualViewportEndPoint = actualScreenSpaceEndPoint.Scale(1 / sca leFromViewportToScreenSpace); 1138 gfx::PointF actualViewportEndPoint = gfx::ScalePoint(actualScreenSpaceEndPoi nt, 1 / scaleFromViewportToScreenSpace);
1139 return actualViewportEndPoint - viewportPoint; 1139 return actualViewportEndPoint - viewportPoint;
1140 } 1140 }
1141 1141
1142 static gfx::Vector2dF scrollLayerWithLocalDelta(LayerImpl& layerImpl, gfx::Vecto r2dF localDelta) 1142 static gfx::Vector2dF scrollLayerWithLocalDelta(LayerImpl& layerImpl, gfx::Vecto r2dF localDelta)
1143 { 1143 {
1144 gfx::Vector2dF previousDelta(layerImpl.scrollDelta()); 1144 gfx::Vector2dF previousDelta(layerImpl.scrollDelta());
1145 layerImpl.scrollBy(localDelta); 1145 layerImpl.scrollBy(localDelta);
1146 return layerImpl.scrollDelta() - previousDelta; 1146 return layerImpl.scrollDelta() - previousDelta;
1147 } 1147 }
1148 1148
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 1220
1221 if (!m_rootScrollLayerImpl) 1221 if (!m_rootScrollLayerImpl)
1222 return; 1222 return;
1223 1223
1224 if (m_previousPinchAnchor == gfx::Point()) 1224 if (m_previousPinchAnchor == gfx::Point())
1225 m_previousPinchAnchor = anchor; 1225 m_previousPinchAnchor = anchor;
1226 1226
1227 // Keep the center-of-pinch anchor specified by (x, y) in a stable 1227 // Keep the center-of-pinch anchor specified by (x, y) in a stable
1228 // position over the course of the magnify. 1228 // position over the course of the magnify.
1229 float pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); 1229 float pageScaleDelta = m_pinchZoomViewport.pageScaleDelta();
1230 gfx::PointF previousScaleAnchor = m_previousPinchAnchor.Scale(1 / pageScaleD elta); 1230 gfx::PointF previousScaleAnchor = gfx::ScalePoint(m_previousPinchAnchor, 1 / pageScaleDelta);
1231 setPageScaleDelta(pageScaleDelta * magnifyDelta); 1231 setPageScaleDelta(pageScaleDelta * magnifyDelta);
1232 pageScaleDelta = m_pinchZoomViewport.pageScaleDelta(); 1232 pageScaleDelta = m_pinchZoomViewport.pageScaleDelta();
1233 gfx::PointF newScaleAnchor = anchor.Scale(1 / pageScaleDelta); 1233 gfx::PointF newScaleAnchor = gfx::ScalePoint(anchor, 1 / pageScaleDelta);
1234 gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor; 1234 gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor;
1235 1235
1236 m_previousPinchAnchor = anchor; 1236 m_previousPinchAnchor = anchor;
1237 1237
1238 if (Settings::pageScalePinchZoomEnabled()) { 1238 if (Settings::pageScalePinchZoomEnabled()) {
1239 // Compute the application of the delta with respect to the current page zoom of the page. 1239 // Compute the application of the delta with respect to the current page zoom of the page.
1240 move.Scale(1 / (m_pinchZoomViewport.pageScaleFactor() * m_deviceScaleFac tor)); 1240 move.Scale(1 / (m_pinchZoomViewport.pageScaleFactor() * m_deviceScaleFac tor));
1241 } 1241 }
1242 1242
1243 gfx::Vector2dF scrollOverflow = Settings::pageScalePinchZoomEnabled() ? m_pi nchZoomViewport.applyScroll(move) : move; 1243 gfx::Vector2dF scrollOverflow = Settings::pageScalePinchZoomEnabled() ? m_pi nchZoomViewport.applyScroll(move) : move;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1489 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1490 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1490 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1491 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1491 if (scrollbarController && scrollbarController->animate(monotonicTime))
1492 m_client->setNeedsRedrawOnImplThread(); 1492 m_client->setNeedsRedrawOnImplThread();
1493 1493
1494 for (size_t i = 0; i < layer->children().size(); ++i) 1494 for (size_t i = 0; i < layer->children().size(); ++i)
1495 animateScrollbarsRecursive(layer->children()[i], time); 1495 animateScrollbarsRecursive(layer->children()[i], time);
1496 } 1496 }
1497 1497
1498 } // namespace cc 1498 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698