Chromium Code Reviews| 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/screen_ash.h" | 14 #include "ash/screen_ash.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
| 17 #include "ash/wm/coordinate_conversion.h" | 17 #include "ash/wm/coordinate_conversion.h" |
| 18 #include "ash/wm/default_window_resizer.h" | 18 #include "ash/wm/default_window_resizer.h" |
| 19 #include "ash/wm/dock/dock_layout_manager.h" | |
| 20 #include "ash/wm/dock/dock_window_resizer.h" | |
| 19 #include "ash/wm/drag_window_resizer.h" | 21 #include "ash/wm/drag_window_resizer.h" |
| 20 #include "ash/wm/panels/panel_window_resizer.h" | 22 #include "ash/wm/panels/panel_window_resizer.h" |
| 21 #include "ash/wm/property_util.h" | 23 #include "ash/wm/property_util.h" |
| 22 #include "ash/wm/window_properties.h" | 24 #include "ash/wm/window_properties.h" |
| 23 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
| 24 #include "ash/wm/workspace/phantom_window_controller.h" | 26 #include "ash/wm/workspace/phantom_window_controller.h" |
| 25 #include "ash/wm/workspace/snap_sizer.h" | 27 #include "ash/wm/workspace/snap_sizer.h" |
| 26 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 27 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
| 28 #include "ui/aura/client/window_types.h" | 30 #include "ui/aura/client/window_types.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 58 window_component, | 60 window_component, |
| 59 std::vector<aura::Window*>()); | 61 std::vector<aura::Window*>()); |
| 60 } else if (wm::IsWindowNormal(window)) { | 62 } else if (wm::IsWindowNormal(window)) { |
| 61 window_resizer = DefaultWindowResizer::Create( | 63 window_resizer = DefaultWindowResizer::Create( |
| 62 window, point_in_parent, window_component); | 64 window, point_in_parent, window_component); |
| 63 } | 65 } |
| 64 if (window_resizer) { | 66 if (window_resizer) { |
| 65 window_resizer = internal::DragWindowResizer::Create( | 67 window_resizer = internal::DragWindowResizer::Create( |
| 66 window_resizer, window, point_in_parent, window_component); | 68 window_resizer, window, point_in_parent, window_component); |
| 67 } | 69 } |
| 68 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { | 70 if (window_resizer && GetDockEdge(window) != DOCK_EDGE_NONE) { |
| 71 window_resizer = DockWindowResizer::Create( | |
| 72 window_resizer, window, point_in_parent, window_component); | |
| 73 } else if (window_resizer && | |
| 74 window->type() == aura::client::WINDOW_TYPE_PANEL) { | |
|
stevenjb
2013/06/03 18:19:03
align
varkha
2013/06/03 21:03:17
Done.
| |
| 69 window_resizer = PanelWindowResizer::Create( | 75 window_resizer = PanelWindowResizer::Create( |
| 70 window_resizer, window, point_in_parent, window_component); | 76 window_resizer, window, point_in_parent, window_component); |
| 71 } | 77 } |
| 72 return make_scoped_ptr<WindowResizer>(window_resizer); | 78 return make_scoped_ptr<WindowResizer>(window_resizer); |
| 73 } | 79 } |
| 74 | 80 |
| 75 namespace internal { | 81 namespace internal { |
| 76 | 82 |
| 77 namespace { | 83 namespace { |
| 78 | 84 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 case HTRIGHT: | 219 case HTRIGHT: |
| 214 return MAGNETISM_EDGE_RIGHT; | 220 return MAGNETISM_EDGE_RIGHT; |
| 215 case HTLEFT: | 221 case HTLEFT: |
| 216 return MAGNETISM_EDGE_LEFT; | 222 return MAGNETISM_EDGE_LEFT; |
| 217 default: | 223 default: |
| 218 break; | 224 break; |
| 219 } | 225 } |
| 220 return 0; | 226 return 0; |
| 221 } | 227 } |
| 222 | 228 |
| 229 internal::DockLayoutManager* GetDockLayoutManager(aura::Window* window) { | |
| 230 aura::Window* dock_container = Shell::GetContainer( | |
| 231 window->GetRootWindow(), internal::kShellWindowId_DockContainer); | |
| 232 return static_cast<internal::DockLayoutManager*>( | |
| 233 dock_container->layout_manager()); | |
| 234 } | |
| 235 | |
| 223 } // namespace | 236 } // namespace |
| 224 | 237 |
| 225 // static | 238 // static |
| 226 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; | 239 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; |
| 227 | 240 |
| 228 // static | 241 // static |
| 229 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; | 242 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; |
| 230 | 243 |
| 231 // static | 244 // static |
| 232 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; | 245 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 | 309 |
| 297 private: | 310 private: |
| 298 int size_; | 311 int size_; |
| 299 int min_; | 312 int min_; |
| 300 int max_; | 313 int max_; |
| 301 }; | 314 }; |
| 302 | 315 |
| 303 WorkspaceWindowResizer::~WorkspaceWindowResizer() { | 316 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
| 304 Shell* shell = Shell::GetInstance(); | 317 Shell* shell = Shell::GetInstance(); |
| 305 shell->cursor_manager()->UnlockCursor(); | 318 shell->cursor_manager()->UnlockCursor(); |
| 319 | |
| 320 if (GetDockEdge(window()) != dock_edge_ && | |
| 321 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 322 switches::kAshEnableDockedWindows)) | |
| 323 if (window()->type() != aura::client::WINDOW_TYPE_PANEL || | |
| 324 !window()->GetProperty(internal::kPanelAttachedKey)) | |
| 325 SetDockEdge(window(), dock_edge_); | |
| 306 } | 326 } |
| 307 | 327 |
| 308 // static | 328 // static |
| 309 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 329 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
| 310 aura::Window* window, | 330 aura::Window* window, |
| 311 const gfx::Point& location_in_parent, | 331 const gfx::Point& location_in_parent, |
| 312 int window_component, | 332 int window_component, |
| 313 const std::vector<aura::Window*>& attached_windows) { | 333 const std::vector<aura::Window*>& attached_windows) { |
| 314 Details details(window, location_in_parent, window_component); | 334 Details details(window, location_in_parent, window_component); |
| 315 return details.is_resizable ? | 335 return details.is_resizable ? |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 if (bounds != window()->bounds()) | 381 if (bounds != window()->bounds()) |
| 362 window()->SetBounds(bounds); | 382 window()->SetBounds(bounds); |
| 363 } | 383 } |
| 364 | 384 |
| 365 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 385 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
| 366 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); | 386 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); |
| 367 snap_phantom_window_controller_.reset(); | 387 snap_phantom_window_controller_.reset(); |
| 368 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 388 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
| 369 return; | 389 return; |
| 370 | 390 |
| 371 // When the window is not in the normal show state, we do not snap thw window. | 391 // When the window is not in the normal show state, we do not snap the window. |
| 372 // This happens when the user minimizes or maximizes the window by keyboard | 392 // This happens when the user minimizes or maximizes the window by keyboard |
| 373 // shortcut while dragging it. If the window is the result of dragging a tab | 393 // shortcut while dragging it. If the window is the result of dragging a tab |
| 374 // out of a maximized window, it's already in the normal show state when this | 394 // out of a maximized window, it's already in the normal show state when this |
| 375 // is called, so it does not matter. | 395 // is called, so it does not matter. |
| 376 if (wm::IsWindowNormal(window()) && | 396 if (wm::IsWindowNormal(window()) && |
| 377 (window()->type() != aura::client::WINDOW_TYPE_PANEL || | 397 (window()->type() != aura::client::WINDOW_TYPE_PANEL || |
| 378 !window()->GetProperty(kPanelAttachedKey)) && | 398 !window()->GetProperty(kPanelAttachedKey)) && |
| 379 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { | 399 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { |
| 380 if (!GetRestoreBoundsInScreen(window())) { | 400 if (!GetRestoreBoundsInScreen(window())) { |
| 381 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( | 401 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 | 446 |
| 427 WorkspaceWindowResizer::WorkspaceWindowResizer( | 447 WorkspaceWindowResizer::WorkspaceWindowResizer( |
| 428 const Details& details, | 448 const Details& details, |
| 429 const std::vector<aura::Window*>& attached_windows) | 449 const std::vector<aura::Window*>& attached_windows) |
| 430 : details_(details), | 450 : details_(details), |
| 431 attached_windows_(attached_windows), | 451 attached_windows_(attached_windows), |
| 432 did_move_or_resize_(false), | 452 did_move_or_resize_(false), |
| 433 total_min_(0), | 453 total_min_(0), |
| 434 total_initial_size_(0), | 454 total_initial_size_(0), |
| 435 snap_type_(SNAP_NONE), | 455 snap_type_(SNAP_NONE), |
| 456 dock_edge_(DOCK_EDGE_NONE), | |
| 436 num_mouse_moves_since_bounds_change_(0), | 457 num_mouse_moves_since_bounds_change_(0), |
| 437 magnetism_window_(NULL) { | 458 magnetism_window_(NULL) { |
| 438 DCHECK(details_.is_resizable); | 459 DCHECK(details_.is_resizable); |
| 439 | 460 |
| 440 Shell* shell = Shell::GetInstance(); | 461 Shell* shell = Shell::GetInstance(); |
| 441 shell->cursor_manager()->LockCursor(); | 462 shell->cursor_manager()->LockCursor(); |
| 442 | 463 |
| 443 // Only support attaching to the right/bottom. | 464 // Only support attaching to the right/bottom. |
| 444 DCHECK(attached_windows_.empty() || | 465 DCHECK(attached_windows_.empty() || |
| 445 (details.window_component == HTRIGHT || | 466 (details.window_component == HTRIGHT || |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 bounds->set_y(max_y); | 697 bounds->set_y(max_y); |
| 677 } else if (bounds->y() <= work_area.y()) { | 698 } else if (bounds->y() <= work_area.y()) { |
| 678 // Don't allow dragging above the top of the display until the mouse | 699 // Don't allow dragging above the top of the display until the mouse |
| 679 // cursor reaches the work area above if any. | 700 // cursor reaches the work area above if any. |
| 680 bounds->set_y(work_area.y()); | 701 bounds->set_y(work_area.y()); |
| 681 } | 702 } |
| 682 | 703 |
| 683 if (sticky_size > 0) { | 704 if (sticky_size > 0) { |
| 684 StickToWorkAreaOnMove(work_area, sticky_size, bounds); | 705 StickToWorkAreaOnMove(work_area, sticky_size, bounds); |
| 685 MagneticallySnapToOtherWindows(bounds); | 706 MagneticallySnapToOtherWindows(bounds); |
| 707 dock_edge_ = FindDockEdge(*bounds); | |
| 686 } | 708 } |
| 687 } else if (sticky_size > 0) { | 709 } else if (sticky_size > 0) { |
| 688 MagneticallySnapResizeToOtherWindows(bounds); | 710 MagneticallySnapResizeToOtherWindows(bounds); |
| 689 if (!magnetism_window_ && sticky_size > 0) | 711 if (!magnetism_window_ && sticky_size > 0) |
| 690 StickToWorkAreaOnResize(work_area, sticky_size, bounds); | 712 StickToWorkAreaOnResize(work_area, sticky_size, bounds); |
| 691 } | 713 } |
| 692 | 714 |
| 693 if (attached_windows_.empty()) | 715 if (attached_windows_.empty()) |
| 694 return; | 716 return; |
| 695 | 717 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 if (edges & MAGNETISM_EDGE_BOTTOM && | 771 if (edges & MAGNETISM_EDGE_BOTTOM && |
| 750 ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) { | 772 ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) { |
| 751 bounds->set_height(bottom_edge - bounds->y()); | 773 bounds->set_height(bottom_edge - bounds->y()); |
| 752 } | 774 } |
| 753 if (edges & MAGNETISM_EDGE_RIGHT && | 775 if (edges & MAGNETISM_EDGE_RIGHT && |
| 754 ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { | 776 ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { |
| 755 bounds->set_width(right_edge - bounds->x()); | 777 bounds->set_width(right_edge - bounds->x()); |
| 756 } | 778 } |
| 757 } | 779 } |
| 758 | 780 |
| 781 ash::DockEdge WorkspaceWindowResizer::FindDockEdge( | |
| 782 const gfx::Rect& bounds) const { | |
|
stevenjb
2013/06/03 18:19:03
This seems like it should be either a static in Do
varkha
2013/06/03 21:03:17
Done (as a static in DockLayoutManager). Also move
| |
| 783 DockEdge dock_edge = DOCK_EDGE_NONE; | |
| 784 DockLayoutManager* dock_layout = GetDockLayoutManager(window()); | |
| 785 if (dock_layout) | |
| 786 dock_edge = dock_layout->FindDockEdge(bounds); | |
| 787 | |
| 788 return dock_edge; | |
| 789 } | |
| 790 | |
| 759 int WorkspaceWindowResizer::PrimaryAxisSize(const gfx::Size& size) const { | 791 int WorkspaceWindowResizer::PrimaryAxisSize(const gfx::Size& size) const { |
| 760 return PrimaryAxisCoordinate(size.width(), size.height()); | 792 return PrimaryAxisCoordinate(size.width(), size.height()); |
| 761 } | 793 } |
| 762 | 794 |
| 763 int WorkspaceWindowResizer::PrimaryAxisCoordinate(int x, int y) const { | 795 int WorkspaceWindowResizer::PrimaryAxisCoordinate(int x, int y) const { |
| 764 switch (details_.window_component) { | 796 switch (details_.window_component) { |
| 765 case HTRIGHT: | 797 case HTRIGHT: |
| 766 return x; | 798 return x; |
| 767 case HTBOTTOM: | 799 case HTBOTTOM: |
| 768 return y; | 800 return y; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); | 876 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); |
| 845 if (location.x() <= area.x()) | 877 if (location.x() <= area.x()) |
| 846 return SNAP_LEFT_EDGE; | 878 return SNAP_LEFT_EDGE; |
| 847 if (location.x() >= area.right() - 1) | 879 if (location.x() >= area.right() - 1) |
| 848 return SNAP_RIGHT_EDGE; | 880 return SNAP_RIGHT_EDGE; |
| 849 return SNAP_NONE; | 881 return SNAP_NONE; |
| 850 } | 882 } |
| 851 | 883 |
| 852 } // namespace internal | 884 } // namespace internal |
| 853 } // namespace ash | 885 } // namespace ash |
| OLD | NEW |