| 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/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/wm/window_state.h" | 9 #include "ash/wm/window_state.h" |
| 10 #include "ash/wm/workspace/workspace_window_resizer.h" | 10 #include "ash/wm/workspace/workspace_window_resizer.h" |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 FindWindowsTouching(windows_.window2, windows_.direction, | 471 FindWindowsTouching(windows_.window2, windows_.direction, |
| 472 &windows_.other_windows); | 472 &windows_.other_windows); |
| 473 for (size_t i = 0; i < windows_.other_windows.size(); ++i) { | 473 for (size_t i = 0; i < windows_.other_windows.size(); ++i) { |
| 474 windows_.other_windows[i]->AddObserver(this); | 474 windows_.other_windows[i]->AddObserver(this); |
| 475 windows.push_back(windows_.other_windows[i]); | 475 windows.push_back(windows_.other_windows[i]); |
| 476 } | 476 } |
| 477 int component = windows_.direction == LEFT_RIGHT ? HTRIGHT : HTBOTTOM; | 477 int component = windows_.direction == LEFT_RIGHT ? HTRIGHT : HTBOTTOM; |
| 478 wm::WindowState* window_state = wm::GetWindowState(windows_.window1); | 478 wm::WindowState* window_state = wm::GetWindowState(windows_.window1); |
| 479 window_state->CreateDragDetails(location_in_parent, component, | 479 window_state->CreateDragDetails(location_in_parent, component, |
| 480 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 480 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 481 window_resizer_.reset(WorkspaceWindowResizer::Create( | 481 window_resizer_.reset(WorkspaceWindowResizer::Create(window_state, windows)); |
| 482 window_state, WmWindow::FromAuraWindows(windows))); | |
| 483 | 482 |
| 484 // Do not hide the resize widget while a drag is active. | 483 // Do not hide the resize widget while a drag is active. |
| 485 mouse_watcher_.reset(); | 484 mouse_watcher_.reset(); |
| 486 } | 485 } |
| 487 | 486 |
| 488 void MultiWindowResizeController::Resize(const gfx::Point& location_in_screen, | 487 void MultiWindowResizeController::Resize(const gfx::Point& location_in_screen, |
| 489 int event_flags) { | 488 int event_flags) { |
| 490 gfx::Point location_in_parent = | 489 gfx::Point location_in_parent = |
| 491 ConvertPointFromScreen(windows_.window1->parent(), location_in_screen); | 490 ConvertPointFromScreen(windows_.window1->parent(), location_in_screen); |
| 492 window_resizer_->Drag(location_in_parent, event_flags); | 491 window_resizer_->Drag(location_in_parent, event_flags); |
| 493 gfx::Rect bounds = | 492 gfx::Rect bounds = |
| 494 ConvertRectToScreen(windows_.window1->parent(), | 493 ConvertRectToScreen(windows_.window1->parent(), |
| 495 CalculateResizeWidgetBounds(location_in_parent)); | 494 CalculateResizeWidgetBounds(location_in_parent)); |
| 496 | 495 |
| 497 if (windows_.direction == LEFT_RIGHT) | 496 if (windows_.direction == LEFT_RIGHT) |
| 498 bounds.set_y(show_bounds_in_screen_.y()); | 497 bounds.set_y(show_bounds_in_screen_.y()); |
| 499 else | 498 else |
| 500 bounds.set_x(show_bounds_in_screen_.x()); | 499 bounds.set_x(show_bounds_in_screen_.x()); |
| 501 resize_widget_->SetBounds(bounds); | 500 resize_widget_->SetBounds(bounds); |
| 502 } | 501 } |
| 503 | 502 |
| 504 void MultiWindowResizeController::CompleteResize() { | 503 void MultiWindowResizeController::CompleteResize() { |
| 505 window_resizer_->CompleteDrag(); | 504 window_resizer_->CompleteDrag(); |
| 506 window_resizer_->GetTarget()->GetWindowState()->DeleteDragDetails(); | 505 wm::GetWindowState(window_resizer_->GetTarget())->DeleteDragDetails(); |
| 507 window_resizer_.reset(); | 506 window_resizer_.reset(); |
| 508 | 507 |
| 509 // Mouse may still be over resizer, if not hide. | 508 // Mouse may still be over resizer, if not hide. |
| 510 gfx::Point screen_loc = display::Screen::GetScreen()->GetCursorScreenPoint(); | 509 gfx::Point screen_loc = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 511 if (!resize_widget_->GetWindowBoundsInScreen().Contains(screen_loc)) { | 510 if (!resize_widget_->GetWindowBoundsInScreen().Contains(screen_loc)) { |
| 512 Hide(); | 511 Hide(); |
| 513 } else { | 512 } else { |
| 514 // If the mouse is over the resizer we need to remove observers on any of | 513 // If the mouse is over the resizer we need to remove observers on any of |
| 515 // the |other_windows|. If we start another resize we'll recalculate the | 514 // the |other_windows|. If we start another resize we'll recalculate the |
| 516 // |other_windows| and invoke AddObserver() as necessary. | 515 // |other_windows| and invoke AddObserver() as necessary. |
| 517 for (size_t i = 0; i < windows_.other_windows.size(); ++i) | 516 for (size_t i = 0; i < windows_.other_windows.size(); ++i) |
| 518 windows_.other_windows[i]->RemoveObserver(this); | 517 windows_.other_windows[i]->RemoveObserver(this); |
| 519 windows_.other_windows.clear(); | 518 windows_.other_windows.clear(); |
| 520 | 519 |
| 521 CreateMouseWatcher(); | 520 CreateMouseWatcher(); |
| 522 } | 521 } |
| 523 } | 522 } |
| 524 | 523 |
| 525 void MultiWindowResizeController::CancelResize() { | 524 void MultiWindowResizeController::CancelResize() { |
| 526 if (!window_resizer_) | 525 if (!window_resizer_) |
| 527 return; // Happens if window was destroyed and we nuked the WindowResizer. | 526 return; // Happens if window was destroyed and we nuked the WindowResizer. |
| 528 window_resizer_->RevertDrag(); | 527 window_resizer_->RevertDrag(); |
| 529 window_resizer_->GetTarget()->GetWindowState()->DeleteDragDetails(); | 528 wm::GetWindowState(window_resizer_->GetTarget())->DeleteDragDetails(); |
| 530 window_resizer_.reset(); | 529 window_resizer_.reset(); |
| 531 Hide(); | 530 Hide(); |
| 532 } | 531 } |
| 533 | 532 |
| 534 gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds( | 533 gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds( |
| 535 const gfx::Point& location_in_parent) const { | 534 const gfx::Point& location_in_parent) const { |
| 536 gfx::Size pref = resize_widget_->GetContentsView()->GetPreferredSize(); | 535 gfx::Size pref = resize_widget_->GetContentsView()->GetPreferredSize(); |
| 537 int x = 0, y = 0; | 536 int x = 0, y = 0; |
| 538 if (windows_.direction == LEFT_RIGHT) { | 537 if (windows_.direction == LEFT_RIGHT) { |
| 539 x = windows_.window1->bounds().right() - pref.width() / 2; | 538 x = windows_.window1->bounds().right() - pref.width() / 2; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 const gfx::Point& location_in_screen, | 596 const gfx::Point& location_in_screen, |
| 598 int component) const { | 597 int component) const { |
| 599 gfx::Point window_loc = ConvertPointFromScreen(window, location_in_screen); | 598 gfx::Point window_loc = ConvertPointFromScreen(window, location_in_screen); |
| 600 const int window_component = | 599 const int window_component = |
| 601 window->delegate() ? window->delegate()->GetNonClientComponent(window_loc) | 600 window->delegate() ? window->delegate()->GetNonClientComponent(window_loc) |
| 602 : HTNOWHERE; | 601 : HTNOWHERE; |
| 603 return window_component == component; | 602 return window_component == component; |
| 604 } | 603 } |
| 605 | 604 |
| 606 } // namespace ash | 605 } // namespace ash |
| OLD | NEW |