Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: ash/common/wm/overview/window_selector_controller.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/common/wm/overview/window_selector_controller.h"
6
7 #include <vector>
8
9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/system/tray/system_tray_delegate.h"
11 #include "ash/common/wm/mru_window_tracker.h"
12 #include "ash/common/wm/overview/window_selector.h"
13 #include "ash/common/wm/window_state.h"
14 #include "ash/common/wm_shell.h"
15 #include "ash/common/wm_window.h"
16 #include "base/metrics/histogram_macros.h"
17
18 namespace ash {
19
20 WindowSelectorController::WindowSelectorController() {}
21
22 WindowSelectorController::~WindowSelectorController() {
23 // Destroy widgets that may be still animating if shell shuts down soon after
24 // exiting overview mode.
25 for (std::unique_ptr<DelayedAnimationObserver>& animation_observer :
26 delayed_animations_) {
27 animation_observer->Shutdown();
28 }
29 }
30
31 // static
32 bool WindowSelectorController::CanSelect() {
33 // Don't allow a window overview if the screen is locked or a modal dialog is
34 // open or running in kiosk app session.
35 WmShell* wm_shell = WmShell::Get();
36 SessionStateDelegate* session_state_delegate =
37 wm_shell->GetSessionStateDelegate();
38 SystemTrayDelegate* system_tray_delegate = wm_shell->system_tray_delegate();
39 return session_state_delegate->IsActiveUserSessionStarted() &&
40 !session_state_delegate->IsScreenLocked() &&
41 !wm_shell->IsSystemModalWindowOpen() && !wm_shell->IsPinned() &&
42 system_tray_delegate->GetUserLoginStatus() != LoginStatus::KIOSK_APP &&
43 system_tray_delegate->GetUserLoginStatus() !=
44 LoginStatus::ARC_KIOSK_APP;
45 }
46
47 bool WindowSelectorController::ToggleOverview() {
48 if (IsSelecting()) {
49 OnSelectionEnded();
50 } else {
51 // Don't start overview if window selection is not allowed.
52 if (!CanSelect())
53 return false;
54
55 std::vector<WmWindow*> windows =
56 WmShell::Get()->mru_window_tracker()->BuildMruWindowList();
57 auto end =
58 std::remove_if(windows.begin(), windows.end(),
59 std::not1(std::ptr_fun(&WindowSelector::IsSelectable)));
60 windows.resize(end - windows.begin());
61
62 // Don't enter overview mode with no windows.
63 if (windows.empty())
64 return false;
65
66 WmShell::Get()->OnOverviewModeStarting();
67 window_selector_.reset(new WindowSelector(this));
68 window_selector_->Init(windows);
69 OnSelectionStarted();
70 }
71 return true;
72 }
73
74 bool WindowSelectorController::IsSelecting() const {
75 return window_selector_.get() != NULL;
76 }
77
78 void WindowSelectorController::IncrementSelection(int increment) {
79 DCHECK(IsSelecting());
80 window_selector_->IncrementSelection(increment);
81 }
82
83 bool WindowSelectorController::AcceptSelection() {
84 DCHECK(IsSelecting());
85 return window_selector_->AcceptSelection();
86 }
87
88 bool WindowSelectorController::IsRestoringMinimizedWindows() const {
89 return window_selector_.get() != NULL &&
90 window_selector_->restoring_minimized_windows();
91 }
92
93 // TODO(flackr): Make WindowSelectorController observe the activation of
94 // windows, so we can remove WindowSelectorDelegate.
95 void WindowSelectorController::OnSelectionEnded() {
96 window_selector_->Shutdown();
97 window_selector_.reset();
98 last_selection_time_ = base::Time::Now();
99 WmShell::Get()->OnOverviewModeEnded();
100 }
101
102 void WindowSelectorController::AddDelayedAnimationObserver(
103 std::unique_ptr<DelayedAnimationObserver> animation_observer) {
104 animation_observer->SetOwner(this);
105 delayed_animations_.push_back(std::move(animation_observer));
106 }
107
108 void WindowSelectorController::RemoveAndDestroyAnimationObserver(
109 DelayedAnimationObserver* animation_observer) {
110 class IsEqual {
111 public:
112 explicit IsEqual(DelayedAnimationObserver* animation_observer)
113 : animation_observer_(animation_observer) {}
114 bool operator()(const std::unique_ptr<DelayedAnimationObserver>& other) {
115 return (other.get() == animation_observer_);
116 }
117
118 private:
119 const DelayedAnimationObserver* animation_observer_;
120 };
121 delayed_animations_.erase(
122 std::remove_if(delayed_animations_.begin(), delayed_animations_.end(),
123 IsEqual(animation_observer)),
124 delayed_animations_.end());
125 }
126
127 void WindowSelectorController::OnSelectionStarted() {
128 if (!last_selection_time_.is_null()) {
129 UMA_HISTOGRAM_LONG_TIMES("Ash.WindowSelector.TimeBetweenUse",
130 base::Time::Now() - last_selection_time_);
131 }
132 }
133
134 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector_controller.h ('k') | ash/common/wm/overview/window_selector_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698