summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-07 19:26:30 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-07 19:26:30 +0000
commit2ddfe43ba403bd2272154b2307e631d7394b55c3 (patch)
treeb736178f711282c82a5b28f5ff47990dd90b79fe /ui
parent554890fecb9712a3e7a99c5c82ca5b3d4f06f0d5 (diff)
downloadchromium_src-2ddfe43ba403bd2272154b2307e631d7394b55c3.zip
chromium_src-2ddfe43ba403bd2272154b2307e631d7394b55c3.tar.gz
chromium_src-2ddfe43ba403bd2272154b2307e631d7394b55c3.tar.bz2
Reenable triggering of screen rotations by sensors.
Depends on http://codereview.chromium.org/8395046 BUG=None TEST=Visiting about:rotate?right, about:rotate?left, etc. should cause the appropriate screen rotations. Review URL: http://codereview.chromium.org/8402002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108889 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/desktop.cc76
-rw-r--r--ui/gfx/compositor/compositor.gyp2
-rw-r--r--ui/gfx/compositor/layer_animator.cc5
-rw-r--r--ui/gfx/compositor/screen_rotation.cc (renamed from ui/aura/screen_rotation.cc)40
-rw-r--r--ui/gfx/compositor/screen_rotation.h (renamed from ui/aura/screen_rotation.h)24
6 files changed, 67 insertions, 82 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index d012a80..1149373 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -45,8 +45,6 @@
'layout_manager.h',
'screen_aura.cc',
'screen_aura.h',
- 'screen_rotation.cc',
- 'screen_rotation.h',
'toplevel_window_container.cc',
'toplevel_window_container.h',
'toplevel_window_event_filter.cc',
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index 07edd11..4b16a0a 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -21,7 +21,6 @@
#include "ui/aura/event_filter.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/screen_aura.h"
-#include "ui/aura/screen_rotation.h"
#include "ui/aura/toplevel_window_container.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
@@ -29,6 +28,7 @@
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
#include "ui/gfx/compositor/layer_animator.h"
+#include "ui/gfx/compositor/screen_rotation.h"
#include "ui/gfx/interpolated_transform.h"
using std::string;
@@ -44,22 +44,6 @@ static const int kDefaultHostWindowY = 200;
static const int kDefaultHostWindowWidth = 1280;
static const int kDefaultHostWindowHeight = 1024;
-#if !defined(NDEBUG)
-// Converts degrees to an angle in the range [-180, 180).
-int NormalizeAngle(int degrees) {
- while (degrees <= -180) degrees += 360;
- while (degrees > 180) degrees -= 360;
- return degrees;
-}
-
-static int SymmetricRound(float x) {
- return static_cast<int>(
- x > 0
- ? std::floor(x + 0.5f)
- : std::ceil(x - 0.5f));
-}
-#endif
-
class DefaultDesktopDelegate : public DesktopDelegate {
public:
explicit DefaultDesktopDelegate(Desktop* desktop) : desktop_(desktop) {}
@@ -168,37 +152,35 @@ bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) {
}
bool MaybeRotate(Desktop* desktop, KeyEvent* event) {
- if ((event->flags() & ui::EF_SHIFT_DOWN) &&
- (event->flags() & ui::EF_ALT_DOWN)) {
- bool should_rotate = true;
- int new_degrees = 0;
- switch (event->key_code()) {
- case ui::VKEY_UP: new_degrees = 0; break;
- case ui::VKEY_DOWN: new_degrees = 180; break;
- case ui::VKEY_RIGHT: new_degrees = 90; break;
- case ui::VKEY_LEFT: new_degrees = -90; break;
- default: should_rotate = false; break;
- }
-
- if (should_rotate) {
- float rotation = 0.0f;
- int degrees = 0;
- const ui::Transform& transform = desktop->layer()->GetTargetTransform();
- if (ui::InterpolatedTransform::FactorTRS(transform,
- NULL, &rotation, NULL))
- degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation));
-
- if (degrees != 0) {
- desktop->layer()->GetAnimator()->set_preemption_strategy(
- ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
- scoped_ptr<ui::LayerAnimationSequence> screen_rotation(
- new ui::LayerAnimationSequence(new ScreenRotation(degrees)));
- screen_rotation->AddObserver(desktop);
- desktop->layer()->GetAnimator()->ScheduleAnimation(
- screen_rotation.release());
- return true;
- }
+ if ((event->flags() & ui::EF_CONTROL_DOWN) &&
+ event->key_code() == ui::VKEY_HOME) {
+ static int i = 0;
+ int delta = 0;
+ switch (i) {
+ case 0: delta = 90; break;
+ case 1: delta = 90; break;
+ case 2: delta = 90; break;
+ case 3: delta = 90; break;
+ case 4: delta = -90; break;
+ case 5: delta = -90; break;
+ case 6: delta = -90; break;
+ case 7: delta = -90; break;
+ case 8: delta = -90; break;
+ case 9: delta = 180; break;
+ case 10: delta = 180; break;
+ case 11: delta = 90; break;
+ case 12: delta = 180; break;
+ case 13: delta = 180; break;
}
+ i = (i + 1) % 14;
+ desktop->layer()->GetAnimator()->set_preemption_strategy(
+ ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
+ scoped_ptr<ui::LayerAnimationSequence> screen_rotation(
+ new ui::LayerAnimationSequence(new ui::ScreenRotation(delta)));
+ screen_rotation->AddObserver(desktop);
+ desktop->layer()->GetAnimator()->ScheduleAnimation(
+ screen_rotation.release());
+ return true;
}
return false;
}
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index 9fa4201..c98aab4 100644
--- a/ui/gfx/compositor/compositor.gyp
+++ b/ui/gfx/compositor/compositor.gyp
@@ -57,6 +57,8 @@
'layer_animation_sequence.h',
'layer_animator.cc',
'layer_animator.h',
+ 'screen_rotation.cc',
+ 'screen_rotation.h',
],
'conditions': [
['os_posix == 1 and OS != "mac"', {
diff --git a/ui/gfx/compositor/layer_animator.cc b/ui/gfx/compositor/layer_animator.cc
index 7bc9698..588231c 100644
--- a/ui/gfx/compositor/layer_animator.cc
+++ b/ui/gfx/compositor/layer_animator.cc
@@ -304,8 +304,9 @@ void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) {
}
void LayerAnimator::FinishAnyAnimationWithZeroDuration() {
- // We need to make a copy because Progress may indirectly cause new animations
- // to start running.
+ // Special case: if we've started a 0 duration animation, just finish it now
+ // and get rid of it. We need to make a copy because Progress may indirectly
+ // cause new animations to start running.
RunningAnimations running_animations_copy = running_animations_;
for (size_t i = 0; i < running_animations_copy.size(); ++i) {
if (running_animations_copy[i].sequence->duration() == base::TimeDelta()) {
diff --git a/ui/aura/screen_rotation.cc b/ui/gfx/compositor/screen_rotation.cc
index 6b46817..df399e2 100644
--- a/ui/aura/screen_rotation.cc
+++ b/ui/gfx/compositor/screen_rotation.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/aura/screen_rotation.h"
+#include "ui/gfx/compositor/screen_rotation.h"
#include "base/debug/trace_event.h"
#include "base/time.h"
@@ -11,6 +11,8 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
+namespace ui {
+
namespace {
const int k90DegreeTransitionDurationMs = 350;
@@ -27,22 +29,19 @@ base::TimeDelta GetTransitionDuration(int degrees) {
} // namespace
ScreenRotation::ScreenRotation(int degrees)
- : ui::LayerAnimationElement(GetProperties(),
- GetTransitionDuration(degrees)),
+ : LayerAnimationElement(GetProperties(), GetTransitionDuration(degrees)),
degrees_(degrees) {
}
ScreenRotation::~ScreenRotation() {
}
-void ScreenRotation::OnStart(ui::LayerAnimationDelegate* delegate) {
- //TRACE_EVENT0("ScreenRotation", "init");
-
+void ScreenRotation::OnStart(LayerAnimationDelegate* delegate) {
// No rotation required.
if (degrees_ == 0)
return;
- const ui::Transform& current_transform = delegate->GetTransformForAnimation();
+ const Transform& current_transform = delegate->GetTransformForAnimation();
const gfx::Rect& bounds = delegate->GetBoundsForAnimation();
gfx::Point old_pivot;
@@ -69,26 +68,26 @@ void ScreenRotation::OnStart(ui::LayerAnimationDelegate* delegate) {
current_transform.TransformPoint(new_pivot);
current_transform.TransformPoint(new_origin_);
- scoped_ptr<ui::InterpolatedTransform> rotation(
- new ui::InterpolatedTransformAboutPivot(
+ scoped_ptr<InterpolatedTransform> rotation(
+ new InterpolatedTransformAboutPivot(
old_pivot,
- new ui::InterpolatedRotation(0, degrees_)));
+ new InterpolatedRotation(0, degrees_)));
- scoped_ptr<ui::InterpolatedTransform> translation(
- new ui::InterpolatedTranslation(
+ scoped_ptr<InterpolatedTransform> translation(
+ new InterpolatedTranslation(
gfx::Point(0, 0),
gfx::Point(new_pivot.x() - old_pivot.x(),
new_pivot.y() - old_pivot.y())));
float scale_factor = 0.9f;
- scoped_ptr<ui::InterpolatedTransform> scale_down(
- new ui::InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f));
+ scoped_ptr<InterpolatedTransform> scale_down(
+ new InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f));
- scoped_ptr<ui::InterpolatedTransform> scale_up(
- new ui::InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f));
+ scoped_ptr<InterpolatedTransform> scale_up(
+ new InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f));
interpolated_transform_.reset(
- new ui::InterpolatedConstantTransform(current_transform));
+ new InterpolatedConstantTransform(current_transform));
scale_up->SetChild(scale_down.release());
translation->SetChild(scale_up.release());
@@ -97,8 +96,7 @@ void ScreenRotation::OnStart(ui::LayerAnimationDelegate* delegate) {
}
void ScreenRotation::OnProgress(double t,
- ui::LayerAnimationDelegate* delegate) {
- //TRACE_EVENT0("ScreenRotation", "Progress");
+ LayerAnimationDelegate* delegate) {
delegate->SetTransformFromAnimation(interpolated_transform_->Interpolate(t));
delegate->ScheduleDrawForAnimation();
}
@@ -111,10 +109,12 @@ void ScreenRotation::OnAbort() {
}
// static
-const ui::LayerAnimationElement::AnimatableProperties&
+const LayerAnimationElement::AnimatableProperties&
ScreenRotation::GetProperties() {
static LayerAnimationElement::AnimatableProperties properties;
if (properties.empty())
properties.insert(LayerAnimationElement::TRANSFORM);
return properties;
}
+
+} // namespace ui
diff --git a/ui/aura/screen_rotation.h b/ui/gfx/compositor/screen_rotation.h
index e947b83..1d95a5d 100644
--- a/ui/aura/screen_rotation.h
+++ b/ui/gfx/compositor/screen_rotation.h
@@ -2,26 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_AURA_SCREEN_ROTATION_H_
-#define UI_AURA_SCREEN_ROTATION_H_
+#ifndef UI_GFX_COMPOSITOR_SCREEN_ROTATION_H_
+#define UI_GFX_COMPOSITOR_SCREEN_ROTATION_H_
#pragma once
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/base/animation/animation_delegate.h"
+#include "ui/gfx/compositor/compositor_export.h"
#include "ui/gfx/compositor/layer_animation_element.h"
#include "ui/gfx/point.h"
namespace ui {
class InterpolatedTransform;
class LayerAnimationDelegate;
-}
// 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::LayerAnimationElement {
+class COMPOSITOR_EXPORT ScreenRotation : public LayerAnimationElement {
public:
// The screen rotation does not own the view or the listener, and these
// objects are required to outlive the Screen rotation object.
@@ -29,26 +29,28 @@ class ScreenRotation : public ui::LayerAnimationElement {
virtual ~ScreenRotation();
private:
- // Implementation of ui::LayerAnimationDelegate
- virtual void OnStart(ui::LayerAnimationDelegate* delegate) OVERRIDE;
+ // Implementation of LayerAnimationDelegate
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE;
virtual void OnProgress(double t,
- ui::LayerAnimationDelegate* delegate) OVERRIDE;
+ LayerAnimationDelegate* delegate) OVERRIDE;
virtual void OnGetTarget(TargetValue* target) const OVERRIDE;
virtual void OnAbort() OVERRIDE;
- static const ui::LayerAnimationElement::AnimatableProperties& GetProperties();
+ static const LayerAnimationElement::AnimatableProperties& GetProperties();
// Generates the intermediate transformation matrices used during the
// animation.
- scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;
+ scoped_ptr<InterpolatedTransform> interpolated_transform_;
// The number of degrees to rotate.
int degrees_;
- // The target origin for |view_|
+ // The target origin
gfx::Point new_origin_;
DISALLOW_COPY_AND_ASSIGN(ScreenRotation);
};
-#endif // UI_AURA_SCREEN_ROTATION_H_
+} // namespace ui
+
+#endif // UI_GFX_COMPOSITOR_SCREEN_ROTATION_H_