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 _cairo cairo_t
;
100 #if defined(OS_ANDROID)
101 struct ANativeWindow
;
111 #if defined(USE_AURA)
112 typedef ui::Cursor NativeCursor
;
113 typedef aura::Window
* NativeView
;
114 typedef aura::Window
* NativeWindow
;
115 typedef SkRegion
* NativeRegion
;
116 typedef ui::Event
* NativeEvent
;
117 #elif defined(OS_IOS)
118 typedef void* NativeCursor
;
119 typedef UIView
* NativeView
;
120 typedef UIWindow
* NativeWindow
;
121 typedef UIEvent
* NativeEvent
;
122 #elif defined(OS_MACOSX)
123 typedef NSCursor
* NativeCursor
;
124 typedef NSView
* NativeView
;
125 typedef NSWindow
* NativeWindow
;
126 typedef void* NativeRegion
;
127 typedef NSEvent
* NativeEvent
;
128 #elif defined(OS_ANDROID)
129 typedef void* NativeCursor
;
130 typedef ui::ViewAndroid
* NativeView
;
131 typedef ui::WindowAndroid
* NativeWindow
;
132 typedef void* NativeRegion
;
133 typedef jobject NativeEvent
;
137 typedef HFONT NativeFont
;
138 typedef HWND NativeEditView
;
139 typedef HDC NativeDrawingContext
;
140 typedef IAccessible
* NativeViewAccessible
;
141 #elif defined(OS_IOS)
142 typedef UIFont
* NativeFont
;
143 typedef UITextField
* NativeEditView
;
144 typedef CGContext
* NativeDrawingContext
;
146 typedef id NativeViewAccessible
;
148 typedef void* NativeViewAccessible
;
150 #elif defined(OS_MACOSX)
151 typedef NSFont
* NativeFont
;
152 typedef NSTextField
* NativeEditView
;
153 typedef CGContext
* NativeDrawingContext
;
155 typedef id NativeViewAccessible
;
157 typedef void* NativeViewAccessible
;
159 #else // Android, Linux, Chrome OS, etc.
160 // Linux doesn't have a native font type.
161 typedef void* NativeEditView
;
162 #if defined(USE_CAIRO)
163 typedef cairo_t
* NativeDrawingContext
;
165 typedef void* NativeDrawingContext
;
166 #endif // defined(USE_CAIRO)
167 typedef void* NativeViewAccessible
;
170 // A constant value to indicate that gfx::NativeCursor refers to no cursor.
171 #if defined(USE_AURA)
172 const int kNullCursor
= 0;
174 const gfx::NativeCursor kNullCursor
= static_cast<gfx::NativeCursor
>(NULL
);
178 typedef UIImage NativeImageType
;
179 #elif defined(OS_MACOSX)
180 typedef NSImage NativeImageType
;
182 typedef SkBitmap NativeImageType
;
184 typedef NativeImageType
* NativeImage
;
186 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if
187 // you make it a type which is smaller than a pointer, you have to fix
190 // See comment at the top of the file for usage.
191 typedef intptr_t NativeViewId
;
193 // PluginWindowHandle is an abstraction wrapping "the types of windows
194 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X
197 typedef HWND PluginWindowHandle
;
198 const PluginWindowHandle kNullPluginWindow
= NULL
;
199 #elif defined(USE_X11)
200 typedef unsigned long PluginWindowHandle
;
201 const PluginWindowHandle kNullPluginWindow
= 0;
202 #elif defined(OS_ANDROID)
203 typedef uint64 PluginWindowHandle
;
204 const PluginWindowHandle kNullPluginWindow
= 0;
205 #elif defined(USE_OZONE)
206 typedef intptr_t PluginWindowHandle
;
207 const PluginWindowHandle kNullPluginWindow
= 0;
209 // On Mac we don't have windowed plugins. We use a NULL/0 PluginWindowHandle
210 // in shared code to indicate there is no window present.
211 typedef bool PluginWindowHandle
;
212 const PluginWindowHandle kNullPluginWindow
= 0;
219 SURFACE_TYPE_LAST
= NULL_TRANSPORT
222 struct GLSurfaceHandle
{
224 : handle(kNullPluginWindow
),
225 transport_type(EMPTY
),
226 parent_client_id(0) {
228 GLSurfaceHandle(PluginWindowHandle handle_
, SurfaceType transport_
)
230 transport_type(transport_
),
231 parent_client_id(0) {
232 DCHECK(!is_null() || handle
== kNullPluginWindow
);
233 DCHECK(transport_type
!= NULL_TRANSPORT
||
234 handle
== kNullPluginWindow
);
236 bool is_null() const { return transport_type
== EMPTY
; }
237 bool is_transport() const {
238 return transport_type
== NULL_TRANSPORT
;
240 PluginWindowHandle handle
;
241 SurfaceType transport_type
;
242 uint32 parent_client_id
;
245 // AcceleratedWidget provides a surface to compositors to paint pixels.
247 typedef HWND AcceleratedWidget
;
248 const AcceleratedWidget kNullAcceleratedWidget
= NULL
;
249 #elif defined(USE_X11)
250 typedef unsigned long AcceleratedWidget
;
251 const AcceleratedWidget kNullAcceleratedWidget
= 0;
252 #elif defined(OS_IOS)
253 typedef UIView
* AcceleratedWidget
;
254 const AcceleratedWidget kNullAcceleratedWidget
= 0;
255 #elif defined(OS_MACOSX)
256 typedef NSView
* AcceleratedWidget
;
257 const AcceleratedWidget kNullAcceleratedWidget
= 0;
258 #elif defined(OS_ANDROID)
259 typedef ANativeWindow
* AcceleratedWidget
;
260 const AcceleratedWidget kNullAcceleratedWidget
= 0;
261 #elif defined(USE_OZONE)
262 typedef intptr_t AcceleratedWidget
;
263 const AcceleratedWidget kNullAcceleratedWidget
= 0;
265 #error unknown platform
270 #endif // UI_GFX_NATIVE_WIDGET_TYPES_H_