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

Unified Diff: views/animation/screen_rotation.h

Issue 7273073: Animated Rotation (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Pulled unnecessary changes out of this CL Created 9 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: views/animation/screen_rotation.h
diff --git a/views/animation/screen_rotation.h b/views/animation/screen_rotation.h
new file mode 100644
index 0000000000000000000000000000000000000000..3833af1634838f0cfe580a1a5dc9990654e3b4e9
--- /dev/null
+++ b/views/animation/screen_rotation.h
@@ -0,0 +1,124 @@
+// Copyright (c) 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 VIEWS_ANIMATION_SCREEN_ROTATION_H_
+#define VIEWS_ANIMATION_SCREEN_ROTATION_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/task.h"
+#include "ui/base/animation/animation_delegate.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/size.h"
+
+namespace ui {
+class SlideAnimation;
+class InterpolatedTransform;
+class Layer;
+class Transform;
+}
+
+namespace views {
+
+class View;
+class ScreenRotation;
+
+// Classes that wish to be notified when a screen rotation completes must
+// implement the screen rotation listener interface.
+class ScreenRotationListener {
+ public:
+ virtual void OnScreenRotationCompleted(ScreenRotation* rotation) = 0;
+};
sky 2011/08/25 03:00:13 Add a virtual destructor and make it public. This
+
+// A screen rotation represents a single transition from one screen orientation
+// to another. The intended usage is that a new instance of the class is
+// created for every transition. It is possible to update the target orientation
+// in the middle of a transition.
+class ScreenRotation : public ui::AnimationDelegate {
sky 2011/08/25 03:00:13 These classes (ScreenRotation and ScreenRotationSe
+ public:
+ ScreenRotation(View* view, float old_degrees, float new_degrees);
+ virtual ~ScreenRotation();
+
+ ScreenRotationListener* listener() { return listener_; }
+ void set_listener(ScreenRotationListener* listener) { listener_ = listener; }
+
+ // Called after the animation is finished and the view has completed painting
+ // in its final state.
+ void Finalize();
+
+ // Use this function to change the target orientation mid animation. The
+ // currently running transition will complete at the same time as it was going
+ // to originally, but in a different orientation.
+ void UpdateTarget(float degrees);
sky 2011/08/25 03:00:13 nit: Name this SetTarget.
+
+ // True if the animation is complete and finalized.
+ bool done() const { return done_; }
+
+ private:
+ // Implementation of ui::AnimationDelegate
+ virtual void AnimationEnded(const ui::Animation* anim) OVERRIDE;
+ virtual void AnimationProgressed(const ui::Animation* anim) OVERRIDE;
+
+ // Initializes |interpolated_transform_|, |new_origin_|, |new_size_|, and
+ // (if it has not already been initialized) |old_transform_|
+ void Init();
+
+ // Initializes the screen rotation and starts |animation_|.
+ void Start();
+
+ // Converts degrees to an angle in the range [-180, 180).
+ int NormalizeAngle(int degrees);
+
+ // This is the view that will be animated. The animation will operate mainly
+ // on |view_|'s layer, but it is used upon completion of the rotation to
+ // update the bounds.
+ View* view_;
+
+ // A ScreenRotation may be associated with a listener that is notified when
+ // the screen rotation completes.
+ ScreenRotationListener* listener_;
+
+ // The initial transform of the layer (not updated by |UpdateTarget|).
+ scoped_ptr<ui::Transform> old_transform_;
+
+ // The animation object that instigates stepping of the animation.
+ scoped_ptr<ui::SlideAnimation> animation_;
+
+ // Generates the intermediate transformation matrices used during the
+ // animation.
+ scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;
+
+ // The original orientation (not updated by |UpdateTarget|.
+ float old_degrees_;
+
+ // The target orientation.
+ float new_degrees_;
+
+ // We keep track of the last step of the animation in case we change our
+ // target in the middle and have to create a new transition from last_t_ to 1
+ float last_t_;
+
+ // The target size for |view_|
+ gfx::Size new_size_;
+
+ // The target origin for |view_|
+ gfx::Point new_origin_;
+
+ // This is true if the rotation is completed and finalized.
+ bool done_;
+
+ // This is the duration of the transition in milliseconds
+ int duration_;
+
+ // This is used to post a task to update the bounds after the final call to
+ // SchedulePaint completes.
+ ScopedRunnableMethodFactory<ScreenRotation> method_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreenRotation);
+};
+
+} // namespace views
+
+#endif // VIEWS_ANIMATION_SCREEN_ROTATION_H_

Powered by Google App Engine
This is Rietveld 408576698