OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/page_scale_animation.h" | 7 #include "cc/page_scale_animation.h" |
8 #include "ui/gfx/point_f.h" | 8 #include "ui/gfx/point_f.h" |
9 #include "ui/gfx/rect_f.h" | 9 #include "ui/gfx/rect_f.h" |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <math.h> | 12 #include <math.h> |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 gfx::PointF toPointF(const gfx::Vector2dF& vector) | 16 gfx::PointF toPointF(const gfx::Vector2dF& vector) |
17 { | 17 { |
18 return gfx::PointF(vector.x(), vector.y()); | 18 return gfx::PointF(vector.x(), vector.y()); |
19 } | 19 } |
20 | 20 |
21 // This takes a viewport-relative vector and returns a vector whose values are | 21 // This takes a viewport-relative vector and returns a vector whose values are |
22 // between 0 and 1, representing the percentage position within the viewport. | 22 // between 0 and 1, representing the percentage position within the viewport. |
23 gfx::Vector2dF normalizeFromViewport(const gfx::Vector2dF& denormalized, const g
fx::SizeF& viewportSize) | 23 gfx::Vector2dF normalizeFromViewport(const gfx::Vector2dF& denormalized, const g
fx::SizeF& viewportSize) |
24 { | 24 { |
25 gfx::Vector2dF normalized(denormalized); | 25 return gfx::ScaleVector2d(denormalized, 1 / viewportSize.width(), 1 / viewpo
rtSize.height()); |
26 normalized.Scale(1 / viewportSize.width(), 1 / viewportSize.height()); | |
27 return normalized; | |
28 } | 26 } |
29 | 27 |
30 gfx::Vector2dF denormalizeToViewport(const gfx::Vector2dF& normalized, const gfx
::SizeF& viewportSize) | 28 gfx::Vector2dF denormalizeToViewport(const gfx::Vector2dF& normalized, const gfx
::SizeF& viewportSize) |
31 { | 29 { |
32 gfx::Vector2dF denormalized(normalized); | 30 return gfx::ScaleVector2d(normalized, viewportSize.width(), viewportSize.hei
ght()); |
33 denormalized.Scale(viewportSize.width(), viewportSize.height()); | |
34 return denormalized; | |
35 } | 31 } |
36 | 32 |
37 gfx::Vector2dF interpolateBetween(const gfx::Vector2dF& start, const gfx::Vector
2dF end, float interp) | 33 gfx::Vector2dF interpolateBetween(const gfx::Vector2dF& start, const gfx::Vector
2dF end, float interp) |
38 { | 34 { |
39 gfx::Vector2dF result; | 35 gfx::Vector2dF result; |
40 result.set_x(start.x() + interp * (end.x() - start.x())); | 36 result.set_x(start.x() + interp * (end.x() - start.x())); |
41 result.set_y(start.y() + interp * (end.y() - start.y())); | 37 result.set_y(start.y() + interp * (end.y() - start.y())); |
42 return result; | 38 return result; |
43 } | 39 } |
44 | 40 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return m_startScrollOffset; | 172 return m_startScrollOffset; |
177 if (interp >= 1) | 173 if (interp >= 1) |
178 return m_targetScrollOffset; | 174 return m_targetScrollOffset; |
179 | 175 |
180 return anchorAt(interp) - viewportRelativeAnchorAt(interp); | 176 return anchorAt(interp) - viewportRelativeAnchorAt(interp); |
181 } | 177 } |
182 | 178 |
183 gfx::Vector2dF PageScaleAnimation::anchorAt(float interp) const | 179 gfx::Vector2dF PageScaleAnimation::anchorAt(float interp) const |
184 { | 180 { |
185 // Interpolate from start to target anchor in absolute space. | 181 // Interpolate from start to target anchor in absolute space. |
186 gfx::Vector2dF delta = m_targetAnchor - m_startAnchor; | 182 gfx::Vector2dF delta = gfx::ScaleVector2d(m_targetAnchor - m_startAnchor, in
terp); |
187 delta.Scale(interp); | |
188 return m_startAnchor + delta; | 183 return m_startAnchor + delta; |
189 } | 184 } |
190 | 185 |
191 gfx::Vector2dF PageScaleAnimation::viewportRelativeAnchorAt(float interp) const | 186 gfx::Vector2dF PageScaleAnimation::viewportRelativeAnchorAt(float interp) const |
192 { | 187 { |
193 // Interpolate from start to target anchor in the space relative to the | 188 // Interpolate from start to target anchor in the space relative to the |
194 // viewport at its current scale level. | 189 // viewport at its current scale level. |
195 gfx::Vector2dF anchorRelativeToStartViewport = m_startAnchor - m_startScroll
Offset; | 190 gfx::Vector2dF anchorRelativeToStartViewport = m_startAnchor - m_startScroll
Offset; |
196 gfx::Vector2dF anchorRelativeToTargetViewport = m_targetAnchor - m_targetScr
ollOffset; | 191 gfx::Vector2dF anchorRelativeToTargetViewport = m_targetAnchor - m_targetScr
ollOffset; |
197 | 192 |
(...skipping 14 matching lines...) Expand all Loading... |
212 | 207 |
213 // Linearly interpolate the magnitude in log scale. | 208 // Linearly interpolate the magnitude in log scale. |
214 float diff = m_targetPageScaleFactor / m_startPageScaleFactor; | 209 float diff = m_targetPageScaleFactor / m_startPageScaleFactor; |
215 float logDiff = log(diff); | 210 float logDiff = log(diff); |
216 logDiff *= interp; | 211 logDiff *= interp; |
217 diff = exp(logDiff); | 212 diff = exp(logDiff); |
218 return m_startPageScaleFactor * diff; | 213 return m_startPageScaleFactor * diff; |
219 } | 214 } |
220 | 215 |
221 } // namespace cc | 216 } // namespace cc |
OLD | NEW |