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