native_widget_types.h revision 4ad1aa43a48567659193a298fad74f55e00b3dd9
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)
46class SkRegion;
47namespace aura {
48class Window;
49}
50namespace ui {
51class Cursor;
52class Event;
53}
54#endif  // defined(USE_AURA)
55
56#if defined(OS_WIN)
57#include <windows.h>  // NOLINT
58typedef struct HFONT__* HFONT;
59struct IAccessible;
60#elif defined(OS_IOS)
61struct CGContext;
62#ifdef __OBJC__
63@class UIEvent;
64@class UIFont;
65@class UIImage;
66@class UIView;
67@class UIWindow;
68@class UITextField;
69#else
70class UIEvent;
71class UIFont;
72class UIImage;
73class UIView;
74class UIWindow;
75class UITextField;
76#endif  // __OBJC__
77#elif defined(OS_MACOSX)
78struct 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
88class NSCursor;
89class NSEvent;
90class NSFont;
91class NSImage;
92struct NSView;
93class NSWindow;
94class NSTextField;
95#endif  // __OBJC__
96#elif defined(OS_POSIX)
97typedef struct _PangoFontDescription PangoFontDescription;
98typedef struct _cairo cairo_t;
99#endif
100
101#if defined(TOOLKIT_GTK)
102typedef struct _GdkCursor GdkCursor;
103typedef union _GdkEvent GdkEvent;
104typedef struct _GdkPixbuf GdkPixbuf;
105typedef struct _GdkRegion GdkRegion;
106typedef struct _GtkWidget GtkWidget;
107typedef struct _GtkWindow GtkWindow;
108#elif defined(OS_ANDROID)
109struct ANativeWindow;
110namespace ui {
111class WindowAndroid;
112class ViewAndroid;
113}
114#endif
115class SkBitmap;
116
117namespace gfx {
118
119#if defined(USE_AURA)
120typedef ui::Cursor NativeCursor;
121typedef aura::Window* NativeView;
122typedef aura::Window* NativeWindow;
123typedef SkRegion* NativeRegion;
124typedef ui::Event* NativeEvent;
125#elif defined(OS_IOS)
126typedef void* NativeCursor;
127typedef UIView* NativeView;
128typedef UIWindow* NativeWindow;
129typedef UIEvent* NativeEvent;
130#elif defined(OS_MACOSX)
131typedef NSCursor* NativeCursor;
132typedef NSView* NativeView;
133typedef NSWindow* NativeWindow;
134typedef NSEvent* NativeEvent;
135#elif defined(TOOLKIT_GTK)
136typedef GdkCursor* NativeCursor;
137typedef GtkWidget* NativeView;
138typedef GtkWindow* NativeWindow;
139typedef GdkRegion* NativeRegion;
140typedef GdkEvent* NativeEvent;
141#elif defined(OS_ANDROID)
142typedef void* NativeCursor;
143typedef ui::ViewAndroid* NativeView;
144typedef ui::WindowAndroid* NativeWindow;
145typedef void* NativeRegion;
146typedef jobject NativeEvent;
147#endif
148
149#if defined(OS_WIN)
150typedef HFONT NativeFont;
151typedef HWND NativeEditView;
152typedef HDC NativeDrawingContext;
153typedef IAccessible* NativeViewAccessible;
154#elif defined(OS_IOS)
155typedef UIFont* NativeFont;
156typedef UITextField* NativeEditView;
157typedef CGContext* NativeDrawingContext;
158#elif defined(OS_MACOSX)
159typedef NSFont* NativeFont;
160typedef NSTextField* NativeEditView;
161typedef CGContext* NativeDrawingContext;
162typedef void* NativeViewAccessible;
163#elif defined(TOOLKIT_GTK)
164typedef PangoFontDescription* NativeFont;
165typedef GtkWidget* NativeEditView;
166typedef cairo_t* NativeDrawingContext;
167typedef void* NativeViewAccessible;
168#elif defined(USE_CAIRO)
169typedef PangoFontDescription* NativeFont;
170typedef void* NativeEditView;
171typedef cairo_t* NativeDrawingContext;
172typedef void* NativeViewAccessible;
173#else
174typedef void* NativeFont;
175typedef void* NativeEditView;
176typedef void* NativeDrawingContext;
177typedef void* NativeViewAccessible;
178#endif
179
180// A constant value to indicate that gfx::NativeCursor refers to no cursor.
181#if defined(USE_AURA)
182const int kNullCursor = 0;
183#else
184const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL);
185#endif
186
187#if defined(OS_IOS)
188typedef UIImage NativeImageType;
189#elif defined(OS_MACOSX)
190typedef NSImage NativeImageType;
191#elif defined(TOOLKIT_GTK)
192typedef GdkPixbuf NativeImageType;
193#else
194typedef SkBitmap NativeImageType;
195#endif
196typedef NativeImageType* NativeImage;
197
198// Note: for test_shell we're packing a pointer into the NativeViewId. So, if
199// you make it a type which is smaller than a pointer, you have to fix
200// test_shell.
201//
202// See comment at the top of the file for usage.
203typedef intptr_t NativeViewId;
204
205// PluginWindowHandle is an abstraction wrapping "the types of windows
206// used by NPAPI plugins". On Windows it's an HWND, on X it's an X
207// window id.
208#if defined(OS_WIN)
209  typedef HWND PluginWindowHandle;
210  const PluginWindowHandle kNullPluginWindow = NULL;
211#elif defined(USE_X11)
212  typedef unsigned long PluginWindowHandle;
213  const PluginWindowHandle kNullPluginWindow = 0;
214#elif defined(OS_ANDROID)
215  typedef uint64 PluginWindowHandle;
216  const PluginWindowHandle kNullPluginWindow = 0;
217#elif defined(USE_OZONE)
218  typedef intptr_t PluginWindowHandle;
219  const PluginWindowHandle kNullPluginWindow = 0;
220#else
221  // On Mac we don't have windowed plugins. We use a NULL/0 PluginWindowHandle
222  // in shared code to indicate there is no window present.
223  typedef bool PluginWindowHandle;
224  const PluginWindowHandle kNullPluginWindow = 0;
225#endif
226
227enum SurfaceType {
228  EMPTY,
229  NATIVE_DIRECT,
230  NATIVE_TRANSPORT,
231  TEXTURE_TRANSPORT,
232  SURFACE_TYPE_LAST = TEXTURE_TRANSPORT
233};
234
235struct GLSurfaceHandle {
236  GLSurfaceHandle()
237      : handle(kNullPluginWindow),
238        transport_type(EMPTY),
239        parent_client_id(0) {
240  }
241  GLSurfaceHandle(PluginWindowHandle handle_, SurfaceType transport_)
242      : handle(handle_),
243        transport_type(transport_),
244        parent_client_id(0) {
245    DCHECK(!is_null() || handle == kNullPluginWindow);
246    DCHECK(transport_type != TEXTURE_TRANSPORT ||
247           handle == kNullPluginWindow);
248  }
249  bool is_null() const { return transport_type == EMPTY; }
250  bool is_transport() const {
251    return transport_type == NATIVE_TRANSPORT ||
252           transport_type == TEXTURE_TRANSPORT;
253  }
254  PluginWindowHandle handle;
255  SurfaceType transport_type;
256  uint32 parent_client_id;
257};
258
259// AcceleratedWidget provides a surface to compositors to paint pixels.
260#if defined(OS_WIN)
261typedef HWND AcceleratedWidget;
262const AcceleratedWidget kNullAcceleratedWidget = NULL;
263#elif defined(USE_X11)
264typedef unsigned long AcceleratedWidget;
265const AcceleratedWidget kNullAcceleratedWidget = 0;
266#elif defined(OS_IOS)
267typedef UIView* AcceleratedWidget;
268const AcceleratedWidget kNullAcceleratedWidget = 0;
269#elif defined(OS_MACOSX)
270typedef NSView* AcceleratedWidget;
271const AcceleratedWidget kNullAcceleratedWidget = 0;
272#elif defined(OS_ANDROID)
273typedef ANativeWindow* AcceleratedWidget;
274const AcceleratedWidget kNullAcceleratedWidget = 0;
275#elif defined(USE_OZONE)
276typedef intptr_t AcceleratedWidget;
277const AcceleratedWidget kNullAcceleratedWidget = 0;
278#else
279#error unknown platform
280#endif
281
282}  // namespace gfx
283
284#endif  // UI_GFX_NATIVE_WIDGET_TYPES_H_
285