• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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"
17 
18 namespace ash {
19 
WindowSelectorController()20 WindowSelectorController::WindowSelectorController() {
21 }
22 
~WindowSelectorController()23 WindowSelectorController::~WindowSelectorController() {
24 }
25 
26 // static
CanSelect()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();
32 }
33 
ToggleOverview()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;
43 
44     window_selector_.reset(
45         new WindowSelector(windows, WindowSelector::OVERVIEW, this));
46     OnSelectionStarted();
47   }
48 }
49 
HandleCycleWindow(WindowSelector::Direction direction)50 void WindowSelectorController::HandleCycleWindow(
51     WindowSelector::Direction direction) {
52   if (!CanSelect())
53     return;
54 
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;
61 
62     window_selector_.reset(
63         new WindowSelector(windows, WindowSelector::CYCLE, this));
64     OnSelectionStarted();
65   }
66   window_selector_->Step(direction);
67 }
68 
IsSelecting()69 bool WindowSelectorController::IsSelecting() {
70   return window_selector_.get() != NULL;
71 }
72 
OnWindowSelected(aura::Window * window)73 void WindowSelectorController::OnWindowSelected(aura::Window* window) {
74   window_selector_.reset();
75   wm::ActivateWindow(window);
76   last_selection_time_ = base::Time::Now();
77   Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
78 }
79 
OnSelectionCanceled()80 void WindowSelectorController::OnSelectionCanceled() {
81   window_selector_.reset();
82   last_selection_time_ = base::Time::Now();
83   Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
84 }
85 
OnSelectionStarted()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_);
94   }
95 }
96 
97 }  // namespace ash
98