native_widget_types.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 "ui/base/ui_export.h" 16 17// This file provides cross platform typedefs for native widget types. 18// NativeWindow: this is a handle to a native, top-level window 19// NativeView: this is a handle to a native UI element. It may be the 20// same type as a NativeWindow on some platforms. 21// NativeViewId: Often, in our cross process model, we need to pass around a 22// reference to a "window". This reference will, say, be echoed back from a 23// renderer to the browser when it wishes to query its size. On Windows we 24// use an HWND for this. 25// 26// As a rule of thumb - if you're in the renderer, you should be dealing 27// with NativeViewIds. This should remind you that you shouldn't be doing 28// direct operations on platform widgets from the renderer process. 29// 30// If you're in the browser, you're probably dealing with NativeViews, 31// unless you're in the IPC layer, which will be translating between 32// NativeViewIds from the renderer and NativeViews. 33// 34// NativeEditView: a handle to a native edit-box. The Mac folks wanted this 35// specific typedef. 36// 37// NativeImage: The platform-specific image type used for drawing UI elements 38// in the browser. 39// 40// The name 'View' here meshes with OS X where the UI elements are called 41// 'views' and with our Chrome UI code where the elements are also called 42// 'views'. 43 44#if defined(USE_AURA) 45#include "ui/base/cursor/cursor.h" 46 47class SkRegion; 48namespace aura { 49class Window; 50} 51namespace ui { 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 content { 111class ContentViewCore; 112} 113namespace ui { 114class WindowAndroid; 115} 116#endif 117class SkBitmap; 118 119namespace gfx { 120 121#if defined(USE_AURA) 122typedef ui::Cursor NativeCursor; 123typedef aura::Window* NativeView; 124typedef aura::Window* NativeWindow; 125typedef SkRegion* NativeRegion; 126typedef ui::Event* NativeEvent; 127#elif defined(OS_WIN) 128typedef HCURSOR NativeCursor; 129typedef HWND NativeView; 130typedef HWND NativeWindow; 131typedef HRGN NativeRegion; 132typedef MSG NativeEvent; 133#elif defined(OS_IOS) 134typedef void* NativeCursor; 135typedef UIView* NativeView; 136typedef UIWindow* NativeWindow; 137typedef UIEvent* NativeEvent; 138#elif defined(OS_MACOSX) 139typedef NSCursor* NativeCursor; 140typedef NSView* NativeView; 141typedef NSWindow* NativeWindow; 142typedef NSEvent* NativeEvent; 143#elif defined(TOOLKIT_GTK) 144typedef GdkCursor* NativeCursor; 145typedef GtkWidget* NativeView; 146typedef GtkWindow* NativeWindow; 147typedef GdkRegion* NativeRegion; 148typedef GdkEvent* NativeEvent; 149#elif defined(OS_ANDROID) 150typedef void* NativeCursor; 151typedef content::ContentViewCore* NativeView; 152typedef ui::WindowAndroid* NativeWindow; 153typedef void* NativeRegion; 154typedef jobject NativeEvent; 155#endif 156 157#if defined(OS_WIN) 158typedef HFONT NativeFont; 159typedef HWND NativeEditView; 160typedef HDC NativeDrawingContext; 161typedef HMENU NativeMenu; 162typedef IAccessible* NativeViewAccessible; 163#elif defined(OS_IOS) 164typedef UIFont* NativeFont; 165typedef UITextField* NativeEditView; 166typedef CGContext* NativeDrawingContext; 167typedef void* NativeMenu; 168#elif defined(OS_MACOSX) 169typedef NSFont* NativeFont; 170typedef NSTextField* NativeEditView; 171typedef CGContext* NativeDrawingContext; 172typedef void* NativeMenu; 173typedef void* NativeViewAccessible; 174#elif defined(TOOLKIT_GTK) 175typedef PangoFontDescription* NativeFont; 176typedef GtkWidget* NativeEditView; 177typedef cairo_t* NativeDrawingContext; 178typedef GtkWidget* NativeMenu; 179typedef void* NativeViewAccessible; 180#elif defined(USE_AURA) 181typedef PangoFontDescription* NativeFont; 182typedef void* NativeEditView; 183typedef cairo_t* NativeDrawingContext; 184typedef void* NativeMenu; 185typedef void* NativeViewAccessible; 186#elif defined(OS_ANDROID) 187typedef void* NativeFont; 188typedef void* NativeEditView; 189typedef void* NativeDrawingContext; 190typedef void* NativeMenu; 191typedef void* NativeViewAccessible; 192#endif 193 194// A constant value to indicate that gfx::NativeCursor refers to no cursor. 195#if defined(USE_AURA) 196const int kNullCursor = 0; 197#else 198const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL); 199#endif 200 201#if defined(OS_IOS) 202typedef UIImage NativeImageType; 203#elif defined(OS_MACOSX) 204typedef NSImage NativeImageType; 205#elif defined(TOOLKIT_GTK) 206typedef GdkPixbuf NativeImageType; 207#else 208typedef SkBitmap NativeImageType; 209#endif 210typedef NativeImageType* NativeImage; 211 212// Note: for test_shell we're packing a pointer into the NativeViewId. So, if 213// you make it a type which is smaller than a pointer, you have to fix 214// test_shell. 215// 216// See comment at the top of the file for usage. 217typedef intptr_t NativeViewId; 218 219#if defined(OS_WIN) && !defined(USE_AURA) 220// Convert a NativeViewId to a NativeView. 221// 222// On Windows, we pass an HWND into the renderer. As stated above, the renderer 223// should not be performing operations on the view. 224static inline NativeView NativeViewFromId(NativeViewId id) { 225 return reinterpret_cast<NativeView>(id); 226} 227#define NativeViewFromIdInBrowser(x) NativeViewFromId(x) 228#elif defined(OS_POSIX) || defined(USE_AURA) 229// On Mac, Linux and USE_AURA, a NativeView is a pointer to an object, and is 230// useless outside the process in which it was created. NativeViewFromId should 231// only be used inside the appropriate platform ifdef outside of the browser. 232// (NativeViewFromIdInBrowser can be used everywhere in the browser.) If your 233// cross-platform design involves a call to NativeViewFromId from outside the 234// browser it will never work on Mac or Linux and is fundamentally broken. 235 236// Please do not call this from outside the browser. It won't work; the name 237// should give you a subtle hint. 238static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) { 239 return reinterpret_cast<NativeView>(id); 240} 241#endif // defined(OS_POSIX) 242 243// PluginWindowHandle is an abstraction wrapping "the types of windows 244// used by NPAPI plugins". On Windows it's an HWND, on X it's an X 245// window id. 246#if defined(OS_WIN) 247 typedef HWND PluginWindowHandle; 248 const PluginWindowHandle kNullPluginWindow = NULL; 249#elif defined(USE_X11) 250 typedef unsigned long PluginWindowHandle; 251 const PluginWindowHandle kNullPluginWindow = 0; 252#elif defined(USE_AURA) && defined(OS_MACOSX) 253 // Mac-Aura uses NSView-backed GLSurface. Regular Mac does not. 254 // TODO(dhollowa): Rationalize these two definitions. http://crbug.com/104551. 255 typedef NSView* PluginWindowHandle; 256 const PluginWindowHandle kNullPluginWindow = 0; 257#elif defined(OS_ANDROID) 258 typedef uint64 PluginWindowHandle; 259 const PluginWindowHandle kNullPluginWindow = 0; 260 const PluginWindowHandle kDummyPluginWindow = 0xFEEDBEEF; 261#else 262 // On OS X we don't have windowed plugins. 263 // We use a NULL/0 PluginWindowHandle in shared code to indicate there 264 // is no window present, so mirror that behavior here. 265 // 266 // The GPU plugin is currently an exception to this rule. As of this 267 // writing it uses some NPAPI infrastructure, and minimally we need 268 // to identify the plugin instance via this window handle. When the 269 // GPU plugin becomes a full-on GPU process, this typedef can be 270 // returned to a bool. For now we use a type large enough to hold a 271 // pointer on 64-bit architectures in case we need this capability. 272 typedef uint64 PluginWindowHandle; 273 const PluginWindowHandle kNullPluginWindow = 0; 274#endif 275 276struct GLSurfaceHandle { 277 GLSurfaceHandle() 278 : handle(kNullPluginWindow), 279 transport(false), 280 parent_gpu_process_id(0), 281 parent_client_id(0), 282 parent_context_id(0), 283 sync_point(0) { 284 parent_texture_id[0] = 0; 285 parent_texture_id[1] = 0; 286 } 287 GLSurfaceHandle(PluginWindowHandle handle_, bool transport_) 288 : handle(handle_), 289 transport(transport_), 290 parent_gpu_process_id(0), 291 parent_client_id(0), 292 parent_context_id(0), 293 sync_point(0) { 294 parent_texture_id[0] = 0; 295 parent_texture_id[1] = 0; 296 } 297 bool is_null() const { return handle == kNullPluginWindow && !transport; } 298 PluginWindowHandle handle; 299 bool transport; 300 int parent_gpu_process_id; 301 uint32 parent_client_id; 302 uint32 parent_context_id; 303 uint32 parent_texture_id[2]; 304 uint32 sync_point; 305}; 306 307// AcceleratedWidget provides a surface to compositors to paint pixels. 308#if defined(OS_WIN) 309typedef HWND AcceleratedWidget; 310const AcceleratedWidget kNullAcceleratedWidget = NULL; 311#elif defined(USE_X11) 312typedef unsigned long AcceleratedWidget; 313const AcceleratedWidget kNullAcceleratedWidget = 0; 314#elif defined(OS_IOS) 315typedef UIView* AcceleratedWidget; 316const AcceleratedWidget kNullAcceleratedWidget = 0; 317#elif defined(OS_MACOSX) 318typedef NSView* AcceleratedWidget; 319const AcceleratedWidget kNullAcceleratedWidget = 0; 320#elif defined(OS_ANDROID) 321typedef ANativeWindow* AcceleratedWidget; 322const AcceleratedWidget kNullAcceleratedWidget = 0; 323#else 324#error unknown platform 325#endif 326 327} // namespace gfx 328 329#endif // UI_GFX_NATIVE_WIDGET_TYPES_H_ 330