| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 WindowSelector::WindowSelector(const WindowList& windows, | 92 WindowSelector::WindowSelector(const WindowList& windows, |
| 93 WindowSelectorDelegate* delegate) | 93 WindowSelectorDelegate* delegate) |
| 94 : delegate_(delegate), | 94 : delegate_(delegate), |
| 95 restore_focus_window_(aura::client::GetFocusClient( | 95 restore_focus_window_(aura::client::GetFocusClient( |
| 96 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), | 96 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), |
| 97 ignore_activations_(false), | 97 ignore_activations_(false), |
| 98 selected_grid_index_(0), |
| 98 overview_start_time_(base::Time::Now()), | 99 overview_start_time_(base::Time::Now()), |
| 99 selected_grid_index_(0) { | 100 num_key_presses_(0), |
| 101 num_items_(0) { |
| 100 DCHECK(delegate_); | 102 DCHECK(delegate_); |
| 101 Shell* shell = Shell::GetInstance(); | 103 Shell* shell = Shell::GetInstance(); |
| 102 shell->OnOverviewModeStarting(); | 104 shell->OnOverviewModeStarting(); |
| 103 | 105 |
| 104 if (restore_focus_window_) | 106 if (restore_focus_window_) |
| 105 restore_focus_window_->AddObserver(this); | 107 restore_focus_window_->AddObserver(this); |
| 106 | 108 |
| 107 const aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 109 const aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 108 size_t items = 0; | |
| 109 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | 110 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| 110 iter != root_windows.end(); iter++) { | 111 iter != root_windows.end(); iter++) { |
| 111 // Observed switchable containers for newly created windows on all root | 112 // Observed switchable containers for newly created windows on all root |
| 112 // windows. | 113 // windows. |
| 113 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { | 114 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { |
| 114 aura::Window* container = Shell::GetContainer(*iter, | 115 aura::Window* container = Shell::GetContainer(*iter, |
| 115 kSwitchableWindowContainerIds[i]); | 116 kSwitchableWindowContainerIds[i]); |
| 116 container->AddObserver(this); | 117 container->AddObserver(this); |
| 117 observed_windows_.insert(container); | 118 observed_windows_.insert(container); |
| 118 } | 119 } |
| 119 scoped_ptr<WindowGrid> grid(new WindowGrid(*iter, windows, this)); | 120 scoped_ptr<WindowGrid> grid(new WindowGrid(*iter, windows, this)); |
| 120 if (grid->empty()) | 121 if (grid->empty()) |
| 121 continue; | 122 continue; |
| 123 num_items_ += grid->size(); |
| 122 grid_list_.push_back(grid.release()); | 124 grid_list_.push_back(grid.release()); |
| 123 items += grid_list_.size(); | |
| 124 } | 125 } |
| 125 | 126 |
| 126 DCHECK(!grid_list_.empty()); | 127 DCHECK(!grid_list_.empty()); |
| 127 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", items); | 128 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); |
| 128 | 129 |
| 129 shell->activation_client()->AddObserver(this); | 130 shell->activation_client()->AddObserver(this); |
| 130 | 131 |
| 131 // Remove focus from active window before entering overview. | 132 // Remove focus from active window before entering overview. |
| 132 aura::client::GetFocusClient( | 133 aura::client::GetFocusClient( |
| 133 Shell::GetPrimaryRootWindow())->FocusWindow(NULL); | 134 Shell::GetPrimaryRootWindow())->FocusWindow(NULL); |
| 134 | 135 |
| 135 shell->PrependPreTargetHandler(this); | 136 shell->PrependPreTargetHandler(this); |
| 136 shell->GetScreen()->AddObserver(this); | 137 shell->GetScreen()->AddObserver(this); |
| 137 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); | 138 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 162 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 163 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 163 ScopedTransformOverviewWindow::kTransitionMilliseconds)); | 164 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| 164 settings.SetPreemptionStrategy( | 165 settings.SetPreemptionStrategy( |
| 165 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 166 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 166 (*iter)->layer()->SetOpacity(1); | 167 (*iter)->layer()->SetOpacity(1); |
| 167 (*iter)->Show(); | 168 (*iter)->Show(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 shell->RemovePreTargetHandler(this); | 171 shell->RemovePreTargetHandler(this); |
| 171 shell->GetScreen()->RemoveObserver(this); | 172 shell->GetScreen()->RemoveObserver(this); |
| 172 UMA_HISTOGRAM_MEDIUM_TIMES( | 173 |
| 173 "Ash.WindowSelector.TimeInOverview", | 174 size_t remaining_items = 0; |
| 174 base::Time::Now() - overview_start_time_); | 175 for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); |
| 176 iter != grid_list_.end(); iter++) { |
| 177 remaining_items += (*iter)->size(); |
| 178 } |
| 179 |
| 180 DCHECK(num_items_ >= remaining_items); |
| 181 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.OverviewClosedItems", |
| 182 num_items_ - remaining_items); |
| 183 UMA_HISTOGRAM_MEDIUM_TIMES("Ash.WindowSelector.TimeInOverview", |
| 184 base::Time::Now() - overview_start_time_); |
| 175 | 185 |
| 176 // TODO(nsatragno): Change this to OnOverviewModeEnded and move it to when | 186 // TODO(nsatragno): Change this to OnOverviewModeEnded and move it to when |
| 177 // everything is done. | 187 // everything is done. |
| 178 shell->OnOverviewModeEnding(); | 188 shell->OnOverviewModeEnding(); |
| 179 | 189 |
| 180 // Clearing the window list resets the ignored_by_shelf flag on the windows. | 190 // Clearing the window list resets the ignored_by_shelf flag on the windows. |
| 181 grid_list_.clear(); | 191 grid_list_.clear(); |
| 182 UpdateShelfVisibility(); | 192 UpdateShelfVisibility(); |
| 183 } | 193 } |
| 184 | 194 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 199 | 209 |
| 200 void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { | 210 void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { |
| 201 if (event->type() != ui::ET_KEY_PRESSED) | 211 if (event->type() != ui::ET_KEY_PRESSED) |
| 202 return; | 212 return; |
| 203 | 213 |
| 204 switch (event->key_code()) { | 214 switch (event->key_code()) { |
| 205 case ui::VKEY_ESCAPE: | 215 case ui::VKEY_ESCAPE: |
| 206 CancelSelection(); | 216 CancelSelection(); |
| 207 break; | 217 break; |
| 208 case ui::VKEY_UP: | 218 case ui::VKEY_UP: |
| 219 num_key_presses_++; |
| 209 Move(WindowSelector::UP); | 220 Move(WindowSelector::UP); |
| 210 break; | 221 break; |
| 211 case ui::VKEY_DOWN: | 222 case ui::VKEY_DOWN: |
| 223 num_key_presses_++; |
| 212 Move(WindowSelector::DOWN); | 224 Move(WindowSelector::DOWN); |
| 213 break; | 225 break; |
| 214 case ui::VKEY_RIGHT: | 226 case ui::VKEY_RIGHT: |
| 227 num_key_presses_++; |
| 215 Move(WindowSelector::RIGHT); | 228 Move(WindowSelector::RIGHT); |
| 216 break; | 229 break; |
| 217 case ui::VKEY_LEFT: | 230 case ui::VKEY_LEFT: |
| 231 num_key_presses_++; |
| 218 Move(WindowSelector::LEFT); | 232 Move(WindowSelector::LEFT); |
| 219 break; | 233 break; |
| 220 case ui::VKEY_RETURN: | 234 case ui::VKEY_RETURN: |
| 221 // Ignore if no item is selected. | 235 // Ignore if no item is selected. |
| 222 if (!grid_list_[selected_grid_index_]->is_selecting()) | 236 if (!grid_list_[selected_grid_index_]->is_selecting()) |
| 223 return; | 237 return; |
| 238 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ArrowKeyPresses", |
| 239 num_key_presses_); |
| 240 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 241 "Ash.WindowSelector.KeyPressesOverItemsRatio", |
| 242 (num_key_presses_ * 100) / num_items_, 1, 300, 30); |
| 243 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 244 UMA_WINDOW_OVERVIEW_ENTER_KEY); |
| 224 wm::GetWindowState(grid_list_[selected_grid_index_]-> | 245 wm::GetWindowState(grid_list_[selected_grid_index_]-> |
| 225 SelectedWindow()->SelectionWindow())->Activate(); | 246 SelectedWindow()->SelectionWindow())->Activate(); |
| 226 break; | 247 break; |
| 227 default: | 248 default: |
| 228 // Not a key we are interested in. | 249 // Not a key we are interested in. |
| 229 return; | 250 return; |
| 230 } | 251 } |
| 231 event->StopPropagation(); | 252 event->StopPropagation(); |
| 232 } | 253 } |
| 233 | 254 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // root window, identify it and call Move() on it to initialize the | 386 // root window, identify it and call Move() on it to initialize the |
| 366 // selection widget. | 387 // selection widget. |
| 367 // TODO(nsatragno): If there are more than two monitors, move between grids | 388 // TODO(nsatragno): If there are more than two monitors, move between grids |
| 368 // in the requested direction. | 389 // in the requested direction. |
| 369 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); | 390 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); |
| 370 grid_list_[selected_grid_index_]->Move(direction); | 391 grid_list_[selected_grid_index_]->Move(direction); |
| 371 } | 392 } |
| 372 } | 393 } |
| 373 | 394 |
| 374 } // namespace ash | 395 } // namespace ash |
| OLD | NEW |