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

Unified Diff: athena/screen/screen_manager_impl.cc

Issue 431183003: Rotate screen in response to accelerator or device orientation sensors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: athena/screen/screen_manager_impl.cc
diff --git a/athena/screen/screen_manager_impl.cc b/athena/screen/screen_manager_impl.cc
index 8522acfc7acd30404c8b2ce8aa0d88fad5963769..a0e58c033424567a8855568a51aa82cb2acacbc1 100644
--- a/athena/screen/screen_manager_impl.cc
+++ b/athena/screen/screen_manager_impl.cc
@@ -36,6 +36,11 @@ bool GrabsInput(aura::Window* container) {
return params && params->grab_inputs;
}
+bool IsRotationPortrait(gfx::Display::Rotation rotation) {
+ return rotation == gfx::Display::ROTATE_90 ||
+ rotation == gfx::Display::ROTATE_270;
+}
+
// Returns the container which contains |window|.
aura::Window* GetContainer(aura::Window* window) {
// No containers for NULL or the root window itself.
@@ -199,9 +204,12 @@ class ScreenManagerImpl : public ScreenManager {
virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE;
virtual aura::Window* GetContext() OVERRIDE { return root_window_; }
virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE;
+ virtual gfx::Display::Rotation GetRotation() OVERRIDE;
+ virtual void SetRotation(gfx::Display::Rotation rotation) OVERRIDE;
aura::Window* root_window_;
aura::Window* background_window_;
+ gfx::Display::Rotation rotation_;
scoped_ptr<BackgroundController> background_controller_;
scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
@@ -213,7 +221,8 @@ class ScreenManagerImpl : public ScreenManager {
};
ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
- : root_window_(root_window) {
+ : root_window_(root_window),
+ rotation_(gfx::Display::ROTATE_0) {
DCHECK(root_window_);
DCHECK(!instance);
instance = this;
@@ -322,6 +331,42 @@ void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
background_controller_->SetImage(image);
}
+gfx::Display::Rotation ScreenManagerImpl::GetRotation() {
+ return rotation_;
+}
+
+void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) {
+ if (rotation == rotation_)
+ return;
+
+ gfx::Rect bounds(root_window_->bounds());
+ if (IsRotationPortrait(rotation) != IsRotationPortrait(rotation_)) {
+ bounds.set_size(gfx::Size(bounds.height(), bounds.width()));
+ }
+
+ rotation_ = rotation;
+ root_window_->SetBounds(bounds);
+ gfx::Transform transform;
+ switch (rotation) {
+ case gfx::Display::ROTATE_90:
+ transform.Translate(bounds.height(), 0);
+ transform.RotateAboutZAxis(90);
+ break;
+ case gfx::Display::ROTATE_180:
+ transform.Translate(bounds.width(), bounds.height());
+ transform.RotateAboutZAxis(180);
+ break;
+ case gfx::Display::ROTATE_270:
+ transform.Translate(0, bounds.width());
+ transform.RotateAboutZAxis(270);
+ break;
+ case gfx::Display::ROTATE_0:
+ default:
+ break;
+ }
+ root_window_->layer()->SetTransform(transform);
oshima 2014/08/01 17:15:11 Note: this won't update gfx::Display objects. A co
flackr 2014/08/06 14:13:51 Noted.
+}
+
} // namespace
ScreenManager::ContainerParams::ContainerParams(const std::string& n,

Powered by Google App Engine
This is Rietveld 408576698