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

Side by Side Diff: athena/screen/screen_accelerator_handler.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: Add dependencies on ipc and content. Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "athena/screen/screen_accelerator_handler.h" 5 #include "athena/screen/screen_accelerator_handler.h"
6 6
7 #include "athena/input/public/accelerator_manager.h" 7 #include "athena/input/public/accelerator_manager.h"
8 #include "athena/screen/public/screen_manager.h"
8 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
9 #include "ui/aura/window_event_dispatcher.h" 10 #include "ui/aura/window_event_dispatcher.h"
10 #include "ui/aura/window_tree_host.h" 11 #include "ui/aura/window_tree_host.h"
11 #include "ui/compositor/debug_utils.h" 12 #include "ui/compositor/debug_utils.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/screen.h"
12 #include "ui/wm/public/activation_client.h" 15 #include "ui/wm/public/activation_client.h"
13 16
14 namespace athena { 17 namespace athena {
15 namespace { 18 namespace {
16 19
17 enum Command { 20 enum Command {
18 CMD_PRINT_LAYER_HIERARCHY, 21 CMD_PRINT_LAYER_HIERARCHY,
19 CMD_PRINT_WINDOW_HIERARCHY, 22 CMD_PRINT_WINDOW_HIERARCHY,
23 CMD_ROTATE_SCREEN,
20 }; 24 };
21 25
22 const int EF_ALL_DOWN = 26 const int EF_ALL_DOWN =
23 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN; 27 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN;
24 28
25 const AcceleratorData accelerator_data[] = { 29 const AcceleratorData accelerator_data[] = {
26 {TRIGGER_ON_PRESS, ui::VKEY_L, EF_ALL_DOWN, CMD_PRINT_LAYER_HIERARCHY, 30 {TRIGGER_ON_PRESS, ui::VKEY_L, EF_ALL_DOWN, CMD_PRINT_LAYER_HIERARCHY,
27 AF_DEBUG}, 31 AF_DEBUG},
28 {TRIGGER_ON_PRESS, ui::VKEY_W, EF_ALL_DOWN, CMD_PRINT_WINDOW_HIERARCHY, 32 {TRIGGER_ON_PRESS, ui::VKEY_W, EF_ALL_DOWN, CMD_PRINT_WINDOW_HIERARCHY,
29 AF_DEBUG}, 33 AF_DEBUG},
34 {TRIGGER_ON_PRESS, ui::VKEY_F3,
35 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN,
36 CMD_ROTATE_SCREEN, AF_NONE},
30 }; 37 };
31 38
32 void PrintLayerHierarchy(aura::Window* root_window) { 39 void PrintLayerHierarchy(aura::Window* root_window) {
33 ui::PrintLayerHierarchy( 40 ui::PrintLayerHierarchy(
34 root_window->layer(), 41 root_window->layer(),
35 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot()); 42 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
36 } 43 }
37 44
38 void PrintWindowHierarchy(aura::Window* window, 45 void PrintWindowHierarchy(aura::Window* window,
39 aura::Window* active, 46 aura::Window* active,
(...skipping 16 matching lines...) Expand all
56 void HandlePrintWindowHierarchy(aura::Window* root_window) { 63 void HandlePrintWindowHierarchy(aura::Window* root_window) {
57 aura::Window* active = 64 aura::Window* active =
58 aura::client::GetActivationClient(root_window)->GetActiveWindow(); 65 aura::client::GetActivationClient(root_window)->GetActiveWindow();
59 std::ostringstream out; 66 std::ostringstream out;
60 out << "RootWindow :\n"; 67 out << "RootWindow :\n";
61 PrintWindowHierarchy(root_window, active, 0, &out); 68 PrintWindowHierarchy(root_window, active, 0, &out);
62 // Error so logs can be collected from end-users. 69 // Error so logs can be collected from end-users.
63 LOG(ERROR) << out.str(); 70 LOG(ERROR) << out.str();
64 } 71 }
65 72
73 void HandleRotateScreen() {
74 ScreenManager* screen_manager = ScreenManager::Get();
75 gfx::Display::Rotation current_rotation =
76 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation();
77 if (current_rotation == gfx::Display::ROTATE_0)
78 screen_manager->SetRotation(gfx::Display::ROTATE_90);
79 else if (current_rotation == gfx::Display::ROTATE_90)
80 screen_manager->SetRotation(gfx::Display::ROTATE_180);
81 else if (current_rotation == gfx::Display::ROTATE_180)
82 screen_manager->SetRotation(gfx::Display::ROTATE_270);
83 else if (current_rotation == gfx::Display::ROTATE_270)
84 screen_manager->SetRotation(gfx::Display::ROTATE_0);
85 }
86
66 } // namespace 87 } // namespace
67 88
68 // static 89 // static
69 ScreenAcceleratorHandler::ScreenAcceleratorHandler(aura::Window* root_window) 90 ScreenAcceleratorHandler::ScreenAcceleratorHandler(aura::Window* root_window)
70 : root_window_(root_window) { 91 : root_window_(root_window) {
71 AcceleratorManager::Get()->RegisterAccelerators( 92 AcceleratorManager::Get()->RegisterAccelerators(
72 accelerator_data, arraysize(accelerator_data), this); 93 accelerator_data, arraysize(accelerator_data), this);
73 } 94 }
74 95
75 ScreenAcceleratorHandler::~ScreenAcceleratorHandler() { 96 ScreenAcceleratorHandler::~ScreenAcceleratorHandler() {
76 } 97 }
77 98
78 bool ScreenAcceleratorHandler::IsCommandEnabled(int command_id) const { 99 bool ScreenAcceleratorHandler::IsCommandEnabled(int command_id) const {
79 return true; 100 return true;
80 } 101 }
81 102
82 bool ScreenAcceleratorHandler::OnAcceleratorFired( 103 bool ScreenAcceleratorHandler::OnAcceleratorFired(
83 int command_id, 104 int command_id,
84 const ui::Accelerator& accelerator) { 105 const ui::Accelerator& accelerator) {
85 switch (command_id) { 106 switch (command_id) {
86 case CMD_PRINT_LAYER_HIERARCHY: 107 case CMD_PRINT_LAYER_HIERARCHY:
87 PrintLayerHierarchy(root_window_); 108 PrintLayerHierarchy(root_window_);
88 return true; 109 return true;
89 case CMD_PRINT_WINDOW_HIERARCHY: 110 case CMD_PRINT_WINDOW_HIERARCHY:
90 HandlePrintWindowHierarchy(root_window_); 111 HandlePrintWindowHierarchy(root_window_);
91 return true; 112 return true;
113 case CMD_ROTATE_SCREEN:
114 HandleRotateScreen();
115 return true;
92 } 116 }
93 return false; 117 return false;
94 } 118 }
95 119
96 } // namesapce athena 120 } // namesapce athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698