Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: ash/wm/workspace/workspace_window_resizer.cc

Issue 127053005: Cleanup: remove Details::window. Use GetTarget() when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 379 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
380 sticky_size = kScreenEdgeInsetForTouchResize; 380 sticky_size = kScreenEdgeInsetForTouchResize;
381 } else { 381 } else {
382 sticky_size = kScreenEdgeInset; 382 sticky_size = kScreenEdgeInset;
383 } 383 }
384 // |bounds| is in |window()->parent()|'s coordinates. 384 // |bounds| is in |window()->parent()|'s coordinates.
385 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); 385 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent);
386 if (window_state()->IsNormalShowState()) 386 if (window_state()->IsNormalShowState())
387 AdjustBoundsForMainWindow(sticky_size, &bounds); 387 AdjustBoundsForMainWindow(sticky_size, &bounds);
388 388
389 if (bounds != window()->bounds()) { 389 if (bounds != GetTarget()->bounds()) {
390 if (!did_move_or_resize_) { 390 if (!did_move_or_resize_) {
391 if (!details_.restore_bounds.IsEmpty()) 391 if (!details_.restore_bounds.IsEmpty())
392 window_state()->ClearRestoreBounds(); 392 window_state()->ClearRestoreBounds();
393 RestackWindows(); 393 RestackWindows();
394 } 394 }
395 did_move_or_resize_ = true; 395 did_move_or_resize_ = true;
396 } 396 }
397 397
398 gfx::Point location_in_screen = location_in_parent; 398 gfx::Point location_in_screen = location_in_parent;
399 wm::ConvertPointToScreen(window()->parent(), &location_in_screen); 399 wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen);
400 400
401 aura::Window* root = NULL; 401 aura::Window* root = NULL;
402 gfx::Display display = 402 gfx::Display display =
403 ScreenAsh::FindDisplayContainingPoint(location_in_screen); 403 ScreenAsh::FindDisplayContainingPoint(location_in_screen);
404 // Track the last screen that the pointer was on to keep the snap phantom 404 // Track the last screen that the pointer was on to keep the snap phantom
405 // window there. 405 // window there.
406 if (display.is_valid()) { 406 if (display.is_valid()) {
407 root = Shell::GetInstance()->display_controller()-> 407 root = Shell::GetInstance()->display_controller()->
408 GetRootWindowForDisplayId(display.id()); 408 GetRootWindowForDisplayId(display.id());
409 } 409 }
410 if (!attached_windows_.empty()) 410 if (!attached_windows_.empty())
411 LayoutAttachedWindows(&bounds); 411 LayoutAttachedWindows(&bounds);
412 if (bounds != window()->bounds()) { 412 if (bounds != GetTarget()->bounds()) {
413 // SetBounds needs to be called to update the layout which affects where the 413 // SetBounds needs to be called to update the layout which affects where the
414 // phantom window is drawn. Keep track if the window was destroyed during 414 // phantom window is drawn. Keep track if the window was destroyed during
415 // the drag and quit early if so. 415 // the drag and quit early if so.
416 base::WeakPtr<WorkspaceWindowResizer> resizer( 416 base::WeakPtr<WorkspaceWindowResizer> resizer(
417 weak_ptr_factory_.GetWeakPtr()); 417 weak_ptr_factory_.GetWeakPtr());
418 window()->SetBounds(bounds); 418 GetTarget()->SetBounds(bounds);
419 if (!resizer) 419 if (!resizer)
420 return; 420 return;
421 } 421 }
422 const bool in_original_root = !root || root == window()->GetRootWindow(); 422 const bool in_original_root = !root || root == GetTarget()->GetRootWindow();
423 // Hide a phantom window for snapping if the cursor is in another root window. 423 // Hide a phantom window for snapping if the cursor is in another root window.
424 if (in_original_root) { 424 if (in_original_root) {
425 UpdateSnapPhantomWindow(location_in_parent, bounds); 425 UpdateSnapPhantomWindow(location_in_parent, bounds);
426 } else { 426 } else {
427 snap_type_ = SNAP_NONE; 427 snap_type_ = SNAP_NONE;
428 snap_phantom_window_controller_.reset(); 428 snap_phantom_window_controller_.reset();
429 snap_sizer_.reset(); 429 snap_sizer_.reset();
430 SetDraggedWindowDocked(false); 430 SetDraggedWindowDocked(false);
431 } 431 }
432 } 432 }
433 433
434 void WorkspaceWindowResizer::CompleteDrag() { 434 void WorkspaceWindowResizer::CompleteDrag() {
435 window_state()->set_bounds_changed_by_user(true); 435 window_state()->set_bounds_changed_by_user(true);
436 snap_phantom_window_controller_.reset(); 436 snap_phantom_window_controller_.reset();
437 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 437 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
438 return; 438 return;
439 439
440 bool snapped = false; 440 bool snapped = false;
441 // When the window is not in the normal show state, we do not snap the window. 441 // When the window is not in the normal show state, we do not snap the window.
442 // This happens when the user minimizes or maximizes the window by keyboard 442 // This happens when the user minimizes or maximizes the window by keyboard
443 // shortcut while dragging it. If the window is the result of dragging a tab 443 // shortcut while dragging it. If the window is the result of dragging a tab
444 // out of a maximized window, it's already in the normal show state when this 444 // out of a maximized window, it's already in the normal show state when this
445 // is called, so it does not matter. 445 // is called, so it does not matter.
446 if (window_state()->IsNormalShowState() && 446 if (window_state()->IsNormalShowState() &&
447 (window()->type() != ui::wm::WINDOW_TYPE_PANEL || 447 (GetTarget()->type() != ui::wm::WINDOW_TYPE_PANEL ||
448 !window_state()->panel_attached() || 448 !window_state()->panel_attached() ||
449 dock_layout_->is_dragged_window_docked()) && 449 dock_layout_->is_dragged_window_docked()) &&
450 (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { 450 (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) {
451 if (!window_state()->HasRestoreBounds()) { 451 if (!window_state()->HasRestoreBounds()) {
452 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( 452 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen(
453 window()->parent(), details_.initial_bounds_in_parent); 453 GetTarget()->parent(), details_.initial_bounds_in_parent);
454 window_state()->SetRestoreBoundsInScreen( 454 window_state()->SetRestoreBoundsInScreen(
455 details_.restore_bounds.IsEmpty() ? 455 details_.restore_bounds.IsEmpty() ?
456 initial_bounds : 456 initial_bounds :
457 details_.restore_bounds); 457 details_.restore_bounds);
458 } 458 }
459 DCHECK(snap_sizer_); 459 DCHECK(snap_sizer_);
460 if (window_state()->CanResize() && 460 if (window_state()->CanResize() &&
461 !dock_layout_->is_dragged_window_docked()) { 461 !dock_layout_->is_dragged_window_docked()) {
462 snap_sizer_->SnapWindowToTargetBounds(); 462 snap_sizer_->SnapWindowToTargetBounds();
463 snapped = true; 463 snapped = true;
464 } 464 }
465 } 465 }
466 if (window_state()->IsSnapped() && !snapped) 466 if (window_state()->IsSnapped() && !snapped)
467 window_state()->Restore(); 467 window_state()->Restore();
468 } 468 }
469 469
470 void WorkspaceWindowResizer::RevertDrag() { 470 void WorkspaceWindowResizer::RevertDrag() {
471 window_state()->set_bounds_changed_by_user(initial_bounds_changed_by_user_); 471 window_state()->set_bounds_changed_by_user(initial_bounds_changed_by_user_);
472 snap_phantom_window_controller_.reset(); 472 snap_phantom_window_controller_.reset();
473 473
474 if (!did_move_or_resize_) 474 if (!did_move_or_resize_)
475 return; 475 return;
476 476
477 window()->SetBounds(details_.initial_bounds_in_parent); 477 GetTarget()->SetBounds(details_.initial_bounds_in_parent);
478 if (!details_.restore_bounds.IsEmpty()) { 478 if (!details_.restore_bounds.IsEmpty()) {
479 window_state()->SetRestoreBoundsInScreen(details_.restore_bounds); 479 window_state()->SetRestoreBoundsInScreen(details_.restore_bounds);
480 } 480 }
481 481
482 if (details_.window_component == HTRIGHT) { 482 if (details_.window_component == HTRIGHT) {
483 int last_x = details_.initial_bounds_in_parent.right(); 483 int last_x = details_.initial_bounds_in_parent.right();
484 for (size_t i = 0; i < attached_windows_.size(); ++i) { 484 for (size_t i = 0; i < attached_windows_.size(); ++i) {
485 gfx::Rect bounds(attached_windows_[i]->bounds()); 485 gfx::Rect bounds(attached_windows_[i]->bounds());
486 bounds.set_x(last_x); 486 bounds.set_x(last_x);
487 bounds.set_width(initial_size_[i]); 487 bounds.set_width(initial_size_[i]);
488 attached_windows_[i]->SetBounds(bounds); 488 attached_windows_[i]->SetBounds(bounds);
489 last_x = attached_windows_[i]->bounds().right(); 489 last_x = attached_windows_[i]->bounds().right();
490 } 490 }
491 } else { 491 } else {
492 int last_y = details_.initial_bounds_in_parent.bottom(); 492 int last_y = details_.initial_bounds_in_parent.bottom();
493 for (size_t i = 0; i < attached_windows_.size(); ++i) { 493 for (size_t i = 0; i < attached_windows_.size(); ++i) {
494 gfx::Rect bounds(attached_windows_[i]->bounds()); 494 gfx::Rect bounds(attached_windows_[i]->bounds());
495 bounds.set_y(last_y); 495 bounds.set_y(last_y);
496 bounds.set_height(initial_size_[i]); 496 bounds.set_height(initial_size_[i]);
497 attached_windows_[i]->SetBounds(bounds); 497 attached_windows_[i]->SetBounds(bounds);
498 last_y = attached_windows_[i]->bounds().bottom(); 498 last_y = attached_windows_[i]->bounds().bottom();
499 } 499 }
500 } 500 }
501 } 501 }
502 502
503 aura::Window* WorkspaceWindowResizer::GetTarget() { 503 aura::Window* WorkspaceWindowResizer::GetTarget() {
varkha 2014/01/08 23:46:56 Should this be const (and virtual OVERRIDE)?
504 return details_.window; 504 return details_.window();
505 } 505 }
506 506
507 const gfx::Point& WorkspaceWindowResizer::GetInitialLocation() const { 507 const gfx::Point& WorkspaceWindowResizer::GetInitialLocation() const {
508 return details_.initial_location_in_parent; 508 return details_.initial_location_in_parent;
509 } 509 }
510 510
511 WorkspaceWindowResizer::WorkspaceWindowResizer( 511 WorkspaceWindowResizer::WorkspaceWindowResizer(
512 const Details& details, 512 const Details& details,
513 const std::vector<aura::Window*>& attached_windows) 513 const std::vector<aura::Window*>& attached_windows)
514 : details_(details), 514 : details_(details),
(...skipping 12 matching lines...) Expand all
527 527
528 // A mousemove should still show the cursor even if the window is 528 // A mousemove should still show the cursor even if the window is
529 // being moved or resized with touch, so do not lock the cursor. 529 // being moved or resized with touch, so do not lock the cursor.
530 if (details.source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 530 if (details.source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
531 Shell* shell = Shell::GetInstance(); 531 Shell* shell = Shell::GetInstance();
532 shell->cursor_manager()->LockCursor(); 532 shell->cursor_manager()->LockCursor();
533 did_lock_cursor_ = true; 533 did_lock_cursor_ = true;
534 } 534 }
535 535
536 aura::Window* dock_container = Shell::GetContainer( 536 aura::Window* dock_container = Shell::GetContainer(
537 window()->GetRootWindow(), kShellWindowId_DockedContainer); 537 GetTarget()->GetRootWindow(), kShellWindowId_DockedContainer);
538 dock_layout_ = static_cast<DockedWindowLayoutManager*>( 538 dock_layout_ = static_cast<DockedWindowLayoutManager*>(
539 dock_container->layout_manager()); 539 dock_container->layout_manager());
540 540
541 // Only support attaching to the right/bottom. 541 // Only support attaching to the right/bottom.
542 DCHECK(attached_windows_.empty() || 542 DCHECK(attached_windows_.empty() ||
543 (details.window_component == HTRIGHT || 543 (details.window_component == HTRIGHT ||
544 details.window_component == HTBOTTOM)); 544 details.window_component == HTBOTTOM));
545 545
546 // TODO: figure out how to deal with window going off the edge. 546 // TODO: figure out how to deal with window going off the edge.
547 547
(...skipping 18 matching lines...) Expand all
566 const gfx::Rect& bounds) const { 566 const gfx::Rect& bounds) const {
567 if (snap_phantom_window_controller_.get() && 567 if (snap_phantom_window_controller_.get() &&
568 snap_phantom_window_controller_->IsShowing()) { 568 snap_phantom_window_controller_->IsShowing()) {
569 return snap_phantom_window_controller_->bounds_in_screen(); 569 return snap_phantom_window_controller_->bounds_in_screen();
570 } 570 }
571 return bounds; 571 return bounds;
572 } 572 }
573 573
574 void WorkspaceWindowResizer::LayoutAttachedWindows( 574 void WorkspaceWindowResizer::LayoutAttachedWindows(
575 gfx::Rect* bounds) { 575 gfx::Rect* bounds) {
576 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window())); 576 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(GetTarget()));
577 int initial_size = PrimaryAxisSize(details_.initial_bounds_in_parent.size()); 577 int initial_size = PrimaryAxisSize(details_.initial_bounds_in_parent.size());
578 int current_size = PrimaryAxisSize(bounds->size()); 578 int current_size = PrimaryAxisSize(bounds->size());
579 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); 579 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom());
580 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); 580 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom());
581 581
582 int delta = current_size - initial_size; 582 int delta = current_size - initial_size;
583 int available_size = end - start; 583 int available_size = end - start;
584 std::vector<int> sizes; 584 std::vector<int> sizes;
585 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes); 585 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes);
586 586
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 int min = PrimaryAxisSize(delegate->GetMinimumSize()); 706 int min = PrimaryAxisSize(delegate->GetMinimumSize());
707 int max = PrimaryAxisSize(delegate->GetMaximumSize()); 707 int max = PrimaryAxisSize(delegate->GetMaximumSize());
708 708
709 sizes->push_back(WindowSize(initial_size, min, max)); 709 sizes->push_back(WindowSize(initial_size, min, max));
710 } 710 }
711 } 711 }
712 712
713 void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) { 713 void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) {
714 if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) { 714 if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) {
715 gfx::Point point = OriginForMagneticAttach( 715 gfx::Point point = OriginForMagneticAttach(
716 ScreenAsh::ConvertRectToScreen(window()->parent(), *bounds), 716 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), *bounds),
717 magnetism_window_->GetBoundsInScreen(), 717 magnetism_window_->GetBoundsInScreen(),
718 magnetism_edge_); 718 magnetism_edge_);
719 aura::client::GetScreenPositionClient(window()->GetRootWindow())-> 719 aura::client::GetScreenPositionClient(GetTarget()->GetRootWindow())->
720 ConvertPointFromScreen(window()->parent(), &point); 720 ConvertPointFromScreen(GetTarget()->parent(), &point);
721 bounds->set_origin(point); 721 bounds->set_origin(point);
722 } 722 }
723 } 723 }
724 724
725 void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows( 725 void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows(
726 gfx::Rect* bounds) { 726 gfx::Rect* bounds) {
727 const uint32 edges = WindowComponentToMagneticEdge(details_.window_component); 727 const uint32 edges = WindowComponentToMagneticEdge(details_.window_component);
728 if (UpdateMagnetismWindow(*bounds, edges)) { 728 if (UpdateMagnetismWindow(*bounds, edges)) {
729 *bounds = ScreenAsh::ConvertRectFromScreen( 729 *bounds = ScreenAsh::ConvertRectFromScreen(
730 window()->parent(), 730 GetTarget()->parent(),
731 BoundsForMagneticResizeAttach( 731 BoundsForMagneticResizeAttach(
732 ScreenAsh::ConvertRectToScreen(window()->parent(), *bounds), 732 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), *bounds),
733 magnetism_window_->GetBoundsInScreen(), 733 magnetism_window_->GetBoundsInScreen(),
734 magnetism_edge_)); 734 magnetism_edge_));
735 } 735 }
736 } 736 }
737 737
738 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds, 738 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds,
739 uint32 edges) { 739 uint32 edges) {
740 // |bounds| are in coordinates of original window's parent. 740 // |bounds| are in coordinates of original window's parent.
741 gfx::Rect bounds_in_screen = 741 gfx::Rect bounds_in_screen =
742 ScreenAsh::ConvertRectToScreen(window()->parent(), bounds); 742 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), bounds);
743 MagnetismMatcher matcher(bounds_in_screen, edges); 743 MagnetismMatcher matcher(bounds_in_screen, edges);
744 744
745 // If we snapped to a window then check it first. That way we don't bounce 745 // If we snapped to a window then check it first. That way we don't bounce
746 // around when close to multiple edges. 746 // around when close to multiple edges.
747 if (magnetism_window_) { 747 if (magnetism_window_) {
748 if (window_tracker_.Contains(magnetism_window_) && 748 if (window_tracker_.Contains(magnetism_window_) &&
749 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), 749 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(),
750 &magnetism_edge_)) { 750 &magnetism_edge_)) {
751 return true; 751 return true;
752 } 752 }
753 window_tracker_.Remove(magnetism_window_); 753 window_tracker_.Remove(magnetism_window_);
754 magnetism_window_ = NULL; 754 magnetism_window_ = NULL;
755 } 755 }
756 756
757 // Avoid magnetically snapping windows that are not resizable. 757 // Avoid magnetically snapping windows that are not resizable.
758 // TODO(oshima): change this to window.type() == TYPE_NORMAL. 758 // TODO(oshima): change this to window.type() == TYPE_NORMAL.
759 if (!window_state()->CanResize()) 759 if (!window_state()->CanResize())
760 return false; 760 return false;
761 761
762 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 762 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
763 for (aura::Window::Windows::iterator iter = root_windows.begin(); 763 for (aura::Window::Windows::iterator iter = root_windows.begin();
764 iter != root_windows.end(); ++iter) { 764 iter != root_windows.end(); ++iter) {
765 const aura::Window* root_window = *iter; 765 const aura::Window* root_window = *iter;
766 // Test all children from the desktop in each root window. 766 // Test all children from the desktop in each root window.
767 const aura::Window::Windows& children = Shell::GetContainer( 767 const aura::Window::Windows& children = Shell::GetContainer(
768 root_window, kShellWindowId_DefaultContainer)->children(); 768 root_window, kShellWindowId_DefaultContainer)->children();
769 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin(); 769 for (aura::Window::Windows::const_reverse_iterator i = children.rbegin();
770 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { 770 i != children.rend() && !matcher.AreEdgesObscured(); ++i) {
771 wm::WindowState* other_state = wm::GetWindowState(*i); 771 wm::WindowState* other_state = wm::GetWindowState(*i);
772 if (other_state->window() == window() || 772 if (other_state->window() == GetTarget() ||
773 !other_state->window()->IsVisible() || 773 !other_state->window()->IsVisible() ||
774 !other_state->IsNormalShowState() || 774 !other_state->IsNormalShowState() ||
775 !other_state->CanResize()) { 775 !other_state->CanResize()) {
776 continue; 776 continue;
777 } 777 }
778 if (matcher.ShouldAttach( 778 if (matcher.ShouldAttach(
779 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) { 779 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) {
780 magnetism_window_ = other_state->window(); 780 magnetism_window_ = other_state->window();
781 window_tracker_.Add(magnetism_window_); 781 window_tracker_.Add(magnetism_window_);
782 return true; 782 return true;
783 } 783 }
784 } 784 }
785 } 785 }
786 return false; 786 return false;
787 } 787 }
788 788
789 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( 789 void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
790 int sticky_size, 790 int sticky_size,
791 gfx::Rect* bounds) { 791 gfx::Rect* bounds) {
792 gfx::Point last_mouse_location_in_screen = last_mouse_location_; 792 gfx::Point last_mouse_location_in_screen = last_mouse_location_;
793 wm::ConvertPointToScreen(window()->parent(), &last_mouse_location_in_screen); 793 wm::ConvertPointToScreen(GetTarget()->parent(),
794 &last_mouse_location_in_screen);
794 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint( 795 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(
795 last_mouse_location_in_screen); 796 last_mouse_location_in_screen);
796 gfx::Rect work_area = 797 gfx::Rect work_area = ScreenAsh::ConvertRectFromScreen(GetTarget()->parent(),
797 ScreenAsh::ConvertRectFromScreen(window()->parent(), display.work_area()); 798 display.work_area());
798 if (details_.window_component == HTCAPTION) { 799 if (details_.window_component == HTCAPTION) {
799 // Adjust the bounds to the work area where the mouse cursor is located. 800 // Adjust the bounds to the work area where the mouse cursor is located.
800 // Always keep kMinOnscreenHeight or the window height (whichever is less) 801 // Always keep kMinOnscreenHeight or the window height (whichever is less)
801 // on the bottom. 802 // on the bottom.
802 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight, 803 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight,
803 bounds->height()); 804 bounds->height());
804 if (bounds->y() > max_y) { 805 if (bounds->y() > max_y) {
805 bounds->set_y(max_y); 806 bounds->set_y(max_y);
806 } else if (bounds->y() <= work_area.y()) { 807 } else if (bounds->y() <= work_area.y()) {
807 // Don't allow dragging above the top of the display until the mouse 808 // Don't allow dragging above the top of the display until the mouse
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 SnapType last_type = snap_type_; 920 SnapType last_type = snap_type_;
920 snap_type_ = GetSnapType(location); 921 snap_type_ = GetSnapType(location);
921 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { 922 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) {
922 snap_phantom_window_controller_.reset(); 923 snap_phantom_window_controller_.reset();
923 snap_sizer_.reset(); 924 snap_sizer_.reset();
924 if (snap_type_ == SNAP_NONE) { 925 if (snap_type_ == SNAP_NONE) {
925 SetDraggedWindowDocked(false); 926 SetDraggedWindowDocked(false);
926 return; 927 return;
927 } 928 }
928 } 929 }
929 const bool can_dock = dock_layout_->CanDockWindow(window(), snap_type_); 930 const bool can_dock = dock_layout_->CanDockWindow(GetTarget(), snap_type_);
930 const bool can_snap = window_state()->CanSnap(); 931 const bool can_snap = window_state()->CanSnap();
931 if (!can_snap && !can_dock) { 932 if (!can_snap && !can_dock) {
932 snap_type_ = SNAP_NONE; 933 snap_type_ = SNAP_NONE;
933 snap_phantom_window_controller_.reset(); 934 snap_phantom_window_controller_.reset();
934 snap_sizer_.reset(); 935 snap_sizer_.reset();
935 SetDraggedWindowDocked(false); 936 SetDraggedWindowDocked(false);
936 return; 937 return;
937 } 938 }
938 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ? 939 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ?
939 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; 940 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE;
940 if (!snap_sizer_) { 941 if (!snap_sizer_) {
941 snap_sizer_.reset(new SnapSizer(window_state(), 942 snap_sizer_.reset(new SnapSizer(window_state(),
942 location, 943 location,
943 edge, 944 edge,
944 internal::SnapSizer::OTHER_INPUT)); 945 internal::SnapSizer::OTHER_INPUT));
945 } else { 946 } else {
946 snap_sizer_->Update(location); 947 snap_sizer_->Update(location);
947 } 948 }
948 949
949 // Update phantom window with snapped or docked guide bounds. 950 // Update phantom window with snapped or docked guide bounds.
950 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get 951 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get
951 // docked without going through a snapping sequence. 952 // docked without going through a snapping sequence.
952 gfx::Rect phantom_bounds; 953 gfx::Rect phantom_bounds;
953 if (can_snap && 954 if (can_snap &&
954 (!can_dock || 955 (!can_dock ||
955 window()->bounds().width() > DockedWindowLayoutManager::kMaxDockWidth)) 956 GetTarget()->bounds().width() >
957 DockedWindowLayoutManager::kMaxDockWidth))
956 phantom_bounds = snap_sizer_->target_bounds(); 958 phantom_bounds = snap_sizer_->target_bounds();
957 const bool should_dock = can_dock && 959 const bool should_dock = can_dock &&
958 (phantom_bounds.IsEmpty() || 960 (phantom_bounds.IsEmpty() ||
959 snap_sizer_->end_of_sequence() || 961 snap_sizer_->end_of_sequence() ||
960 dock_layout_->is_dragged_window_docked()); 962 dock_layout_->is_dragged_window_docked());
961 SetDraggedWindowDocked(should_dock); 963 SetDraggedWindowDocked(should_dock);
962 snap_type_ = GetSnapType(location); 964 snap_type_ = GetSnapType(location);
963 if (dock_layout_->is_dragged_window_docked()) { 965 if (dock_layout_->is_dragged_window_docked()) {
964 phantom_bounds = ScreenAsh::ConvertRectFromScreen( 966 phantom_bounds = ScreenAsh::ConvertRectFromScreen(
965 window()->parent(), dock_layout_->dragged_bounds()); 967 GetTarget()->parent(), dock_layout_->dragged_bounds());
966 } 968 }
967 969
968 if (phantom_bounds.IsEmpty()) { 970 if (phantom_bounds.IsEmpty()) {
969 snap_phantom_window_controller_.reset(); 971 snap_phantom_window_controller_.reset();
970 return; 972 return;
971 } 973 }
972 974
973 if (!snap_phantom_window_controller_) { 975 if (!snap_phantom_window_controller_) {
974 snap_phantom_window_controller_.reset( 976 snap_phantom_window_controller_.reset(
975 new PhantomWindowController(window())); 977 new PhantomWindowController(GetTarget()));
976 } 978 }
977 snap_phantom_window_controller_->Show(ScreenAsh::ConvertRectToScreen( 979 snap_phantom_window_controller_->Show(ScreenAsh::ConvertRectToScreen(
978 window()->parent(), phantom_bounds)); 980 GetTarget()->parent(), phantom_bounds));
979 } 981 }
980 982
981 void WorkspaceWindowResizer::RestackWindows() { 983 void WorkspaceWindowResizer::RestackWindows() {
982 if (attached_windows_.empty()) 984 if (attached_windows_.empty())
983 return; 985 return;
984 // Build a map from index in children to window, returning if there is a 986 // Build a map from index in children to window, returning if there is a
985 // window with a different parent. 987 // window with a different parent.
986 typedef std::map<size_t, aura::Window*> IndexToWindowMap; 988 typedef std::map<size_t, aura::Window*> IndexToWindowMap;
987 IndexToWindowMap map; 989 IndexToWindowMap map;
988 aura::Window* parent = window()->parent(); 990 aura::Window* parent = GetTarget()->parent();
989 const aura::Window::Windows& windows(parent->children()); 991 const aura::Window::Windows& windows(parent->children());
990 map[std::find(windows.begin(), windows.end(), window()) - 992 map[std::find(windows.begin(), windows.end(), GetTarget()) -
991 windows.begin()] = window(); 993 windows.begin()] = GetTarget();
992 for (std::vector<aura::Window*>::const_iterator i = 994 for (std::vector<aura::Window*>::const_iterator i =
993 attached_windows_.begin(); i != attached_windows_.end(); ++i) { 995 attached_windows_.begin(); i != attached_windows_.end(); ++i) {
994 if ((*i)->parent() != parent) 996 if ((*i)->parent() != parent)
995 return; 997 return;
996 size_t index = 998 size_t index =
997 std::find(windows.begin(), windows.end(), *i) - windows.begin(); 999 std::find(windows.begin(), windows.end(), *i) - windows.begin();
998 map[index] = *i; 1000 map[index] = *i;
999 } 1001 }
1000 1002
1001 // Reorder the windows starting at the topmost. 1003 // Reorder the windows starting at the topmost.
1002 parent->StackChildAtTop(map.rbegin()->second); 1004 parent->StackChildAtTop(map.rbegin()->second);
1003 for (IndexToWindowMap::const_reverse_iterator i = map.rbegin(); 1005 for (IndexToWindowMap::const_reverse_iterator i = map.rbegin();
1004 i != map.rend(); ) { 1006 i != map.rend(); ) {
1005 aura::Window* window = i->second; 1007 aura::Window* window = i->second;
1006 ++i; 1008 ++i;
1007 if (i != map.rend()) 1009 if (i != map.rend())
1008 parent->StackChildBelow(i->second, window); 1010 parent->StackChildBelow(i->second, window);
1009 } 1011 }
1010 } 1012 }
1011 1013
1012 SnapType WorkspaceWindowResizer::GetSnapType( 1014 SnapType WorkspaceWindowResizer::GetSnapType(
1013 const gfx::Point& location) const { 1015 const gfx::Point& location) const {
1014 // TODO: this likely only wants total display area, not the area of a single 1016 // TODO: this likely only wants total display area, not the area of a single
1015 // display. 1017 // display.
1016 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window())); 1018 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(GetTarget()));
1017 if (details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 1019 if (details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
1018 // Increase tolerance for touch-snapping near the screen edges. This is only 1020 // Increase tolerance for touch-snapping near the screen edges. This is only
1019 // necessary when the work area left or right edge is same as screen edge. 1021 // necessary when the work area left or right edge is same as screen edge.
1020 gfx::Rect display_bounds(ScreenAsh::GetDisplayBoundsInParent(window())); 1022 gfx::Rect display_bounds(ScreenAsh::GetDisplayBoundsInParent(GetTarget()));
1021 int inset_left = 0; 1023 int inset_left = 0;
1022 if (area.x() == display_bounds.x()) 1024 if (area.x() == display_bounds.x())
1023 inset_left = kScreenEdgeInsetForTouchResize; 1025 inset_left = kScreenEdgeInsetForTouchResize;
1024 int inset_right = 0; 1026 int inset_right = 0;
1025 if (area.right() == display_bounds.right()) 1027 if (area.right() == display_bounds.right())
1026 inset_right = kScreenEdgeInsetForTouchResize; 1028 inset_right = kScreenEdgeInsetForTouchResize;
1027 area.Inset(inset_left, 0, inset_right, 0); 1029 area.Inset(inset_left, 0, inset_right, 0);
1028 } 1030 }
1029 if (location.x() <= area.x()) 1031 if (location.x() <= area.x())
1030 return SNAP_LEFT; 1032 return SNAP_LEFT;
1031 if (location.x() >= area.right() - 1) 1033 if (location.x() >= area.right() - 1)
1032 return SNAP_RIGHT; 1034 return SNAP_RIGHT;
1033 return SNAP_NONE; 1035 return SNAP_NONE;
1034 } 1036 }
1035 1037
1036 void WorkspaceWindowResizer::SetDraggedWindowDocked(bool should_dock) { 1038 void WorkspaceWindowResizer::SetDraggedWindowDocked(bool should_dock) {
1037 if (should_dock && 1039 if (should_dock &&
1038 dock_layout_->GetAlignmentOfWindow(window()) != DOCKED_ALIGNMENT_NONE) { 1040 dock_layout_->GetAlignmentOfWindow(GetTarget()) !=
1041 DOCKED_ALIGNMENT_NONE) {
1039 if (!dock_layout_->is_dragged_window_docked()) { 1042 if (!dock_layout_->is_dragged_window_docked()) {
1040 window_state()->set_bounds_changed_by_user(false); 1043 window_state()->set_bounds_changed_by_user(false);
1041 dock_layout_->DockDraggedWindow(window()); 1044 dock_layout_->DockDraggedWindow(GetTarget());
1042 } 1045 }
1043 } else { 1046 } else {
1044 if (dock_layout_->is_dragged_window_docked()) { 1047 if (dock_layout_->is_dragged_window_docked()) {
1045 dock_layout_->UndockDraggedWindow(); 1048 dock_layout_->UndockDraggedWindow();
1046 window_state()->set_bounds_changed_by_user(true); 1049 window_state()->set_bounds_changed_by_user(true);
1047 } 1050 }
1048 } 1051 }
1049 } 1052 }
1050 1053
1051 } // namespace internal 1054 } // namespace internal
1052 } // namespace ash 1055 } // namespace ash
OLDNEW
« ash/wm/workspace/workspace_window_resizer.h ('K') | « ash/wm/workspace/workspace_window_resizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698