Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / native_widget_types.h
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.
4
5 #ifndef UI_GFX_NATIVE_WIDGET_TYPES_H_
6 #define UI_GFX_NATIVE_WIDGET_TYPES_H_
7
8 #include "build/build_config.h"
9
10 #if defined(OS_ANDROID)
11 #include <jni.h>
12 #endif
13
14 #include "base/basictypes.h"
15 #include "base/logging.h"
16 #include "ui/gfx/gfx_export.h"
17
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.
26 //
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.
30 //
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.
34 //
35 //   NativeEditView: a handle to a native edit-box. The Mac folks wanted this
36 //     specific typedef.
37 //
38 //   NativeImage: The platform-specific image type used for drawing UI elements
39 //     in the browser.
40 //
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'.
44
45 #if defined(USE_AURA)
46 class SkRegion;
47 namespace aura {
48 class Window;
49 }
50 namespace ui {
51 class Cursor;
52 class Event;
53 }
54 #endif  // defined(USE_AURA)
55
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
100
101 #if defined(OS_ANDROID)
102 struct ANativeWindow;
103 namespace ui {
104 class WindowAndroid;
105 class ViewAndroid;
106 }
107 #endif
108 class SkBitmap;
109
110 namespace gfx {
111
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 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;
134 #endif
135
136 #if defined(OS_WIN)
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;
145 #elif defined(OS_MACOSX)
146 typedef NSFont* NativeFont;
147 typedef NSTextField* NativeEditView;
148 typedef CGContext* NativeDrawingContext;
149 typedef void* NativeViewAccessible;
150 #elif defined(USE_CAIRO)
151 typedef PangoFontDescription* NativeFont;
152 typedef void* NativeEditView;
153 typedef cairo_t* NativeDrawingContext;
154 typedef void* NativeViewAccessible;
155 #else
156 typedef void* NativeFont;
157 typedef void* NativeEditView;
158 typedef void* NativeDrawingContext;
159 typedef void* NativeViewAccessible;
160 #endif
161
162 // A constant value to indicate that gfx::NativeCursor refers to no cursor.
163 #if defined(USE_AURA)
164 const int kNullCursor = 0;
165 #else
166 const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL);
167 #endif
168
169 #if defined(OS_IOS)
170 typedef UIImage NativeImageType;
171 #elif defined(OS_MACOSX)
172 typedef NSImage NativeImageType;
173 #else
174 typedef SkBitmap NativeImageType;
175 #endif
176 typedef NativeImageType* NativeImage;
177
178 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if
179 // you make it a type which is smaller than a pointer, you have to fix
180 // test_shell.
181 //
182 // See comment at the top of the file for usage.
183 typedef intptr_t NativeViewId;
184
185 // PluginWindowHandle is an abstraction wrapping "the types of windows
186 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X
187 // window id.
188 #if defined(OS_WIN)
189   typedef HWND PluginWindowHandle;
190   const PluginWindowHandle kNullPluginWindow = NULL;
191 #elif defined(USE_X11)
192   typedef unsigned long PluginWindowHandle;
193   const PluginWindowHandle kNullPluginWindow = 0;
194 #elif defined(OS_ANDROID)
195   typedef uint64 PluginWindowHandle;
196   const PluginWindowHandle kNullPluginWindow = 0;
197 #elif defined(USE_OZONE)
198   typedef intptr_t PluginWindowHandle;
199   const PluginWindowHandle kNullPluginWindow = 0;
200 #else
201   // On Mac we don't have windowed plugins. We use a NULL/0 PluginWindowHandle
202   // in shared code to indicate there is no window present.
203   typedef bool PluginWindowHandle;
204   const PluginWindowHandle kNullPluginWindow = 0;
205 #endif
206
207 enum SurfaceType {
208   EMPTY,
209   NATIVE_DIRECT,
210   NATIVE_TRANSPORT,
211   TEXTURE_TRANSPORT,
212   SURFACE_TYPE_LAST = TEXTURE_TRANSPORT
213 };
214
215 struct GLSurfaceHandle {
216   GLSurfaceHandle()
217       : handle(kNullPluginWindow),
218         transport_type(EMPTY),
219         parent_client_id(0) {
220   }
221   GLSurfaceHandle(PluginWindowHandle handle_, SurfaceType transport_)
222       : handle(handle_),
223         transport_type(transport_),
224         parent_client_id(0) {
225     DCHECK(!is_null() || handle == kNullPluginWindow);
226     DCHECK(transport_type != TEXTURE_TRANSPORT ||
227            handle == kNullPluginWindow);
228   }
229   bool is_null() const { return transport_type == EMPTY; }
230   bool is_transport() const {
231     return transport_type == NATIVE_TRANSPORT ||
232            transport_type == TEXTURE_TRANSPORT;
233   }
234   PluginWindowHandle handle;
235   SurfaceType transport_type;
236   uint32 parent_client_id;
237 };
238
239 // AcceleratedWidget provides a surface to compositors to paint pixels.
240 #if defined(OS_WIN)
241 typedef HWND AcceleratedWidget;
242 const AcceleratedWidget kNullAcceleratedWidget = NULL;
243 #elif defined(USE_X11)
244 typedef unsigned long AcceleratedWidget;
245 const AcceleratedWidget kNullAcceleratedWidget = 0;
246 #elif defined(OS_IOS)
247 typedef UIView* AcceleratedWidget;
248 const AcceleratedWidget kNullAcceleratedWidget = 0;
249 #elif defined(OS_MACOSX)
250 typedef NSView* AcceleratedWidget;
251 const AcceleratedWidget kNullAcceleratedWidget = 0;
252 #elif defined(OS_ANDROID)
253 typedef ANativeWindow* AcceleratedWidget;
254 const AcceleratedWidget kNullAcceleratedWidget = 0;
255 #elif defined(USE_OZONE)
256 typedef intptr_t AcceleratedWidget;
257 const AcceleratedWidget kNullAcceleratedWidget = 0;
258 #else
259 #error unknown platform
260 #endif
261
262 }  // namespace gfx
263
264 #endif  // UI_GFX_NATIVE_WIDGET_TYPES_H_