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.
5 #ifndef UI_GFX_NATIVE_WIDGET_TYPES_H_
6 #define UI_GFX_NATIVE_WIDGET_TYPES_H_
8 #include "build/build_config.h"
10 #if defined(OS_ANDROID)
14 #include "base/basictypes.h"
15 #include "base/logging.h"
16 #include "ui/base/ui_export.h"
18 // This file provides cross platform typedefs for native widget types.
19 // NativeWindow: this is a handle to a native, top-level window
20 // NativeView: this is a handle to a native UI element. It may be the
21 // same type as a NativeWindow on some platforms.
22 // NativeViewId: Often, in our cross process model, we need to pass around a
23 // reference to a "window". This reference will, say, be echoed back from a
24 // renderer to the browser when it wishes to query its size. On Windows we
25 // use an HWND for this.
27 // As a rule of thumb - if you're in the renderer, you should be dealing
28 // with NativeViewIds. This should remind you that you shouldn't be doing
29 // direct operations on platform widgets from the renderer process.
31 // If you're in the browser, you're probably dealing with NativeViews,
32 // unless you're in the IPC layer, which will be translating between
33 // NativeViewIds from the renderer and NativeViews.
35 // NativeEditView: a handle to a native edit-box. The Mac folks wanted this
38 // NativeImage: The platform-specific image type used for drawing UI elements
41 // The name 'View' here meshes with OS X where the UI elements are called
42 // 'views' and with our Chrome UI code where the elements are also called
46 #include "ui/base/cursor/cursor.h"
55 #endif // defined(USE_AURA)
58 #include <windows.h> // NOLINT
59 typedef struct HFONT__
* HFONT
;
78 #elif defined(OS_MACOSX)
97 #elif defined(OS_POSIX)
98 typedef struct _PangoFontDescription PangoFontDescription
;
99 typedef struct _cairo cairo_t
;
102 #if defined(TOOLKIT_GTK)
103 typedef struct _GdkCursor GdkCursor
;
104 typedef union _GdkEvent GdkEvent
;
105 typedef struct _GdkPixbuf GdkPixbuf
;
106 typedef struct _GdkRegion GdkRegion
;
107 typedef struct _GtkWidget GtkWidget
;
108 typedef struct _GtkWindow GtkWindow
;
109 #elif defined(OS_ANDROID)
110 struct ANativeWindow
;
120 #if defined(USE_AURA)
121 typedef ui::Cursor NativeCursor
;
122 typedef aura::Window
* NativeView
;
123 typedef aura::Window
* NativeWindow
;
124 typedef SkRegion
* NativeRegion
;
125 typedef ui::Event
* NativeEvent
;
126 #elif defined(OS_WIN)
127 typedef HCURSOR NativeCursor
;
128 typedef HWND NativeView
;
129 typedef HWND NativeWindow
;
130 typedef HRGN NativeRegion
;
131 typedef MSG NativeEvent
;
132 #elif defined(OS_IOS)
133 typedef void* NativeCursor
;
134 typedef UIView
* NativeView
;
135 typedef UIWindow
* NativeWindow
;
136 typedef UIEvent
* NativeEvent
;
137 #elif defined(OS_MACOSX)
138 typedef NSCursor
* NativeCursor
;
139 typedef NSView
* NativeView
;
140 typedef NSWindow
* NativeWindow
;
141 typedef NSEvent
* NativeEvent
;
142 #elif defined(TOOLKIT_GTK)
143 typedef GdkCursor
* NativeCursor
;
144 typedef GtkWidget
* NativeView
;
145 typedef GtkWindow
* NativeWindow
;
146 typedef GdkRegion
* NativeRegion
;
147 typedef GdkEvent
* NativeEvent
;
148 #elif defined(OS_ANDROID)
149 typedef void* NativeCursor
;
150 typedef ui::ViewAndroid
* NativeView
;
151 typedef ui::WindowAndroid
* NativeWindow
;
152 typedef void* NativeRegion
;
153 typedef jobject NativeEvent
;
157 typedef HFONT NativeFont
;
158 typedef HWND NativeEditView
;
159 typedef HDC NativeDrawingContext
;
160 typedef IAccessible
* NativeViewAccessible
;
161 #elif defined(OS_IOS)
162 typedef UIFont
* NativeFont
;
163 typedef UITextField
* NativeEditView
;
164 typedef CGContext
* NativeDrawingContext
;
165 #elif defined(OS_MACOSX)
166 typedef NSFont
* NativeFont
;
167 typedef NSTextField
* NativeEditView
;
168 typedef CGContext
* NativeDrawingContext
;
169 typedef void* NativeViewAccessible
;
170 #elif defined(TOOLKIT_GTK)
171 typedef PangoFontDescription
* NativeFont
;
172 typedef GtkWidget
* NativeEditView
;
173 typedef cairo_t
* NativeDrawingContext
;
174 typedef void* NativeViewAccessible
;
175 #elif defined(USE_AURA)
176 typedef PangoFontDescription
* NativeFont
;
177 typedef void* NativeEditView
;
178 typedef cairo_t
* NativeDrawingContext
;
179 typedef void* NativeViewAccessible
;
180 #elif defined(OS_ANDROID)
181 typedef void* NativeFont
;
182 typedef void* NativeEditView
;
183 typedef void* NativeDrawingContext
;
184 typedef void* NativeViewAccessible
;
187 // A constant value to indicate that gfx::NativeCursor refers to no cursor.
188 #if defined(USE_AURA)
189 const int kNullCursor
= 0;
191 const gfx::NativeCursor kNullCursor
= static_cast<gfx::NativeCursor
>(NULL
);
195 typedef UIImage NativeImageType
;
196 #elif defined(OS_MACOSX)
197 typedef NSImage NativeImageType
;
198 #elif defined(TOOLKIT_GTK)
199 typedef GdkPixbuf NativeImageType
;
201 typedef SkBitmap NativeImageType
;
203 typedef NativeImageType
* NativeImage
;
205 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if
206 // you make it a type which is smaller than a pointer, you have to fix
209 // See comment at the top of the file for usage.
210 typedef intptr_t NativeViewId
;
212 #if defined(OS_WIN) && !defined(USE_AURA)
213 // Convert a NativeViewId to a NativeView.
215 // On Windows, we pass an HWND into the renderer. As stated above, the renderer
216 // should not be performing operations on the view.
217 static inline NativeView
NativeViewFromId(NativeViewId id
) {
218 return reinterpret_cast<NativeView
>(id
);
220 #define NativeViewFromIdInBrowser(x) NativeViewFromId(x)
221 #elif defined(OS_POSIX) || defined(USE_AURA)
222 // On Mac, Linux and USE_AURA, a NativeView is a pointer to an object, and is
223 // useless outside the process in which it was created. NativeViewFromId should
224 // only be used inside the appropriate platform ifdef outside of the browser.
225 // (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your
226 // cross-platform design involves a call to NativeViewFromId from outside the
227 // browser it will never work on Mac or Linux and is fundamentally broken.
229 // Please do not call this from outside the browser. It won't work; the name
230 // should give you a subtle hint.
231 static inline NativeView
NativeViewFromIdInBrowser(NativeViewId id
) {
232 return reinterpret_cast<NativeView
>(id
);
234 #endif // defined(OS_POSIX)
236 // PluginWindowHandle is an abstraction wrapping "the types of windows
237 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X
240 typedef HWND PluginWindowHandle
;
241 const PluginWindowHandle kNullPluginWindow
= NULL
;
242 #elif defined(USE_X11)
243 typedef unsigned long PluginWindowHandle
;
244 const PluginWindowHandle kNullPluginWindow
= 0;
245 #elif defined(USE_AURA) && defined(OS_MACOSX)
246 // Mac-Aura uses NSView-backed GLSurface. Regular Mac does not.
247 // TODO(dhollowa): Rationalize these two definitions. http://crbug.com/104551.
248 typedef NSView
* PluginWindowHandle
;
249 const PluginWindowHandle kNullPluginWindow
= 0;
250 #elif defined(OS_ANDROID)
251 typedef uint64 PluginWindowHandle
;
252 const PluginWindowHandle kNullPluginWindow
= 0;
253 #elif defined(USE_OZONE)
254 typedef intptr_t PluginWindowHandle
;
255 const PluginWindowHandle kNullPluginWindow
= 0;
257 // On OS X we don't have windowed plugins.
258 // We use a NULL/0 PluginWindowHandle in shared code to indicate there
259 // is no window present, so mirror that behavior here.
261 // The GPU plugin is currently an exception to this rule. As of this
262 // writing it uses some NPAPI infrastructure, and minimally we need
263 // to identify the plugin instance via this window handle. When the
264 // GPU plugin becomes a full-on GPU process, this typedef can be
265 // returned to a bool. For now we use a type large enough to hold a
266 // pointer on 64-bit architectures in case we need this capability.
267 typedef uint64 PluginWindowHandle
;
268 const PluginWindowHandle kNullPluginWindow
= 0;
278 struct GLSurfaceHandle
{
280 : handle(kNullPluginWindow
),
281 transport_type(EMPTY
),
282 parent_gpu_process_id(0),
283 parent_client_id(0) {
285 GLSurfaceHandle(PluginWindowHandle handle_
, SurfaceType transport_
)
287 transport_type(transport_
),
288 parent_gpu_process_id(0),
289 parent_client_id(0) {
290 DCHECK(!is_null() || handle
== kNullPluginWindow
);
291 DCHECK(transport_type
!= TEXTURE_TRANSPORT
||
292 handle
== kNullPluginWindow
);
294 bool is_null() const { return transport_type
== EMPTY
; }
295 bool is_transport() const {
296 return transport_type
== NATIVE_TRANSPORT
||
297 transport_type
== TEXTURE_TRANSPORT
;
299 PluginWindowHandle handle
;
300 SurfaceType transport_type
;
301 int parent_gpu_process_id
;
302 uint32 parent_client_id
;
305 // AcceleratedWidget provides a surface to compositors to paint pixels.
307 typedef HWND AcceleratedWidget
;
308 const AcceleratedWidget kNullAcceleratedWidget
= NULL
;
309 #elif defined(USE_X11)
310 typedef unsigned long AcceleratedWidget
;
311 const AcceleratedWidget kNullAcceleratedWidget
= 0;
312 #elif defined(OS_IOS)
313 typedef UIView
* AcceleratedWidget
;
314 const AcceleratedWidget kNullAcceleratedWidget
= 0;
315 #elif defined(OS_MACOSX)
316 typedef NSView
* AcceleratedWidget
;
317 const AcceleratedWidget kNullAcceleratedWidget
= 0;
318 #elif defined(OS_ANDROID)
319 typedef ANativeWindow
* AcceleratedWidget
;
320 const AcceleratedWidget kNullAcceleratedWidget
= 0;
321 #elif defined(USE_OZONE)
322 typedef intptr_t AcceleratedWidget
;
323 const AcceleratedWidget kNullAcceleratedWidget
= 0;
325 #error unknown platform
330 #endif // UI_GFX_NATIVE_WIDGET_TYPES_H_