| 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/window_resizer.h" | 5 #include "ash/wm/window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/wm/root_window_finder.h" | 7 #include "ash/wm/root_window_finder.h" |
| 8 #include "ash/wm/window_positioning_utils.h" | 8 #include "ash/wm/window_positioning_utils.h" |
| 9 #include "ash/wm/window_state.h" | 9 #include "ash/wm/window_state.h" |
| 10 #include "ash/wm_window.h" | 10 #include "ash/wm_window.h" |
| 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_delegate.h" |
| 11 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 12 #include "ui/base/ui_base_types.h" | 14 #include "ui/base/ui_base_types.h" |
| 13 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 14 #include "ui/display/screen.h" | 16 #include "ui/display/screen.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/wm/core/coordinate_conversion.h" |
| 16 | 19 |
| 17 namespace ash { | 20 namespace ash { |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 // Returns true for resize components along the right edge, where a drag in | 24 // Returns true for resize components along the right edge, where a drag in |
| 22 // positive x will make the window larger. | 25 // positive x will make the window larger. |
| 23 bool IsRightEdge(int window_component) { | 26 bool IsRightEdge(int window_component) { |
| 24 return window_component == HTTOPRIGHT || window_component == HTRIGHT || | 27 return window_component == HTTOPRIGHT || window_component == HTRIGHT || |
| 25 window_component == HTBOTTOMRIGHT || window_component == HTGROWBOX; | 28 window_component == HTBOTTOMRIGHT || window_component == HTGROWBOX; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 case HTRIGHT: | 99 case HTRIGHT: |
| 97 case HTLEFT: | 100 case HTLEFT: |
| 98 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal; | 101 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal; |
| 99 break; | 102 break; |
| 100 default: | 103 default: |
| 101 break; | 104 break; |
| 102 } | 105 } |
| 103 return pos_change_direction; | 106 return pos_change_direction; |
| 104 } | 107 } |
| 105 | 108 |
| 109 aura::Window* WindowResizer::GetTarget() const { |
| 110 return window_state_ ? window_state_->window()->aura_window() : nullptr; |
| 111 } |
| 112 |
| 106 gfx::Rect WindowResizer::CalculateBoundsForDrag( | 113 gfx::Rect WindowResizer::CalculateBoundsForDrag( |
| 107 const gfx::Point& passed_location) { | 114 const gfx::Point& passed_location) { |
| 108 if (!details().is_resizable) | 115 if (!details().is_resizable) |
| 109 return details().initial_bounds_in_parent; | 116 return details().initial_bounds_in_parent; |
| 110 | 117 |
| 111 gfx::Point location = passed_location; | 118 gfx::Point location = passed_location; |
| 112 int delta_x = location.x() - details().initial_location_in_parent.x(); | 119 int delta_x = location.x() - details().initial_location_in_parent.x(); |
| 113 int delta_y = location.y() - details().initial_location_in_parent.y(); | 120 int delta_y = location.y() - details().initial_location_in_parent.y(); |
| 114 | 121 |
| 115 AdjustDeltaForTouchResize(&delta_x, &delta_y); | 122 AdjustDeltaForTouchResize(&delta_x, &delta_y); |
| 116 | 123 |
| 117 // The minimize size constraint may limit how much we change the window | 124 // The minimize size constraint may limit how much we change the window |
| 118 // position. For example, dragging the left edge to the right should stop | 125 // position. For example, dragging the left edge to the right should stop |
| 119 // repositioning the window when the minimize size is reached. | 126 // repositioning the window when the minimize size is reached. |
| 120 gfx::Size size = GetSizeForDrag(&delta_x, &delta_y); | 127 gfx::Size size = GetSizeForDrag(&delta_x, &delta_y); |
| 121 gfx::Point origin = GetOriginForDrag(delta_x, delta_y); | 128 gfx::Point origin = GetOriginForDrag(delta_x, delta_y); |
| 122 gfx::Rect new_bounds(origin, size); | 129 gfx::Rect new_bounds(origin, size); |
| 123 | 130 |
| 124 // Sizing has to keep the result on the screen. Note that this correction | 131 // Sizing has to keep the result on the screen. Note that this correction |
| 125 // has to come first since it might have an impact on the origin as well as | 132 // has to come first since it might have an impact on the origin as well as |
| 126 // on the size. | 133 // on the size. |
| 127 if (details().bounds_change & kBoundsChange_Resizes) { | 134 if (details().bounds_change & kBoundsChange_Resizes) { |
| 128 gfx::Rect work_area = GetTarget()->GetDisplayNearestWindow().work_area(); | 135 gfx::Rect work_area = display::Screen::GetScreen() |
| 129 work_area = GetTarget()->GetParent()->ConvertRectFromScreen(work_area); | 136 ->GetDisplayNearestWindow(GetTarget()) |
| 137 .work_area(); |
| 138 ::wm::ConvertRectFromScreen(GetTarget()->parent(), &work_area); |
| 130 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { | 139 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 131 if (IsRightEdge(details().window_component) && | 140 if (IsRightEdge(details().window_component) && |
| 132 new_bounds.right() < work_area.x() + wm::kMinimumOnScreenArea) { | 141 new_bounds.right() < work_area.x() + wm::kMinimumOnScreenArea) { |
| 133 int delta = | 142 int delta = |
| 134 work_area.x() + wm::kMinimumOnScreenArea - new_bounds.right(); | 143 work_area.x() + wm::kMinimumOnScreenArea - new_bounds.right(); |
| 135 new_bounds.set_width(new_bounds.width() + delta); | 144 new_bounds.set_width(new_bounds.width() + delta); |
| 136 } else if (new_bounds.x() > | 145 } else if (new_bounds.x() > |
| 137 work_area.right() - wm::kMinimumOnScreenArea) { | 146 work_area.right() - wm::kMinimumOnScreenArea) { |
| 138 int width = | 147 int width = |
| 139 new_bounds.right() - work_area.right() + wm::kMinimumOnScreenArea; | 148 new_bounds.right() - work_area.right() + wm::kMinimumOnScreenArea; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // be still hit by the cursor. | 182 // be still hit by the cursor. |
| 174 if (details().initial_location_in_parent.x() > | 183 if (details().initial_location_in_parent.x() > |
| 175 details().initial_bounds_in_parent.x() + | 184 details().initial_bounds_in_parent.x() + |
| 176 details().restore_bounds.width()) | 185 details().restore_bounds.width()) |
| 177 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); | 186 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); |
| 178 } | 187 } |
| 179 | 188 |
| 180 // Make sure that |new_bounds| doesn't leave any of the displays. Note that | 189 // Make sure that |new_bounds| doesn't leave any of the displays. Note that |
| 181 // the |work_area| above isn't good for this check since it is the work area | 190 // the |work_area| above isn't good for this check since it is the work area |
| 182 // for the current display but the window can move to a different one. | 191 // for the current display but the window can move to a different one. |
| 183 WmWindow* parent = GetTarget()->GetParent(); | 192 aura::Window* parent = GetTarget()->parent(); |
| 184 gfx::Point passed_location_in_screen( | 193 gfx::Point passed_location_in_screen(passed_location); |
| 185 parent->ConvertPointToScreen(passed_location)); | 194 ::wm::ConvertPointToScreen(parent, &passed_location_in_screen); |
| 186 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); | 195 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); |
| 187 // Use a pointer location (matching the logic in DragWindowResizer) to | 196 // Use a pointer location (matching the logic in DragWindowResizer) to |
| 188 // calculate the target display after the drag. | 197 // calculate the target display after the drag. |
| 189 const display::Display& display = | 198 const display::Display& display = |
| 190 display::Screen::GetScreen()->GetDisplayMatching(near_passed_location); | 199 display::Screen::GetScreen()->GetDisplayMatching(near_passed_location); |
| 191 gfx::Rect screen_work_area = display.work_area(); | 200 gfx::Rect screen_work_area = display.work_area(); |
| 192 screen_work_area.Inset(wm::kMinimumOnScreenArea, 0); | 201 screen_work_area.Inset(wm::kMinimumOnScreenArea, 0); |
| 193 gfx::Rect new_bounds_in_screen = parent->ConvertRectToScreen(new_bounds); | 202 gfx::Rect new_bounds_in_screen(new_bounds); |
| 203 ::wm::ConvertRectToScreen(parent, &new_bounds_in_screen); |
| 194 if (!screen_work_area.Intersects(new_bounds_in_screen)) { | 204 if (!screen_work_area.Intersects(new_bounds_in_screen)) { |
| 195 // Make sure that the x origin does not leave the current display. | 205 // Make sure that the x origin does not leave the current display. |
| 196 new_bounds_in_screen.set_x(std::max( | 206 new_bounds_in_screen.set_x(std::max( |
| 197 screen_work_area.x() - new_bounds.width(), | 207 screen_work_area.x() - new_bounds.width(), |
| 198 std::min(screen_work_area.right(), new_bounds_in_screen.x()))); | 208 std::min(screen_work_area.right(), new_bounds_in_screen.x()))); |
| 199 new_bounds = parent->ConvertRectFromScreen(new_bounds_in_screen); | 209 new_bounds = new_bounds_in_screen; |
| 210 ::wm::ConvertRectFromScreen(parent, &new_bounds); |
| 200 } | 211 } |
| 201 } | 212 } |
| 202 | 213 |
| 203 return new_bounds; | 214 return new_bounds; |
| 204 } | 215 } |
| 205 | 216 |
| 206 // static | 217 // static |
| 207 bool WindowResizer::IsBottomEdge(int window_component) { | 218 bool WindowResizer::IsBottomEdge(int window_component) { |
| 208 return window_component == HTBOTTOMLEFT || window_component == HTBOTTOM || | 219 return window_component == HTBOTTOMLEFT || window_component == HTBOTTOM || |
| 209 window_component == HTBOTTOMRIGHT || window_component == HTGROWBOX; | 220 window_component == HTBOTTOMRIGHT || window_component == HTGROWBOX; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 origin.Offset(delta_x, 0); | 254 origin.Offset(delta_x, 0); |
| 244 if (pos_change_direction & kBoundsChangeDirection_Vertical) | 255 if (pos_change_direction & kBoundsChangeDirection_Vertical) |
| 245 origin.Offset(0, delta_y); | 256 origin.Offset(0, delta_y); |
| 246 } | 257 } |
| 247 return origin; | 258 return origin; |
| 248 } | 259 } |
| 249 | 260 |
| 250 gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) { | 261 gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) { |
| 251 gfx::Size size = details().initial_bounds_in_parent.size(); | 262 gfx::Size size = details().initial_bounds_in_parent.size(); |
| 252 if (details().bounds_change & kBoundsChange_Resizes) { | 263 if (details().bounds_change & kBoundsChange_Resizes) { |
| 253 gfx::Size min_size = GetTarget()->GetMinimumSize(); | 264 gfx::Size min_size = GetTarget()->delegate() |
| 265 ? GetTarget()->delegate()->GetMinimumSize() |
| 266 : gfx::Size(); |
| 254 size.SetSize(GetWidthForDrag(min_size.width(), delta_x), | 267 size.SetSize(GetWidthForDrag(min_size.width(), delta_x), |
| 255 GetHeightForDrag(min_size.height(), delta_y)); | 268 GetHeightForDrag(min_size.height(), delta_y)); |
| 256 } else if (!details().restore_bounds.IsEmpty()) { | 269 } else if (!details().restore_bounds.IsEmpty()) { |
| 257 size = details().restore_bounds.size(); | 270 size = details().restore_bounds.size(); |
| 258 } | 271 } |
| 259 return size; | 272 return size; |
| 260 } | 273 } |
| 261 | 274 |
| 262 int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) { | 275 int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) { |
| 263 int width = details().initial_bounds_in_parent.width(); | 276 int width = details().initial_bounds_in_parent.width(); |
| 264 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { | 277 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 265 // Along the right edge, positive delta_x increases the window size. | 278 // Along the right edge, positive delta_x increases the window size. |
| 266 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; | 279 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; |
| 267 width += x_multiplier * (*delta_x); | 280 width += x_multiplier * (*delta_x); |
| 268 | 281 |
| 269 // Ensure we don't shrink past the minimum width and clamp delta_x | 282 // Ensure we don't shrink past the minimum width and clamp delta_x |
| 270 // for the window origin computation. | 283 // for the window origin computation. |
| 271 if (width < min_width) { | 284 if (width < min_width) { |
| 272 width = min_width; | 285 width = min_width; |
| 273 *delta_x = -x_multiplier * | 286 *delta_x = -x_multiplier * |
| 274 (details().initial_bounds_in_parent.width() - min_width); | 287 (details().initial_bounds_in_parent.width() - min_width); |
| 275 } | 288 } |
| 276 | 289 |
| 277 // And don't let the window go bigger than the display. | 290 // And don't let the window go bigger than the display. |
| 278 int max_width = GetTarget()->GetDisplayNearestWindow().bounds().width(); | 291 int max_width = display::Screen::GetScreen() |
| 279 gfx::Size max_size = GetTarget()->GetMaximumSize(); | 292 ->GetDisplayNearestWindow(GetTarget()) |
| 293 .bounds() |
| 294 .width(); |
| 295 gfx::Size max_size = GetTarget()->delegate() |
| 296 ? GetTarget()->delegate()->GetMaximumSize() |
| 297 : gfx::Size(); |
| 280 if (max_size.width() != 0) | 298 if (max_size.width() != 0) |
| 281 max_width = std::min(max_width, max_size.width()); | 299 max_width = std::min(max_width, max_size.width()); |
| 282 if (width > max_width) { | 300 if (width > max_width) { |
| 283 width = max_width; | 301 width = max_width; |
| 284 *delta_x = -x_multiplier * | 302 *delta_x = -x_multiplier * |
| 285 (details().initial_bounds_in_parent.width() - max_width); | 303 (details().initial_bounds_in_parent.width() - max_width); |
| 286 } | 304 } |
| 287 } | 305 } |
| 288 return width; | 306 return width; |
| 289 } | 307 } |
| 290 | 308 |
| 291 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { | 309 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { |
| 292 int height = details().initial_bounds_in_parent.height(); | 310 int height = details().initial_bounds_in_parent.height(); |
| 293 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { | 311 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { |
| 294 // Along the bottom edge, positive delta_y increases the window size. | 312 // Along the bottom edge, positive delta_y increases the window size. |
| 295 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; | 313 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; |
| 296 height += y_multiplier * (*delta_y); | 314 height += y_multiplier * (*delta_y); |
| 297 | 315 |
| 298 // Ensure we don't shrink past the minimum height and clamp delta_y | 316 // Ensure we don't shrink past the minimum height and clamp delta_y |
| 299 // for the window origin computation. | 317 // for the window origin computation. |
| 300 if (height < min_height) { | 318 if (height < min_height) { |
| 301 height = min_height; | 319 height = min_height; |
| 302 *delta_y = -y_multiplier * | 320 *delta_y = -y_multiplier * |
| 303 (details().initial_bounds_in_parent.height() - min_height); | 321 (details().initial_bounds_in_parent.height() - min_height); |
| 304 } | 322 } |
| 305 | 323 |
| 306 // And don't let the window go bigger than the display. | 324 // And don't let the window go bigger than the display. |
| 307 int max_height = GetTarget()->GetDisplayNearestWindow().bounds().height(); | 325 int max_height = display::Screen::GetScreen() |
| 308 gfx::Size max_size = GetTarget()->GetMaximumSize(); | 326 ->GetDisplayNearestWindow(GetTarget()) |
| 327 .bounds() |
| 328 .height(); |
| 329 gfx::Size max_size = GetTarget()->delegate() |
| 330 ? GetTarget()->delegate()->GetMaximumSize() |
| 331 : gfx::Size(); |
| 309 if (max_size.height() != 0) | 332 if (max_size.height() != 0) |
| 310 max_height = std::min(max_height, max_size.height()); | 333 max_height = std::min(max_height, max_size.height()); |
| 311 if (height > max_height) { | 334 if (height > max_height) { |
| 312 height = max_height; | 335 height = max_height; |
| 313 *delta_y = -y_multiplier * | 336 *delta_y = -y_multiplier * |
| 314 (details().initial_bounds_in_parent.height() - max_height); | 337 (details().initial_bounds_in_parent.height() - max_height); |
| 315 } | 338 } |
| 316 } | 339 } |
| 317 return height; | 340 return height; |
| 318 } | 341 } |
| 319 | 342 |
| 320 } // namespace ash | 343 } // namespace ash |
| OLD | NEW |