OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef GFX_NATIVE_WIDGET_TYPES_H_ | 5 #ifndef GFX_NATIVE_WIDGET_TYPES_H_ |
6 #define GFX_NATIVE_WIDGET_TYPES_H_ | 6 #define GFX_NATIVE_WIDGET_TYPES_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "ui/gfx/native_widget_types.h" |
10 #include "build/build_config.h" | 10 // TODO(sail): remove this file once all includes have been updated. |
11 | |
12 // This file provides cross platform typedefs for native widget types. | |
13 // NativeWindow: this is a handle to a native, top-level window | |
14 // NativeView: this is a handle to a native UI element. It may be the | |
15 // same type as a NativeWindow on some platforms. | |
16 // NativeViewId: Often, in our cross process model, we need to pass around a | |
17 // reference to a "window". This reference will, say, be echoed back from a | |
18 // renderer to the browser when it wishes to query its size. On Windows we | |
19 // use an HWND for this. | |
20 // | |
21 // As a rule of thumb - if you're in the renderer, you should be dealing | |
22 // with NativeViewIds. This should remind you that you shouldn't be doing | |
23 // direct operations on platform widgets from the renderer process. | |
24 // | |
25 // If you're in the browser, you're probably dealing with NativeViews, | |
26 // unless you're in the IPC layer, which will be translating between | |
27 // NativeViewIds from the renderer and NativeViews. | |
28 // | |
29 // NativeEditView: a handle to a native edit-box. The Mac folks wanted this | |
30 // specific typedef. | |
31 // | |
32 // NativeImage: The platform-specific image type used for drawing UI elements | |
33 // in the browser. | |
34 // | |
35 // The name 'View' here meshes with OS X where the UI elements are called | |
36 // 'views' and with our Chrome UI code where the elements are also called | |
37 // 'views'. | |
38 | |
39 #if defined(OS_WIN) | |
40 #include <windows.h> // NOLINT | |
41 typedef struct HFONT__* HFONT; | |
42 #elif defined(OS_MACOSX) | |
43 struct CGContext; | |
44 #ifdef __OBJC__ | |
45 @class NSFont; | |
46 @class NSImage; | |
47 @class NSView; | |
48 @class NSWindow; | |
49 @class NSTextField; | |
50 #else | |
51 class NSFont; | |
52 class NSImage; | |
53 class NSView; | |
54 class NSWindow; | |
55 class NSTextField; | |
56 #endif // __OBJC__ | |
57 #elif defined(TOOLKIT_USES_GTK) | |
58 typedef struct _PangoFontDescription PangoFontDescription; | |
59 typedef struct _GdkCursor GdkCursor; | |
60 typedef struct _GdkPixbuf GdkPixbuf; | |
61 typedef struct _GdkRegion GdkRegion; | |
62 typedef struct _GtkWidget GtkWidget; | |
63 typedef struct _GtkWindow GtkWindow; | |
64 typedef struct _cairo cairo_t; | |
65 #endif | |
66 class SkBitmap; | |
67 | |
68 namespace gfx { | |
69 | |
70 #if defined(OS_WIN) | |
71 typedef HFONT NativeFont; | |
72 typedef HWND NativeView; | |
73 typedef HWND NativeWindow; | |
74 typedef HWND NativeEditView; | |
75 typedef HDC NativeDrawingContext; | |
76 typedef HCURSOR NativeCursor; | |
77 typedef HMENU NativeMenu; | |
78 typedef HRGN NativeRegion; | |
79 #elif defined(OS_MACOSX) | |
80 typedef NSFont* NativeFont; | |
81 typedef NSView* NativeView; | |
82 typedef NSWindow* NativeWindow; | |
83 typedef NSTextField* NativeEditView; | |
84 typedef CGContext* NativeDrawingContext; | |
85 typedef void* NativeCursor; | |
86 typedef void* NativeMenu; | |
87 #elif defined(USE_X11) | |
88 typedef PangoFontDescription* NativeFont; | |
89 typedef GtkWidget* NativeView; | |
90 typedef GtkWindow* NativeWindow; | |
91 typedef GtkWidget* NativeEditView; | |
92 typedef cairo_t* NativeDrawingContext; | |
93 typedef GdkCursor* NativeCursor; | |
94 typedef GtkWidget* NativeMenu; | |
95 typedef GdkRegion* NativeRegion; | |
96 #endif | |
97 | |
98 #if defined(OS_MACOSX) | |
99 typedef NSImage NativeImageType; | |
100 #elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | |
101 typedef GdkPixbuf NativeImageType; | |
102 #else | |
103 typedef SkBitmap NativeImageType; | |
104 #endif | |
105 typedef NativeImageType* NativeImage; | |
106 | |
107 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if | |
108 // you make it a type which is smaller than a pointer, you have to fix | |
109 // test_shell. | |
110 // | |
111 // See comment at the top of the file for usage. | |
112 typedef intptr_t NativeViewId; | |
113 | |
114 #if defined(OS_WIN) | |
115 // Convert a NativeViewId to a NativeView. | |
116 // | |
117 // On Windows, we pass an HWND into the renderer. As stated above, the renderer | |
118 // should not be performing operations on the view. | |
119 static inline NativeView NativeViewFromId(NativeViewId id) { | |
120 return reinterpret_cast<NativeView>(id); | |
121 } | |
122 #define NativeViewFromIdInBrowser(x) NativeViewFromId(x) | |
123 #elif defined(OS_POSIX) | |
124 // On Mac and Linux, a NativeView is a pointer to an object, and is useless | |
125 // outside the process in which it was created. NativeViewFromId should only be | |
126 // used inside the appropriate platform ifdef outside of the browser. | |
127 // (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your | |
128 // cross-platform design involves a call to NativeViewFromId from outside the | |
129 // browser it will never work on Mac or Linux and is fundamentally broken. | |
130 | |
131 // Please do not call this from outside the browser. It won't work; the name | |
132 // should give you a subtle hint. | |
133 static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) { | |
134 return reinterpret_cast<NativeView>(id); | |
135 } | |
136 #endif // defined(OS_POSIX) | |
137 | |
138 // Convert a NativeView to a NativeViewId. See the comments at the top of | |
139 // this file. | |
140 #if defined(OS_WIN) || defined(OS_MACOSX) | |
141 static inline NativeViewId IdFromNativeView(NativeView view) { | |
142 return reinterpret_cast<NativeViewId>(view); | |
143 } | |
144 #elif defined(USE_X11) | |
145 // Not inlined because it involves pulling too many headers. | |
146 NativeViewId IdFromNativeView(NativeView view); | |
147 #endif // defined(USE_X11) | |
148 | |
149 | |
150 // PluginWindowHandle is an abstraction wrapping "the types of windows | |
151 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X | |
152 // window id. | |
153 #if defined(OS_WIN) | |
154 typedef HWND PluginWindowHandle; | |
155 const PluginWindowHandle kNullPluginWindow = NULL; | |
156 #elif defined(USE_X11) | |
157 typedef unsigned long PluginWindowHandle; | |
158 const PluginWindowHandle kNullPluginWindow = 0; | |
159 #else | |
160 // On OS X we don't have windowed plugins. | |
161 // We use a NULL/0 PluginWindowHandle in shared code to indicate there | |
162 // is no window present, so mirror that behavior here. | |
163 // | |
164 // The GPU plugin is currently an exception to this rule. As of this | |
165 // writing it uses some NPAPI infrastructure, and minimally we need | |
166 // to identify the plugin instance via this window handle. When the | |
167 // GPU plugin becomes a full-on GPU process, this typedef can be | |
168 // returned to a bool. For now we use a type large enough to hold a | |
169 // pointer on 64-bit architectures in case we need this capability. | |
170 typedef uint64 PluginWindowHandle; | |
171 const PluginWindowHandle kNullPluginWindow = 0; | |
172 #endif | |
173 | |
174 } // namespace gfx | |
175 | 11 |
176 #endif // GFX_NATIVE_WIDGET_TYPES_H_ | 12 #endif // GFX_NATIVE_WIDGET_TYPES_H_ |
OLD | NEW |