| 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/common/wm/workspace/workspace_window_resizer.h" | 5 #include "ash/common/wm/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> |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds, | 697 bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds, |
| 698 uint32_t edges) { | 698 uint32_t edges) { |
| 699 // |bounds| are in coordinates of original window's parent. | 699 // |bounds| are in coordinates of original window's parent. |
| 700 gfx::Rect bounds_in_screen = | 700 gfx::Rect bounds_in_screen = |
| 701 GetTarget()->GetParent()->ConvertRectToScreen(bounds); | 701 GetTarget()->GetParent()->ConvertRectToScreen(bounds); |
| 702 MagnetismMatcher matcher(bounds_in_screen, edges); | 702 MagnetismMatcher matcher(bounds_in_screen, edges); |
| 703 | 703 |
| 704 // If we snapped to a window then check it first. That way we don't bounce | 704 // If we snapped to a window then check it first. That way we don't bounce |
| 705 // around when close to multiple edges. | 705 // around when close to multiple edges. |
| 706 if (magnetism_window_) { | 706 if (magnetism_window_) { |
| 707 if (window_tracker_.Contains(magnetism_window_) && | 707 if (window_tracker_.Contains(magnetism_window_->aura_window()) && |
| 708 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), | 708 matcher.ShouldAttach(magnetism_window_->GetBoundsInScreen(), |
| 709 &magnetism_edge_)) { | 709 &magnetism_edge_)) { |
| 710 return true; | 710 return true; |
| 711 } | 711 } |
| 712 window_tracker_.Remove(magnetism_window_); | 712 window_tracker_.Remove(magnetism_window_->aura_window()); |
| 713 magnetism_window_ = NULL; | 713 magnetism_window_ = NULL; |
| 714 } | 714 } |
| 715 | 715 |
| 716 // Avoid magnetically snapping windows that are not resizable. | 716 // Avoid magnetically snapping windows that are not resizable. |
| 717 // TODO(oshima): change this to window.type() == TYPE_NORMAL. | 717 // TODO(oshima): change this to window.type() == TYPE_NORMAL. |
| 718 if (!window_state()->CanResize()) | 718 if (!window_state()->CanResize()) |
| 719 return false; | 719 return false; |
| 720 | 720 |
| 721 for (WmWindow* root_window : shell_->GetAllRootWindows()) { | 721 for (WmWindow* root_window : shell_->GetAllRootWindows()) { |
| 722 // Test all children from the desktop in each root window. | 722 // Test all children from the desktop in each root window. |
| 723 const std::vector<WmWindow*> children = | 723 const std::vector<WmWindow*> children = |
| 724 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) | 724 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer) |
| 725 ->GetChildren(); | 725 ->GetChildren(); |
| 726 for (auto i = children.rbegin(); | 726 for (auto i = children.rbegin(); |
| 727 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { | 727 i != children.rend() && !matcher.AreEdgesObscured(); ++i) { |
| 728 wm::WindowState* other_state = (*i)->GetWindowState(); | 728 wm::WindowState* other_state = (*i)->GetWindowState(); |
| 729 if (other_state->window() == GetTarget() || | 729 if (other_state->window() == GetTarget() || |
| 730 !other_state->window()->IsVisible() || | 730 !other_state->window()->IsVisible() || |
| 731 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { | 731 !other_state->IsNormalOrSnapped() || !other_state->CanResize()) { |
| 732 continue; | 732 continue; |
| 733 } | 733 } |
| 734 if (matcher.ShouldAttach(other_state->window()->GetBoundsInScreen(), | 734 if (matcher.ShouldAttach(other_state->window()->GetBoundsInScreen(), |
| 735 &magnetism_edge_)) { | 735 &magnetism_edge_)) { |
| 736 magnetism_window_ = other_state->window(); | 736 magnetism_window_ = other_state->window(); |
| 737 window_tracker_.Add(magnetism_window_); | 737 window_tracker_.Add(magnetism_window_->aura_window()); |
| 738 return true; | 738 return true; |
| 739 } | 739 } |
| 740 } | 740 } |
| 741 } | 741 } |
| 742 return false; | 742 return false; |
| 743 } | 743 } |
| 744 | 744 |
| 745 void WorkspaceWindowResizer::AdjustBoundsForMainWindow(int sticky_size, | 745 void WorkspaceWindowResizer::AdjustBoundsForMainWindow(int sticky_size, |
| 746 gfx::Rect* bounds) { | 746 gfx::Rect* bounds) { |
| 747 gfx::Point last_mouse_location_in_screen = | 747 gfx::Point last_mouse_location_in_screen = |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || | 1013 DCHECK(snapped_type == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || |
| 1014 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); | 1014 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
| 1015 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); | 1015 gfx::Rect snapped_bounds = wm::GetDisplayWorkAreaBoundsInParent(GetTarget()); |
| 1016 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) | 1016 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) |
| 1017 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); | 1017 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); |
| 1018 snapped_bounds.set_width(bounds_in_parent.width()); | 1018 snapped_bounds.set_width(bounds_in_parent.width()); |
| 1019 return bounds_in_parent == snapped_bounds; | 1019 return bounds_in_parent == snapped_bounds; |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 } // namespace ash | 1022 } // namespace ash |
| OLD | NEW |