summaryrefslogtreecommitdiffstats
path: root/cc/input/page_scale_animation.h
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 07:41:21 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 07:41:21 +0000
commit3052b10f18b49c24c05cec21be0d901189a9b487 (patch)
tree951c8347b53f393768ac63621149b94dabf08fa8 /cc/input/page_scale_animation.h
parent8ba4bbe268033b0534b00a4261f092e1bbe31190 (diff)
downloadchromium_src-3052b10f18b49c24c05cec21be0d901189a9b487.zip
chromium_src-3052b10f18b49c24c05cec21be0d901189a9b487.tar.gz
chromium_src-3052b10f18b49c24c05cec21be0d901189a9b487.tar.bz2
Part 5 of cc/ directory shuffles: input
Continuation of https://src.chromium.org/viewvc/chrome?view=rev&revision=188681 BUG=190824 TBR=piman@chromium.org, enne@chromium.org Review URL: https://codereview.chromium.org/12722006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188691 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/input/page_scale_animation.h')
-rw-r--r--cc/input/page_scale_animation.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/cc/input/page_scale_animation.h b/cc/input/page_scale_animation.h
new file mode 100644
index 0000000..09fbd15
--- /dev/null
+++ b/cc/input/page_scale_animation.h
@@ -0,0 +1,104 @@
+// Copyright 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_INPUT_PAGE_SCALE_ANIMATION_H_
+#define CC_INPUT_PAGE_SCALE_ANIMATION_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/gfx/size.h"
+#include "ui/gfx/vector2d_f.h"
+
+namespace cc {
+
+// A small helper class that does the math for zoom animations, primarily for
+// double-tap zoom. Initialize it with starting and ending scroll/page scale
+// positions and an animation length time, then call ...AtTime() at every frame
+// to obtain the current interpolated position.
+//
+// All sizes and vectors in this class's public methods are in the root scroll
+// layer's coordinate space.
+class PageScaleAnimation {
+ public:
+ // Construct with the state at the beginning of the animation.
+ static scoped_ptr<PageScaleAnimation> Create(
+ gfx::Vector2dF start_scroll_offset,
+ float start_page_scale_factor,
+ gfx::SizeF viewport_size,
+ gfx::SizeF root_layer_size,
+ double start_time);
+
+ ~PageScaleAnimation();
+
+ // The following methods initialize the animation. Call one of them
+ // immediately after construction to set the final scroll and page scale.
+
+ // Zoom while explicitly specifying the top-left scroll position.
+ void ZoomTo(gfx::Vector2dF target_scroll_offset,
+ float target_page_scale_factor,
+ double duration);
+
+ // Zoom based on a specified anchor. The animator will attempt to keep it
+ // at the same position on the physical display throughout the animation,
+ // unless the edges of the root layer are hit. The anchor is specified
+ // as an offset from the content layer.
+ void ZoomWithAnchor(gfx::Vector2dF anchor,
+ float target_page_scale_factor,
+ double duration);
+
+ // Call these functions while the animation is in progress to output the
+ // current state.
+ gfx::Vector2dF ScrollOffsetAtTime(double time) const;
+ float PageScaleFactorAtTime(double time) const;
+ bool IsAnimationCompleteAtTime(double time) const;
+
+ // The following methods return state which is invariant throughout the
+ // course of the animation.
+ double start_time() const { return start_time_; }
+ double duration() const { return duration_; }
+ double end_time() const { return start_time_ + duration_; }
+ gfx::Vector2dF target_scroll_offset() const { return target_scroll_offset_; }
+ float target_page_scale_factor() const { return target_page_scale_factor_; }
+
+ protected:
+ PageScaleAnimation(gfx::Vector2dF start_scroll_offset,
+ float start_page_scale_factor,
+ gfx::SizeF viewport_size,
+ gfx::SizeF root_layer_size,
+ double start_time);
+
+ private:
+ void ClampTargetScrollOffset();
+ void InferTargetScrollOffsetFromStartAnchor();
+ void InferTargetAnchorFromScrollOffsets();
+
+ gfx::SizeF StartViewportSize() const;
+ gfx::SizeF TargetViewportSize() const;
+ float InterpAtTime(double time) const;
+ gfx::SizeF ViewportSizeAt(float interp) const;
+ gfx::Vector2dF ScrollOffsetAt(float interp) const;
+ gfx::Vector2dF AnchorAt(float interp) const;
+ gfx::Vector2dF ViewportRelativeAnchorAt(float interp) const;
+ float PageScaleFactorAt(float interp) const;
+
+ float start_page_scale_factor_;
+ float target_page_scale_factor_;
+ gfx::Vector2dF start_scroll_offset_;
+ gfx::Vector2dF target_scroll_offset_;
+
+ gfx::Vector2dF start_anchor_;
+ gfx::Vector2dF target_anchor_;
+
+ gfx::SizeF viewport_size_;
+ gfx::SizeF root_layer_size_;
+
+ double start_time_;
+ double duration_;
+
+ DISALLOW_COPY_AND_ASSIGN(PageScaleAnimation);
+};
+
+} // namespace cc
+
+#endif // CC_INPUT_PAGE_SCALE_ANIMATION_H_