| 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_util.h" | 8 #include "ash/screen_util.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" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return new DragWindowResizer(next_window_resizer, window_state); | 69 return new DragWindowResizer(next_window_resizer, window_state); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 72 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
| 73 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); | 73 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
| 74 next_window_resizer_->Drag(location, event_flags); | 74 next_window_resizer_->Drag(location, event_flags); |
| 75 | 75 |
| 76 if (!resizer) | 76 if (!resizer) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 if (!GetTarget()->HasCapture()) |
| 80 GetTarget()->SetCapture(); |
| 81 |
| 79 last_mouse_location_ = location; | 82 last_mouse_location_ = location; |
| 80 // Show a phantom window for dragging in another root window. | 83 // Show a phantom window for dragging in another root window. |
| 81 if (HasSecondaryRootWindow()) { | 84 if (HasSecondaryRootWindow()) { |
| 82 gfx::Point location_in_screen = location; | 85 gfx::Point location_in_screen = location; |
| 83 ::wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); | 86 ::wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); |
| 84 const bool in_original_root = | 87 const bool in_original_root = |
| 85 wm::GetRootWindowAt(location_in_screen) == GetTarget()->GetRootWindow(); | 88 wm::GetRootWindowAt(location_in_screen) == GetTarget()->GetRootWindow(); |
| 86 UpdateDragWindow(GetTarget()->bounds(), in_original_root); | 89 UpdateDragWindow(GetTarget()->bounds(), in_original_root); |
| 87 } else { | 90 } else { |
| 88 drag_window_controller_.reset(); | 91 drag_window_controller_.reset(); |
| 89 } | 92 } |
| 90 } | 93 } |
| 91 | 94 |
| 92 void DragWindowResizer::CompleteDrag() { | 95 void DragWindowResizer::CompleteDrag() { |
| 93 next_window_resizer_->CompleteDrag(); | 96 next_window_resizer_->CompleteDrag(); |
| 94 | 97 |
| 95 GetTarget()->layer()->SetOpacity(details().initial_opacity); | 98 GetTarget()->layer()->SetOpacity(details().initial_opacity); |
| 96 drag_window_controller_.reset(); | 99 drag_window_controller_.reset(); |
| 97 | 100 |
| 98 // Check if the destination is another display. | 101 // Check if the destination is another display. |
| 99 gfx::Point last_mouse_location_in_screen = last_mouse_location_; | 102 gfx::Point last_mouse_location_in_screen = last_mouse_location_; |
| 100 ::wm::ConvertPointToScreen(GetTarget()->parent(), | 103 ::wm::ConvertPointToScreen(GetTarget()->parent(), |
| 101 &last_mouse_location_in_screen); | 104 &last_mouse_location_in_screen); |
| 102 gfx::Screen* screen = Shell::GetScreen(); | 105 gfx::Screen* screen = Shell::GetScreen(); |
| 103 const gfx::Display dst_display = | 106 const gfx::Display dst_display = |
| 104 screen->GetDisplayNearestPoint(last_mouse_location_in_screen); | 107 screen->GetDisplayNearestPoint(last_mouse_location_in_screen); |
| 105 | 108 |
| 109 if (GetTarget()->HasCapture()) |
| 110 GetTarget()->ReleaseCapture(); |
| 111 |
| 106 if (dst_display.id() != | 112 if (dst_display.id() != |
| 107 screen->GetDisplayNearestWindow(GetTarget()->GetRootWindow()).id()) { | 113 screen->GetDisplayNearestWindow(GetTarget()->GetRootWindow()).id()) { |
| 108 // Adjust the size and position so that it doesn't exceed the size of | 114 // Adjust the size and position so that it doesn't exceed the size of |
| 109 // work area. | 115 // work area. |
| 110 const gfx::Size& size = dst_display.work_area().size(); | 116 const gfx::Size& size = dst_display.work_area().size(); |
| 111 gfx::Rect bounds = GetTarget()->bounds(); | 117 gfx::Rect bounds = GetTarget()->bounds(); |
| 112 if (bounds.width() > size.width()) { | 118 if (bounds.width() > size.width()) { |
| 113 int diff = bounds.width() - size.width(); | 119 int diff = bounds.width() - size.width(); |
| 114 bounds.set_x(bounds.x() + diff / 2); | 120 bounds.set_x(bounds.x() + diff / 2); |
| 115 bounds.set_width(size.width()); | 121 bounds.set_width(size.width()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 133 | 139 |
| 134 GetTarget()->SetBoundsInScreen(dst_bounds, dst_display); | 140 GetTarget()->SetBoundsInScreen(dst_bounds, dst_display); |
| 135 } | 141 } |
| 136 } | 142 } |
| 137 | 143 |
| 138 void DragWindowResizer::RevertDrag() { | 144 void DragWindowResizer::RevertDrag() { |
| 139 next_window_resizer_->RevertDrag(); | 145 next_window_resizer_->RevertDrag(); |
| 140 | 146 |
| 141 drag_window_controller_.reset(); | 147 drag_window_controller_.reset(); |
| 142 GetTarget()->layer()->SetOpacity(details().initial_opacity); | 148 GetTarget()->layer()->SetOpacity(details().initial_opacity); |
| 149 |
| 150 if (GetTarget()->HasCapture()) |
| 151 GetTarget()->ReleaseCapture(); |
| 143 } | 152 } |
| 144 | 153 |
| 145 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, | 154 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, |
| 146 wm::WindowState* window_state) | 155 wm::WindowState* window_state) |
| 147 : WindowResizer(window_state), | 156 : WindowResizer(window_state), |
| 148 next_window_resizer_(next_window_resizer), | 157 next_window_resizer_(next_window_resizer), |
| 149 weak_ptr_factory_(this) { | 158 weak_ptr_factory_(this) { |
| 150 // The pointer should be confined in one display during resizing a window | 159 // The pointer should be confined in one display during resizing a window |
| 151 // because the window cannot span two displays at the same time anyway. The | 160 // because the window cannot span two displays at the same time anyway. The |
| 152 // exception is window/tab dragging operation. During that operation, | 161 // exception is window/tab dragging operation. During that operation, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 213 } |
| 205 | 214 |
| 206 bool DragWindowResizer::ShouldAllowMouseWarp() { | 215 bool DragWindowResizer::ShouldAllowMouseWarp() { |
| 207 return (details().window_component == HTCAPTION) && | 216 return (details().window_component == HTCAPTION) && |
| 208 !::wm::GetTransientParent(GetTarget()) && | 217 !::wm::GetTransientParent(GetTarget()) && |
| 209 (GetTarget()->type() == ui::wm::WINDOW_TYPE_NORMAL || | 218 (GetTarget()->type() == ui::wm::WINDOW_TYPE_NORMAL || |
| 210 GetTarget()->type() == ui::wm::WINDOW_TYPE_PANEL); | 219 GetTarget()->type() == ui::wm::WINDOW_TYPE_PANEL); |
| 211 } | 220 } |
| 212 | 221 |
| 213 } // namespace ash | 222 } // namespace ash |
| OLD | NEW |