Flutter Engine
The Flutter Engine
native_widget_types.h
Go to the documentation of this file.
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 ACCESSIBILITY_GFX_NATIVE_WIDGET_TYPES_H_
6#define ACCESSIBILITY_GFX_NATIVE_WIDGET_TYPES_H_
7
8#include <cstdint>
9
11#include "gfx/gfx_export.h"
12
13#if defined(OS_ANDROID)
14#include "base/android/scoped_java_ref.h"
15#elif defined(OS_APPLE)
16#include <objc/objc.h>
17#elif defined(OS_WIN)
19#endif
20
21// This file provides cross platform typedefs for native widget types.
22// NativeWindow: this is a handle to a native, top-level window
23// NativeView: this is a handle to a native UI element. It may be the
24// same type as a NativeWindow on some platforms.
25// NativeViewId: Often, in our cross process model, we need to pass around a
26// reference to a "window". This reference will, say, be echoed back from a
27// renderer to the browser when it wishes to query its size. On Windows we
28// use an HWND for this.
29//
30// As a rule of thumb - if you're in the renderer, you should be dealing
31// with NativeViewIds. This should remind you that you shouldn't be doing
32// direct operations on platform widgets from the renderer process.
33//
34// If you're in the browser, you're probably dealing with NativeViews,
35// unless you're in the IPC layer, which will be translating between
36// NativeViewIds from the renderer and NativeViews.
37//
38// The name 'View' here meshes with OS X where the UI elements are called
39// 'views' and with our Chrome UI code where the elements are also called
40// 'views'.
41
42#if defined(USE_AURA)
43namespace aura {
44class Window;
45}
46namespace ui {
47class Cursor;
48class Event;
49namespace mojom {
50enum class CursorType;
51}
52} // namespace ui
53
54#endif // defined(USE_AURA)
55
56#if defined(OS_WIN)
57typedef struct HFONT__* HFONT;
58struct IAccessible;
59#elif defined(OS_IOS)
60struct CGContext;
61#ifdef __OBJC__
62@class UIEvent;
63@class UIFont;
64@class UIImage;
65@class UIView;
66@class UIWindow;
67@class UITextField;
68#else
69class UIEvent;
70class UIFont;
71class UIImage;
72class UIView;
73class UIWindow;
74class UITextField;
75#endif // __OBJC__
76#elif defined(OS_MAC)
77struct CGContext;
78#ifdef __OBJC__
79@class NSCursor;
80@class NSEvent;
81@class NSFont;
82@class NSImage;
83@class NSView;
84@class NSWindow;
85@class NSTextField;
86#else
87class NSCursor;
88class NSEvent;
89class NSFont;
90class NSImage;
91struct NSView;
92class NSWindow;
93class NSTextField;
94#endif // __OBJC__
95#endif
96
97#if defined(OS_ANDROID)
98struct ANativeWindow;
99namespace ui {
100class WindowAndroid;
101class ViewAndroid;
102} // namespace ui
103#endif
104class SkBitmap;
105
106#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
107extern "C" {
108struct _AtkObject;
109typedef struct _AtkObject AtkObject;
110}
111#endif
112
113namespace gfx {
114
115#if defined(USE_AURA)
116typedef ui::Cursor NativeCursor;
117typedef aura::Window* NativeView;
118typedef aura::Window* NativeWindow;
119typedef ui::Event* NativeEvent;
120constexpr NativeView kNullNativeView = nullptr;
121constexpr NativeWindow kNullNativeWindow = nullptr;
122#elif defined(OS_IOS)
123typedef void* NativeCursor;
124typedef UIView* NativeView;
125typedef UIWindow* NativeWindow;
126typedef UIEvent* NativeEvent;
127constexpr NativeView kNullNativeView = nullptr;
128constexpr NativeWindow kNullNativeWindow = nullptr;
129#elif defined(OS_MAC)
130typedef NSCursor* NativeCursor;
131typedef NSEvent* NativeEvent;
132// NativeViews and NativeWindows on macOS are not necessarily in the same
133// process as the NSViews and NSWindows that they represent. Require an
134// explicit function call (GetNativeNSView or GetNativeNSWindow) to retrieve
135// the underlying NSView or NSWindow.
136// https://crbug.com/893719
137class GFX_EXPORT NativeView {
138 public:
139 constexpr NativeView() {}
140 // TODO(ccameron): Make this constructor explicit.
141 constexpr NativeView(NSView* ns_view) : ns_view_(ns_view) {}
142
143 // This function name is verbose (that is, not just GetNSView) so that it
144 // is easily grep-able.
145 NSView* GetNativeNSView() const { return ns_view_; }
146
147 operator bool() const { return ns_view_ != 0; }
148 bool operator==(const NativeView& other) const {
149 return ns_view_ == other.ns_view_;
150 }
151 bool operator!=(const NativeView& other) const {
152 return ns_view_ != other.ns_view_;
153 }
154 bool operator<(const NativeView& other) const {
155 return ns_view_ < other.ns_view_;
156 }
157
158 private:
159 NSView* ns_view_ = nullptr;
160};
161class GFX_EXPORT NativeWindow {
162 public:
163 constexpr NativeWindow() {}
164 // TODO(ccameron): Make this constructor explicit.
165 constexpr NativeWindow(NSWindow* ns_window) : ns_window_(ns_window) {}
166
167 // This function name is verbose (that is, not just GetNSWindow) so that it
168 // is easily grep-able.
169 NSWindow* GetNativeNSWindow() const { return ns_window_; }
170
171 operator bool() const { return ns_window_ != 0; }
172 bool operator==(const NativeWindow& other) const {
173 return ns_window_ == other.ns_window_;
174 }
175 bool operator!=(const NativeWindow& other) const {
176 return ns_window_ != other.ns_window_;
177 }
178 bool operator<(const NativeWindow& other) const {
179 return ns_window_ < other.ns_window_;
180 }
181
182 private:
183 NSWindow* ns_window_ = nullptr;
184};
185const NativeView kNullNativeView = NativeView(nullptr);
186const NativeWindow kNullNativeWindow = NativeWindow(nullptr);
187#elif defined(OS_ANDROID)
188typedef void* NativeCursor;
189typedef ui::ViewAndroid* NativeView;
190typedef ui::WindowAndroid* NativeWindow;
191typedef base::android::ScopedJavaGlobalRef<jobject> NativeEvent;
192constexpr NativeView kNullNativeView = nullptr;
193constexpr NativeWindow kNullNativeWindow = nullptr;
194#elif defined(OS_LINUX)
195// TODO(chunhtai): Figures out what is the correct type for Linux
196// https://github.com/flutter/flutter/issues/74270
197typedef void* NativeCursor;
198#elif defined(OS_WIN)
199typedef void* NativeCursor;
200typedef void* NativeView;
201typedef void* NativeWindow;
202typedef void* NativeEvent;
203constexpr NativeView kNullNativeView = nullptr;
204constexpr NativeWindow kNullNativeWindow = nullptr;
205#else
206#error Unknown build environment.
207#endif
208
209#if defined(OS_WIN)
210typedef HFONT NativeFont;
211typedef IAccessible* NativeViewAccessible;
212#elif defined(OS_IOS)
213typedef UIFont* NativeFont;
214typedef id NativeViewAccessible;
215#elif defined(OS_MAC)
216typedef NSFont* NativeFont;
217typedef id NativeViewAccessible;
218#elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
219// Linux doesn't have a native font type.
220typedef AtkObject* NativeViewAccessible;
221#else
222// Android, Chrome OS, etc.
223typedef struct _UnimplementedNativeViewAccessible
226#endif
227
228// A constant value to indicate that gfx::NativeCursor refers to no cursor.
229#if defined(USE_AURA)
230const ui::mojom::CursorType kNullCursor =
231 static_cast<ui::mojom::CursorType>(-1);
232#else
233const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(nullptr);
234#endif
235
236// Note: for test_shell we're packing a pointer into the NativeViewId. So, if
237// you make it a type which is smaller than a pointer, you have to fix
238// test_shell.
239//
240// See comment at the top of the file for usage.
241typedef intptr_t NativeViewId;
242
243// AcceleratedWidget provides a surface to compositors to paint pixels.
244#if defined(OS_WIN)
245typedef HWND AcceleratedWidget;
246constexpr AcceleratedWidget kNullAcceleratedWidget = nullptr;
247#elif defined(OS_IOS)
248typedef UIView* AcceleratedWidget;
249constexpr AcceleratedWidget kNullAcceleratedWidget = 0;
250#elif defined(OS_MAC)
251typedef uint64_t AcceleratedWidget;
252constexpr AcceleratedWidget kNullAcceleratedWidget = 0;
253#elif defined(OS_ANDROID)
254typedef ANativeWindow* AcceleratedWidget;
255constexpr AcceleratedWidget kNullAcceleratedWidget = 0;
256#elif defined(USE_OZONE) || defined(USE_X11)
257typedef uint32_t AcceleratedWidget;
258constexpr AcceleratedWidget kNullAcceleratedWidget = 0;
259#elif defined(OS_LINUX)
260// TODO(chunhtai): Figure out what the correct type is for the Linux.
261// https://github.com/flutter/flutter/issues/74270
262typedef void* AcceleratedWidget;
263constexpr AcceleratedWidget kNullAcceleratedWidget = nullptr;
264#else
265#error unknown platform
266#endif
267
268} // namespace gfx
269
270#endif // ACCESSIBILITY_GFX_NATIVE_WIDGET_TYPES_H_
GrAATriangulator::Event Event
#define GFX_EXPORT
Definition: gfx_export.h:26
Definition: dart.idl:641
Definition: dart.idl:411
Definition: insets.cc:10
const gfx::NativeCursor kNullCursor
struct _UnimplementedNativeViewAccessible UnimplementedNativeViewAccessible
intptr_t NativeViewId
bool operator==(const Point &lhs, const Point &rhs)
Definition: point.h:96
UnimplementedNativeViewAccessible * NativeViewAccessible
bool operator!=(const Point &lhs, const Point &rhs)
Definition: point.h:100
constexpr bool operator<(const EnumType &lhs, const Mask< EnumType > &rhs)
Definition: mask.h:188
struct ANativeWindow ANativeWindow