[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/screen_util.h" |
| 6 | |
Ahmed Fakhry | 1ac713b | 2018-11-06 18:57:46 | [diff] [blame] | 7 | #include "ash/display/display_configuration_controller.h" |
| 8 | #include "ash/display/mirror_window_controller.h" |
| 9 | #include "ash/display/window_tree_host_manager.h" |
Sammie Quon | 17d0def | 2018-12-14 22:19:15 | [diff] [blame] | 10 | #include "ash/public/cpp/shell_window_ids.h" |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 11 | #include "ash/shelf/shelf.h" |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 12 | #include "ash/shell.h" |
Ahmed Fakhry | f929d5f | 2019-04-11 02:22:48 | [diff] [blame] | 13 | #include "ash/wm/desks/desks_util.h" |
Aga Wronska | f053e52 | 2019-03-27 00:08:42 | [diff] [blame] | 14 | #include "ash/wm/work_area_insets.h" |
Hans Wennborg | 3769645 | 2020-04-24 18:28:49 | [diff] [blame] | 15 | #include "base/check_op.h" |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 16 | #include "ui/aura/client/screen_position_client.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 17 | #include "ui/aura/window_event_dispatcher.h" |
Malay Keshav | fd6fd0c | 2018-07-31 22:07:47 | [diff] [blame] | 18 | #include "ui/aura/window_tree_host.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 19 | #include "ui/display/display.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 20 | #include "ui/display/manager/display_manager.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 21 | #include "ui/display/screen.h" |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 22 | #include "ui/gfx/geometry/size_conversions.h" |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 23 | #include "ui/wm/core/coordinate_conversion.h" |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 24 | |
| 25 | namespace ash { |
| 26 | |
Qiang Xu | 07d7c9e3 | 2018-01-18 20:25:44 | [diff] [blame] | 27 | namespace screen_util { |
| 28 | |
| 29 | gfx::Rect GetMaximizedWindowBoundsInParent(aura::Window* window) { |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 30 | if (Shelf::ForWindow(window)->shelf_widget()) |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 31 | return GetDisplayWorkAreaBoundsInParent(window); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 32 | return GetDisplayBoundsInParent(window); |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 33 | } |
| 34 | |
Qiang Xu | 07d7c9e3 | 2018-01-18 20:25:44 | [diff] [blame] | 35 | gfx::Rect GetDisplayBoundsInParent(aura::Window* window) { |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 36 | gfx::Rect result = |
| 37 | display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds(); |
| 38 | ::wm::ConvertRectFromScreen(window->parent(), &result); |
| 39 | return result; |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 40 | } |
| 41 | |
Ahmed Fakhry | 5d73bdf7 | 2019-02-27 18:21:07 | [diff] [blame] | 42 | gfx::Rect GetFullscreenWindowBoundsInParent(aura::Window* window) { |
| 43 | gfx::Rect result = GetDisplayBoundsInParent(window); |
Aga Wronska | f053e52 | 2019-03-27 00:08:42 | [diff] [blame] | 44 | const WorkAreaInsets* const work_area_insets = |
| 45 | WorkAreaInsets::ForWindow(window->GetRootWindow()); |
Aga Wronska | 5f0a7e07 | 2019-03-26 17:31:20 | [diff] [blame] | 46 | result.Inset(0, |
Aga Wronska | f053e52 | 2019-03-27 00:08:42 | [diff] [blame] | 47 | work_area_insets->accessibility_panel_height() + |
| 48 | work_area_insets->docked_magnifier_height(), |
Aga Wronska | 5f0a7e07 | 2019-03-26 17:31:20 | [diff] [blame] | 49 | 0, 0); |
Ahmed Fakhry | 5d73bdf7 | 2019-02-27 18:21:07 | [diff] [blame] | 50 | return result; |
| 51 | } |
| 52 | |
Qiang Xu | 07d7c9e3 | 2018-01-18 20:25:44 | [diff] [blame] | 53 | gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window) { |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 54 | gfx::Rect result = |
| 55 | display::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
| 56 | ::wm::ConvertRectFromScreen(window->parent(), &result); |
| 57 | return result; |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 58 | } |
| 59 | |
Qiang Xu | 07d7c9e3 | 2018-01-18 20:25:44 | [diff] [blame] | 60 | gfx::Rect GetDisplayWorkAreaBoundsInParentForLockScreen(aura::Window* window) { |
Aga Wronska | 4397114 | 2019-04-12 01:18:20 | [diff] [blame] | 61 | gfx::Rect bounds = WorkAreaInsets::ForWindow(window)->user_work_area_bounds(); |
tbarzic | 98adf00 | 2017-05-26 17:28:17 | [diff] [blame] | 62 | ::wm::ConvertRectFromScreen(window->parent(), &bounds); |
| 63 | return bounds; |
| 64 | } |
| 65 | |
Ahmed Fakhry | f929d5f | 2019-04-11 02:22:48 | [diff] [blame] | 66 | gfx::Rect GetDisplayWorkAreaBoundsInParentForActiveDeskContainer( |
Sammie Quon | 17d0def | 2018-12-14 22:19:15 | [diff] [blame] | 67 | aura::Window* window) { |
| 68 | aura::Window* root_window = window->GetRootWindow(); |
| 69 | return GetDisplayWorkAreaBoundsInParent( |
Ahmed Fakhry | f929d5f | 2019-04-11 02:22:48 | [diff] [blame] | 70 | desks_util::GetActiveDeskContainerForRoot(root_window)); |
Sammie Quon | 17d0def | 2018-12-14 22:19:15 | [diff] [blame] | 71 | } |
| 72 | |
Ahmed Fakhry | f929d5f | 2019-04-11 02:22:48 | [diff] [blame] | 73 | gfx::Rect GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer( |
Sammie Quon | 17d0def | 2018-12-14 22:19:15 | [diff] [blame] | 74 | aura::Window* window) { |
| 75 | gfx::Rect bounds = |
Ahmed Fakhry | f929d5f | 2019-04-11 02:22:48 | [diff] [blame] | 76 | GetDisplayWorkAreaBoundsInParentForActiveDeskContainer(window); |
Sammie Quon | 17d0def | 2018-12-14 22:19:15 | [diff] [blame] | 77 | ::wm::ConvertRectToScreen(window->GetRootWindow(), &bounds); |
| 78 | return bounds; |
| 79 | } |
| 80 | |
Qiang Xu | 07d7c9e3 | 2018-01-18 20:25:44 | [diff] [blame] | 81 | gfx::Rect GetDisplayBoundsWithShelf(aura::Window* window) { |
Manu Cornet | 5bab914 | 2019-09-04 01:56:34 | [diff] [blame] | 82 | if (!Shell::Get()->display_manager()->IsInUnifiedMode()) { |
| 83 | return display::Screen::GetScreen() |
| 84 | ->GetDisplayNearestWindow(window) |
| 85 | .bounds(); |
| 86 | } |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 87 | |
Ahmed Fakhry | 1ac713b | 2018-11-06 18:57:46 | [diff] [blame] | 88 | // In Unified Mode, the display that should contain the shelf depends on the |
| 89 | // current shelf alignment. |
| 90 | const display::Display shelf_display = |
| 91 | Shell::Get() |
| 92 | ->display_configuration_controller() |
| 93 | ->GetPrimaryMirroringDisplayForUnifiedDesktop(); |
| 94 | DCHECK_NE(shelf_display.id(), display::kInvalidDisplayId); |
| 95 | gfx::RectF shelf_display_screen_bounds(shelf_display.bounds()); |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame] | 96 | |
Ahmed Fakhry | 1ac713b | 2018-11-06 18:57:46 | [diff] [blame] | 97 | // Transform the bounds back to the unified host's coordinates. |
| 98 | auto inverse_unified_transform = |
| 99 | window->GetRootWindow()->GetHost()->GetInverseRootTransform(); |
| 100 | inverse_unified_transform.TransformRect(&shelf_display_screen_bounds); |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame] | 101 | |
Ahmed Fakhry | 1ac713b | 2018-11-06 18:57:46 | [diff] [blame] | 102 | return gfx::ToEnclosingRect(shelf_display_screen_bounds); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 103 | } |
| 104 | |
Malay Keshav | fd6fd0c | 2018-07-31 22:07:47 | [diff] [blame] | 105 | gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds, |
| 106 | const aura::Window* window) { |
Mitsuru Oshima | 60172c2 | 2019-11-13 22:56:27 | [diff] [blame] | 107 | display::Display display = |
| 108 | display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 109 | const_cast<aura::Window*>(window)); |
Malay Keshav | fd6fd0c | 2018-07-31 22:07:47 | [diff] [blame] | 110 | |
Mitsuru Oshima | 60172c2 | 2019-11-13 22:56:27 | [diff] [blame] | 111 | const float dsf = display.device_scale_factor(); |
| 112 | const gfx::Size display_size_in_pixel = display.GetSizeInPixel(); |
| 113 | const gfx::Size scaled_size_in_pixel = |
| 114 | gfx::ScaleToFlooredSize(display.size(), dsf); |
Malay Keshav | fd6fd0c | 2018-07-31 22:07:47 | [diff] [blame] | 115 | |
| 116 | // Adjusts |bounds| such that the scaled enclosed bounds are atleast as big as |
| 117 | // the scaled enclosing unadjusted bounds. |
| 118 | gfx::Rect snapped_bounds = bounds; |
Mitsuru Oshima | 60172c2 | 2019-11-13 22:56:27 | [diff] [blame] | 119 | if (scaled_size_in_pixel.width() < display_size_in_pixel.width() && |
| 120 | display.bounds().right() == bounds.right()) { |
Malay Keshav | fd6fd0c | 2018-07-31 22:07:47 | [diff] [blame] | 121 | snapped_bounds.Inset(0, 0, -1, 0); |
| 122 | DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).right(), |
| 123 | gfx::ScaleToEnclosingRect(bounds, dsf).right()); |
| 124 | } |
Mitsuru Oshima | 60172c2 | 2019-11-13 22:56:27 | [diff] [blame] | 125 | if (scaled_size_in_pixel.height() < display_size_in_pixel.height() && |
| 126 | display.bounds().bottom() == bounds.bottom()) { |
Malay Keshav | fd6fd0c | 2018-07-31 22:07:47 | [diff] [blame] | 127 | snapped_bounds.Inset(0, 0, 0, -1); |
| 128 | DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).bottom(), |
| 129 | gfx::ScaleToEnclosingRect(bounds, dsf).bottom()); |
| 130 | } |
| 131 | |
| 132 | return snapped_bounds; |
| 133 | } |
| 134 | |
Qiang Xu | 07d7c9e3 | 2018-01-18 20:25:44 | [diff] [blame] | 135 | } // namespace screen_util |
| 136 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 137 | } // namespace ash |