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

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: Correcting logic to avoid getting stuck on resize Created 7 years, 7 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/drag_window_resizer.h" 19 #include "ash/wm/drag_window_resizer.h"
20 #include "ash/wm/panels/panel_window_resizer.h" 20 #include "ash/wm/panels/panel_window_resizer.h"
21 #include "ash/wm/property_util.h" 21 #include "ash/wm/property_util.h"
22 #include "ash/wm/window_properties.h" 22 #include "ash/wm/window_properties.h"
23 #include "ash/wm/window_util.h" 23 #include "ash/wm/window_util.h"
24 #include "ash/wm/workspace/phantom_window_controller.h" 24 #include "ash/wm/workspace/phantom_window_controller.h"
25 #include "ash/wm/workspace/snap_sizer.h" 25 #include "ash/wm/workspace/snap_sizer.h"
26 #include "ash/wm/workspace/stuck_edge_types.h"
26 #include "base/command_line.h" 27 #include "base/command_line.h"
27 #include "ui/aura/client/aura_constants.h" 28 #include "ui/aura/client/aura_constants.h"
28 #include "ui/aura/client/window_types.h" 29 #include "ui/aura/client/window_types.h"
29 #include "ui/aura/root_window.h" 30 #include "ui/aura/root_window.h"
30 #include "ui/aura/window.h" 31 #include "ui/aura/window.h"
31 #include "ui/aura/window_delegate.h" 32 #include "ui/aura/window_delegate.h"
32 #include "ui/base/hit_test.h" 33 #include "ui/base/hit_test.h"
33 #include "ui/compositor/layer.h" 34 #include "ui/compositor/layer.h"
34 #include "ui/gfx/screen.h" 35 #include "ui/gfx/screen.h"
35 #include "ui/gfx/transform.h" 36 #include "ui/gfx/transform.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 if (bounds != window()->bounds()) 362 if (bounds != window()->bounds())
362 window()->SetBounds(bounds); 363 window()->SetBounds(bounds);
363 } 364 }
364 365
365 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { 366 void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
366 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); 367 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true);
367 snap_phantom_window_controller_.reset(); 368 snap_phantom_window_controller_.reset();
368 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 369 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
369 return; 370 return;
370 371
371 // When the window is not in the normal show state, we do not snap thw window. 372 // 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 373 // 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 374 // 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 375 // out of a maximized window, it's already in the normal show state when this
375 // is called, so it does not matter. 376 // is called, so it does not matter.
376 if (wm::IsWindowNormal(window()) && 377 if (wm::IsWindowNormal(window()) &&
377 (window()->type() != aura::client::WINDOW_TYPE_PANEL || 378 (window()->type() != aura::client::WINDOW_TYPE_PANEL ||
378 !window()->GetProperty(kPanelAttachedKey)) && 379 !window()->GetProperty(kPanelAttachedKey)) &&
379 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { 380 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) {
380 if (!GetRestoreBoundsInScreen(window())) { 381 if (!GetRestoreBoundsInScreen(window())) {
381 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( 382 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen(
382 window()->parent(), details_.initial_bounds_in_parent); 383 window()->parent(), details_.initial_bounds_in_parent);
383 SetRestoreBoundsInScreen(window(), details_.restore_bounds.IsEmpty() ? 384 SetRestoreBoundsInScreen(window(), details_.restore_bounds.IsEmpty() ?
384 initial_bounds : 385 initial_bounds :
385 details_.restore_bounds); 386 details_.restore_bounds);
386 } 387 }
387 window()->SetBounds(snap_sizer_->target_bounds()); 388 gfx::Rect bounds = snap_sizer_->target_bounds();
389 window()->SetBounds(bounds);
390
391 gfx::Rect bounds_in_parent = ScreenAsh::ConvertRectToScreen(
392 window()->parent(),
393 ScreenAsh::GetMaximizedWindowBoundsInParent(window()));
394 int stuck_edges_mask =
395 internal::WorkspaceWindowResizer::CalculateStuckEdges(
396 bounds, bounds_in_parent);
397 if (GetStuckToEdge(window()) != stuck_edges_mask &&
398 CommandLine::ForCurrentProcess()->HasSwitch(
399 switches::kAshEnableDockedWindows))
400 SetStuckToEdge(window(), stuck_edges_mask);
388 return; 401 return;
389 } 402 }
390 } 403 }
391 404
392 void WorkspaceWindowResizer::RevertDrag() { 405 void WorkspaceWindowResizer::RevertDrag() {
393 snap_phantom_window_controller_.reset(); 406 snap_phantom_window_controller_.reset();
394 407
395 if (!did_move_or_resize_) 408 if (!did_move_or_resize_)
396 return; 409 return;
397 410
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 731 }
719 if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { 732 if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) {
720 bounds->set_y(top_edge); 733 bounds->set_y(top_edge);
721 } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size) && 734 } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size) &&
722 bounds->height() < (bottom_edge - top_edge)) { 735 bounds->height() < (bottom_edge - top_edge)) {
723 // Only snap to the bottom if the window is smaller than the work area. 736 // 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 737 // Doing otherwise can lead to window snapping in weird ways as it bounces
725 // between snapping to top then bottom. 738 // between snapping to top then bottom.
726 bounds->set_y(bottom_edge - bounds->height()); 739 bounds->set_y(bottom_edge - bounds->height());
727 } 740 }
741 int stuck_edges_mask = CalculateStuckEdges(*bounds, work_area);
742 if (GetStuckToEdge(window()) != stuck_edges_mask &&
743 CommandLine::ForCurrentProcess()->HasSwitch(
744 switches::kAshEnableDockedWindows))
745 SetStuckToEdge(window(), stuck_edges_mask);
728 } 746 }
729 747
730 void WorkspaceWindowResizer::StickToWorkAreaOnResize( 748 void WorkspaceWindowResizer::StickToWorkAreaOnResize(
731 const gfx::Rect& work_area, 749 const gfx::Rect& work_area,
732 int sticky_size, 750 int sticky_size,
733 gfx::Rect* bounds) const { 751 gfx::Rect* bounds) const {
734 const uint32 edges = WindowComponentToMagneticEdge(details_.window_component); 752 const uint32 edges = WindowComponentToMagneticEdge(details_.window_component);
735 const int left_edge = work_area.x(); 753 const int left_edge = work_area.x();
736 const int right_edge = work_area.right(); 754 const int right_edge = work_area.right();
737 const int top_edge = work_area.y(); 755 const int top_edge = work_area.y();
(...skipping 11 matching lines...) Expand all
749 if (edges & MAGNETISM_EDGE_BOTTOM && 767 if (edges & MAGNETISM_EDGE_BOTTOM &&
750 ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) { 768 ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) {
751 bounds->set_height(bottom_edge - bounds->y()); 769 bounds->set_height(bottom_edge - bounds->y());
752 } 770 }
753 if (edges & MAGNETISM_EDGE_RIGHT && 771 if (edges & MAGNETISM_EDGE_RIGHT &&
754 ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { 772 ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) {
755 bounds->set_width(right_edge - bounds->x()); 773 bounds->set_width(right_edge - bounds->x());
756 } 774 }
757 } 775 }
758 776
777 int WorkspaceWindowResizer::CalculateStuckEdges(
778 const gfx::Rect& bounds,
779 const gfx::Rect& work_area) {
780 int stuck_edges_mask = STUCK_EDGE_NONE;
781 if (bounds.x() == work_area.x())
782 stuck_edges_mask |= STUCK_EDGE_LEFT;
783 if (bounds.right() == work_area.right())
784 stuck_edges_mask |= STUCK_EDGE_RIGHT;
785 if (bounds.y() == work_area.y())
786 stuck_edges_mask |= STUCK_EDGE_TOP;
787 if (bounds.bottom() == work_area.bottom())
788 stuck_edges_mask |= STUCK_EDGE_BOTTOM;
789 return stuck_edges_mask;
790 }
791
759 int WorkspaceWindowResizer::PrimaryAxisSize(const gfx::Size& size) const { 792 int WorkspaceWindowResizer::PrimaryAxisSize(const gfx::Size& size) const {
760 return PrimaryAxisCoordinate(size.width(), size.height()); 793 return PrimaryAxisCoordinate(size.width(), size.height());
761 } 794 }
762 795
763 int WorkspaceWindowResizer::PrimaryAxisCoordinate(int x, int y) const { 796 int WorkspaceWindowResizer::PrimaryAxisCoordinate(int x, int y) const {
764 switch (details_.window_component) { 797 switch (details_.window_component) {
765 case HTRIGHT: 798 case HTRIGHT:
766 return x; 799 return x;
767 case HTBOTTOM: 800 case HTBOTTOM:
768 return y; 801 return y;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); 877 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window()));
845 if (location.x() <= area.x()) 878 if (location.x() <= area.x())
846 return SNAP_LEFT_EDGE; 879 return SNAP_LEFT_EDGE;
847 if (location.x() >= area.right() - 1) 880 if (location.x() >= area.right() - 1)
848 return SNAP_RIGHT_EDGE; 881 return SNAP_RIGHT_EDGE;
849 return SNAP_NONE; 882 return SNAP_NONE;
850 } 883 }
851 884
852 } // namespace internal 885 } // namespace internal
853 } // namespace ash 886 } // namespace ash
OLDNEW
« ash/wm/workspace/workspace_layout_manager.cc ('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