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.
5 #include "ash/screen_util.h"
7 #include "ash/display/display_controller.h"
8 #include "ash/display/display_manager.h"
9 #include "ash/root_window_controller.h"
10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "ash/wm/coordinate_conversion.h"
14 #include "base/logging.h"
15 #include "ui/aura/client/screen_position_client.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/gfx/display.h"
18 #include "ui/gfx/geometry/size_conversions.h"
19 #include "ui/gfx/screen.h"
24 DisplayManager
* GetDisplayManager() {
25 return Shell::GetInstance()->display_manager();
30 gfx::Display
ScreenUtil::FindDisplayContainingPoint(const gfx::Point
& point
) {
31 return GetDisplayManager()->FindDisplayContainingPoint(point
);
35 gfx::Rect
ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window
* window
) {
36 if (GetRootWindowController(window
->GetRootWindow())->shelf())
37 return GetDisplayWorkAreaBoundsInParent(window
);
39 return GetDisplayBoundsInParent(window
);
43 gfx::Rect
ScreenUtil::GetDisplayBoundsInParent(aura::Window
* window
) {
44 return ConvertRectFromScreen(
46 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
50 gfx::Rect
ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window
* window
) {
51 return ConvertRectFromScreen(
53 Shell::GetScreen()->GetDisplayNearestWindow(window
).work_area());
56 gfx::Rect
ScreenUtil::GetShelfDisplayBoundsInScreen(aura::Window
* window
) {
57 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.
60 const gfx::Display
& first
=
61 display_manager
->software_mirroring_display_list()[0];
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
));
69 return gfx::Screen::GetScreenFor(window
)
70 ->GetDisplayNearestWindow(window
)
76 gfx::Rect
ScreenUtil::ConvertRectToScreen(aura::Window
* window
,
77 const gfx::Rect
& rect
) {
78 gfx::Point point
= rect
.origin();
79 aura::client::GetScreenPositionClient(window
->GetRootWindow())->
80 ConvertPointToScreen(window
, &point
);
81 return gfx::Rect(point
, rect
.size());
85 gfx::Rect
ScreenUtil::ConvertRectFromScreen(aura::Window
* window
,
86 const gfx::Rect
& rect
) {
87 gfx::Point point
= rect
.origin();
88 aura::client::GetScreenPositionClient(window
->GetRootWindow())->
89 ConvertPointFromScreen(window
, &point
);
90 return gfx::Rect(point
, rect
.size());
94 const gfx::Display
& ScreenUtil::GetSecondaryDisplay() {
95 DisplayManager
* display_manager
= GetDisplayManager();
96 CHECK_LE(2U, display_manager
->GetNumDisplays());
97 return display_manager
->GetDisplayAt(0).id() ==
98 Shell::GetScreen()->GetPrimaryDisplay().id() ?
99 display_manager
->GetDisplayAt(1) : display_manager
->GetDisplayAt(0);