- add sources.
[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
13 namespace ash {
14 namespace accelerators {
15
16 bool ToggleMinimized() {
17   aura::Window* window = wm::GetActiveWindow();
18   // Attempt to restore the window that would be cycled through next from
19   // the launcher when there is no active window.
20   if (!window) {
21     ash::Shell::GetInstance()->window_cycle_controller()->
22         HandleCycleWindow(WindowCycleController::FORWARD, false);
23     return true;
24   }
25   wm::WindowState* window_state = wm::GetWindowState(window);
26   if (!window_state->CanMinimize())
27     return false;
28   ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction(
29       ash::UMA_MINIMIZE_PER_KEY);
30   window_state->Minimize();
31   return true;
32 }
33
34 void ToggleMaximized() {
35   wm::WindowState* window_state = wm::GetActiveWindowState();
36   if (!window_state)
37     return;
38   // Get out of fullscreen when in fullscreen mode.
39   if (window_state->IsFullscreen())
40     ToggleFullscreen();
41   else
42     window_state->ToggleMaximized();
43 }
44
45 void ToggleFullscreen() {
46   wm::WindowState* window_state = wm::GetActiveWindowState();
47   if (window_state)
48     window_state->ToggleFullscreen();
49 }
50
51 }  // namespace accelerators
52 }  // namespace ash