Skip to content

Truly independent web browser

UI/Qt: Move the content layer lookup into MacWindow

Andreas Kling8ea7c92a130c
diff --git a/UI/Qt/MacWindow.h b/UI/Qt/MacWindow.h
index 9bb19737424..13ace215081 100644
--- a/UI/Qt/MacWindow.h
+++ b/UI/Qt/MacWindow.h
@@ -33,6 +33,8 @@ void keep_appkit_window_visible_while_inactive(QWidget&);
void disable_appkit_window_animations(QWidget&);
void ensure_appkit_window_is_exposed(QWidget&);
void set_appkit_window_content_aspect_ratio(QWidget&, Gfx::IntSize);
+// The Core Animation layer that shows the widget's own surface, or null if the widget has no native window.
+void* appkit_content_layer(QWidget&);
void offset_appkit_window_controls(QWidget&, int x_offset, int y_offset);
// AppKit puts the window controls back in their default place when the window title changes; this moves them back
// to their offset right away, before the next frame is drawn.
diff --git a/UI/Qt/MacWindow.mm b/UI/Qt/MacWindow.mm
index 599501eedd9..33913bedf8e 100644
--- a/UI/Qt/MacWindow.mm
+++ b/UI/Qt/MacWindow.mm
@@ -23,6 +23,7 @@
#include <QWidget>
#include <QWindow>
#include <UI/Qt/WebContentView.h>
+#include <qpa/qplatformwindow_p.h>
#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
@@ -634,6 +635,13 @@ void show_appkit_dictionary_lookup(QWidget& widget, WebView::DictionaryLookup co
show_dictionary_lookup(view, lookup, widget_position_to_ns_point(widget, position));
}
+void* appkit_content_layer(QWidget& widget)
+{
+ auto* window_handle = widget.windowHandle();
+ auto* cocoa_window = window_handle ? window_handle->nativeInterface<QNativeInterface::Private::QCocoaWindow>() : nullptr;
+ return cocoa_window ? cocoa_window->contentLayer() : nullptr;
+}
+
void round_appkit_view_corners(QWidget& widget, qreal radius, QColor const& border_color)
{
auto* view = reinterpret_cast<NSView*>(widget.winId());
diff --git a/UI/Qt/WebContentViewMac.mm b/UI/Qt/WebContentViewMac.mm
index 7044205b689..9cb7a2dd4cc 100644
--- a/UI/Qt/WebContentViewMac.mm
+++ b/UI/Qt/WebContentViewMac.mm
@@ -7,11 +7,11 @@
#include <AK/ScopeGuard.h>
#include <LibGfx/SharedImageBuffer.h>
#include <UI/Qt/ChromeStyle.h>
+#include <UI/Qt/MacWindow.h>
#include <UI/Qt/WebContentView.h>
#include <QChildEvent>
#include <QWindow>
-#include <qpa/qplatformwindow_p.h>
#import <AppKit/AppKit.h>
#import <IOSurface/IOSurface.h>
@@ -26,15 +26,13 @@ static CALayer* as_layer(void* layer)
bool WebContentView::ensure_iosurface_layer_attached_to_native_view()
{
- auto* window_handle = windowHandle();
- auto* cocoa_window = window_handle ? window_handle->nativeInterface<QNativeInterface::Private::QCocoaWindow>() : nullptr;
- CALayer* content_layer = cocoa_window ? cocoa_window->contentLayer() : nil;
+ auto* content_layer = as_layer(appkit_content_layer(*this));
if (!content_layer)
return false;
// NB: Qt restores the native view's exposed state from the content layer's display callback after it is unhidden.
// Presenting our own sublayer may leave that layer clean, which keeps Qt from routing mouse events to the view.
- if (isVisible() && !window_handle->isExposed())
+ if (isVisible() && !windowHandle()->isExposed())
[content_layer setNeedsDisplay];
if (!m_iosurface_layer) {