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