| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/screen.h" | 5 #include "ui/gfx/screen.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "ui/aura/desktop.h" | |
| 13 #include "ui/aura/window.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
| 15 | 13 |
| 16 namespace { | |
| 17 | |
| 18 gfx::Rect GetMonitorAreaOrWorkAreaNearestPoint(const gfx::Point& point, | |
| 19 bool work_area) { | |
| 20 // TODO(oshima): Take point/work_area into account. Support multiple monitors. | |
| 21 return gfx::Rect(aura::Desktop::GetInstance()->GetSize()); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace gfx { | 14 namespace gfx { |
| 27 | 15 |
| 16 // gfx can't depend upon aura, otherwise we have circular dependencies. So, |
| 17 // gfx::Screen is pluggable for aura and Desktop plugs in the real |
| 18 // implementation. |
| 19 |
| 20 // static |
| 21 Screen* Screen::instance_ = NULL; |
| 22 |
| 23 // static |
| 24 void Screen::SetInstance(Screen* screen) { |
| 25 delete instance_; |
| 26 instance_ = screen; |
| 27 } |
| 28 |
| 28 // static | 29 // static |
| 29 gfx::Point Screen::GetCursorScreenPoint() { | 30 gfx::Point Screen::GetCursorScreenPoint() { |
| 30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 31 POINT pt; | 32 POINT pt; |
| 32 GetCursorPos(&pt); | 33 GetCursorPos(&pt); |
| 33 return gfx::Point(pt); | 34 return gfx::Point(pt); |
| 34 #endif | 35 #endif |
| 35 NOTIMPLEMENTED(); | 36 NOTIMPLEMENTED(); |
| 36 return gfx::Point(); | 37 return gfx::Point(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 // static | 40 // static |
| 40 gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { | 41 gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { |
| 41 gfx::Rect bounds = GetMonitorAreaNearestWindow(window); | 42 DCHECK(instance_); |
| 42 // Emulate that a work area can be smaller than its monitor. | 43 return instance_->GetMonitorWorkAreaNearestWindowImpl(window); |
| 43 bounds.Inset(10, 10, 10, 10); | |
| 44 return bounds; | |
| 45 } | 44 } |
| 46 | 45 |
| 47 // static | 46 // static |
| 48 gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) { | 47 gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) { |
| 49 // TODO(oshima): Take point/work_area into account. Support multiple monitors. | 48 DCHECK(instance_); |
| 50 return gfx::Rect(aura::Desktop::GetInstance()->GetSize()); | 49 return instance_->GetMonitorAreaNearestWindowImpl(window); |
| 51 } | 50 } |
| 52 | 51 |
| 53 // static | 52 // static |
| 54 gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { | 53 gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { |
| 55 return GetMonitorAreaOrWorkAreaNearestPoint(point, true); | 54 DCHECK(instance_); |
| 55 return instance_->GetMonitorWorkAreaNearestPointImpl(point); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { | 59 gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { |
| 60 return GetMonitorAreaOrWorkAreaNearestPoint(point, false); | 60 DCHECK(instance_); |
| 61 return instance_->GetMonitorAreaNearestPointImpl(point); |
| 61 } | 62 } |
| 62 | 63 |
| 63 gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { | 64 gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { |
| 64 NOTIMPLEMENTED(); | 65 DCHECK(instance_); |
| 65 return NULL; | 66 return instance_->GetWindowAtCursorScreenPointImpl(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace gfx | 69 } // namespace gfx |
| OLD | NEW |