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/metrics/user_metrics_recorder.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/session_state_delegate.h"
10 #include "ash/shell.h"
11 #include "ash/wm/mru_window_tracker.h"
12 #include "ash/wm/overview/window_selector.h"
13 #include "ash/wm/window_state.h"
14 #include "ash/wm/window_util.h"
15 #include "base/metrics/histogram.h"
16 #include "ui/aura/window.h"
20 WindowSelectorController::WindowSelectorController() {
23 WindowSelectorController::~WindowSelectorController() {
27 bool WindowSelectorController::CanSelect() {
28 // Don't allow a window overview if the screen is locked or a modal dialog is
30 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
31 !Shell::GetInstance()->IsSystemModalWindowOpen();
34 void WindowSelectorController::ToggleOverview() {
36 OnSelectionCanceled();
38 std::vector
<aura::Window
*> windows
= ash::Shell::GetInstance()->
39 mru_window_tracker()->BuildMruWindowList();
40 // Don't enter overview mode with no windows.
44 window_selector_
.reset(
45 new WindowSelector(windows
, WindowSelector::OVERVIEW
, this));
50 void WindowSelectorController::HandleCycleWindow(
51 WindowSelector::Direction direction
) {
56 std::vector
<aura::Window
*> windows
= ash::Shell::GetInstance()->
57 mru_window_tracker()->BuildMruWindowList();
58 // Don't cycle with no windows.
62 window_selector_
.reset(
63 new WindowSelector(windows
, WindowSelector::CYCLE
, this));
66 window_selector_
->Step(direction
);
69 bool WindowSelectorController::IsSelecting() {
70 return window_selector_
.get() != NULL
;
73 void WindowSelectorController::OnWindowSelected(aura::Window
* window
) {
74 wm::ActivateWindow(window
);
75 window_selector_
.reset();
76 last_selection_time_
= base::Time::Now();
77 Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
80 void WindowSelectorController::OnSelectionCanceled() {
81 window_selector_
.reset();
82 last_selection_time_
= base::Time::Now();
83 Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
86 void WindowSelectorController::OnSelectionStarted() {
87 Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
88 Shell
* shell
= Shell::GetInstance();
89 shell
->metrics()->RecordUserMetricsAction(UMA_WINDOW_SELECTION
);
90 if (!last_selection_time_
.is_null()) {
91 UMA_HISTOGRAM_LONG_TIMES(
92 "Ash.WindowSelector.TimeBetweenUse",
93 base::Time::Now() - last_selection_time_
);