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/gfx/gfx_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
54 #endif // defined(USE_AURA)
57 #include <windows.h> // NOLINT
58 typedef struct HFONT__
* HFONT
;
77 #elif defined(OS_MACOSX)
96 #elif defined(OS_POSIX)
97 typedef struct _PangoFontDescription PangoFontDescription
;
98 typedef struct _cairo cairo_t
;
101 #if defined(OS_ANDROID)
102 struct ANativeWindow
;
112 #if defined(USE_AURA)
113 typedef ui::Cursor NativeCursor
;
114 typedef aura::Window
* NativeView
;
115 typedef aura::Window
* NativeWindow
;
116 typedef SkRegion
* NativeRegion
;
117 typedef ui::Event
* NativeEvent
;
118 #elif defined(OS_IOS)
119 typedef void* NativeCursor
;
120 typedef UIView
* NativeView
;
121 typedef UIWindow
* NativeWindow
;
122 typedef UIEvent
* NativeEvent
;
123 #elif defined(OS_MACOSX)
124 typedef NSCursor
* NativeCursor
;
125 typedef NSView
* NativeView
;
126 typedef NSWindow
* NativeWindow
;
127 typedef void* NativeRegion
;
128 typedef NSEvent
* NativeEvent
;
129 #elif defined(OS_ANDROID)
130 typedef void* NativeCursor
;
131 typedef ui::ViewAndroid
* NativeView
;
132 typedef ui::WindowAndroid
* NativeWindow
;
133 typedef void* NativeRegion
;
134 typedef jobject NativeEvent
;
138 typedef HFONT NativeFont
;
139 typedef HWND NativeEditView
;
140 typedef HDC NativeDrawingContext
;
141 typedef IAccessible
* NativeViewAccessible
;
142 #elif defined(OS_IOS)
143 typedef UIFont
* NativeFont
;
144 typedef UITextField
* NativeEditView
;
145 typedef CGContext
* NativeDrawingContext
;
147 typedef id NativeViewAccessible
;
149 typedef void* NativeViewAccessible
;
151 #elif defined(OS_MACOSX)
152 typedef NSFont
* NativeFont
;
153 typedef NSTextField
* NativeEditView
;
154 typedef CGContext
* NativeDrawingContext
;
156 typedef id NativeViewAccessible
;
158 typedef void* NativeViewAccessible
;
160 #elif defined(USE_CAIRO)
161 typedef PangoFontDescription
* NativeFont
;
162 typedef void* NativeEditView
;
163 typedef cairo_t
* NativeDrawingContext
;
164 typedef void* NativeViewAccessible
;
166 typedef void* NativeFont
;
167 typedef void* NativeEditView
;
168 typedef void* NativeDrawingContext
;
169 typedef void* NativeViewAccessible
;
172 // A constant value to indicate that gfx::NativeCursor refers to no cursor.
173 #if defined(USE_AURA)
174 const int kNullCursor
= 0;
176 const gfx::NativeCursor kNullCursor
= static_cast<gfx::NativeCursor
>(NULL
);
180 typedef UIImage NativeImageType
;
181 #elif defined(OS_MACOSX)
182 typedef NSImage NativeImageType
;
184 typedef SkBitmap NativeImageType
;
186 typedef NativeImageType
* NativeImage
;
188 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if
189 // you make it a type which is smaller than a pointer, you have to fix
192 // See comment at the top of the file for usage.
193 typedef intptr_t NativeViewId
;
195 // PluginWindowHandle is an abstraction wrapping "the types of windows
196 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X
199 typedef HWND PluginWindowHandle
;
200 const PluginWindowHandle kNullPluginWindow
= NULL
;
201 #elif defined(USE_X11)
202 typedef unsigned long PluginWindowHandle
;
203 const PluginWindowHandle kNullPluginWindow
= 0;
204 #elif defined(OS_ANDROID)
205 typedef uint64 PluginWindowHandle
;
206 const PluginWindowHandle kNullPluginWindow
= 0;
207 #elif defined(USE_OZONE)
208 typedef intptr_t PluginWindowHandle
;
209 const PluginWindowHandle kNullPluginWindow
= 0;
211 // On Mac we don't have windowed plugins. We use a NULL/0 PluginWindowHandle
212 // in shared code to indicate there is no window present.
213 typedef bool PluginWindowHandle
;
214 const PluginWindowHandle kNullPluginWindow
= 0;
222 SURFACE_TYPE_LAST
= TEXTURE_TRANSPORT
225 struct GLSurfaceHandle
{
227 : handle(kNullPluginWindow
),
228 transport_type(EMPTY
),
229 parent_client_id(0) {
231 GLSurfaceHandle(PluginWindowHandle handle_
, SurfaceType transport_
)
233 transport_type(transport_
),
234 parent_client_id(0) {
235 DCHECK(!is_null() || handle
== kNullPluginWindow
);
236 DCHECK(transport_type
!= TEXTURE_TRANSPORT
||
237 handle
== kNullPluginWindow
);
239 bool is_null() const { return transport_type
== EMPTY
; }
240 bool is_transport() const {
241 return transport_type
== NATIVE_TRANSPORT
||
242 transport_type
== TEXTURE_TRANSPORT
;
244 PluginWindowHandle handle
;
245 SurfaceType transport_type
;
246 uint32 parent_client_id
;
249 // AcceleratedWidget provides a surface to compositors to paint pixels.
251 typedef HWND AcceleratedWidget
;
252 const AcceleratedWidget kNullAcceleratedWidget
= NULL
;
253 #elif defined(USE_X11)
254 typedef unsigned long AcceleratedWidget
;
255 const AcceleratedWidget kNullAcceleratedWidget
= 0;
256 #elif defined(OS_IOS)
257 typedef UIView
* AcceleratedWidget
;
258 const AcceleratedWidget kNullAcceleratedWidget
= 0;
259 #elif defined(OS_MACOSX)
260 typedef NSView
* AcceleratedWidget
;
261 const AcceleratedWidget kNullAcceleratedWidget
= 0;
262 #elif defined(OS_ANDROID)
263 typedef ANativeWindow
* AcceleratedWidget
;
264 const AcceleratedWidget kNullAcceleratedWidget
= 0;
265 #elif defined(USE_OZONE)
266 typedef intptr_t AcceleratedWidget
;
267 const AcceleratedWidget kNullAcceleratedWidget
= 0;
269 #error unknown platform
274 #endif // UI_GFX_NATIVE_WIDGET_TYPES_H_