| 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 | 8 |
| 9 #include "FloatRect.h" | 9 #include "FloatPoint.h" |
| 10 #include "FloatSize.h" | 10 #include "FloatSize.h" |
| 11 #include "IntPoint.h" |
| 12 #include "IntSize.h" |
| 13 #include "ui/gfx/rect_f.h" |
| 11 | 14 |
| 12 #include <math.h> | 15 #include <math.h> |
| 13 | 16 |
| 14 namespace cc { | 17 namespace cc { |
| 15 | 18 |
| 16 scoped_ptr<PageScaleAnimation> PageScaleAnimation::create(const IntSize& scrollS
tart, float pageScaleStart, const IntSize& windowSize, const IntSize& contentSiz
e, double startTime) | 19 scoped_ptr<PageScaleAnimation> PageScaleAnimation::create(const IntSize& scrollS
tart, float pageScaleStart, const gfx::Size& windowSize, const gfx::Size& conten
tSize, double startTime) |
| 17 { | 20 { |
| 18 return make_scoped_ptr(new PageScaleAnimation(scrollStart, pageScaleStart, w
indowSize, contentSize, startTime)); | 21 return make_scoped_ptr(new PageScaleAnimation(scrollStart, pageScaleStart, w
indowSize, contentSize, startTime)); |
| 19 } | 22 } |
| 20 | 23 |
| 21 PageScaleAnimation::PageScaleAnimation(const IntSize& scrollStart, float pageSca
leStart, const IntSize& windowSize, const IntSize& contentSize, double startTime
) | 24 PageScaleAnimation::PageScaleAnimation(const IntSize& scrollStart, float pageSca
leStart, const gfx::Size& windowSize, const gfx::Size& contentSize, double start
Time) |
| 22 : m_scrollStart(scrollStart) | 25 : m_scrollStart(scrollStart) |
| 23 , m_pageScaleStart(pageScaleStart) | 26 , m_pageScaleStart(pageScaleStart) |
| 24 , m_windowSize(windowSize) | 27 , m_windowSize(windowSize) |
| 25 , m_contentSize(contentSize) | 28 , m_contentSize(contentSize) |
| 26 , m_anchorMode(false) | 29 , m_anchorMode(false) |
| 27 , m_scrollEnd(scrollStart) | 30 , m_scrollEnd(scrollStart) |
| 28 , m_pageScaleEnd(pageScaleStart) | 31 , m_pageScaleEnd(pageScaleStart) |
| 29 , m_startTime(startTime) | 32 , m_startTime(startTime) |
| 30 , m_duration(0) | 33 , m_duration(0) |
| 31 { | 34 { |
| 32 } | 35 } |
| 33 | 36 |
| 37 PageScaleAnimation::~PageScaleAnimation() |
| 38 { |
| 39 } |
| 40 |
| 34 void PageScaleAnimation::zoomTo(const IntSize& finalScroll, float finalPageScale
, double duration) | 41 void PageScaleAnimation::zoomTo(const IntSize& finalScroll, float finalPageScale
, double duration) |
| 35 { | 42 { |
| 36 if (m_pageScaleStart != finalPageScale) { | 43 if (m_pageScaleStart != finalPageScale) { |
| 37 // For uniform-looking zooming, infer the anchor (point that remains in | 44 // For uniform-looking zooming, infer the anchor (point that remains in |
| 38 // place throughout the zoom) from the start and end rects. | 45 // place throughout the zoom) from the start and end rects. |
| 39 FloatRect startRect(IntPoint(m_scrollStart), m_windowSize); | 46 gfx::RectF startRect(cc::FloatPoint(cc::IntPoint(m_scrollStart)), m_wind
owSize); |
| 40 FloatRect endRect(IntPoint(finalScroll), m_windowSize); | 47 gfx::RectF endRect(cc::FloatPoint(cc::IntPoint(finalScroll)), m_windowSi
ze); |
| 41 endRect.scale(m_pageScaleStart / finalPageScale); | 48 endRect.Scale(m_pageScaleStart / finalPageScale); |
| 42 | 49 |
| 43 // The anchor is the point which is at the same ratio of the sides of | 50 // The anchor is the point which is at the same ratio of the sides of |
| 44 // both startRect and endRect. For example, a zoom-in double-tap to a | 51 // both startRect and endRect. For example, a zoom-in double-tap to a |
| 45 // perfectly centered rect will have anchor ratios (0.5, 0.5), while one | 52 // perfectly centered rect will have anchor ratios (0.5, 0.5), while one |
| 46 // to a rect touching the bottom-right of the screen will have anchor | 53 // to a rect touching the bottom-right of the screen will have anchor |
| 47 // ratios (1.0, 1.0). In other words, it obeys the equations: | 54 // ratios (1.0, 1.0). In other words, it obeys the equations: |
| 48 // anchorX = start_width * ratioX + start_x | 55 // anchorX = start_width * ratioX + start_x |
| 49 // anchorX = end_width * ratioX + end_x | 56 // anchorX = end_width * ratioX + end_x |
| 50 // anchorY = start_height * ratioY + start_y | 57 // anchorY = start_height * ratioY + start_y |
| 51 // anchorY = end_height * ratioY + end_y | 58 // anchorY = end_height * ratioY + end_y |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 } | 73 } |
| 67 } | 74 } |
| 68 | 75 |
| 69 void PageScaleAnimation::zoomWithAnchor(const IntSize& anchor, float finalPageSc
ale, double duration) | 76 void PageScaleAnimation::zoomWithAnchor(const IntSize& anchor, float finalPageSc
ale, double duration) |
| 70 { | 77 { |
| 71 m_scrollEnd = m_scrollStart + anchor; | 78 m_scrollEnd = m_scrollStart + anchor; |
| 72 m_scrollEnd.scale(finalPageScale / m_pageScaleStart); | 79 m_scrollEnd.scale(finalPageScale / m_pageScaleStart); |
| 73 m_scrollEnd -= anchor; | 80 m_scrollEnd -= anchor; |
| 74 | 81 |
| 75 m_scrollEnd.clampNegativeToZero(); | 82 m_scrollEnd.clampNegativeToZero(); |
| 76 FloatSize scaledContentSize(m_contentSize); | 83 gfx::SizeF scaledContentSize = m_contentSize.Scale(finalPageScale / m_pageSc
aleStart); |
| 77 scaledContentSize.scale(finalPageScale / m_pageScaleStart); | 84 IntSize maxScrollPosition = roundedIntSize(cc::FloatSize(scaledContentSize)
- cc::IntSize(m_windowSize)); |
| 78 IntSize maxScrollPosition = roundedIntSize(scaledContentSize - m_windowSize)
; | |
| 79 m_scrollEnd = m_scrollEnd.shrunkTo(maxScrollPosition); | 85 m_scrollEnd = m_scrollEnd.shrunkTo(maxScrollPosition); |
| 80 | 86 |
| 81 m_anchor = anchor; | 87 m_anchor = anchor; |
| 82 m_pageScaleEnd = finalPageScale; | 88 m_pageScaleEnd = finalPageScale; |
| 83 m_duration = duration; | 89 m_duration = duration; |
| 84 m_anchorMode = true; | 90 m_anchorMode = true; |
| 85 } | 91 } |
| 86 | 92 |
| 87 IntSize PageScaleAnimation::scrollOffsetAtTime(double time) const | 93 IntSize PageScaleAnimation::scrollOffsetAtTime(double time) const |
| 88 { | 94 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // example, if we zoom from 0.5 to 4.0 in 3 seconds, then we should | 155 // example, if we zoom from 0.5 to 4.0 in 3 seconds, then we should |
| 150 // be zooming by 2x every second. | 156 // be zooming by 2x every second. |
| 151 float diff = m_pageScaleEnd / m_pageScaleStart; | 157 float diff = m_pageScaleEnd / m_pageScaleStart; |
| 152 float logDiff = log(diff); | 158 float logDiff = log(diff); |
| 153 logDiff *= ratio; | 159 logDiff *= ratio; |
| 154 diff = exp(logDiff); | 160 diff = exp(logDiff); |
| 155 return m_pageScaleStart * diff; | 161 return m_pageScaleStart * diff; |
| 156 } | 162 } |
| 157 | 163 |
| 158 } // namespace cc | 164 } // namespace cc |
| OLD | NEW |