blob: 7d58d2565a8519b6e76dc4d739ec0fcb9cb56442 [file] [log] [blame]
[email protected]55ad8c12014-01-17 18:24:331// 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 Fakhry1ac713b2018-11-06 18:57:467#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 Quon17d0def2018-12-14 22:19:1510#include "ash/public/cpp/shell_window_ids.h"
James Cook840177e2017-05-25 02:20:0111#include "ash/shelf/shelf.h"
[email protected]55ad8c12014-01-17 18:24:3312#include "ash/shell.h"
Ahmed Fakhryf929d5f2019-04-11 02:22:4813#include "ash/wm/desks/desks_util.h"
Aga Wronskaf053e522019-03-27 00:08:4214#include "ash/wm/work_area_insets.h"
Hans Wennborg37696452020-04-24 18:28:4915#include "base/check_op.h"
[email protected]55ad8c12014-01-17 18:24:3316#include "ui/aura/client/screen_position_client.h"
[email protected]fcc51c952014-02-21 21:31:2617#include "ui/aura/window_event_dispatcher.h"
Malay Keshavfd6fd0c2018-07-31 22:07:4718#include "ui/aura/window_tree_host.h"
oshimaf84b0da722016-04-27 19:47:1919#include "ui/display/display.h"
rjkroege72f8154f2016-10-29 00:49:0220#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:1921#include "ui/display/screen.h"
oshima5337ca92015-07-18 02:23:5722#include "ui/gfx/geometry/size_conversions.h"
yhanada698af192017-02-23 10:57:0723#include "ui/wm/core/coordinate_conversion.h"
[email protected]55ad8c12014-01-17 18:24:3324
25namespace ash {
26
Qiang Xu07d7c9e32018-01-18 20:25:4427namespace screen_util {
28
29gfx::Rect GetMaximizedWindowBoundsInParent(aura::Window* window) {
msw257a6a232017-06-01 01:46:3030 if (Shelf::ForWindow(window)->shelf_widget())
[email protected]55ad8c12014-01-17 18:24:3331 return GetDisplayWorkAreaBoundsInParent(window);
sky00f0b892017-05-05 17:06:2432 return GetDisplayBoundsInParent(window);
[email protected]55ad8c12014-01-17 18:24:3333}
34
Qiang Xu07d7c9e32018-01-18 20:25:4435gfx::Rect GetDisplayBoundsInParent(aura::Window* window) {
yhanada698af192017-02-23 10:57:0736 gfx::Rect result =
37 display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds();
38 ::wm::ConvertRectFromScreen(window->parent(), &result);
39 return result;
[email protected]55ad8c12014-01-17 18:24:3340}
41
Ahmed Fakhry5d73bdf72019-02-27 18:21:0742gfx::Rect GetFullscreenWindowBoundsInParent(aura::Window* window) {
43 gfx::Rect result = GetDisplayBoundsInParent(window);
Aga Wronskaf053e522019-03-27 00:08:4244 const WorkAreaInsets* const work_area_insets =
45 WorkAreaInsets::ForWindow(window->GetRootWindow());
Aga Wronska5f0a7e072019-03-26 17:31:2046 result.Inset(0,
Aga Wronskaf053e522019-03-27 00:08:4247 work_area_insets->accessibility_panel_height() +
48 work_area_insets->docked_magnifier_height(),
Aga Wronska5f0a7e072019-03-26 17:31:2049 0, 0);
Ahmed Fakhry5d73bdf72019-02-27 18:21:0750 return result;
51}
52
Qiang Xu07d7c9e32018-01-18 20:25:4453gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
yhanada698af192017-02-23 10:57:0754 gfx::Rect result =
55 display::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area();
56 ::wm::ConvertRectFromScreen(window->parent(), &result);
57 return result;
[email protected]55ad8c12014-01-17 18:24:3358}
59
Qiang Xu07d7c9e32018-01-18 20:25:4460gfx::Rect GetDisplayWorkAreaBoundsInParentForLockScreen(aura::Window* window) {
Aga Wronska43971142019-04-12 01:18:2061 gfx::Rect bounds = WorkAreaInsets::ForWindow(window)->user_work_area_bounds();
tbarzic98adf002017-05-26 17:28:1762 ::wm::ConvertRectFromScreen(window->parent(), &bounds);
63 return bounds;
64}
65
Ahmed Fakhryf929d5f2019-04-11 02:22:4866gfx::Rect GetDisplayWorkAreaBoundsInParentForActiveDeskContainer(
Sammie Quon17d0def2018-12-14 22:19:1567 aura::Window* window) {
68 aura::Window* root_window = window->GetRootWindow();
69 return GetDisplayWorkAreaBoundsInParent(
Ahmed Fakhryf929d5f2019-04-11 02:22:4870 desks_util::GetActiveDeskContainerForRoot(root_window));
Sammie Quon17d0def2018-12-14 22:19:1571}
72
Ahmed Fakhryf929d5f2019-04-11 02:22:4873gfx::Rect GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
Sammie Quon17d0def2018-12-14 22:19:1574 aura::Window* window) {
75 gfx::Rect bounds =
Ahmed Fakhryf929d5f2019-04-11 02:22:4876 GetDisplayWorkAreaBoundsInParentForActiveDeskContainer(window);
Sammie Quon17d0def2018-12-14 22:19:1577 ::wm::ConvertRectToScreen(window->GetRootWindow(), &bounds);
78 return bounds;
79}
80
Qiang Xu07d7c9e32018-01-18 20:25:4481gfx::Rect GetDisplayBoundsWithShelf(aura::Window* window) {
Manu Cornet5bab9142019-09-04 01:56:3482 if (!Shell::Get()->display_manager()->IsInUnifiedMode()) {
83 return display::Screen::GetScreen()
84 ->GetDisplayNearestWindow(window)
85 .bounds();
86 }
sky00f0b892017-05-05 17:06:2487
Ahmed Fakhry1ac713b2018-11-06 18:57:4688 // 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 Fakhry4f8e3722017-10-31 21:01:5896
Ahmed Fakhry1ac713b2018-11-06 18:57:4697 // 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 Fakhry4f8e3722017-10-31 21:01:58101
Ahmed Fakhry1ac713b2018-11-06 18:57:46102 return gfx::ToEnclosingRect(shelf_display_screen_bounds);
sky00f0b892017-05-05 17:06:24103}
104
Malay Keshavfd6fd0c2018-07-31 22:07:47105gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds,
106 const aura::Window* window) {
Mitsuru Oshima60172c22019-11-13 22:56:27107 display::Display display =
108 display::Screen::GetScreen()->GetDisplayNearestWindow(
109 const_cast<aura::Window*>(window));
Malay Keshavfd6fd0c2018-07-31 22:07:47110
Mitsuru Oshima60172c22019-11-13 22:56:27111 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 Keshavfd6fd0c2018-07-31 22:07:47115
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 Oshima60172c22019-11-13 22:56:27119 if (scaled_size_in_pixel.width() < display_size_in_pixel.width() &&
120 display.bounds().right() == bounds.right()) {
Malay Keshavfd6fd0c2018-07-31 22:07:47121 snapped_bounds.Inset(0, 0, -1, 0);
122 DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).right(),
123 gfx::ScaleToEnclosingRect(bounds, dsf).right());
124 }
Mitsuru Oshima60172c22019-11-13 22:56:27125 if (scaled_size_in_pixel.height() < display_size_in_pixel.height() &&
126 display.bounds().bottom() == bounds.bottom()) {
Malay Keshavfd6fd0c2018-07-31 22:07:47127 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 Xu07d7c9e32018-01-18 20:25:44135} // namespace screen_util
136
[email protected]55ad8c12014-01-17 18:24:33137} // namespace ash