#ifndef UI_GFX_NATIVE_WIDGET_TYPES_H_
#define UI_GFX_NATIVE_WIDGET_TYPES_H_
#include <stdint.h>
#include "base/compiler_specific.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/gfx/gfx_export.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/scoped_java_ref.h"
#endif
#if BUILDFLAG(IS_APPLE)
#include "base/apple/owned_objc.h"
#endif
#if BUILDFLAG(IS_MAC)
#include <string>
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#endif
#if defined(USE_AURA)
namespace aura {
class Window;
}
namespace ui {
class Cursor;
class Event;
namespace mojom {
enum class CursorType;
}
}
#endif
#if BUILDFLAG(IS_WIN)
struct IAccessible;
#elif BUILDFLAG(IS_IOS)
#ifdef __OBJC__
@class UIImage;
#else
struct objc_object;
class UIImage;
#endif
#elif BUILDFLAG(IS_MAC)
#ifdef __OBJC__
@class NSImage;
@class NSView;
@class NSWindow;
#else
struct objc_object;
class NSImage;
class NSView;
class NSWindow;
#endif
#endif
#if BUILDFLAG(IS_ANDROID)
struct ANativeWindow;
namespace ui {
class WindowAndroid;
class ViewAndroid;
}
#endif
class SkBitmap;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
extern "C" {
struct _AtkObject;
AtkObject;
}
#endif
namespace gfx {
#if defined(USE_AURA)
NativeCursor;
NativeView;
NativeWindow;
NativeEvent;
#elif BUILDFLAG(IS_IOS)
using NativeCursor = void*;
using NativeView = base::apple::WeakUIView;
using NativeWindow = base::apple::WeakUIWindow;
using NativeEvent = base::apple::OwnedUIEvent;
#elif BUILDFLAG(IS_MAC)
using NativeCursor = base::apple::OwnedNSCursor;
using NativeEvent = base::apple::OwnedNSEvent;
class GFX_EXPORT NativeView {
public:
constexpr NativeView() = default;
constexpr NativeView(__unsafe_unretained NSView* ns_view)
: ns_view_(ns_view) {}
NSView* GetNativeNSView() const { return ns_view_; }
explicit operator bool() const { return ns_view_ != nullptr; }
bool operator==(const NativeView& other) const {
return ns_view_ == other.ns_view_;
}
bool operator!=(const NativeView& other) const {
return ns_view_ != other.ns_view_;
}
bool operator<(const NativeView& other) const {
return ns_view_ < other.ns_view_;
}
std::string ToString() const;
private:
#if HAS_FEATURE(objc_arc)
__unsafe_unretained NSView* ns_view_ = nullptr;
#else
RAW_PTR_EXCLUSION NSView* ns_view_ = nullptr;
#endif
};
class GFX_EXPORT NativeWindow {
public:
constexpr NativeWindow() = default;
constexpr NativeWindow(__unsafe_unretained NSWindow* ns_window)
: ns_window_(ns_window) {}
NSWindow* GetNativeNSWindow() const { return ns_window_; }
explicit operator bool() const { return ns_window_ != nullptr; }
bool operator==(const NativeWindow& other) const {
return ns_window_ == other.ns_window_;
}
bool operator!=(const NativeWindow& other) const {
return ns_window_ != other.ns_window_;
}
bool operator<(const NativeWindow& other) const {
return ns_window_ < other.ns_window_;
}
std::string ToString() const;
private:
#if defined(__has_feature) && __has_feature(objc_arc)
__unsafe_unretained NSWindow* ns_window_ = nullptr;
#else
RAW_PTR_EXCLUSION NSWindow* ns_window_ = nullptr;
#endif
};
#elif BUILDFLAG(IS_ANDROID)
using NativeCursor = void*;
using NativeView = ui::ViewAndroid*;
using NativeWindow = ui::WindowAndroid*;
using NativeEvent = base::android::ScopedJavaGlobalRef<jobject>;
#else
#error Unknown build environment.
#endif
#if BUILDFLAG(IS_WIN)
using NativeViewAccessible = IAccessible*;
#elif BUILDFLAG(IS_IOS)
#ifdef __OBJC__
using NativeViewAccessible = id;
#else
using NativeViewAccessible = struct objc_object*;
#endif
#elif BUILDFLAG(IS_MAC)
#ifdef __OBJC__
using NativeViewAccessible = id;
#else
using NativeViewAccessible = struct objc_object*;
#endif
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
NativeViewAccessible;
#else
using UnimplementedNativeViewAccessible =
struct _UnimplementedNativeViewAccessible;
using NativeViewAccessible = UnimplementedNativeViewAccessible*;
#endif
NativeViewId;
#if BUILDFLAG(IS_WIN)
using AcceleratedWidget = HWND;
constexpr AcceleratedWidget kNullAcceleratedWidget = nullptr;
#elif BUILDFLAG(IS_IOS)
using AcceleratedWidget = uint64_t;
constexpr AcceleratedWidget kNullAcceleratedWidget = 0;
#elif BUILDFLAG(IS_MAC)
using AcceleratedWidget = uint64_t;
constexpr AcceleratedWidget kNullAcceleratedWidget = 0;
#elif BUILDFLAG(IS_ANDROID)
using AcceleratedWidget = ANativeWindow*;
constexpr AcceleratedWidget kNullAcceleratedWidget = nullptr;
#elif BUILDFLAG(IS_OZONE)
AcceleratedWidget;
constexpr AcceleratedWidget kNullAcceleratedWidget = …;
#else
#error unknown platform
#endif
}
#endif