| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/screen_util.h" | 5 #include "ash/screen_util.h" |
| 6 | 6 |
| 7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "ui/aura/client/screen_position_client.h" | 13 #include "ui/aura/client/screen_position_client.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/gfx/display.h" | 15 #include "ui/display/display.h" |
| 16 #include "ui/display/screen.h" |
| 16 #include "ui/gfx/geometry/size_conversions.h" | 17 #include "ui/gfx/geometry/size_conversions.h" |
| 17 #include "ui/gfx/screen.h" | |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 DisplayManager* GetDisplayManager() { | 22 DisplayManager* GetDisplayManager() { |
| 23 return Shell::GetInstance()->display_manager(); | 23 return Shell::GetInstance()->display_manager(); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 gfx::Display ScreenUtil::FindDisplayContainingPoint(const gfx::Point& point) { | 28 display::Display ScreenUtil::FindDisplayContainingPoint( |
| 29 const gfx::Point& point) { |
| 29 return GetDisplayManager()->FindDisplayContainingPoint(point); | 30 return GetDisplayManager()->FindDisplayContainingPoint(point); |
| 30 } | 31 } |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) { | 34 gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) { |
| 34 if (GetRootWindowController(window->GetRootWindow())->shelf()) | 35 if (GetRootWindowController(window->GetRootWindow())->shelf()) |
| 35 return GetDisplayWorkAreaBoundsInParent(window); | 36 return GetDisplayWorkAreaBoundsInParent(window); |
| 36 else | 37 else |
| 37 return GetDisplayBoundsInParent(window); | 38 return GetDisplayBoundsInParent(window); |
| 38 } | 39 } |
| 39 | 40 |
| 40 // static | 41 // static |
| 41 gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) { | 42 gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) { |
| 42 return ConvertRectFromScreen( | 43 return ConvertRectFromScreen( |
| 43 window->parent(), | 44 window->parent(), |
| 44 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds()); | 45 display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds()); |
| 45 } | 46 } |
| 46 | 47 |
| 47 // static | 48 // static |
| 48 gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) { | 49 gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) { |
| 49 return ConvertRectFromScreen( | 50 return ConvertRectFromScreen(window->parent(), |
| 50 window->parent(), | 51 display::Screen::GetScreen() |
| 51 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area()); | 52 ->GetDisplayNearestWindow(window) |
| 53 .work_area()); |
| 52 } | 54 } |
| 53 | 55 |
| 54 gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) { | 56 gfx::Rect ScreenUtil::GetShelfDisplayBoundsInRoot(aura::Window* window) { |
| 55 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 57 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 56 if (display_manager->IsInUnifiedMode()) { | 58 if (display_manager->IsInUnifiedMode()) { |
| 57 // In unified desktop mode, there is only one shelf in the 1st display. | 59 // In unified desktop mode, there is only one shelf in the 1st display. |
| 58 const gfx::Display& first = | 60 const display::Display& first = |
| 59 display_manager->software_mirroring_display_list()[0]; | 61 display_manager->software_mirroring_display_list()[0]; |
| 60 float scale = | 62 float scale = |
| 61 static_cast<float>(window->GetRootWindow()->bounds().height()) / | 63 static_cast<float>(window->GetRootWindow()->bounds().height()) / |
| 62 first.size().height(); | 64 first.size().height(); |
| 63 gfx::SizeF size(first.size()); | 65 gfx::SizeF size(first.size()); |
| 64 size.Scale(scale, scale); | 66 size.Scale(scale, scale); |
| 65 return gfx::Rect(gfx::ToCeiledSize(size)); | 67 return gfx::Rect(gfx::ToCeiledSize(size)); |
| 66 } else { | 68 } else { |
| 67 if (window->GetRootWindow()->bounds().IsEmpty()) { | 69 if (window->GetRootWindow()->bounds().IsEmpty()) { |
| 68 // TODO(sad): This only happens when running with mustash, since the | 70 // TODO(sad): This only happens when running with mustash, since the |
| 69 // root-window here refers to the shelf Widget, which has not been | 71 // root-window here refers to the shelf Widget, which has not been |
| 70 // sized/positioned yet. Use the bounds of the display in this case. | 72 // sized/positioned yet. Use the bounds of the display in this case. |
| 71 // Ideally, we would not run this code at all for mustash. | 73 // Ideally, we would not run this code at all for mustash. |
| 72 NOTIMPLEMENTED(); | 74 NOTIMPLEMENTED(); |
| 73 gfx::Display display = | 75 display::Display display = |
| 74 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window); | 76 display::Screen::GetScreen()->GetDisplayNearestWindow(window); |
| 75 return gfx::Rect(display.size()); | 77 return gfx::Rect(display.size()); |
| 76 } | 78 } |
| 77 return window->GetRootWindow()->bounds(); | 79 return window->GetRootWindow()->bounds(); |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 | 82 |
| 81 // static | 83 // static |
| 82 gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window, | 84 gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window, |
| 83 const gfx::Rect& rect) { | 85 const gfx::Rect& rect) { |
| 84 gfx::Point point = rect.origin(); | 86 gfx::Point point = rect.origin(); |
| 85 aura::client::GetScreenPositionClient(window->GetRootWindow())-> | 87 aura::client::GetScreenPositionClient(window->GetRootWindow())-> |
| 86 ConvertPointToScreen(window, &point); | 88 ConvertPointToScreen(window, &point); |
| 87 return gfx::Rect(point, rect.size()); | 89 return gfx::Rect(point, rect.size()); |
| 88 } | 90 } |
| 89 | 91 |
| 90 // static | 92 // static |
| 91 gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window, | 93 gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window, |
| 92 const gfx::Rect& rect) { | 94 const gfx::Rect& rect) { |
| 93 gfx::Point point = rect.origin(); | 95 gfx::Point point = rect.origin(); |
| 94 aura::client::GetScreenPositionClient(window->GetRootWindow())-> | 96 aura::client::GetScreenPositionClient(window->GetRootWindow())-> |
| 95 ConvertPointFromScreen(window, &point); | 97 ConvertPointFromScreen(window, &point); |
| 96 return gfx::Rect(point, rect.size()); | 98 return gfx::Rect(point, rect.size()); |
| 97 } | 99 } |
| 98 | 100 |
| 99 // static | 101 // static |
| 100 const gfx::Display& ScreenUtil::GetSecondaryDisplay() { | 102 const display::Display& ScreenUtil::GetSecondaryDisplay() { |
| 101 DisplayManager* display_manager = GetDisplayManager(); | 103 DisplayManager* display_manager = GetDisplayManager(); |
| 102 CHECK_LE(2U, display_manager->GetNumDisplays()); | 104 CHECK_LE(2U, display_manager->GetNumDisplays()); |
| 103 return display_manager->GetDisplayAt(0).id() == | 105 return display_manager->GetDisplayAt(0).id() == |
| 104 gfx::Screen::GetScreen()->GetPrimaryDisplay().id() | 106 display::Screen::GetScreen()->GetPrimaryDisplay().id() |
| 105 ? display_manager->GetDisplayAt(1) | 107 ? display_manager->GetDisplayAt(1) |
| 106 : display_manager->GetDisplayAt(0); | 108 : display_manager->GetDisplayAt(0); |
| 107 } | 109 } |
| 108 | 110 |
| 109 } // namespace ash | 111 } // namespace ash |
| OLD | NEW |