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/system/tray/system_tray_delegate.h"
12 #include "ash/wm/mru_window_tracker.h"
13 #include "ash/wm/overview/window_selector.h"
14 #include "ash/wm/window_state.h"
15 #include "ash/wm/window_util.h"
16 #include "base/metrics/histogram.h"
17 #include "ui/aura/window.h"
21 WindowSelectorController::WindowSelectorController() {
24 WindowSelectorController::~WindowSelectorController() {
28 bool WindowSelectorController::CanSelect() {
29 // Don't allow a window overview if the screen is locked or a modal dialog is
30 // open or running in kiosk app session.
31 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
32 !Shell::GetInstance()->IsSystemModalWindowOpen() &&
33 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() !=
34 user::LOGGED_IN_KIOSK_APP;
37 void WindowSelectorController::ToggleOverview() {
39 OnSelectionCanceled();
41 // Don't start overview if window selection is not allowed.
45 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
46 mru_window_tracker()->BuildMruWindowList();
47 // Don't enter overview mode with no windows.
51 window_selector_.reset(
52 new WindowSelector(windows, WindowSelector::OVERVIEW, this));
57 void WindowSelectorController::HandleCycleWindow(
58 WindowSelector::Direction direction) {
63 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
64 mru_window_tracker()->BuildMruWindowList();
65 // Don't cycle with no windows.
69 window_selector_.reset(
70 new WindowSelector(windows, WindowSelector::CYCLE, this));
73 window_selector_->Step(direction);
76 bool WindowSelectorController::IsSelecting() {
77 return window_selector_.get() != NULL;
80 void WindowSelectorController::OnWindowSelected(aura::Window* window) {
81 wm::ActivateWindow(window);
82 window_selector_.reset();
83 last_selection_time_ = base::Time::Now();
84 Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
87 void WindowSelectorController::OnSelectionCanceled() {
88 window_selector_.reset();
89 last_selection_time_ = base::Time::Now();
90 Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
93 void WindowSelectorController::OnSelectionStarted() {
94 Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
95 Shell* shell = Shell::GetInstance();
96 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_SELECTION);
97 if (!last_selection_time_.is_null()) {
98 UMA_HISTOGRAM_LONG_TIMES(
99 "Ash.WindowSelector.TimeBetweenUse",
100 base::Time::Now() - last_selection_time_);