blob: d8ad15ce94f7749d1871d20989653fc071c491a3 [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"
[email protected]55ad8c12014-01-17 18:24:3315#include "base/logging.h"
16#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) {
tbarzic98adf002017-05-26 17:28:1761 gfx::Rect bounds = Shelf::ForWindow(window)->GetUserWorkAreaBounds();
62 ::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) {
Ahmed Fakhry4f8e3722017-10-31 21:01:5882 if (!Shell::Get()->display_manager()->IsInUnifiedMode())
83 return window->GetRootWindow()->bounds();
sky00f0b892017-05-05 17:06:2484
Ahmed Fakhry1ac713b2018-11-06 18:57:4685 // In Unified Mode, the display that should contain the shelf depends on the
86 // current shelf alignment.
87 const display::Display shelf_display =
88 Shell::Get()
89 ->display_configuration_controller()
90 ->GetPrimaryMirroringDisplayForUnifiedDesktop();
91 DCHECK_NE(shelf_display.id(), display::kInvalidDisplayId);
92 gfx::RectF shelf_display_screen_bounds(shelf_display.bounds());
Ahmed Fakhry4f8e3722017-10-31 21:01:5893
Ahmed Fakhry1ac713b2018-11-06 18:57:4694 // Transform the bounds back to the unified host's coordinates.
95 auto inverse_unified_transform =
96 window->GetRootWindow()->GetHost()->GetInverseRootTransform();
97 inverse_unified_transform.TransformRect(&shelf_display_screen_bounds);
Ahmed Fakhry4f8e3722017-10-31 21:01:5898
Ahmed Fakhry1ac713b2018-11-06 18:57:4699 return gfx::ToEnclosingRect(shelf_display_screen_bounds);
sky00f0b892017-05-05 17:06:24100}
101
Malay Keshavfd6fd0c2018-07-31 22:07:47102gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds,
103 const aura::Window* window) {
104 const aura::WindowTreeHost* host = window->GetHost();
105 if (!host)
106 return bounds;
107
108 const float dsf = host->device_scale_factor();
109 const gfx::Rect display_bounds_in_pixel = host->GetBoundsInPixels();
110 const gfx::Rect display_bounds_in_dip = window->GetRootWindow()->bounds();
111 const gfx::Rect bounds_in_pixel = gfx::ScaleToEnclosedRect(bounds, dsf);
112
113 // Adjusts |bounds| such that the scaled enclosed bounds are atleast as big as
114 // the scaled enclosing unadjusted bounds.
115 gfx::Rect snapped_bounds = bounds;
116 if ((display_bounds_in_dip.width() == bounds.width() &&
117 bounds_in_pixel.width() != display_bounds_in_pixel.width()) ||
118 (bounds.right() == display_bounds_in_dip.width() &&
119 bounds_in_pixel.right() != display_bounds_in_pixel.width())) {
120 snapped_bounds.Inset(0, 0, -1, 0);
121 DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).right(),
122 gfx::ScaleToEnclosingRect(bounds, dsf).right());
123 }
124 if ((display_bounds_in_dip.height() == bounds.height() &&
125 bounds_in_pixel.height() != display_bounds_in_pixel.height()) ||
126 (bounds.bottom() == display_bounds_in_dip.height() &&
127 bounds_in_pixel.bottom() != display_bounds_in_pixel.height())) {
128 snapped_bounds.Inset(0, 0, 0, -1);
129 DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).bottom(),
130 gfx::ScaleToEnclosingRect(bounds, dsf).bottom());
131 }
132
133 return snapped_bounds;
134}
135
Qiang Xu07d7c9e32018-01-18 20:25:44136} // namespace screen_util
137
[email protected]55ad8c12014-01-17 18:24:33138} // namespace ash