Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / ash / wm / overview / window_selector_controller.cc
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.
4
5 #include "ash/wm/overview/window_selector_controller.h"
6
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"
18
19 namespace ash {
20
21 WindowSelectorController::WindowSelectorController() {
22 }
23
24 WindowSelectorController::~WindowSelectorController() {
25 }
26
27 // static
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;
35 }
36
37 void WindowSelectorController::ToggleOverview() {
38   if (IsSelecting()) {
39     OnSelectionCanceled();
40   } else {
41     // Don't start overview if window selection is not allowed.
42     if (!CanSelect())
43       return;
44
45     std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
46         mru_window_tracker()->BuildMruWindowList();
47     // Don't enter overview mode with no windows.
48     if (windows.empty())
49       return;
50
51     window_selector_.reset(
52         new WindowSelector(windows, WindowSelector::OVERVIEW, this));
53     OnSelectionStarted();
54   }
55 }
56
57 void WindowSelectorController::HandleCycleWindow(
58     WindowSelector::Direction direction) {
59   if (!CanSelect())
60     return;
61
62   if (!IsSelecting()) {
63     std::vector<aura::Window*> windows = ash::Shell::GetInstance()->
64         mru_window_tracker()->BuildMruWindowList();
65     // Don't cycle with no windows.
66     if (windows.empty())
67       return;
68
69     window_selector_.reset(
70         new WindowSelector(windows, WindowSelector::CYCLE, this));
71     OnSelectionStarted();
72   }
73   window_selector_->Step(direction);
74 }
75
76 bool WindowSelectorController::IsSelecting() {
77   return window_selector_.get() != NULL;
78 }
79
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);
85 }
86
87 void WindowSelectorController::OnSelectionCanceled() {
88   window_selector_.reset();
89   last_selection_time_ = base::Time::Now();
90   Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
91 }
92
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_);
101   }
102 }
103
104 }  // namespace ash