Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / gfx / native_widget_types.h
blob1a8256bdf1a64ce3315f46daa82ff5f4271eb67c
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)
11 #include <jni.h>
12 #endif
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
36 // specific typedef.
38 // NativeImage: The platform-specific image type used for drawing UI elements
39 // in the browser.
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
43 // 'views'.
45 #if defined(USE_AURA)
46 class SkRegion;
47 namespace aura {
48 class Window;
50 namespace ui {
51 class Cursor;
52 class Event;
54 #endif // defined(USE_AURA)
56 #if defined(OS_WIN)
57 #include <windows.h> // NOLINT
58 typedef struct HFONT__* HFONT;
59 struct IAccessible;
60 #elif defined(OS_IOS)
61 struct CGContext;
62 #ifdef __OBJC__
63 @class UIEvent;
64 @class UIFont;
65 @class UIImage;
66 @class UIView;
67 @class UIWindow;
68 @class UITextField;
69 #else
70 class UIEvent;
71 class UIFont;
72 class UIImage;
73 class UIView;
74 class UIWindow;
75 class UITextField;
76 #endif // __OBJC__
77 #elif defined(OS_MACOSX)
78 struct CGContext;
79 #ifdef __OBJC__
80 @class NSCursor;
81 @class NSEvent;
82 @class NSFont;
83 @class NSImage;
84 @class NSView;
85 @class NSWindow;
86 @class NSTextField;
87 #else
88 class NSCursor;
89 class NSEvent;
90 class NSFont;
91 class NSImage;
92 struct NSView;
93 class NSWindow;
94 class NSTextField;
95 #endif // __OBJC__
96 #elif defined(OS_POSIX)
97 typedef struct _cairo cairo_t;
98 #endif
100 #if defined(OS_ANDROID)
101 struct ANativeWindow;
102 namespace ui {
103 class WindowAndroid;
104 class ViewAndroid;
106 #endif
107 class SkBitmap;
109 #if defined(USE_X11) && !defined(OS_CHROMEOS)
110 extern "C" {
111 struct _AtkObject;
112 typedef struct _AtkObject AtkObject;
114 #endif
116 namespace gfx {
118 #if defined(USE_AURA)
119 typedef ui::Cursor NativeCursor;
120 typedef aura::Window* NativeView;
121 typedef aura::Window* NativeWindow;
122 typedef SkRegion* NativeRegion;
123 typedef ui::Event* NativeEvent;
124 #elif defined(OS_IOS)
125 typedef void* NativeCursor;
126 typedef UIView* NativeView;
127 typedef UIWindow* NativeWindow;
128 typedef UIEvent* NativeEvent;
129 #elif defined(OS_MACOSX)
130 typedef NSCursor* NativeCursor;
131 typedef NSView* NativeView;
132 typedef NSWindow* NativeWindow;
133 typedef void* NativeRegion;
134 typedef NSEvent* NativeEvent;
135 #elif defined(OS_ANDROID)
136 typedef void* NativeCursor;
137 typedef ui::ViewAndroid* NativeView;
138 typedef ui::WindowAndroid* NativeWindow;
139 typedef void* NativeRegion;
140 typedef jobject NativeEvent;
141 #endif
143 #if defined(OS_WIN)
144 typedef HFONT NativeFont;
145 typedef HWND NativeEditView;
146 typedef HDC NativeDrawingContext;
147 typedef IAccessible* NativeViewAccessible;
148 #elif defined(OS_IOS)
149 typedef UIFont* NativeFont;
150 typedef UITextField* NativeEditView;
151 typedef CGContext* NativeDrawingContext;
152 #ifdef __OBJC__
153 typedef id NativeViewAccessible;
154 #else
155 typedef void* NativeViewAccessible;
156 #endif // __OBJC__
157 #elif defined(OS_MACOSX)
158 typedef NSFont* NativeFont;
159 typedef NSTextField* NativeEditView;
160 typedef CGContext* NativeDrawingContext;
161 #ifdef __OBJC__
162 typedef id NativeViewAccessible;
163 #else
164 typedef void* NativeViewAccessible;
165 #endif // __OBJC__
166 #else // Android, Linux, Chrome OS, etc.
167 // Linux doesn't have a native font type.
168 typedef void* NativeEditView;
169 #if defined(USE_CAIRO)
170 typedef cairo_t* NativeDrawingContext;
171 #else
172 typedef void* NativeDrawingContext;
173 #endif // defined(USE_CAIRO)
174 #if defined(USE_X11) && !defined(OS_CHROMEOS)
175 typedef AtkObject* NativeViewAccessible;
176 #else
177 typedef void* NativeViewAccessible;
178 #endif
179 #endif
181 // A constant value to indicate that gfx::NativeCursor refers to no cursor.
182 #if defined(USE_AURA)
183 const int kNullCursor = 0;
184 #else
185 const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL);
186 #endif
188 #if defined(OS_IOS)
189 typedef UIImage NativeImageType;
190 #elif defined(OS_MACOSX)
191 typedef NSImage NativeImageType;
192 #else
193 typedef SkBitmap NativeImageType;
194 #endif
195 typedef NativeImageType* NativeImage;
197 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if
198 // you make it a type which is smaller than a pointer, you have to fix
199 // test_shell.
201 // See comment at the top of the file for usage.
202 typedef intptr_t NativeViewId;
204 // PluginWindowHandle is an abstraction wrapping "the types of windows
205 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X
206 // window id.
207 #if defined(OS_WIN)
208 typedef HWND PluginWindowHandle;
209 const PluginWindowHandle kNullPluginWindow = NULL;
210 #elif defined(USE_X11)
211 typedef unsigned long PluginWindowHandle;
212 const PluginWindowHandle kNullPluginWindow = 0;
213 #elif defined(OS_ANDROID)
214 typedef uint64 PluginWindowHandle;
215 const PluginWindowHandle kNullPluginWindow = 0;
216 #elif defined(USE_OZONE)
217 typedef intptr_t PluginWindowHandle;
218 const PluginWindowHandle kNullPluginWindow = 0;
219 #else
220 // On Mac we don't have windowed plugins. We use a NULL/0 PluginWindowHandle
221 // in shared code to indicate there is no window present.
222 typedef bool PluginWindowHandle;
223 const PluginWindowHandle kNullPluginWindow = 0;
224 #endif
226 enum SurfaceType {
227 EMPTY,
228 NATIVE_DIRECT,
229 NULL_TRANSPORT,
230 SURFACE_TYPE_LAST = NULL_TRANSPORT
233 struct GLSurfaceHandle {
234 GLSurfaceHandle()
235 : handle(kNullPluginWindow),
236 transport_type(EMPTY),
237 parent_client_id(0) {
239 GLSurfaceHandle(PluginWindowHandle handle_, SurfaceType transport_)
240 : handle(handle_),
241 transport_type(transport_),
242 parent_client_id(0) {
243 DCHECK(!is_null() || handle == kNullPluginWindow);
244 DCHECK(transport_type != NULL_TRANSPORT ||
245 handle == kNullPluginWindow);
247 bool is_null() const { return transport_type == EMPTY; }
248 bool is_transport() const {
249 return transport_type == NULL_TRANSPORT;
251 PluginWindowHandle handle;
252 SurfaceType transport_type;
253 uint32 parent_client_id;
256 // AcceleratedWidget provides a surface to compositors to paint pixels.
257 #if defined(OS_WIN)
258 typedef HWND AcceleratedWidget;
259 const AcceleratedWidget kNullAcceleratedWidget = NULL;
260 #elif defined(USE_X11)
261 typedef unsigned long AcceleratedWidget;
262 const AcceleratedWidget kNullAcceleratedWidget = 0;
263 #elif defined(OS_IOS)
264 typedef UIView* AcceleratedWidget;
265 const AcceleratedWidget kNullAcceleratedWidget = 0;
266 #elif defined(OS_MACOSX)
267 typedef NSView* AcceleratedWidget;
268 const AcceleratedWidget kNullAcceleratedWidget = 0;
269 #elif defined(OS_ANDROID)
270 typedef ANativeWindow* AcceleratedWidget;
271 const AcceleratedWidget kNullAcceleratedWidget = 0;
272 #elif defined(USE_OZONE)
273 typedef intptr_t AcceleratedWidget;
274 const AcceleratedWidget kNullAcceleratedWidget = 0;
275 #else
276 #error unknown platform
277 #endif
279 } // namespace gfx
281 #endif // UI_GFX_NATIVE_WIDGET_TYPES_H_