[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / ash / screen_ash.cc
blob4635ed67dfd0b00e809c1bb562e26ff4350b7d3d
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/shell.h"
11 #include "ash/wm/property_util.h"
12 #include "ash/wm/coordinate_conversion.h"
13 #include "ash/wm/shelf_layout_manager.h"
14 #include "base/logging.h"
15 #include "ui/aura/client/screen_position_client.h"
16 #include "ui/aura/env.h"
17 #include "ui/aura/root_window.h"
18 #include "ui/gfx/display.h"
19 #include "ui/gfx/screen.h"
21 namespace ash {
23 namespace {
24 internal::DisplayManager* GetDisplayManager() {
25 return Shell::GetInstance()->display_manager();
27 } // namespace
29 ScreenAsh::ScreenAsh() {
32 ScreenAsh::~ScreenAsh() {
35 // static
36 gfx::Display ScreenAsh::FindDisplayContainingPoint(const gfx::Point& point) {
37 return GetDisplayManager()->FindDisplayContainingPoint(point);
40 // static
41 gfx::Rect ScreenAsh::GetMaximizedWindowBoundsInParent(aura::Window* window) {
42 if (GetRootWindowController(window->GetRootWindow())->launcher())
43 return GetDisplayWorkAreaBoundsInParent(window);
44 else
45 return GetDisplayBoundsInParent(window);
48 // static
49 gfx::Rect ScreenAsh::GetDisplayBoundsInParent(aura::Window* window) {
50 return ConvertRectFromScreen(
51 window->parent(),
52 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
55 // static
56 gfx::Rect ScreenAsh::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
57 return ConvertRectFromScreen(
58 window->parent(),
59 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area());
62 // static
63 gfx::Rect ScreenAsh::ConvertRectToScreen(aura::Window* window,
64 const gfx::Rect& rect) {
65 gfx::Point point = rect.origin();
66 aura::client::GetScreenPositionClient(window->GetRootWindow())->
67 ConvertPointToScreen(window, &point);
68 return gfx::Rect(point, rect.size());
71 // static
72 gfx::Rect ScreenAsh::ConvertRectFromScreen(aura::Window* window,
73 const gfx::Rect& rect) {
74 gfx::Point point = rect.origin();
75 aura::client::GetScreenPositionClient(window->GetRootWindow())->
76 ConvertPointFromScreen(window, &point);
77 return gfx::Rect(point, rect.size());
80 // static
81 const gfx::Display& ScreenAsh::GetSecondaryDisplay() {
82 return *(Shell::GetInstance()->display_controller()->GetSecondaryDisplay());
85 // static
86 const gfx::Display& ScreenAsh::GetDisplayForId(int64 display_id) {
87 return GetDisplayManager()->GetDisplayForId(display_id);
90 void ScreenAsh::NotifyBoundsChanged(const gfx::Display& display) {
91 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_,
92 OnDisplayBoundsChanged(display));
95 void ScreenAsh::NotifyDisplayAdded(const gfx::Display& display) {
96 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, OnDisplayAdded(display));
99 void ScreenAsh::NotifyDisplayRemoved(const gfx::Display& display) {
100 FOR_EACH_OBSERVER(
101 gfx::DisplayObserver, observers_, OnDisplayRemoved(display));
104 bool ScreenAsh::IsDIPEnabled() {
105 return true;
108 gfx::Point ScreenAsh::GetCursorScreenPoint() {
109 return aura::Env::GetInstance()->last_mouse_location();
112 gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPoint() {
113 const gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
114 return wm::GetRootWindowAt(point)->GetTopWindowContainingPoint(point);
117 int ScreenAsh::GetNumDisplays() {
118 return DisplayController::GetNumDisplays();
121 gfx::Display ScreenAsh::GetDisplayNearestWindow(gfx::NativeView window) const {
122 return GetDisplayManager()->GetDisplayNearestWindow(window);
125 gfx::Display ScreenAsh::GetDisplayNearestPoint(const gfx::Point& point) const {
126 return GetDisplayManager()->GetDisplayNearestPoint(point);
129 gfx::Display ScreenAsh::GetDisplayMatching(const gfx::Rect& match_rect) const {
130 return GetDisplayManager()->GetDisplayMatching(match_rect);
133 gfx::Display ScreenAsh::GetPrimaryDisplay() const {
134 return DisplayController::GetPrimaryDisplay();
137 void ScreenAsh::AddObserver(gfx::DisplayObserver* observer) {
138 observers_.AddObserver(observer);
141 void ScreenAsh::RemoveObserver(gfx::DisplayObserver* observer) {
142 observers_.RemoveObserver(observer);
145 } // namespace ash