| 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 "cc/page_scale_animation.h" | 5 #include "cc/page_scale_animation.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "cc/geometry.h" | |
| 9 #include "ui/gfx/point_f.h" | 8 #include "ui/gfx/point_f.h" |
| 10 #include "ui/gfx/rect_f.h" | 9 #include "ui/gfx/rect_f.h" |
| 11 #include "ui/gfx/vector2d_conversions.h" | 10 #include "ui/gfx/vector2d_conversions.h" |
| 12 | 11 |
| 13 #include <math.h> | 12 #include <math.h> |
| 14 | 13 |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 // This takes a viewport-relative vector and returns a vector whose values are | 16 // This takes a viewport-relative vector and returns a vector whose values are |
| 18 // between 0 and 1, representing the percentage position within the viewport. | 17 // between 0 and 1, representing the percentage position within the viewport. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // where both anchor and normalized begin as unknowns. Solving | 109 // where both anchor and normalized begin as unknowns. Solving |
| 111 // for the normalized, we get the following: | 110 // for the normalized, we get the following: |
| 112 float widthScale = 1 / (targetViewportSize().width() - startViewportSize().w
idth()); | 111 float widthScale = 1 / (targetViewportSize().width() - startViewportSize().w
idth()); |
| 113 float heightScale = 1 / (targetViewportSize().height() - startViewportSize()
.height()); | 112 float heightScale = 1 / (targetViewportSize().height() - startViewportSize()
.height()); |
| 114 gfx::Vector2dF normalized = gfx::ScaleVector2d(m_startScrollOffset - m_targe
tScrollOffset, widthScale, heightScale); | 113 gfx::Vector2dF normalized = gfx::ScaleVector2d(m_startScrollOffset - m_targe
tScrollOffset, widthScale, heightScale); |
| 115 m_targetAnchor = m_targetScrollOffset + denormalizeToViewport(normalized, ta
rgetViewportSize()); | 114 m_targetAnchor = m_targetScrollOffset + denormalizeToViewport(normalized, ta
rgetViewportSize()); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void PageScaleAnimation::clampTargetScrollOffset() | 117 void PageScaleAnimation::clampTargetScrollOffset() |
| 119 { | 118 { |
| 120 gfx::Vector2dF maxScrollOffset = BottomRight(gfx::RectF(m_rootLayerSize)) -
BottomRight(gfx::RectF(targetViewportSize())); | 119 gfx::Vector2dF maxScrollOffset = gfx::RectF(m_rootLayerSize).BottomRight() -
gfx::RectF(targetViewportSize()).BottomRight(); |
| 121 m_targetScrollOffset.ClampToMin(gfx::Vector2dF()); | 120 m_targetScrollOffset.ClampToMin(gfx::Vector2dF()); |
| 122 m_targetScrollOffset.ClampToMax(maxScrollOffset); | 121 m_targetScrollOffset.ClampToMax(maxScrollOffset); |
| 123 } | 122 } |
| 124 | 123 |
| 125 gfx::SizeF PageScaleAnimation::startViewportSize() const | 124 gfx::SizeF PageScaleAnimation::startViewportSize() const |
| 126 { | 125 { |
| 127 return gfx::ScaleSize(m_viewportSize, 1 / m_startPageScaleFactor); | 126 return gfx::ScaleSize(m_viewportSize, 1 / m_startPageScaleFactor); |
| 128 } | 127 } |
| 129 | 128 |
| 130 gfx::SizeF PageScaleAnimation::targetViewportSize() const | 129 gfx::SizeF PageScaleAnimation::targetViewportSize() const |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 195 |
| 197 // Linearly interpolate the magnitude in log scale. | 196 // Linearly interpolate the magnitude in log scale. |
| 198 float diff = m_targetPageScaleFactor / m_startPageScaleFactor; | 197 float diff = m_targetPageScaleFactor / m_startPageScaleFactor; |
| 199 float logDiff = log(diff); | 198 float logDiff = log(diff); |
| 200 logDiff *= interp; | 199 logDiff *= interp; |
| 201 diff = exp(logDiff); | 200 diff = exp(logDiff); |
| 202 return m_startPageScaleFactor * diff; | 201 return m_startPageScaleFactor * diff; |
| 203 } | 202 } |
| 204 | 203 |
| 205 } // namespace cc | 204 } // namespace cc |
| OLD | NEW |