Switch all windows bots to use Aura.
[chromium-blink-merge.git] / ash / screen_ash.cc
blob6155d54b97716d768c493f3807a35d47cd4bde2d
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/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/property_util.h"
14 #include "ash/wm/coordinate_conversion.h"
15 #include "base/logging.h"
16 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h"
19 #include "ui/gfx/display.h"
20 #include "ui/gfx/screen.h"
22 namespace ash {
24 namespace {
25 internal::DisplayManager* GetDisplayManager() {
26 return Shell::GetInstance()->display_manager();
28 } // namespace
30 ScreenAsh::ScreenAsh() {
33 ScreenAsh::~ScreenAsh() {
36 // static
37 gfx::Display ScreenAsh::FindDisplayContainingPoint(const gfx::Point& point) {
38 return GetDisplayManager()->FindDisplayContainingPoint(point);
41 // static
42 gfx::Rect ScreenAsh::GetMaximizedWindowBoundsInParent(aura::Window* window) {
43 if (GetRootWindowController(window->GetRootWindow())->shelf())
44 return GetDisplayWorkAreaBoundsInParent(window);
45 else
46 return GetDisplayBoundsInParent(window);
49 // static
50 gfx::Rect ScreenAsh::GetDisplayBoundsInParent(aura::Window* window) {
51 return ConvertRectFromScreen(
52 window->parent(),
53 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
56 // static
57 gfx::Rect ScreenAsh::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
58 return ConvertRectFromScreen(
59 window->parent(),
60 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area());
63 // static
64 gfx::Rect ScreenAsh::ConvertRectToScreen(aura::Window* window,
65 const gfx::Rect& rect) {
66 gfx::Point point = rect.origin();
67 aura::client::GetScreenPositionClient(window->GetRootWindow())->
68 ConvertPointToScreen(window, &point);
69 return gfx::Rect(point, rect.size());
72 // static
73 gfx::Rect ScreenAsh::ConvertRectFromScreen(aura::Window* window,
74 const gfx::Rect& rect) {
75 gfx::Point point = rect.origin();
76 aura::client::GetScreenPositionClient(window->GetRootWindow())->
77 ConvertPointFromScreen(window, &point);
78 return gfx::Rect(point, rect.size());
81 // static
82 const gfx::Display& ScreenAsh::GetSecondaryDisplay() {
83 return *(Shell::GetInstance()->display_controller()->GetSecondaryDisplay());
86 // static
87 const gfx::Display& ScreenAsh::GetDisplayForId(int64 display_id) {
88 return GetDisplayManager()->GetDisplayForId(display_id);
91 void ScreenAsh::NotifyBoundsChanged(const gfx::Display& display) {
92 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_,
93 OnDisplayBoundsChanged(display));
96 void ScreenAsh::NotifyDisplayAdded(const gfx::Display& display) {
97 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, OnDisplayAdded(display));
100 void ScreenAsh::NotifyDisplayRemoved(const gfx::Display& display) {
101 FOR_EACH_OBSERVER(
102 gfx::DisplayObserver, observers_, OnDisplayRemoved(display));
105 bool ScreenAsh::IsDIPEnabled() {
106 return true;
109 gfx::Point ScreenAsh::GetCursorScreenPoint() {
110 return aura::Env::GetInstance()->last_mouse_location();
113 gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPoint() {
114 const gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
115 return wm::GetRootWindowAt(point)->GetTopWindowContainingPoint(point);
118 int ScreenAsh::GetNumDisplays() {
119 return DisplayController::GetNumDisplays();
122 gfx::Display ScreenAsh::GetDisplayNearestWindow(gfx::NativeView window) const {
123 return GetDisplayManager()->GetDisplayNearestWindow(window);
126 gfx::Display ScreenAsh::GetDisplayNearestPoint(const gfx::Point& point) const {
127 return GetDisplayManager()->GetDisplayNearestPoint(point);
130 gfx::Display ScreenAsh::GetDisplayMatching(const gfx::Rect& match_rect) const {
131 return GetDisplayManager()->GetDisplayMatching(match_rect);
134 gfx::Display ScreenAsh::GetPrimaryDisplay() const {
135 return DisplayController::GetPrimaryDisplay();
138 void ScreenAsh::AddObserver(gfx::DisplayObserver* observer) {
139 observers_.AddObserver(observer);
142 void ScreenAsh::RemoveObserver(gfx::DisplayObserver* observer) {
143 observers_.RemoveObserver(observer);
146 } // namespace ash