Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "ui/gfx/screen.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/gfx/native_widget_types.h" | |
| 9 #include "ui/gfx/monitor.h" | |
| 10 | |
| 11 namespace gfx { | |
| 12 | |
| 13 // gfx can't depend upon aura, otherwise we have circular dependencies. So, | |
| 14 // gfx::Screen is pluggable and Desktop plugs in the real implementation. | |
| 15 namespace { | |
| 16 ScreenImpl* instance_ = NULL; | |
|
Ben Goodger (Google)
2012/04/10 16:37:20
g_instance
oshima
2012/04/10 21:31:46
Done.
| |
| 17 | |
| 18 // TODO(erg): Figure out what to do about the Screen class. For now, I've | |
| 19 // added default values for when a Screen instance class isn't passed in, but | |
| 20 // this is the wrong thing. | |
| 21 const Monitor* GetDefaultMonitor() { | |
| 22 static SimpleMonitor* default_monitor = | |
| 23 new SimpleMonitor(gfx::Rect(0, 0, 800, 800)); | |
| 24 return default_monitor; | |
| 25 }; | |
| 26 | |
| 27 } | |
| 28 | |
| 29 // static | |
| 30 void Screen::SetInstance(ScreenImpl* screen) { | |
| 31 delete instance_; | |
| 32 instance_ = screen; | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 gfx::Point Screen::GetCursorScreenPoint() { | |
| 37 if (!instance_) | |
| 38 return gfx::Point(); | |
| 39 return instance_->GetCursorScreenPoint(); | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { | |
| 44 if (!instance_) | |
| 45 return NULL; | |
| 46 return instance_->GetWindowAtCursorScreenPoint(); | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 int Screen::GetNumMonitors() { | |
| 51 if (!instance_) | |
| 52 return 1; | |
| 53 return instance_->GetNumMonitors(); | |
| 54 } | |
| 55 | |
| 56 // static | |
| 57 const gfx::Monitor* Screen::GetMonitorNearestWindow(gfx::NativeWindow window) { | |
| 58 if (!instance_) | |
| 59 return GetDefaultMonitor(); | |
| 60 return instance_->GetMonitorNearestWindow(window); | |
| 61 } | |
| 62 | |
| 63 // static | |
| 64 const gfx::Monitor* Screen::GetMonitorNearestPoint(const gfx::Point& point) { | |
| 65 if (!instance_) | |
| 66 return GetDefaultMonitor(); | |
| 67 return instance_->GetMonitorNearestPoint(point); | |
| 68 } | |
| 69 | |
| 70 // static | |
| 71 const gfx::Monitor* Screen::GetPrimaryMonitor() { | |
| 72 if (!instance_) | |
| 73 return GetDefaultMonitor(); | |
| 74 return instance_->GetPrimaryMonitor(); | |
| 75 } | |
| 76 | |
| 77 // static | |
| 78 const gfx::Monitor* Screen::GetMonitorMatching(const gfx::Rect& match_rect) { | |
| 79 if (!instance_) | |
| 80 return GetDefaultMonitor(); | |
| 81 return instance_->GetMonitorNearestPoint(match_rect.CenterPoint()); | |
| 82 } | |
| 83 | |
| 84 } // namespace gfx | |
| OLD | NEW |