blob: 7e4017e13010b38991bf301f2b8da0749f9d6199 [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
[email protected]55ad8c12014-01-17 18:24:337#include "ash/display/display_manager.h"
8#include "ash/root_window_controller.h"
9#include "ash/shelf/shelf_layout_manager.h"
10#include "ash/shelf/shelf_widget.h"
11#include "ash/shell.h"
12#include "ash/wm/coordinate_conversion.h"
13#include "base/logging.h"
14#include "ui/aura/client/screen_position_client.h"
[email protected]fcc51c952014-02-21 21:31:2615#include "ui/aura/window_event_dispatcher.h"
[email protected]55ad8c12014-01-17 18:24:3316#include "ui/gfx/display.h"
oshima5337ca92015-07-18 02:23:5717#include "ui/gfx/geometry/size_conversions.h"
[email protected]55ad8c12014-01-17 18:24:3318#include "ui/gfx/screen.h"
19
20namespace ash {
21
22namespace {
[email protected]093b8d642014-04-03 20:59:2823DisplayManager* GetDisplayManager() {
[email protected]55ad8c12014-01-17 18:24:3324 return Shell::GetInstance()->display_manager();
25}
26}
27
28// static
29gfx::Display ScreenUtil::FindDisplayContainingPoint(const gfx::Point& point) {
30 return GetDisplayManager()->FindDisplayContainingPoint(point);
31}
32
33// static
34gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) {
[email protected]093b8d642014-04-03 20:59:2835 if (GetRootWindowController(window->GetRootWindow())->shelf())
[email protected]55ad8c12014-01-17 18:24:3336 return GetDisplayWorkAreaBoundsInParent(window);
37 else
38 return GetDisplayBoundsInParent(window);
39}
40
41// static
42gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) {
43 return ConvertRectFromScreen(
44 window->parent(),
scottmge8b042972016-01-27 05:07:3545 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds());
[email protected]55ad8c12014-01-17 18:24:3346}
47
48// static
49gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
50 return ConvertRectFromScreen(
51 window->parent(),
scottmge8b042972016-01-27 05:07:3552 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area());
[email protected]55ad8c12014-01-17 18:24:3353}
54
oshimac0c9eb72015-11-04 02:16:3655gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) {
oshima96f6a502015-05-02 08:43:3256 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
57 if (display_manager->IsInUnifiedMode()) {
58 // In unified desktop mode, there is only one shelf in the 1st display.
59 const gfx::Display& first =
60 display_manager->software_mirroring_display_list()[0];
oshima5337ca92015-07-18 02:23:5761 float scale =
62 static_cast<float>(window->GetRootWindow()->bounds().height()) /
63 first.size().height();
64 gfx::SizeF size(first.size());
65 size.Scale(scale, scale);
66 return gfx::Rect(gfx::ToCeiledSize(size));
oshima96f6a502015-05-02 08:43:3267 } else {
sadrul618dd9e2016-02-10 19:38:1368 if (window->GetRootWindow()->bounds().IsEmpty()) {
69 // TODO(sad): This only happens when running with mustash, since the
70 // root-window here refers to the shelf Widget, which has not been
71 // sized/positioned yet. Use the bounds of the display in this case.
72 // Ideally, we would not run this code at all for mustash.
73 NOTIMPLEMENTED();
74 gfx::Display display =
75 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window);
76 return gfx::Rect(display.size());
77 }
oshimac0c9eb72015-11-04 02:16:3678 return window->GetRootWindow()->bounds();
oshima96f6a502015-05-02 08:43:3279 }
80}
81
[email protected]55ad8c12014-01-17 18:24:3382// static
83gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
84 const gfx::Rect& rect) {
85 gfx::Point point = rect.origin();
86 aura::client::GetScreenPositionClient(window->GetRootWindow())->
87 ConvertPointToScreen(window, &point);
88 return gfx::Rect(point, rect.size());
89}
90
91// static
92gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
93 const gfx::Rect& rect) {
94 gfx::Point point = rect.origin();
95 aura::client::GetScreenPositionClient(window->GetRootWindow())->
96 ConvertPointFromScreen(window, &point);
97 return gfx::Rect(point, rect.size());
98}
99
100// static
101const gfx::Display& ScreenUtil::GetSecondaryDisplay() {
[email protected]093b8d642014-04-03 20:59:28102 DisplayManager* display_manager = GetDisplayManager();
mukai9afa39c2014-10-14 21:28:25103 CHECK_LE(2U, display_manager->GetNumDisplays());
[email protected]55ad8c12014-01-17 18:24:33104 return display_manager->GetDisplayAt(0).id() ==
scottmge8b042972016-01-27 05:07:35105 gfx::Screen::GetScreen()->GetPrimaryDisplay().id()
106 ? display_manager->GetDisplayAt(1)
107 : display_manager->GetDisplayAt(0);
[email protected]55ad8c12014-01-17 18:24:33108}
109
[email protected]55ad8c12014-01-17 18:24:33110} // namespace ash