blob: 9bbd52bb01f1c57ae52b916810097eee0fa2a51d [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"
[email protected]55ad8c12014-01-17 18:24:3312#include "base/logging.h"
13#include "ui/aura/client/screen_position_client.h"
[email protected]fcc51c952014-02-21 21:31:2614#include "ui/aura/window_event_dispatcher.h"
oshimaf84b0da722016-04-27 19:47:1915#include "ui/display/display.h"
16#include "ui/display/screen.h"
oshima5337ca92015-07-18 02:23:5717#include "ui/gfx/geometry/size_conversions.h"
[email protected]55ad8c12014-01-17 18:24:3318
19namespace ash {
20
21namespace {
[email protected]093b8d642014-04-03 20:59:2822DisplayManager* GetDisplayManager() {
[email protected]55ad8c12014-01-17 18:24:3323 return Shell::GetInstance()->display_manager();
24}
25}
26
27// static
oshimaf84b0da722016-04-27 19:47:1928display::Display ScreenUtil::FindDisplayContainingPoint(
29 const gfx::Point& point) {
[email protected]55ad8c12014-01-17 18:24:3330 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(),
oshimaf84b0da722016-04-27 19:47:1945 display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds());
[email protected]55ad8c12014-01-17 18:24:3346}
47
48// static
49gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
oshimaf84b0da722016-04-27 19:47:1950 return ConvertRectFromScreen(window->parent(),
51 display::Screen::GetScreen()
52 ->GetDisplayNearestWindow(window)
53 .work_area());
[email protected]55ad8c12014-01-17 18:24:3354}
55
oshimac0c9eb72015-11-04 02:16:3656gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) {
oshima96f6a502015-05-02 08:43:3257 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
58 if (display_manager->IsInUnifiedMode()) {
59 // In unified desktop mode, there is only one shelf in the 1st display.
oshimaf84b0da722016-04-27 19:47:1960 const display::Display& first =
oshima96f6a502015-05-02 08:43:3261 display_manager->software_mirroring_display_list()[0];
oshima5337ca92015-07-18 02:23:5762 float scale =
63 static_cast<float>(window->GetRootWindow()->bounds().height()) /
64 first.size().height();
65 gfx::SizeF size(first.size());
66 size.Scale(scale, scale);
67 return gfx::Rect(gfx::ToCeiledSize(size));
oshima96f6a502015-05-02 08:43:3268 } else {
sadrul618dd9e2016-02-10 19:38:1369 if (window->GetRootWindow()->bounds().IsEmpty()) {
70 // TODO(sad): This only happens when running with mustash, since the
71 // root-window here refers to the shelf Widget, which has not been
72 // sized/positioned yet. Use the bounds of the display in this case.
73 // Ideally, we would not run this code at all for mustash.
74 NOTIMPLEMENTED();
oshimaf84b0da722016-04-27 19:47:1975 display::Display display =
76 display::Screen::GetScreen()->GetDisplayNearestWindow(window);
sadrul618dd9e2016-02-10 19:38:1377 return gfx::Rect(display.size());
78 }
oshimac0c9eb72015-11-04 02:16:3679 return window->GetRootWindow()->bounds();
oshima96f6a502015-05-02 08:43:3280 }
81}
82
[email protected]55ad8c12014-01-17 18:24:3383// static
84gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
85 const gfx::Rect& rect) {
86 gfx::Point point = rect.origin();
87 aura::client::GetScreenPositionClient(window->GetRootWindow())->
88 ConvertPointToScreen(window, &point);
89 return gfx::Rect(point, rect.size());
90}
91
92// static
93gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
94 const gfx::Rect& rect) {
95 gfx::Point point = rect.origin();
96 aura::client::GetScreenPositionClient(window->GetRootWindow())->
97 ConvertPointFromScreen(window, &point);
98 return gfx::Rect(point, rect.size());
99}
100
101// static
oshimaf84b0da722016-04-27 19:47:19102const display::Display& ScreenUtil::GetSecondaryDisplay() {
[email protected]093b8d642014-04-03 20:59:28103 DisplayManager* display_manager = GetDisplayManager();
mukai9afa39c2014-10-14 21:28:25104 CHECK_LE(2U, display_manager->GetNumDisplays());
[email protected]55ad8c12014-01-17 18:24:33105 return display_manager->GetDisplayAt(0).id() ==
oshimaf84b0da722016-04-27 19:47:19106 display::Screen::GetScreen()->GetPrimaryDisplay().id()
scottmge8b042972016-01-27 05:07:35107 ? display_manager->GetDisplayAt(1)
108 : display_manager->GetDisplayAt(0);
[email protected]55ad8c12014-01-17 18:24:33109}
110
[email protected]55ad8c12014-01-17 18:24:33111} // namespace ash