Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / ash / screen_ash.cc
blobf2217d7b0fb7633f7a820911c6ebd3d46d8bf38a
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();
29 DisplayController* GetDisplayController() {
30 return Shell::GetInstance()->display_controller();
32 } // namespace
34 ScreenAsh::ScreenAsh() {
37 ScreenAsh::~ScreenAsh() {
40 // static
41 gfx::Display ScreenAsh::FindDisplayContainingPoint(const gfx::Point& point) {
42 return GetDisplayManager()->FindDisplayContainingPoint(point);
45 // static
46 gfx::Rect ScreenAsh::GetMaximizedWindowBoundsInParent(aura::Window* window) {
47 if (GetRootWindowController(window->GetRootWindow())->shelf())
48 return GetDisplayWorkAreaBoundsInParent(window);
49 else
50 return GetDisplayBoundsInParent(window);
53 // static
54 gfx::Rect ScreenAsh::GetDisplayBoundsInParent(aura::Window* window) {
55 return ConvertRectFromScreen(
56 window->parent(),
57 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
60 // static
61 gfx::Rect ScreenAsh::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
62 return ConvertRectFromScreen(
63 window->parent(),
64 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area());
67 // static
68 gfx::Rect ScreenAsh::ConvertRectToScreen(aura::Window* window,
69 const gfx::Rect& rect) {
70 gfx::Point point = rect.origin();
71 aura::client::GetScreenPositionClient(window->GetRootWindow())->
72 ConvertPointToScreen(window, &point);
73 return gfx::Rect(point, rect.size());
76 // static
77 gfx::Rect ScreenAsh::ConvertRectFromScreen(aura::Window* window,
78 const gfx::Rect& rect) {
79 gfx::Point point = rect.origin();
80 aura::client::GetScreenPositionClient(window->GetRootWindow())->
81 ConvertPointFromScreen(window, &point);
82 return gfx::Rect(point, rect.size());
85 // static
86 const gfx::Display& ScreenAsh::GetSecondaryDisplay() {
87 internal::DisplayManager* display_manager = GetDisplayManager();
88 CHECK_EQ(2U, display_manager->GetNumDisplays());
89 return display_manager->GetDisplayAt(0).id() ==
90 DisplayController::GetPrimaryDisplay().id() ?
91 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
94 // static
95 const gfx::Display& ScreenAsh::GetDisplayForId(int64 display_id) {
96 return GetDisplayManager()->GetDisplayForId(display_id);
99 void ScreenAsh::NotifyBoundsChanged(const gfx::Display& display) {
100 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_,
101 OnDisplayBoundsChanged(display));
104 void ScreenAsh::NotifyDisplayAdded(const gfx::Display& display) {
105 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, OnDisplayAdded(display));
108 void ScreenAsh::NotifyDisplayRemoved(const gfx::Display& display) {
109 FOR_EACH_OBSERVER(
110 gfx::DisplayObserver, observers_, OnDisplayRemoved(display));
113 bool ScreenAsh::IsDIPEnabled() {
114 return true;
117 gfx::Point ScreenAsh::GetCursorScreenPoint() {
118 return aura::Env::GetInstance()->last_mouse_location();
121 gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPoint() {
122 const gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
123 return wm::GetRootWindowAt(point)->GetTopWindowContainingPoint(point);
126 int ScreenAsh::GetNumDisplays() {
127 return DisplayController::GetNumDisplays();
130 gfx::Display ScreenAsh::GetDisplayNearestWindow(gfx::NativeView window) const {
131 return GetDisplayController()->GetDisplayNearestWindow(window);
134 gfx::Display ScreenAsh::GetDisplayNearestPoint(const gfx::Point& point) const {
135 return GetDisplayController()->GetDisplayNearestPoint(point);
138 gfx::Display ScreenAsh::GetDisplayMatching(const gfx::Rect& match_rect) const {
139 return GetDisplayController()->GetDisplayMatching(match_rect);
142 gfx::Display ScreenAsh::GetPrimaryDisplay() const {
143 return DisplayController::GetPrimaryDisplay();
146 void ScreenAsh::AddObserver(gfx::DisplayObserver* observer) {
147 observers_.AddObserver(observer);
150 void ScreenAsh::RemoveObserver(gfx::DisplayObserver* observer) {
151 observers_.RemoveObserver(observer);
154 } // namespace ash