Fix UserSessionManager::Shutdown ordering.
[chromium-blink-merge.git] / ash / screen_util.cc
blobd0e41212dca4b688c89bd0f5b7305c8180a898cd
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_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"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/gfx/display.h"
17 #include "ui/gfx/geometry/size_conversions.h"
18 #include "ui/gfx/screen.h"
20 namespace ash {
22 namespace {
23 DisplayManager* GetDisplayManager() {
24 return Shell::GetInstance()->display_manager();
28 // static
29 gfx::Display ScreenUtil::FindDisplayContainingPoint(const gfx::Point& point) {
30 return GetDisplayManager()->FindDisplayContainingPoint(point);
33 // static
34 gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) {
35 if (GetRootWindowController(window->GetRootWindow())->shelf())
36 return GetDisplayWorkAreaBoundsInParent(window);
37 else
38 return GetDisplayBoundsInParent(window);
41 // static
42 gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) {
43 return ConvertRectFromScreen(
44 window->parent(),
45 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
48 // static
49 gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
50 return ConvertRectFromScreen(
51 window->parent(),
52 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area());
55 gfx::Rect ScreenUtil::GetShelfDisplayBoundsInScreen(aura::Window* window) {
56 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];
61 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));
67 } else {
68 return gfx::Screen::GetScreenFor(window)
69 ->GetDisplayNearestWindow(window)
70 .bounds();
74 // static
75 gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
76 const gfx::Rect& rect) {
77 gfx::Point point = rect.origin();
78 aura::client::GetScreenPositionClient(window->GetRootWindow())->
79 ConvertPointToScreen(window, &point);
80 return gfx::Rect(point, rect.size());
83 // static
84 gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
85 const gfx::Rect& rect) {
86 gfx::Point point = rect.origin();
87 aura::client::GetScreenPositionClient(window->GetRootWindow())->
88 ConvertPointFromScreen(window, &point);
89 return gfx::Rect(point, rect.size());
92 // static
93 const gfx::Display& ScreenUtil::GetSecondaryDisplay() {
94 DisplayManager* display_manager = GetDisplayManager();
95 CHECK_LE(2U, display_manager->GetNumDisplays());
96 return display_manager->GetDisplayAt(0).id() ==
97 Shell::GetScreen()->GetPrimaryDisplay().id() ?
98 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
101 } // namespace ash