Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/overview/window_selector_controller.h" | 5 #include "ash/wm/overview/window_selector_controller.h" |
| 6 | 6 |
| 7 #include "ash/session_state_delegate.h" | 7 #include "ash/session_state_delegate.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" | |
| 9 #include "ash/wm/mru_window_tracker.h" | 10 #include "ash/wm/mru_window_tracker.h" |
| 10 #include "ash/wm/overview/window_selector.h" | 11 #include "ash/wm/overview/window_selector.h" |
| 11 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "base/metrics/histogram.h" | |
| 12 | 14 |
| 13 namespace ash { | 15 namespace ash { |
| 14 | 16 |
| 15 WindowSelectorController::WindowSelectorController() { | 17 WindowSelectorController::WindowSelectorController() { |
| 16 } | 18 } |
| 17 | 19 |
| 18 WindowSelectorController::~WindowSelectorController() { | 20 WindowSelectorController::~WindowSelectorController() { |
| 19 } | 21 } |
| 20 | 22 |
| 21 // static | 23 // static |
| 22 bool WindowSelectorController::CanSelect() { | 24 bool WindowSelectorController::CanSelect() { |
| 23 // Don't allow a window overview if the screen is locked or a modal dialog is | 25 // Don't allow a window overview if the screen is locked or a modal dialog is |
| 24 // open. | 26 // open. |
| 25 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && | 27 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && |
| 26 !Shell::GetInstance()->IsSystemModalWindowOpen(); | 28 !Shell::GetInstance()->IsSystemModalWindowOpen(); |
| 27 } | 29 } |
| 28 | 30 |
| 29 void WindowSelectorController::ToggleOverview() { | 31 void WindowSelectorController::ToggleOverview() { |
| 30 if (IsSelecting()) { | 32 if (IsSelecting()) { |
| 31 OnSelectionCanceled(); | 33 OnSelectionCanceled(); |
| 32 } else { | 34 } else { |
| 33 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> | 35 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> |
| 34 mru_window_tracker()->BuildMruWindowList(); | 36 mru_window_tracker()->BuildMruWindowList(); |
| 35 // Don't enter overview mode with no windows. | 37 // Don't enter overview mode with no windows. |
| 36 if (windows.empty()) | 38 if (windows.empty()) |
| 37 return; | 39 return; |
| 38 | 40 |
| 39 // Removing focus will hide popup windows like the omnibar or open menus. | |
| 40 window_selector_.reset( | 41 window_selector_.reset( |
| 41 new WindowSelector(windows, WindowSelector::OVERVIEW, this)); | 42 new WindowSelector(windows, WindowSelector::OVERVIEW, this)); |
| 43 OnSelectionStarted(); | |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 void WindowSelectorController::HandleCycleWindow( | 47 void WindowSelectorController::HandleCycleWindow( |
| 46 WindowSelector::Direction direction) { | 48 WindowSelector::Direction direction) { |
| 47 if (!CanSelect()) | 49 if (!CanSelect()) |
| 48 return; | 50 return; |
| 49 | 51 |
| 50 if (!IsSelecting()) { | 52 if (!IsSelecting()) { |
| 51 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> | 53 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> |
| 52 mru_window_tracker()->BuildMruWindowList(); | 54 mru_window_tracker()->BuildMruWindowList(); |
| 53 // Don't cycle with no windows. | 55 // Don't cycle with no windows. |
| 54 if (windows.empty()) | 56 if (windows.empty()) |
| 55 return; | 57 return; |
| 56 | 58 |
| 57 // Removing focus will hide popup windows like the omnibar or open menus. | |
| 58 window_selector_.reset( | 59 window_selector_.reset( |
| 59 new WindowSelector(windows, WindowSelector::CYCLE, this)); | 60 new WindowSelector(windows, WindowSelector::CYCLE, this)); |
| 61 OnSelectionStarted(); | |
| 60 window_selector_->Step(direction); | 62 window_selector_->Step(direction); |
| 61 } else if (window_selector_->mode() == WindowSelector::CYCLE) { | 63 } else if (window_selector_->mode() == WindowSelector::CYCLE) { |
| 62 window_selector_->Step(direction); | 64 window_selector_->Step(direction); |
| 63 } | 65 } |
| 64 } | 66 } |
| 65 | 67 |
| 66 bool WindowSelectorController::IsSelecting() { | 68 bool WindowSelectorController::IsSelecting() { |
| 67 return window_selector_.get() != NULL; | 69 return window_selector_.get() != NULL; |
| 68 } | 70 } |
| 69 | 71 |
| 70 void WindowSelectorController::OnWindowSelected(aura::Window* window) { | 72 void WindowSelectorController::OnWindowSelected(aura::Window* window) { |
| 71 window_selector_.reset(); | 73 window_selector_.reset(); |
| 72 wm::ActivateWindow(window); | 74 wm::ActivateWindow(window); |
| 75 last_selection_time_ = base::Time::Now(); | |
| 73 } | 76 } |
| 74 | 77 |
| 75 void WindowSelectorController::OnSelectionCanceled() { | 78 void WindowSelectorController::OnSelectionCanceled() { |
| 76 window_selector_.reset(); | 79 window_selector_.reset(); |
| 80 last_selection_time_ = base::Time::Now(); | |
| 81 } | |
| 82 | |
| 83 void WindowSelectorController::OnSelectionStarted() { | |
| 84 if (!last_selection_time_.is_null()) { | |
| 85 Shell* shell = Shell::GetInstance(); | |
| 86 shell->delegate()->RecordUserMetricsAction(UMA_WINDOW_SELECTION); | |
|
Ilya Sherman
2013/09/19 23:08:04
Why is this gated on whether or not the last_selec
flackr
2013/09/19 23:23:45
Good catch, this should not be.
| |
| 87 UMA_HISTOGRAM_LONG_TIMES( | |
| 88 "Ash.WindowSelector.TimeBetweenUse", | |
| 89 base::Time::Now() - last_selection_time_); | |
|
Ilya Sherman
2013/09/19 23:08:04
Hmm, is LONG_TIMES really enough? I'd expect it t
flackr
2013/09/19 23:23:45
In terms of usage, I think the exact timing beyond
| |
| 90 } | |
| 77 } | 91 } |
| 78 | 92 |
| 79 } // namespace ash | 93 } // namespace ash |
| OLD | NEW |