blob: 02d90e23b881f37ab47c3a5d383cfef68c0ac6be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/screen_util.h"
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/wm/coordinate_conversion.h"
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/gfx/display.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/screen.h"
namespace ash {
namespace {
DisplayManager* GetDisplayManager() {
return Shell::GetInstance()->display_manager();
}
}
// static
gfx::Display ScreenUtil::FindDisplayContainingPoint(const gfx::Point& point) {
return GetDisplayManager()->FindDisplayContainingPoint(point);
}
// static
gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) {
if (GetRootWindowController(window->GetRootWindow())->shelf())
return GetDisplayWorkAreaBoundsInParent(window);
else
return GetDisplayBoundsInParent(window);
}
// static
gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) {
return ConvertRectFromScreen(
window->parent(),
Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
}
// static
gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
return ConvertRectFromScreen(
window->parent(),
Shell::GetScreen()->GetDisplayNearestWindow(window).work_area());
}
gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) {
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
if (display_manager->IsInUnifiedMode()) {
// In unified desktop mode, there is only one shelf in the 1st display.
const gfx::Display& first =
display_manager->software_mirroring_display_list()[0];
float scale =
static_cast<float>(window->GetRootWindow()->bounds().height()) /
first.size().height();
gfx::SizeF size(first.size());
size.Scale(scale, scale);
return gfx::Rect(gfx::ToCeiledSize(size));
} else {
return window->GetRootWindow()->bounds();
}
}
// static
gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
const gfx::Rect& rect) {
gfx::Point point = rect.origin();
aura::client::GetScreenPositionClient(window->GetRootWindow())->
ConvertPointToScreen(window, &point);
return gfx::Rect(point, rect.size());
}
// static
gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
const gfx::Rect& rect) {
gfx::Point point = rect.origin();
aura::client::GetScreenPositionClient(window->GetRootWindow())->
ConvertPointFromScreen(window, &point);
return gfx::Rect(point, rect.size());
}
// static
const gfx::Display& ScreenUtil::GetSecondaryDisplay() {
DisplayManager* display_manager = GetDisplayManager();
CHECK_LE(2U, display_manager->GetNumDisplays());
return display_manager->GetDisplayAt(0).id() ==
Shell::GetScreen()->GetPrimaryDisplay().id() ?
display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
}
} // namespace ash
|