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