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

Unified Diff: views/animation/screen_rotation_setter.cc

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_setter.cc
diff --git a/views/animation/screen_rotation_setter.cc b/views/animation/screen_rotation_setter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9edd193b01ccb3c13144ba9ba769c21743b0edc5
--- /dev/null
+++ b/views/animation/screen_rotation_setter.cc
@@ -0,0 +1,69 @@
+// 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.
+
+#include "views/animation/screen_rotation_setter.h"
+
+#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/interpolated_transform.h"
+#include "views/view.h"
+
+namespace {
+
+static int SymmetricRound(float x) {
+ return static_cast<int>(
+ x > 0
+ ? std::floor(x + 0.5f)
+ : std::ceil(x - 0.5f));
+}
+
+} // namespace
+
+namespace views {
+
+ScreenRotationSetter::ScreenRotationSetter(views::View* view)
+ : rotation_(NULL),
sky 2011/08/25 03:00:13 don't need rotation_
+ view_(view) {
+}
+
+void ScreenRotationSetter::Installed(ui::Layer* layer) OVERRIDE {
+}
+
+void ScreenRotationSetter::Uninstalled(ui::Layer* layer) OVERRIDE {
+}
+
+void ScreenRotationSetter::SetTransform(
+ ui::Layer* layer, const ui::Transform& transform) OVERRIDE {
+ float degrees;
+ if (!ui::InterpolatedTransform::FactorTRS(transform, NULL, &degrees, NULL))
+ return;
+
+ if (rotation_.get()) {
+ rotation_->UpdateTarget(SymmetricRound(degrees));
+ } else {
+ float old_degrees;
+ if (ui::InterpolatedTransform::FactorTRS(layer->transform(),
+ NULL, &old_degrees, NULL)) {
+ rotation_.reset(new views::ScreenRotation(view_,
+ SymmetricRound(old_degrees),
+ SymmetricRound(degrees)));
+ rotation_->set_listener(this);
+ }
+ }
+}
+
+void ScreenRotationSetter::SetBounds(
+ ui::Layer* layer, const gfx::Rect& bounds) {
sky 2011/08/25 03:00:13 nit: each param on its own line.
+ // Ignore bounds changes during an animation.
+ if (rotation_.get() && !rotation_->done())
+ return;
sky 2011/08/25 03:00:13 Don't you need to cache and apply the bounds chang
+ layer->SetBounds(bounds);
+}
+
+void ScreenRotationSetter::OnScreenRotationCompleted(
+ views::ScreenRotation* rotation) {
+ DCHECK(rotation_.get() == rotation);
sky 2011/08/25 03:00:13 nit: DCHECK_EQ
+ rotation_.reset();
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698