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/drag_window_resizer.h" | 5 #include "ash/wm/drag_window_resizer.h" |
6 | 6 |
7 #include "ash/display/mouse_cursor_event_filter.h" | 7 #include "ash/display/mouse_cursor_event_filter.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/coordinate_conversion.h" | 10 #include "ash/wm/coordinate_conversion.h" |
11 #include "ash/wm/drag_window_controller.h" | 11 #include "ash/wm/drag_window_controller.h" |
12 #include "ash/wm/property_util.h" | 12 #include "ash/wm/property_util.h" |
| 13 #include "base/memory/weak_ptr.h" |
13 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
14 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
18 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
19 #include "ui/base/ui_base_types.h" | 20 #include "ui/base/ui_base_types.h" |
20 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
21 | 22 |
22 namespace ash { | 23 namespace ash { |
(...skipping 26 matching lines...) Expand all Loading... |
49 // static | 50 // static |
50 DragWindowResizer* DragWindowResizer::instance_ = NULL; | 51 DragWindowResizer* DragWindowResizer::instance_ = NULL; |
51 | 52 |
52 DragWindowResizer::~DragWindowResizer() { | 53 DragWindowResizer::~DragWindowResizer() { |
53 Shell* shell = Shell::GetInstance(); | 54 Shell* shell = Shell::GetInstance(); |
54 shell->mouse_cursor_filter()->set_mouse_warp_mode( | 55 shell->mouse_cursor_filter()->set_mouse_warp_mode( |
55 MouseCursorEventFilter::WARP_ALWAYS); | 56 MouseCursorEventFilter::WARP_ALWAYS); |
56 shell->mouse_cursor_filter()->HideSharedEdgeIndicator(); | 57 shell->mouse_cursor_filter()->HideSharedEdgeIndicator(); |
57 if (instance_ == this) | 58 if (instance_ == this) |
58 instance_ = NULL; | 59 instance_ = NULL; |
59 | |
60 if (destroyed_) | |
61 *destroyed_ = true; | |
62 } | 60 } |
63 | 61 |
64 // static | 62 // static |
65 DragWindowResizer* DragWindowResizer::Create( | 63 DragWindowResizer* DragWindowResizer::Create( |
66 WindowResizer* next_window_resizer, | 64 WindowResizer* next_window_resizer, |
67 aura::Window* window, | 65 aura::Window* window, |
68 const gfx::Point& location, | 66 const gfx::Point& location, |
69 int window_component, | 67 int window_component, |
70 aura::client::WindowMoveSource source) { | 68 aura::client::WindowMoveSource source) { |
71 Details details(window, location, window_component, source); | 69 Details details(window, location, window_component, source); |
72 return details.is_resizable ? | 70 return details.is_resizable ? |
73 new DragWindowResizer(next_window_resizer, details) : NULL; | 71 new DragWindowResizer(next_window_resizer, details) : NULL; |
74 } | 72 } |
75 | 73 |
76 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 74 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
77 bool destroyed = false; | 75 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
78 destroyed_ = &destroyed; | |
79 next_window_resizer_->Drag(location, event_flags); | 76 next_window_resizer_->Drag(location, event_flags); |
| 77 if (!resizer) |
| 78 return; |
80 | 79 |
81 // TODO(flackr): Refactor the way WindowResizer calls into other window | |
82 // resizers to avoid the awkward pattern here for checking if | |
83 // next_window_resizer_ destroys the resizer object. | |
84 if (destroyed) | |
85 return; | |
86 destroyed_ = NULL; | |
87 last_mouse_location_ = location; | 80 last_mouse_location_ = location; |
88 | |
89 // Show a phantom window for dragging in another root window. | 81 // Show a phantom window for dragging in another root window. |
90 if (HasSecondaryRootWindow()) { | 82 if (HasSecondaryRootWindow()) { |
91 gfx::Point location_in_screen = location; | 83 gfx::Point location_in_screen = location; |
92 wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); | 84 wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); |
93 const bool in_original_root = | 85 const bool in_original_root = |
94 wm::GetRootWindowAt(location_in_screen) == GetTarget()->GetRootWindow(); | 86 wm::GetRootWindowAt(location_in_screen) == GetTarget()->GetRootWindow(); |
95 UpdateDragWindow(GetTarget()->bounds(), in_original_root); | 87 UpdateDragWindow(GetTarget()->bounds(), in_original_root); |
96 } else { | 88 } else { |
97 drag_window_controller_.reset(); | 89 drag_window_controller_.reset(); |
98 } | 90 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 125 } |
134 | 126 |
135 const gfx::Point& DragWindowResizer::GetInitialLocation() const { | 127 const gfx::Point& DragWindowResizer::GetInitialLocation() const { |
136 return details_.initial_location_in_parent; | 128 return details_.initial_location_in_parent; |
137 } | 129 } |
138 | 130 |
139 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, | 131 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, |
140 const Details& details) | 132 const Details& details) |
141 : next_window_resizer_(next_window_resizer), | 133 : next_window_resizer_(next_window_resizer), |
142 details_(details), | 134 details_(details), |
143 destroyed_(NULL) { | 135 weak_ptr_factory_(this) { |
144 // The pointer should be confined in one display during resizing a window | 136 // The pointer should be confined in one display during resizing a window |
145 // because the window cannot span two displays at the same time anyway. The | 137 // because the window cannot span two displays at the same time anyway. The |
146 // exception is window/tab dragging operation. During that operation, | 138 // exception is window/tab dragging operation. During that operation, |
147 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a | 139 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a |
148 // window/tab to another display. | 140 // window/tab to another display. |
149 MouseCursorEventFilter* mouse_cursor_filter = | 141 MouseCursorEventFilter* mouse_cursor_filter = |
150 Shell::GetInstance()->mouse_cursor_filter(); | 142 Shell::GetInstance()->mouse_cursor_filter(); |
151 mouse_cursor_filter->set_mouse_warp_mode( | 143 mouse_cursor_filter->set_mouse_warp_mode( |
152 ShouldAllowMouseWarp() ? | 144 ShouldAllowMouseWarp() ? |
153 MouseCursorEventFilter::WARP_DRAG : MouseCursorEventFilter::WARP_NONE); | 145 MouseCursorEventFilter::WARP_DRAG : MouseCursorEventFilter::WARP_NONE); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 193 |
202 bool DragWindowResizer::ShouldAllowMouseWarp() { | 194 bool DragWindowResizer::ShouldAllowMouseWarp() { |
203 return (details_.window_component == HTCAPTION) && | 195 return (details_.window_component == HTCAPTION) && |
204 !GetTarget()->transient_parent() && | 196 !GetTarget()->transient_parent() && |
205 (GetTarget()->type() == aura::client::WINDOW_TYPE_NORMAL || | 197 (GetTarget()->type() == aura::client::WINDOW_TYPE_NORMAL || |
206 GetTarget()->type() == aura::client::WINDOW_TYPE_PANEL); | 198 GetTarget()->type() == aura::client::WINDOW_TYPE_PANEL); |
207 } | 199 } |
208 | 200 |
209 } // namespace internal | 201 } // namespace internal |
210 } // namespace ash | 202 } // namespace ash |
OLD | NEW |