2021-02-23 21:08:33 +01:00
|
|
|
// Copyright 2021 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/views/view_util.h"
|
|
|
|
|
2022-04-19 19:45:03 +02:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2021-02-23 21:08:33 +01:00
|
|
|
#include "include/internal/cef_types_mac.h"
|
2023-02-28 19:34:12 +01:00
|
|
|
#include "libcef/browser/views/native_widget_mac.h"
|
2021-02-23 21:08:33 +01:00
|
|
|
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
|
|
|
namespace view_util {
|
|
|
|
|
2023-04-14 18:58:21 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr char kNativeHostViewKey[] = "CefNativeHostViewKey";
|
|
|
|
|
2023-04-12 20:34:39 +02:00
|
|
|
// For Venura 13.3.1.
|
|
|
|
constexpr float kDefaultTitleBarHeight = 30;
|
|
|
|
|
2023-04-14 18:58:21 +02:00
|
|
|
} // namespace
|
|
|
|
|
2021-02-23 21:08:33 +01:00
|
|
|
gfx::NativeWindow GetNativeWindow(views::Widget* widget) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget) {
|
2021-02-23 21:08:33 +01:00
|
|
|
return widget->GetNativeWindow();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-02-23 21:08:33 +01:00
|
|
|
return gfx::NativeWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeView GetNativeView(views::Widget* widget) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget) {
|
2021-02-23 21:08:33 +01:00
|
|
|
return widget->GetNativeView();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-02-23 21:08:33 +01:00
|
|
|
return gfx::NativeView();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowHandle GetWindowHandle(views::Widget* widget) {
|
2022-04-19 19:45:03 +02:00
|
|
|
// |view| is a wrapper type from native_widget_types.h.
|
2021-02-23 21:08:33 +01:00
|
|
|
auto view = GetNativeView(widget);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view) {
|
2021-02-23 21:08:33 +01:00
|
|
|
return CAST_NSVIEW_TO_CEF_WINDOW_HANDLE(view.GetNativeNSView());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-02-23 21:08:33 +01:00
|
|
|
return kNullWindowHandle;
|
|
|
|
}
|
|
|
|
|
2022-04-19 19:45:03 +02:00
|
|
|
CefWindowHandle GetWindowHandle(gfx::NativeWindow window) {
|
|
|
|
// |window| is a wrapper type from native_widget_types.h.
|
|
|
|
if (window) {
|
|
|
|
NSWindow* nswindow = window.GetNativeNSWindow();
|
|
|
|
return CAST_NSVIEW_TO_CEF_WINDOW_HANDLE([nswindow contentView]);
|
|
|
|
}
|
|
|
|
return kNullWindowHandle;
|
|
|
|
}
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
views::NativeWidget* CreateNativeWidget(
|
|
|
|
views::internal::NativeWidgetDelegate* delegate,
|
2023-03-16 18:19:50 +01:00
|
|
|
CefRefPtr<CefWindow> window,
|
|
|
|
CefWindowDelegate* window_delegate) {
|
|
|
|
return new CefNativeWidgetMac(delegate, window, window_delegate);
|
2023-02-28 19:34:12 +01:00
|
|
|
}
|
2023-04-14 18:58:21 +02:00
|
|
|
|
|
|
|
void SetHostView(views::Widget* widget, views::View* host_view) {
|
|
|
|
widget->SetNativeWindowProperty(kNativeHostViewKey, host_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
views::View* GetHostView(views::Widget* widget) {
|
|
|
|
return static_cast<views::View*>(
|
|
|
|
widget->GetNativeWindowProperty(kNativeHostViewKey));
|
|
|
|
}
|
|
|
|
|
2023-04-12 20:34:39 +02:00
|
|
|
float GetNSWindowTitleBarHeight(views::Widget* widget) {
|
|
|
|
if (auto window = GetNativeWindow(widget)) {
|
|
|
|
NSWindow* nswindow = window.GetNativeNSWindow();
|
|
|
|
return nswindow.frame.size.height -
|
|
|
|
[nswindow contentRectForFrameRect:nswindow.frame].size.height;
|
|
|
|
}
|
|
|
|
return kDefaultTitleBarHeight;
|
|
|
|
}
|
|
|
|
|
2021-02-23 21:08:33 +01:00
|
|
|
} // namespace view_util
|