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"
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
,
30 {TRIGGER_ON_PRESS
, ui::VKEY_W
, EF_ALL_DOWN
, CMD_PRINT_WINDOW_HIERARCHY
,
34 void PrintLayerHierarchy(aura::Window
* root_window
) {
35 ui::PrintLayerHierarchy(
37 root_window
->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
40 void PrintWindowHierarchy(aura::Window
* window
,
43 std::ostringstream
* out
) {
44 std::string
indent_str(indent
, ' ');
45 std::string
name(window
->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
);
56 << " state=" << activity
->GetCurrentState()
57 << " visible=" << activity
->IsVisible()
58 << " media_state=" << activity
->GetMediaState()
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();
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 {
92 bool DebugAcceleratorHandler::OnAcceleratorFired(
94 const ui::Accelerator
& accelerator
) {
96 case CMD_PRINT_LAYER_HIERARCHY
:
97 PrintLayerHierarchy(root_window_
);
99 case CMD_PRINT_WINDOW_HIERARCHY
:
100 HandlePrintWindowHierarchy(root_window_
);
106 } // namesapce athena