native_widget_types.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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(OS_ANDROID) 102struct ANativeWindow; 103namespace ui { 104class WindowAndroid; 105class ViewAndroid; 106} 107#endif 108class SkBitmap; 109 110namespace gfx { 111 112#if defined(USE_AURA) 113typedef ui::Cursor NativeCursor; 114typedef aura::Window* NativeView; 115typedef aura::Window* NativeWindow; 116typedef SkRegion* NativeRegion; 117typedef ui::Event* NativeEvent; 118#elif defined(OS_IOS) 119typedef void* NativeCursor; 120typedef UIView* NativeView; 121typedef UIWindow* NativeWindow; 122typedef UIEvent* NativeEvent; 123#elif defined(OS_MACOSX) 124typedef NSCursor* NativeCursor; 125typedef NSView* NativeView; 126typedef NSWindow* NativeWindow; 127typedef void* NativeRegion; 128typedef NSEvent* NativeEvent; 129#elif defined(OS_ANDROID) 130typedef void* NativeCursor; 131typedef ui::ViewAndroid* NativeView; 132typedef ui::WindowAndroid* NativeWindow; 133typedef void* NativeRegion; 134typedef jobject NativeEvent; 135#endif 136 137#if defined(OS_WIN) 138typedef HFONT NativeFont; 139typedef HWND NativeEditView; 140typedef HDC NativeDrawingContext; 141typedef IAccessible* NativeViewAccessible; 142#elif defined(OS_IOS) 143typedef UIFont* NativeFont; 144typedef UITextField* NativeEditView; 145typedef CGContext* NativeDrawingContext; 146#elif defined(OS_MACOSX) 147typedef NSFont* NativeFont; 148typedef NSTextField* NativeEditView; 149typedef CGContext* NativeDrawingContext; 150typedef void* NativeViewAccessible; 151#elif defined(USE_CAIRO) 152typedef PangoFontDescription* NativeFont; 153typedef void* NativeEditView; 154typedef cairo_t* NativeDrawingContext; 155typedef void* NativeViewAccessible; 156#else 157typedef void* NativeFont; 158typedef void* NativeEditView; 159typedef void* NativeDrawingContext; 160typedef void* NativeViewAccessible; 161#endif 162 163// A constant value to indicate that gfx::NativeCursor refers to no cursor. 164#if defined(USE_AURA) 165const int kNullCursor = 0; 166#else 167const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL); 168#endif 169 170#if defined(OS_IOS) 171typedef UIImage NativeImageType; 172#elif defined(OS_MACOSX) 173typedef NSImage NativeImageType; 174#else 175typedef SkBitmap NativeImageType; 176#endif 177typedef NativeImageType* NativeImage; 178 179// Note: for test_shell we're packing a pointer into the NativeViewId. So, if 180// you make it a type which is smaller than a pointer, you have to fix 181// test_shell. 182// 183// See comment at the top of the file for usage. 184typedef intptr_t NativeViewId; 185 186// PluginWindowHandle is an abstraction wrapping "the types of windows 187// used by NPAPI plugins". On Windows it's an HWND, on X it's an X 188// window id. 189#if defined(OS_WIN) 190 typedef HWND PluginWindowHandle; 191 const PluginWindowHandle kNullPluginWindow = NULL; 192#elif defined(USE_X11) 193 typedef unsigned long PluginWindowHandle; 194 const PluginWindowHandle kNullPluginWindow = 0; 195#elif defined(OS_ANDROID) 196 typedef uint64 PluginWindowHandle; 197 const PluginWindowHandle kNullPluginWindow = 0; 198#elif defined(USE_OZONE) 199 typedef intptr_t PluginWindowHandle; 200 const PluginWindowHandle kNullPluginWindow = 0; 201#else 202 // On Mac we don't have windowed plugins. We use a NULL/0 PluginWindowHandle 203 // in shared code to indicate there is no window present. 204 typedef bool PluginWindowHandle; 205 const PluginWindowHandle kNullPluginWindow = 0; 206#endif 207 208enum SurfaceType { 209 EMPTY, 210 NATIVE_DIRECT, 211 NATIVE_TRANSPORT, 212 TEXTURE_TRANSPORT, 213 SURFACE_TYPE_LAST = TEXTURE_TRANSPORT 214}; 215 216struct GLSurfaceHandle { 217 GLSurfaceHandle() 218 : handle(kNullPluginWindow), 219 transport_type(EMPTY), 220 parent_client_id(0) { 221 } 222 GLSurfaceHandle(PluginWindowHandle handle_, SurfaceType transport_) 223 : handle(handle_), 224 transport_type(transport_), 225 parent_client_id(0) { 226 DCHECK(!is_null() || handle == kNullPluginWindow); 227 DCHECK(transport_type != TEXTURE_TRANSPORT || 228 handle == kNullPluginWindow); 229 } 230 bool is_null() const { return transport_type == EMPTY; } 231 bool is_transport() const { 232 return transport_type == NATIVE_TRANSPORT || 233 transport_type == TEXTURE_TRANSPORT; 234 } 235 PluginWindowHandle handle; 236 SurfaceType transport_type; 237 uint32 parent_client_id; 238}; 239 240// AcceleratedWidget provides a surface to compositors to paint pixels. 241#if defined(OS_WIN) 242typedef HWND AcceleratedWidget; 243const AcceleratedWidget kNullAcceleratedWidget = NULL; 244#elif defined(USE_X11) 245typedef unsigned long AcceleratedWidget; 246const AcceleratedWidget kNullAcceleratedWidget = 0; 247#elif defined(OS_IOS) 248typedef UIView* AcceleratedWidget; 249const AcceleratedWidget kNullAcceleratedWidget = 0; 250#elif defined(OS_MACOSX) 251typedef NSView* AcceleratedWidget; 252const AcceleratedWidget kNullAcceleratedWidget = 0; 253#elif defined(OS_ANDROID) 254typedef ANativeWindow* AcceleratedWidget; 255const AcceleratedWidget kNullAcceleratedWidget = 0; 256#elif defined(USE_OZONE) 257typedef intptr_t AcceleratedWidget; 258const AcceleratedWidget kNullAcceleratedWidget = 0; 259#else 260#error unknown platform 261#endif 262 263} // namespace gfx 264 265#endif // UI_GFX_NATIVE_WIDGET_TYPES_H_ 266