1 // Copyright (c) 2012 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_ash.h"
7 #include "ash/display/multi_display_manager.h"
9 #include "ash/wm/coordinate_conversion.h"
10 #include "ash/wm/shelf_layout_manager.h"
11 #include "base/logging.h"
12 #include "ui/aura/client/screen_position_client.h"
13 #include "ui/aura/env.h"
14 #include "ui/aura/display_manager.h"
15 #include "ui/aura/root_window.h"
16 #include "ui/gfx/display.h"
17 #include "ui/gfx/screen.h"
22 internal::MultiDisplayManager
* GetDisplayManager() {
23 return static_cast<internal::MultiDisplayManager
*>(
24 aura::Env::GetInstance()->display_manager());
28 ScreenAsh::ScreenAsh() {
31 ScreenAsh::~ScreenAsh() {
35 gfx::Display
ScreenAsh::FindDisplayContainingPoint(const gfx::Point
& point
) {
36 return GetDisplayManager()->FindDisplayContainingPoint(point
);
40 gfx::Rect
ScreenAsh::GetMaximizedWindowBoundsInParent(aura::Window
* window
) {
41 if (window
->GetRootWindow() == Shell::GetPrimaryRootWindow())
42 return Shell::GetInstance()->shelf()->GetMaximizedWindowBounds(window
);
44 return GetDisplayBoundsInParent(window
);
48 gfx::Rect
ScreenAsh::GetUnmaximizedWorkAreaBoundsInParent(
49 aura::Window
* window
) {
50 if (window
->GetRootWindow() == Shell::GetPrimaryRootWindow())
51 return Shell::GetInstance()->shelf()->GetUnmaximizedWorkAreaBounds(window
);
53 return GetDisplayWorkAreaBoundsInParent(window
);
57 gfx::Rect
ScreenAsh::GetDisplayBoundsInParent(aura::Window
* window
) {
58 return ConvertRectFromScreen(
60 gfx::Screen::GetDisplayNearestWindow(window
).bounds());
64 gfx::Rect
ScreenAsh::GetDisplayWorkAreaBoundsInParent(aura::Window
* window
) {
65 return ConvertRectFromScreen(
67 gfx::Screen::GetDisplayNearestWindow(window
).work_area());
71 gfx::Rect
ScreenAsh::ConvertRectToScreen(aura::Window
* window
,
72 const gfx::Rect
& rect
) {
73 gfx::Point point
= rect
.origin();
74 aura::client::GetScreenPositionClient(window
->GetRootWindow())->
75 ConvertPointToScreen(window
, &point
);
76 return gfx::Rect(point
, rect
.size());
80 gfx::Rect
ScreenAsh::ConvertRectFromScreen(aura::Window
* window
,
81 const gfx::Rect
& rect
) {
82 gfx::Point point
= rect
.origin();
83 aura::client::GetScreenPositionClient(window
->GetRootWindow())->
84 ConvertPointFromScreen(window
, &point
);
85 return gfx::Rect(point
, rect
.size());
88 gfx::Point
ScreenAsh::GetCursorScreenPoint() {
89 return aura::Env::GetInstance()->last_mouse_location();
92 gfx::NativeWindow
ScreenAsh::GetWindowAtCursorScreenPoint() {
93 const gfx::Point point
= gfx::Screen::GetCursorScreenPoint();
94 return wm::GetRootWindowAt(point
)->GetTopWindowContainingPoint(point
);
97 int ScreenAsh::GetNumDisplays() {
98 return GetDisplayManager()->GetNumDisplays();
101 gfx::Display
ScreenAsh::GetDisplayNearestWindow(gfx::NativeView window
) const {
102 return GetDisplayManager()->GetDisplayNearestWindow(window
);
105 gfx::Display
ScreenAsh::GetDisplayNearestPoint(const gfx::Point
& point
) const {
106 return GetDisplayManager()->GetDisplayNearestPoint(point
);
109 gfx::Display
ScreenAsh::GetDisplayMatching(const gfx::Rect
& match_rect
) const {
110 return GetDisplayManager()->GetDisplayMatching(match_rect
);
113 gfx::Display
ScreenAsh::GetPrimaryDisplay() const {
114 return *GetDisplayManager()->GetDisplayAt(0);