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> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "ui/aura/root_window.h" | 29 #include "ui/aura/root_window.h" |
| 30 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_delegate.h" | 31 #include "ui/aura/window_delegate.h" |
| 32 #include "ui/base/hit_test.h" | 32 #include "ui/base/hit_test.h" |
| 33 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
| 34 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 35 #include "ui/gfx/transform.h" | 35 #include "ui/gfx/transform.h" |
| 36 | 36 |
| 37 namespace ash { | 37 namespace ash { |
| 38 | 38 |
| 39 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window, | 39 scoped_ptr<WindowResizer> CreateWindowResizer( |
| 40 const gfx::Point& point_in_parent, | 40 aura::Window* window, |
| 41 int window_component) { | 41 const gfx::Point& point_in_parent, |
| 42 int window_component, | |
| 43 aura::client::WindowMoveSource source) { | |
| 42 DCHECK(window); | 44 DCHECK(window); |
| 43 // No need to return a resizer when the window cannot get resized. | 45 // No need to return a resizer when the window cannot get resized. |
| 44 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) | 46 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) |
| 45 return scoped_ptr<WindowResizer>(); | 47 return scoped_ptr<WindowResizer>(); |
| 46 | 48 |
| 47 WindowResizer* window_resizer = NULL; | 49 WindowResizer* window_resizer = NULL; |
| 48 if (window->parent() && | 50 if (window->parent() && |
| 49 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { | 51 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { |
| 50 // Allow dragging maximized windows if it's not tracked by workspace. This | 52 // Allow dragging maximized windows if it's not tracked by workspace. This |
| 51 // is set by tab dragging code. | 53 // is set by tab dragging code. |
| 52 if (!wm::IsWindowNormal(window) && | 54 if (!wm::IsWindowNormal(window) && |
| 53 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) | 55 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) |
| 54 return scoped_ptr<WindowResizer>(); | 56 return scoped_ptr<WindowResizer>(); |
| 55 window_resizer = internal::WorkspaceWindowResizer::Create( | 57 window_resizer = internal::WorkspaceWindowResizer::Create( |
| 56 window, | 58 window, |
| 57 point_in_parent, | 59 point_in_parent, |
| 58 window_component, | 60 window_component, |
| 61 source, | |
| 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, source); |
| 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, source); |
| 67 } | 70 } |
| 68 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { | 71 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { |
| 69 window_resizer = PanelWindowResizer::Create( | 72 window_resizer = PanelWindowResizer::Create( |
| 70 window_resizer, window, point_in_parent, window_component); | 73 window_resizer, window, point_in_parent, window_component, source); |
| 71 } | 74 } |
| 72 return make_scoped_ptr<WindowResizer>(window_resizer); | 75 return make_scoped_ptr<WindowResizer>(window_resizer); |
| 73 } | 76 } |
| 74 | 77 |
| 75 namespace internal { | 78 namespace internal { |
| 76 | 79 |
| 77 namespace { | 80 namespace { |
| 78 | 81 |
| 79 // Distance in pixels that the cursor must move past an edge for a window | 82 // Distance in pixels that the cursor must move past an edge for a window |
| 80 // to move or resize beyond that edge. | 83 // to move or resize beyond that edge. |
| 81 const int kStickyDistancePixels = 64; | 84 const int kStickyDistancePixels = 64; |
| 82 | 85 |
| 86 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset | |
| 87 // when resizing a window using touchscreen. | |
| 88 const int kScreenEdgeInsetForTouchResize = 16; | |
|
sky
2013/06/14 15:57:27
I thought we were going to make this 32?
mohsen
2013/06/14 16:21:48
32 was for the case that we only wanted to use sna
sky
2013/06/14 16:25:07
I only mention it since I thought we agreed on 32
mohsen
2013/06/14 18:17:17
Well, I thought that was for when we only have sna
| |
| 89 | |
| 83 // Returns true if the window should stick to the edge. | 90 // Returns true if the window should stick to the edge. |
| 84 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { | 91 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { |
| 85 if (CommandLine::ForCurrentProcess()->HasSwitch( | 92 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 switches::kAshEnableStickyEdges)) { | 93 switches::kAshEnableStickyEdges)) { |
| 87 return distance_from_edge < 0 && | 94 return distance_from_edge < 0 && |
| 88 distance_from_edge > -sticky_size; | 95 distance_from_edge > -sticky_size; |
| 89 } | 96 } |
| 90 return distance_from_edge < sticky_size && | 97 return distance_from_edge < sticky_size && |
| 91 distance_from_edge > -sticky_size * 2; | 98 distance_from_edge > -sticky_size * 2; |
| 92 } | 99 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 WorkspaceWindowResizer::~WorkspaceWindowResizer() { | 310 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
| 304 Shell* shell = Shell::GetInstance(); | 311 Shell* shell = Shell::GetInstance(); |
| 305 shell->cursor_manager()->UnlockCursor(); | 312 shell->cursor_manager()->UnlockCursor(); |
| 306 } | 313 } |
| 307 | 314 |
| 308 // static | 315 // static |
| 309 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 316 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
| 310 aura::Window* window, | 317 aura::Window* window, |
| 311 const gfx::Point& location_in_parent, | 318 const gfx::Point& location_in_parent, |
| 312 int window_component, | 319 int window_component, |
| 320 aura::client::WindowMoveSource source, | |
| 313 const std::vector<aura::Window*>& attached_windows) { | 321 const std::vector<aura::Window*>& attached_windows) { |
| 314 Details details(window, location_in_parent, window_component); | 322 Details details(window, location_in_parent, window_component, source); |
| 315 return details.is_resizable ? | 323 return details.is_resizable ? |
| 316 new WorkspaceWindowResizer(details, attached_windows) : NULL; | 324 new WorkspaceWindowResizer(details, attached_windows) : NULL; |
| 317 } | 325 } |
| 318 | 326 |
| 319 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, | 327 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, |
| 320 int event_flags) { | 328 int event_flags) { |
| 321 last_mouse_location_ = location_in_parent; | 329 last_mouse_location_ = location_in_parent; |
| 322 | 330 |
| 323 int sticky_size; | 331 int sticky_size; |
| 324 if (event_flags & ui::EF_CONTROL_DOWN) { | 332 if (event_flags & ui::EF_CONTROL_DOWN) { |
| 325 sticky_size = 0; | 333 sticky_size = 0; |
| 326 } else if (CommandLine::ForCurrentProcess()->HasSwitch( | 334 } else if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 327 switches::kAshEnableStickyEdges)) { | 335 switches::kAshEnableStickyEdges)) { |
| 328 sticky_size = kStickyDistancePixels; | 336 sticky_size = kStickyDistancePixels; |
| 337 } else if ((details_.bounds_change & kBoundsChange_Resizes) && | |
| 338 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | |
| 339 sticky_size = kScreenEdgeInsetForTouchResize; | |
|
sky
2013/06/14 15:57:27
Do you want this only effect snapping to screen bo
mohsen
2013/06/14 16:21:48
The problem only happens for resizing to the scree
sky
2013/06/14 16:25:07
My point is that doing the change here effects *al
mohsen
2013/06/14 18:17:17
I think this sticy_size is only used for snapping
sky
2013/06/14 19:22:22
Ah yes, you are right. Sorry about that.
| |
| 329 } else { | 340 } else { |
| 330 sticky_size = kScreenEdgeInset; | 341 sticky_size = kScreenEdgeInset; |
| 331 } | 342 } |
| 332 // |bounds| is in |window()->parent()|'s coordinates. | 343 // |bounds| is in |window()->parent()|'s coordinates. |
| 333 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); | 344 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); |
| 334 | 345 |
| 335 if (wm::IsWindowNormal(window())) | 346 if (wm::IsWindowNormal(window())) |
| 336 AdjustBoundsForMainWindow(sticky_size, &bounds); | 347 AdjustBoundsForMainWindow(sticky_size, &bounds); |
| 337 | 348 |
| 338 if (bounds != window()->bounds()) { | 349 if (bounds != window()->bounds()) { |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); | 855 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); |
| 845 if (location.x() <= area.x()) | 856 if (location.x() <= area.x()) |
| 846 return SNAP_LEFT_EDGE; | 857 return SNAP_LEFT_EDGE; |
| 847 if (location.x() >= area.right() - 1) | 858 if (location.x() >= area.right() - 1) |
| 848 return SNAP_RIGHT_EDGE; | 859 return SNAP_RIGHT_EDGE; |
| 849 return SNAP_NONE; | 860 return SNAP_NONE; |
| 850 } | 861 } |
| 851 | 862 |
| 852 } // namespace internal | 863 } // namespace internal |
| 853 } // namespace ash | 864 } // namespace ash |
| OLD | NEW |