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

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: not equal 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
« no previous file with comments | « ash/wm/window_cycle_list.h ('k') | ash/wm/window_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Only interested in removal.
96 if (params.new_parent != nullptr)
97 return;
98
99 if (params.target == window_) {
101 CancelRestore(); 100 CancelRestore();
102 } else if (window == stack_window_above_) { 101 } else if (params.target == stack_window_above_) {
103 // If the window this window was above is removed, use the next window down 102 // If the window this window was above is removed, use the next window down
104 // as the restore marker. 103 // as the restore marker.
105 stack_window_above_ = GetWindowBelow(stack_window_above_); 104 stack_window_above_ = GetWindowBelow(stack_window_above_);
106 } 105 }
107 } 106 }
108 107
109 WindowCycleList::WindowCycleList(const WindowList& windows) 108 WindowCycleList::WindowCycleList(const WindowList& windows)
110 : windows_(windows), 109 : windows_(windows),
111 current_index_(0) { 110 current_index_(0) {
112 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true); 111 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
113 112
114 for (auto* window : windows_) 113 for (WmWindow* window : windows_)
115 window->AddObserver(this); 114 window->AddObserver(this);
116 } 115 }
117 116
118 WindowCycleList::~WindowCycleList() { 117 WindowCycleList::~WindowCycleList() {
119 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false); 118 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
120 for (auto* window : windows_) { 119 for (WmWindow* window : windows_) {
121 // TODO(oshima): Remove this once crbug.com/483491 is fixed. 120 // TODO(oshima): Remove this once crbug.com/483491 is fixed.
122 CHECK(window); 121 CHECK(window);
123 window->RemoveObserver(this); 122 window->RemoveObserver(this);
124 } 123 }
125 if (showing_window_) 124 if (showing_window_)
126 showing_window_->CancelRestore(); 125 showing_window_->CancelRestore();
127 } 126 }
128 127
129 void WindowCycleList::Step(WindowCycleController::Direction direction) { 128 void WindowCycleList::Step(WindowCycleController::Direction direction) {
130 if (windows_.empty()) 129 if (windows_.empty())
131 return; 130 return;
132 131
133 // When there is only one window, we should give feedback to the user. If the 132 // When there is only one window, we should give feedback to the user. If the
134 // window is minimized, we should also show it. 133 // window is minimized, we should also show it.
135 if (windows_.size() == 1) { 134 if (windows_.size() == 1) {
136 ::wm::AnimateWindow(windows_[0], ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); 135 windows_[0]->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
137 windows_[0]->Show(); 136 windows_[0]->Show();
138 wm::GetWindowState(windows_[0])->Activate(); 137 windows_[0]->GetWindowState()->Activate();
139 return; 138 return;
140 } 139 }
141 140
142 DCHECK(static_cast<size_t>(current_index_) < windows_.size()); 141 DCHECK(static_cast<size_t>(current_index_) < windows_.size());
143 142
144 // We're in a valid cycle, so step forward or backward. 143 // We're in a valid cycle, so step forward or backward.
145 current_index_ += direction == WindowCycleController::FORWARD ? 1 : -1; 144 current_index_ += direction == WindowCycleController::FORWARD ? 1 : -1;
146 145
147 // Wrap to window list size. 146 // Wrap to window list size.
148 current_index_ = (current_index_ + windows_.size()) % windows_.size(); 147 current_index_ = (current_index_ + windows_.size()) % windows_.size();
149 DCHECK(windows_[current_index_]); 148 DCHECK(windows_[current_index_]);
150 149
151 // Make sure the next window is visible. 150 // Make sure the next window is visible.
152 showing_window_.reset(new ScopedShowWindow); 151 showing_window_.reset(new ScopedShowWindow);
153 showing_window_->Show(windows_[current_index_]); 152 showing_window_->Show(windows_[current_index_]);
154 } 153 }
155 154
156 void WindowCycleList::OnWindowDestroying(aura::Window* window) { 155 void WindowCycleList::OnWindowDestroying(WmWindow* window) {
157 window->RemoveObserver(this); 156 window->RemoveObserver(this);
158 157
159 WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window); 158 WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window);
160 // TODO(oshima): Change this back to DCHECK once crbug.com/483491 is fixed. 159 // TODO(oshima): Change this back to DCHECK once crbug.com/483491 is fixed.
161 CHECK(i != windows_.end()); 160 CHECK(i != windows_.end());
162 int removed_index = static_cast<int>(i - windows_.begin()); 161 int removed_index = static_cast<int>(i - windows_.begin());
163 windows_.erase(i); 162 windows_.erase(i);
164 if (current_index_ > removed_index || 163 if (current_index_ > removed_index ||
165 current_index_ == static_cast<int>(windows_.size())) { 164 current_index_ == static_cast<int>(windows_.size())) {
166 current_index_--; 165 current_index_--;
167 } 166 }
168 } 167 }
169 168
170 } // namespace ash 169 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_cycle_list.h ('k') | ash/wm/window_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698