forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented screen rotation animation experiment.
This patch implements 2 different animations for when the screen orientation changes. These animations are still experimental and will be disabled by default. Depends on: https://codereview.chromium.org/983933002/ BUG=337596 Review URL: https://codereview.chromium.org/975943002 Cr-Commit-Position: refs/heads/master@{#320391}
- Loading branch information
1 parent
febbefc
commit 37f9cad
Showing
15 changed files
with
581 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2015 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. | ||
|
||
#include "ash/rotator/screen_rotation_animation.h" | ||
|
||
#include "base/time/time.h" | ||
#include "ui/compositor/layer.h" | ||
#include "ui/compositor/layer_animation_delegate.h" | ||
#include "ui/gfx/animation/tween.h" | ||
#include "ui/gfx/geometry/point.h" | ||
#include "ui/gfx/interpolated_transform.h" | ||
#include "ui/gfx/transform.h" | ||
|
||
namespace ash { | ||
|
||
ScreenRotationAnimation::ScreenRotationAnimation( | ||
ui::Layer* layer, | ||
int start_degrees, | ||
int end_degrees, | ||
float initial_opacity, | ||
float target_opacity, | ||
const gfx::Point3F& initial_scale, | ||
const gfx::Point3F& target_scale, | ||
gfx::Point pivot, | ||
base::TimeDelta duration, | ||
gfx::Tween::Type tween_type) | ||
: ui::LayerAnimationElement( | ||
LayerAnimationElement::TRANSFORM | LayerAnimationElement::OPACITY, | ||
duration), | ||
tween_type_(tween_type), | ||
initial_opacity_(initial_opacity), | ||
target_opacity_(target_opacity) { | ||
scoped_ptr<ui::InterpolatedTransform> scale( | ||
new ui::InterpolatedTransformAboutPivot( | ||
pivot, new ui::InterpolatedScale(initial_scale, target_scale))); | ||
|
||
scoped_ptr<ui::InterpolatedTransform> rotation( | ||
new ui::InterpolatedTransformAboutPivot( | ||
pivot, new ui::InterpolatedRotation(start_degrees, end_degrees))); | ||
|
||
// Use the target transform/bounds in case the layer is already animating. | ||
gfx::Transform current_transform = layer->GetTargetTransform(); | ||
interpolated_transform_.reset( | ||
new ui::InterpolatedConstantTransform(current_transform)); | ||
scale->SetChild(rotation.release()); | ||
interpolated_transform_->SetChild(scale.release()); | ||
} | ||
|
||
ScreenRotationAnimation::~ScreenRotationAnimation() { | ||
} | ||
|
||
void ScreenRotationAnimation::OnStart(ui::LayerAnimationDelegate* delegate) { | ||
} | ||
|
||
bool ScreenRotationAnimation::OnProgress(double current, | ||
ui::LayerAnimationDelegate* delegate) { | ||
const double tweened = gfx::Tween::CalculateValue(tween_type_, current); | ||
delegate->SetTransformFromAnimation( | ||
interpolated_transform_->Interpolate(tweened)); | ||
delegate->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween( | ||
tweened, initial_opacity_, target_opacity_)); | ||
return true; | ||
} | ||
|
||
void ScreenRotationAnimation::OnGetTarget(TargetValue* target) const { | ||
target->transform = interpolated_transform_->Interpolate(1.0); | ||
} | ||
|
||
void ScreenRotationAnimation::OnAbort(ui::LayerAnimationDelegate* delegate) { | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2015 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 ASH_ROTATOR_SCREEN_ROTATION_ANIMATION_H_ | ||
#define ASH_ROTATOR_SCREEN_ROTATION_ANIMATION_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include "ash/ash_export.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "base/time/time.h" | ||
#include "ui/compositor/layer_animation_element.h" | ||
#include "ui/gfx/animation/tween.h" | ||
#include "ui/gfx/geometry/point.h" | ||
#include "ui/gfx/geometry/point3_f.h" | ||
|
||
namespace ui { | ||
class InterpolatedTransform; | ||
class Layer; | ||
} | ||
|
||
namespace ash { | ||
|
||
// A LayerAnimationElement that will animate a layer by rotating it around a | ||
// pivot point. | ||
class ASH_EXPORT ScreenRotationAnimation : public ui::LayerAnimationElement { | ||
public: | ||
// Creates an animation element that will rotate |layer| from |start_degrees| | ||
// to |end_degrees| around the given |pivot|. The animation will take | ||
// |duration| amount of time and |layer| will be scaled as defined by the | ||
// |initial_scale| and |target_scale| values. | ||
ScreenRotationAnimation(ui::Layer* layer, | ||
int start_degrees, | ||
int end_degrees, | ||
float initial_opacity, | ||
float target_opacity, | ||
const gfx::Point3F& initial_scale, | ||
const gfx::Point3F& target_scale, | ||
gfx::Point pivot, | ||
base::TimeDelta duration, | ||
gfx::Tween::Type twen_type); | ||
~ScreenRotationAnimation() override; | ||
|
||
private: | ||
// Implementation of ui::LayerAnimationDelegate | ||
void OnStart(ui::LayerAnimationDelegate* delegate) override; | ||
bool OnProgress(double current, | ||
ui::LayerAnimationDelegate* delegate) override; | ||
void OnGetTarget(TargetValue* target) const override; | ||
void OnAbort(ui::LayerAnimationDelegate* delegate) override; | ||
|
||
// The root InterpolatedTransform that defines the animation. | ||
scoped_ptr<ui::InterpolatedTransform> interpolated_transform_; | ||
|
||
// The Tween type to use for the animation. | ||
gfx::Tween::Type tween_type_; | ||
|
||
// The initial layer opacity to start the animation with. | ||
float initial_opacity_; | ||
|
||
// The target layer opacity to end the animation with. | ||
float target_opacity_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimation); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATION_H_ |
Oops, something went wrong.