1a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// found in the LICENSE file. 4a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/wm/overview/window_selector_controller.h" 6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/metrics/user_metrics_recorder.h" 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/root_window_controller.h" 95c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h" 10a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/shell.h" 110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ash/system/tray/system_tray_delegate.h" 12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/wm/mru_window_tracker.h" 133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/wm/overview/window_selector.h" 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/wm/window_state.h" 15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/wm/window_util.h" 1668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "base/metrics/histogram.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/aura/window.h" 18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)namespace ash { 20a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)WindowSelectorController::WindowSelectorController() { 22a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 23a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)WindowSelectorController::~WindowSelectorController() { 25a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 26a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 27a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// static 28a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)bool WindowSelectorController::CanSelect() { 29a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Don't allow a window overview if the screen is locked or a modal dialog is 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // open or running in kiosk app session. 31e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch return Shell::GetInstance()->session_state_delegate()-> 32e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch IsActiveUserSessionStarted() && 33e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && 340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch !Shell::GetInstance()->IsSystemModalWindowOpen() && 350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() != 360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch user::LOGGED_IN_KIOSK_APP; 37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void WindowSelectorController::ToggleOverview() { 40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (IsSelecting()) { 41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) OnSelectionEnded(); 42a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) } else { 430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Don't start overview if window selection is not allowed. 440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!CanSelect()) 450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return; 460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 47a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> 48a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) mru_window_tracker()->BuildMruWindowList(); 49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Don't enter overview mode with no windows. 50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) if (windows.empty()) 51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) return; 52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) window_selector_.reset(new WindowSelector(windows, this)); 5468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) OnSelectionStarted(); 55ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 56ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch} 57ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)bool WindowSelectorController::IsSelecting() { 59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) return window_selector_.get() != NULL; 60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 62116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// TODO(flackr): Make WindowSelectorController observe the activation of 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// windows, so we can remove WindowSelectorDelegate. 64cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void WindowSelectorController::OnSelectionEnded() { 65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) window_selector_.reset(); 6668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) last_selection_time_ = base::Time::Now(); 6768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 6868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 6968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void WindowSelectorController::OnSelectionStarted() { 7068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!last_selection_time_.is_null()) { 7168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UMA_HISTOGRAM_LONG_TIMES( 7268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "Ash.WindowSelector.TimeBetweenUse", 7368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) base::Time::Now() - last_selection_time_); 7468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} // namespace ash 78