Morph the selector widget to a constant padding on the window shapes in overview.
[chromium-blink-merge.git] / ash / wm / overview / window_selector_controller.cc
blobd56c4636ae5a8f06eba26263bfbbc826b6e3c1c6
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"
8 #include "ash/shell.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"
15 namespace ash {
17 WindowSelectorController::WindowSelectorController() {
20 WindowSelectorController::~WindowSelectorController() {
23 // static
24 bool WindowSelectorController::CanSelect() {
25 // Don't allow a window overview if the screen is locked or a modal dialog is
26 // open.
27 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
28 !Shell::GetInstance()->IsSystemModalWindowOpen();
31 void WindowSelectorController::ToggleOverview() {
32 if (IsSelecting()) {
33 OnSelectionCanceled();
34 } else {
35 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
36 mru_window_tracker()->BuildMruWindowList();
37 // Don't enter overview mode with no windows.
38 if (windows.empty())
39 return;
41 window_selector_.reset(
42 new WindowSelector(windows, WindowSelector::OVERVIEW, this));
43 OnSelectionStarted();
47 void WindowSelectorController::HandleCycleWindow(
48 WindowSelector::Direction direction) {
49 if (!CanSelect())
50 return;
52 if (!IsSelecting()) {
53 std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
54 mru_window_tracker()->BuildMruWindowList();
55 // Don't cycle with no windows.
56 if (windows.empty())
57 return;
59 window_selector_.reset(
60 new WindowSelector(windows, WindowSelector::CYCLE, this));
61 OnSelectionStarted();
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_);
91 } // namespace ash