Enable Enhanced Bookmark on Android Tablet
[chromium-blink-merge.git] / athena / main / debug_accelerator_handler.cc
blob1a223ab9a6877f2194b91d5593d62d66afbd049b
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.
5 #include "athena/main/debug_accelerator_handler.h"
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"
16 namespace athena {
17 namespace {
19 enum Command {
20 CMD_PRINT_LAYER_HIERARCHY,
21 CMD_PRINT_WINDOW_HIERARCHY,
24 const int EF_ALL_DOWN =
25 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN;
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},
34 void PrintLayerHierarchy(aura::Window* root_window) {
35 ui::PrintLayerHierarchy(
36 root_window->layer(),
37 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
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 << ">";
61 *out << '\n';
63 for (size_t i = 0; i < window->children().size(); ++i)
64 PrintWindowHierarchy(window->children()[i], active, indent + 3, out);
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();
77 } // namespace
79 DebugAcceleratorHandler::DebugAcceleratorHandler(aura::Window* root_window)
80 : root_window_(root_window) {
81 AcceleratorManager::Get()->RegisterAccelerators(
82 accelerator_data, arraysize(accelerator_data), this);
85 DebugAcceleratorHandler::~DebugAcceleratorHandler() {
88 bool DebugAcceleratorHandler::IsCommandEnabled(int command_id) const {
89 return true;
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;
103 return false;
106 } // namesapce athena