OLD | NEW |
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" | |
9 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
10 #include "ui/aura/window_event_dispatcher.h" | 9 #include "ui/aura/window_event_dispatcher.h" |
11 #include "ui/aura/window_tree_host.h" | 10 #include "ui/aura/window_tree_host.h" |
12 #include "ui/compositor/debug_utils.h" | 11 #include "ui/compositor/debug_utils.h" |
13 #include "ui/gfx/display.h" | |
14 #include "ui/gfx/screen.h" | |
15 #include "ui/wm/public/activation_client.h" | 12 #include "ui/wm/public/activation_client.h" |
16 | 13 |
17 namespace athena { | 14 namespace athena { |
18 namespace { | 15 namespace { |
19 | 16 |
20 enum Command { | 17 enum Command { |
21 CMD_PRINT_LAYER_HIERARCHY, | 18 CMD_PRINT_LAYER_HIERARCHY, |
22 CMD_PRINT_WINDOW_HIERARCHY, | 19 CMD_PRINT_WINDOW_HIERARCHY, |
23 CMD_ROTATE_SCREEN, | |
24 }; | 20 }; |
25 | 21 |
26 const int EF_ALL_DOWN = | 22 const int EF_ALL_DOWN = |
27 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN; | 23 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN; |
28 | 24 |
29 const AcceleratorData accelerator_data[] = { | 25 const AcceleratorData accelerator_data[] = { |
30 {TRIGGER_ON_PRESS, ui::VKEY_L, EF_ALL_DOWN, CMD_PRINT_LAYER_HIERARCHY, | 26 {TRIGGER_ON_PRESS, ui::VKEY_L, EF_ALL_DOWN, CMD_PRINT_LAYER_HIERARCHY, |
31 AF_DEBUG}, | 27 AF_DEBUG}, |
32 {TRIGGER_ON_PRESS, ui::VKEY_W, EF_ALL_DOWN, CMD_PRINT_WINDOW_HIERARCHY, | 28 {TRIGGER_ON_PRESS, ui::VKEY_W, EF_ALL_DOWN, CMD_PRINT_WINDOW_HIERARCHY, |
33 AF_DEBUG}, | 29 AF_DEBUG}, |
34 {TRIGGER_ON_PRESS, ui::VKEY_F3, | |
35 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, | |
36 CMD_ROTATE_SCREEN, AF_NONE}, | |
37 }; | 30 }; |
38 | 31 |
39 void PrintLayerHierarchy(aura::Window* root_window) { | 32 void PrintLayerHierarchy(aura::Window* root_window) { |
40 ui::PrintLayerHierarchy( | 33 ui::PrintLayerHierarchy( |
41 root_window->layer(), | 34 root_window->layer(), |
42 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot()); | 35 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot()); |
43 } | 36 } |
44 | 37 |
45 void PrintWindowHierarchy(aura::Window* window, | 38 void PrintWindowHierarchy(aura::Window* window, |
46 aura::Window* active, | 39 aura::Window* active, |
(...skipping 16 matching lines...) Expand all Loading... |
63 void HandlePrintWindowHierarchy(aura::Window* root_window) { | 56 void HandlePrintWindowHierarchy(aura::Window* root_window) { |
64 aura::Window* active = | 57 aura::Window* active = |
65 aura::client::GetActivationClient(root_window)->GetActiveWindow(); | 58 aura::client::GetActivationClient(root_window)->GetActiveWindow(); |
66 std::ostringstream out; | 59 std::ostringstream out; |
67 out << "RootWindow :\n"; | 60 out << "RootWindow :\n"; |
68 PrintWindowHierarchy(root_window, active, 0, &out); | 61 PrintWindowHierarchy(root_window, active, 0, &out); |
69 // Error so logs can be collected from end-users. | 62 // Error so logs can be collected from end-users. |
70 LOG(ERROR) << out.str(); | 63 LOG(ERROR) << out.str(); |
71 } | 64 } |
72 | 65 |
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 | |
87 } // namespace | 66 } // namespace |
88 | 67 |
89 // static | 68 // static |
90 ScreenAcceleratorHandler::ScreenAcceleratorHandler(aura::Window* root_window) | 69 ScreenAcceleratorHandler::ScreenAcceleratorHandler(aura::Window* root_window) |
91 : root_window_(root_window) { | 70 : root_window_(root_window) { |
92 AcceleratorManager::Get()->RegisterAccelerators( | 71 AcceleratorManager::Get()->RegisterAccelerators( |
93 accelerator_data, arraysize(accelerator_data), this); | 72 accelerator_data, arraysize(accelerator_data), this); |
94 } | 73 } |
95 | 74 |
96 ScreenAcceleratorHandler::~ScreenAcceleratorHandler() { | 75 ScreenAcceleratorHandler::~ScreenAcceleratorHandler() { |
97 } | 76 } |
98 | 77 |
99 bool ScreenAcceleratorHandler::IsCommandEnabled(int command_id) const { | 78 bool ScreenAcceleratorHandler::IsCommandEnabled(int command_id) const { |
100 return true; | 79 return true; |
101 } | 80 } |
102 | 81 |
103 bool ScreenAcceleratorHandler::OnAcceleratorFired( | 82 bool ScreenAcceleratorHandler::OnAcceleratorFired( |
104 int command_id, | 83 int command_id, |
105 const ui::Accelerator& accelerator) { | 84 const ui::Accelerator& accelerator) { |
106 switch (command_id) { | 85 switch (command_id) { |
107 case CMD_PRINT_LAYER_HIERARCHY: | 86 case CMD_PRINT_LAYER_HIERARCHY: |
108 PrintLayerHierarchy(root_window_); | 87 PrintLayerHierarchy(root_window_); |
109 return true; | 88 return true; |
110 case CMD_PRINT_WINDOW_HIERARCHY: | 89 case CMD_PRINT_WINDOW_HIERARCHY: |
111 HandlePrintWindowHierarchy(root_window_); | 90 HandlePrintWindowHierarchy(root_window_); |
112 return true; | 91 return true; |
113 case CMD_ROTATE_SCREEN: | |
114 HandleRotateScreen(); | |
115 return true; | |
116 } | 92 } |
117 return false; | 93 return false; |
118 } | 94 } |
119 | 95 |
120 } // namesapce athena | 96 } // namesapce athena |
OLD | NEW |