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/mru_window_tracker.h"
10#include "ash/wm/window_state.h"
11#include "ash/wm/window_util.h"
12#include "ash/wm/wm_event.h"
13#include "base/metrics/user_metrics.h"
14
15namespace ash {
16namespace accelerators {
17
18bool ToggleMinimized() {
19  aura::Window* window = wm::GetActiveWindow();
20  // Attempt to restore the window that would be cycled through next from
21  // the launcher when there is no active window.
22  if (!window) {
23    MruWindowTracker::WindowList mru_windows(
24        Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList());
25    if (!mru_windows.empty())
26      wm::GetWindowState(mru_windows.front())->Activate();
27    return true;
28  }
29  wm::WindowState* window_state = wm::GetWindowState(window);
30  if (!window_state->CanMinimize())
31    return false;
32  window_state->Minimize();
33  return true;
34}
35
36void ToggleMaximized() {
37  wm::WindowState* window_state = wm::GetActiveWindowState();
38  if (!window_state)
39    return;
40  base::RecordAction(base::UserMetricsAction("Accel_Toggle_Maximized"));
41  wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE);
42  window_state->OnWMEvent(&event);
43}
44
45void ToggleFullscreen() {
46  wm::WindowState* window_state = wm::GetActiveWindowState();
47  if (window_state) {
48    const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
49    window_state->OnWMEvent(&event);
50  }
51}
52
53}  // namespace accelerators
54}  // namespace ash
55