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.
5 #include "ash/wm/overview/window_selector_controller.h"
7 #include "ash/session_state_delegate.h"
9 #include "ash/shell_delegate.h"
10 #include "ash/wm/mru_window_tracker.h"
11 #include "ash/wm/overview/window_selector.h"
12 #include "ash/wm/window_util.h"
13 #include "base/metrics/histogram.h"
17 WindowSelectorController::WindowSelectorController() {
20 WindowSelectorController::~WindowSelectorController() {
24 bool WindowSelectorController::CanSelect() {
25 // Don't allow a window overview if the screen is locked or a modal dialog is
27 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
28 !Shell::GetInstance()->IsSystemModalWindowOpen();
31 void WindowSelectorController::ToggleOverview() {
33 OnSelectionCanceled();
35 std::vector
<aura::Window
*> windows
= ash::Shell::GetInstance()->
36 mru_window_tracker()->BuildMruWindowList();
37 // Don't enter overview mode with no windows.
41 window_selector_
.reset(
42 new WindowSelector(windows
, WindowSelector::OVERVIEW
, this));
47 void WindowSelectorController::HandleCycleWindow(
48 WindowSelector::Direction direction
) {
53 std::vector
<aura::Window
*> windows
= ash::Shell::GetInstance()->
54 mru_window_tracker()->BuildMruWindowList();
55 // Don't cycle with no windows.
59 window_selector_
.reset(
60 new WindowSelector(windows
, WindowSelector::CYCLE
, this));
63 window_selector_
->Step(direction
);
66 bool WindowSelectorController::IsSelecting() {
67 return window_selector_
.get() != NULL
;
70 void WindowSelectorController::OnWindowSelected(aura::Window
* window
) {
71 window_selector_
.reset();
72 wm::ActivateWindow(window
);
73 last_selection_time_
= base::Time::Now();
76 void WindowSelectorController::OnSelectionCanceled() {
77 window_selector_
.reset();
78 last_selection_time_
= base::Time::Now();
81 void WindowSelectorController::OnSelectionStarted() {
82 Shell
* shell
= Shell::GetInstance();
83 shell
->delegate()->RecordUserMetricsAction(UMA_WINDOW_SELECTION
);
84 if (!last_selection_time_
.is_null()) {
85 UMA_HISTOGRAM_LONG_TIMES(
86 "Ash.WindowSelector.TimeBetweenUse",
87 base::Time::Now() - last_selection_time_
);