Chromium Code Reviews| Index: ui/gfx/screen_aura.cc |
| diff --git a/ui/gfx/screen_aura.cc b/ui/gfx/screen_aura.cc |
| index befdeafa7d001f393ec4ad7c911c3c8542217f7c..22bedaa5397f6f9d00689521f864b769ab6ce64b 100644 |
| --- a/ui/gfx/screen_aura.cc |
| +++ b/ui/gfx/screen_aura.cc |
| @@ -8,59 +8,96 @@ |
| #include "ui/gfx/display.h" |
| #include "ui/gfx/native_widget_types.h" |
| #include "ui/gfx/screen_impl.h" |
| +#include "ui/gfx/screen_type_delegate.h" |
| namespace gfx { |
| +#if defined(USE_AURA) |
|
oshima
2012/10/04 20:18:26
this is aura only file.
|
| + |
| // gfx can't depend upon aura, otherwise we have circular dependencies. So, |
| // gfx::Screen is pluggable and Desktop plugs in the real implementation. |
| -namespace { |
| -ScreenImpl* g_instance_ = NULL; |
| +ScreenImpl* g_instance_[SCREEN_TYPE_COUNT]; |
| +ScreenTypeDelegate* g_type_delegate_; |
| +ScreenType g_screen_type_force_ = SCREEN_TYPE_COUNT; |
| + |
| +// TODO(scottmg): This needs to be always given a context object, rather than |
| +// using global state. It is currently passed BadTwoWorldsContext() == NULL |
| +// in many places. http://crbug.com/133312 |
| +ScreenImpl* GetImplForContext(NativeView context) { |
| + if (!g_type_delegate_) |
| + return g_instance_[SCREEN_TYPE_NATIVE]; |
| + if (g_screen_type_force_ != SCREEN_TYPE_COUNT) |
| + return g_instance_[g_screen_type_force_]; |
| + ScreenType type = g_type_delegate_->GetScreenTypeForNativeView(context); |
| + ScreenImpl* screen_impl = g_instance_[type]; |
| + DCHECK(screen_impl); |
| + return screen_impl; |
| +} |
| + |
| +// static |
| +void Screen::ForceScreenTypeOverride(ScreenType type) { |
| + g_screen_type_force_ = type; |
| +} |
| + |
| +// static |
| +void Screen::SetInstance(ScreenType type, ScreenImpl* screen) { |
| + DCHECK(!g_instance_[type]); |
| + g_instance_[type] = screen; |
| } |
| // static |
| -void Screen::SetInstance(ScreenImpl* screen) { |
| - delete g_instance_; |
| - g_instance_ = screen; |
| +void Screen::SetScreenTypeDelegate(ScreenTypeDelegate* delegate) { |
| + DCHECK(!g_type_delegate_); |
| + g_type_delegate_ = delegate; |
| } |
| +#endif |
| + |
| // static |
| bool Screen::IsDIPEnabled() { |
| return true; |
| } |
| // static |
| -Point Screen::GetCursorScreenPoint() { |
| - return g_instance_->GetCursorScreenPoint(); |
| +Point Screen::GetCursorScreenPoint(NativeView context) { |
| + return GetImplForContext(context)->GetCursorScreenPoint(); |
| +} |
| + |
| +// static |
| +NativeWindow Screen::GetWindowAtCursorScreenPoint(NativeView context) { |
| + return GetImplForContext(context)->GetWindowAtCursorScreenPoint(); |
| } |
| // static |
| -NativeWindow Screen::GetWindowAtCursorScreenPoint() { |
| - return g_instance_->GetWindowAtCursorScreenPoint(); |
| +int Screen::GetNumDisplays(NativeView context) { |
| + return GetImplForContext(context)->GetNumDisplays(); |
| } |
| // static |
| -int Screen::GetNumDisplays() { |
| - return g_instance_->GetNumDisplays(); |
| +Display Screen::GetDisplayNearestWindow(NativeView view) { |
| + return GetImplForContext(view)->GetDisplayNearestWindow(view); |
| } |
| // static |
| -Display Screen::GetDisplayNearestWindow(NativeView window) { |
| - return g_instance_->GetDisplayNearestWindow(window); |
| +Display Screen::GetDisplayNearestPoint(NativeView context, const Point& point) { |
| + return GetImplForContext(context)->GetDisplayNearestPoint(point); |
| } |
| // static |
| -Display Screen::GetDisplayNearestPoint(const Point& point) { |
| - return g_instance_->GetDisplayNearestPoint(point); |
| +Display Screen::GetDisplayMatching( |
| + NativeView context, const gfx::Rect& match_rect) { |
| + return GetImplForContext(context)->GetDisplayMatching(match_rect); |
| } |
| // static |
| -Display Screen::GetDisplayMatching(const gfx::Rect& match_rect) { |
| - return g_instance_->GetDisplayMatching(match_rect); |
| +Display Screen::GetPrimaryDisplay(NativeView context) { |
| + return GetImplForContext(context)->GetPrimaryDisplay(); |
| } |
| // static |
| -Display Screen::GetPrimaryDisplay() { |
| - return g_instance_->GetPrimaryDisplay(); |
| +gfx::NativeView Screen::BadTwoWorldsContext() { |
| + // TODO(scottmg): Any calls to this are a bug. http://crbug.com/133312 |
| + return NULL; |
| } |
| } // namespace gfx |