OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dock/docked_window_resizer.h" | 5 #include "ash/wm/dock/docked_window_resizer.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
11 #include "ash/shelf/shelf_types.h" | 11 #include "ash/shelf/shelf_types.h" |
12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "ash/wm/coordinate_conversion.h" | 15 #include "ash/wm/coordinate_conversion.h" |
16 #include "ash/wm/dock/docked_window_layout_manager.h" | 16 #include "ash/wm/dock/docked_window_layout_manager.h" |
17 #include "ash/wm/property_util.h" | 17 #include "ash/wm/property_util.h" |
18 #include "ash/wm/window_properties.h" | 18 #include "ash/wm/window_properties.h" |
19 #include "ash/wm/workspace/magnetism_matcher.h" | 19 #include "ash/wm/workspace/magnetism_matcher.h" |
20 #include "ash/wm/workspace/phantom_window_controller.h" | 20 #include "ash/wm/workspace/phantom_window_controller.h" |
21 #include "ash/wm/workspace/workspace_window_resizer.h" | 21 #include "ash/wm/workspace/workspace_window_resizer.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 23 #include "base/memory/weak_ptr.h" |
23 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
24 #include "ui/aura/env.h" | 25 #include "ui/aura/env.h" |
25 #include "ui/aura/root_window.h" | 26 #include "ui/aura/root_window.h" |
26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
27 #include "ui/aura/window_delegate.h" | 28 #include "ui/aura/window_delegate.h" |
28 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
29 #include "ui/base/ui_base_types.h" | 30 #include "ui/base/ui_base_types.h" |
30 #include "ui/gfx/screen.h" | 31 #include "ui/gfx/screen.h" |
31 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
32 | 33 |
33 namespace ash { | 34 namespace ash { |
34 namespace internal { | 35 namespace internal { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( | 39 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( |
39 const gfx::Point& point) { | 40 const gfx::Point& point) { |
40 aura::Window* dock_container = Shell::GetContainer( | 41 aura::Window* dock_container = Shell::GetContainer( |
41 wm::GetRootWindowAt(point), | 42 wm::GetRootWindowAt(point), |
42 kShellWindowId_DockedContainer); | 43 kShellWindowId_DockedContainer); |
43 return static_cast<DockedWindowLayoutManager*>( | 44 return static_cast<DockedWindowLayoutManager*>( |
44 dock_container->layout_manager()); | 45 dock_container->layout_manager()); |
45 } | 46 } |
46 | 47 |
47 } // namespace | 48 } // namespace |
48 | 49 |
49 DockedWindowResizer::~DockedWindowResizer() { | 50 DockedWindowResizer::~DockedWindowResizer() { |
50 if (destroyed_) | |
51 *destroyed_ = true; | |
52 } | 51 } |
53 | 52 |
54 // static | 53 // static |
55 DockedWindowResizer* | 54 DockedWindowResizer* |
56 DockedWindowResizer::Create(WindowResizer* next_window_resizer, | 55 DockedWindowResizer::Create(WindowResizer* next_window_resizer, |
57 aura::Window* window, | 56 aura::Window* window, |
58 const gfx::Point& location, | 57 const gfx::Point& location, |
59 int window_component, | 58 int window_component, |
60 aura::client::WindowMoveSource source) { | 59 aura::client::WindowMoveSource source) { |
61 Details details(window, location, window_component, source); | 60 Details details(window, location, window_component, source); |
62 return details.is_resizable ? | 61 return details.is_resizable ? |
63 new DockedWindowResizer(next_window_resizer, details) : NULL; | 62 new DockedWindowResizer(next_window_resizer, details) : NULL; |
64 } | 63 } |
65 | 64 |
66 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 65 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
67 last_location_ = location; | 66 last_location_ = location; |
68 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); | 67 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); |
69 bool destroyed = false; | |
70 if (!did_move_or_resize_) { | 68 if (!did_move_or_resize_) { |
71 did_move_or_resize_ = true; | 69 did_move_or_resize_ = true; |
72 StartedDragging(); | 70 StartedDragging(); |
73 } | 71 } |
74 gfx::Point offset; | 72 gfx::Point offset; |
75 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); | 73 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); |
76 bool set_tracked_by_workspace = MaybeSnapToEdge(bounds, &offset); | 74 bool set_tracked_by_workspace = MaybeSnapToEdge(bounds, &offset); |
77 | 75 |
78 // Temporarily clear kWindowTrackedByWorkspaceKey for windows that are snapped | 76 // Temporarily clear kWindowTrackedByWorkspaceKey for windows that are snapped |
79 // to screen edges e.g. when they are docked. This prevents the windows from | 77 // to screen edges e.g. when they are docked. This prevents the windows from |
80 // getting snapped to other nearby windows during the drag. | 78 // getting snapped to other nearby windows during the drag. |
81 bool tracked_by_workspace = GetTrackedByWorkspace(GetTarget()); | 79 bool tracked_by_workspace = GetTrackedByWorkspace(GetTarget()); |
82 if (set_tracked_by_workspace) | 80 if (set_tracked_by_workspace) |
83 SetTrackedByWorkspace(GetTarget(), false); | 81 SetTrackedByWorkspace(GetTarget(), false); |
84 gfx::Point modified_location(location.x() + offset.x(), | 82 gfx::Point modified_location(location.x() + offset.x(), |
85 location.y() + offset.y()); | 83 location.y() + offset.y()); |
86 destroyed_ = &destroyed; | 84 |
| 85 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
87 next_window_resizer_->Drag(modified_location, event_flags); | 86 next_window_resizer_->Drag(modified_location, event_flags); |
| 87 if (!resizer) |
| 88 return; |
88 | 89 |
89 // TODO(varkha): Refactor the way WindowResizer calls into other window | |
90 // resizers to avoid the awkward pattern here for checking if | |
91 // next_window_resizer_ destroys the resizer object. | |
92 if (destroyed) | |
93 return; | |
94 destroyed_ = NULL; | |
95 if (set_tracked_by_workspace) | 90 if (set_tracked_by_workspace) |
96 SetTrackedByWorkspace(GetTarget(), tracked_by_workspace); | 91 SetTrackedByWorkspace(GetTarget(), tracked_by_workspace); |
97 | 92 |
98 DockedWindowLayoutManager* new_dock_layout = | 93 DockedWindowLayoutManager* new_dock_layout = |
99 GetDockedLayoutManagerAtPoint(last_location_); | 94 GetDockedLayoutManagerAtPoint(last_location_); |
100 if (new_dock_layout != dock_layout_) { | 95 if (new_dock_layout != dock_layout_) { |
101 // The window is being dragged to a new display. If the previous | 96 // The window is being dragged to a new display. If the previous |
102 // container is the current parent of the window it will be informed of | 97 // container is the current parent of the window it will be informed of |
103 // the end of drag when the window is reparented, otherwise let the | 98 // the end of drag when the window is reparented, otherwise let the |
104 // previous container know the drag is complete. If we told the | 99 // previous container know the drag is complete. If we told the |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 173 |
179 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, | 174 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, |
180 const Details& details) | 175 const Details& details) |
181 : details_(details), | 176 : details_(details), |
182 next_window_resizer_(next_window_resizer), | 177 next_window_resizer_(next_window_resizer), |
183 dock_layout_(NULL), | 178 dock_layout_(NULL), |
184 initial_dock_layout_(NULL), | 179 initial_dock_layout_(NULL), |
185 did_move_or_resize_(false), | 180 did_move_or_resize_(false), |
186 was_docked_(false), | 181 was_docked_(false), |
187 is_docked_(false), | 182 is_docked_(false), |
188 destroyed_(NULL) { | 183 weak_ptr_factory_(this) { |
189 DCHECK(details_.is_resizable); | 184 DCHECK(details_.is_resizable); |
190 aura::Window* dock_container = Shell::GetContainer( | 185 aura::Window* dock_container = Shell::GetContainer( |
191 details.window->GetRootWindow(), | 186 details.window->GetRootWindow(), |
192 kShellWindowId_DockedContainer); | 187 kShellWindowId_DockedContainer); |
193 dock_layout_ = static_cast<DockedWindowLayoutManager*>( | 188 dock_layout_ = static_cast<DockedWindowLayoutManager*>( |
194 dock_container->layout_manager()); | 189 dock_container->layout_manager()); |
195 initial_dock_layout_ = dock_layout_; | 190 initial_dock_layout_ = dock_layout_; |
196 was_docked_ = details.window->parent() == dock_container; | 191 was_docked_ = details.window->parent() == dock_container; |
197 is_docked_ = was_docked_; | 192 is_docked_ = was_docked_; |
198 } | 193 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 346 |
352 if (!snap_phantom_window_controller_) { | 347 if (!snap_phantom_window_controller_) { |
353 snap_phantom_window_controller_.reset( | 348 snap_phantom_window_controller_.reset( |
354 new PhantomWindowController(GetTarget())); | 349 new PhantomWindowController(GetTarget())); |
355 } | 350 } |
356 snap_phantom_window_controller_->Show(dock_layout_->dragged_bounds()); | 351 snap_phantom_window_controller_->Show(dock_layout_->dragged_bounds()); |
357 } | 352 } |
358 | 353 |
359 } // namespace internal | 354 } // namespace internal |
360 } // namespace ash | 355 } // namespace ash |
OLD | NEW |