summaryrefslogtreecommitdiffstats
path: root/cc/page_scale_animation.cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-05 16:56:49 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-05 16:56:49 +0000
commitec454716d4056ddc796788b0cab45ec99b16113b (patch)
treec12de89ddf61012d1d5eb7f8c8573773a9215f5a /cc/page_scale_animation.cc
parent992359d7cb13821cbc9cbf76d3e870860dea760d (diff)
downloadchromium_src-ec454716d4056ddc796788b0cab45ec99b16113b.zip
chromium_src-ec454716d4056ddc796788b0cab45ec99b16113b.tar.gz
chromium_src-ec454716d4056ddc796788b0cab45ec99b16113b.tar.bz2
cc: Remove all remaining use of WebCore Rect/Point/Size types from the compositor.
This change removes all IntPoint/FloatRect/IntSize/etc from the compositor. There remains an indirect dependency on these types through the WebCore::Region class, which we wrap but need to replace. However, the wrapper there hides the WebCore types inside it, so there are now no references to the types from anywhere else in the compositor. I went back and forth on how to deal with scroll "positions". The name suggested that they should be Points, and that the deltas should be Vectors. However this lent itself to super awkward math at times. In the end, it was much cleaner to make all scroll "positions" into scroll "offsets" and represent everything as Vectors. Covered by existing tests; no change in behaviour. R=enne BUG=147395 Review URL: https://codereview.chromium.org/11367080 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165947 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/page_scale_animation.cc')
-rw-r--r--cc/page_scale_animation.cc56
1 files changed, 28 insertions, 28 deletions
diff --git a/cc/page_scale_animation.cc b/cc/page_scale_animation.cc
index 59424d4..49948ab 100644
--- a/cc/page_scale_animation.cc
+++ b/cc/page_scale_animation.cc
@@ -6,22 +6,21 @@
#include "cc/page_scale_animation.h"
-#include "FloatPoint.h"
-#include "FloatSize.h"
-#include "IntPoint.h"
-#include "IntSize.h"
+#include "cc/geometry.h"
#include "ui/gfx/rect_f.h"
+#include "ui/gfx/vector2d_conversions.h"
+#include "ui/gfx/vector2d_f.h"
#include <math.h>
namespace cc {
-scoped_ptr<PageScaleAnimation> PageScaleAnimation::create(const IntSize& scrollStart, float pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, double startTime)
+scoped_ptr<PageScaleAnimation> PageScaleAnimation::create(gfx::Vector2d scrollStart, float pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, double startTime)
{
return make_scoped_ptr(new PageScaleAnimation(scrollStart, pageScaleStart, windowSize, contentSize, startTime));
}
-PageScaleAnimation::PageScaleAnimation(const IntSize& scrollStart, float pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, double startTime)
+PageScaleAnimation::PageScaleAnimation(gfx::Vector2d scrollStart, float pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, double startTime)
: m_scrollStart(scrollStart)
, m_pageScaleStart(pageScaleStart)
, m_windowSize(windowSize)
@@ -38,13 +37,13 @@ PageScaleAnimation::~PageScaleAnimation()
{
}
-void PageScaleAnimation::zoomTo(const IntSize& finalScroll, float finalPageScale, double duration)
+void PageScaleAnimation::zoomTo(gfx::Vector2d finalScroll, float finalPageScale, double duration)
{
if (m_pageScaleStart != finalPageScale) {
// For uniform-looking zooming, infer the anchor (point that remains in
// place throughout the zoom) from the start and end rects.
- gfx::RectF startRect(cc::FloatPoint(cc::IntPoint(m_scrollStart)), m_windowSize);
- gfx::RectF endRect(cc::FloatPoint(cc::IntPoint(finalScroll)), m_windowSize);
+ gfx::RectF startRect(gfx::PointAtOffsetFromOrigin(m_scrollStart), m_windowSize);
+ gfx::RectF endRect(gfx::PointAtOffsetFromOrigin(finalScroll), m_windowSize);
endRect.Scale(m_pageScaleStart / finalPageScale);
// The anchor is the point which is at the same ratio of the sides of
@@ -61,7 +60,7 @@ void PageScaleAnimation::zoomTo(const IntSize& finalScroll, float finalPageScale
float ratioX = (startRect.x() - endRect.x()) / (endRect.width() - startRect.width());
float ratioY = (startRect.y() - endRect.y()) / (endRect.height() - startRect.height());
- IntSize anchor(m_windowSize.width() * ratioX, m_windowSize.height() * ratioY);
+ gfx::Vector2d anchor(m_windowSize.width() * ratioX, m_windowSize.height() * ratioY);
zoomWithAnchor(anchor, finalPageScale, duration);
} else {
// If this is a pure translation, then there exists no anchor. Linearly
@@ -73,16 +72,17 @@ void PageScaleAnimation::zoomTo(const IntSize& finalScroll, float finalPageScale
}
}
-void PageScaleAnimation::zoomWithAnchor(const IntSize& anchor, float finalPageScale, double duration)
+void PageScaleAnimation::zoomWithAnchor(gfx::Vector2d anchor, float finalPageScale, double duration)
{
m_scrollEnd = m_scrollStart + anchor;
- m_scrollEnd.scale(finalPageScale / m_pageScaleStart);
+ m_scrollEnd = gfx::ToFlooredVector2d(cc::ScaleVector2d(m_scrollEnd, finalPageScale / m_pageScaleStart));
m_scrollEnd -= anchor;
- m_scrollEnd.clampNegativeToZero();
+ m_scrollEnd = ClampFromBelow(m_scrollEnd, gfx::Vector2d());
gfx::SizeF scaledContentSize = m_contentSize.Scale(finalPageScale / m_pageScaleStart);
- IntSize maxScrollPosition = roundedIntSize(cc::FloatSize(scaledContentSize) - cc::IntSize(m_windowSize));
- m_scrollEnd = m_scrollEnd.shrunkTo(maxScrollPosition);
+ gfx::Vector2d maxScrollOffset = gfx::ToRoundedVector2d(BottomRight(gfx::RectF(scaledContentSize)) - BottomRight(gfx::Rect(m_windowSize)));
+ m_scrollEnd = m_scrollEnd;
+ m_scrollEnd = ClampFromAbove(m_scrollEnd, maxScrollOffset);
m_anchor = anchor;
m_pageScaleEnd = finalPageScale;
@@ -90,7 +90,7 @@ void PageScaleAnimation::zoomWithAnchor(const IntSize& anchor, float finalPageSc
m_anchorMode = true;
}
-IntSize PageScaleAnimation::scrollOffsetAtTime(double time) const
+gfx::Vector2d PageScaleAnimation::scrollOffsetAtTime(double time) const
{
return scrollOffsetAtRatio(progressRatioForTime(time));
}
@@ -113,7 +113,7 @@ float PageScaleAnimation::progressRatioForTime(double time) const
return (time - m_startTime) / m_duration;
}
-IntSize PageScaleAnimation::scrollOffsetAtRatio(float ratio) const
+gfx::Vector2d PageScaleAnimation::scrollOffsetAtRatio(float ratio) const
{
if (ratio <= 0)
return m_scrollStart;
@@ -121,23 +121,23 @@ IntSize PageScaleAnimation::scrollOffsetAtRatio(float ratio) const
return m_scrollEnd;
float currentPageScale = pageScaleAtRatio(ratio);
- IntSize currentScrollOffset;
+ gfx::Vector2d currentScrollOffset;
if (m_anchorMode) {
// Keep the anchor stable on the screen at the current scale.
- IntSize documentAnchor = m_scrollStart + m_anchor;
- documentAnchor.scale(currentPageScale / m_pageScaleStart);
- currentScrollOffset = documentAnchor - m_anchor;
+ gfx::Vector2dF documentAnchor = m_scrollStart + m_anchor;
+ documentAnchor.Scale(currentPageScale / m_pageScaleStart);
+ currentScrollOffset = gfx::ToRoundedVector2d(documentAnchor - m_anchor);
} else {
// First move both scroll offsets to the current coordinate space.
- FloatSize scaledStartScroll(m_scrollStart);
- scaledStartScroll.scale(currentPageScale / m_pageScaleStart);
- FloatSize scaledEndScroll(m_scrollEnd);
- scaledEndScroll.scale(currentPageScale / m_pageScaleEnd);
+ gfx::Vector2dF scaledStartScroll(m_scrollStart);
+ scaledStartScroll.Scale(currentPageScale / m_pageScaleStart);
+ gfx::Vector2dF scaledEndScroll(m_scrollEnd);
+ scaledEndScroll.Scale(currentPageScale / m_pageScaleEnd);
// Linearly interpolate between them.
- FloatSize delta = scaledEndScroll - scaledStartScroll;
- delta.scale(ratio);
- currentScrollOffset = roundedIntSize(scaledStartScroll + delta);
+ gfx::Vector2dF delta = scaledEndScroll - scaledStartScroll;
+ delta.Scale(ratio);
+ currentScrollOffset = gfx::ToRoundedVector2d(scaledStartScroll + delta);
}
return currentScrollOffset;