summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp')
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
index eb3a3931a..27268d26b 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
@@ -138,6 +138,21 @@ RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(Rende
setAttribute(Qt::WA_AcceptTouchEvents);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_AlwaysShowToolTips);
+
+ if (parent) {
+ // Unset the popup parent if the parent is being destroyed, thus making sure a double
+ // delete does not happen.
+ // Also in case the delegate is destroyed before its parent (when a popup is simply
+ // dismissed), this connection will automatically be removed by ~QObject(), preventing
+ // a use-after-free.
+ connect(parent, &QObject::destroyed,
+ this, &RenderWidgetHostViewQtDelegateWidget::removeParentBeforeParentDelete);
+ }
+}
+
+void RenderWidgetHostViewQtDelegateWidget::removeParentBeforeParentDelete()
+{
+ setParent(Q_NULLPTR);
}
void RenderWidgetHostViewQtDelegateWidget::initAsChild(WebContentsAdapterClient* container)
@@ -164,7 +179,11 @@ void RenderWidgetHostViewQtDelegateWidget::initAsPopup(const QRect& screenRect)
// to be destroyed.
setAttribute(Qt::WA_ShowWithoutActivating);
setFocusPolicy(Qt::NoFocus);
- setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
+
+ // macOS doesn't like Qt::ToolTip when QWebEngineView is inside a modal dialog, specifically by
+ // not forwarding click events to the popup. So we use Qt::Tool which behaves the same way, but
+ // works on macOS too.
+ setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
setGeometry(screenRect);
show();
@@ -183,6 +202,13 @@ QRectF RenderWidgetHostViewQtDelegateWidget::contentsRect() const
void RenderWidgetHostViewQtDelegateWidget::setKeyboardFocus()
{
+ // If the corresponding window is inactive (for example, because of a popup),
+ // the active focus cannot be set. Sync up with the Window System to try to
+ // reactivate the window in time if the other window (possibly popup) which took
+ // the focus is already closed.
+ if (window() && !window()->isActive())
+ QGuiApplication::sync();
+
m_rootItem->forceActiveFocus();
}