OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/workspace/multi_window_resize_controller.h" | 5 #include "ash/wm/workspace/multi_window_resize_controller.h" |
6 | 6 |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/wm/coordinate_conversion.h" | 10 #include "ash/wm/coordinate_conversion.h" |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 std::vector<aura::Window*> windows; | 426 std::vector<aura::Window*> windows; |
427 windows.push_back(windows_.window2); | 427 windows.push_back(windows_.window2); |
428 DCHECK(windows_.other_windows.empty()); | 428 DCHECK(windows_.other_windows.empty()); |
429 FindWindowsTouching(windows_.window2, windows_.direction, | 429 FindWindowsTouching(windows_.window2, windows_.direction, |
430 &windows_.other_windows); | 430 &windows_.other_windows); |
431 for (size_t i = 0; i < windows_.other_windows.size(); ++i) { | 431 for (size_t i = 0; i < windows_.other_windows.size(); ++i) { |
432 windows_.other_windows[i]->AddObserver(this); | 432 windows_.other_windows[i]->AddObserver(this); |
433 windows.push_back(windows_.other_windows[i]); | 433 windows.push_back(windows_.other_windows[i]); |
434 } | 434 } |
435 int component = windows_.direction == LEFT_RIGHT ? HTRIGHT : HTBOTTOM; | 435 int component = windows_.direction == LEFT_RIGHT ? HTRIGHT : HTBOTTOM; |
436 window_resizer_.reset(WorkspaceWindowResizer::Create( | 436 scoped_ptr<DragDetails> details(new DragDetails( |
437 windows_.window1, | 437 windows_.window1, |
438 location_in_parent, | 438 location_in_parent, |
439 component, | 439 component, |
440 aura::client::WINDOW_MOVE_SOURCE_MOUSE, | 440 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
441 windows)); | 441 wm::WindowState* window_state = wm::GetWindowState(windows_.window1); |
| 442 window_state->set_drag_details(details.release()); |
| 443 window_resizer_.reset(WorkspaceWindowResizer::Create(window_state, windows)); |
442 } | 444 } |
443 | 445 |
444 void MultiWindowResizeController::Resize(const gfx::Point& location_in_screen, | 446 void MultiWindowResizeController::Resize(const gfx::Point& location_in_screen, |
445 int event_flags) { | 447 int event_flags) { |
446 gfx::Point location_in_parent(location_in_screen); | 448 gfx::Point location_in_parent(location_in_screen); |
447 aura::client::GetScreenPositionClient(windows_.window1->GetRootWindow())-> | 449 aura::client::GetScreenPositionClient(windows_.window1->GetRootWindow())-> |
448 ConvertPointFromScreen(windows_.window1->parent(), &location_in_parent); | 450 ConvertPointFromScreen(windows_.window1->parent(), &location_in_parent); |
449 window_resizer_->Drag(location_in_parent, event_flags); | 451 window_resizer_->Drag(location_in_parent, event_flags); |
450 gfx::Rect bounds = ScreenAsh::ConvertRectToScreen( | 452 gfx::Rect bounds = ScreenAsh::ConvertRectToScreen( |
451 windows_.window1->parent(), | 453 windows_.window1->parent(), |
452 CalculateResizeWidgetBounds(location_in_parent)); | 454 CalculateResizeWidgetBounds(location_in_parent)); |
453 | 455 |
454 if (windows_.direction == LEFT_RIGHT) | 456 if (windows_.direction == LEFT_RIGHT) |
455 bounds.set_y(show_bounds_in_screen_.y()); | 457 bounds.set_y(show_bounds_in_screen_.y()); |
456 else | 458 else |
457 bounds.set_x(show_bounds_in_screen_.x()); | 459 bounds.set_x(show_bounds_in_screen_.x()); |
458 resize_widget_->SetBounds(bounds); | 460 resize_widget_->SetBounds(bounds); |
459 } | 461 } |
460 | 462 |
461 void MultiWindowResizeController::CompleteResize() { | 463 void MultiWindowResizeController::CompleteResize() { |
462 window_resizer_->CompleteDrag(); | 464 window_resizer_->CompleteDrag(); |
| 465 wm::GetWindowState(window_resizer_->GetTarget())->set_drag_details(NULL); |
463 window_resizer_.reset(); | 466 window_resizer_.reset(); |
464 | 467 |
465 // Mouse may still be over resizer, if not hide. | 468 // Mouse may still be over resizer, if not hide. |
466 gfx::Point screen_loc = Shell::GetScreen()->GetCursorScreenPoint(); | 469 gfx::Point screen_loc = Shell::GetScreen()->GetCursorScreenPoint(); |
467 if (!resize_widget_->GetWindowBoundsInScreen().Contains(screen_loc)) { | 470 if (!resize_widget_->GetWindowBoundsInScreen().Contains(screen_loc)) { |
468 Hide(); | 471 Hide(); |
469 } else { | 472 } else { |
470 // If the mouse is over the resizer we need to remove observers on any of | 473 // If the mouse is over the resizer we need to remove observers on any of |
471 // the |other_windows|. If we start another resize we'll recalculate the | 474 // the |other_windows|. If we start another resize we'll recalculate the |
472 // |other_windows| and invoke AddObserver() as necessary. | 475 // |other_windows| and invoke AddObserver() as necessary. |
473 for (size_t i = 0; i < windows_.other_windows.size(); ++i) | 476 for (size_t i = 0; i < windows_.other_windows.size(); ++i) |
474 windows_.other_windows[i]->RemoveObserver(this); | 477 windows_.other_windows[i]->RemoveObserver(this); |
475 windows_.other_windows.clear(); | 478 windows_.other_windows.clear(); |
476 } | 479 } |
477 } | 480 } |
478 | 481 |
479 void MultiWindowResizeController::CancelResize() { | 482 void MultiWindowResizeController::CancelResize() { |
480 if (!window_resizer_) | 483 if (!window_resizer_) |
481 return; // Happens if window was destroyed and we nuked the WindowResizer. | 484 return; // Happens if window was destroyed and we nuked the WindowResizer. |
482 window_resizer_->RevertDrag(); | 485 window_resizer_->RevertDrag(); |
| 486 wm::GetWindowState(window_resizer_->GetTarget())->set_drag_details(NULL); |
483 window_resizer_.reset(); | 487 window_resizer_.reset(); |
484 Hide(); | 488 Hide(); |
485 } | 489 } |
486 | 490 |
487 gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds( | 491 gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds( |
488 const gfx::Point& location_in_parent) const { | 492 const gfx::Point& location_in_parent) const { |
489 gfx::Size pref = resize_widget_->GetContentsView()->GetPreferredSize(); | 493 gfx::Size pref = resize_widget_->GetContentsView()->GetPreferredSize(); |
490 int x = 0, y = 0; | 494 int x = 0, y = 0; |
491 if (windows_.direction == LEFT_RIGHT) { | 495 if (windows_.direction == LEFT_RIGHT) { |
492 x = windows_.window1->bounds().right() - pref.width() / 2; | 496 x = windows_.window1->bounds().right() - pref.width() / 2; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 540 |
537 gfx::Point window_loc(location_in_screen); | 541 gfx::Point window_loc(location_in_screen); |
538 aura::Window::ConvertPointToTarget( | 542 aura::Window::ConvertPointToTarget( |
539 window->GetRootWindow(), window, &window_loc); | 543 window->GetRootWindow(), window, &window_loc); |
540 return window->HitTest(window_loc) && | 544 return window->HitTest(window_loc) && |
541 window->delegate()->GetNonClientComponent(window_loc) == component; | 545 window->delegate()->GetNonClientComponent(window_loc) == component; |
542 } | 546 } |
543 | 547 |
544 } // namespace internal | 548 } // namespace internal |
545 } // namespace ash | 549 } // namespace ash |
OLD | NEW |