| 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/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/common/workspace/workspace_window_resizer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/wm/common/default_window_resizer.h" | 12 #include "ash/wm/common/default_window_resizer.h" |
| 13 #include "ash/wm/common/dock/docked_window_layout_manager.h" | 13 #include "ash/wm/common/dock/docked_window_layout_manager.h" |
| 14 #include "ash/wm/common/dock/docked_window_resizer.h" |
| 15 #include "ash/wm/common/panels/panel_window_resizer.h" |
| 14 #include "ash/wm/common/window_positioning_utils.h" | 16 #include "ash/wm/common/window_positioning_utils.h" |
| 15 #include "ash/wm/common/window_state.h" | 17 #include "ash/wm/common/window_state.h" |
| 16 #include "ash/wm/common/wm_event.h" | 18 #include "ash/wm/common/wm_event.h" |
| 17 #include "ash/wm/common/wm_globals.h" | 19 #include "ash/wm/common/wm_globals.h" |
| 18 #include "ash/wm/common/wm_root_window_controller.h" | 20 #include "ash/wm/common/wm_root_window_controller.h" |
| 19 #include "ash/wm/common/wm_screen_util.h" | 21 #include "ash/wm/common/wm_screen_util.h" |
| 20 #include "ash/wm/common/wm_shell_window_ids.h" | 22 #include "ash/wm/common/wm_shell_window_ids.h" |
| 21 #include "ash/wm/common/wm_user_metrics_action.h" | 23 #include "ash/wm/common/wm_user_metrics_action.h" |
| 22 #include "ash/wm/common/wm_window.h" | 24 #include "ash/wm/common/wm_window.h" |
| 23 #include "ash/wm/dock/docked_window_resizer.h" | 25 #include "ash/wm/common/workspace/phantom_window_controller.h" |
| 24 #include "ash/wm/panels/panel_window_resizer.h" | 26 #include "ash/wm/common/workspace/two_step_edge_cycler.h" |
| 25 #include "ash/wm/workspace/phantom_window_controller.h" | |
| 26 #include "ash/wm/workspace/two_step_edge_cycler.h" | |
| 27 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
| 28 #include "base/memory/weak_ptr.h" | 28 #include "base/memory/weak_ptr.h" |
| 29 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
| 30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 31 #include "ui/display/screen.h" | 31 #include "ui/display/screen.h" |
| 32 #include "ui/gfx/transform.h" | 32 #include "ui/gfx/transform.h" |
| 33 #include "ui/wm/public/window_types.h" | 33 #include "ui/wm/public/window_types.h" |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| 36 | 36 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 60 // layout manager when a docked window is being dragged. We should have a | 60 // layout manager when a docked window is being dragged. We should have a |
| 61 // better way of doing this, perhaps by having a way of observing drags or | 61 // better way of doing this, perhaps by having a way of observing drags or |
| 62 // having a generic drag window wrapper which informs a layout manager that a | 62 // having a generic drag window wrapper which informs a layout manager that a |
| 63 // drag has started or stopped. | 63 // drag has started or stopped. |
| 64 // It may be possible to refactor and eliminate chaining. | 64 // It may be possible to refactor and eliminate chaining. |
| 65 std::unique_ptr<WindowResizer> window_resizer; | 65 std::unique_ptr<WindowResizer> window_resizer; |
| 66 | 66 |
| 67 if (!window_state->IsNormalOrSnapped() && !window_state->IsDocked()) | 67 if (!window_state->IsNormalOrSnapped() && !window_state->IsDocked()) |
| 68 return std::unique_ptr<WindowResizer>(); | 68 return std::unique_ptr<WindowResizer>(); |
| 69 | 69 |
| 70 int bounds_change = WindowResizer::GetBoundsChangeForWindowComponent( | 70 int bounds_change = |
| 71 window_component); | 71 WindowResizer::GetBoundsChangeForWindowComponent(window_component); |
| 72 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) | 72 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) |
| 73 return std::unique_ptr<WindowResizer>(); | 73 return std::unique_ptr<WindowResizer>(); |
| 74 | 74 |
| 75 window_state->CreateDragDetails(point_in_parent, window_component, source); | 75 window_state->CreateDragDetails(point_in_parent, window_component, source); |
| 76 const int parent_shell_window_id = | 76 const int parent_shell_window_id = |
| 77 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1; | 77 window->GetParent() ? window->GetParent()->GetShellWindowId() : -1; |
| 78 if (window->GetParent() && | 78 if (window->GetParent() && |
| 79 (parent_shell_window_id == kShellWindowId_DefaultContainer || | 79 (parent_shell_window_id == kShellWindowId_DefaultContainer || |
| 80 parent_shell_window_id == kShellWindowId_DockedContainer || | 80 parent_shell_window_id == kShellWindowId_DockedContainer || |
| 81 parent_shell_window_id == kShellWindowId_PanelContainer)) { | 81 parent_shell_window_id == kShellWindowId_PanelContainer)) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 case MAGNETISM_EDGE_BOTTOM: | 147 case MAGNETISM_EDGE_BOTTOM: |
| 148 y = attach_to.y() - src.height(); | 148 y = attach_to.y() - src.height(); |
| 149 break; | 149 break; |
| 150 case MAGNETISM_EDGE_RIGHT: | 150 case MAGNETISM_EDGE_RIGHT: |
| 151 x = attach_to.x() - src.width(); | 151 x = attach_to.x() - src.width(); |
| 152 break; | 152 break; |
| 153 } | 153 } |
| 154 switch (edge.primary_edge) { | 154 switch (edge.primary_edge) { |
| 155 case MAGNETISM_EDGE_TOP: | 155 case MAGNETISM_EDGE_TOP: |
| 156 case MAGNETISM_EDGE_BOTTOM: | 156 case MAGNETISM_EDGE_BOTTOM: |
| 157 x = CoordinateAlongSecondaryAxis( | 157 x = CoordinateAlongSecondaryAxis(edge.secondary_edge, attach_to.x(), |
| 158 edge.secondary_edge, attach_to.x(), attach_to.right() - src.width(), | 158 attach_to.right() - src.width(), |
| 159 src.x()); | 159 src.x()); |
| 160 break; | 160 break; |
| 161 case MAGNETISM_EDGE_LEFT: | 161 case MAGNETISM_EDGE_LEFT: |
| 162 case MAGNETISM_EDGE_RIGHT: | 162 case MAGNETISM_EDGE_RIGHT: |
| 163 y = CoordinateAlongSecondaryAxis( | 163 y = CoordinateAlongSecondaryAxis(edge.secondary_edge, attach_to.y(), |
| 164 edge.secondary_edge, attach_to.y(), attach_to.bottom() - src.height(), | 164 attach_to.bottom() - src.height(), |
| 165 src.y()); | 165 src.y()); |
| 166 break; | 166 break; |
| 167 } | 167 } |
| 168 return gfx::Point(x, y); | 168 return gfx::Point(x, y); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Returns the bounds for a magnetic attach when resizing. |src| is the bounds | 171 // Returns the bounds for a magnetic attach when resizing. |src| is the bounds |
| 172 // of window being resized, |attach_to| the bounds of the window to attach to | 172 // of window being resized, |attach_to| the bounds of the window to attach to |
| 173 // and |edge| identifies the edge to attach to. | 173 // and |edge| identifies the edge to attach to. |
| 174 gfx::Rect BoundsForMagneticResizeAttach(const gfx::Rect& src, | 174 gfx::Rect BoundsForMagneticResizeAttach(const gfx::Rect& src, |
| 175 const gfx::Rect& attach_to, | 175 const gfx::Rect& attach_to, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; | 255 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; |
| 256 | 256 |
| 257 WorkspaceWindowResizer* WorkspaceWindowResizer::GetInstanceForTest() { | 257 WorkspaceWindowResizer* WorkspaceWindowResizer::GetInstanceForTest() { |
| 258 return instance; | 258 return instance; |
| 259 } | 259 } |
| 260 | 260 |
| 261 // Represents the width or height of a window with constraints on its minimum | 261 // Represents the width or height of a window with constraints on its minimum |
| 262 // and maximum size. 0 represents a lack of a constraint. | 262 // and maximum size. 0 represents a lack of a constraint. |
| 263 class WindowSize { | 263 class WindowSize { |
| 264 public: | 264 public: |
| 265 WindowSize(int size, int min, int max) | 265 WindowSize(int size, int min, int max) : size_(size), min_(min), max_(max) { |
| 266 : size_(size), | |
| 267 min_(min), | |
| 268 max_(max) { | |
| 269 // Grow the min/max bounds to include the starting size. | 266 // Grow the min/max bounds to include the starting size. |
| 270 if (is_underflowing()) | 267 if (is_underflowing()) |
| 271 min_ = size_; | 268 min_ = size_; |
| 272 if (is_overflowing()) | 269 if (is_overflowing()) |
| 273 max_ = size_; | 270 max_ = size_; |
| 274 } | 271 } |
| 275 | 272 |
| 276 bool is_at_capacity(bool shrinking) const { | 273 bool is_at_capacity(bool shrinking) const { |
| 277 return size_ == (shrinking ? min_ : max_); | 274 return size_ == (shrinking ? min_ : max_); |
| 278 } | 275 } |
| 279 | 276 |
| 280 int size() const { | 277 int size() const { return size_; } |
| 281 return size_; | |
| 282 } | |
| 283 | 278 |
| 284 bool has_min() const { | 279 bool has_min() const { return min_ != 0; } |
| 285 return min_ != 0; | |
| 286 } | |
| 287 | 280 |
| 288 bool has_max() const { | 281 bool has_max() const { return max_ != 0; } |
| 289 return max_ != 0; | |
| 290 } | |
| 291 | 282 |
| 292 bool is_valid() const { | 283 bool is_valid() const { return !is_overflowing() && !is_underflowing(); } |
| 293 return !is_overflowing() && !is_underflowing(); | |
| 294 } | |
| 295 | 284 |
| 296 bool is_overflowing() const { | 285 bool is_overflowing() const { return has_max() && size_ > max_; } |
| 297 return has_max() && size_ > max_; | |
| 298 } | |
| 299 | 286 |
| 300 bool is_underflowing() const { | 287 bool is_underflowing() const { return has_min() && size_ < min_; } |
| 301 return has_min() && size_ < min_; | |
| 302 } | |
| 303 | 288 |
| 304 // Add |amount| to this WindowSize not exceeding min or max size constraints. | 289 // Add |amount| to this WindowSize not exceeding min or max size constraints. |
| 305 // Returns by how much |size_| + |amount| exceeds the min/max constraints. | 290 // Returns by how much |size_| + |amount| exceeds the min/max constraints. |
| 306 int Add(int amount) { | 291 int Add(int amount) { |
| 307 DCHECK(is_valid()); | 292 DCHECK(is_valid()); |
| 308 int new_value = size_ + amount; | 293 int new_value = size_ + amount; |
| 309 | 294 |
| 310 if (has_min() && new_value < min_) { | 295 if (has_min() && new_value < min_) { |
| 311 size_ = min_; | 296 size_ = min_; |
| 312 return new_value - min_; | 297 return new_value - min_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 343 } | 328 } |
| 344 | 329 |
| 345 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, | 330 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, |
| 346 int event_flags) { | 331 int event_flags) { |
| 347 last_mouse_location_ = location_in_parent; | 332 last_mouse_location_ = location_in_parent; |
| 348 | 333 |
| 349 int sticky_size; | 334 int sticky_size; |
| 350 if (event_flags & ui::EF_CONTROL_DOWN) { | 335 if (event_flags & ui::EF_CONTROL_DOWN) { |
| 351 sticky_size = 0; | 336 sticky_size = 0; |
| 352 } else if ((details().bounds_change & kBoundsChange_Resizes) && | 337 } else if ((details().bounds_change & kBoundsChange_Resizes) && |
| 353 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 338 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
| 354 sticky_size = kScreenEdgeInsetForTouchDrag; | 339 sticky_size = kScreenEdgeInsetForTouchDrag; |
| 355 } else { | 340 } else { |
| 356 sticky_size = kScreenEdgeInset; | 341 sticky_size = kScreenEdgeInset; |
| 357 } | 342 } |
| 358 // |bounds| is in |GetTarget()->parent()|'s coordinates. | 343 // |bounds| is in |GetTarget()->parent()|'s coordinates. |
| 359 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent); | 344 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent); |
| 360 AdjustBoundsForMainWindow(sticky_size, &bounds); | 345 AdjustBoundsForMainWindow(sticky_size, &bounds); |
| 361 | 346 |
| 362 if (bounds != GetTarget()->GetBounds()) { | 347 if (bounds != GetTarget()->GetBounds()) { |
| 363 if (!did_move_or_resize_) { | 348 if (!did_move_or_resize_) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 // using a keyboard shortcut while dragging it. | 401 // using a keyboard shortcut while dragging it. |
| 417 if (window_state()->GetStateType() != details().initial_state_type) | 402 if (window_state()->GetStateType() != details().initial_state_type) |
| 418 return; | 403 return; |
| 419 | 404 |
| 420 bool snapped = false; | 405 bool snapped = false; |
| 421 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { | 406 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { |
| 422 if (!window_state()->HasRestoreBounds()) { | 407 if (!window_state()->HasRestoreBounds()) { |
| 423 gfx::Rect initial_bounds = GetTarget()->GetParent()->ConvertRectToScreen( | 408 gfx::Rect initial_bounds = GetTarget()->GetParent()->ConvertRectToScreen( |
| 424 details().initial_bounds_in_parent); | 409 details().initial_bounds_in_parent); |
| 425 window_state()->SetRestoreBoundsInScreen( | 410 window_state()->SetRestoreBoundsInScreen( |
| 426 details().restore_bounds.IsEmpty() ? | 411 details().restore_bounds.IsEmpty() ? initial_bounds |
| 427 initial_bounds : | 412 : details().restore_bounds); |
| 428 details().restore_bounds); | |
| 429 } | 413 } |
| 430 if (!dock_layout_->is_dragged_window_docked()) { | 414 if (!dock_layout_->is_dragged_window_docked()) { |
| 431 // TODO(oshima): Add event source type to WMEvent and move | 415 // TODO(oshima): Add event source type to WMEvent and move |
| 432 // metrics recording inside WindowState::OnWMEvent. | 416 // metrics recording inside WindowState::OnWMEvent. |
| 433 const wm::WMEvent event(snap_type_ == SNAP_LEFT ? | 417 const wm::WMEvent event(snap_type_ == SNAP_LEFT |
| 434 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); | 418 ? wm::WM_EVENT_SNAP_LEFT |
| 419 : wm::WM_EVENT_SNAP_RIGHT); |
| 435 window_state()->OnWMEvent(&event); | 420 window_state()->OnWMEvent(&event); |
| 436 globals_->RecordUserMetricsAction( | 421 globals_->RecordUserMetricsAction( |
| 437 snap_type_ == SNAP_LEFT | 422 snap_type_ == SNAP_LEFT |
| 438 ? wm::WmUserMetricsAction::DRAG_MAXIMIZE_LEFT | 423 ? wm::WmUserMetricsAction::DRAG_MAXIMIZE_LEFT |
| 439 : wm::WmUserMetricsAction::DRAG_MAXIMIZE_RIGHT); | 424 : wm::WmUserMetricsAction::DRAG_MAXIMIZE_RIGHT); |
| 440 snapped = true; | 425 snapped = true; |
| 441 } | 426 } |
| 442 } | 427 } |
| 443 | 428 |
| 444 if (!snapped) { | 429 if (!snapped) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // A mousemove should still show the cursor even if the window is | 507 // A mousemove should still show the cursor even if the window is |
| 523 // being moved or resized with touch, so do not lock the cursor. | 508 // being moved or resized with touch, so do not lock the cursor. |
| 524 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 509 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
| 525 globals_->LockCursor(); | 510 globals_->LockCursor(); |
| 526 did_lock_cursor_ = true; | 511 did_lock_cursor_ = true; |
| 527 } | 512 } |
| 528 | 513 |
| 529 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget()); | 514 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget()); |
| 530 | 515 |
| 531 // Only support attaching to the right/bottom. | 516 // Only support attaching to the right/bottom. |
| 532 DCHECK(attached_windows_.empty() || | 517 DCHECK(attached_windows_.empty() || (details().window_component == HTRIGHT || |
| 533 (details().window_component == HTRIGHT || | 518 details().window_component == HTBOTTOM)); |
| 534 details().window_component == HTBOTTOM)); | |
| 535 | 519 |
| 536 // TODO: figure out how to deal with window going off the edge. | 520 // TODO: figure out how to deal with window going off the edge. |
| 537 | 521 |
| 538 // Calculate sizes so that we can maintain the ratios if we need to resize. | 522 // Calculate sizes so that we can maintain the ratios if we need to resize. |
| 539 int total_available = 0; | 523 int total_available = 0; |
| 540 for (size_t i = 0; i < attached_windows_.size(); ++i) { | 524 for (size_t i = 0; i < attached_windows_.size(); ++i) { |
| 541 gfx::Size min(attached_windows_[i]->GetMinimumSize()); | 525 gfx::Size min(attached_windows_[i]->GetMinimumSize()); |
| 542 int initial_size = | 526 int initial_size = |
| 543 PrimaryAxisSize(attached_windows_[i]->GetBounds().size()); | 527 PrimaryAxisSize(attached_windows_[i]->GetBounds().size()); |
| 544 initial_size_.push_back(initial_size); | 528 initial_size_.push_back(initial_size); |
| 545 // If current size is smaller than the min, use the current size as the min. | 529 // If current size is smaller than the min, use the current size as the min. |
| 546 // This way we don't snap on resize. | 530 // This way we don't snap on resize. |
| 547 int min_size = std::min(initial_size, | 531 int min_size = std::min(initial_size, |
| 548 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); | 532 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); |
| 549 total_min_ += min_size; | 533 total_min_ += min_size; |
| 550 total_initial_size_ += initial_size; | 534 total_initial_size_ += initial_size; |
| 551 total_available += std::max(min_size, initial_size) - min_size; | 535 total_available += std::max(min_size, initial_size) - min_size; |
| 552 } | 536 } |
| 553 instance = this; | 537 instance = this; |
| 554 } | 538 } |
| 555 | 539 |
| 556 void WorkspaceWindowResizer::LayoutAttachedWindows( | 540 void WorkspaceWindowResizer::LayoutAttachedWindows(gfx::Rect* bounds) { |
| 557 gfx::Rect* bounds) { | |
| 558 gfx::Rect work_area(wm::GetDisplayWorkAreaBoundsInParent(GetTarget())); | 541 gfx::Rect work_area(wm::GetDisplayWorkAreaBoundsInParent(GetTarget())); |
| 559 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size()); | 542 int initial_size = PrimaryAxisSize(details().initial_bounds_in_parent.size()); |
| 560 int current_size = PrimaryAxisSize(bounds->size()); | 543 int current_size = PrimaryAxisSize(bounds->size()); |
| 561 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); | 544 int start = PrimaryAxisCoordinate(bounds->right(), bounds->bottom()); |
| 562 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); | 545 int end = PrimaryAxisCoordinate(work_area.right(), work_area.bottom()); |
| 563 | 546 |
| 564 int delta = current_size - initial_size; | 547 int delta = current_size - initial_size; |
| 565 int available_size = end - start; | 548 int available_size = end - start; |
| 566 std::vector<int> sizes; | 549 std::vector<int> sizes; |
| 567 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes); | 550 int leftovers = CalculateAttachedSizes(delta, available_size, &sizes); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 652 |
| 670 void WorkspaceWindowResizer::CalculateGrowthRatios( | 653 void WorkspaceWindowResizer::CalculateGrowthRatios( |
| 671 const std::vector<WindowSize*>& sizes, | 654 const std::vector<WindowSize*>& sizes, |
| 672 std::vector<float>* out_ratios) const { | 655 std::vector<float>* out_ratios) const { |
| 673 DCHECK(out_ratios->empty()); | 656 DCHECK(out_ratios->empty()); |
| 674 int total_value = 0; | 657 int total_value = 0; |
| 675 for (size_t i = 0; i < sizes.size(); ++i) | 658 for (size_t i = 0; i < sizes.size(); ++i) |
| 676 total_value += sizes[i]->size(); | 659 total_value += sizes[i]->size(); |
| 677 | 660 |
| 678 for (size_t i = 0; i < sizes.size(); ++i) | 661 for (size_t i = 0; i < sizes.size(); ++i) |
| 679 out_ratios->push_back( | 662 out_ratios->push_back((static_cast<float>(sizes[i]->size())) / total_value); |
| 680 (static_cast<float>(sizes[i]->size())) / total_value); | |
| 681 } | 663 } |
| 682 | 664 |
| 683 void WorkspaceWindowResizer::CreateBucketsForAttached( | 665 void WorkspaceWindowResizer::CreateBucketsForAttached( |
| 684 std::vector<WindowSize>* sizes) const { | 666 std::vector<WindowSize>* sizes) const { |
| 685 for (size_t i = 0; i < attached_windows_.size(); i++) { | 667 for (size_t i = 0; i < attached_windows_.size(); i++) { |
| 686 int initial_size = initial_size_[i]; | 668 int initial_size = initial_size_[i]; |
| 687 int min = PrimaryAxisSize(attached_windows_[i]->GetMinimumSize()); | 669 int min = PrimaryAxisSize(attached_windows_[i]->GetMinimumSize()); |
| 688 int max = PrimaryAxisSize(attached_windows_[i]->GetMaximumSize()); | 670 int max = PrimaryAxisSize(attached_windows_[i]->GetMaximumSize()); |
| 689 | 671 |
| 690 sizes->push_back(WindowSize(initial_size, min, max)); | 672 sizes->push_back(WindowSize(initial_size, min, max)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) | 725 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) |
| 744 ->GetChildren(); | 726 ->GetChildren(); |
| 745 for (auto i = children.rbegin(); | 727 for (auto i = children.rbegin(); |
| 746 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { | 728 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { |
| 747 wm::WindowState* other_state = (*i)->GetWindowState(); | 729 wm::WindowState* other_state = (*i)->GetWindowState(); |
| 748 if (other_state->window() == GetTarget() || | 730 if (other_state->window() == GetTarget() || |
| 749 !other_state->window()->IsVisible() || | 731 !other_state->window()->IsVisible() || |
| 750 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { | 732 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { |
| 751 continue; | 733 continue; |
| 752 } | 734 } |
| 753 if (matcher.ShouldAttach( | 735 if (matcher.ShouldAttach(other_state->window()->GetBoundsInScreen(), |
| 754 other_state->window()->GetBoundsInScreen(), &magnetism_edge_)) { | 736 &magnetism_edge_)) { |
| 755 magnetism_window_ = other_state->window(); | 737 magnetism_window_ = other_state->window(); |
| 756 window_tracker_.Add(magnetism_window_); | 738 window_tracker_.Add(magnetism_window_); |
| 757 return true; | 739 return true; |
| 758 } | 740 } |
| 759 } | 741 } |
| 760 } | 742 } |
| 761 return false; | 743 return false; |
| 762 } | 744 } |
| 763 | 745 |
| 764 void WorkspaceWindowResizer::AdjustBoundsForMainWindow( | 746 void WorkspaceWindowResizer::AdjustBoundsForMainWindow(int sticky_size, |
| 765 int sticky_size, | 747 gfx::Rect* bounds) { |
| 766 gfx::Rect* bounds) { | |
| 767 gfx::Point last_mouse_location_in_screen = | 748 gfx::Point last_mouse_location_in_screen = |
| 768 GetTarget()->GetParent()->ConvertPointToScreen(last_mouse_location_); | 749 GetTarget()->GetParent()->ConvertPointToScreen(last_mouse_location_); |
| 769 display::Display display = | 750 display::Display display = |
| 770 display::Screen::GetScreen()->GetDisplayNearestPoint( | 751 display::Screen::GetScreen()->GetDisplayNearestPoint( |
| 771 last_mouse_location_in_screen); | 752 last_mouse_location_in_screen); |
| 772 gfx::Rect work_area = | 753 gfx::Rect work_area = |
| 773 GetTarget()->GetParent()->ConvertRectFromScreen(display.work_area()); | 754 GetTarget()->GetParent()->ConvertRectFromScreen(display.work_area()); |
| 774 if (details().window_component == HTCAPTION) { | 755 if (details().window_component == HTCAPTION) { |
| 775 // Adjust the bounds to the work area where the mouse cursor is located. | 756 // Adjust the bounds to the work area where the mouse cursor is located. |
| 776 // Always keep kMinOnscreenHeight or the window height (whichever is less) | 757 // Always keep kMinOnscreenHeight or the window height (whichever is less) |
| 777 // on the bottom. | 758 // on the bottom. |
| 778 int max_y = work_area.bottom() - std::min(kMinOnscreenHeight, | 759 int max_y = |
| 779 bounds->height()); | 760 work_area.bottom() - std::min(kMinOnscreenHeight, bounds->height()); |
| 780 if (bounds->y() > max_y) { | 761 if (bounds->y() > max_y) { |
| 781 bounds->set_y(max_y); | 762 bounds->set_y(max_y); |
| 782 } else if (bounds->y() <= work_area.y()) { | 763 } else if (bounds->y() <= work_area.y()) { |
| 783 // Don't allow dragging above the top of the display until the mouse | 764 // Don't allow dragging above the top of the display until the mouse |
| 784 // cursor reaches the work area above if any. | 765 // cursor reaches the work area above if any. |
| 785 bounds->set_y(work_area.y()); | 766 bounds->set_y(work_area.y()); |
| 786 } | 767 } |
| 787 | 768 |
| 788 if (sticky_size > 0) { | 769 if (sticky_size > 0) { |
| 789 // Possibly stick to edge except when a mouse pointer is outside the | 770 // Possibly stick to edge except when a mouse pointer is outside the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 804 if (details().window_component == HTRIGHT) { | 785 if (details().window_component == HTRIGHT) { |
| 805 bounds->set_width(std::min(bounds->width(), | 786 bounds->set_width(std::min(bounds->width(), |
| 806 work_area.right() - total_min_ - bounds->x())); | 787 work_area.right() - total_min_ - bounds->x())); |
| 807 } else { | 788 } else { |
| 808 DCHECK_EQ(HTBOTTOM, details().window_component); | 789 DCHECK_EQ(HTBOTTOM, details().window_component); |
| 809 bounds->set_height(std::min(bounds->height(), | 790 bounds->set_height(std::min(bounds->height(), |
| 810 work_area.bottom() - total_min_ - bounds->y())); | 791 work_area.bottom() - total_min_ - bounds->y())); |
| 811 } | 792 } |
| 812 } | 793 } |
| 813 | 794 |
| 814 bool WorkspaceWindowResizer::StickToWorkAreaOnMove( | 795 bool WorkspaceWindowResizer::StickToWorkAreaOnMove(const gfx::Rect& work_area, |
| 815 const gfx::Rect& work_area, | 796 int sticky_size, |
| 816 int sticky_size, | 797 gfx::Rect* bounds) const { |
| 817 gfx::Rect* bounds) const { | |
| 818 const int left_edge = work_area.x(); | 798 const int left_edge = work_area.x(); |
| 819 const int right_edge = work_area.right(); | 799 const int right_edge = work_area.right(); |
| 820 const int top_edge = work_area.y(); | 800 const int top_edge = work_area.y(); |
| 821 const int bottom_edge = work_area.bottom(); | 801 const int bottom_edge = work_area.bottom(); |
| 822 bool updated = false; | 802 bool updated = false; |
| 823 if (ShouldStickToEdge(bounds->x() - left_edge, sticky_size)) { | 803 if (ShouldStickToEdge(bounds->x() - left_edge, sticky_size)) { |
| 824 bounds->set_x(left_edge); | 804 bounds->set_x(left_edge); |
| 825 updated = true; | 805 updated = true; |
| 826 } else if (ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { | 806 } else if (ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { |
| 827 bounds->set_x(right_edge - bounds->width()); | 807 bounds->set_x(right_edge - bounds->width()); |
| 828 updated = true; | 808 updated = true; |
| 829 } | 809 } |
| 830 if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { | 810 if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { |
| 831 bounds->set_y(top_edge); | 811 bounds->set_y(top_edge); |
| 832 updated = true; | 812 updated = true; |
| 833 } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size) && | 813 } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size) && |
| 834 bounds->height() < (bottom_edge - top_edge)) { | 814 bounds->height() < (bottom_edge - top_edge)) { |
| 835 // Only snap to the bottom if the window is smaller than the work area. | 815 // Only snap to the bottom if the window is smaller than the work area. |
| 836 // Doing otherwise can lead to window snapping in weird ways as it bounces | 816 // Doing otherwise can lead to window snapping in weird ways as it bounces |
| 837 // between snapping to top then bottom. | 817 // between snapping to top then bottom. |
| 838 bounds->set_y(bottom_edge - bounds->height()); | 818 bounds->set_y(bottom_edge - bounds->height()); |
| 839 updated = true; | 819 updated = true; |
| 840 } | 820 } |
| 841 return updated; | 821 return updated; |
| 842 } | 822 } |
| 843 | 823 |
| 844 void WorkspaceWindowResizer::StickToWorkAreaOnResize( | 824 void WorkspaceWindowResizer::StickToWorkAreaOnResize(const gfx::Rect& work_area, |
| 845 const gfx::Rect& work_area, | 825 int sticky_size, |
| 846 int sticky_size, | 826 gfx::Rect* bounds) const { |
| 847 gfx::Rect* bounds) const { | |
| 848 const uint32_t edges = | 827 const uint32_t edges = |
| 849 WindowComponentToMagneticEdge(details().window_component); | 828 WindowComponentToMagneticEdge(details().window_component); |
| 850 const int left_edge = work_area.x(); | 829 const int left_edge = work_area.x(); |
| 851 const int right_edge = work_area.right(); | 830 const int right_edge = work_area.right(); |
| 852 const int top_edge = work_area.y(); | 831 const int top_edge = work_area.y(); |
| 853 const int bottom_edge = work_area.bottom(); | 832 const int bottom_edge = work_area.bottom(); |
| 854 if (edges & MAGNETISM_EDGE_TOP && | 833 if (edges & MAGNETISM_EDGE_TOP && |
| 855 ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { | 834 ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { |
| 856 bounds->set_height(bounds->bottom() - top_edge); | 835 bounds->set_height(bounds->bottom() - top_edge); |
| 857 bounds->set_y(top_edge); | 836 bounds->set_y(top_edge); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { | 876 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { |
| 898 snap_phantom_window_controller_.reset(); | 877 snap_phantom_window_controller_.reset(); |
| 899 edge_cycler_.reset(); | 878 edge_cycler_.reset(); |
| 900 if (snap_type_ == SNAP_NONE) { | 879 if (snap_type_ == SNAP_NONE) { |
| 901 SetDraggedWindowDocked(false); | 880 SetDraggedWindowDocked(false); |
| 902 return; | 881 return; |
| 903 } | 882 } |
| 904 } | 883 } |
| 905 | 884 |
| 906 DCHECK(snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT); | 885 DCHECK(snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT); |
| 907 DockedAlignment desired_alignment = (snap_type_ == SNAP_LEFT) ? | 886 DockedAlignment desired_alignment = (snap_type_ == SNAP_LEFT) |
| 908 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; | 887 ? DOCKED_ALIGNMENT_LEFT |
| 888 : DOCKED_ALIGNMENT_RIGHT; |
| 909 const bool can_dock = | 889 const bool can_dock = |
| 910 dock_layout_->CanDockWindow(GetTarget(), desired_alignment) && | 890 dock_layout_->CanDockWindow(GetTarget(), desired_alignment) && |
| 911 dock_layout_->GetAlignmentOfWindow(GetTarget()) != DOCKED_ALIGNMENT_NONE; | 891 dock_layout_->GetAlignmentOfWindow(GetTarget()) != DOCKED_ALIGNMENT_NONE; |
| 912 if (!can_dock) { | 892 if (!can_dock) { |
| 913 // If the window cannot be docked, undock the window. This may change the | 893 // If the window cannot be docked, undock the window. This may change the |
| 914 // workspace bounds and hence |snap_type_|. | 894 // workspace bounds and hence |snap_type_|. |
| 915 SetDraggedWindowDocked(false); | 895 SetDraggedWindowDocked(false); |
| 916 snap_type_ = GetSnapType(location); | 896 snap_type_ = GetSnapType(location); |
| 917 } | 897 } |
| 918 const bool can_snap = snap_type_ != SNAP_NONE && window_state()->CanSnap(); | 898 const bool can_snap = snap_type_ != SNAP_NONE && window_state()->CanSnap(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || | 1013 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || |
| 1034 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); | 1014 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
| 1035 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); | 1015 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); |
| 1036 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) | 1016 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) |
| 1037 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); | 1017 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); |
| 1038 snapped_bounds.set_width(bounds_in_parent.width()); | 1018 snapped_bounds.set_width(bounds_in_parent.width()); |
| 1039 return bounds_in_parent == snapped_bounds; | 1019 return bounds_in_parent == snapped_bounds; |
| 1040 } | 1020 } |
| 1041 | 1021 |
| 1042 } // namespace ash | 1022 } // namespace ash |
| OLD | NEW |