| 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_overview.h" | 5 #include "ash/wm/overview/window_overview.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/metrics/user_metrics_recorder.h" | 9 #include "ash/metrics/user_metrics_recorder.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/switchable_windows.h" | 13 #include "ash/switchable_windows.h" |
| 14 #include "ash/wm/overview/scoped_transform_overview_window.h" | 14 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| 15 #include "ash/wm/overview/window_selector.h" | 15 #include "ash/wm/overview/window_selector.h" |
| 16 #include "ash/wm/overview/window_selector_item.h" | 16 #include "ash/wm/overview/window_selector_item.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/aura/client/cursor_client.h" | 19 #include "ui/aura/client/cursor_client.h" |
| 20 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 22 #include "ui/compositor/layer_animation_observer.h" | 22 #include "ui/compositor/layer_animation_observer.h" |
| 23 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 24 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
| 25 #include "ui/gfx/screen.h" |
| 25 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
| 26 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 27 | 28 |
| 28 namespace ash { | 29 namespace ash { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // Conceptually the window overview is a table or grid of cells having this | 33 // Conceptually the window overview is a table or grid of cells having this |
| 33 // fixed aspect ratio. The number of columns is determined by maximizing the | 34 // fixed aspect ratio. The number of columns is determined by maximizing the |
| 34 // area of them based on the number of windows. | 35 // area of them based on the number of windows. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 selection_index_(0), | 126 selection_index_(0), |
| 126 single_root_window_(single_root_window), | 127 single_root_window_(single_root_window), |
| 127 overview_start_time_(base::Time::Now()), | 128 overview_start_time_(base::Time::Now()), |
| 128 cursor_client_(NULL) { | 129 cursor_client_(NULL) { |
| 129 Shell* shell = Shell::GetInstance(); | 130 Shell* shell = Shell::GetInstance(); |
| 130 shell->OnOverviewModeStarting(); | 131 shell->OnOverviewModeStarting(); |
| 131 for (WindowSelectorItemList::iterator iter = windows_->begin(); | 132 for (WindowSelectorItemList::iterator iter = windows_->begin(); |
| 132 iter != windows_->end(); ++iter) { | 133 iter != windows_->end(); ++iter) { |
| 133 (*iter)->PrepareForOverview(); | 134 (*iter)->PrepareForOverview(); |
| 134 } | 135 } |
| 135 PositionWindows(); | 136 PositionWindows(/* animate */ true); |
| 136 DCHECK(!windows_->empty()); | 137 DCHECK(!windows_->empty()); |
| 137 cursor_client_ = aura::client::GetCursorClient( | 138 cursor_client_ = aura::client::GetCursorClient( |
| 138 windows_->front()->GetRootWindow()); | 139 windows_->front()->GetRootWindow()); |
| 139 if (cursor_client_) { | 140 if (cursor_client_) { |
| 140 cursor_client_->SetCursor(ui::kCursorPointer); | 141 cursor_client_->SetCursor(ui::kCursorPointer); |
| 141 cursor_client_->ShowCursor(); | 142 cursor_client_->ShowCursor(); |
| 142 // TODO(flackr): Only prevent cursor changes for windows in the overview. | 143 // TODO(flackr): Only prevent cursor changes for windows in the overview. |
| 143 // This will be easier to do without exposing the overview mode code if the | 144 // This will be easier to do without exposing the overview mode code if the |
| 144 // cursor changes are moved to ToplevelWindowEventHandler::HandleMouseMoved | 145 // cursor changes are moved to ToplevelWindowEventHandler::HandleMouseMoved |
| 145 // as suggested there. | 146 // as suggested there. |
| 146 cursor_client_->LockCursor(); | 147 cursor_client_->LockCursor(); |
| 147 } | 148 } |
| 148 shell->PrependPreTargetHandler(this); | 149 shell->PrependPreTargetHandler(this); |
| 150 shell->GetScreen()->AddObserver(this); |
| 149 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); | 151 shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
| 150 HideAndTrackNonOverviewWindows(); | 152 HideAndTrackNonOverviewWindows(); |
| 151 } | 153 } |
| 152 | 154 |
| 153 WindowOverview::~WindowOverview() { | 155 WindowOverview::~WindowOverview() { |
| 154 const aura::WindowTracker::Windows hidden_windows = hidden_windows_.windows(); | 156 const aura::WindowTracker::Windows hidden_windows = hidden_windows_.windows(); |
| 155 for (aura::WindowTracker::Windows::const_iterator iter = | 157 for (aura::WindowTracker::Windows::const_iterator iter = |
| 156 hidden_windows.begin(); iter != hidden_windows.end(); ++iter) { | 158 hidden_windows.begin(); iter != hidden_windows.end(); ++iter) { |
| 157 ui::ScopedLayerAnimationSettings settings( | 159 ui::ScopedLayerAnimationSettings settings( |
| 158 (*iter)->layer()->GetAnimator()); | 160 (*iter)->layer()->GetAnimator()); |
| 159 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 161 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 160 ScopedTransformOverviewWindow::kTransitionMilliseconds)); | 162 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| 161 settings.SetPreemptionStrategy( | 163 settings.SetPreemptionStrategy( |
| 162 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 164 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 163 (*iter)->layer()->SetOpacity(1); | 165 (*iter)->layer()->SetOpacity(1); |
| 164 (*iter)->Show(); | 166 (*iter)->Show(); |
| 165 } | 167 } |
| 166 if (cursor_client_) | 168 if (cursor_client_) |
| 167 cursor_client_->UnlockCursor(); | 169 cursor_client_->UnlockCursor(); |
| 168 ash::Shell* shell = ash::Shell::GetInstance(); | 170 ash::Shell* shell = ash::Shell::GetInstance(); |
| 169 shell->RemovePreTargetHandler(this); | 171 shell->RemovePreTargetHandler(this); |
| 172 shell->GetScreen()->RemoveObserver(this); |
| 170 UMA_HISTOGRAM_MEDIUM_TIMES( | 173 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 171 "Ash.WindowSelector.TimeInOverview", | 174 "Ash.WindowSelector.TimeInOverview", |
| 172 base::Time::Now() - overview_start_time_); | 175 base::Time::Now() - overview_start_time_); |
| 173 shell->OnOverviewModeEnding(); | 176 shell->OnOverviewModeEnding(); |
| 174 } | 177 } |
| 175 | 178 |
| 176 void WindowOverview::SetSelection(size_t index) { | 179 void WindowOverview::SetSelection(size_t index) { |
| 177 gfx::Rect target_bounds(GetSelectionBounds(index)); | 180 gfx::Rect target_bounds(GetSelectionBounds(index)); |
| 178 | 181 |
| 179 if (selection_widget_) { | 182 if (selection_widget_) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 selection_widget_->GetNativeWindow()->layer()->SetOpacity( | 238 selection_widget_->GetNativeWindow()->layer()->SetOpacity( |
| 236 kWindowOverviewSelectionOpacity); | 239 kWindowOverviewSelectionOpacity); |
| 237 } else { | 240 } else { |
| 238 InitializeSelectionWidget(); | 241 InitializeSelectionWidget(); |
| 239 selection_widget_->SetBounds(target_bounds); | 242 selection_widget_->SetBounds(target_bounds); |
| 240 } | 243 } |
| 241 selection_index_ = index; | 244 selection_index_ = index; |
| 242 } | 245 } |
| 243 | 246 |
| 244 void WindowOverview::OnWindowsChanged() { | 247 void WindowOverview::OnWindowsChanged() { |
| 245 PositionWindows(); | 248 PositionWindows(/* animate */ true); |
| 246 } | 249 } |
| 247 | 250 |
| 248 void WindowOverview::MoveToSingleRootWindow(aura::Window* root_window) { | 251 void WindowOverview::MoveToSingleRootWindow(aura::Window* root_window) { |
| 249 single_root_window_ = root_window; | 252 single_root_window_ = root_window; |
| 250 PositionWindows(); | 253 PositionWindows(/* animate */ true); |
| 251 } | 254 } |
| 252 | 255 |
| 253 void WindowOverview::OnKeyEvent(ui::KeyEvent* event) { | 256 void WindowOverview::OnKeyEvent(ui::KeyEvent* event) { |
| 254 if (GetTargetedWindow(static_cast<aura::Window*>(event->target()))) | 257 if (GetTargetedWindow(static_cast<aura::Window*>(event->target()))) |
| 255 event->StopPropagation(); | 258 event->StopPropagation(); |
| 256 if (event->type() != ui::ET_KEY_PRESSED) | 259 if (event->type() != ui::ET_KEY_PRESSED) |
| 257 return; | 260 return; |
| 258 | 261 |
| 259 if (event->key_code() == ui::VKEY_ESCAPE) | 262 if (event->key_code() == ui::VKEY_ESCAPE) |
| 260 window_selector_->CancelSelection(); | 263 window_selector_->CancelSelection(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 291 | 294 |
| 292 // TODO(flackr): StopPropogation prevents generation of gesture events. | 295 // TODO(flackr): StopPropogation prevents generation of gesture events. |
| 293 // We should find a better way to prevent events from being delivered to | 296 // We should find a better way to prevent events from being delivered to |
| 294 // the window, perhaps a transparent window in front of the target window | 297 // the window, perhaps a transparent window in front of the target window |
| 295 // or using EventClientImpl::CanProcessEventsWithinSubtree and then a tap | 298 // or using EventClientImpl::CanProcessEventsWithinSubtree and then a tap |
| 296 // gesture could be used to activate the window. | 299 // gesture could be used to activate the window. |
| 297 event->SetHandled(); | 300 event->SetHandled(); |
| 298 window_selector_->SelectWindow(target); | 301 window_selector_->SelectWindow(target); |
| 299 } | 302 } |
| 300 | 303 |
| 304 void WindowOverview::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 305 PositionWindows(/* animate */ false); |
| 306 } |
| 307 |
| 308 void WindowOverview::OnDisplayAdded(const gfx::Display& display) { |
| 309 } |
| 310 |
| 311 void WindowOverview::OnDisplayRemoved(const gfx::Display& display) { |
| 312 } |
| 313 |
| 301 aura::Window* WindowOverview::GetEventTarget(ui::LocatedEvent* event) { | 314 aura::Window* WindowOverview::GetEventTarget(ui::LocatedEvent* event) { |
| 302 aura::Window* target = static_cast<aura::Window*>(event->target()); | 315 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 303 // If the target window doesn't actually contain the event location (i.e. | 316 // If the target window doesn't actually contain the event location (i.e. |
| 304 // mouse down over the window and mouse up elsewhere) then do not select the | 317 // mouse down over the window and mouse up elsewhere) then do not select the |
| 305 // window. | 318 // window. |
| 306 if (!target->ContainsPoint(event->location())) | 319 if (!target->ContainsPoint(event->location())) |
| 307 return NULL; | 320 return NULL; |
| 308 | 321 |
| 309 return GetTargetedWindow(target); | 322 return GetTargetedWindow(target); |
| 310 } | 323 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 settings.SetPreemptionStrategy( | 364 settings.SetPreemptionStrategy( |
| 352 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 365 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 353 (*iter)->Hide(); | 366 (*iter)->Hide(); |
| 354 // Hiding the window can result in it being destroyed. | 367 // Hiding the window can result in it being destroyed. |
| 355 if (!hidden_windows_.Contains(*iter)) | 368 if (!hidden_windows_.Contains(*iter)) |
| 356 continue; | 369 continue; |
| 357 (*iter)->layer()->SetOpacity(0); | 370 (*iter)->layer()->SetOpacity(0); |
| 358 } | 371 } |
| 359 } | 372 } |
| 360 | 373 |
| 361 void WindowOverview::PositionWindows() { | 374 void WindowOverview::PositionWindows(bool animate) { |
| 362 if (single_root_window_) { | 375 if (single_root_window_) { |
| 363 std::vector<WindowSelectorItem*> windows; | 376 std::vector<WindowSelectorItem*> windows; |
| 364 for (WindowSelectorItemList::iterator iter = windows_->begin(); | 377 for (WindowSelectorItemList::iterator iter = windows_->begin(); |
| 365 iter != windows_->end(); ++iter) { | 378 iter != windows_->end(); ++iter) { |
| 366 windows.push_back(*iter); | 379 windows.push_back(*iter); |
| 367 } | 380 } |
| 368 PositionWindowsOnRoot(single_root_window_, windows); | 381 PositionWindowsOnRoot(single_root_window_, windows, animate); |
| 369 } else { | 382 } else { |
| 370 aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); | 383 aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); |
| 371 for (size_t i = 0; i < root_window_list.size(); ++i) | 384 for (size_t i = 0; i < root_window_list.size(); ++i) |
| 372 PositionWindowsFromRoot(root_window_list[i]); | 385 PositionWindowsFromRoot(root_window_list[i], animate); |
| 373 } | 386 } |
| 374 } | 387 } |
| 375 | 388 |
| 376 void WindowOverview::PositionWindowsFromRoot(aura::Window* root_window) { | 389 void WindowOverview::PositionWindowsFromRoot(aura::Window* root_window, |
| 390 bool animate) { |
| 377 std::vector<WindowSelectorItem*> windows; | 391 std::vector<WindowSelectorItem*> windows; |
| 378 for (WindowSelectorItemList::iterator iter = windows_->begin(); | 392 for (WindowSelectorItemList::iterator iter = windows_->begin(); |
| 379 iter != windows_->end(); ++iter) { | 393 iter != windows_->end(); ++iter) { |
| 380 if ((*iter)->GetRootWindow() == root_window) | 394 if ((*iter)->GetRootWindow() == root_window) |
| 381 windows.push_back(*iter); | 395 windows.push_back(*iter); |
| 382 } | 396 } |
| 383 PositionWindowsOnRoot(root_window, windows); | 397 PositionWindowsOnRoot(root_window, windows, animate); |
| 384 } | 398 } |
| 385 | 399 |
| 386 void WindowOverview::PositionWindowsOnRoot( | 400 void WindowOverview::PositionWindowsOnRoot( |
| 387 aura::Window* root_window, | 401 aura::Window* root_window, |
| 388 const std::vector<WindowSelectorItem*>& windows) { | 402 const std::vector<WindowSelectorItem*>& windows, |
| 403 bool animate) { |
| 389 if (windows.empty()) | 404 if (windows.empty()) |
| 390 return; | 405 return; |
| 391 | 406 |
| 392 gfx::Size window_size; | 407 gfx::Size window_size; |
| 393 gfx::Rect total_bounds = ScreenUtil::ConvertRectToScreen( | 408 gfx::Rect total_bounds = ScreenUtil::ConvertRectToScreen( |
| 394 root_window, | 409 root_window, |
| 395 ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 410 ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 396 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer))); | 411 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer))); |
| 397 | 412 |
| 398 // Find the minimum number of windows per row that will fit all of the | 413 // Find the minimum number of windows per row that will fit all of the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 415 rows * window_size.height()) / 2; | 430 rows * window_size.height()) / 2; |
| 416 for (size_t i = 0; i < windows.size(); ++i) { | 431 for (size_t i = 0; i < windows.size(); ++i) { |
| 417 gfx::Transform transform; | 432 gfx::Transform transform; |
| 418 int column = i % columns; | 433 int column = i % columns; |
| 419 int row = i / columns; | 434 int row = i / columns; |
| 420 gfx::Rect target_bounds(window_size.width() * column + x_offset, | 435 gfx::Rect target_bounds(window_size.width() * column + x_offset, |
| 421 window_size.height() * row + y_offset, | 436 window_size.height() * row + y_offset, |
| 422 window_size.width(), | 437 window_size.width(), |
| 423 window_size.height()); | 438 window_size.height()); |
| 424 target_bounds.Inset(kWindowMargin, kWindowMargin); | 439 target_bounds.Inset(kWindowMargin, kWindowMargin); |
| 425 windows[i]->SetBounds(root_window, target_bounds); | 440 windows[i]->SetBounds(root_window, target_bounds, animate); |
| 426 } | 441 } |
| 427 } | 442 } |
| 428 | 443 |
| 429 void WindowOverview::InitializeSelectionWidget() { | 444 void WindowOverview::InitializeSelectionWidget() { |
| 430 selection_widget_.reset(new views::Widget); | 445 selection_widget_.reset(new views::Widget); |
| 431 views::Widget::InitParams params; | 446 views::Widget::InitParams params; |
| 432 params.type = views::Widget::InitParams::TYPE_POPUP; | 447 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 433 params.can_activate = false; | 448 params.can_activate = false; |
| 434 params.keep_on_top = false; | 449 params.keep_on_top = false; |
| 435 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 450 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 453 } | 468 } |
| 454 | 469 |
| 455 gfx::Rect WindowOverview::GetSelectionBounds(size_t index) { | 470 gfx::Rect WindowOverview::GetSelectionBounds(size_t index) { |
| 456 gfx::Rect bounds((*windows_)[index]->bounds()); | 471 gfx::Rect bounds((*windows_)[index]->bounds()); |
| 457 bounds.Inset(-kWindowOverviewSelectionPadding, | 472 bounds.Inset(-kWindowOverviewSelectionPadding, |
| 458 -kWindowOverviewSelectionPadding); | 473 -kWindowOverviewSelectionPadding); |
| 459 return bounds; | 474 return bounds; |
| 460 } | 475 } |
| 461 | 476 |
| 462 } // namespace ash | 477 } // namespace ash |
| OLD | NEW |