| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2008 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 BASE_GFX_NATIVE_WIDGET_TYPES_H_ | |
| 6 #define BASE_GFX_NATIVE_WIDGET_TYPES_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "build/build_config.h" | |
| 10 | |
| 11 // This file provides cross platform typedefs for native widget types. | |
| 12 // NativeWindow: this is a handle to a native, top-level window | |
| 13 // NativeView: this is a handle to a native UI element. It may be the | |
| 14 // same type as a NativeWindow on some platforms. | |
| 15 // NativeViewId: Often, in our cross process model, we need to pass around a | |
| 16 // reference to a "window". This reference will, say, be echoed back from a | |
| 17 // renderer to the browser when it wishes to query it's size. On Windows, a | |
| 18 // HWND can be used for this. On other platforms, we may wish to pass | |
| 19 // around X window ids, or maybe abstract identifiers. | |
| 20 // | |
| 21 // As a rule of thumb - if you're in the renderer, you should be dealing | |
| 22 // with NativeViewIds. This should remind you that you shouldn't be doing | |
| 23 // direct operations on platform widgets from the renderer process. | |
| 24 // | |
| 25 // If you're in the browser, you're probably dealing with NativeViews, | |
| 26 // unless you're in the IPC layer, which will be translating between | |
| 27 // NativeViewIds from the renderer and NativeViews. | |
| 28 // | |
| 29 // NativeEditView: a handle to a native edit-box. The Mac folks wanted this | |
| 30 // specific typedef. | |
| 31 // | |
| 32 // The name 'View' here meshes with OS X where the UI elements are called | |
| 33 // 'views' and with our Chrome UI code where the elements are also called | |
| 34 // 'views'. | |
| 35 | |
| 36 #if defined(OS_WIN) | |
| 37 #include <windows.h> | |
| 38 #elif defined(OS_MACOSX) | |
| 39 struct CGContext; | |
| 40 #ifdef __OBJC__ | |
| 41 @class NSView; | |
| 42 @class NSWindow; | |
| 43 @class NSTextField; | |
| 44 #else | |
| 45 class NSView; | |
| 46 class NSWindow; | |
| 47 class NSTextField; | |
| 48 #endif // __OBJC__ | |
| 49 #elif defined(USE_X11) | |
| 50 typedef struct _GdkCursor GdkCursor; | |
| 51 typedef struct _GtkWidget GtkWidget; | |
| 52 typedef struct _GtkWindow GtkWindow; | |
| 53 typedef struct _cairo cairo_t; | |
| 54 #endif | |
| 55 | |
| 56 namespace gfx { | |
| 57 | |
| 58 #if defined(OS_WIN) | |
| 59 typedef HWND NativeView; | |
| 60 typedef HWND NativeWindow; | |
| 61 typedef HWND NativeEditView; | |
| 62 typedef HDC NativeDrawingContext; | |
| 63 typedef HCURSOR NativeCursor; | |
| 64 typedef HMENU NativeMenu; | |
| 65 #elif defined(OS_MACOSX) | |
| 66 typedef NSView* NativeView; | |
| 67 typedef NSWindow* NativeWindow; | |
| 68 typedef NSTextField* NativeEditView; | |
| 69 typedef CGContext* NativeDrawingContext; | |
| 70 typedef void* NativeCursor; | |
| 71 typedef void* NativeMenu; | |
| 72 #elif defined(USE_X11) | |
| 73 typedef GtkWidget* NativeView; | |
| 74 typedef GtkWindow* NativeWindow; | |
| 75 typedef GtkWidget* NativeEditView; | |
| 76 typedef cairo_t* NativeDrawingContext; | |
| 77 typedef GdkCursor* NativeCursor; | |
| 78 typedef GtkWidget* NativeMenu; | |
| 79 #endif | |
| 80 | |
| 81 // Note: for test_shell we're packing a pointer into the NativeViewId. So, if | |
| 82 // you make it a type which is smaller than a pointer, you have to fix | |
| 83 // test_shell. | |
| 84 // | |
| 85 // See comment at the top of the file for usage. | |
| 86 typedef intptr_t NativeViewId; | |
| 87 | |
| 88 // Convert a NativeViewId to a NativeView. | |
| 89 // On Windows, these are both HWNDS so it's just a cast. | |
| 90 // On Mac, for now, we pass the NSView pointer into the renderer | |
| 91 // On Linux we use an opaque id | |
| 92 #if defined(OS_WIN) | |
| 93 static inline NativeView NativeViewFromId(NativeViewId id) { | |
| 94 return reinterpret_cast<NativeView>(id); | |
| 95 } | |
| 96 #elif defined(OS_MACOSX) | |
| 97 | |
| 98 // A recent CL removed the need for Mac to actually convert | |
| 99 // NativeViewId to NativeView. Until other platforms make changes, | |
| 100 // the platform-independent code cannot be removed. The following is | |
| 101 // to discourage new platform-independent uses. | |
| 102 | |
| 103 #define NativeViewFromId(x) NATIVE_VIEW_FROM_ID_NOT_AVAILABLE_ON_MAC | |
| 104 | |
| 105 #elif defined(USE_X11) | |
| 106 // A NativeView on Linux is a GtkWidget*. However, we can't go directly from an | |
| 107 // X window ID to a GtkWidget. Thus, functions which handle NativeViewIds from | |
| 108 // the renderer have to use Xlib. This is fine since these functions are | |
| 109 // generally performed on the BACKGROUND_X thread which can't use GTK anyway. | |
| 110 | |
| 111 #define NativeViewFromId(x) NATIVE_VIEW_FROM_ID_NOT_AVAILIBLE_ON_X11 | |
| 112 | |
| 113 #endif // defined(USE_X11) | |
| 114 | |
| 115 // Convert a NativeView to a NativeViewId. See the comments above | |
| 116 // NativeViewFromId. | |
| 117 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 118 static inline NativeViewId IdFromNativeView(NativeView view) { | |
| 119 return reinterpret_cast<NativeViewId>(view); | |
| 120 } | |
| 121 #elif defined(USE_X11) | |
| 122 // Not inlined because it involves pulling too many headers. | |
| 123 NativeViewId IdFromNativeView(NativeView view); | |
| 124 #endif // defined(USE_X11) | |
| 125 | |
| 126 | |
| 127 // PluginWindowHandle is an abstraction wrapping "the types of windows | |
| 128 // used by NPAPI plugins". On Windows it's an HWND, on X it's an X | |
| 129 // window id. | |
| 130 #if defined(OS_WIN) | |
| 131 typedef HWND PluginWindowHandle; | |
| 132 #elif defined(USE_X11) | |
| 133 typedef unsigned long PluginWindowHandle; | |
| 134 #else | |
| 135 // On OS X we don't have windowed plugins. | |
| 136 // We use a NULL/0 PluginWindowHandle in shared code to indicate there | |
| 137 // is no window present, so mirror that behavior here. | |
| 138 typedef bool PluginWindowHandle; | |
| 139 #endif | |
| 140 | |
| 141 } // namespace gfx | |
| 142 | |
| 143 #endif // BASE_GFX_NATIVE_WIDGET_TYPES_H_ | |
| OLD | NEW |