blob: 0e19b9dfc8e3c6790bed997063477d966a8a41e5 [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
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"
[email protected]fcc51c952014-02-21 21:31:2616#include "ui/aura/window_event_dispatcher.h"
[email protected]55ad8c12014-01-17 18:24:3317#include "ui/gfx/display.h"
18#include "ui/gfx/screen.h"
19
20namespace ash {
21
22namespace {
[email protected]093b8d642014-04-03 20:59:2823DisplayManager* GetDisplayManager() {
[email protected]55ad8c12014-01-17 18:24:3324 return Shell::GetInstance()->display_manager();
25}
26}
27
28// static
29gfx::Display ScreenUtil::FindDisplayContainingPoint(const gfx::Point& point) {
30 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(),
45 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
46}
47
48// static
49gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
50 return ConvertRectFromScreen(
51 window->parent(),
52 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area());
53}
54
55// static
56gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
57 const gfx::Rect& rect) {
58 gfx::Point point = rect.origin();
59 aura::client::GetScreenPositionClient(window->GetRootWindow())->
60 ConvertPointToScreen(window, &point);
61 return gfx::Rect(point, rect.size());
62}
63
64// static
65gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
66 const gfx::Rect& rect) {
67 gfx::Point point = rect.origin();
68 aura::client::GetScreenPositionClient(window->GetRootWindow())->
69 ConvertPointFromScreen(window, &point);
70 return gfx::Rect(point, rect.size());
71}
72
73// static
74const gfx::Display& ScreenUtil::GetSecondaryDisplay() {
[email protected]093b8d642014-04-03 20:59:2875 DisplayManager* display_manager = GetDisplayManager();
mukai9afa39c2014-10-14 21:28:2576 CHECK_LE(2U, display_manager->GetNumDisplays());
[email protected]55ad8c12014-01-17 18:24:3377 return display_manager->GetDisplayAt(0).id() ==
78 Shell::GetScreen()->GetPrimaryDisplay().id() ?
79 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
80}
81
82// static
83const gfx::Display& ScreenUtil::GetDisplayForId(int64 display_id) {
84 return GetDisplayManager()->GetDisplayForId(display_id);
85}
86
87} // namespace ash