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/screen/screen_accelerator_handler.h"
7 #include "athena/input/public/accelerator_manager.h"
8 #include "athena/screen/public/screen_manager.h"
9 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/aura/window_tree_host.h"
12 #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"
21 CMD_PRINT_LAYER_HIERARCHY
,
22 CMD_PRINT_WINDOW_HIERARCHY
,
26 const int EF_ALL_DOWN
=
27 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
;
29 const AcceleratorData accelerator_data
[] = {
30 {TRIGGER_ON_PRESS
, ui::VKEY_L
, EF_ALL_DOWN
, CMD_PRINT_LAYER_HIERARCHY
,
32 {TRIGGER_ON_PRESS
, ui::VKEY_W
, EF_ALL_DOWN
, CMD_PRINT_WINDOW_HIERARCHY
,
34 {TRIGGER_ON_PRESS
, ui::VKEY_F3
,
35 ui::EF_CONTROL_DOWN
| ui::EF_SHIFT_DOWN
,
36 CMD_ROTATE_SCREEN
, AF_NONE
},
39 void PrintLayerHierarchy(aura::Window
* root_window
) {
40 ui::PrintLayerHierarchy(
42 root_window
->GetHost()->dispatcher()->GetLastMouseLocationInRoot());
45 void PrintWindowHierarchy(aura::Window
* window
,
48 std::ostringstream
* out
) {
49 std::string
indent_str(indent
, ' ');
50 std::string
name(window
->name());
53 *out
<< indent_str
<< name
<< " (" << window
<< ")"
54 << " type=" << window
->type()
55 << ((window
== active
) ? " [active] " : " ")
56 << (window
->IsVisible() ? " visible " : " ")
57 << window
->bounds().ToString() << '\n';
59 for (size_t i
= 0; i
< window
->children().size(); ++i
)
60 PrintWindowHierarchy(window
->children()[i
], active
, indent
+ 3, out
);
63 void HandlePrintWindowHierarchy(aura::Window
* root_window
) {
64 aura::Window
* active
=
65 aura::client::GetActivationClient(root_window
)->GetActiveWindow();
66 std::ostringstream out
;
67 out
<< "RootWindow :\n";
68 PrintWindowHierarchy(root_window
, active
, 0, &out
);
69 // Error so logs can be collected from end-users.
70 LOG(ERROR
) << out
.str();
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
);
90 ScreenAcceleratorHandler::ScreenAcceleratorHandler(aura::Window
* root_window
)
91 : root_window_(root_window
) {
92 AcceleratorManager::Get()->RegisterAccelerators(
93 accelerator_data
, arraysize(accelerator_data
), this);
96 ScreenAcceleratorHandler::~ScreenAcceleratorHandler() {
99 bool ScreenAcceleratorHandler::IsCommandEnabled(int command_id
) const {
103 bool ScreenAcceleratorHandler::OnAcceleratorFired(
105 const ui::Accelerator
& accelerator
) {
106 switch (command_id
) {
107 case CMD_PRINT_LAYER_HIERARCHY
:
108 PrintLayerHierarchy(root_window_
);
110 case CMD_PRINT_WINDOW_HIERARCHY
:
111 HandlePrintWindowHierarchy(root_window_
);
113 case CMD_ROTATE_SCREEN
:
114 HandleRotateScreen();
120 } // namesapce athena