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

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

Issue 13896026: Stick windows to sides of workspaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dock on left or right edge Created 7 years, 6 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
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>
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_edge_types.h"
20 #include "ash/wm/dock/dock_layout_manager.h"
21 #include "ash/wm/dock/dock_window_resizer.h"
19 #include "ash/wm/drag_window_resizer.h" 22 #include "ash/wm/drag_window_resizer.h"
20 #include "ash/wm/panels/panel_window_resizer.h" 23 #include "ash/wm/panels/panel_window_resizer.h"
21 #include "ash/wm/property_util.h" 24 #include "ash/wm/property_util.h"
22 #include "ash/wm/window_properties.h" 25 #include "ash/wm/window_properties.h"
23 #include "ash/wm/window_util.h" 26 #include "ash/wm/window_util.h"
24 #include "ash/wm/workspace/phantom_window_controller.h" 27 #include "ash/wm/workspace/phantom_window_controller.h"
25 #include "ash/wm/workspace/snap_sizer.h" 28 #include "ash/wm/workspace/snap_sizer.h"
26 #include "base/command_line.h" 29 #include "base/command_line.h"
27 #include "ui/aura/client/aura_constants.h" 30 #include "ui/aura/client/aura_constants.h"
28 #include "ui/aura/client/window_types.h" 31 #include "ui/aura/client/window_types.h"
(...skipping 29 matching lines...) Expand all
58 window_component, 61 window_component,
59 std::vector<aura::Window*>()); 62 std::vector<aura::Window*>());
60 } else if (wm::IsWindowNormal(window)) { 63 } else if (wm::IsWindowNormal(window)) {
61 window_resizer = DefaultWindowResizer::Create( 64 window_resizer = DefaultWindowResizer::Create(
62 window, point_in_parent, window_component); 65 window, point_in_parent, window_component);
63 } 66 }
64 if (window_resizer) { 67 if (window_resizer) {
65 window_resizer = internal::DragWindowResizer::Create( 68 window_resizer = internal::DragWindowResizer::Create(
66 window_resizer, window, point_in_parent, window_component); 69 window_resizer, window, point_in_parent, window_component);
67 } 70 }
68 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { 71 if (window_resizer && GetDockEdges(window) != DOCK_EDGE_NONE) {
72 window_resizer = DockWindowResizer::Create(
73 window_resizer, window, point_in_parent, window_component);
74 } else if (window_resizer &&
75 window->type() == aura::client::WINDOW_TYPE_PANEL) {
69 window_resizer = PanelWindowResizer::Create( 76 window_resizer = PanelWindowResizer::Create(
70 window_resizer, window, point_in_parent, window_component); 77 window_resizer, window, point_in_parent, window_component);
71 } 78 }
72 return make_scoped_ptr<WindowResizer>(window_resizer); 79 return make_scoped_ptr<WindowResizer>(window_resizer);
73 } 80 }
74 81
75 namespace internal { 82 namespace internal {
76 83
77 namespace { 84 namespace {
78 85
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 case HTRIGHT: 220 case HTRIGHT:
214 return MAGNETISM_EDGE_RIGHT; 221 return MAGNETISM_EDGE_RIGHT;
215 case HTLEFT: 222 case HTLEFT:
216 return MAGNETISM_EDGE_LEFT; 223 return MAGNETISM_EDGE_LEFT;
217 default: 224 default:
218 break; 225 break;
219 } 226 }
220 return 0; 227 return 0;
221 } 228 }
222 229
230 internal::DockLayoutManager* GetDockLayoutManager(aura::Window* window) {
231 aura::Window* dock_container = Shell::GetContainer(
232 window->GetRootWindow(), internal::kShellWindowId_DockContainer);
233 return static_cast<internal::DockLayoutManager*>(
234 dock_container->layout_manager());
235 }
236
223 } // namespace 237 } // namespace
224 238
225 // static 239 // static
226 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; 240 const int WorkspaceWindowResizer::kMinOnscreenSize = 20;
227 241
228 // static 242 // static
229 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; 243 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32;
230 244
231 // static 245 // static
232 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; 246 const int WorkspaceWindowResizer::kScreenEdgeInset = 8;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 310
297 private: 311 private:
298 int size_; 312 int size_;
299 int min_; 313 int min_;
300 int max_; 314 int max_;
301 }; 315 };
302 316
303 WorkspaceWindowResizer::~WorkspaceWindowResizer() { 317 WorkspaceWindowResizer::~WorkspaceWindowResizer() {
304 Shell* shell = Shell::GetInstance(); 318 Shell* shell = Shell::GetInstance();
305 shell->cursor_manager()->UnlockCursor(); 319 shell->cursor_manager()->UnlockCursor();
320
321 if (GetDockEdges(window()) != dock_edges_mask_ &&
322 CommandLine::ForCurrentProcess()->HasSwitch(
323 switches::kAshEnableDockedWindows))
324 if (window()->type() != aura::client::WINDOW_TYPE_PANEL ||
325 !window()->GetProperty(internal::kPanelAttachedKey))
326 SetDockEdges(window(), dock_edges_mask_);
306 } 327 }
307 328
308 // static 329 // static
309 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( 330 WorkspaceWindowResizer* WorkspaceWindowResizer::Create(
310 aura::Window* window, 331 aura::Window* window,
311 const gfx::Point& location_in_parent, 332 const gfx::Point& location_in_parent,
312 int window_component, 333 int window_component,
313 const std::vector<aura::Window*>& attached_windows) { 334 const std::vector<aura::Window*>& attached_windows) {
314 Details details(window, location_in_parent, window_component); 335 Details details(window, location_in_parent, window_component);
315 return details.is_resizable ? 336 return details.is_resizable ?
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 if (bounds != window()->bounds()) 382 if (bounds != window()->bounds())
362 window()->SetBounds(bounds); 383 window()->SetBounds(bounds);
363 } 384 }
364 385
365 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { 386 void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
366 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); 387 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true);
367 snap_phantom_window_controller_.reset(); 388 snap_phantom_window_controller_.reset();
368 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 389 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
369 return; 390 return;
370 391
371 // When the window is not in the normal show state, we do not snap thw window. 392 // 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 393 // 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 394 // 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 395 // out of a maximized window, it's already in the normal show state when this
375 // is called, so it does not matter. 396 // is called, so it does not matter.
376 if (wm::IsWindowNormal(window()) && 397 if (wm::IsWindowNormal(window()) &&
377 (window()->type() != aura::client::WINDOW_TYPE_PANEL || 398 (window()->type() != aura::client::WINDOW_TYPE_PANEL ||
378 !window()->GetProperty(kPanelAttachedKey)) && 399 !window()->GetProperty(kPanelAttachedKey)) &&
379 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { 400 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) {
380 if (!GetRestoreBoundsInScreen(window())) { 401 if (!GetRestoreBoundsInScreen(window())) {
381 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( 402 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 447
427 WorkspaceWindowResizer::WorkspaceWindowResizer( 448 WorkspaceWindowResizer::WorkspaceWindowResizer(
428 const Details& details, 449 const Details& details,
429 const std::vector<aura::Window*>& attached_windows) 450 const std::vector<aura::Window*>& attached_windows)
430 : details_(details), 451 : details_(details),
431 attached_windows_(attached_windows), 452 attached_windows_(attached_windows),
432 did_move_or_resize_(false), 453 did_move_or_resize_(false),
433 total_min_(0), 454 total_min_(0),
434 total_initial_size_(0), 455 total_initial_size_(0),
435 snap_type_(SNAP_NONE), 456 snap_type_(SNAP_NONE),
457 dock_edges_mask_(DOCK_EDGE_NONE),
436 num_mouse_moves_since_bounds_change_(0), 458 num_mouse_moves_since_bounds_change_(0),
437 magnetism_window_(NULL) { 459 magnetism_window_(NULL) {
438 DCHECK(details_.is_resizable); 460 DCHECK(details_.is_resizable);
439 461
440 Shell* shell = Shell::GetInstance(); 462 Shell* shell = Shell::GetInstance();
441 shell->cursor_manager()->LockCursor(); 463 shell->cursor_manager()->LockCursor();
442 464
443 // Only support attaching to the right/bottom. 465 // Only support attaching to the right/bottom.
444 DCHECK(attached_windows_.empty() || 466 DCHECK(attached_windows_.empty() ||
445 (details.window_component == HTRIGHT || 467 (details.window_component == HTRIGHT ||
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 740 }
719 if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { 741 if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) {
720 bounds->set_y(top_edge); 742 bounds->set_y(top_edge);
721 } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size) && 743 } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size) &&
722 bounds->height() < (bottom_edge - top_edge)) { 744 bounds->height() < (bottom_edge - top_edge)) {
723 // Only snap to the bottom if the window is smaller than the work area. 745 // Only snap to the bottom if the window is smaller than the work area.
724 // Doing otherwise can lead to window snapping in weird ways as it bounces 746 // Doing otherwise can lead to window snapping in weird ways as it bounces
725 // between snapping to top then bottom. 747 // between snapping to top then bottom.
726 bounds->set_y(bottom_edge - bounds->height()); 748 bounds->set_y(bottom_edge - bounds->height());
727 } 749 }
750 dock_edges_mask_ = CalculateDockEdges(*bounds);
728 } 751 }
729 752
730 void WorkspaceWindowResizer::StickToWorkAreaOnResize( 753 void WorkspaceWindowResizer::StickToWorkAreaOnResize(
731 const gfx::Rect& work_area, 754 const gfx::Rect& work_area,
732 int sticky_size, 755 int sticky_size,
733 gfx::Rect* bounds) const { 756 gfx::Rect* bounds) const {
734 const uint32 edges = WindowComponentToMagneticEdge(details_.window_component); 757 const uint32 edges = WindowComponentToMagneticEdge(details_.window_component);
735 const int left_edge = work_area.x(); 758 const int left_edge = work_area.x();
736 const int right_edge = work_area.right(); 759 const int right_edge = work_area.right();
737 const int top_edge = work_area.y(); 760 const int top_edge = work_area.y();
(...skipping 11 matching lines...) Expand all
749 if (edges & MAGNETISM_EDGE_BOTTOM && 772 if (edges & MAGNETISM_EDGE_BOTTOM &&
750 ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) { 773 ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) {
751 bounds->set_height(bottom_edge - bounds->y()); 774 bounds->set_height(bottom_edge - bounds->y());
752 } 775 }
753 if (edges & MAGNETISM_EDGE_RIGHT && 776 if (edges & MAGNETISM_EDGE_RIGHT &&
754 ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { 777 ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) {
755 bounds->set_width(right_edge - bounds->x()); 778 bounds->set_width(right_edge - bounds->x());
756 } 779 }
757 } 780 }
758 781
782 int WorkspaceWindowResizer::CalculateDockEdges(const gfx::Rect& bounds) const {
783 int stuck_edges_mask = DOCK_EDGE_NONE;
784 DockLayoutManager* dock_layout = GetDockLayoutManager(window());
785 if (dock_layout)
786 stuck_edges_mask = dock_layout->CalculateDockEdges(bounds);
787
788 return stuck_edges_mask;
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
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
OLDNEW
« ash/wm/window_properties.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