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

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

Issue 2042913002: Converts MruWindowTracker to work with common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 4 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/window_cycle_list.h" 5 #include "ash/wm/window_cycle_list.h"
6 6
7 #include "ash/common/wm/window_state.h" 7 #include "ash/common/wm/window_state.h"
8 #include "ash/common/wm_window.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/wm/mru_window_tracker.h" 10 #include "ash/wm/mru_window_tracker.h"
10 #include "ash/wm/window_animations.h" 11 #include "ash/wm/window_animations.h"
11 #include "ash/wm/window_state_aura.h"
12 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
13 #include "ui/aura/window.h"
14 13
15 namespace ash { 14 namespace ash {
16 15
17 // Returns the window immediately below |window| in the current container. 16 // Returns the window immediately below |window| in the current container.
18 aura::Window* GetWindowBelow(aura::Window* window) { 17 WmWindow* GetWindowBelow(WmWindow* window) {
19 aura::Window* parent = window->parent(); 18 WmWindow* parent = window->GetParent();
20 if (!parent) 19 if (!parent)
21 return NULL; 20 return nullptr;
22 aura::Window::Windows::const_iterator iter = 21 const WmWindow::Windows children = parent->GetChildren();
23 std::find(parent->children().begin(), parent->children().end(), window); 22 auto iter = std::find(children.begin(), children.end(), window);
24 CHECK(*iter == window); 23 CHECK(*iter == window);
25 if (iter != parent->children().begin()) 24 return (iter != children.begin()) ? *(iter - 1) : nullptr;
26 return *(iter - 1);
27 else
28 return NULL;
29 } 25 }
30 26
31 // This class restores and moves a window to the front of the stacking order for 27 // This class restores and moves a window to the front of the stacking order for
32 // the duration of the class's scope. 28 // the duration of the class's scope.
33 class ScopedShowWindow : public aura::WindowObserver { 29 class ScopedShowWindow : public WmWindowObserver {
34 public: 30 public:
35 ScopedShowWindow(); 31 ScopedShowWindow();
36 ~ScopedShowWindow() override; 32 ~ScopedShowWindow() override;
37 33
38 // Show |window| at the top of the stacking order. 34 // Show |window| at the top of the stacking order.
39 void Show(aura::Window* window); 35 void Show(WmWindow* window);
40 36
41 // Cancel restoring the window on going out of scope. 37 // Cancel restoring the window on going out of scope.
42 void CancelRestore(); 38 void CancelRestore();
43 39
44 private: 40 private:
45 // aura::WindowObserver: 41 // WmWindowObserver:
46 void OnWillRemoveWindow(aura::Window* window) override; 42 void OnWindowTreeChanging(WmWindow* window,
43 const TreeChangeParams& params) override;
47 44
48 // The window being shown. 45 // The window being shown.
49 aura::Window* window_; 46 WmWindow* window_;
50 47
51 // The window immediately below where window_ belongs. 48 // The window immediately below where window_ belongs.
52 aura::Window* stack_window_above_; 49 WmWindow* stack_window_above_;
53 50
54 // If true, minimize window_ on going out of scope. 51 // If true, minimize window_ on going out of scope.
55 bool minimized_; 52 bool minimized_;
56 53
57 DISALLOW_COPY_AND_ASSIGN(ScopedShowWindow); 54 DISALLOW_COPY_AND_ASSIGN(ScopedShowWindow);
58 }; 55 };
59 56
60 ScopedShowWindow::ScopedShowWindow() 57 ScopedShowWindow::ScopedShowWindow()
61 : window_(NULL), 58 : window_(nullptr), stack_window_above_(nullptr), minimized_(false) {}
62 stack_window_above_(NULL),
63 minimized_(false) {
64 }
65 59
66 ScopedShowWindow::~ScopedShowWindow() { 60 ScopedShowWindow::~ScopedShowWindow() {
67 if (window_) { 61 if (window_) {
68 window_->parent()->RemoveObserver(this); 62 window_->GetParent()->RemoveObserver(this);
69 63
70 // Restore window's stacking position. 64 // Restore window's stacking position.
71 if (stack_window_above_) 65 if (stack_window_above_)
72 window_->parent()->StackChildAbove(window_, stack_window_above_); 66 window_->GetParent()->StackChildAbove(window_, stack_window_above_);
73 else 67 else
74 window_->parent()->StackChildAtBottom(window_); 68 window_->GetParent()->StackChildAtBottom(window_);
75 69
76 // Restore minimized state. 70 // Restore minimized state.
77 if (minimized_) 71 if (minimized_)
78 wm::GetWindowState(window_)->Minimize(); 72 window_->GetWindowState()->Minimize();
79 } 73 }
80 } 74 }
81 75
82 void ScopedShowWindow::Show(aura::Window* window) { 76 void ScopedShowWindow::Show(WmWindow* window) {
83 DCHECK(!window_); 77 DCHECK(!window_);
84 window_ = window; 78 window_ = window;
85 stack_window_above_ = GetWindowBelow(window); 79 stack_window_above_ = GetWindowBelow(window);
86 minimized_ = wm::GetWindowState(window)->IsMinimized(); 80 minimized_ = window->GetWindowState()->IsMinimized();
87 window_->parent()->AddObserver(this); 81 window_->GetParent()->AddObserver(this);
88 window_->Show(); 82 window_->Show();
89 wm::GetWindowState(window_)->Activate(); 83 window_->GetWindowState()->Activate();
90 } 84 }
91 85
92 void ScopedShowWindow::CancelRestore() { 86 void ScopedShowWindow::CancelRestore() {
93 if (!window_) 87 if (!window_)
94 return; 88 return;
95 window_->parent()->RemoveObserver(this); 89 window_->GetParent()->RemoveObserver(this);
96 window_ = stack_window_above_ = NULL; 90 window_ = stack_window_above_ = nullptr;
97 } 91 }
98 92
99 void ScopedShowWindow::OnWillRemoveWindow(aura::Window* window) { 93 void ScopedShowWindow::OnWindowTreeChanging(WmWindow* window,
100 if (window == window_) { 94 const TreeChangeParams& params) {
95 if (params.target == window_ && params.new_parent == nullptr) {
James Cook 2016/06/07 01:21:05 nit: I think this would be clearer as an early exi
sky 2016/06/07 02:46:21 Done.
101 CancelRestore(); 96 CancelRestore();
102 } else if (window == stack_window_above_) { 97 } else if (params.target == stack_window_above_ &&
98 params.new_parent == nullptr) {
103 // If the window this window was above is removed, use the next window down 99 // If the window this window was above is removed, use the next window down
104 // as the restore marker. 100 // as the restore marker.
105 stack_window_above_ = GetWindowBelow(stack_window_above_); 101 stack_window_above_ = GetWindowBelow(stack_window_above_);
106 } 102 }
107 } 103 }
108 104
109 WindowCycleList::WindowCycleList(const WindowList& windows) 105 WindowCycleList::WindowCycleList(const WindowList& windows)
110 : windows_(windows), 106 : windows_(windows),
111 current_index_(0) { 107 current_index_(0) {
112 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true); 108 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
113 109
114 for (auto* window : windows_) 110 for (WmWindow* window : windows_)
James Cook 2016/06/07 01:21:05 Thank you for fixing this to use explicit types.
115 window->AddObserver(this); 111 window->AddObserver(this);
116 } 112 }
117 113
118 WindowCycleList::~WindowCycleList() { 114 WindowCycleList::~WindowCycleList() {
119 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false); 115 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
120 for (auto* window : windows_) { 116 for (WmWindow* window : windows_) {
121 // TODO(oshima): Remove this once crbug.com/483491 is fixed. 117 // TODO(oshima): Remove this once crbug.com/483491 is fixed.
122 CHECK(window); 118 CHECK(window);
123 window->RemoveObserver(this); 119 window->RemoveObserver(this);
124 } 120 }
125 if (showing_window_) 121 if (showing_window_)
126 showing_window_->CancelRestore(); 122 showing_window_->CancelRestore();
127 } 123 }
128 124
129 void WindowCycleList::Step(WindowCycleController::Direction direction) { 125 void WindowCycleList::Step(WindowCycleController::Direction direction) {
130 if (windows_.empty()) 126 if (windows_.empty())
131 return; 127 return;
132 128
133 // When there is only one window, we should give feedback to the user. If the 129 // When there is only one window, we should give feedback to the user. If the
134 // window is minimized, we should also show it. 130 // window is minimized, we should also show it.
135 if (windows_.size() == 1) { 131 if (windows_.size() == 1) {
136 ::wm::AnimateWindow(windows_[0], ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); 132 windows_[0]->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
137 windows_[0]->Show(); 133 windows_[0]->Show();
138 wm::GetWindowState(windows_[0])->Activate(); 134 windows_[0]->GetWindowState()->Activate();
139 return; 135 return;
140 } 136 }
141 137
142 DCHECK(static_cast<size_t>(current_index_) < windows_.size()); 138 DCHECK(static_cast<size_t>(current_index_) < windows_.size());
143 139
144 // We're in a valid cycle, so step forward or backward. 140 // We're in a valid cycle, so step forward or backward.
145 current_index_ += direction == WindowCycleController::FORWARD ? 1 : -1; 141 current_index_ += direction == WindowCycleController::FORWARD ? 1 : -1;
146 142
147 // Wrap to window list size. 143 // Wrap to window list size.
148 current_index_ = (current_index_ + windows_.size()) % windows_.size(); 144 current_index_ = (current_index_ + windows_.size()) % windows_.size();
149 DCHECK(windows_[current_index_]); 145 DCHECK(windows_[current_index_]);
150 146
151 // Make sure the next window is visible. 147 // Make sure the next window is visible.
152 showing_window_.reset(new ScopedShowWindow); 148 showing_window_.reset(new ScopedShowWindow);
153 showing_window_->Show(windows_[current_index_]); 149 showing_window_->Show(windows_[current_index_]);
154 } 150 }
155 151
156 void WindowCycleList::OnWindowDestroying(aura::Window* window) { 152 void WindowCycleList::OnWindowDestroying(WmWindow* window) {
157 window->RemoveObserver(this); 153 window->RemoveObserver(this);
158 154
159 WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window); 155 WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window);
160 // TODO(oshima): Change this back to DCHECK once crbug.com/483491 is fixed. 156 // TODO(oshima): Change this back to DCHECK once crbug.com/483491 is fixed.
161 CHECK(i != windows_.end()); 157 CHECK(i != windows_.end());
162 int removed_index = static_cast<int>(i - windows_.begin()); 158 int removed_index = static_cast<int>(i - windows_.begin());
163 windows_.erase(i); 159 windows_.erase(i);
164 if (current_index_ > removed_index || 160 if (current_index_ > removed_index ||
165 current_index_ == static_cast<int>(windows_.size())) { 161 current_index_ == static_cast<int>(windows_.size())) {
166 current_index_--; 162 current_index_--;
167 } 163 }
168 } 164 }
169 165
170 } // namespace ash 166 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698