Prevent extensions from changing the window properties
[chromium-blink-merge.git] / ash / screen_ash.cc
blob74a6f96f59c79639b6a624d395945bc52ca70aba
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/multi_display_manager.h"
8 #include "ash/shell.h"
9 #include "ash/wm/coordinate_conversion.h"
10 #include "ash/wm/shelf_layout_manager.h"
11 #include "base/logging.h"
12 #include "ui/aura/client/screen_position_client.h"
13 #include "ui/aura/env.h"
14 #include "ui/aura/display_manager.h"
15 #include "ui/aura/root_window.h"
16 #include "ui/gfx/display.h"
17 #include "ui/gfx/screen.h"
19 namespace ash {
21 namespace {
22 internal::MultiDisplayManager* GetDisplayManager() {
23 return static_cast<internal::MultiDisplayManager*>(
24 aura::Env::GetInstance()->display_manager());
26 } // namespace
28 ScreenAsh::ScreenAsh() {
31 ScreenAsh::~ScreenAsh() {
34 // static
35 gfx::Display ScreenAsh::FindDisplayContainingPoint(const gfx::Point& point) {
36 return GetDisplayManager()->FindDisplayContainingPoint(point);
39 // static
40 gfx::Rect ScreenAsh::GetMaximizedWindowBoundsInParent(aura::Window* window) {
41 if (window->GetRootWindow() == Shell::GetPrimaryRootWindow())
42 return Shell::GetInstance()->shelf()->GetMaximizedWindowBounds(window);
43 else
44 return GetDisplayBoundsInParent(window);
47 // static
48 gfx::Rect ScreenAsh::GetUnmaximizedWorkAreaBoundsInParent(
49 aura::Window* window) {
50 if (window->GetRootWindow() == Shell::GetPrimaryRootWindow())
51 return Shell::GetInstance()->shelf()->GetUnmaximizedWorkAreaBounds(window);
52 else
53 return GetDisplayWorkAreaBoundsInParent(window);
56 // static
57 gfx::Rect ScreenAsh::GetDisplayBoundsInParent(aura::Window* window) {
58 return ConvertRectFromScreen(
59 window->parent(),
60 gfx::Screen::GetDisplayNearestWindow(window).bounds());
63 // static
64 gfx::Rect ScreenAsh::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
65 return ConvertRectFromScreen(
66 window->parent(),
67 gfx::Screen::GetDisplayNearestWindow(window).work_area());
70 // static
71 gfx::Rect ScreenAsh::ConvertRectToScreen(aura::Window* window,
72 const gfx::Rect& rect) {
73 gfx::Point point = rect.origin();
74 aura::client::GetScreenPositionClient(window->GetRootWindow())->
75 ConvertPointToScreen(window, &point);
76 return gfx::Rect(point, rect.size());
79 // static
80 gfx::Rect ScreenAsh::ConvertRectFromScreen(aura::Window* window,
81 const gfx::Rect& rect) {
82 gfx::Point point = rect.origin();
83 aura::client::GetScreenPositionClient(window->GetRootWindow())->
84 ConvertPointFromScreen(window, &point);
85 return gfx::Rect(point, rect.size());
88 gfx::Point ScreenAsh::GetCursorScreenPoint() {
89 return aura::Env::GetInstance()->last_mouse_location();
92 gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPoint() {
93 const gfx::Point point = gfx::Screen::GetCursorScreenPoint();
94 return wm::GetRootWindowAt(point)->GetTopWindowContainingPoint(point);
97 int ScreenAsh::GetNumDisplays() {
98 return GetDisplayManager()->GetNumDisplays();
101 gfx::Display ScreenAsh::GetDisplayNearestWindow(gfx::NativeView window) const {
102 return GetDisplayManager()->GetDisplayNearestWindow(window);
105 gfx::Display ScreenAsh::GetDisplayNearestPoint(const gfx::Point& point) const {
106 return GetDisplayManager()->GetDisplayNearestPoint(point);
109 gfx::Display ScreenAsh::GetDisplayMatching(const gfx::Rect& match_rect) const {
110 return GetDisplayManager()->GetDisplayMatching(match_rect);
113 gfx::Display ScreenAsh::GetPrimaryDisplay() const {
114 return *GetDisplayManager()->GetDisplayAt(0);
117 } // namespace ash