Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: ui/gfx/screen_aura.cc

Issue 11030017: Add context to gfx::Screen calls in support of simultaneous desktop+ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix other os's Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gfx/display.h" 8 #include "ui/gfx/display.h"
9 #include "ui/gfx/native_widget_types.h" 9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/screen_impl.h" 10 #include "ui/gfx/screen_impl.h"
11 #include "ui/gfx/screen_type_delegate.h"
11 12
12 namespace gfx { 13 namespace gfx {
13 14
15 #if defined(USE_AURA)
oshima 2012/10/04 20:18:26 this is aura only file.
16
14 // gfx can't depend upon aura, otherwise we have circular dependencies. So, 17 // gfx can't depend upon aura, otherwise we have circular dependencies. So,
15 // gfx::Screen is pluggable and Desktop plugs in the real implementation. 18 // gfx::Screen is pluggable and Desktop plugs in the real implementation.
16 namespace { 19 ScreenImpl* g_instance_[SCREEN_TYPE_COUNT];
17 ScreenImpl* g_instance_ = NULL; 20 ScreenTypeDelegate* g_type_delegate_;
21 ScreenType g_screen_type_force_ = SCREEN_TYPE_COUNT;
22
23 // TODO(scottmg): This needs to be always given a context object, rather than
24 // using global state. It is currently passed BadTwoWorldsContext() == NULL
25 // in many places. http://crbug.com/133312
26 ScreenImpl* GetImplForContext(NativeView context) {
27 if (!g_type_delegate_)
28 return g_instance_[SCREEN_TYPE_NATIVE];
29 if (g_screen_type_force_ != SCREEN_TYPE_COUNT)
30 return g_instance_[g_screen_type_force_];
31 ScreenType type = g_type_delegate_->GetScreenTypeForNativeView(context);
32 ScreenImpl* screen_impl = g_instance_[type];
33 DCHECK(screen_impl);
34 return screen_impl;
18 } 35 }
19 36
20 // static 37 // static
21 void Screen::SetInstance(ScreenImpl* screen) { 38 void Screen::ForceScreenTypeOverride(ScreenType type) {
22 delete g_instance_; 39 g_screen_type_force_ = type;
23 g_instance_ = screen;
24 } 40 }
25 41
26 // static 42 // static
43 void Screen::SetInstance(ScreenType type, ScreenImpl* screen) {
44 DCHECK(!g_instance_[type]);
45 g_instance_[type] = screen;
46 }
47
48 // static
49 void Screen::SetScreenTypeDelegate(ScreenTypeDelegate* delegate) {
50 DCHECK(!g_type_delegate_);
51 g_type_delegate_ = delegate;
52 }
53
54 #endif
55
56 // static
27 bool Screen::IsDIPEnabled() { 57 bool Screen::IsDIPEnabled() {
28 return true; 58 return true;
29 } 59 }
30 60
31 // static 61 // static
32 Point Screen::GetCursorScreenPoint() { 62 Point Screen::GetCursorScreenPoint(NativeView context) {
33 return g_instance_->GetCursorScreenPoint(); 63 return GetImplForContext(context)->GetCursorScreenPoint();
34 } 64 }
35 65
36 // static 66 // static
37 NativeWindow Screen::GetWindowAtCursorScreenPoint() { 67 NativeWindow Screen::GetWindowAtCursorScreenPoint(NativeView context) {
38 return g_instance_->GetWindowAtCursorScreenPoint(); 68 return GetImplForContext(context)->GetWindowAtCursorScreenPoint();
39 } 69 }
40 70
41 // static 71 // static
42 int Screen::GetNumDisplays() { 72 int Screen::GetNumDisplays(NativeView context) {
43 return g_instance_->GetNumDisplays(); 73 return GetImplForContext(context)->GetNumDisplays();
44 } 74 }
45 75
46 // static 76 // static
47 Display Screen::GetDisplayNearestWindow(NativeView window) { 77 Display Screen::GetDisplayNearestWindow(NativeView view) {
48 return g_instance_->GetDisplayNearestWindow(window); 78 return GetImplForContext(view)->GetDisplayNearestWindow(view);
49 } 79 }
50 80
51 // static 81 // static
52 Display Screen::GetDisplayNearestPoint(const Point& point) { 82 Display Screen::GetDisplayNearestPoint(NativeView context, const Point& point) {
53 return g_instance_->GetDisplayNearestPoint(point); 83 return GetImplForContext(context)->GetDisplayNearestPoint(point);
54 } 84 }
55 85
56 // static 86 // static
57 Display Screen::GetDisplayMatching(const gfx::Rect& match_rect) { 87 Display Screen::GetDisplayMatching(
58 return g_instance_->GetDisplayMatching(match_rect); 88 NativeView context, const gfx::Rect& match_rect) {
89 return GetImplForContext(context)->GetDisplayMatching(match_rect);
59 } 90 }
60 91
61 // static 92 // static
62 Display Screen::GetPrimaryDisplay() { 93 Display Screen::GetPrimaryDisplay(NativeView context) {
63 return g_instance_->GetPrimaryDisplay(); 94 return GetImplForContext(context)->GetPrimaryDisplay();
95 }
96
97 // static
98 gfx::NativeView Screen::BadTwoWorldsContext() {
99 // TODO(scottmg): Any calls to this are a bug. http://crbug.com/133312
100 return NULL;
64 } 101 }
65 102
66 } // namespace gfx 103 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698