[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "ash/screen_util.h" |
| 6 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 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" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 15 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 16 | #include "ui/gfx/display.h" |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 17 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 18 | #include "ui/gfx/screen.h" |
| 19 | |
| 20 | namespace ash { |
| 21 | |
| 22 | namespace { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 23 | DisplayManager* GetDisplayManager() { |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 24 | return Shell::GetInstance()->display_manager(); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // static |
| 29 | gfx::Display ScreenUtil::FindDisplayContainingPoint(const gfx::Point& point) { |
| 30 | return GetDisplayManager()->FindDisplayContainingPoint(point); |
| 31 | } |
| 32 | |
| 33 | // static |
| 34 | gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 35 | if (GetRootWindowController(window->GetRootWindow())->shelf()) |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 36 | return GetDisplayWorkAreaBoundsInParent(window); |
| 37 | else |
| 38 | return GetDisplayBoundsInParent(window); |
| 39 | } |
| 40 | |
| 41 | // static |
| 42 | gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) { |
| 43 | return ConvertRectFromScreen( |
| 44 | window->parent(), |
scottmg | e8b04297 | 2016-01-27 05:07:35 | [diff] [blame] | 45 | gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds()); |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | // static |
| 49 | gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) { |
| 50 | return ConvertRectFromScreen( |
| 51 | window->parent(), |
scottmg | e8b04297 | 2016-01-27 05:07:35 | [diff] [blame] | 52 | gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area()); |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 53 | } |
| 54 | |
oshima | c0c9eb7 | 2015-11-04 02:16:36 | [diff] [blame] | 55 | gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) { |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 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]; |
oshima | 5337ca9 | 2015-07-18 02:23:57 | [diff] [blame] | 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)); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 67 | } else { |
sadrul | 618dd9e | 2016-02-10 19:38:13 | [diff] [blame^] | 68 | if (window->GetRootWindow()->bounds().IsEmpty()) { |
| 69 | // TODO(sad): This only happens when running with mustash, since the |
| 70 | // root-window here refers to the shelf Widget, which has not been |
| 71 | // sized/positioned yet. Use the bounds of the display in this case. |
| 72 | // Ideally, we would not run this code at all for mustash. |
| 73 | NOTIMPLEMENTED(); |
| 74 | gfx::Display display = |
| 75 | gfx::Screen::GetScreen()->GetDisplayNearestWindow(window); |
| 76 | return gfx::Rect(display.size()); |
| 77 | } |
oshima | c0c9eb7 | 2015-11-04 02:16:36 | [diff] [blame] | 78 | return window->GetRootWindow()->bounds(); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 82 | // static |
| 83 | gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window, |
| 84 | const gfx::Rect& rect) { |
| 85 | gfx::Point point = rect.origin(); |
| 86 | aura::client::GetScreenPositionClient(window->GetRootWindow())-> |
| 87 | ConvertPointToScreen(window, &point); |
| 88 | return gfx::Rect(point, rect.size()); |
| 89 | } |
| 90 | |
| 91 | // static |
| 92 | gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window, |
| 93 | const gfx::Rect& rect) { |
| 94 | gfx::Point point = rect.origin(); |
| 95 | aura::client::GetScreenPositionClient(window->GetRootWindow())-> |
| 96 | ConvertPointFromScreen(window, &point); |
| 97 | return gfx::Rect(point, rect.size()); |
| 98 | } |
| 99 | |
| 100 | // static |
| 101 | const gfx::Display& ScreenUtil::GetSecondaryDisplay() { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 102 | DisplayManager* display_manager = GetDisplayManager(); |
mukai | 9afa39c | 2014-10-14 21:28:25 | [diff] [blame] | 103 | CHECK_LE(2U, display_manager->GetNumDisplays()); |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 104 | return display_manager->GetDisplayAt(0).id() == |
scottmg | e8b04297 | 2016-01-27 05:07:35 | [diff] [blame] | 105 | gfx::Screen::GetScreen()->GetPrimaryDisplay().id() |
| 106 | ? display_manager->GetDisplayAt(1) |
| 107 | : display_manager->GetDisplayAt(0); |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 110 | } // namespace ash |