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_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" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 delete this; | 112 delete this; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void CleanupWidgetAfterAnimationObserver::OnLayerAnimationScheduled( | 115 void CleanupWidgetAfterAnimationObserver::OnLayerAnimationScheduled( |
| 116 ui::LayerAnimationSequence* sequence) { | 116 ui::LayerAnimationSequence* sequence) { |
| 117 } | 117 } |
| 118 | 118 |
| 119 } // namespace | 119 } // namespace |
| 120 | 120 |
| 121 WindowOverview::WindowOverview(WindowSelector* window_selector, | 121 WindowOverview::WindowOverview(WindowSelector* window_selector, |
| 122 WindowSelectorItemList* windows, | 122 WindowSelectorItemList* windows) |
| 123 aura::Window* single_root_window) | |
| 124 : window_selector_(window_selector), | 123 : window_selector_(window_selector), |
| 125 windows_(windows), | 124 windows_(windows), |
| 126 selection_index_(0), | 125 selection_index_(0), |
| 127 single_root_window_(single_root_window), | |
| 128 overview_start_time_(base::Time::Now()), | 126 overview_start_time_(base::Time::Now()), |
| 129 cursor_client_(NULL) { | 127 cursor_client_(NULL) { |
| 130 Shell* shell = Shell::GetInstance(); | 128 Shell* shell = Shell::GetInstance(); |
| 131 shell->OnOverviewModeStarting(); | 129 shell->OnOverviewModeStarting(); |
| 132 for (WindowSelectorItemList::iterator iter = windows_->begin(); | 130 for (WindowSelectorItemList::iterator iter = windows_->begin(); |
| 133 iter != windows_->end(); ++iter) { | 131 iter != windows_->end(); ++iter) { |
| 134 (*iter)->PrepareForOverview(); | 132 (*iter)->PrepareForOverview(); |
| 135 } | 133 } |
| 136 PositionWindows(/* animate */ true); | 134 PositionWindows(/* animate */ true); |
| 137 DCHECK(!windows_->empty()); | 135 DCHECK(!windows_->empty()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 InitializeSelectionWidget(); | 239 InitializeSelectionWidget(); |
| 242 selection_widget_->SetBounds(target_bounds); | 240 selection_widget_->SetBounds(target_bounds); |
| 243 } | 241 } |
| 244 selection_index_ = index; | 242 selection_index_ = index; |
| 245 } | 243 } |
| 246 | 244 |
| 247 void WindowOverview::OnWindowsChanged() { | 245 void WindowOverview::OnWindowsChanged() { |
| 248 PositionWindows(/* animate */ true); | 246 PositionWindows(/* animate */ true); |
| 249 } | 247 } |
| 250 | 248 |
| 251 void WindowOverview::MoveToSingleRootWindow(aura::Window* root_window) { | |
| 252 single_root_window_ = root_window; | |
| 253 PositionWindows(/* animate */ true); | |
| 254 } | |
| 255 | |
| 256 void WindowOverview::OnKeyEvent(ui::KeyEvent* event) { | 249 void WindowOverview::OnKeyEvent(ui::KeyEvent* event) { |
| 257 if (GetTargetedWindow(static_cast<aura::Window*>(event->target()))) | 250 if (GetTargetedWindow(static_cast<aura::Window*>(event->target()))) |
| 258 event->StopPropagation(); | 251 event->StopPropagation(); |
| 259 if (event->type() != ui::ET_KEY_PRESSED) | 252 if (event->type() != ui::ET_KEY_PRESSED) |
| 260 return; | 253 return; |
| 261 | 254 |
| 262 if (event->key_code() == ui::VKEY_ESCAPE) | 255 if (event->key_code() == ui::VKEY_ESCAPE) |
| 263 window_selector_->CancelSelection(); | 256 window_selector_->CancelSelection(); |
| 264 } | 257 } |
| 265 | 258 |
| 266 void WindowOverview::OnMouseEvent(ui::MouseEvent* event) { | 259 void WindowOverview::OnMouseEvent(ui::MouseEvent* event) { |
| 267 aura::Window* target = GetEventTarget(event); | 260 aura::Window* target = GetEventTarget(event); |
| 268 if (!target) | 261 if (!target) |
| 269 return; | 262 return; |
| 270 | 263 |
| 271 event->SetHandled(); | 264 event->StopPropagation(); |
|
tdanderson
2014/05/01 18:51:39
What is this change for?
Nina
2014/05/01 20:41:16
The reason was that with SetHandled the mouse even
tdanderson
2014/05/01 21:58:33
Sounds good (please file a separate bug for that).
| |
| 272 if (event->type() != ui::ET_MOUSE_RELEASED) | 265 if (event->type() != ui::ET_MOUSE_RELEASED) |
| 273 return; | 266 return; |
| 274 | 267 |
| 275 window_selector_->SelectWindow(target); | 268 window_selector_->SelectWindow(target); |
| 276 } | 269 } |
| 277 | 270 |
| 278 void WindowOverview::OnScrollEvent(ui::ScrollEvent* event) { | 271 void WindowOverview::OnScrollEvent(ui::ScrollEvent* event) { |
| 279 // Set the handled flag to prevent delivering scroll events to the window but | 272 // Set the handled flag to prevent delivering scroll events to the window but |
| 280 // still allowing other pretarget handlers to process the scroll event. | 273 // still allowing other pretarget handlers to process the scroll event. |
| 281 if (GetTargetedWindow(static_cast<aura::Window*>(event->target()))) | 274 if (GetTargetedWindow(static_cast<aura::Window*>(event->target()))) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 358 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 366 (*iter)->Hide(); | 359 (*iter)->Hide(); |
| 367 // Hiding the window can result in it being destroyed. | 360 // Hiding the window can result in it being destroyed. |
| 368 if (!hidden_windows_.Contains(*iter)) | 361 if (!hidden_windows_.Contains(*iter)) |
| 369 continue; | 362 continue; |
| 370 (*iter)->layer()->SetOpacity(0); | 363 (*iter)->layer()->SetOpacity(0); |
| 371 } | 364 } |
| 372 } | 365 } |
| 373 | 366 |
| 374 void WindowOverview::PositionWindows(bool animate) { | 367 void WindowOverview::PositionWindows(bool animate) { |
| 375 if (single_root_window_) { | 368 aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); |
| 376 std::vector<WindowSelectorItem*> windows; | 369 for (size_t i = 0; i < root_window_list.size(); ++i) |
| 377 for (WindowSelectorItemList::iterator iter = windows_->begin(); | 370 PositionWindowsFromRoot(root_window_list[i], animate); |
| 378 iter != windows_->end(); ++iter) { | |
| 379 windows.push_back(*iter); | |
| 380 } | |
| 381 PositionWindowsOnRoot(single_root_window_, windows, animate); | |
| 382 } else { | |
| 383 aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); | |
| 384 for (size_t i = 0; i < root_window_list.size(); ++i) | |
| 385 PositionWindowsFromRoot(root_window_list[i], animate); | |
| 386 } | |
| 387 } | 371 } |
| 388 | 372 |
| 389 void WindowOverview::PositionWindowsFromRoot(aura::Window* root_window, | 373 void WindowOverview::PositionWindowsFromRoot(aura::Window* root_window, |
| 390 bool animate) { | 374 bool animate) { |
| 391 std::vector<WindowSelectorItem*> windows; | 375 std::vector<WindowSelectorItem*> windows; |
| 392 for (WindowSelectorItemList::iterator iter = windows_->begin(); | 376 for (WindowSelectorItemList::iterator iter = windows_->begin(); |
| 393 iter != windows_->end(); ++iter) { | 377 iter != windows_->end(); ++iter) { |
| 394 if ((*iter)->GetRootWindow() == root_window) | 378 if ((*iter)->GetRootWindow() == root_window) |
| 395 windows.push_back(*iter); | 379 windows.push_back(*iter); |
| 396 } | 380 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 } | 426 } |
| 443 | 427 |
| 444 void WindowOverview::InitializeSelectionWidget() { | 428 void WindowOverview::InitializeSelectionWidget() { |
| 445 selection_widget_.reset(new views::Widget); | 429 selection_widget_.reset(new views::Widget); |
| 446 views::Widget::InitParams params; | 430 views::Widget::InitParams params; |
| 447 params.type = views::Widget::InitParams::TYPE_POPUP; | 431 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 448 params.can_activate = false; | 432 params.can_activate = false; |
| 449 params.keep_on_top = false; | 433 params.keep_on_top = false; |
| 450 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 434 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 451 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | 435 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
| 452 params.parent = Shell::GetContainer(single_root_window_ | 436 params.parent = Shell::GetContainer(windows_->front()->GetRootWindow(), |
| 453 ? single_root_window_ | |
| 454 : windows_->front()->GetRootWindow(), | |
| 455 kShellWindowId_DefaultContainer); | 437 kShellWindowId_DefaultContainer); |
| 456 params.accept_events = false; | 438 params.accept_events = false; |
| 457 selection_widget_->set_focus_on_creation(false); | 439 selection_widget_->set_focus_on_creation(false); |
| 458 selection_widget_->Init(params); | 440 selection_widget_->Init(params); |
| 459 views::View* content_view = new views::View; | 441 views::View* content_view = new views::View; |
| 460 content_view->set_background( | 442 content_view->set_background( |
| 461 views::Background::CreateSolidBackground(kWindowOverviewSelectionColor)); | 443 views::Background::CreateSolidBackground(kWindowOverviewSelectionColor)); |
| 462 selection_widget_->SetContentsView(content_view); | 444 selection_widget_->SetContentsView(content_view); |
| 463 selection_widget_->Show(); | 445 selection_widget_->Show(); |
| 464 selection_widget_->GetNativeWindow()->parent()->StackChildAtBottom( | 446 selection_widget_->GetNativeWindow()->parent()->StackChildAtBottom( |
| 465 selection_widget_->GetNativeWindow()); | 447 selection_widget_->GetNativeWindow()); |
| 466 selection_widget_->GetNativeWindow()->layer()->SetOpacity( | 448 selection_widget_->GetNativeWindow()->layer()->SetOpacity( |
| 467 kWindowOverviewSelectionOpacity); | 449 kWindowOverviewSelectionOpacity); |
| 468 } | 450 } |
| 469 | 451 |
| 470 gfx::Rect WindowOverview::GetSelectionBounds(size_t index) { | 452 gfx::Rect WindowOverview::GetSelectionBounds(size_t index) { |
| 471 gfx::Rect bounds((*windows_)[index]->bounds()); | 453 gfx::Rect bounds((*windows_)[index]->bounds()); |
| 472 bounds.Inset(-kWindowOverviewSelectionPadding, | 454 bounds.Inset(-kWindowOverviewSelectionPadding, |
| 473 -kWindowOverviewSelectionPadding); | 455 -kWindowOverviewSelectionPadding); |
| 474 return bounds; | 456 return bounds; |
| 475 } | 457 } |
| 476 | 458 |
| 477 } // namespace ash | 459 } // namespace ash |
| OLD | NEW |