| 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/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> |
| 11 | 11 |
| 12 #include "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
| 13 #include "ash/display/display_controller.h" | 13 #include "ash/display/display_controller.h" |
| 14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
| 15 #include "ash/screen_ash.h" | 15 #include "ash/screen_util.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
| 18 #include "ash/wm/coordinate_conversion.h" | 18 #include "ash/wm/coordinate_conversion.h" |
| 19 #include "ash/wm/default_window_resizer.h" | 19 #include "ash/wm/default_window_resizer.h" |
| 20 #include "ash/wm/dock/docked_window_layout_manager.h" | 20 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 21 #include "ash/wm/dock/docked_window_resizer.h" | 21 #include "ash/wm/dock/docked_window_resizer.h" |
| 22 #include "ash/wm/drag_window_resizer.h" | 22 #include "ash/wm/drag_window_resizer.h" |
| 23 #include "ash/wm/panels/panel_window_resizer.h" | 23 #include "ash/wm/panels/panel_window_resizer.h" |
| 24 #include "ash/wm/window_state.h" | 24 #include "ash/wm/window_state.h" |
| 25 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(GetTarget()->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 ScreenUtil::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 != GetTarget()->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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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 (GetTarget()->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 = ScreenUtil::ConvertRectToScreen( |
| 453 GetTarget()->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(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); | 548 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); |
| 549 total_min_ += min_size; | 549 total_min_ += min_size; |
| 550 total_initial_size_ += initial_size; | 550 total_initial_size_ += initial_size; |
| 551 total_available += std::max(min_size, initial_size) - min_size; | 551 total_available += std::max(min_size, initial_size) - min_size; |
| 552 } | 552 } |
| 553 instance_ = this; | 553 instance_ = this; |
| 554 } | 554 } |
| 555 | 555 |
| 556 void WorkspaceWindowResizer::LayoutAttachedWindows( | 556 void WorkspaceWindowResizer::LayoutAttachedWindows( |
| 557 gfx::Rect* bounds) { | 557 gfx::Rect* bounds) { |
| 558 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(GetTarget())); | 558 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 559 GetTarget())); |
| 559 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size()); | 560 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size()); |
| 560 int current_size = PrimaryAxisSize(bounds->size()); | 561 int current_size = PrimaryAxisSize(bounds->size()); |
| 561 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); | 562 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); |
| 562 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); | 563 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); |
| 563 | 564 |
| 564 int delta = current_size - initial_size; | 565 int delta = current_size - initial_size; |
| 565 int available_size = end - start; | 566 int available_size = end - start; |
| 566 std::vector<int> sizes; | 567 std::vector<int> sizes; |
| 567 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes); | 568 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes); |
| 568 | 569 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 int min = PrimaryAxisSize(delegate->GetMinimumSize()); | 689 int min = PrimaryAxisSize(delegate->GetMinimumSize()); |
| 689 int max = PrimaryAxisSize(delegate->GetMaximumSize()); | 690 int max = PrimaryAxisSize(delegate->GetMaximumSize()); |
| 690 | 691 |
| 691 sizes->push_back(WindowSize(initial_size, min, max)); | 692 sizes->push_back(WindowSize(initial_size, min, max)); |
| 692 } | 693 } |
| 693 } | 694 } |
| 694 | 695 |
| 695 void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) { | 696 void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) { |
| 696 if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) { | 697 if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) { |
| 697 gfx::Point point = OriginForMagneticAttach( | 698 gfx::Point point = OriginForMagneticAttach( |
| 698 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), *bounds), | 699 ScreenUtil::ConvertRectToScreen(GetTarget()->parent(), *bounds), |
| 699 magnetism_window_->GetBoundsInScreen(), | 700 magnetism_window_->GetBoundsInScreen(), |
| 700 magnetism_edge_); | 701 magnetism_edge_); |
| 701 aura::client::GetScreenPositionClient(GetTarget()->GetRootWindow())-> | 702 aura::client::GetScreenPositionClient(GetTarget()->GetRootWindow())-> |
| 702 ConvertPointFromScreen(GetTarget()->parent(), &point); | 703 ConvertPointFromScreen(GetTarget()->parent(), &point); |
| 703 bounds->set_origin(point); | 704 bounds->set_origin(point); |
| 704 } | 705 } |
| 705 } | 706 } |
| 706 | 707 |
| 707 void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows( | 708 void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows( |
| 708 gfx::Rect* bounds) { | 709 gfx::Rect* bounds) { |
| 709 const uint32 edges = WindowComponentToMagneticEdge( | 710 const uint32 edges = WindowComponentToMagneticEdge( |
| 710 details().window_component); | 711 details().window_component); |
| 711 if (UpdateMagnetismWindow(*bounds, edges)) { | 712 if (UpdateMagnetismWindow(*bounds, edges)) { |
| 712 *bounds = ScreenAsh::ConvertRectFromScreen( | 713 *bounds = ScreenUtil::ConvertRectFromScreen( |
| 713 GetTarget()->parent(), | 714 GetTarget()->parent(), |
| 714 BoundsForMagneticResizeAttach( | 715 BoundsForMagneticResizeAttach( |
| 715 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), *bounds), | 716 ScreenUtil::ConvertRectToScreen(GetTarget()->parent(), *bounds), |
| 716 magnetism_window_->GetBoundsInScreen(), | 717 magnetism_window_->GetBoundsInScreen(), |
| 717 magnetism_edge_)); | 718 magnetism_edge_)); |
| 718 } | 719 } |
| 719 } | 720 } |
| 720 | 721 |
| 721 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds, | 722 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds, |
| 722 uint32 edges) { | 723 uint32 edges) { |
| 723 // |bounds| are in coordinates of original window's parent. | 724 // |bounds| are in coordinates of original window's parent. |
| 724 gfx::Rect bounds_in_screen = | 725 gfx::Rect bounds_in_screen = |
| 725 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), bounds); | 726 ScreenUtil::ConvertRectToScreen(GetTarget()->parent(), bounds); |
| 726 MagnetismMatcher matcher(bounds_in_screen, edges); | 727 MagnetismMatcher matcher(bounds_in_screen, edges); |
| 727 | 728 |
| 728 // If we snapped to a window then check it first. That way we don't bounce | 729 // If we snapped to a window then check it first. That way we don't bounce |
| 729 // around when close to multiple edges. | 730 // around when close to multiple edges. |
| 730 if (magnetism_window_) { | 731 if (magnetism_window_) { |
| 731 if (window_tracker_.Contains(magnetism_window_) && | 732 if (window_tracker_.Contains(magnetism_window_) && |
| 732 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), | 733 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), |
| 733 &magnetism_edge_)) { | 734 &magnetism_edge_)) { |
| 734 return true; | 735 return true; |
| 735 } | 736 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 772 |
| 772 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( | 773 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( |
| 773 int sticky_size, | 774 int sticky_size, |
| 774 gfx::Rect* bounds) { | 775 gfx::Rect* bounds) { |
| 775 gfx::Point last_mouse_location_in_screen = last_mouse_location_; | 776 gfx::Point last_mouse_location_in_screen = last_mouse_location_; |
| 776 wm::ConvertPointToScreen(GetTarget()->parent(), | 777 wm::ConvertPointToScreen(GetTarget()->parent(), |
| 777 &last_mouse_location_in_screen); | 778 &last_mouse_location_in_screen); |
| 778 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint( | 779 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint( |
| 779 last_mouse_location_in_screen); | 780 last_mouse_location_in_screen); |
| 780 gfx::Rect work_area = | 781 gfx::Rect work_area = |
| 781 ScreenAsh::ConvertRectFromScreen(GetTarget()->parent(), | 782 ScreenUtil::ConvertRectFromScreen(GetTarget()->parent(), |
| 782 display.work_area()); | 783 display.work_area()); |
| 783 if (details().window_component == HTCAPTION) { | 784 if (details().window_component == HTCAPTION) { |
| 784 // Adjust the bounds to the work area where the mouse cursor is located. | 785 // Adjust the bounds to the work area where the mouse cursor is located. |
| 785 // Always keep kMinOnscreenHeight or the window height (whichever is less) | 786 // Always keep kMinOnscreenHeight or the window height (whichever is less) |
| 786 // on the bottom. | 787 // on the bottom. |
| 787 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight, | 788 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight, |
| 788 bounds->height()); | 789 bounds->height()); |
| 789 if (bounds->y() > max_y) { | 790 if (bounds->y() > max_y) { |
| 790 bounds->set_y(max_y); | 791 bounds->set_y(max_y); |
| 791 } else if (bounds->y() <= work_area.y()) { | 792 } else if (bounds->y() <= work_area.y()) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 DockedWindowLayoutManager::kMaxDockWidth)) { | 941 DockedWindowLayoutManager::kMaxDockWidth)) { |
| 941 phantom_bounds = snap_sizer_->target_bounds(); | 942 phantom_bounds = snap_sizer_->target_bounds(); |
| 942 } | 943 } |
| 943 const bool should_dock = can_dock && | 944 const bool should_dock = can_dock && |
| 944 (phantom_bounds.IsEmpty() || | 945 (phantom_bounds.IsEmpty() || |
| 945 snap_sizer_->end_of_sequence() || | 946 snap_sizer_->end_of_sequence() || |
| 946 dock_layout_->is_dragged_window_docked()); | 947 dock_layout_->is_dragged_window_docked()); |
| 947 SetDraggedWindowDocked(should_dock); | 948 SetDraggedWindowDocked(should_dock); |
| 948 snap_type_ = GetSnapType(location); | 949 snap_type_ = GetSnapType(location); |
| 949 if (dock_layout_->is_dragged_window_docked()) { | 950 if (dock_layout_->is_dragged_window_docked()) { |
| 950 phantom_bounds = ScreenAsh::ConvertRectFromScreen( | 951 phantom_bounds = ScreenUtil::ConvertRectFromScreen( |
| 951 GetTarget()->parent(), dock_layout_->dragged_bounds()); | 952 GetTarget()->parent(), dock_layout_->dragged_bounds()); |
| 952 } | 953 } |
| 953 | 954 |
| 954 if (phantom_bounds.IsEmpty()) { | 955 if (phantom_bounds.IsEmpty()) { |
| 955 snap_phantom_window_controller_.reset(); | 956 snap_phantom_window_controller_.reset(); |
| 956 return; | 957 return; |
| 957 } | 958 } |
| 958 | 959 |
| 959 if (!snap_phantom_window_controller_) { | 960 if (!snap_phantom_window_controller_) { |
| 960 snap_phantom_window_controller_.reset( | 961 snap_phantom_window_controller_.reset( |
| 961 new PhantomWindowController(GetTarget())); | 962 new PhantomWindowController(GetTarget())); |
| 962 } | 963 } |
| 963 snap_phantom_window_controller_->Show(ScreenAsh::ConvertRectToScreen( | 964 snap_phantom_window_controller_->Show(ScreenUtil::ConvertRectToScreen( |
| 964 GetTarget()->parent(), phantom_bounds)); | 965 GetTarget()->parent(), phantom_bounds)); |
| 965 } | 966 } |
| 966 | 967 |
| 967 void WorkspaceWindowResizer::RestackWindows() { | 968 void WorkspaceWindowResizer::RestackWindows() { |
| 968 if (attached_windows_.empty()) | 969 if (attached_windows_.empty()) |
| 969 return; | 970 return; |
| 970 // Build a map from index in children to window, returning if there is a | 971 // Build a map from index in children to window, returning if there is a |
| 971 // window with a different parent. | 972 // window with a different parent. |
| 972 typedef std::map<size_t, aura::Window*> IndexToWindowMap; | 973 typedef std::map<size_t, aura::Window*> IndexToWindowMap; |
| 973 IndexToWindowMap map; | 974 IndexToWindowMap map; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 992 ++i; | 993 ++i; |
| 993 if (i != map.rend()) | 994 if (i != map.rend()) |
| 994 parent->StackChildBelow(i->second, window); | 995 parent->StackChildBelow(i->second, window); |
| 995 } | 996 } |
| 996 } | 997 } |
| 997 | 998 |
| 998 SnapType WorkspaceWindowResizer::GetSnapType( | 999 SnapType WorkspaceWindowResizer::GetSnapType( |
| 999 const gfx::Point& location) const { | 1000 const gfx::Point& location) const { |
| 1000 // TODO: this likely only wants total display area, not the area of a single | 1001 // TODO: this likely only wants total display area, not the area of a single |
| 1001 // display. | 1002 // display. |
| 1002 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(GetTarget())); | 1003 gfx::Rect area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(GetTarget())); |
| 1003 if (details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 1004 if (details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
| 1004 // Increase tolerance for touch-snapping near the screen edges. This is only | 1005 // Increase tolerance for touch-snapping near the screen edges. This is only |
| 1005 // necessary when the work area left or right edge is same as screen edge. | 1006 // necessary when the work area left or right edge is same as screen edge. |
| 1006 gfx::Rect display_bounds(ScreenAsh::GetDisplayBoundsInParent(GetTarget())); | 1007 gfx::Rect display_bounds(ScreenUtil::GetDisplayBoundsInParent(GetTarget())); |
| 1007 int inset_left = 0; | 1008 int inset_left = 0; |
| 1008 if (area.x() == display_bounds.x()) | 1009 if (area.x() == display_bounds.x()) |
| 1009 inset_left = kScreenEdgeInsetForTouchResize; | 1010 inset_left = kScreenEdgeInsetForTouchResize; |
| 1010 int inset_right = 0; | 1011 int inset_right = 0; |
| 1011 if (area.right() == display_bounds.right()) | 1012 if (area.right() == display_bounds.right()) |
| 1012 inset_right = kScreenEdgeInsetForTouchResize; | 1013 inset_right = kScreenEdgeInsetForTouchResize; |
| 1013 area.Inset(inset_left, 0, inset_right, 0); | 1014 area.Inset(inset_left, 0, inset_right, 0); |
| 1014 } | 1015 } |
| 1015 if (location.x() <= area.x()) | 1016 if (location.x() <= area.x()) |
| 1016 return SNAP_LEFT; | 1017 return SNAP_LEFT; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1030 } else { | 1031 } else { |
| 1031 if (dock_layout_->is_dragged_window_docked()) { | 1032 if (dock_layout_->is_dragged_window_docked()) { |
| 1032 dock_layout_->UndockDraggedWindow(); | 1033 dock_layout_->UndockDraggedWindow(); |
| 1033 window_state()->set_bounds_changed_by_user(true); | 1034 window_state()->set_bounds_changed_by_user(true); |
| 1034 } | 1035 } |
| 1035 } | 1036 } |
| 1036 } | 1037 } |
| 1037 | 1038 |
| 1038 } // namespace internal | 1039 } // namespace internal |
| 1039 } // namespace ash | 1040 } // namespace ash |
| OLD | NEW |