| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "athena/main/debug_accelerator_handler.h" | |
| 6 | |
| 7 #include "athena/activity/public/activity.h" | |
| 8 #include "athena/activity/public/activity_manager.h" | |
| 9 #include "athena/input/public/accelerator_manager.h" | |
| 10 #include "ui/aura/window.h" | |
| 11 #include "ui/aura/window_event_dispatcher.h" | |
| 12 #include "ui/aura/window_tree_host.h" | |
| 13 #include "ui/compositor/debug_utils.h" | |
| 14 #include "ui/wm/public/activation_client.h" | |
| 15 | |
| 16 namespace athena { | |
| 17 namespace { | |
| 18 | |
| 19 enum Command { | |
| 20 CMD_PRINT_LAYER_HIERARCHY, | |
| 21 CMD_PRINT_WINDOW_HIERARCHY, | |
| 22 }; | |
| 23 | |
| 24 const int EF_ALL_DOWN = | |
| 25 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN; | |
| 26 | |
| 27 const AcceleratorData accelerator_data[] = { | |
| 28 {TRIGGER_ON_PRESS, ui::VKEY_L, EF_ALL_DOWN, CMD_PRINT_LAYER_HIERARCHY, | |
| 29 AF_DEBUG}, | |
| 30 {TRIGGER_ON_PRESS, ui::VKEY_W, EF_ALL_DOWN, CMD_PRINT_WINDOW_HIERARCHY, | |
| 31 AF_DEBUG}, | |
| 32 }; | |
| 33 | |
| 34 void PrintLayerHierarchy(aura::Window* root_window) { | |
| 35 ui::PrintLayerHierarchy( | |
| 36 root_window->layer(), | |
| 37 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot()); | |
| 38 } | |
| 39 | |
| 40 void PrintWindowHierarchy(aura::Window* window, | |
| 41 aura::Window* active, | |
| 42 int indent, | |
| 43 std::ostringstream* out) { | |
| 44 std::string indent_str(indent, ' '); | |
| 45 std::string name(window->name()); | |
| 46 if (name.empty()) | |
| 47 name = "\"\""; | |
| 48 *out << indent_str << name << " (" << window << ")" | |
| 49 << " type=" << window->type() | |
| 50 << ((window == active) ? " [active] " : " ") | |
| 51 << (window->IsVisible() ? " visible " : " ") | |
| 52 << window->bounds().ToString(); | |
| 53 Activity* activity = ActivityManager::Get()->GetActivityForWindow(window); | |
| 54 if (activity) { | |
| 55 *out << " <activity:" | |
| 56 << " state=" << activity->GetCurrentState() | |
| 57 << " visible=" << activity->IsVisible() | |
| 58 << " media_state=" << activity->GetMediaState() | |
| 59 << ">"; | |
| 60 } | |
| 61 *out << '\n'; | |
| 62 | |
| 63 for (size_t i = 0; i < window->children().size(); ++i) | |
| 64 PrintWindowHierarchy(window->children()[i], active, indent + 3, out); | |
| 65 } | |
| 66 | |
| 67 void HandlePrintWindowHierarchy(aura::Window* root_window) { | |
| 68 aura::Window* active = | |
| 69 aura::client::GetActivationClient(root_window)->GetActiveWindow(); | |
| 70 std::ostringstream out; | |
| 71 out << "RootWindow :\n"; | |
| 72 PrintWindowHierarchy(root_window, active, 0, &out); | |
| 73 // Error so logs can be collected from end-users. | |
| 74 LOG(ERROR) << out.str(); | |
| 75 } | |
| 76 | |
| 77 } // namespace | |
| 78 | |
| 79 DebugAcceleratorHandler::DebugAcceleratorHandler(aura::Window* root_window) | |
| 80 : root_window_(root_window) { | |
| 81 AcceleratorManager::Get()->RegisterAccelerators( | |
| 82 accelerator_data, arraysize(accelerator_data), this); | |
| 83 } | |
| 84 | |
| 85 DebugAcceleratorHandler::~DebugAcceleratorHandler() { | |
| 86 } | |
| 87 | |
| 88 bool DebugAcceleratorHandler::IsCommandEnabled(int command_id) const { | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 bool DebugAcceleratorHandler::OnAcceleratorFired( | |
| 93 int command_id, | |
| 94 const ui::Accelerator& accelerator) { | |
| 95 switch (command_id) { | |
| 96 case CMD_PRINT_LAYER_HIERARCHY: | |
| 97 PrintLayerHierarchy(root_window_); | |
| 98 return true; | |
| 99 case CMD_PRINT_WINDOW_HIERARCHY: | |
| 100 HandlePrintWindowHierarchy(root_window_); | |
| 101 return true; | |
| 102 } | |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 } // namesapce athena | |
| OLD | NEW |