From 5d1ef38f9f6815807596d0606cf7ed06b7930aac Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 9 May 2022 12:04:12 +0200 Subject: Create a RWHV delegate in core This is adapting the Quick code for shared use with widgets, and allows us to use it from QWebEnginePage. Pick-to: 6.4 Fixes: QTBUG-96377 Change-Id: I3f09c1a949eff86d80fbe6c513dc66e3f9f2f611 Reviewed-by: Michal Klocek --- src/webenginequick/api/qquickwebengineview.cpp | 146 ++++++++++------------- src/webenginequick/api/qquickwebengineview_p.h | 5 - src/webenginequick/api/qquickwebengineview_p_p.h | 30 +---- 3 files changed, 70 insertions(+), 111 deletions(-) (limited to 'src/webenginequick/api') diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp index 7eb5a8677..24c059d39 100644 --- a/src/webenginequick/api/qquickwebengineview.cpp +++ b/src/webenginequick/api/qquickwebengineview.cpp @@ -59,7 +59,8 @@ #include "file_picker_controller.h" #include "find_text_helper.h" #include "javascript_dialog_controller.h" -#include "render_widget_host_view_qt_delegate_quick.h" +#include "qquickwebengine_accessible.h" +#include "render_widget_host_view_qt_delegate_item.h" #include "render_widget_host_view_qt_delegate_quickwindow.h" #include "touch_selection_menu_controller.h" #include "ui_delegates_manager.h" @@ -139,14 +140,61 @@ Q_STATIC_ASSERT(static_cast(QQuickWebEngineView::LoadSucceededStatus) == st QT_WARNING_POP #endif -#ifndef QT_NO_ACCESSIBILITY +class WebEngineQuickWidgetDelegate : public QtWebEngineCore::WidgetDelegate +{ +public: + WebEngineQuickWidgetDelegate(QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *item, QQuickWebEngineView *parent) + : m_contentItem(item) + , m_parentView(parent) + { + } + + ~WebEngineQuickWidgetDelegate() override + { + if (m_contentItem) + m_contentItem->setWidgetDelegate(nullptr); + } + + void InitAsPopup(const QRect &screenRect) override + { + Q_UNUSED(screenRect); + Q_UNREACHABLE(); + } + + void Bind(WebContentsAdapterClient *client) override + { + QQuickWebEngineViewPrivate::bindViewAndWidget( + static_cast(client)->q_func(), m_contentItem); + } + + void Unbind() override + { + QQuickWebEngineViewPrivate::bindViewAndWidget(nullptr, m_contentItem); + } + + void Destroy() override + { + delete this; + } + + bool ActiveFocusOnPress() override + { + return m_parentView->property("activeFocusOnPress").toBool() || m_parentView->hasActiveFocus(); + } + +private: + QPointer m_contentItem; // deleted by core + QPointer m_parentView; +}; + +#if QT_CONFIG(accessibility) static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *object) { if (QQuickWebEngineView *v = qobject_cast(object)) return new QQuickWebEngineViewAccessible(v); - return 0; + return nullptr; } -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) static QLatin1String defaultMimeType("text/html;charset=UTF-8"); @@ -174,9 +222,9 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() { memset(actions, 0, sizeof(actions)); -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QAccessible::installFactory(&webAccessibleFactory); -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) } QQuickWebEngineViewPrivate::~QQuickWebEngineViewPrivate() @@ -234,22 +282,26 @@ UIDelegatesManager *QQuickWebEngineViewPrivate::ui() RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client) { - return new RenderWidgetHostViewQtDelegateQuick(client, /*isPopup = */ false); + Q_Q(QQuickWebEngineView); + auto *item = new RenderWidgetHostViewQtDelegateItem(client, /*isPopup = */ false); + item->setWidgetDelegate(new WebEngineQuickWidgetDelegate(item, q)); + return item; } RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client) { Q_Q(QQuickWebEngineView); const bool hasWindowCapability = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MultipleWindows); - RenderWidgetHostViewQtDelegateQuick *quickDelegate = new RenderWidgetHostViewQtDelegateQuick(client, /*isPopup = */ true); + RenderWidgetHostViewQtDelegateItem *quickDelegate = new RenderWidgetHostViewQtDelegateItem(client, /*isPopup = */ true); if (hasWindowCapability) { RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(quickDelegate, q->window()); + quickDelegate->setWidgetDelegate(wrapperWindow); wrapperWindow->setVirtualParent(q); - quickDelegate->setParentItem(wrapperWindow->contentItem()); - return wrapperWindow; + return quickDelegate; } quickDelegate->setParentItem(q); + quickDelegate->setWidgetDelegate(new WebEngineQuickWidgetDelegate(quickDelegate, q)); quickDelegate->show(); return quickDelegate; } @@ -715,74 +767,6 @@ void QQuickWebEngineViewPrivate::visibleChanged(bool visible) Q_UNUSED(visible); } -#ifndef QT_NO_ACCESSIBILITY -QQuickWebEngineViewAccessible::QQuickWebEngineViewAccessible(QQuickWebEngineView *o) - : QAccessibleObject(o) -{} - -bool QQuickWebEngineViewAccessible::isValid() const -{ - if (!QAccessibleObject::isValid()) - return false; - - if (!engineView() || !engineView()->d_func()) - return false; - - return true; -} - -QAccessibleInterface *QQuickWebEngineViewAccessible::parent() const -{ - QQuickItem *parent = engineView()->parentItem(); - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(parent); - if (!iface) - return QAccessible::queryAccessibleInterface(engineView()->window()); - return iface; -} - -QAccessibleInterface *QQuickWebEngineViewAccessible::focusChild() const -{ - if (child(0) && child(0)->focusChild()) - return child(0)->focusChild(); - return const_cast(this); -} - -int QQuickWebEngineViewAccessible::childCount() const -{ - return child(0) ? 1 : 0; -} - -QAccessibleInterface *QQuickWebEngineViewAccessible::child(int index) const -{ - if (index == 0 && isValid()) - return engineView()->d_func()->adapter->browserAccessible(); - return nullptr; -} - -int QQuickWebEngineViewAccessible::indexOfChild(const QAccessibleInterface *c) const -{ - if (child(0) && c == child(0)) - return 0; - return -1; -} - -QString QQuickWebEngineViewAccessible::text(QAccessible::Text) const -{ - return QString(); -} - -QAccessible::Role QQuickWebEngineViewAccessible::role() const -{ - return QAccessible::Client; -} - -QAccessible::State QQuickWebEngineViewAccessible::state() const -{ - QAccessible::State s; - return s; -} -#endif // QT_NO_ACCESSIBILITY - class WebContentsAdapterOwner : public QObject { public: @@ -912,7 +896,7 @@ void QQuickWebEngineViewPrivate::setFullScreenMode(bool fullscreen) } void QQuickWebEngineViewPrivate::bindViewAndWidget(QQuickWebEngineView *view, - RenderWidgetHostViewQtDelegateQuick *widget) + RenderWidgetHostViewQtDelegateItem *widget) { auto oldWidget = view ? view->d_func()->widget : nullptr; auto oldView = widget ? widget->m_view : nullptr; @@ -940,8 +924,8 @@ void QQuickWebEngineViewPrivate::bindViewAndWidget(QQuickWebEngineView *view, view->d_func()->widgetChanged(oldWidget, widget); } -void QQuickWebEngineViewPrivate::widgetChanged(RenderWidgetHostViewQtDelegateQuick *oldWidget, - RenderWidgetHostViewQtDelegateQuick *newWidget) +void QQuickWebEngineViewPrivate::widgetChanged(QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *oldWidget, + QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *newWidget) { Q_Q(QQuickWebEngineView); diff --git a/src/webenginequick/api/qquickwebengineview_p.h b/src/webenginequick/api/qquickwebengineview_p.h index fb736085b..46b92b9c6 100644 --- a/src/webenginequick/api/qquickwebengineview_p.h +++ b/src/webenginequick/api/qquickwebengineview_p.h @@ -57,10 +57,6 @@ #include #include -namespace QtWebEngineCore { -class RenderWidgetHostViewQtDelegateQuick; -} - QT_BEGIN_NAMESPACE class QQmlWebChannel; @@ -589,7 +585,6 @@ private: Q_DECLARE_PRIVATE(QQuickWebEngineView) QScopedPointer d_ptr; - friend class QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick; friend class QQuickContextMenuBuilder; friend class FaviconImageResponse; friend class FaviconImageResponseRunnable; diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h index 2096f79c6..fe9f78322 100644 --- a/src/webenginequick/api/qquickwebengineview_p_p.h +++ b/src/webenginequick/api/qquickwebengineview_p_p.h @@ -66,7 +66,7 @@ #include namespace QtWebEngineCore { -class RenderWidgetHostViewQtDelegateQuick; +class RenderWidgetHostViewQtDelegateItem; class TouchSelectionMenuController; class UIDelegatesManager; class WebContentsAdapter; @@ -174,9 +174,9 @@ public: void ensureContentsAdapter(); void setFullScreenMode(bool); - static void bindViewAndWidget(QQuickWebEngineView *view, QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick *widget); - void widgetChanged(QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick *oldWidget, - QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick *newWidget); + static void bindViewAndWidget(QQuickWebEngineView *view, QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *widget); + void widgetChanged(QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *oldWidget, + QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *newWidget); QQuickWebEngineProfile *m_profile; QSharedPointer adapter; @@ -200,7 +200,7 @@ public: bool m_defaultAudioMuted; bool m_isBeingAdopted; mutable QQuickWebEngineAction *actions[QQuickWebEngineView::WebActionCount]; - QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick *widget = nullptr; + QtWebEngineCore::RenderWidgetHostViewQtDelegateItem *widget = nullptr; bool profileInitialized() const; QQuickWebEngineScriptCollection *getUserScripts(); @@ -216,26 +216,6 @@ private: QQmlComponent *m_touchHandleDelegate; }; -#ifndef QT_NO_ACCESSIBILITY -class QQuickWebEngineViewAccessible : public QAccessibleObject -{ -public: - QQuickWebEngineViewAccessible(QQuickWebEngineView *o); - bool isValid() const override; - QAccessibleInterface *parent() const override; - QAccessibleInterface *focusChild() const override; - int childCount() const override; - QAccessibleInterface *child(int index) const override; - int indexOfChild(const QAccessibleInterface*) const override; - QString text(QAccessible::Text) const override; - QAccessible::Role role() const override; - QAccessible::State state() const override; - -private: - QQuickWebEngineView *engineView() const { return static_cast(object()); } -}; -#endif // QT_NO_ACCESSIBILITY - class QQuickContextMenuBuilder : public QtWebEngineCore::RenderViewContextMenuQt { public: -- cgit v1.2.1