| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_positioning_utils.h" | 5 #include "ash/wm/window_positioning_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_util.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/wm/system_modal_container_layout_manager.h" | 12 #include "ash/wm/system_modal_container_layout_manager.h" |
| 12 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 13 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 14 #include "ash/wm/wm_event.h" | 15 #include "ash/wm/wm_event.h" |
| 15 #include "ash/wm/wm_screen_util.h" | |
| 16 #include "ash/wm_window.h" | 16 #include "ash/wm_window.h" |
| 17 #include "ui/aura/window_tracker.h" | 17 #include "ui/aura/window_tracker.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/types/display_constants.h" | 19 #include "ui/display/types/display_constants.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 22 | 22 |
| 23 namespace ash { | 23 namespace ash { |
| 24 namespace wm { | 24 namespace wm { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Returns the default width of a snapped window. | 28 // Returns the default width of a snapped window. |
| 29 int GetDefaultSnappedWindowWidth(WmWindow* window) { | 29 int GetDefaultSnappedWindowWidth(WmWindow* window) { |
| 30 const float kSnappedWidthWorkspaceRatio = 0.5f; | 30 const float kSnappedWidthWorkspaceRatio = 0.5f; |
| 31 | 31 |
| 32 int work_area_width = GetDisplayWorkAreaBoundsInParent(window).width(); | 32 int work_area_width = |
| 33 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()) |
| 34 .width(); |
| 33 int min_width = window->GetMinimumSize().width(); | 35 int min_width = window->GetMinimumSize().width(); |
| 34 int ideal_width = | 36 int ideal_width = |
| 35 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); | 37 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); |
| 36 return std::min(work_area_width, std::max(ideal_width, min_width)); | 38 return std::min(work_area_width, std::max(ideal_width, min_width)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 // Return true if the window or one of its ancestor returns true from | 41 // Return true if the window or one of its ancestor returns true from |
| 40 // IsLockedToRoot(). | 42 // IsLockedToRoot(). |
| 41 bool IsWindowOrAncestorLockedToRoot(const WmWindow* window) { | 43 bool IsWindowOrAncestorLockedToRoot(const WmWindow* window) { |
| 42 return window && (window->IsLockedToRoot() || | 44 return window && (window->IsLockedToRoot() || |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 bounds->set_y(visible_area.y()); | 102 bounds->set_y(visible_area.y()); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, | 105 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, |
| 104 gfx::Rect* bounds) { | 106 gfx::Rect* bounds) { |
| 105 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea, | 107 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea, |
| 106 kMinimumOnScreenArea, bounds); | 108 kMinimumOnScreenArea, bounds); |
| 107 } | 109 } |
| 108 | 110 |
| 109 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(WmWindow* window) { | 111 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(WmWindow* window) { |
| 110 gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); | 112 gfx::Rect work_area_in_parent( |
| 113 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window())); |
| 111 return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), | 114 return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), |
| 112 GetDefaultSnappedWindowWidth(window), | 115 GetDefaultSnappedWindowWidth(window), |
| 113 work_area_in_parent.height()); | 116 work_area_in_parent.height()); |
| 114 } | 117 } |
| 115 | 118 |
| 116 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(WmWindow* window) { | 119 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(WmWindow* window) { |
| 117 gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); | 120 gfx::Rect work_area_in_parent( |
| 121 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window())); |
| 118 int width = GetDefaultSnappedWindowWidth(window); | 122 int width = GetDefaultSnappedWindowWidth(window); |
| 119 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), | 123 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), |
| 120 width, work_area_in_parent.height()); | 124 width, work_area_in_parent.height()); |
| 121 } | 125 } |
| 122 | 126 |
| 123 void CenterWindow(WmWindow* window) { | 127 void CenterWindow(WmWindow* window) { |
| 124 WMEvent event(WM_EVENT_CENTER); | 128 WMEvent event(WM_EVENT_CENTER); |
| 125 window->GetWindowState()->OnWMEvent(&event); | 129 window->GetWindowState()->OnWMEvent(&event); |
| 126 } | 130 } |
| 127 | 131 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 195 } |
| 192 gfx::Point origin(bounds_in_screen.origin()); | 196 gfx::Point origin(bounds_in_screen.origin()); |
| 193 const gfx::Point display_origin = | 197 const gfx::Point display_origin = |
| 194 window->GetDisplayNearestWindow().bounds().origin(); | 198 window->GetDisplayNearestWindow().bounds().origin(); |
| 195 origin.Offset(-display_origin.x(), -display_origin.y()); | 199 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 196 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); | 200 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); |
| 197 } | 201 } |
| 198 | 202 |
| 199 } // namespace wm | 203 } // namespace wm |
| 200 } // namespace ash | 204 } // namespace ash |
| OLD | NEW |