Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_selector.h" | 5 #include "ash/wm/overview/window_selector.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/accessibility_delegate.h" | 9 #include "ash/accessibility_delegate.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/metrics/user_metrics_recorder.h" | 11 #include "ash/metrics/user_metrics_recorder.h" |
| 12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 13 #include "ash/screen_util.h" | |
| 14 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 15 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 16 #include "ash/switchable_windows.h" | 15 #include "ash/switchable_windows.h" |
| 17 #include "ash/wm/overview/scoped_transform_overview_window.h" | 16 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| 17 #include "ash/wm/overview/window_grid.h" | |
| 18 #include "ash/wm/overview/window_selector_delegate.h" | 18 #include "ash/wm/overview/window_selector_delegate.h" |
| 19 #include "ash/wm/overview/window_selector_item.h" | 19 #include "ash/wm/overview/window_selector_item.h" |
| 20 #include "ash/wm/overview/window_selector_panels.h" | |
| 21 #include "ash/wm/overview/window_selector_window.h" | |
| 22 #include "ash/wm/window_state.h" | 20 #include "ash/wm/window_state.h" |
| 23 #include "base/auto_reset.h" | 21 #include "base/auto_reset.h" |
| 24 #include "base/command_line.h" | |
| 25 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 26 #include "base/strings/string_number_conversions.h" | |
| 27 #include "third_party/skia/include/core/SkColor.h" | |
| 28 #include "ui/aura/client/focus_client.h" | 23 #include "ui/aura/client/focus_client.h" |
| 29 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 30 #include "ui/aura/window_event_dispatcher.h" | 25 #include "ui/aura/window_event_dispatcher.h" |
| 31 #include "ui/aura/window_observer.h" | 26 #include "ui/aura/window_observer.h" |
| 32 #include "ui/compositor/layer_animation_observer.h" | |
| 33 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 34 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
| 35 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 36 #include "ui/views/background.h" | |
| 37 #include "ui/views/widget/widget.h" | |
| 38 #include "ui/wm/core/window_util.h" | 30 #include "ui/wm/core/window_util.h" |
| 39 #include "ui/wm/public/activation_client.h" | 31 #include "ui/wm/public/activation_client.h" |
| 40 | 32 |
| 41 namespace ash { | 33 namespace ash { |
| 42 | 34 |
| 43 namespace { | 35 namespace { |
| 44 | 36 |
| 45 // Conceptually the window overview is a table or grid of cells having this | 37 // A comparator for locating a grid with a given root window. |
| 46 // fixed aspect ratio. The number of columns is determined by maximizing the | 38 struct RootWindowGridComparator |
| 47 // area of them based on the number of windows. | 39 : public std::unary_function<WindowGrid*, bool> { |
| 48 const float kCardAspectRatio = 4.0f / 3.0f; | 40 explicit RootWindowGridComparator(const aura::Window* root_window) |
| 49 | 41 : root_window_(root_window) { |
| 50 // The minimum number of cards along the major axis (i.e. horizontally on a | |
| 51 // landscape orientation). | |
| 52 const int kMinCardsMajor = 3; | |
| 53 | |
| 54 // A comparator for locating a given target window. | |
| 55 struct WindowSelectorItemComparator | |
| 56 : public std::unary_function<WindowSelectorItem*, bool> { | |
| 57 explicit WindowSelectorItemComparator(const aura::Window* target_window) | |
| 58 : target(target_window) { | |
| 59 } | 42 } |
| 60 | 43 |
| 61 bool operator()(WindowSelectorItem* window) const { | 44 bool operator()(WindowGrid* grid) const { |
| 62 return window->HasSelectableWindow(target); | 45 return (grid->root_window() == root_window_); |
| 63 } | 46 } |
| 64 | 47 |
| 65 const aura::Window* target; | 48 const aura::Window* root_window_; |
| 66 }; | 49 }; |
| 67 | 50 |
| 68 // An observer which holds onto the passed widget until the animation is | |
| 69 // complete. | |
| 70 class CleanupWidgetAfterAnimationObserver : public ui::LayerAnimationObserver { | |
| 71 public: | |
| 72 explicit CleanupWidgetAfterAnimationObserver( | |
| 73 scoped_ptr<views::Widget> widget); | |
| 74 | |
| 75 // ui::LayerAnimationObserver: | |
| 76 virtual void OnLayerAnimationEnded( | |
| 77 ui::LayerAnimationSequence* sequence) OVERRIDE; | |
| 78 virtual void OnLayerAnimationAborted( | |
| 79 ui::LayerAnimationSequence* sequence) OVERRIDE; | |
| 80 virtual void OnLayerAnimationScheduled( | |
| 81 ui::LayerAnimationSequence* sequence) OVERRIDE; | |
| 82 | |
| 83 private: | |
| 84 virtual ~CleanupWidgetAfterAnimationObserver(); | |
| 85 | |
| 86 scoped_ptr<views::Widget> widget_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(CleanupWidgetAfterAnimationObserver); | |
| 89 }; | |
| 90 | |
| 91 CleanupWidgetAfterAnimationObserver::CleanupWidgetAfterAnimationObserver( | |
| 92 scoped_ptr<views::Widget> widget) | |
| 93 : widget_(widget.Pass()) { | |
| 94 widget_->GetNativeWindow()->layer()->GetAnimator()->AddObserver(this); | |
| 95 } | |
| 96 | |
| 97 CleanupWidgetAfterAnimationObserver::~CleanupWidgetAfterAnimationObserver() { | |
| 98 widget_->GetNativeWindow()->layer()->GetAnimator()->RemoveObserver(this); | |
| 99 } | |
| 100 | |
| 101 void CleanupWidgetAfterAnimationObserver::OnLayerAnimationEnded( | |
| 102 ui::LayerAnimationSequence* sequence) { | |
| 103 delete this; | |
| 104 } | |
| 105 | |
| 106 void CleanupWidgetAfterAnimationObserver::OnLayerAnimationAborted( | |
| 107 ui::LayerAnimationSequence* sequence) { | |
| 108 delete this; | |
| 109 } | |
| 110 | |
| 111 void CleanupWidgetAfterAnimationObserver::OnLayerAnimationScheduled( | |
| 112 ui::LayerAnimationSequence* sequence) { | |
| 113 } | |
| 114 | |
| 115 // A comparator for locating a selectable window given a targeted window. | 51 // A comparator for locating a selectable window given a targeted window. |
| 116 struct WindowSelectorItemTargetComparator | 52 struct WindowSelectorItemTargetComparator |
| 117 : public std::unary_function<WindowSelectorItem*, bool> { | 53 : public std::unary_function<WindowSelectorItem*, bool> { |
| 118 explicit WindowSelectorItemTargetComparator(const aura::Window* target_window) | 54 explicit WindowSelectorItemTargetComparator(const aura::Window* target_window) |
| 119 : target(target_window) { | 55 : target(target_window) { |
| 120 } | 56 } |
| 121 | 57 |
| 122 bool operator()(WindowSelectorItem* window) const { | 58 bool operator()(WindowSelectorItem* window) const { |
| 123 return window->Contains(target); | 59 return window->Contains(target); |
| 124 } | 60 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 144 void UpdateShelfVisibility() { | 80 void UpdateShelfVisibility() { |
| 145 Shell::RootWindowControllerList root_window_controllers = | 81 Shell::RootWindowControllerList root_window_controllers = |
| 146 Shell::GetInstance()->GetAllRootWindowControllers(); | 82 Shell::GetInstance()->GetAllRootWindowControllers(); |
| 147 for (Shell::RootWindowControllerList::iterator iter = | 83 for (Shell::RootWindowControllerList::iterator iter = |
| 148 root_window_controllers.begin(); | 84 root_window_controllers.begin(); |
| 149 iter != root_window_controllers.end(); ++iter) { | 85 iter != root_window_controllers.end(); ++iter) { |
| 150 (*iter)->UpdateShelfVisibility(); | 86 (*iter)->UpdateShelfVisibility(); |
| 151 } | 87 } |
| 152 } | 88 } |
| 153 | 89 |
| 90 // Returns true if a window is contained in any of the windows passed on the | |
| 91 // list. | |
| 92 bool ContainedIn(const aura::Window* window, | |
| 93 const std::vector<WindowSelectorItem*>& window_list) { | |
| 94 std::vector<WindowSelectorItem*>::const_iterator iter = | |
| 95 std::find_if(window_list.begin(), window_list.end(), | |
| 96 WindowSelectorItemTargetComparator(window)); | |
| 97 return iter != window_list.end(); | |
|
flackr
2014/06/04 22:25:06
No need to create/store iter variable, i.e. just r
Nina
2014/06/05 18:04:35
Done. Note that the method has been moved to Windo
| |
| 98 } | |
| 99 | |
| 154 } // namespace | 100 } // namespace |
| 155 | 101 |
| 156 WindowSelector::WindowSelector(const WindowList& windows, | 102 WindowSelector::WindowSelector(const WindowList& windows, |
| 157 WindowSelectorDelegate* delegate) | 103 WindowSelectorDelegate* delegate) |
| 158 : delegate_(delegate), | 104 : delegate_(delegate), |
| 159 restore_focus_window_(aura::client::GetFocusClient( | 105 restore_focus_window_(aura::client::GetFocusClient( |
| 160 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), | 106 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), |
| 161 ignore_activations_(false) { | 107 ignore_activations_(false), |
| 108 selected_grid_index_(0) { | |
| 162 DCHECK(delegate_); | 109 DCHECK(delegate_); |
| 110 Shell* shell = Shell::GetInstance(); | |
| 111 shell->OnOverviewModeStarting(); | |
| 163 | 112 |
| 164 if (restore_focus_window_) | 113 if (restore_focus_window_) |
| 165 restore_focus_window_->AddObserver(this); | 114 restore_focus_window_->AddObserver(this); |
| 166 | 115 |
| 167 std::vector<WindowSelectorPanels*> panels_items; | 116 const aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 168 for (size_t i = 0; i < windows.size(); ++i) { | 117 size_t items = 0; |
| 169 WindowSelectorItem* item = NULL; | 118 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| 170 if (windows[i] != restore_focus_window_) | 119 iter != root_windows.end(); iter++) { |
| 171 windows[i]->AddObserver(this); | 120 WindowGrid* grid(new WindowGrid(*iter, windows, this)); |
| 172 observed_windows_.insert(windows[i]); | 121 if (grid->empty()) { |
| 173 | 122 delete grid; |
| 174 if (windows[i]->type() == ui::wm::WINDOW_TYPE_PANEL && | |
| 175 wm::GetWindowState(windows[i])->panel_attached()) { | |
| 176 // Attached panel windows are grouped into a single overview item per | |
| 177 // root window (display). | |
| 178 std::vector<WindowSelectorPanels*>::iterator iter = | |
| 179 std::find_if(panels_items.begin(), panels_items.end(), | |
| 180 WindowSelectorItemForRoot(windows[i]->GetRootWindow())); | |
| 181 WindowSelectorPanels* panels_item = NULL; | |
| 182 if (iter == panels_items.end()) { | |
| 183 panels_item = new WindowSelectorPanels(); | |
| 184 panels_items.push_back(panels_item); | |
| 185 windows_.push_back(panels_item); | |
| 186 } else { | |
| 187 panels_item = *iter; | |
| 188 } | |
| 189 panels_item->AddWindow(windows[i]); | |
| 190 item = panels_item; | |
| 191 } else { | 123 } else { |
|
flackr
2014/06/04 22:25:06
nit: Instead of else, use continue in first if sta
Nina
2014/06/05 18:04:35
But then we wouldn't add the containers to the obs
flackr
2014/06/05 20:16:32
You can move observing the containers before creat
Nina
2014/06/05 22:06:22
Done.
| |
| 192 item = new WindowSelectorWindow(windows[i]); | 124 grid_list_.push_back(grid); |
| 193 windows_.push_back(item); | 125 items += grid_list_.size(); |
| 194 } | 126 } |
| 195 // Verify that the window has been added to an item in overview. | |
| 196 CHECK(item->Contains(windows[i])); | |
| 197 } | |
| 198 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", windows_.size()); | |
| 199 | |
| 200 // Observe window activations and switchable containers on all root windows | |
| 201 // for newly created windows during overview. | |
| 202 Shell::GetInstance()->activation_client()->AddObserver(this); | |
| 203 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 204 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | |
| 205 iter != root_windows.end(); ++iter) { | |
| 206 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { | 127 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { |
| 207 aura::Window* container = Shell::GetContainer(*iter, | 128 aura::Window* container = Shell::GetContainer(*iter, |
| 208 kSwitchableWindowContainerIds[i]); | 129 kSwitchableWindowContainerIds[i]); |
| 209 container->AddObserver(this); | 130 container->AddObserver(this); |
| 210 observed_windows_.insert(container); | 131 observed_windows_.insert(container); |
| 211 } | 132 } |
| 212 } | 133 } |
| 213 | 134 |
| 214 StartOverview(); | 135 DCHECK(!grid_list_.empty()); |
| 136 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", items); | |
| 137 | |
| 138 // Observe window activations and switchable containers on all root windows | |
|
flackr
2014/06/04 22:25:06
Observing switchable containers seems to be lines
Nina
2014/06/05 18:04:35
Moved and modified comment.
| |
| 139 // for newly created windows during overview. | |
| 140 shell->activation_client()->AddObserver(this); | |
| 141 | |
| 142 // Remove focus from active window before entering overview. | |
| 143 aura::client::GetFocusClient( | |
| 144 Shell::GetPrimaryRootWindow())->FocusWindow(NULL); | |
| 145 | |
| 146 DCHECK(!grid_list_.empty()); | |
| 147 | |
| 148 shell->PrependPreTargetHandler(this); | |
| 149 shell->GetScreen()->AddObserver(this); | |
| 150 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); | |
| 151 HideAndTrackNonOverviewWindows(); | |
| 152 // Send an a11y alert. | |
| 153 shell->accessibility_delegate()->TriggerAccessibilityAlert( | |
| 154 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); | |
| 155 | |
| 156 UpdateShelfVisibility(); | |
| 215 } | 157 } |
| 216 | 158 |
| 217 WindowSelector::~WindowSelector() { | 159 WindowSelector::~WindowSelector() { |
| 218 ash::Shell* shell = ash::Shell::GetInstance(); | 160 ash::Shell* shell = ash::Shell::GetInstance(); |
| 219 | 161 |
| 220 ResetFocusRestoreWindow(true); | 162 ResetFocusRestoreWindow(true); |
| 221 for (std::set<aura::Window*>::iterator iter = observed_windows_.begin(); | 163 for (std::set<aura::Window*>::iterator iter = observed_windows_.begin(); |
| 222 iter != observed_windows_.end(); ++iter) { | 164 iter != observed_windows_.end(); ++iter) { |
| 223 (*iter)->RemoveObserver(this); | 165 (*iter)->RemoveObserver(this); |
| 224 } | 166 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 242 shell->GetScreen()->RemoveObserver(this); | 184 shell->GetScreen()->RemoveObserver(this); |
| 243 UMA_HISTOGRAM_MEDIUM_TIMES( | 185 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 244 "Ash.WindowSelector.TimeInOverview", | 186 "Ash.WindowSelector.TimeInOverview", |
| 245 base::Time::Now() - overview_start_time_); | 187 base::Time::Now() - overview_start_time_); |
| 246 | 188 |
| 247 // TODO(nsatragno): Change this to OnOverviewModeEnded and move it to when | 189 // TODO(nsatragno): Change this to OnOverviewModeEnded and move it to when |
| 248 // everything is done. | 190 // everything is done. |
| 249 shell->OnOverviewModeEnding(); | 191 shell->OnOverviewModeEnding(); |
| 250 | 192 |
| 251 // Clearing the window list resets the ignored_by_shelf flag on the windows. | 193 // Clearing the window list resets the ignored_by_shelf flag on the windows. |
| 252 windows_.clear(); | 194 grid_list_.clear(); |
| 253 UpdateShelfVisibility(); | 195 UpdateShelfVisibility(); |
| 254 } | 196 } |
| 255 | 197 |
| 256 void WindowSelector::CancelSelection() { | 198 void WindowSelector::CancelSelection() { |
| 257 delegate_->OnSelectionEnded(); | 199 delegate_->OnSelectionEnded(); |
| 258 } | 200 } |
| 259 | 201 |
| 202 void WindowSelector::OnGridEmpty(WindowGrid* grid) { | |
| 203 ScopedVector<WindowGrid>::iterator iter = | |
| 204 std::find(grid_list_.begin(), grid_list_.end(), grid); | |
| 205 DCHECK(iter != grid_list_.end()); | |
| 206 grid_list_.erase(iter); | |
| 207 // TODO(nsatragno): Use the previous index for more than two displays. | |
| 208 selected_grid_index_ = 0; | |
| 209 if (grid_list_.empty()) | |
| 210 CancelSelection(); | |
| 211 } | |
| 212 | |
| 260 void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { | 213 void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { |
| 261 if (event->type() != ui::ET_KEY_PRESSED) | 214 if (event->type() != ui::ET_KEY_PRESSED) |
| 262 return; | 215 return; |
| 263 | 216 |
| 264 if (event->key_code() == ui::VKEY_ESCAPE) { | 217 bool handled = true; |
| 265 CancelSelection(); | 218 |
| 219 switch (event->key_code()) { | |
| 220 case ui::VKEY_ESCAPE: | |
| 221 CancelSelection(); | |
| 222 break; | |
| 223 case ui::VKEY_UP: | |
| 224 Move(WindowSelector::UP); | |
| 225 break; | |
| 226 case ui::VKEY_DOWN: | |
| 227 Move(WindowSelector::DOWN); | |
| 228 break; | |
| 229 case ui::VKEY_RIGHT: | |
| 230 Move(WindowSelector::RIGHT); | |
| 231 break; | |
| 232 case ui::VKEY_LEFT: | |
| 233 Move(WindowSelector::LEFT); | |
| 234 break; | |
| 235 case ui::VKEY_RETURN: | |
| 236 wm::GetWindowState( | |
| 237 grid_list_[selected_grid_index_]-> | |
| 238 SelectedWindow()->SelectionWindow())->Activate(); | |
| 239 break; | |
| 240 default: | |
| 241 // Not a key we are interested in. | |
| 242 handled = false; | |
| 243 break; | |
| 244 } | |
| 245 if (handled) | |
| 266 event->SetHandled(); | 246 event->SetHandled(); |
| 267 } | |
| 268 } | 247 } |
| 269 | 248 |
| 270 void WindowSelector::OnDisplayAdded(const gfx::Display& display) { | 249 void WindowSelector::OnDisplayAdded(const gfx::Display& display) { |
| 271 } | 250 } |
| 272 | 251 |
| 273 void WindowSelector::OnDisplayRemoved(const gfx::Display& display) { | 252 void WindowSelector::OnDisplayRemoved(const gfx::Display& display) { |
| 253 // TODO(nsatragno): Keep window selection active on remaining displays. | |
| 254 CancelSelection(); | |
| 274 } | 255 } |
| 275 | 256 |
| 276 void WindowSelector::OnDisplayMetricsChanged(const gfx::Display& display, | 257 void WindowSelector::OnDisplayMetricsChanged(const gfx::Display& display, |
| 277 uint32_t metrics) { | 258 uint32_t metrics) { |
| 278 PositionWindows(/* animate */ false); | 259 PositionWindows(/* animate */ false); |
| 279 } | 260 } |
| 280 | 261 |
| 281 void WindowSelector::OnWindowAdded(aura::Window* new_window) { | 262 void WindowSelector::OnWindowAdded(aura::Window* new_window) { |
| 282 if (new_window->type() != ui::wm::WINDOW_TYPE_NORMAL && | 263 if (new_window->type() != ui::wm::WINDOW_TYPE_NORMAL && |
| 283 new_window->type() != ui::wm::WINDOW_TYPE_PANEL) { | 264 new_window->type() != ui::wm::WINDOW_TYPE_PANEL) { |
| 284 return; | 265 return; |
| 285 } | 266 } |
| 286 | 267 |
| 287 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { | 268 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { |
| 288 if (new_window->parent()->id() == kSwitchableWindowContainerIds[i] && | 269 if (new_window->parent()->id() == kSwitchableWindowContainerIds[i] && |
| 289 !::wm::GetTransientParent(new_window)) { | 270 !::wm::GetTransientParent(new_window)) { |
| 290 // The new window is in one of the switchable containers, abort overview. | 271 // The new window is in one of the switchable containers, abort overview. |
| 291 CancelSelection(); | 272 CancelSelection(); |
| 292 return; | 273 return; |
| 293 } | 274 } |
| 294 } | 275 } |
| 295 } | 276 } |
| 296 | 277 |
| 297 void WindowSelector::OnWindowDestroying(aura::Window* window) { | 278 void WindowSelector::OnWindowDestroying(aura::Window* window) { |
| 298 // window is one of a container, the restore_focus_window and/or | |
| 299 // one of the selectable windows in overview. | |
| 300 ScopedVector<WindowSelectorItem>::iterator iter = | |
| 301 std::find_if(windows_.begin(), windows_.end(), | |
| 302 WindowSelectorItemComparator(window)); | |
| 303 window->RemoveObserver(this); | 279 window->RemoveObserver(this); |
| 304 observed_windows_.erase(window); | 280 observed_windows_.erase(window); |
| 305 if (window == restore_focus_window_) | 281 if (window == restore_focus_window_) |
| 306 restore_focus_window_ = NULL; | 282 restore_focus_window_ = NULL; |
| 307 if (iter == windows_.end()) | |
| 308 return; | |
| 309 | |
| 310 (*iter)->RemoveWindow(window); | |
| 311 // If there are still windows in this selector entry then the overview is | |
| 312 // still active and the active selection remains the same. | |
| 313 if (!(*iter)->empty()) | |
| 314 return; | |
| 315 | |
| 316 windows_.erase(iter); | |
| 317 if (windows_.empty()) { | |
| 318 CancelSelection(); | |
| 319 return; | |
| 320 } | |
| 321 PositionWindows(true); | |
| 322 } | |
| 323 | |
| 324 void WindowSelector::OnWindowBoundsChanged(aura::Window* window, | |
| 325 const gfx::Rect& old_bounds, | |
| 326 const gfx::Rect& new_bounds) { | |
| 327 ScopedVector<WindowSelectorItem>::iterator iter = | |
| 328 std::find_if(windows_.begin(), windows_.end(), | |
| 329 WindowSelectorItemTargetComparator(window)); | |
| 330 if (iter == windows_.end()) | |
| 331 return; | |
| 332 | |
| 333 // Immediately finish any active bounds animation. | |
| 334 window->layer()->GetAnimator()->StopAnimatingProperty( | |
| 335 ui::LayerAnimationElement::BOUNDS); | |
| 336 | |
| 337 // Recompute the transform for the window. | |
| 338 (*iter)->RecomputeWindowTransforms(); | |
| 339 } | 283 } |
| 340 | 284 |
| 341 void WindowSelector::OnWindowActivated(aura::Window* gained_active, | 285 void WindowSelector::OnWindowActivated(aura::Window* gained_active, |
| 342 aura::Window* lost_active) { | 286 aura::Window* lost_active) { |
| 343 if (ignore_activations_ || !gained_active) | 287 if (ignore_activations_ || !gained_active) |
| 344 return; | 288 return; |
| 345 | 289 |
| 346 ScopedVector<WindowSelectorItem>::iterator iter = std::find_if( | 290 ScopedVector<WindowGrid>::iterator grid = |
| 347 windows_.begin(), windows_.end(), | 291 std::find_if(grid_list_.begin(), grid_list_.end(), |
| 348 WindowSelectorItemComparator(gained_active)); | 292 RootWindowGridComparator(gained_active->GetRootWindow())); |
| 293 if (grid == grid_list_.end()) | |
| 294 return; | |
| 295 const std::vector<WindowSelectorItem*> windows = (*grid)->window_list(); | |
| 349 | 296 |
| 350 if (iter != windows_.end()) | 297 ScopedVector<WindowSelectorItem>::const_iterator iter = std::find_if( |
| 298 windows.begin(), windows.end(), | |
| 299 WindowSelectorItemTargetComparator(gained_active)); | |
| 300 | |
| 301 if (iter != windows.end()) | |
| 351 (*iter)->RestoreWindowOnExit(gained_active); | 302 (*iter)->RestoreWindowOnExit(gained_active); |
| 352 | 303 |
| 353 // Don't restore focus on exit if a window was just activated. | 304 // Don't restore focus on exit if a window was just activated. |
| 354 ResetFocusRestoreWindow(false); | 305 ResetFocusRestoreWindow(false); |
| 355 CancelSelection(); | 306 CancelSelection(); |
| 356 } | 307 } |
| 357 | 308 |
| 358 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active, | 309 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active, |
| 359 aura::Window* actual_active) { | 310 aura::Window* actual_active) { |
| 360 OnWindowActivated(request_active, actual_active); | 311 OnWindowActivated(request_active, actual_active); |
| 361 } | 312 } |
| 362 | 313 |
| 363 void WindowSelector::StartOverview() { | |
| 364 // Remove focus from active window before entering overview. | |
| 365 aura::client::GetFocusClient( | |
| 366 Shell::GetPrimaryRootWindow())->FocusWindow(NULL); | |
| 367 | |
| 368 Shell* shell = Shell::GetInstance(); | |
| 369 shell->OnOverviewModeStarting(); | |
| 370 | |
| 371 for (WindowSelectorItemList::iterator iter = windows_.begin(); | |
| 372 iter != windows_.end(); ++iter) { | |
| 373 (*iter)->PrepareForOverview(); | |
| 374 } | |
| 375 PositionWindows(/* animate */ true); | |
| 376 DCHECK(!windows_.empty()); | |
| 377 shell->PrependPreTargetHandler(this); | |
| 378 shell->GetScreen()->AddObserver(this); | |
| 379 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); | |
| 380 HideAndTrackNonOverviewWindows(); | |
| 381 // Send an a11y alert. | |
| 382 shell->accessibility_delegate()->TriggerAccessibilityAlert( | |
| 383 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); | |
| 384 | |
| 385 UpdateShelfVisibility(); | |
| 386 } | |
| 387 | |
| 388 bool WindowSelector::Contains(const aura::Window* window) { | |
| 389 for (WindowSelectorItemList::iterator iter = windows_.begin(); | |
| 390 iter != windows_.end(); ++iter) { | |
| 391 if ((*iter)->Contains(window)) | |
| 392 return true; | |
| 393 } | |
| 394 return false; | |
| 395 } | |
| 396 | |
| 397 void WindowSelector::PositionWindows(bool animate) { | 314 void WindowSelector::PositionWindows(bool animate) { |
| 398 aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); | 315 for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); |
| 399 for (size_t i = 0; i < root_window_list.size(); ++i) | 316 iter != grid_list_.end(); iter++) { |
| 400 PositionWindowsFromRoot(root_window_list[i], animate); | 317 (*iter)->PositionWindows(animate); |
| 401 } | |
| 402 | |
| 403 void WindowSelector::PositionWindowsFromRoot(aura::Window* root_window, | |
| 404 bool animate) { | |
| 405 std::vector<WindowSelectorItem*> windows; | |
| 406 for (WindowSelectorItemList::iterator iter = windows_.begin(); | |
| 407 iter != windows_.end(); ++iter) { | |
| 408 if ((*iter)->GetRootWindow() == root_window) | |
| 409 windows.push_back(*iter); | |
| 410 } | |
| 411 | |
| 412 if (windows.empty()) | |
| 413 return; | |
| 414 | |
| 415 gfx::Size window_size; | |
| 416 gfx::Rect total_bounds = ScreenUtil::ConvertRectToScreen( | |
| 417 root_window, | |
| 418 ScreenUtil::GetDisplayWorkAreaBoundsInParent( | |
| 419 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer))); | |
| 420 | |
| 421 // Find the minimum number of windows per row that will fit all of the | |
| 422 // windows on screen. | |
| 423 size_t columns = std::max( | |
| 424 total_bounds.width() > total_bounds.height() ? kMinCardsMajor : 1, | |
| 425 static_cast<int>(ceil(sqrt(total_bounds.width() * windows.size() / | |
| 426 (kCardAspectRatio * total_bounds.height()))))); | |
| 427 size_t rows = ((windows.size() + columns - 1) / columns); | |
| 428 window_size.set_width(std::min( | |
| 429 static_cast<int>(total_bounds.width() / columns), | |
| 430 static_cast<int>(total_bounds.height() * kCardAspectRatio / rows))); | |
| 431 window_size.set_height(window_size.width() / kCardAspectRatio); | |
| 432 | |
| 433 // Calculate the X and Y offsets necessary to center the grid. | |
| 434 int x_offset = total_bounds.x() + ((windows.size() >= columns ? 0 : | |
| 435 (columns - windows.size()) * window_size.width()) + | |
| 436 (total_bounds.width() - columns * window_size.width())) / 2; | |
| 437 int y_offset = total_bounds.y() + (total_bounds.height() - | |
| 438 rows * window_size.height()) / 2; | |
| 439 for (size_t i = 0; i < windows.size(); ++i) { | |
| 440 gfx::Transform transform; | |
| 441 int column = i % columns; | |
| 442 int row = i / columns; | |
| 443 gfx::Rect target_bounds(window_size.width() * column + x_offset, | |
| 444 window_size.height() * row + y_offset, | |
| 445 window_size.width(), | |
| 446 window_size.height()); | |
| 447 windows[i]->SetBounds(root_window, target_bounds, animate); | |
| 448 } | 318 } |
| 449 } | 319 } |
| 450 | 320 |
| 451 void WindowSelector::HideAndTrackNonOverviewWindows() { | 321 void WindowSelector::HideAndTrackNonOverviewWindows() { |
| 452 // Add the windows to hidden_windows first so that if any are destroyed | 322 // Add the windows to hidden_windows first so that if any are destroyed |
| 453 // while hiding them they are tracked. | 323 // while hiding them they are tracked. |
| 454 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 324 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 455 for (aura::Window::Windows::const_iterator root_iter = root_windows.begin(); | 325 for (aura::Window::Windows::const_iterator root_iter = root_windows.begin(); |
| 456 root_iter != root_windows.end(); ++root_iter) { | 326 root_iter != root_windows.end(); ++root_iter) { |
|
flackr
2014/06/04 22:25:06
May as well change this to loop through the Window
Nina
2014/06/05 18:04:35
Sounds reasonable, done.
| |
| 327 // Find the overview items for this root window. | |
| 328 std::vector<WindowSelectorItem*> overview_items; | |
| 329 ScopedVector<WindowGrid>::iterator grid = | |
| 330 std::find_if(grid_list_.begin(), grid_list_.end(), | |
| 331 RootWindowGridComparator(*root_iter)); | |
| 332 if (grid != grid_list_.end()) | |
| 333 overview_items = (*grid)->window_list(); | |
|
flackr
2014/06/04 22:25:06
Instead, add WindowGrid::Contains(Window*) and use
Nina
2014/06/05 18:04:36
Done.
| |
| 334 | |
| 457 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { | 335 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { |
| 458 aura::Window* container = Shell::GetContainer(*root_iter, | 336 aura::Window* container = Shell::GetContainer(*root_iter, |
| 459 kSwitchableWindowContainerIds[i]); | 337 kSwitchableWindowContainerIds[i]); |
| 460 for (aura::Window::Windows::const_iterator iter = | 338 for (aura::Window::Windows::const_iterator iter = |
| 461 container->children().begin(); iter != container->children().end(); | 339 container->children().begin(); iter != container->children().end(); |
| 462 ++iter) { | 340 ++iter) { |
| 463 if (Contains(*iter) || !(*iter)->IsVisible()) | 341 if (ContainedIn(*iter, overview_items) || !(*iter)->IsVisible()) |
| 464 continue; | 342 continue; |
| 465 hidden_windows_.Add(*iter); | 343 hidden_windows_.Add(*iter); |
| 466 } | 344 } |
| 467 } | 345 } |
| 468 } | 346 } |
| 469 | 347 |
| 470 // Copy the window list as it can change during iteration. | 348 // Copy the window list as it can change during iteration. |
| 471 const aura::WindowTracker::Windows hidden_windows(hidden_windows_.windows()); | 349 const aura::WindowTracker::Windows hidden_windows(hidden_windows_.windows()); |
| 472 for (aura::WindowTracker::Windows::const_iterator iter = | 350 for (aura::WindowTracker::Windows::const_iterator iter = |
| 473 hidden_windows.begin(); iter != hidden_windows.end(); ++iter) { | 351 hidden_windows.begin(); iter != hidden_windows.end(); ++iter) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 496 } | 374 } |
| 497 // If the window is in the observed_windows_ list it needs to continue to be | 375 // If the window is in the observed_windows_ list it needs to continue to be |
| 498 // observed. | 376 // observed. |
| 499 if (observed_windows_.find(restore_focus_window_) == | 377 if (observed_windows_.find(restore_focus_window_) == |
| 500 observed_windows_.end()) { | 378 observed_windows_.end()) { |
| 501 restore_focus_window_->RemoveObserver(this); | 379 restore_focus_window_->RemoveObserver(this); |
| 502 } | 380 } |
| 503 restore_focus_window_ = NULL; | 381 restore_focus_window_ = NULL; |
| 504 } | 382 } |
| 505 | 383 |
| 384 void WindowSelector::Move(Direction direction) { | |
| 385 if (grid_list_[selected_grid_index_]->Move(direction)) { | |
| 386 // The grid reported that the movement command corresponds to the next | |
| 387 // root window, identify it and call Move() on it to initialize the | |
| 388 // selection widget. | |
| 389 // TODO(nsatragno): If there are more than two monitors, move between grids | |
| 390 // in the requested direction. | |
| 391 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); | |
| 392 grid_list_[selected_grid_index_]->Move(direction); | |
| 393 } | |
| 394 } | |
| 395 | |
| 506 } // namespace ash | 396 } // namespace ash |
| OLD | NEW |