Chromium Code Reviews| 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/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/system_modal_container_layout_manager.h" | 12 #include "ash/wm/system_modal_container_layout_manager.h" |
| 13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/wm_event.h" | 15 #include "ash/wm/wm_event.h" |
| 16 #include "ash/wm_window.h" | 16 #include "ash/wm_window.h" |
| 17 #include "ui/aura/client/focus_client.h" | 17 #include "ui/aura/client/focus_client.h" |
| 18 #include "ui/aura/window.h" | |
| 19 #include "ui/aura/window_delegate.h" | |
| 18 #include "ui/aura/window_tracker.h" | 20 #include "ui/aura/window_tracker.h" |
| 19 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 20 #include "ui/display/types/display_constants.h" | 22 #include "ui/display/types/display_constants.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 23 | 25 |
| 24 namespace ash { | 26 namespace ash { |
| 25 namespace wm { | 27 namespace wm { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 // Returns the default width of a snapped window. | 31 // Returns the default width of a snapped window. |
| 30 int GetDefaultSnappedWindowWidth(WmWindow* window) { | 32 int GetDefaultSnappedWindowWidth(aura::Window* window) { |
| 31 const float kSnappedWidthWorkspaceRatio = 0.5f; | 33 const float kSnappedWidthWorkspaceRatio = 0.5f; |
| 32 | 34 |
| 33 int work_area_width = | 35 int work_area_width = |
| 34 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()) | 36 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window).width(); |
| 35 .width(); | 37 int min_width = |
| 36 int min_width = window->GetMinimumSize().width(); | 38 window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; |
|
msw
2017/05/22 19:26:11
Is it okay for this to ignore WmWidow::use_empty_m
sky
2017/05/22 19:50:59
All tests pass with this patch, so currently yet.
| |
| 37 int ideal_width = | 39 int ideal_width = |
| 38 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); | 40 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); |
| 39 return std::min(work_area_width, std::max(ideal_width, min_width)); | 41 return std::min(work_area_width, std::max(ideal_width, min_width)); |
| 40 } | 42 } |
| 41 | 43 |
| 42 // Return true if the window or one of its ancestor returns true from | 44 // Return true if the window or one of its ancestor returns true from |
| 43 // IsLockedToRoot(). | 45 // IsLockedToRoot(). |
| 44 bool IsWindowOrAncestorLockedToRoot(const WmWindow* window) { | 46 bool IsWindowOrAncestorLockedToRoot(const WmWindow* window) { |
| 45 return window && (window->IsLockedToRoot() || | 47 return window && (window->IsLockedToRoot() || |
| 46 IsWindowOrAncestorLockedToRoot(window->GetParent())); | 48 IsWindowOrAncestorLockedToRoot(window->GetParent())); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 if (bounds->y() < visible_area.y()) | 104 if (bounds->y() < visible_area.y()) |
| 103 bounds->set_y(visible_area.y()); | 105 bounds->set_y(visible_area.y()); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, | 108 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, |
| 107 gfx::Rect* bounds) { | 109 gfx::Rect* bounds) { |
| 108 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea, | 110 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea, |
| 109 kMinimumOnScreenArea, bounds); | 111 kMinimumOnScreenArea, bounds); |
| 110 } | 112 } |
| 111 | 113 |
| 112 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(WmWindow* window) { | 114 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(aura::Window* window) { |
| 113 gfx::Rect work_area_in_parent( | 115 gfx::Rect work_area_in_parent( |
| 114 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window())); | 116 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window)); |
| 115 return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), | 117 return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), |
| 116 GetDefaultSnappedWindowWidth(window), | 118 GetDefaultSnappedWindowWidth(window), |
| 117 work_area_in_parent.height()); | 119 work_area_in_parent.height()); |
| 118 } | 120 } |
| 119 | 121 |
| 120 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(WmWindow* window) { | 122 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { |
| 121 gfx::Rect work_area_in_parent( | 123 gfx::Rect work_area_in_parent( |
| 122 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window())); | 124 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window)); |
| 123 int width = GetDefaultSnappedWindowWidth(window); | 125 int width = GetDefaultSnappedWindowWidth(window); |
| 124 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), | 126 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), |
| 125 width, work_area_in_parent.height()); | 127 width, work_area_in_parent.height()); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void CenterWindow(WmWindow* window) { | 130 void CenterWindow(WmWindow* window) { |
| 129 WMEvent event(WM_EVENT_CENTER); | 131 WMEvent event(WM_EVENT_CENTER); |
| 130 window->GetWindowState()->OnWMEvent(&event); | 132 window->GetWindowState()->OnWMEvent(&event); |
| 131 } | 133 } |
| 132 | 134 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 } | 199 } |
| 198 gfx::Point origin(bounds_in_screen.origin()); | 200 gfx::Point origin(bounds_in_screen.origin()); |
| 199 const gfx::Point display_origin = | 201 const gfx::Point display_origin = |
| 200 window->GetDisplayNearestWindow().bounds().origin(); | 202 window->GetDisplayNearestWindow().bounds().origin(); |
| 201 origin.Offset(-display_origin.x(), -display_origin.y()); | 203 origin.Offset(-display_origin.x(), -display_origin.y()); |
| 202 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); | 204 window->SetBounds(gfx::Rect(origin, bounds_in_screen.size())); |
| 203 } | 205 } |
| 204 | 206 |
| 205 } // namespace wm | 207 } // namespace wm |
| 206 } // namespace ash | 208 } // namespace ash |
| OLD | NEW |