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

Side by Side Diff: ash/wm/window_cycle_list.cc

Issue 260883005: Separated alt-tab window cycle from overview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed CL issues Created 6 years, 7 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 (c) 2012 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/window_cycle_list.h"
6
7 #include "ash/shell.h"
8 #include "ash/wm/mru_window_tracker.h"
9 #include "ash/wm/window_animations.h"
10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h"
12 #include "ui/aura/window.h"
13
14 namespace ash {
15
16 // Returns the window immediately below |window| in the current container.
17 aura::Window* GetWindowBelow(aura::Window* window) {
18 aura::Window* parent = window->parent();
19 if (!parent)
20 return NULL;
21 aura::Window* below = NULL;
22 for (aura::Window::Windows::const_iterator iter = parent->children().begin();
23 iter != parent->children().end();
24 ++iter) {
25 if (*iter == window)
26 return below;
27 below = *iter;
28 }
29 NOTREACHED();
30 return NULL;
31 }
32
33 // This class restores and moves a window to the front of the stacking order for
34 // the duration of the class's scope.
35 class ScopedShowWindow : public aura::WindowObserver {
36 public:
37 ScopedShowWindow();
38 virtual ~ScopedShowWindow();
39
40 // Show |window| at the top of the stacking order.
41 void Show(aura::Window* window);
42
43 // Cancel restoring the window on going out of scope.
44 void CancelRestore();
45
46 aura::Window* window() { return window_; }
47
48 // aura::WindowObserver:
49 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
50
51 private:
52 // The window being shown.
53 aura::Window* window_;
54
55 // The window immediately below where window_ belongs.
56 aura::Window* stack_window_above_;
57
58 // If true, minimize window_ on going out of scope.
59 bool minimized_;
60
61 DISALLOW_COPY_AND_ASSIGN(ScopedShowWindow);
62 };
63
64 ScopedShowWindow::ScopedShowWindow()
65 : window_(NULL), stack_window_above_(NULL), minimized_(false) {
66 }
67
68 void ScopedShowWindow::Show(aura::Window* window) {
69 DCHECK(!window_);
70 window_ = window;
71 stack_window_above_ = GetWindowBelow(window);
72 minimized_ = wm::GetWindowState(window)->IsMinimized();
73 window_->parent()->AddObserver(this);
74 window_->Show();
75 wm::GetWindowState(window_)->Activate();
76 }
77
78 ScopedShowWindow::~ScopedShowWindow() {
79 if (window_) {
80 window_->parent()->RemoveObserver(this);
81
82 // Restore window's stacking position.
83 if (stack_window_above_)
84 window_->parent()->StackChildAbove(window_, stack_window_above_);
85 else
86 window_->parent()->StackChildAtBottom(window_);
87
88 // Restore minimized state.
89 if (minimized_)
90 wm::GetWindowState(window_)->Minimize();
91 }
92 }
93
94 void ScopedShowWindow::CancelRestore() {
95 if (!window_)
96 return;
97 window_->parent()->RemoveObserver(this);
98 window_ = stack_window_above_ = NULL;
99 }
100
101 void ScopedShowWindow::OnWillRemoveWindow(aura::Window* window) {
102 if (window == window_) {
103 CancelRestore();
104 } else if (window == stack_window_above_) {
105 // If the window this window was above is removed, use the next window down
106 // as the restore marker.
107 stack_window_above_ = GetWindowBelow(stack_window_above_);
108 }
109 }
110
111 WindowCycleList::WindowCycleList(const WindowList& windows)
112 : windows_(windows), current_index_(0) {
113 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
114
115 for (WindowList::const_iterator i = windows_.begin(); i != windows_.end();
116 ++i)
tdanderson 2014/05/01 21:58:33 {} around loop body since multiple lines
Nina 2014/05/02 13:27:34 Done.
117 (*i)->AddObserver(this);
118 }
119
120 WindowCycleList::~WindowCycleList() {
121 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
122 for (WindowList::const_iterator i = windows_.begin(); i != windows_.end();
123 ++i) {
124 (*i)->RemoveObserver(this);
125 }
126 if (showing_window_)
127 showing_window_->CancelRestore();
128 }
129
130 void WindowCycleList::Step(WindowCycleController::Direction direction) {
131 if (windows_.empty())
132 return;
133
134 // When there is only one window, we should give feedback to the user.
135 if (windows_.size() == 1) {
136 ::wm::AnimateWindow(windows_[0], ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
137 return;
138 }
139
140 DCHECK(static_cast<size_t>(current_index_) < windows_.size());
141
142 // We're in a valid cycle, so step forward or backward.
143 current_index_ += direction == WindowCycleController::FORWARD ? 1 : -1;
144
145 // Wrap to window list size.
146 current_index_ = (current_index_ + windows_.size()) % windows_.size();
147 DCHECK(windows_[current_index_]);
tdanderson 2014/05/01 21:58:33 new line after line 147
Nina 2014/05/02 13:27:34 Done.
148 // Make sure the next window is visible.
149 showing_window_.reset(new ScopedShowWindow);
150 showing_window_->Show(windows_[current_index_]);
151 }
152
153 void WindowCycleList::OnWindowDestroyed(aura::Window* window) {
154 window->RemoveObserver(this);
155
156 WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window);
157 DCHECK(i != windows_.end());
158 int removed_index = static_cast<int>(i - windows_.begin());
159 windows_.erase(i);
160 if (current_index_ > removed_index ||
161 current_index_ == static_cast<int>(windows_.size()))
162 current_index_--;
163 // If the first window was destroyed, move the index to the new first window.
164 if (current_index_ == -1)
165 current_index_ = 0;
166 }
167
168 } // namespace ash
OLDNEW
« ash/wm/window_cycle_controller.cc ('K') | « ash/wm/window_cycle_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698