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/webenginewidgets/CMakeLists.txt | 2 +- src/webenginewidgets/api/qwebengineview.cpp | 371 ++++++++++++-- src/webenginewidgets/api/qwebengineview_p.h | 30 +- src/webenginewidgets/qwebengine_accessible.cpp | 142 ++++++ src/webenginewidgets/qwebengine_accessible.h | 88 ++++ .../render_widget_host_view_qt_delegate_widget.cpp | 542 --------------------- .../render_widget_host_view_qt_delegate_widget.h | 138 ------ 7 files changed, 555 insertions(+), 758 deletions(-) create mode 100644 src/webenginewidgets/qwebengine_accessible.cpp create mode 100644 src/webenginewidgets/qwebengine_accessible.h delete mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp delete mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/CMakeLists.txt b/src/webenginewidgets/CMakeLists.txt index 6a25e7297..1aa4ae1e2 100644 --- a/src/webenginewidgets/CMakeLists.txt +++ b/src/webenginewidgets/CMakeLists.txt @@ -8,7 +8,7 @@ qt_internal_add_module(WebEngineWidgets api/qtwebenginewidgetsglobal.h api/qwebenginenotificationpresenter.cpp api/qwebenginenotificationpresenter_p.h api/qwebengineview.cpp api/qwebengineview.h api/qwebengineview_p.h - render_widget_host_view_qt_delegate_widget.cpp render_widget_host_view_qt_delegate_widget.h + qwebengine_accessible.cpp qwebengine_accessible.h DEFINES QT_BUILD_WEBENGINEWIDGETS_LIB INCLUDE_DIRECTORIES diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index 8016b2d57..b3bba7d9e 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -40,7 +40,9 @@ #include "qwebenginenotificationpresenter_p.h" #include "qwebengineview.h" #include "qwebengineview_p.h" -#include "render_widget_host_view_qt_delegate_widget.h" +#include "render_widget_host_view_qt_delegate_client.h" +#include "render_widget_host_view_qt_delegate_item.h" +#include "qwebengine_accessible.h" #include #include @@ -57,6 +59,7 @@ #include #include #include +#include #if QT_CONFIG(action) #include @@ -91,6 +94,286 @@ #include #endif +namespace QtWebEngineCore { +class WebEngineQuickWidget : public QQuickWidget, public WidgetDelegate +{ +public: + WebEngineQuickWidget(RenderWidgetHostViewQtDelegateItem *widget, QWidget *parent) + : QQuickWidget(parent) + , m_contentItem(widget) + { + setFocusPolicy(Qt::StrongFocus); + setMouseTracking(true); + setAttribute(Qt::WA_AcceptTouchEvents); + setAttribute(Qt::WA_OpaquePaintEvent); + setAttribute(Qt::WA_AlwaysShowToolTips); + + QQuickItem *root = new QQuickItem(); // Indirection so we don't delete m_contentItem + setContent(QUrl(), nullptr, root); + root->setFlags(QQuickItem::ItemHasContents); + root->setFocus(true); + root->setVisible(true); + m_contentItem->setParentItem(root); + + connectRemoveParentBeforeParentDelete(); + } + ~WebEngineQuickWidget() override + { + if (m_contentItem) { + m_contentItem->setWidgetDelegate(nullptr); + m_contentItem->setParentItem(nullptr); + } + } + + void InitAsPopup(const QRect &screenRect) override + { + setAttribute(Qt::WA_ShowWithoutActivating); + setFocusPolicy(Qt::NoFocus); + setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); + + setGeometry(screenRect); + raise(); + m_contentItem->show(); + show(); + } + + void Bind(WebContentsAdapterClient *client) override + { + if (m_pageDestroyedConnection) + QObject::disconnect(m_pageDestroyedConnection); + QWebEnginePage *page = static_cast(client)->q_func(); + QWebEngineViewPrivate::bindPageAndWidget(page, this); + m_pageDestroyedConnection = QObject::connect(page, &QWebEnginePage::_q_aboutToDelete, this, &WebEngineQuickWidget::Unbind); + } + + void Unbind() override + { + if (m_pageDestroyedConnection) + QObject::disconnect(m_pageDestroyedConnection); + QWebEngineViewPrivate::bindPageAndWidget(nullptr, this); + } + + void Destroy() override + { + deleteLater(); + } + + bool ActiveFocusOnPress() override + { + return true; + } + + void SetInputMethodEnabled(bool enabled) override + { + QQuickWidget::setAttribute(Qt::WA_InputMethodEnabled, enabled); + } + void SetInputMethodHints(Qt::InputMethodHints hints) override + { + QQuickWidget::setInputMethodHints(hints); + } + void SetClearColor(const QColor &color) override + { + QQuickWidget::setClearColor(color); + // QQuickWidget is usually blended by punching holes into widgets + // above it to simulate the visual stacking order. If we want it to be + // transparent we have to throw away the proper stacking order and always + // blend the complete normal widgets backing store under it. + bool isTranslucent = color.alpha() < 255; + setAttribute(Qt::WA_AlwaysStackOnTop, isTranslucent); + setAttribute(Qt::WA_OpaquePaintEvent, !isTranslucent); + update(); + } + void MoveWindow(const QPoint &screenPos) override + { + QQuickWidget::move(screenPos); + } + void Resize(int width, int height) override + { + QQuickWidget::resize(width, height); + } + QWindow *Window() override + { + if (const QWidget *root = QQuickWidget::window()) + return root->windowHandle(); + return nullptr; + } + +protected: + void closeEvent(QCloseEvent *event) override + { + QQuickWidget::closeEvent(event); + + // If a close event was received from the window manager (e.g. when moving the parent window, + // clicking outside the popup area) + // make sure to notify the Chromium WebUI popup and its underlying + // RenderWidgetHostViewQtDelegate instance to be closed. + if (m_contentItem && m_contentItem->m_isPopup) + m_contentItem->m_client->closePopup(); + } + void showEvent(QShowEvent *event) override + { + QQuickWidget::showEvent(event); + // We don't have a way to catch a top-level window change with QWidget + // but a widget will most likely be shown again if it changes, so do + // the reconnection at this point. + for (const QMetaObject::Connection &c : qAsConst(m_windowConnections)) + disconnect(c); + m_windowConnections.clear(); + if (QWindow *w = Window()) { + m_windowConnections.append(connect(w, SIGNAL(xChanged(int)), m_contentItem, SLOT(onWindowPosChanged()))); + m_windowConnections.append(connect(w, SIGNAL(yChanged(int)), m_contentItem, SLOT(onWindowPosChanged()))); + } + } + void resizeEvent(QResizeEvent *event) override + { + QQuickWidget::resizeEvent(event); + if (m_contentItem) { // FIXME: Not sure why we need to set m_contentItem size manually + m_contentItem->setSize(event->size()); + m_contentItem->onWindowPosChanged(); + } + } + QVariant inputMethodQuery(Qt::InputMethodQuery query) const override + { + if (m_contentItem) + return m_contentItem->inputMethodQuery(query); + return QVariant(); + } + bool event(QEvent *event) override; + + void connectRemoveParentBeforeParentDelete(); + void removeParentBeforeParentDelete(); + +private: + friend QWebEngineViewPrivate; + QPointer m_contentItem; // deleted by core + QMetaObject::Connection m_parentDestroyedConnection; + QMetaObject::Connection m_pageDestroyedConnection; + QList m_windowConnections; +}; + +void WebEngineQuickWidget::connectRemoveParentBeforeParentDelete() +{ + disconnect(m_parentDestroyedConnection); + + if (QWidget *parent = parentWidget()) { + m_parentDestroyedConnection = connect(parent, &QObject::destroyed, + this, + &WebEngineQuickWidget::removeParentBeforeParentDelete); + } else { + m_parentDestroyedConnection = QMetaObject::Connection(); + } +} + +void WebEngineQuickWidget::removeParentBeforeParentDelete() +{ + // Unset the parent, because parent is being destroyed, but the owner of this + // WebEngineQuickWidget is actually a RenderWidgetHostViewQt instance. + setParent(nullptr); + + // If this widget represents a popup window, make sure to close it, so that if the popup was the + // last visible top level window, the application event loop can quit if it deems it necessarry. + if (m_contentItem && m_contentItem->m_isPopup) + close(); +} + +bool WebEngineQuickWidget::event(QEvent *event) +{ + bool handled = false; + + // Track parent to make sure we don't get deleted. + if (event->type() == QEvent::ParentChange) + connectRemoveParentBeforeParentDelete(); + + if (!m_contentItem) + return QQuickWidget::event(event); + + // Mimic QWidget::event() by ignoring mouse, keyboard, touch and tablet events if the widget is + // disabled. + if (!isEnabled()) { + switch (event->type()) { + case QEvent::TabletPress: + case QEvent::TabletRelease: + case QEvent::TabletMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + case QEvent::MouseMove: + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + case QEvent::TouchCancel: + case QEvent::ContextMenu: + case QEvent::KeyPress: + case QEvent::KeyRelease: +#ifndef QT_NO_WHEELEVENT + case QEvent::Wheel: +#endif + return false; + default: + break; + } + } + + switch (event->type()) { + case QEvent::FocusIn: + case QEvent::FocusOut: + // We forward focus events later, once they have made it to the content item. + return QQuickWidget::event(event); + case QEvent::DragEnter: + case QEvent::DragLeave: + case QEvent::DragMove: + case QEvent::Drop: + case QEvent::HoverEnter: + case QEvent::HoverLeave: + case QEvent::HoverMove: + // Let the parent handle these events. + return false; + default: + break; + } + + switch (event->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + case QEvent::MouseMove: + // Don't forward mouse events synthesized by the system, which are caused by genuine touch + // events. Chromium would then process for e.g. a mouse click handler twice, once due to the + // system synthesized mouse event, and another time due to a touch-to-gesture-to-mouse + // transformation done by Chromium. + // Only allow them for popup type, since QWidgetWindow will ignore them for Qt::Popup flag, + // which is expected to get input through synthesized mouse events (either by system or Qt) + if (!m_contentItem->m_isPopup && + static_cast(event)->source() == Qt::MouseEventSynthesizedBySystem) { + Q_ASSERT(!windowFlags().testFlag(Qt::Popup)); + return true; + } + break; + default: + break; + } + + if (event->type() == QEvent::MouseButtonDblClick) { + // QWidget keeps the Qt4 behavior where the DblClick event would replace the Press event. + // QtQuick is different by sending both the Press and DblClick events for the second press + // where we can simply ignore the DblClick event. + QMouseEvent *dblClick = static_cast(event); + QMouseEvent press(QEvent::MouseButtonPress, dblClick->position(), dblClick->scenePosition(), + dblClick->globalPosition(), dblClick->button(), dblClick->buttons(), + dblClick->modifiers(), dblClick->source()); + press.setTimestamp(dblClick->timestamp()); + handled = m_contentItem->m_client->forwardEvent(&press); + } else + handled = m_contentItem->m_client->forwardEvent(event); + + if (!handled) + return QQuickWidget::event(event); + event->accept(); + return true; +} + +} // namespace QtWebEngineCore + QT_BEGIN_NAMESPACE void QWebEngineViewPrivate::pageChanged(QWebEnginePage *oldPage, QWebEnginePage *newPage) @@ -144,8 +427,8 @@ void QWebEngineViewPrivate::pageChanged(QWebEnginePage *oldPage, QWebEnginePage Q_EMIT q->selectionChanged(); } -void QWebEngineViewPrivate::widgetChanged(QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget *oldWidget, - QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget *newWidget) +void QWebEngineViewPrivate::widgetChanged(QtWebEngineCore::WebEngineQuickWidget *oldWidget, + QtWebEngineCore::WebEngineQuickWidget *newWidget) { Q_Q(QWebEngineView); @@ -162,8 +445,6 @@ void QWebEngineViewPrivate::widgetChanged(QtWebEngineCore::RenderWidgetHostViewQ if (newWidget) { Q_ASSERT(!QtWebEngineCore::closingDown()); #if QT_CONFIG(accessibility) - // An earlier QAccessible::queryAccessibleInterface() call may have already registered a default - // QAccessibleInterface for newWidget: remove it first to avoid assert in QAccessibleCache::insert(). QAccessible::deleteAccessibleInterface(QAccessible::uniqueId(QAccessible::queryAccessibleInterface(newWidget))); QAccessible::registerAccessibleInterface(new QtWebEngineCore::RenderWidgetHostViewQtDelegateWidgetAccessible(newWidget, q)); #endif @@ -403,20 +684,24 @@ void QWebEngineViewPrivate::bindPageAndView(QWebEnginePage *page, QWebEngineView // Then notify. - auto widget = page ? page->d_func()->widget : nullptr; - auto oldWidget = (oldPage && oldPage->d_func()) ? oldPage->d_func()->widget : nullptr; + auto widget = page ? static_cast(page->d_func()->widget) : nullptr; + auto oldWidget = (oldPage && oldPage->d_func()) ? static_cast(oldPage->d_func()->widget) : nullptr; + // New page/widget moving away from oldView if (page && oldView != view && oldView) { oldView->d_func()->pageChanged(page, nullptr); if (widget) oldView->d_func()->widgetChanged(widget, nullptr); } + // New page/widget moving into new view if (view && oldPage != page) { if (oldPage && oldPage->d_func()) view->d_func()->pageChanged(oldPage, page); else view->d_func()->pageChanged(nullptr, page); + if (!widget && page && page->d_func()->item) + widget = new QtWebEngineCore::WebEngineQuickWidget(page->d_func()->item, nullptr); if (oldWidget != widget) view->d_func()->widgetChanged(oldWidget, widget); } @@ -425,23 +710,27 @@ void QWebEngineViewPrivate::bindPageAndView(QWebEnginePage *page, QWebEngineView } void QWebEngineViewPrivate::bindPageAndWidget( - QWebEnginePage *page, QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget *widget) + QWebEnginePage *page, QtWebEngineCore::WebEngineQuickWidget *widget) { - auto oldPage = widget ? widget->m_page : nullptr; - auto oldWidget = page ? page->d_func()->widget : nullptr; + auto oldPage = (widget && widget->m_contentItem) ? widget->m_contentItem->m_page : nullptr; + auto oldWidget = page ? static_cast(page->d_func()->widget) : nullptr; // Change pointers first. if (widget && oldPage != page) { - if (oldPage && oldPage->d_func()) + if (oldPage && oldPage->d_func()) { oldPage->d_func()->widget = nullptr; - widget->m_page = page; + oldPage->d_func()->item = nullptr; + } + if (widget->m_contentItem) + widget->m_contentItem->m_page = page; } if (page && oldWidget != widget) { - if (oldWidget) - oldWidget->m_page = nullptr; + if (oldWidget && oldWidget->m_contentItem) + oldWidget->m_contentItem->m_page = nullptr; page->d_func()->widget = widget; + page->d_func()->item = widget->m_contentItem; } // Then notify. @@ -584,9 +873,22 @@ QRect QWebEngineViewPrivate::viewportRect() const QtWebEngineCore::RenderWidgetHostViewQtDelegate * QWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegate( QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) +{ + auto *item = new QtWebEngineCore::RenderWidgetHostViewQtDelegateItem(client, false); + auto *widget = new QtWebEngineCore::WebEngineQuickWidget(item, nullptr); + item->setWidgetDelegate(widget); + return item; +} + +QtWebEngineCore::RenderWidgetHostViewQtDelegate * +QWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegateForPopup( + QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) { Q_Q(QWebEngineView); - return new QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget(client, q); + auto *item = new QtWebEngineCore::RenderWidgetHostViewQtDelegateItem(client, true); + auto *widget = new QtWebEngineCore::WebEngineQuickWidget(item, q); + item->setWidgetDelegate(widget); + return item; } QWebEngineContextMenuRequest *QWebEngineViewPrivate::lastContextMenuRequest() const @@ -1115,45 +1417,6 @@ void QWebEngineView::print(QPrinter *printer) #endif } -#ifndef QT_NO_ACCESSIBILITY -bool QWebEngineViewAccessible::isValid() const -{ - if (!QAccessibleWidget::isValid()) - return false; - - if (!view() || !view()->d_func() || !view()->d_func()->page || !view()->d_func()->page->d_func()) - return false; - - return true; -} - -QAccessibleInterface *QWebEngineViewAccessible::focusChild() const -{ - if (child(0) && child(0)->focusChild()) - return child(0)->focusChild(); - return const_cast(this); -} - -int QWebEngineViewAccessible::childCount() const -{ - return child(0) ? 1 : 0; -} - -QAccessibleInterface *QWebEngineViewAccessible::child(int index) const -{ - if (index == 0 && isValid()) - return view()->page()->d_func()->adapter->browserAccessible(); - return nullptr; -} - -int QWebEngineViewAccessible::indexOfChild(const QAccessibleInterface *c) const -{ - if (child(0) && c == child(0)) - return 0; - return -1; -} -#endif // QT_NO_ACCESSIBILITY - #if QT_CONFIG(action) QContextMenuBuilder::QContextMenuBuilder(QWebEngineContextMenuRequest *request, QWebEngineView *view, QMenu *menu) diff --git a/src/webenginewidgets/api/qwebengineview_p.h b/src/webenginewidgets/api/qwebengineview_p.h index b5d38a6c1..e3c9468ce 100644 --- a/src/webenginewidgets/api/qwebengineview_p.h +++ b/src/webenginewidgets/api/qwebengineview_p.h @@ -52,14 +52,14 @@ // #include // PageView -#include #include "render_view_context_menu_qt.h" namespace QtWebEngineCore { class QWebEngineContextMenuRequest; -class RenderWidgetHostViewQtDelegateWidget; +class WebEngineQuickWidget; class RenderWidgetHostViewQtDelegate; +class RenderWidgetHostViewQtDelegateClient; } QT_BEGIN_NAMESPACE @@ -75,8 +75,8 @@ public: QWebEngineView *q_ptr; void pageChanged(QWebEnginePage *oldPage, QWebEnginePage *newPage); - void widgetChanged(QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget *oldWidget, - QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget *newWidget); + void widgetChanged(QtWebEngineCore::WebEngineQuickWidget *oldWidget, + QtWebEngineCore::WebEngineQuickWidget *newWidget); void contextMenuRequested(QWebEngineContextMenuRequest *request) override; QStringList chooseFiles(QWebEnginePage::FileSelectionMode mode, const QStringList &oldFiles, @@ -91,6 +91,8 @@ public: void setToolTip(const QString &toolTipText) override; QtWebEngineCore::RenderWidgetHostViewQtDelegate *CreateRenderWidgetHostViewQtDelegate( QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) override; + QtWebEngineCore::RenderWidgetHostViewQtDelegate *CreateRenderWidgetHostViewQtDelegateForPopup( + QtWebEngineCore::RenderWidgetHostViewQtDelegateClient *client) override; QWebEngineContextMenuRequest *lastContextMenuRequest() const override; QWebEnginePage *createPageForWindow(QWebEnginePage::WebWindowType type) override; QObject *accessibilityParentObject() override; @@ -102,7 +104,7 @@ public: virtual ~QWebEngineViewPrivate(); static void bindPageAndView(QWebEnginePage *page, QWebEngineView *view); static void bindPageAndWidget(QWebEnginePage *page, - QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget *widget); + QtWebEngineCore::WebEngineQuickWidget *widget); QIcon webActionIcon(QWebEnginePage::WebAction action); void unhandledKeyEvent(QKeyEvent *event) override; void focusContainer() override; @@ -117,24 +119,6 @@ public: QWebEngineContextMenuRequest *m_contextRequest; }; -#ifndef QT_NO_ACCESSIBILITY -class QWebEngineViewAccessible : public QAccessibleWidget -{ -public: - QWebEngineViewAccessible(QWebEngineView *o) : QAccessibleWidget(o) - {} - - bool isValid() const override; - QAccessibleInterface *focusChild() const override; - int childCount() const override; - QAccessibleInterface *child(int index) const override; - int indexOfChild(const QAccessibleInterface *child) const override; - -private: - QWebEngineView *view() const { return static_cast(object()); } -}; -#endif // QT_NO_ACCESSIBILITY - class QContextMenuBuilder : public QtWebEngineCore::RenderViewContextMenuQt { public: diff --git a/src/webenginewidgets/qwebengine_accessible.cpp b/src/webenginewidgets/qwebengine_accessible.cpp new file mode 100644 index 000000000..a1b4bc889 --- /dev/null +++ b/src/webenginewidgets/qwebengine_accessible.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengine_accessible.h" + +#include "qwebengineview.h" +#include "qwebengineview_p.h" + +#include "web_contents_adapter.h" + +#if QT_CONFIG(accessibility) + +QT_BEGIN_NAMESPACE + +QWebEngineViewAccessible::QWebEngineViewAccessible(QWebEngineView *o) : QAccessibleWidget(o) +{ +} + +bool QWebEngineViewAccessible::isValid() const +{ + if (!QAccessibleWidget::isValid()) + return false; + + if (!view() || !view()->d_func() || !view()->d_func()->page || !view()->d_func()->page->d_func()) + return false; + + return true; +} + +QAccessibleInterface *QWebEngineViewAccessible::focusChild() const +{ + if (child(0) && child(0)->focusChild()) + return child(0)->focusChild(); + return const_cast(this); +} + +int QWebEngineViewAccessible::childCount() const +{ + return child(0) ? 1 : 0; +} + +QAccessibleInterface *QWebEngineViewAccessible::child(int index) const +{ + if (index == 0 && isValid()) + return view()->page()->d_func()->adapter->browserAccessible(); + return nullptr; +} + +int QWebEngineViewAccessible::indexOfChild(const QAccessibleInterface *c) const +{ + if (child(0) && c == child(0)) + return 0; + return -1; +} + +QWebEngineView *QWebEngineViewAccessible::view() const +{ + return static_cast(object()); +} + +QT_END_NAMESPACE + +namespace QtWebEngineCore { + +RenderWidgetHostViewQtDelegateWidgetAccessible::RenderWidgetHostViewQtDelegateWidgetAccessible(QWidget *o, QWebEngineView *view) + : QAccessibleWidget(o) + , m_view(view) +{ +} + +bool RenderWidgetHostViewQtDelegateWidgetAccessible::isValid() const +{ + if (!viewAccessible() || !viewAccessible()->isValid()) + return false; + + return QAccessibleWidget::isValid(); +} + +QAccessibleInterface *RenderWidgetHostViewQtDelegateWidgetAccessible::focusChild() const +{ + return viewAccessible()->focusChild(); +} + +int RenderWidgetHostViewQtDelegateWidgetAccessible::childCount() const +{ + return viewAccessible()->childCount(); +} + +QAccessibleInterface *RenderWidgetHostViewQtDelegateWidgetAccessible::child(int index) const +{ + return viewAccessible()->child(index); +} + +int RenderWidgetHostViewQtDelegateWidgetAccessible::indexOfChild(const QAccessibleInterface *c) const +{ + return viewAccessible()->indexOfChild(c); +} + +QWebEngineViewAccessible *RenderWidgetHostViewQtDelegateWidgetAccessible::viewAccessible() const +{ + return static_cast(QAccessible::queryAccessibleInterface(m_view)); +} + +} // namespace QtWebEngineCore + +#endif // QT_CONFIG(accessibility) diff --git a/src/webenginewidgets/qwebengine_accessible.h b/src/webenginewidgets/qwebengine_accessible.h new file mode 100644 index 000000000..d0781635d --- /dev/null +++ b/src/webenginewidgets/qwebengine_accessible.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINE_ACCESSIBLE_H +#define QWEBENGINE_ACCESSIBLE_H + +#include +#include + +#if QT_CONFIG(accessibility) + +QT_BEGIN_NAMESPACE +class QWebEngineView; + +class QWebEngineViewAccessible : public QAccessibleWidget +{ +public: + QWebEngineViewAccessible(QWebEngineView *o); + + bool isValid() const override; + QAccessibleInterface *focusChild() const override; + int childCount() const override; + QAccessibleInterface *child(int index) const override; + int indexOfChild(const QAccessibleInterface *child) const override; + +private: + QWebEngineView *view() const; +}; + +QT_END_NAMESPACE + +namespace QtWebEngineCore { + +class RenderWidgetHostViewQtDelegateWidgetAccessible : public QAccessibleWidget +{ +public: + RenderWidgetHostViewQtDelegateWidgetAccessible(QWidget *o, QWebEngineView *view); + + bool isValid() const override; + QAccessibleInterface *focusChild() const override; + int childCount() const override; + QAccessibleInterface *child(int index) const override; + int indexOfChild(const QAccessibleInterface *child) const override; + +private: + QWebEngineViewAccessible *viewAccessible() const; + QPointer m_view; +}; +} // namespace QtWebEngineCore +#endif // QT_CONFIG(accessibility) + +#endif // QWEBENGINE_ACCESSIBLE_H diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp deleted file mode 100644 index 1dd19fd67..000000000 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp +++ /dev/null @@ -1,542 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "render_widget_host_view_qt_delegate_widget.h" - -#include "render_widget_host_view_qt_delegate_client.h" - -#include -#include "qwebengineview.h" -#include "qwebengineview_p.h" - -#include -#include -#include -#include -#include - -namespace QtWebEngineCore { - -class RenderWidgetHostViewQuickItem : public QQuickItem, public Compositor::Observer -{ -public: - RenderWidgetHostViewQuickItem(RenderWidgetHostViewQtDelegateClient *client) : m_client(client) - { - setFlag(ItemHasContents, true); - // Mark that this item should receive focus when the parent QQuickWidget receives focus. - setFocus(true); - - bind(client->compositorId()); - } - -protected: - bool event(QEvent *event) override - { - if (event->type() == QEvent::ShortcutOverride) - return m_client->forwardEvent(event); - - return QQuickItem::event(event); - } - void focusInEvent(QFocusEvent *event) override - { - m_client->forwardEvent(event); - } - void focusOutEvent(QFocusEvent *event) override - { - m_client->forwardEvent(event); - } - void inputMethodEvent(QInputMethodEvent *event) override - { - m_client->forwardEvent(event); - } - void itemChange(ItemChange change, const ItemChangeData &value) override - { - QQuickItem::itemChange(change, value); - if (change == QQuickItem::ItemSceneChange) { - for (const QMetaObject::Connection &c : qAsConst(m_windowConnections)) - disconnect(c); - m_windowConnections.clear(); - if (value.window) { - m_windowConnections.append(connect( - value.window, &QQuickWindow::beforeRendering, this, - &RenderWidgetHostViewQuickItem::onBeforeRendering, Qt::DirectConnection)); - } - } - } - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override - { - auto comp = compositor(); - if (!comp) - return nullptr; - - QQuickWindow *win = QQuickItem::window(); - - // Delete old node before swapFrame to decrement refcount of - // QImage in software mode. - delete oldNode; - QSGImageNode *node = win->createImageNode(); - node->setOwnsTexture(true); - - comp->swapFrame(); - - QSize texSize = comp->size(); - QSizeF texSizeInDips = QSizeF(texSize) / comp->devicePixelRatio(); - node->setRect(QRectF(QPointF(0, 0), texSizeInDips)); - - if (comp->type() == Compositor::Type::Software) { - QImage image = comp->image(); - node->setTexture(win->createTextureFromImage(image)); - } else if (comp->type() == Compositor::Type::OpenGL) { -#if QT_CONFIG(opengl) - QQuickWindow::CreateTextureOptions texOpts; - if (comp->hasAlphaChannel()) - texOpts.setFlag(QQuickWindow::TextureHasAlphaChannel); - int texId = comp->textureId(); - node->setTexture(QNativeInterface::QSGOpenGLTexture::fromNative(texId, win, texSize, texOpts)); - node->setTextureCoordinatesTransform(QSGImageNode::MirrorVertically); -#else - Q_UNREACHABLE(); - -#endif - } else { - Q_UNREACHABLE(); - } - - return node; - } - void onBeforeRendering() - { - auto comp = compositor(); - if (!comp || comp->type() != Compositor::Type::OpenGL) - return; - comp->waitForTexture(); - } - QVariant inputMethodQuery(Qt::InputMethodQuery query) const override - { - return m_client->inputMethodQuery(query); - } - void readyToSwap() override - { - // Call update() on UI thread. - QMetaObject::invokeMethod(this, &QQuickItem::update, Qt::QueuedConnection); - } - -private: - RenderWidgetHostViewQtDelegateClient *m_client; - QList m_windowConnections; -}; - -RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent) - : QQuickWidget(parent) - , m_client(client) - , m_rootItem(new RenderWidgetHostViewQuickItem(client)) - , m_isPopup(false) -{ - setFocusPolicy(Qt::StrongFocus); - setMouseTracking(true); - setAttribute(Qt::WA_AcceptTouchEvents); - setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_AlwaysShowToolTips); - - setContent(QUrl(), nullptr, m_rootItem.data()); - - connectRemoveParentBeforeParentDelete(); -} - -RenderWidgetHostViewQtDelegateWidget::~RenderWidgetHostViewQtDelegateWidget() -{ - QWebEngineViewPrivate::bindPageAndWidget(nullptr, this); -} - -void RenderWidgetHostViewQtDelegateWidget::connectRemoveParentBeforeParentDelete() -{ - disconnect(m_parentDestroyedConnection); - - if (QWidget *parent = parentWidget()) { - m_parentDestroyedConnection = connect(parent, &QObject::destroyed, - this, - &RenderWidgetHostViewQtDelegateWidget::removeParentBeforeParentDelete); - } else { - m_parentDestroyedConnection = QMetaObject::Connection(); - } -} - -void RenderWidgetHostViewQtDelegateWidget::removeParentBeforeParentDelete() -{ - // Unset the parent, because parent is being destroyed, but the owner of this - // RenderWidgetHostViewQtDelegateWidget is actually a RenderWidgetHostViewQt instance. - setParent(nullptr); - - // If this widget represents a popup window, make sure to close it, so that if the popup was the - // last visible top level window, the application event loop can quit if it deems it necessarry. - if (m_isPopup) - close(); -} - -void RenderWidgetHostViewQtDelegateWidget::initAsPopup(const QRect& screenRect) -{ - m_isPopup = true; - - // The keyboard events are supposed to go to the parent RenderHostView - // so the WebUI popups should never have focus. Besides, if the parent view - // loses focus, WebKit will cause its associated popups (including this one) - // to be destroyed. - setAttribute(Qt::WA_ShowWithoutActivating); - setFocusPolicy(Qt::NoFocus); - setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); - - setGeometry(screenRect); - show(); -} - -void RenderWidgetHostViewQtDelegateWidget::closeEvent(QCloseEvent *event) -{ - Q_UNUSED(event); - - // If a close event was received from the window manager (e.g. when moving the parent window, - // clicking outside the popup area) - // make sure to notify the Chromium WebUI popup and its underlying - // RenderWidgetHostViewQtDelegate instance to be closed. - if (m_isPopup) - m_client->closePopup(); -} - -QRectF RenderWidgetHostViewQtDelegateWidget::viewGeometry() const -{ - return QRectF(mapToGlobal(pos()), size()); -} - -QRect RenderWidgetHostViewQtDelegateWidget::windowGeometry() const -{ - if (!window()) - return QRect(); - return window()->frameGeometry(); -} - -void RenderWidgetHostViewQtDelegateWidget::setKeyboardFocus() -{ - // The root item always has focus within the root focus scope: - Q_ASSERT(m_rootItem->hasFocus()); - - setFocus(); -} - -bool RenderWidgetHostViewQtDelegateWidget::hasKeyboardFocus() -{ - // The root item always has focus within the root focus scope: - Q_ASSERT(m_rootItem->hasFocus()); - - return hasFocus(); -} - -void RenderWidgetHostViewQtDelegateWidget::lockMouse() -{ - grabMouse(); -} - -void RenderWidgetHostViewQtDelegateWidget::unlockMouse() -{ - releaseMouse(); -} - -void RenderWidgetHostViewQtDelegateWidget::show() -{ - m_rootItem->setVisible(true); - // Check if we're attached to a QWebEngineView, we don't - // want to show anything else than popups as top-level. - if (parent() || m_isPopup) { - QQuickWidget::show(); - } -} - -void RenderWidgetHostViewQtDelegateWidget::hide() -{ - m_rootItem->setVisible(false); - QQuickWidget::hide(); -} - -bool RenderWidgetHostViewQtDelegateWidget::isVisible() const -{ - return QQuickWidget::isVisible() && m_rootItem->isVisible(); -} - -QWindow* RenderWidgetHostViewQtDelegateWidget::window() const -{ - const QWidget* root = QQuickWidget::window(); - return root ? root->windowHandle() : 0; -} - -void RenderWidgetHostViewQtDelegateWidget::updateCursor(const QCursor &cursor) -{ - QQuickWidget::setCursor(cursor); -} - -void RenderWidgetHostViewQtDelegateWidget::resize(int width, int height) -{ - QQuickWidget::resize(width, height); -} - -void RenderWidgetHostViewQtDelegateWidget::move(const QPoint &screenPos) -{ - Q_ASSERT(m_isPopup); - QQuickWidget::move(screenPos); -} - -void RenderWidgetHostViewQtDelegateWidget::inputMethodStateChanged(bool editorVisible, bool passwordInput) -{ - QQuickWidget::setAttribute(Qt::WA_InputMethodEnabled, editorVisible && !passwordInput); - qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); - if (qApp->inputMethod()->isVisible() != editorVisible) - qApp->inputMethod()->setVisible(editorVisible); -} - -void RenderWidgetHostViewQtDelegateWidget::setInputMethodHints(Qt::InputMethodHints hints) -{ - QQuickWidget::setInputMethodHints(hints); -} - -void RenderWidgetHostViewQtDelegateWidget::setClearColor(const QColor &color) -{ - QQuickWidget::setClearColor(color); - // QQuickWidget is usually blended by punching holes into widgets - // above it to simulate the visual stacking order. If we want it to be - // transparent we have to throw away the proper stacking order and always - // blend the complete normal widgets backing store under it. - bool isTranslucent = color.alpha() < 255; - setAttribute(Qt::WA_AlwaysStackOnTop, isTranslucent); - setAttribute(Qt::WA_OpaquePaintEvent, !isTranslucent); - update(); -} - -QVariant RenderWidgetHostViewQtDelegateWidget::inputMethodQuery(Qt::InputMethodQuery query) const -{ - return m_client->inputMethodQuery(query); -} - -void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent) -{ - QQuickWidget::resizeEvent(resizeEvent); - m_client->visualPropertiesChanged(); -} - -void RenderWidgetHostViewQtDelegateWidget::showEvent(QShowEvent *event) -{ - QQuickWidget::showEvent(event); - // We don't have a way to catch a top-level window change with QWidget - // but a widget will most likely be shown again if it changes, so do - // the reconnection at this point. - for (const QMetaObject::Connection &c : qAsConst(m_windowConnections)) - disconnect(c); - m_windowConnections.clear(); - if (QWindow *w = window()) { - m_windowConnections.append(connect(w, SIGNAL(xChanged(int)), SLOT(onWindowPosChanged()))); - m_windowConnections.append(connect(w, SIGNAL(yChanged(int)), SLOT(onWindowPosChanged()))); - } - m_client->visualPropertiesChanged(); - m_client->notifyShown(); -} - -void RenderWidgetHostViewQtDelegateWidget::hideEvent(QHideEvent *event) -{ - QQuickWidget::hideEvent(event); - m_client->notifyHidden(); -} - -bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event) -{ - bool handled = false; - - // Track parent to make sure we don't get deleted. - switch (event->type()) { - case QEvent::ParentChange: - connectRemoveParentBeforeParentDelete(); - break; - default: - break; - } - - // Mimic QWidget::event() by ignoring mouse, keyboard, touch and tablet events if the widget is - // disabled. - if (!isEnabled()) { - switch (event->type()) { - case QEvent::TabletPress: - case QEvent::TabletRelease: - case QEvent::TabletMove: - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - case QEvent::MouseMove: - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - case QEvent::TouchCancel: - case QEvent::ContextMenu: - case QEvent::KeyPress: - case QEvent::KeyRelease: -#ifndef QT_NO_WHEELEVENT - case QEvent::Wheel: -#endif - return false; - default: - break; - } - } - - switch (event->type()) { - case QEvent::FocusIn: - case QEvent::FocusOut: - // We forward focus events later, once they have made it to the m_rootItem. - return QQuickWidget::event(event); - case QEvent::DragEnter: - case QEvent::DragLeave: - case QEvent::DragMove: - case QEvent::Drop: - case QEvent::HoverEnter: - case QEvent::HoverLeave: - case QEvent::HoverMove: - // Let the parent handle these events. - return false; - default: - break; - } - - switch (event->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - case QEvent::MouseMove: - // Don't forward mouse events synthesized by the system, which are caused by genuine touch - // events. Chromium would then process for e.g. a mouse click handler twice, once due to the - // system synthesized mouse event, and another time due to a touch-to-gesture-to-mouse - // transformation done by Chromium. - // Only allow them for popup type, since QWidgetWindow will ignore them for Qt::Popup flag, - // which is expected to get input through synthesized mouse events (either by system or Qt) - if (!m_isPopup && static_cast(event)->source() == Qt::MouseEventSynthesizedBySystem) { - Q_ASSERT(!windowFlags().testFlag(Qt::Popup)); - return true; - } - break; - default: - break; - } - - if (event->type() == QEvent::MouseButtonDblClick) { - // QWidget keeps the Qt4 behavior where the DblClick event would replace the Press event. - // QtQuick is different by sending both the Press and DblClick events for the second press - // where we can simply ignore the DblClick event. - QMouseEvent *dblClick = static_cast(event); - QMouseEvent press(QEvent::MouseButtonPress, dblClick->position(), dblClick->scenePosition(), - dblClick->globalPosition(), dblClick->button(), dblClick->buttons(), - dblClick->modifiers(), dblClick->source()); - press.setTimestamp(dblClick->timestamp()); - handled = m_client->forwardEvent(&press); - } else - handled = m_client->forwardEvent(event); - - if (!handled) - return QQuickWidget::event(event); - event->accept(); - return true; -} - -void RenderWidgetHostViewQtDelegateWidget::unhandledWheelEvent(QWheelEvent *ev) -{ - if (QWidget *p = parentWidget()) - qApp->sendEvent(p, ev); -} - -void RenderWidgetHostViewQtDelegateWidget::onWindowPosChanged() -{ - m_client->visualPropertiesChanged(); -} - -void RenderWidgetHostViewQtDelegateWidget::adapterClientChanged(WebContentsAdapterClient *client) -{ - if (m_pageDestroyedConnection) - disconnect(m_pageDestroyedConnection); - QWebEnginePage *page = static_cast(client)->q_func(); - QWebEngineViewPrivate::bindPageAndWidget(page, this); - m_pageDestroyedConnection = connect(page, &QWebEnginePage::_q_aboutToDelete, this, - [this]() { QWebEngineViewPrivate::bindPageAndWidget(nullptr, this); }); -} - -#if QT_CONFIG(accessibility) -RenderWidgetHostViewQtDelegateWidgetAccessible::RenderWidgetHostViewQtDelegateWidgetAccessible(RenderWidgetHostViewQtDelegateWidget *o, QWebEngineView *view) - : QAccessibleWidget(o) - , m_view(view) -{ -} - -bool RenderWidgetHostViewQtDelegateWidgetAccessible::isValid() const -{ - if (!viewAccessible() || !viewAccessible()->isValid()) - return false; - - return QAccessibleWidget::isValid(); -} - -QAccessibleInterface *RenderWidgetHostViewQtDelegateWidgetAccessible::focusChild() const -{ - return viewAccessible()->focusChild(); -} - -int RenderWidgetHostViewQtDelegateWidgetAccessible::childCount() const -{ - return viewAccessible()->childCount(); -} - -QAccessibleInterface *RenderWidgetHostViewQtDelegateWidgetAccessible::child(int index) const -{ - return viewAccessible()->child(index); -} - -int RenderWidgetHostViewQtDelegateWidgetAccessible::indexOfChild(const QAccessibleInterface *c) const -{ - return viewAccessible()->indexOfChild(c); -} - -QWebEngineViewAccessible *RenderWidgetHostViewQtDelegateWidgetAccessible::viewAccessible() const -{ - return static_cast(QAccessible::queryAccessibleInterface(m_view)); -} -#endif // QT_CONFIG(accessibility) - -} // namespace QtWebEngineCore - -#include "moc_render_widget_host_view_qt_delegate_widget.cpp" diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h deleted file mode 100644 index 1adebd3b5..000000000 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WIDGET_H -#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WIDGET_H - -#include "render_widget_host_view_qt_delegate.h" -#include "web_contents_adapter_client.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QWebEnginePage; -class QWebEngineView; -class QWebEngineViewAccessible; -class QWebEngineViewPrivate; -QT_END_NAMESPACE - -namespace QtWebEngineCore { - -// Useful information keyboard and mouse QEvent propagation. -// A RenderWidgetHostViewQtDelegateWidget instance initialized as a popup will receive -// no keyboard focus (so all keyboard QEvents will be sent to the parent RWHVQD instance), -// but will still receive mouse input (all mouse QEvent moves and clicks will be given to the popup -// RWHVQD instance, and the mouse interaction area covers the surface of the whole parent -// QWebEngineView, and not only the smaller surface that an HTML select popup would occupy). -class RenderWidgetHostViewQtDelegateWidget : public QQuickWidget, public RenderWidgetHostViewQtDelegate { - Q_OBJECT -public: - RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent = nullptr); - ~RenderWidgetHostViewQtDelegateWidget(); - - void initAsPopup(const QRect&) override; - QRectF viewGeometry() const override; - QRect windowGeometry() const override; - void setKeyboardFocus() override; - bool hasKeyboardFocus() override; - void lockMouse() override; - void unlockMouse() override; - void show() override; - void hide() override; - bool isVisible() const override; - QWindow* window() const override; - void updateCursor(const QCursor &) override; - void resize(int width, int height) override; - void move(const QPoint &screenPos) override; - void inputMethodStateChanged(bool editorVisible, bool passwordInput) override; - void setInputMethodHints(Qt::InputMethodHints) override; - void setClearColor(const QColor &color) override; - void unhandledWheelEvent(QWheelEvent *ev) override; - -protected: - bool event(QEvent *event) override; - void resizeEvent(QResizeEvent *resizeEvent) override; - void showEvent(QShowEvent *) override; - void hideEvent(QHideEvent *) override; - void closeEvent(QCloseEvent *event) override; - - QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; - void adapterClientChanged(WebContentsAdapterClient *client) override; - -private Q_SLOTS: - void onWindowPosChanged(); - void connectRemoveParentBeforeParentDelete(); - void removeParentBeforeParentDelete(); - -private: - friend QWebEngineViewPrivate; - - RenderWidgetHostViewQtDelegateClient *m_client; - QScopedPointer m_rootItem; - bool m_isPopup; - QColor m_clearColor; - QList m_windowConnections; - QWebEnginePage *m_page = nullptr; - QMetaObject::Connection m_parentDestroyedConnection; - QMetaObject::Connection m_pageDestroyedConnection; -}; - -#if QT_CONFIG(accessibility) -class RenderWidgetHostViewQtDelegateWidgetAccessible : public QAccessibleWidget -{ -public: - RenderWidgetHostViewQtDelegateWidgetAccessible(RenderWidgetHostViewQtDelegateWidget *o, QWebEngineView *view); - - bool isValid() const override; - QAccessibleInterface *focusChild() const override; - int childCount() const override; - QAccessibleInterface *child(int index) const override; - int indexOfChild(const QAccessibleInterface *child) const override; - -private: - QWebEngineViewAccessible *viewAccessible() const; - QWebEngineView *m_view; -}; -#endif // QT_CONFIG(accessibility) - -} // namespace QtWebEngineCore - -#endif -- cgit v1.2.3