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

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 with zero width (exposing DragWindowResizer for tests, rebase) 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/docked_window_layout_manager.h"
20 #include "ash/wm/dock/docked_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"
29 #include "ui/aura/root_window.h" 31 #include "ui/aura/root_window.h"
30 #include "ui/aura/window.h" 32 #include "ui/aura/window.h"
31 #include "ui/aura/window_delegate.h" 33 #include "ui/aura/window_delegate.h"
32 #include "ui/base/hit_test.h" 34 #include "ui/base/hit_test.h"
33 #include "ui/compositor/layer.h" 35 #include "ui/compositor/layer.h"
34 #include "ui/gfx/screen.h" 36 #include "ui/gfx/screen.h"
35 #include "ui/gfx/transform.h" 37 #include "ui/gfx/transform.h"
36 38
37 namespace ash { 39 namespace ash {
38 40
39 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window, 41 namespace internal {
40 const gfx::Point& point_in_parent, 42
41 int window_component) { 43 scoped_ptr<WindowResizer> CreateWindowResizerExposeDragResizer(
44 aura::Window* window,
45 const gfx::Point& point_in_parent,
46 int window_component,
47 DragWindowResizer** drag_resizer) {
42 DCHECK(window); 48 DCHECK(window);
43 // No need to return a resizer when the window cannot get resized. 49 // No need to return a resizer when the window cannot get resized.
44 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) 50 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION)
45 return scoped_ptr<WindowResizer>(); 51 return scoped_ptr<WindowResizer>();
46 52
53 // TODO(varkha): The chaining of window resizers causes some of the logic
54 // to be repeated and the logic flow difficult to control. With some windows
55 // classes using reparenting during drag operations it becomes challenging to
56 // implement proper transition from one resizer to another during or at the
57 // end of the drag. This also causes http://crbug.com/247085.
58 // It seems the only thing the panel or dock resizer needs to do is notify the
59 // layout manager when a docked window is being dragged. We should have a
60 // better way of doing this, perhaps by having a way of observing drags or
61 // having a generic drag window wrapper which informs a layout manager that a
62 // drag has started or stopped.
63 // It may be possible to refactor and eliminate chaining.
47 WindowResizer* window_resizer = NULL; 64 WindowResizer* window_resizer = NULL;
48 if (window->parent() && 65 if (window->parent() &&
49 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { 66 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) {
50 // Allow dragging maximized windows if it's not tracked by workspace. This 67 // Allow dragging maximized windows if it's not tracked by workspace. This
51 // is set by tab dragging code. 68 // is set by tab dragging code.
52 if (!wm::IsWindowNormal(window) && 69 if (!wm::IsWindowNormal(window) &&
53 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) 70 (window_component != HTCAPTION || GetTrackedByWorkspace(window)))
54 return scoped_ptr<WindowResizer>(); 71 return scoped_ptr<WindowResizer>();
55 window_resizer = internal::WorkspaceWindowResizer::Create( 72 window_resizer = internal::WorkspaceWindowResizer::Create(
56 window, 73 window,
57 point_in_parent, 74 point_in_parent,
58 window_component, 75 window_component,
59 std::vector<aura::Window*>()); 76 std::vector<aura::Window*>());
60 } else if (wm::IsWindowNormal(window)) { 77 } else if (wm::IsWindowNormal(window)) {
61 window_resizer = DefaultWindowResizer::Create( 78 window_resizer = DefaultWindowResizer::Create(
62 window, point_in_parent, window_component); 79 window, point_in_parent, window_component);
63 } 80 }
64 if (window_resizer) { 81 if (window_resizer) {
65 window_resizer = internal::DragWindowResizer::Create( 82 window_resizer = internal::DragWindowResizer::Create(
66 window_resizer, window, point_in_parent, window_component); 83 window_resizer, window, point_in_parent, window_component);
84 if (drag_resizer)
85 *drag_resizer = static_cast<DragWindowResizer*>(window_resizer);
67 } 86 }
68 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { 87 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) {
69 window_resizer = PanelWindowResizer::Create( 88 window_resizer = PanelWindowResizer::Create(
70 window_resizer, window, point_in_parent, window_component); 89 window_resizer, window, point_in_parent, window_component);
71 } 90 }
91 if (window_resizer) {
92 window_resizer = DockedWindowResizer::Create(
93 window_resizer, window, point_in_parent, window_component);
94 }
72 return make_scoped_ptr<WindowResizer>(window_resizer); 95 return make_scoped_ptr<WindowResizer>(window_resizer);
73 } 96 }
74 97
75 namespace internal {
76
77 namespace { 98 namespace {
78 99
79 // Distance in pixels that the cursor must move past an edge for a window 100 // Distance in pixels that the cursor must move past an edge for a window
80 // to move or resize beyond that edge. 101 // to move or resize beyond that edge.
81 const int kStickyDistancePixels = 64; 102 const int kStickyDistancePixels = 64;
82 103
83 // Returns true if the window should stick to the edge. 104 // Returns true if the window should stick to the edge.
84 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { 105 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) {
85 if (CommandLine::ForCurrentProcess()->HasSwitch( 106 if (CommandLine::ForCurrentProcess()->HasSwitch(
86 switches::kAshEnableStickyEdges)) { 107 switches::kAshEnableStickyEdges)) {
(...skipping 274 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 attached_windows_[i]->SetBounds(bounds); 438 attached_windows_[i]->SetBounds(bounds);
418 last_y = attached_windows_[i]->bounds().bottom(); 439 last_y = attached_windows_[i]->bounds().bottom();
419 } 440 }
420 } 441 }
421 } 442 }
422 443
423 aura::Window* WorkspaceWindowResizer::GetTarget() { 444 aura::Window* WorkspaceWindowResizer::GetTarget() {
424 return details_.window; 445 return details_.window;
425 } 446 }
426 447
448 const gfx::Point& WorkspaceWindowResizer::GetInitialLocationForTest() const {
449 return details_.initial_location_in_parent;
450 }
451
427 WorkspaceWindowResizer::WorkspaceWindowResizer( 452 WorkspaceWindowResizer::WorkspaceWindowResizer(
428 const Details& details, 453 const Details& details,
429 const std::vector<aura::Window*>& attached_windows) 454 const std::vector<aura::Window*>& attached_windows)
430 : details_(details), 455 : details_(details),
431 attached_windows_(attached_windows), 456 attached_windows_(attached_windows),
432 did_move_or_resize_(false), 457 did_move_or_resize_(false),
433 total_min_(0), 458 total_min_(0),
434 total_initial_size_(0), 459 total_initial_size_(0),
435 snap_type_(SNAP_NONE), 460 snap_type_(SNAP_NONE),
436 num_mouse_moves_since_bounds_change_(0), 461 num_mouse_moves_since_bounds_change_(0),
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // display. 868 // display.
844 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); 869 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window()));
845 if (location.x() <= area.x()) 870 if (location.x() <= area.x())
846 return SNAP_LEFT_EDGE; 871 return SNAP_LEFT_EDGE;
847 if (location.x() >= area.right() - 1) 872 if (location.x() >= area.right() - 1)
848 return SNAP_RIGHT_EDGE; 873 return SNAP_RIGHT_EDGE;
849 return SNAP_NONE; 874 return SNAP_NONE;
850 } 875 }
851 876
852 } // namespace internal 877 } // namespace internal
878
879 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window,
880 const gfx::Point& point_in_parent,
881 int window_component) {
882 return internal::CreateWindowResizerExposeDragResizer(window,
883 point_in_parent,
884 window_component,
885 NULL);
886 }
887
853 } // namespace ash 888 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698