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

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 (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_resizer.h"
19 #include "ash/wm/drag_window_resizer.h" 20 #include "ash/wm/drag_window_resizer.h"
20 #include "ash/wm/panels/panel_window_resizer.h" 21 #include "ash/wm/panels/panel_window_resizer.h"
21 #include "ash/wm/property_util.h" 22 #include "ash/wm/property_util.h"
22 #include "ash/wm/window_properties.h" 23 #include "ash/wm/window_properties.h"
23 #include "ash/wm/window_util.h" 24 #include "ash/wm/window_util.h"
24 #include "ash/wm/workspace/phantom_window_controller.h" 25 #include "ash/wm/workspace/phantom_window_controller.h"
25 #include "ash/wm/workspace/snap_sizer.h" 26 #include "ash/wm/workspace/snap_sizer.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"
(...skipping 10 matching lines...) Expand all
39 scoped_ptr<WindowResizer> CreateWindowResizer( 40 scoped_ptr<WindowResizer> CreateWindowResizer(
40 aura::Window* window, 41 aura::Window* window,
41 const gfx::Point& point_in_parent, 42 const gfx::Point& point_in_parent,
42 int window_component, 43 int window_component,
43 aura::client::WindowMoveSource source) { 44 aura::client::WindowMoveSource source) {
44 DCHECK(window); 45 DCHECK(window);
45 // No need to return a resizer when the window cannot get resized. 46 // No need to return a resizer when the window cannot get resized.
46 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) 47 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION)
47 return scoped_ptr<WindowResizer>(); 48 return scoped_ptr<WindowResizer>();
48 49
50 // TODO(varkha): The chaining of window resizers causes some of the logic
51 // to be repeated and the logic flow difficult to control. With some windows
52 // classes using reparenting during drag operations it becomes challenging to
53 // implement proper transition from one resizer to another during or at the
54 // end of the drag. This also causes http://crbug.com/247085.
55 // It seems the only thing the panel or dock resizer needs to do is notify the
56 // layout manager when a docked window is being dragged. We should have a
57 // better way of doing this, perhaps by having a way of observing drags or
58 // having a generic drag window wrapper which informs a layout manager that a
59 // drag has started or stopped.
60 // It may be possible to refactor and eliminate chaining.
49 WindowResizer* window_resizer = NULL; 61 WindowResizer* window_resizer = NULL;
50 if (window->parent() && 62 if (window->parent() &&
51 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { 63 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) {
52 // Allow dragging maximized windows if it's not tracked by workspace. This 64 // Allow dragging maximized windows if it's not tracked by workspace. This
53 // is set by tab dragging code. 65 // is set by tab dragging code.
54 if (!wm::IsWindowNormal(window) && 66 if (!wm::IsWindowNormal(window) &&
55 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) 67 (window_component != HTCAPTION || GetTrackedByWorkspace(window)))
56 return scoped_ptr<WindowResizer>(); 68 return scoped_ptr<WindowResizer>();
57 window_resizer = internal::WorkspaceWindowResizer::Create( 69 window_resizer = internal::WorkspaceWindowResizer::Create(
58 window, 70 window,
59 point_in_parent, 71 point_in_parent,
60 window_component, 72 window_component,
61 source, 73 source,
62 std::vector<aura::Window*>()); 74 std::vector<aura::Window*>());
63 } else if (wm::IsWindowNormal(window)) { 75 } else if (wm::IsWindowNormal(window)) {
64 window_resizer = DefaultWindowResizer::Create( 76 window_resizer = DefaultWindowResizer::Create(
65 window, point_in_parent, window_component, source); 77 window, point_in_parent, window_component, source);
66 } 78 }
67 if (window_resizer) { 79 if (window_resizer) {
68 window_resizer = internal::DragWindowResizer::Create( 80 window_resizer = internal::DragWindowResizer::Create(
69 window_resizer, window, point_in_parent, window_component, source); 81 window_resizer, window, point_in_parent, window_component, source);
70 } 82 }
71 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { 83 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) {
72 window_resizer = PanelWindowResizer::Create( 84 window_resizer = PanelWindowResizer::Create(
73 window_resizer, window, point_in_parent, window_component, source); 85 window_resizer, window, point_in_parent, window_component, source);
74 } 86 }
87 if (window_resizer) {
88 window_resizer = DockedWindowResizer::Create(
89 window_resizer, window, point_in_parent, window_component, source);
90 }
75 return make_scoped_ptr<WindowResizer>(window_resizer); 91 return make_scoped_ptr<WindowResizer>(window_resizer);
76 } 92 }
77 93
78 namespace internal { 94 namespace internal {
79 95
80 namespace { 96 namespace {
81 97
82 // Distance in pixels that the cursor must move past an edge for a window 98 // Distance in pixels that the cursor must move past an edge for a window
83 // to move or resize beyond that edge. 99 // to move or resize beyond that edge.
84 const int kStickyDistancePixels = 64; 100 const int kStickyDistancePixels = 64;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 if (bounds != window()->bounds()) 388 if (bounds != window()->bounds())
373 window()->SetBounds(bounds); 389 window()->SetBounds(bounds);
374 } 390 }
375 391
376 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { 392 void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
377 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); 393 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true);
378 snap_phantom_window_controller_.reset(); 394 snap_phantom_window_controller_.reset();
379 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 395 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
380 return; 396 return;
381 397
382 // When the window is not in the normal show state, we do not snap thw window. 398 // When the window is not in the normal show state, we do not snap the window.
383 // This happens when the user minimizes or maximizes the window by keyboard 399 // This happens when the user minimizes or maximizes the window by keyboard
384 // shortcut while dragging it. If the window is the result of dragging a tab 400 // shortcut while dragging it. If the window is the result of dragging a tab
385 // out of a maximized window, it's already in the normal show state when this 401 // out of a maximized window, it's already in the normal show state when this
386 // is called, so it does not matter. 402 // is called, so it does not matter.
387 if (wm::IsWindowNormal(window()) && 403 if (wm::IsWindowNormal(window()) &&
388 (window()->type() != aura::client::WINDOW_TYPE_PANEL || 404 (window()->type() != aura::client::WINDOW_TYPE_PANEL ||
389 !window()->GetProperty(kPanelAttachedKey)) && 405 !window()->GetProperty(kPanelAttachedKey)) &&
390 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { 406 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) {
391 if (!GetRestoreBoundsInScreen(window())) { 407 if (!GetRestoreBoundsInScreen(window())) {
392 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( 408 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 attached_windows_[i]->SetBounds(bounds); 444 attached_windows_[i]->SetBounds(bounds);
429 last_y = attached_windows_[i]->bounds().bottom(); 445 last_y = attached_windows_[i]->bounds().bottom();
430 } 446 }
431 } 447 }
432 } 448 }
433 449
434 aura::Window* WorkspaceWindowResizer::GetTarget() { 450 aura::Window* WorkspaceWindowResizer::GetTarget() {
435 return details_.window; 451 return details_.window;
436 } 452 }
437 453
454 const gfx::Point& WorkspaceWindowResizer::GetInitialLocation() const {
455 return details_.initial_location_in_parent;
456 }
457
438 WorkspaceWindowResizer::WorkspaceWindowResizer( 458 WorkspaceWindowResizer::WorkspaceWindowResizer(
439 const Details& details, 459 const Details& details,
440 const std::vector<aura::Window*>& attached_windows) 460 const std::vector<aura::Window*>& attached_windows)
441 : details_(details), 461 : details_(details),
442 attached_windows_(attached_windows), 462 attached_windows_(attached_windows),
443 did_move_or_resize_(false), 463 did_move_or_resize_(false),
444 total_min_(0), 464 total_min_(0),
445 total_initial_size_(0), 465 total_initial_size_(0),
446 snap_type_(SNAP_NONE), 466 snap_type_(SNAP_NONE),
447 num_mouse_moves_since_bounds_change_(0), 467 num_mouse_moves_since_bounds_change_(0),
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); 875 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window()));
856 if (location.x() <= area.x()) 876 if (location.x() <= area.x())
857 return SNAP_LEFT_EDGE; 877 return SNAP_LEFT_EDGE;
858 if (location.x() >= area.right() - 1) 878 if (location.x() >= area.right() - 1)
859 return SNAP_RIGHT_EDGE; 879 return SNAP_RIGHT_EDGE;
860 return SNAP_NONE; 880 return SNAP_NONE;
861 } 881 }
862 882
863 } // namespace internal 883 } // namespace internal
864 } // namespace ash 884 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698