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/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/drag_window_controller.h" | 9 #include "ash/wm/drag_window_controller.h" |
10 #include "ash/wm/window_positioning_utils.h" | 10 #include "ash/wm/window_positioning_utils.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); | 48 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
49 next_window_resizer_->Drag(location, event_flags); | 49 next_window_resizer_->Drag(location, event_flags); |
50 | 50 |
51 if (!resizer) | 51 if (!resizer) |
52 return; | 52 return; |
53 | 53 |
54 last_mouse_location_ = location; | 54 last_mouse_location_ = location; |
55 // Show a phantom window for dragging in another root window. | 55 // Show a phantom window for dragging in another root window. |
56 if (display::Screen::GetScreen()->GetNumDisplays() > 1) { | 56 if (display::Screen::GetScreen()->GetNumDisplays() > 1) { |
57 gfx::Point location_in_screen = location; | 57 gfx::Point location_in_screen = location; |
58 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), &location_in_screen); | 58 ::wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); |
59 UpdateDragWindow(GetAuraTarget()->bounds(), location_in_screen); | 59 UpdateDragWindow(GetTarget()->bounds(), location_in_screen); |
60 } else { | 60 } else { |
61 drag_window_controller_.reset(); | 61 drag_window_controller_.reset(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void DragWindowResizer::CompleteDrag() { | 65 void DragWindowResizer::CompleteDrag() { |
66 next_window_resizer_->CompleteDrag(); | 66 next_window_resizer_->CompleteDrag(); |
67 | 67 |
68 GetAuraTarget()->layer()->SetOpacity(details().initial_opacity); | 68 GetTarget()->layer()->SetOpacity(details().initial_opacity); |
69 drag_window_controller_.reset(); | 69 drag_window_controller_.reset(); |
70 | 70 |
71 // Check if the destination is another display. | 71 // Check if the destination is another display. |
72 gfx::Point last_mouse_location_in_screen = last_mouse_location_; | 72 gfx::Point last_mouse_location_in_screen = last_mouse_location_; |
73 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), | 73 ::wm::ConvertPointToScreen(GetTarget()->parent(), |
74 &last_mouse_location_in_screen); | 74 &last_mouse_location_in_screen); |
75 display::Screen* screen = display::Screen::GetScreen(); | 75 display::Screen* screen = display::Screen::GetScreen(); |
76 const display::Display dst_display = | 76 const display::Display dst_display = |
77 screen->GetDisplayNearestPoint(last_mouse_location_in_screen); | 77 screen->GetDisplayNearestPoint(last_mouse_location_in_screen); |
78 | 78 |
79 if (dst_display.id() != | 79 if (dst_display.id() != |
80 screen->GetDisplayNearestWindow(GetAuraTarget()->GetRootWindow()).id()) { | 80 screen->GetDisplayNearestWindow(GetTarget()->GetRootWindow()).id()) { |
81 // Adjust the size and position so that it doesn't exceed the size of | 81 // Adjust the size and position so that it doesn't exceed the size of |
82 // work area. | 82 // work area. |
83 const gfx::Size& size = dst_display.work_area().size(); | 83 const gfx::Size& size = dst_display.work_area().size(); |
84 gfx::Rect bounds = GetAuraTarget()->bounds(); | 84 gfx::Rect bounds = GetTarget()->bounds(); |
85 if (bounds.width() > size.width()) { | 85 if (bounds.width() > size.width()) { |
86 int diff = bounds.width() - size.width(); | 86 int diff = bounds.width() - size.width(); |
87 bounds.set_x(bounds.x() + diff / 2); | 87 bounds.set_x(bounds.x() + diff / 2); |
88 bounds.set_width(size.width()); | 88 bounds.set_width(size.width()); |
89 } | 89 } |
90 if (bounds.height() > size.height()) | 90 if (bounds.height() > size.height()) |
91 bounds.set_height(size.height()); | 91 bounds.set_height(size.height()); |
92 | 92 |
93 gfx::Rect dst_bounds = bounds; | 93 gfx::Rect dst_bounds = bounds; |
94 ::wm::ConvertRectToScreen(GetAuraTarget()->parent(), &dst_bounds); | 94 ::wm::ConvertRectToScreen(GetTarget()->parent(), &dst_bounds); |
95 | 95 |
96 // Adjust the position so that the cursor is on the window. | 96 // Adjust the position so that the cursor is on the window. |
97 if (!dst_bounds.Contains(last_mouse_location_in_screen)) { | 97 if (!dst_bounds.Contains(last_mouse_location_in_screen)) { |
98 if (last_mouse_location_in_screen.x() < dst_bounds.x()) | 98 if (last_mouse_location_in_screen.x() < dst_bounds.x()) |
99 dst_bounds.set_x(last_mouse_location_in_screen.x()); | 99 dst_bounds.set_x(last_mouse_location_in_screen.x()); |
100 else if (last_mouse_location_in_screen.x() > dst_bounds.right()) | 100 else if (last_mouse_location_in_screen.x() > dst_bounds.right()) |
101 dst_bounds.set_x(last_mouse_location_in_screen.x() - | 101 dst_bounds.set_x(last_mouse_location_in_screen.x() - |
102 dst_bounds.width()); | 102 dst_bounds.width()); |
103 } | 103 } |
104 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(dst_display.bounds(), | 104 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(dst_display.bounds(), |
105 &dst_bounds); | 105 &dst_bounds); |
106 | 106 |
107 GetAuraTarget()->SetBoundsInScreen(dst_bounds, dst_display); | 107 GetTarget()->SetBoundsInScreen(dst_bounds, dst_display); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 void DragWindowResizer::RevertDrag() { | 111 void DragWindowResizer::RevertDrag() { |
112 next_window_resizer_->RevertDrag(); | 112 next_window_resizer_->RevertDrag(); |
113 | 113 |
114 drag_window_controller_.reset(); | 114 drag_window_controller_.reset(); |
115 GetAuraTarget()->layer()->SetOpacity(details().initial_opacity); | 115 GetTarget()->layer()->SetOpacity(details().initial_opacity); |
116 } | 116 } |
117 | 117 |
118 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, | 118 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, |
119 wm::WindowState* window_state) | 119 wm::WindowState* window_state) |
120 : WindowResizer(window_state), | 120 : WindowResizer(window_state), |
121 next_window_resizer_(next_window_resizer), | 121 next_window_resizer_(next_window_resizer), |
122 weak_ptr_factory_(this) { | 122 weak_ptr_factory_(this) { |
123 // The pointer should be confined in one display during resizing a window | 123 // The pointer should be confined in one display during resizing a window |
124 // because the window cannot span two displays at the same time anyway. The | 124 // because the window cannot span two displays at the same time anyway. The |
125 // exception is window/tab dragging operation. During that operation, | 125 // exception is window/tab dragging operation. During that operation, |
126 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a | 126 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a |
127 // window/tab to another display. | 127 // window/tab to another display. |
128 MouseCursorEventFilter* mouse_cursor_filter = | 128 MouseCursorEventFilter* mouse_cursor_filter = |
129 Shell::Get()->mouse_cursor_filter(); | 129 Shell::Get()->mouse_cursor_filter(); |
130 mouse_cursor_filter->set_mouse_warp_enabled(ShouldAllowMouseWarp()); | 130 mouse_cursor_filter->set_mouse_warp_enabled(ShouldAllowMouseWarp()); |
131 if (ShouldAllowMouseWarp()) | 131 if (ShouldAllowMouseWarp()) |
132 mouse_cursor_filter->ShowSharedEdgeIndicator( | 132 mouse_cursor_filter->ShowSharedEdgeIndicator(GetTarget()->GetRootWindow()); |
133 GetAuraTarget()->GetRootWindow()); | |
134 instance_ = this; | 133 instance_ = this; |
135 } | 134 } |
136 | 135 |
137 void DragWindowResizer::UpdateDragWindow( | 136 void DragWindowResizer::UpdateDragWindow( |
138 const gfx::Rect& bounds_in_parent, | 137 const gfx::Rect& bounds_in_parent, |
139 const gfx::Point& drag_location_in_screen) { | 138 const gfx::Point& drag_location_in_screen) { |
140 if (details().window_component != HTCAPTION || !ShouldAllowMouseWarp()) | 139 if (details().window_component != HTCAPTION || !ShouldAllowMouseWarp()) |
141 return; | 140 return; |
142 | 141 |
143 if (!drag_window_controller_) | 142 if (!drag_window_controller_) |
144 drag_window_controller_.reset(new DragWindowController(GetAuraTarget())); | 143 drag_window_controller_.reset(new DragWindowController(GetTarget())); |
145 | 144 |
146 gfx::Rect bounds_in_screen = bounds_in_parent; | 145 gfx::Rect bounds_in_screen = bounds_in_parent; |
147 ::wm::ConvertRectToScreen(GetAuraTarget()->parent(), &bounds_in_screen); | 146 ::wm::ConvertRectToScreen(GetTarget()->parent(), &bounds_in_screen); |
148 | 147 |
149 gfx::Rect root_bounds_in_screen = | 148 gfx::Rect root_bounds_in_screen = |
150 GetAuraTarget()->GetRootWindow()->GetBoundsInScreen(); | 149 GetTarget()->GetRootWindow()->GetBoundsInScreen(); |
151 float opacity = 1.0f; | 150 float opacity = 1.0f; |
152 if (!root_bounds_in_screen.Contains(drag_location_in_screen)) { | 151 if (!root_bounds_in_screen.Contains(drag_location_in_screen)) { |
153 gfx::Rect visible_bounds = root_bounds_in_screen; | 152 gfx::Rect visible_bounds = root_bounds_in_screen; |
154 visible_bounds.Intersect(bounds_in_screen); | 153 visible_bounds.Intersect(bounds_in_screen); |
155 opacity = DragWindowController::GetDragWindowOpacity(bounds_in_screen, | 154 opacity = DragWindowController::GetDragWindowOpacity(bounds_in_screen, |
156 visible_bounds); | 155 visible_bounds); |
157 } | 156 } |
158 GetAuraTarget()->layer()->SetOpacity(opacity); | 157 GetTarget()->layer()->SetOpacity(opacity); |
159 drag_window_controller_->Update(bounds_in_screen, drag_location_in_screen); | 158 drag_window_controller_->Update(bounds_in_screen, drag_location_in_screen); |
160 } | 159 } |
161 | 160 |
162 bool DragWindowResizer::ShouldAllowMouseWarp() { | 161 bool DragWindowResizer::ShouldAllowMouseWarp() { |
163 return details().window_component == HTCAPTION && | 162 return details().window_component == HTCAPTION && |
164 !::wm::GetTransientParent(GetAuraTarget()) && | 163 !::wm::GetTransientParent(GetTarget()) && |
165 wm::IsWindowUserPositionable(GetAuraTarget()); | 164 wm::IsWindowUserPositionable(GetTarget()); |
166 } | |
167 | |
168 aura::Window* DragWindowResizer::GetAuraTarget() { | |
169 return WmWindow::GetAuraWindow(GetTarget()); | |
170 } | 165 } |
171 | 166 |
172 } // namespace ash | 167 } // namespace ash |
OLD | NEW |