Use active window if on current workspace for fullscreen mode.
[chromium-blink-merge.git] / ash / wm / overview / window_selector_controller.cc
blob25419c4a6d2df55cc0eee001c4ebbbcab653746b
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"
18 namespace ash {
20 WindowSelectorController::WindowSelectorController() {
23 WindowSelectorController::~WindowSelectorController() {
26 // static
27 bool WindowSelectorController::CanSelect() {
28 // Don't allow a window overview if the screen is locked or a modal dialog is
29 // open.
30 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
31 !Shell::GetInstance()->IsSystemModalWindowOpen();
34 void WindowSelectorController::ToggleOverview() {
35 if (IsSelecting()) {
36 OnSelectionCanceled();
37 } else {
38 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
39 mru_window_tracker()->BuildMruWindowList();
40 // Don't enter overview mode with no windows.
41 if (windows.empty())
42 return;
44 window_selector_.reset(
45 new WindowSelector(windows, WindowSelector::OVERVIEW, this));
46 OnSelectionStarted();
50 void WindowSelectorController::HandleCycleWindow(
51 WindowSelector::Direction direction) {
52 if (!CanSelect())
53 return;
55 if (!IsSelecting()) {
56 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
57 mru_window_tracker()->BuildMruWindowList();
58 // Don't cycle with no windows.
59 if (windows.empty())
60 return;
62 window_selector_.reset(
63 new WindowSelector(windows, WindowSelector::CYCLE, this));
64 OnSelectionStarted();
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_);
97 } // namespace ash