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

Side by Side Diff: cc/page_scale_animation.cc

Issue 11361186: ui: Add methods to clamp Sizes, Points, and Vectors from above or below. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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/layer_tree_host_impl.cc ('k') | cc/tiled_layer.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 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
9 #include "cc/geometry.h"
8 #include "ui/gfx/point_f.h" 10 #include "ui/gfx/point_f.h"
9 #include "ui/gfx/rect_f.h" 11 #include "ui/gfx/rect_f.h"
10 12
11 #include <algorithm>
12 #include <math.h> 13 #include <math.h>
13 14
14 namespace { 15 namespace {
15 16
16 gfx::PointF toPointF(const gfx::Vector2dF& vector) 17 gfx::PointF toPointF(const gfx::Vector2dF& vector)
17 { 18 {
18 return gfx::PointF(vector.x(), vector.y()); 19 return gfx::PointF(vector.x(), vector.y());
19 } 20 }
20 21
21 // This takes a viewport-relative vector and returns a vector whose values are 22 // This takes a viewport-relative vector and returns a vector whose values are
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // where both anchor{x,y} and normalized{x,y} begin as unknowns. Solving 132 // where both anchor{x,y} and normalized{x,y} begin as unknowns. Solving
132 // for the normalized, we get the following formulas: 133 // for the normalized, we get the following formulas:
133 gfx::Vector2dF normalized; 134 gfx::Vector2dF normalized;
134 normalized.set_x((startRect.x() - targetRect.x()) / (targetRect.width() - st artRect.width())); 135 normalized.set_x((startRect.x() - targetRect.x()) / (targetRect.width() - st artRect.width()));
135 normalized.set_y((startRect.y() - targetRect.y()) / (targetRect.height() - s tartRect.height())); 136 normalized.set_y((startRect.y() - targetRect.y()) / (targetRect.height() - s tartRect.height()));
136 m_targetAnchor = m_targetScrollOffset + denormalizeToViewport(normalized, vi ewportSizeAtScale(m_targetPageScaleFactor)); 137 m_targetAnchor = m_targetScrollOffset + denormalizeToViewport(normalized, vi ewportSizeAtScale(m_targetPageScaleFactor));
137 } 138 }
138 139
139 void PageScaleAnimation::clampTargetScrollOffset() 140 void PageScaleAnimation::clampTargetScrollOffset()
140 { 141 {
141 gfx::Vector2dF maxScrollPosition; 142 gfx::Vector2dF maxScrollOffset = BottomRight(gfx::RectF(m_rootLayerSize)) - BottomRight(gfx::RectF(viewportSizeAtScale(m_targetPageScaleFactor)));
142 maxScrollPosition.set_x(m_rootLayerSize.width() - viewportSizeAtScale(m_targ etPageScaleFactor).width()); 143 m_targetScrollOffset.ClampToMin(gfx::Vector2dF());
143 maxScrollPosition.set_y(m_rootLayerSize.height() - viewportSizeAtScale(m_tar getPageScaleFactor).height()); 144 m_targetScrollOffset.ClampToMax(maxScrollOffset);
144 m_targetScrollOffset.set_x(std::max<float>(0, m_targetScrollOffset.x()));
145 m_targetScrollOffset.set_y(std::max<float>(0, m_targetScrollOffset.y()));
146 m_targetScrollOffset.set_x(std::min<float>(maxScrollPosition.x(), m_targetSc rollOffset.x()));
147 m_targetScrollOffset.set_y(std::min<float>(maxScrollPosition.y(), m_targetSc rollOffset.y()));
148 } 145 }
149 146
150 gfx::Vector2dF PageScaleAnimation::scrollOffsetAtTime(double time) const 147 gfx::Vector2dF PageScaleAnimation::scrollOffsetAtTime(double time) const
151 { 148 {
152 return scrollOffsetAt(interpAtTime(time)); 149 return scrollOffsetAt(interpAtTime(time));
153 } 150 }
154 151
155 float PageScaleAnimation::pageScaleFactorAtTime(double time) const 152 float PageScaleAnimation::pageScaleFactorAtTime(double time) const
156 { 153 {
157 return pageScaleFactorAt(interpAtTime(time)); 154 return pageScaleFactorAt(interpAtTime(time));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 209
213 // Linearly interpolate the magnitude in log scale. 210 // Linearly interpolate the magnitude in log scale.
214 float diff = m_targetPageScaleFactor / m_startPageScaleFactor; 211 float diff = m_targetPageScaleFactor / m_startPageScaleFactor;
215 float logDiff = log(diff); 212 float logDiff = log(diff);
216 logDiff *= interp; 213 logDiff *= interp;
217 diff = exp(logDiff); 214 diff = exp(logDiff);
218 return m_startPageScaleFactor * diff; 215 return m_startPageScaleFactor * diff;
219 } 216 }
220 217
221 } // namespace cc 218 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/tiled_layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698