Roll src/third_party/skia 7b05ff1:dab1f60
[chromium-blink-merge.git] / ash / screen_util.cc
blob95b70ca124294a73d698025511a27a16c7f7d225
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/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* root_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 return first.bounds();
62 } else {
63 return gfx::Screen::GetScreenFor(root_window)
64 ->GetDisplayNearestWindow(root_window)
65 .bounds();
69 // static
70 gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
71 const gfx::Rect& rect) {
72 gfx::Point point = rect.origin();
73 aura::client::GetScreenPositionClient(window->GetRootWindow())->
74 ConvertPointToScreen(window, &point);
75 return gfx::Rect(point, rect.size());
78 // static
79 gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
80 const gfx::Rect& rect) {
81 gfx::Point point = rect.origin();
82 aura::client::GetScreenPositionClient(window->GetRootWindow())->
83 ConvertPointFromScreen(window, &point);
84 return gfx::Rect(point, rect.size());
87 // static
88 const gfx::Display& ScreenUtil::GetSecondaryDisplay() {
89 DisplayManager* display_manager = GetDisplayManager();
90 CHECK_LE(2U, display_manager->GetNumDisplays());
91 return display_manager->GetDisplayAt(0).id() ==
92 Shell::GetScreen()->GetPrimaryDisplay().id() ?
93 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
96 } // namespace ash