OLD | NEW |
---|---|
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/overview/window_grid.h" | 5 #include "ash/wm/overview/window_grid.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 } | 67 } |
68 | 68 |
69 // A comparator for locating a given target window. | 69 // A comparator for locating a given target window. |
70 struct WindowSelectorItemComparator | 70 struct WindowSelectorItemComparator |
71 : public std::unary_function<WindowSelectorItem*, bool> { | 71 : public std::unary_function<WindowSelectorItem*, bool> { |
72 explicit WindowSelectorItemComparator(const aura::Window* target_window) | 72 explicit WindowSelectorItemComparator(const aura::Window* target_window) |
73 : target(target_window) { | 73 : target(target_window) { |
74 } | 74 } |
75 | 75 |
76 bool operator()(WindowSelectorItem* window) const { | 76 bool operator()(WindowSelectorItem* window) const { |
77 return window->HasSelectableWindow(target); | 77 return window->GetWindow() == target; |
78 } | 78 } |
79 | 79 |
80 const aura::Window* target; | 80 const aura::Window* target; |
81 }; | |
82 | |
83 // A comparator for locating a WindowSelectorItem given a targeted window. | |
84 struct WindowSelectorItemTargetComparator | |
85 : public std::unary_function<WindowSelectorItem*, bool> { | |
86 explicit WindowSelectorItemTargetComparator(const aura::Window* target_window) | |
87 : target(target_window) { | |
88 } | |
89 | |
90 bool operator()(WindowSelectorItem* window) const { | |
91 return window->Contains(target); | |
92 } | |
93 | |
94 const aura::Window* target; | |
95 }; | 81 }; |
96 | 82 |
97 // Conceptually the window overview is a table or grid of cells having this | 83 // Conceptually the window overview is a table or grid of cells having this |
98 // fixed aspect ratio. The number of columns is determined by maximizing the | 84 // fixed aspect ratio. The number of columns is determined by maximizing the |
99 // area of them based on the number of window_list. | 85 // area of them based on the number of window_list. |
100 const float kCardAspectRatio = 4.0f / 3.0f; | 86 const float kCardAspectRatio = 4.0f / 3.0f; |
101 | 87 |
102 // The minimum number of cards along the major axis (i.e. horizontally on a | 88 // The minimum number of cards along the major axis (i.e. horizontally on a |
103 // landscape orientation). | 89 // landscape orientation). |
104 const int kMinCardsMajor = 3; | 90 const int kMinCardsMajor = 3; |
(...skipping 29 matching lines...) Expand all Loading... | |
134 return vector; | 120 return vector; |
135 } | 121 } |
136 | 122 |
137 } // namespace | 123 } // namespace |
138 | 124 |
139 WindowGrid::WindowGrid(aura::Window* root_window, | 125 WindowGrid::WindowGrid(aura::Window* root_window, |
140 const std::vector<aura::Window*>& windows, | 126 const std::vector<aura::Window*>& windows, |
141 WindowSelector* window_selector) | 127 WindowSelector* window_selector) |
142 : root_window_(root_window), | 128 : root_window_(root_window), |
143 window_selector_(window_selector) { | 129 window_selector_(window_selector) { |
144 WindowSelectorItem* panels_item = nullptr; | |
145 | |
146 std::set<aura::Window*> panels_item_windows; | |
147 aura::Window* panels_parent = nullptr; | |
148 | 130 |
149 for (aura::Window::Windows::const_iterator iter = windows.begin(); | 131 for (aura::Window::Windows::const_iterator iter = windows.begin(); |
150 iter != windows.end(); ++iter) { | 132 iter != windows.end(); ++iter) { |
151 if ((*iter)->GetRootWindow() != root_window) | 133 if ((*iter)->GetRootWindow() != root_window) |
152 continue; | 134 continue; |
153 (*iter)->AddObserver(this); | 135 (*iter)->AddObserver(this); |
154 observed_windows_.insert(*iter); | 136 observed_windows_.insert(*iter); |
155 | 137 |
156 if ((*iter)->type() == ui::wm::WINDOW_TYPE_PANEL && | 138 window_list_.push_back(new WindowSelectorItem(root_window_, *iter)); |
157 wm::GetWindowState(*iter)->panel_attached()) { | |
158 // Attached panel windows are grouped into a single overview item per | |
159 // grid. | |
160 if (!panels_item) { | |
161 panels_item = new WindowSelectorItem(root_window_); | |
162 window_list_.push_back(panels_item); | |
163 } | |
164 DCHECK(panels_parent == nullptr || panels_parent == (*iter)->parent()); | |
165 panels_parent = (*iter)->parent(); | |
166 panels_item_windows.insert(*iter); | |
167 } else { | |
168 WindowSelectorItem* selector_item = new WindowSelectorItem(root_window_); | |
169 window_list_.push_back(selector_item); | |
170 selector_item->AddWindow(*iter); | |
171 } | |
172 } | |
173 | |
174 if (panels_item) { | |
175 // Sort and add panel windows in reverse z order to the WindowSelectorItem | |
176 // so that the transparent overlays are in the proper order. | |
177 | |
178 CHECK_GT(panels_item_windows.size(), 0u); | |
179 | |
180 const Windows& children = panels_parent->children(); | |
181 for (Windows::const_reverse_iterator iter = children.rbegin(); | |
182 iter != children.rend(); ++iter) { | |
183 if (panels_item_windows.find(*iter) != panels_item_windows.end()) | |
184 panels_item->AddWindow(*iter); | |
185 } | |
186 } | 139 } |
187 } | 140 } |
188 | 141 |
189 WindowGrid::~WindowGrid() { | 142 WindowGrid::~WindowGrid() { |
190 for (std::set<aura::Window*>::iterator iter = observed_windows_.begin(); | 143 for (std::set<aura::Window*>::iterator iter = observed_windows_.begin(); |
191 iter != observed_windows_.end(); iter++) { | 144 iter != observed_windows_.end(); iter++) { |
192 (*iter)->RemoveObserver(this); | 145 (*iter)->RemoveObserver(this); |
193 } | 146 } |
194 } | 147 } |
195 | 148 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 num_rows * window_size.height()) / 2; | 193 num_rows * window_size.height()) / 2; |
241 | 194 |
242 for (size_t i = 0; i < window_list_.size(); ++i) { | 195 for (size_t i = 0; i < window_list_.size(); ++i) { |
243 gfx::Transform transform; | 196 gfx::Transform transform; |
244 int column = i % num_columns_; | 197 int column = i % num_columns_; |
245 int row = i / num_columns_; | 198 int row = i / num_columns_; |
246 gfx::Rect target_bounds(window_size.width() * column + x_offset, | 199 gfx::Rect target_bounds(window_size.width() * column + x_offset, |
247 window_size.height() * row + y_offset, | 200 window_size.height() * row + y_offset, |
248 window_size.width(), | 201 window_size.width(), |
249 window_size.height()); | 202 window_size.height()); |
250 window_list_[i]->SetBounds(root_window_, target_bounds, animate ? | 203 window_list_[i]->SetBounds(target_bounds, animate ? |
251 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS : | 204 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS : |
252 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | 205 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
253 } | 206 } |
254 | 207 |
255 // If we have less than |kMinCardsMajor| windows, adjust the column_ value to | 208 // If we have less than |kMinCardsMajor| windows, adjust the column_ value to |
256 // reflect how many "real" columns we have. | 209 // reflect how many "real" columns we have. |
257 if (num_columns_ > window_list_.size()) | 210 if (num_columns_ > window_list_.size()) |
258 num_columns_ = window_list_.size(); | 211 num_columns_ = window_list_.size(); |
259 | 212 |
260 // If the selection widget is active, reposition it without any animation. | 213 // If the selection widget is active, reposition it without any animation. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 out_of_bounds, animate); | 279 out_of_bounds, animate); |
327 return out_of_bounds; | 280 return out_of_bounds; |
328 } | 281 } |
329 | 282 |
330 WindowSelectorItem* WindowGrid::SelectedWindow() const { | 283 WindowSelectorItem* WindowGrid::SelectedWindow() const { |
331 CHECK(selected_index_ < window_list_.size()); | 284 CHECK(selected_index_ < window_list_.size()); |
332 return window_list_[selected_index_]; | 285 return window_list_[selected_index_]; |
333 } | 286 } |
334 | 287 |
335 bool WindowGrid::Contains(const aura::Window* window) const { | 288 bool WindowGrid::Contains(const aura::Window* window) const { |
336 return std::find_if(window_list_.begin(), window_list_.end(), | 289 for (auto window_item : window_list_) { |
337 WindowSelectorItemTargetComparator(window)) != | 290 if (window_item->Contains(window)) |
338 window_list_.end(); | 291 return true; |
292 } | |
293 return false; | |
339 } | 294 } |
340 | 295 |
341 void WindowGrid::FilterItems(const base::string16& pattern) { | 296 void WindowGrid::FilterItems(const base::string16& pattern) { |
342 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder(pattern); | 297 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder(pattern); |
343 for (ScopedVector<WindowSelectorItem>::iterator iter = window_list_.begin(); | 298 for (ScopedVector<WindowSelectorItem>::iterator iter = window_list_.begin(); |
344 iter != window_list_.end(); iter++) { | 299 iter != window_list_.end(); iter++) { |
345 if (finder.Search((*iter)->SelectionWindow()->title(), nullptr, nullptr)) { | 300 if (finder.Search((*iter)->GetWindow()->title(), nullptr, nullptr)) { |
346 (*iter)->SetDimmed(false); | 301 (*iter)->SetDimmed(false); |
347 } else { | 302 } else { |
348 (*iter)->SetDimmed(true); | 303 (*iter)->SetDimmed(true); |
349 if (selection_widget_ && SelectedWindow() == *iter) | 304 if (selection_widget_ && SelectedWindow() == *iter) |
350 selection_widget_.reset(); | 305 selection_widget_.reset(); |
351 } | 306 } |
352 } | 307 } |
353 } | 308 } |
354 | 309 |
355 void WindowGrid::OnWindowDestroying(aura::Window* window) { | 310 void WindowGrid::OnWindowDestroying(aura::Window* window) { |
356 window->RemoveObserver(this); | 311 window->RemoveObserver(this); |
357 observed_windows_.erase(window); | 312 observed_windows_.erase(window); |
358 ScopedVector<WindowSelectorItem>::iterator iter = | 313 ScopedVector<WindowSelectorItem>::iterator iter = |
359 std::find_if(window_list_.begin(), window_list_.end(), | 314 std::find_if(window_list_.begin(), window_list_.end(), |
360 WindowSelectorItemComparator(window)); | 315 WindowSelectorItemComparator(window)); |
361 | 316 |
362 DCHECK(iter != window_list_.end()); | 317 DCHECK(iter != window_list_.end()); |
363 | 318 |
364 (*iter)->RemoveWindow(window); | 319 (*iter)->OnWindowDestroyed(); |
jonross
2015/01/15 13:37:47
Remove this.
Instead WindowSelectorItem should ha
bruthig
2015/01/15 18:27:25
Done.
| |
365 | |
366 // If there are still windows in this selector entry then the overview is | |
367 // still active and the active selection remains the same. | |
368 if (!(*iter)->empty()) | |
369 return; | |
370 | 320 |
371 size_t removed_index = iter - window_list_.begin(); | 321 size_t removed_index = iter - window_list_.begin(); |
372 window_list_.erase(iter); | 322 window_list_.erase(iter); |
373 | 323 |
374 if (empty()) { | 324 if (empty()) { |
375 // If the grid is now empty, notify the window selector so that it erases us | 325 // If the grid is now empty, notify the window selector so that it erases us |
376 // from its grid list. | 326 // from its grid list. |
377 window_selector_->OnGridEmpty(this); | 327 window_selector_->OnGridEmpty(this); |
378 return; | 328 return; |
379 } | 329 } |
380 | 330 |
381 // If selecting, update the selection index. | 331 // If selecting, update the selection index. |
382 if (selection_widget_) { | 332 if (selection_widget_) { |
383 bool send_focus_alert = selected_index_ == removed_index; | 333 bool send_focus_alert = selected_index_ == removed_index; |
384 if (selected_index_ >= removed_index && selected_index_ != 0) | 334 if (selected_index_ >= removed_index && selected_index_ != 0) |
385 selected_index_--; | 335 selected_index_--; |
386 if (send_focus_alert) | 336 if (send_focus_alert) |
387 SelectedWindow()->SendFocusAlert(); | 337 SelectedWindow()->SendFocusAlert(); |
388 } | 338 } |
389 | 339 |
390 PositionWindows(true); | 340 PositionWindows(true); |
391 } | 341 } |
392 | 342 |
393 void WindowGrid::OnWindowBoundsChanged(aura::Window* window, | 343 void WindowGrid::OnWindowBoundsChanged(aura::Window* window, |
394 const gfx::Rect& old_bounds, | 344 const gfx::Rect& old_bounds, |
395 const gfx::Rect& new_bounds) { | 345 const gfx::Rect& new_bounds) { |
396 ScopedVector<WindowSelectorItem>::const_iterator iter = | 346 ScopedVector<WindowSelectorItem>::const_iterator iter = |
397 std::find_if(window_list_.begin(), window_list_.end(), | 347 std::find_if(window_list_.begin(), window_list_.end(), |
398 WindowSelectorItemTargetComparator(window)); | 348 WindowSelectorItemComparator(window)); |
399 DCHECK(iter != window_list_.end()); | 349 DCHECK(iter != window_list_.end()); |
400 | 350 |
401 // Immediately finish any active bounds animation. | 351 // Immediately finish any active bounds animation. |
402 window->layer()->GetAnimator()->StopAnimatingProperty( | 352 window->layer()->GetAnimator()->StopAnimatingProperty( |
403 ui::LayerAnimationElement::BOUNDS); | 353 ui::LayerAnimationElement::BOUNDS); |
404 | 354 |
405 // Recompute the transform for the window. | 355 // Recompute the transform for the window. |
406 (*iter)->RecomputeWindowTransforms(); | 356 (*iter)->RecomputeWindowTransforms(); |
407 } | 357 } |
408 | 358 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 448 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
499 selection_widget_->SetBounds(SelectedWindow()->target_bounds()); | 449 selection_widget_->SetBounds(SelectedWindow()->target_bounds()); |
500 selection_widget_->SetOpacity(kWindowOverviewSelectorOpacity); | 450 selection_widget_->SetOpacity(kWindowOverviewSelectorOpacity); |
501 return; | 451 return; |
502 } | 452 } |
503 selection_widget_->SetBounds(SelectedWindow()->target_bounds()); | 453 selection_widget_->SetBounds(SelectedWindow()->target_bounds()); |
504 selection_widget_->SetOpacity(kWindowOverviewSelectorOpacity); | 454 selection_widget_->SetOpacity(kWindowOverviewSelectorOpacity); |
505 } | 455 } |
506 | 456 |
507 } // namespace ash | 457 } // namespace ash |
OLD | NEW |