Chromium Code Reviews| Index: chrome/browser/ui/touch/animation/screen_rotation.h |
| diff --git a/chrome/browser/ui/touch/animation/screen_rotation.h b/chrome/browser/ui/touch/animation/screen_rotation.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ce67eae9678268250138ab48f1e324767ccff41f |
| --- /dev/null |
| +++ b/chrome/browser/ui/touch/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 CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_ |
| +#define CHROME_BROWSER_UI_TOUCH_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; |
|
sky
2011/08/25 21:10:12
nit: sort these
|
| +class InterpolatedTransform; |
| +class Layer; |
| +class Transform; |
| +} |
| + |
| +namespace gfx { |
| +class Rect; |
| +} |
| + |
| +namespace views { |
| +class View; |
| +class PaintLock; |
| +} |
| + |
| +// Classes that wish to be notified when a screen rotation completes must |
| +// implement the screen rotation listener interface. |
| +class ScreenRotationListenerInterface { |
|
sky
2011/08/25 21:10:12
Nuke the interface, eg ScreenRotationListener, or
|
| + public: |
| + virtual void OnScreenRotationCompleted(const ui::Transform& target_transform, |
| + const gfx::Rect& target_bounds) = 0; |
| + virtual ~ScreenRotationListenerInterface(); |
| +}; |
|
sky
2011/08/25 21:10:12
Add a virtual protected destructor
|
| + |
| +// 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 { |
| + public: |
| + // The screen rotation does not own the view or the listener, and these |
| + // objects are required to outlive the Screen rotation object. |
| + ScreenRotation(views::View* view, |
| + ScreenRotationListenerInterface* listener, |
| + float old_degrees, |
| + float new_degrees); |
| + virtual ~ScreenRotation(); |
| + |
| + // Initializes the screen rotation and starts |animation_|. |
| + void Start(); |
| + |
| + // 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 SetTarget(float degrees); |
| + |
| + 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(); |
| + |
| + // 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. |
| + views::View* view_; |
| + |
| + // A ScreenRotation may be associated with a listener that is notified when |
| + // the screen rotation completes. |
| + ScreenRotationListenerInterface* listener_; |
| + |
| + // 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_; |
| + |
| + // Ensures that the view is not repainted during the screen rotation. |
| + scoped_ptr<views::PaintLock> paint_lock_; |
| + |
| + // The original orientation (not updated by |SetTarget|. |
| + 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 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); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_ |