diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-01-31 15:01:43 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-02-20 12:42:40 +0000 |
commit | a6c6665d79e6d4097c0a1155ff5f963b9a9eab19 (patch) | |
tree | 407d18d34eaff097e0b6ebf26d101895c0f4dc49 /tests/auto/widgets/qwebengineview | |
parent | 8666e9d50346ce4ae68b577812282b7bc17b41c9 (diff) |
Fix QWebEngineView::setFocus to properly set internal QQuickItem focus
The widgets object hierarchy related to focus goes like this:
QWebEngineView's focus proxy is ->
RenderWidgetHostViewQtDelegateWidget, which has an internal
QQuickRootItem defined by QQuickWidget, and the child of the item is ->
RenderWidgetHostViewQuickItem.
Previously when QWebEngineView::setFocus was called, the focus was set
on the RenderWidgetHostViewQtDelegateWidget and the QQuickRootItem,
but not on the RenderWidgetHostViewQuickItem. This caused for e.g.
an active HTML text input not receiving focus.
Make sure the RenderWidgetHostViewQuickItem is marked to have focus
within its root item, so that if the root item receives active focus,
so will RenderWidgetHostViewQuickItem receive it.
Task-number: QTBUG-58515
Change-Id: I175610e3dfebc03733aefe26c16f47096df8ff5b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebengineview')
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 151b82b61..02e1d417e 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -84,6 +84,7 @@ private Q_SLOTS: void stopSettingFocusWhenDisabled_data(); void focusOnNavigation_data(); void focusOnNavigation(); + void focusInternalRenderWidgetHostViewQuickItem(); void changeLocale(); void inputMethodsTextFormat_data(); @@ -843,11 +844,60 @@ void tst_QWebEngineView::focusOnNavigation() webView->setFocus(); QTRY_COMPARE(webView->hasFocus(), true); + // Clean up. #undef loadAndTriggerFocusAndCompare #undef triggerJavascriptFocus } +void tst_QWebEngineView::focusInternalRenderWidgetHostViewQuickItem() +{ + // Create a container widget, that will hold a line edit that has initial focus, and a web + // engine view. + QScopedPointer<QWidget> containerWidget(new QWidget); + QLineEdit *label = new QLineEdit; + label->setText(QString::fromLatin1("Text")); + label->setFocus(); + + // Create the web view, and set its focusOnNavigation property to false, so it doesn't + // get initial focus. + QWebEngineView *webView = new QWebEngineView; + QWebEngineSettings *settings = webView->page()->settings(); + settings->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, false); + webView->resize(300, 300); + + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(label); + layout->addWidget(webView); + + containerWidget->setLayout(layout); + containerWidget->show(); + QTest::qWaitForWindowExposed(containerWidget.data()); + + // Load the content, and check that focus is not set. + QSignalSpy loadSpy(webView, SIGNAL(loadFinished(bool))); + webView->setHtml("<html><head><title>Title</title></head><body>Hello" + "<input id=\"input\" type=\"text\"></body></html>"); + QTRY_COMPARE(loadSpy.count(), 1); + QTRY_COMPARE(webView->hasFocus(), false); + + // Manually trigger focus. + webView->setFocus(); + + // Check that focus is set in QWebEngineView and all internal classes. + QTRY_COMPARE(webView->hasFocus(), true); + + QQuickWidget *renderWidgetHostViewQtDelegateWidget = + qobject_cast<QQuickWidget *>(webView->focusProxy()); + QVERIFY(renderWidgetHostViewQtDelegateWidget); + QTRY_COMPARE(renderWidgetHostViewQtDelegateWidget->hasFocus(), true); + + QQuickItem *renderWidgetHostViewQuickItem = + renderWidgetHostViewQtDelegateWidget->rootObject(); + QVERIFY(renderWidgetHostViewQuickItem); + QTRY_COMPARE(renderWidgetHostViewQuickItem->hasFocus(), true); +} + void tst_QWebEngineView::changeLocale() { QUrl url("http://non.existent/"); |