Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / accelerators / accelerator_commands.cc
1 // Copyright 2013 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 "ash/accelerators/accelerator_commands.h"
6
7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h"
9 #include "ash/wm/window_cycle_controller.h"
10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h"
12 #include "base/metrics/user_metrics.h"
13
14 namespace ash {
15 namespace accelerators {
16
17 bool ToggleMinimized() {
18   aura::Window* window = wm::GetActiveWindow();
19   // Attempt to restore the window that would be cycled through next from
20   // the launcher when there is no active window.
21   if (!window) {
22     ash::Shell::GetInstance()->window_cycle_controller()->
23         HandleCycleWindow(WindowCycleController::FORWARD, false);
24     return true;
25   }
26   wm::WindowState* window_state = wm::GetWindowState(window);
27   if (!window_state->CanMinimize())
28     return false;
29   window_state->Minimize();
30   return true;
31 }
32
33 void ToggleMaximized() {
34   wm::WindowState* window_state = wm::GetActiveWindowState();
35   if (!window_state)
36     return;
37   base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized"));
38   window_state->OnWMEvent(wm::TOGGLE_MAXIMIZE);
39 }
40
41 void ToggleFullscreen() {
42   wm::WindowState* window_state = wm::GetActiveWindowState();
43   if (window_state)
44     window_state->ToggleFullscreen();
45 }
46
47 }  // namespace accelerators
48 }  // namespace ash