Remove WebKitTestRunner::setClientWindowRect.
[chromium-blink-merge.git] / ui / gfx / native_widget_types.h
blob3d7b9d1cd3b774e993f210ac112d40e57ef3be86
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 _PangoFontDescription PangoFontDescription;
98 typedef struct _cairo cairo_t;
99 #endif
101 #if defined(TOOLKIT_GTK)
102 typedef struct _GdkCursor GdkCursor;
103 typedef union _GdkEvent GdkEvent;
104 typedef struct _GdkPixbuf GdkPixbuf;
105 typedef struct _GdkRegion GdkRegion;
106 typedef struct _GtkWidget GtkWidget;
107 typedef struct _GtkWindow GtkWindow;
108 #elif defined(OS_ANDROID)
109 struct ANativeWindow;
110 namespace ui {
111 class WindowAndroid;
112 class ViewAndroid;
114 #endif
115 class SkBitmap;
117 namespace gfx {
119 #if defined(USE_AURA)
120 typedef ui::Cursor NativeCursor;
121 typedef aura::Window* NativeView;
122 typedef aura::Window* NativeWindow;
123 typedef SkRegion* NativeRegion;
124 typedef ui::Event* NativeEvent;
125 #elif defined(OS_WIN)
126 typedef HCURSOR NativeCursor;
127 typedef HWND NativeView;
128 typedef HWND NativeWindow;
129 typedef HRGN NativeRegion;
130 typedef MSG NativeEvent;
131 #elif defined(OS_IOS)
132 typedef void* NativeCursor;
133 typedef UIView* NativeView;
134 typedef UIWindow* NativeWindow;
135 typedef UIEvent* NativeEvent;
136 #elif defined(OS_MACOSX)
137 typedef NSCursor* NativeCursor;
138 typedef NSView* NativeView;
139 typedef NSWindow* NativeWindow;
140 typedef NSEvent* NativeEvent;
141 #elif defined(TOOLKIT_GTK)
142 typedef GdkCursor* NativeCursor;
143 typedef GtkWidget* NativeView;
144 typedef GtkWindow* NativeWindow;
145 typedef GdkRegion* NativeRegion;
146 typedef GdkEvent* NativeEvent;
147 #elif defined(OS_ANDROID)
148 typedef void* NativeCursor;
149 typedef ui::ViewAndroid* NativeView;
150 typedef ui::WindowAndroid* NativeWindow;
151 typedef void* NativeRegion;
152 typedef jobject NativeEvent;
153 #endif
155 #if defined(OS_WIN)
156 typedef HFONT NativeFont;
157 typedef HWND NativeEditView;
158 typedef HDC NativeDrawingContext;
159 typedef IAccessible* NativeViewAccessible;
160 #elif defined(OS_IOS)
161 typedef UIFont* NativeFont;
162 typedef UITextField* NativeEditView;
163 typedef CGContext* NativeDrawingContext;
164 #elif defined(OS_MACOSX)
165 typedef NSFont* NativeFont;
166 typedef NSTextField* NativeEditView;
167 typedef CGContext* NativeDrawingContext;
168 typedef void* NativeViewAccessible;
169 #elif defined(TOOLKIT_GTK)
170 typedef PangoFontDescription* NativeFont;
171 typedef GtkWidget* NativeEditView;
172 typedef cairo_t* NativeDrawingContext;
173 typedef void* NativeViewAccessible;
174 #elif defined(USE_AURA)
175 typedef PangoFontDescription* NativeFont;
176 typedef void* NativeEditView;
177 typedef cairo_t* NativeDrawingContext;
178 typedef void* NativeViewAccessible;
179 #elif defined(OS_ANDROID)
180 typedef void* NativeFont;
181 typedef void* NativeEditView;
182 typedef void* NativeDrawingContext;
183 typedef void* NativeViewAccessible;
184 #endif
186 // A constant value to indicate that gfx::NativeCursor refers to no cursor.
187 #if defined(USE_AURA)
188 const int kNullCursor = 0;
189 #else
190 const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL);
191 #endif
193 #if defined(OS_IOS)
194 typedef UIImage NativeImageType;
195 #elif defined(OS_MACOSX)
196 typedef NSImage NativeImageType;
197 #elif defined(TOOLKIT_GTK)
198 typedef GdkPixbuf NativeImageType;
199 #else
200 typedef SkBitmap NativeImageType;
201 #endif
202 typedef NativeImageType* NativeImage;
204 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if
205 // you make it a type which is smaller than a pointer, you have to fix
206 // test_shell.
208 // See comment at the top of the file for usage.
209 typedef intptr_t NativeViewId;
211 #if defined(OS_WIN) && !defined(USE_AURA)
212 // Convert a NativeViewId to a NativeView.
214 // On Windows, we pass an HWND into the renderer. As stated above, the renderer
215 // should not be performing operations on the view.
216 static inline NativeView NativeViewFromId(NativeViewId id) {
217 return reinterpret_cast<NativeView>(id);
219 #define NativeViewFromIdInBrowser(x) NativeViewFromId(x)
220 #elif defined(OS_POSIX) || defined(USE_AURA)
221 // On Mac, Linux and USE_AURA, a NativeView is a pointer to an object, and is
222 // useless outside the process in which it was created. NativeViewFromId should
223 // only be used inside the appropriate platform ifdef outside of the browser.
224 // (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your
225 // cross-platform design involves a call to NativeViewFromId from outside the
226 // browser it will never work on Mac or Linux and is fundamentally broken.
228 // Please do not call this from outside the browser. It won't work; the name
229 // should give you a subtle hint.
230 static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) {
231 return reinterpret_cast<NativeView>(id);
233 #endif // defined(OS_POSIX)
235 // PluginWindowHandle is an abstraction wrapping "the types of windows
236 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X
237 // window id.
238 #if defined(OS_WIN)
239 typedef HWND PluginWindowHandle;
240 const PluginWindowHandle kNullPluginWindow = NULL;
241 #elif defined(USE_X11)
242 typedef unsigned long PluginWindowHandle;
243 const PluginWindowHandle kNullPluginWindow = 0;
244 #elif defined(USE_AURA) && defined(OS_MACOSX)
245 // Mac-Aura uses NSView-backed GLSurface. Regular Mac does not.
246 // TODO(dhollowa): Rationalize these two definitions. http://crbug.com/104551.
247 typedef NSView* PluginWindowHandle;
248 const PluginWindowHandle kNullPluginWindow = 0;
249 #elif defined(OS_ANDROID)
250 typedef uint64 PluginWindowHandle;
251 const PluginWindowHandle kNullPluginWindow = 0;
252 #elif defined(USE_OZONE)
253 typedef intptr_t PluginWindowHandle;
254 const PluginWindowHandle kNullPluginWindow = 0;
255 #else
256 // On OS X we don't have windowed plugins.
257 // We use a NULL/0 PluginWindowHandle in shared code to indicate there
258 // is no window present, so mirror that behavior here.
260 // The GPU plugin is currently an exception to this rule. As of this
261 // writing it uses some NPAPI infrastructure, and minimally we need
262 // to identify the plugin instance via this window handle. When the
263 // GPU plugin becomes a full-on GPU process, this typedef can be
264 // returned to a bool. For now we use a type large enough to hold a
265 // pointer on 64-bit architectures in case we need this capability.
266 typedef uint64 PluginWindowHandle;
267 const PluginWindowHandle kNullPluginWindow = 0;
268 #endif
270 enum SurfaceType {
271 EMPTY,
272 NATIVE_DIRECT,
273 NATIVE_TRANSPORT,
274 TEXTURE_TRANSPORT
277 struct GLSurfaceHandle {
278 GLSurfaceHandle()
279 : handle(kNullPluginWindow),
280 transport_type(EMPTY),
281 parent_gpu_process_id(0),
282 parent_client_id(0) {
284 GLSurfaceHandle(PluginWindowHandle handle_, SurfaceType transport_)
285 : handle(handle_),
286 transport_type(transport_),
287 parent_gpu_process_id(0),
288 parent_client_id(0) {
289 DCHECK(!is_null() || handle == kNullPluginWindow);
290 DCHECK(transport_type != TEXTURE_TRANSPORT ||
291 handle == kNullPluginWindow);
293 bool is_null() const { return transport_type == EMPTY; }
294 bool is_transport() const {
295 return transport_type == NATIVE_TRANSPORT ||
296 transport_type == TEXTURE_TRANSPORT;
298 PluginWindowHandle handle;
299 SurfaceType transport_type;
300 int parent_gpu_process_id;
301 uint32 parent_client_id;
304 // AcceleratedWidget provides a surface to compositors to paint pixels.
305 #if defined(OS_WIN)
306 typedef HWND AcceleratedWidget;
307 const AcceleratedWidget kNullAcceleratedWidget = NULL;
308 #elif defined(USE_X11)
309 typedef unsigned long AcceleratedWidget;
310 const AcceleratedWidget kNullAcceleratedWidget = 0;
311 #elif defined(OS_IOS)
312 typedef UIView* AcceleratedWidget;
313 const AcceleratedWidget kNullAcceleratedWidget = 0;
314 #elif defined(OS_MACOSX)
315 typedef NSView* AcceleratedWidget;
316 const AcceleratedWidget kNullAcceleratedWidget = 0;
317 #elif defined(OS_ANDROID)
318 typedef ANativeWindow* AcceleratedWidget;
319 const AcceleratedWidget kNullAcceleratedWidget = 0;
320 #elif defined(USE_OZONE)
321 typedef intptr_t AcceleratedWidget;
322 const AcceleratedWidget kNullAcceleratedWidget = 0;
323 #else
324 #error unknown platform
325 #endif
327 } // namespace gfx
329 #endif // UI_GFX_NATIVE_WIDGET_TYPES_H_