From dd7917e0203a9144719214c5a5d36fcd7a0b6f93 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 23 Aug 2016 13:32:55 +0200 Subject: Add support of colored underline and background to InputMethodEvent Moreover, unskip and update inputMethodsTextFormat widget auto test and move it to the tst_QWebEngineView tests. New manual test has been also added for testing input methods format. Task-number: QTBUG-55766 Change-Id: I4c71e15cb426925f76c770266a3c20f1cc12b687 Reviewed-by: Allan Sandfeld Jensen --- src/core/render_widget_host_view_qt.cpp | 20 ++- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 57 -------- .../widgets/qwebengineview/tst_qwebengineview.cpp | 65 ++++++++++ tests/manual/manual.pro | 6 + tests/manual/widgets/inputmethods/colorpicker.cpp | 80 ++++++++++++ tests/manual/widgets/inputmethods/colorpicker.h | 56 ++++++++ tests/manual/widgets/inputmethods/controlview.cpp | 108 ++++++++++++++++ tests/manual/widgets/inputmethods/controlview.h | 66 ++++++++++ tests/manual/widgets/inputmethods/inputmethods.pro | 26 ++++ tests/manual/widgets/inputmethods/main.cpp | 144 +++++++++++++++++++++ .../manual/widgets/inputmethods/referenceview.cpp | 49 +++++++ tests/manual/widgets/inputmethods/referenceview.h | 46 +++++++ tests/manual/widgets/inputmethods/test.qrc | 5 + tests/manual/widgets/inputmethods/testdata.csv | 21 +++ tests/manual/widgets/inputmethods/testview.cpp | 141 ++++++++++++++++++++ tests/manual/widgets/inputmethods/testview.h | 60 +++++++++ tests/manual/widgets/inputmethods/webview.cpp | 50 +++++++ tests/manual/widgets/inputmethods/webview.h | 40 ++++++ tests/manual/widgets/widgets.pro | 4 + 19 files changed, 986 insertions(+), 58 deletions(-) create mode 100644 tests/manual/manual.pro create mode 100644 tests/manual/widgets/inputmethods/colorpicker.cpp create mode 100644 tests/manual/widgets/inputmethods/colorpicker.h create mode 100644 tests/manual/widgets/inputmethods/controlview.cpp create mode 100644 tests/manual/widgets/inputmethods/controlview.h create mode 100644 tests/manual/widgets/inputmethods/inputmethods.pro create mode 100644 tests/manual/widgets/inputmethods/main.cpp create mode 100644 tests/manual/widgets/inputmethods/referenceview.cpp create mode 100644 tests/manual/widgets/inputmethods/referenceview.h create mode 100644 tests/manual/widgets/inputmethods/test.qrc create mode 100644 tests/manual/widgets/inputmethods/testdata.csv create mode 100644 tests/manual/widgets/inputmethods/testview.cpp create mode 100644 tests/manual/widgets/inputmethods/testview.h create mode 100644 tests/manual/widgets/inputmethods/webview.cpp create mode 100644 tests/manual/widgets/inputmethods/webview.h create mode 100644 tests/manual/widgets/widgets.pro diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 77fd55aab..097dda1cd 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -1026,7 +1026,25 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) int start = qMin(attribute.start, (attribute.start + attribute.length)); int end = qMax(attribute.start, (attribute.start + attribute.length)); - underlines.push_back(blink::WebCompositionUnderline(start, end, /*color*/ SK_ColorBLACK, /*thick*/ false, /*backgroundColor*/ SK_ColorTRANSPARENT)); + + // Blink does not support negative position values. Adjust start and end positions + // to non-negative values. + if (start < 0) { + start = 0; + end = qMax(0, start + end); + } + + QTextCharFormat format = qvariant_cast(attribute.value).toCharFormat(); + + QColor underlineColor(0, 0, 0, 0); + if (format.underlineStyle() != QTextCharFormat::NoUnderline) + underlineColor = format.underlineColor(); + + QColor backgroundColor(0, 0, 0, 0); + if (format.background().style() != Qt::NoBrush) + backgroundColor = format.background().color(); + + underlines.push_back(blink::WebCompositionUnderline(start, end, toSk(underlineColor), /*thick*/ false, toSk(backgroundColor))); break; } case QInputMethodEvent::Cursor: diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 88b7596d9..2d56d3521 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -155,8 +155,6 @@ private Q_SLOTS: void consoleOutput(); void inputMethods_data(); void inputMethods(); - void inputMethodsTextFormat_data(); - void inputMethodsTextFormat(); void errorPageExtension(); void errorPageExtensionLoadFinished(); void userAgentNewlineStripping(); @@ -2405,61 +2403,6 @@ void tst_QWebEnginePage::inputMethods() #endif } -void tst_QWebEnginePage::inputMethodsTextFormat_data() -{ - QTest::addColumn("string"); - QTest::addColumn("start"); - QTest::addColumn("length"); - - QTest::newRow("") << QString("") << 0 << 0; - QTest::newRow("Q") << QString("Q") << 0 << 1; - QTest::newRow("Qt") << QString("Qt") << 0 << 1; - QTest::newRow("Qt") << QString("Qt") << 0 << 2; - QTest::newRow("Qt") << QString("Qt") << 1 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 0 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 1 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 2 << 1; - QTest::newRow("Qt ") << QString("Qt ") << 2 << -1; - QTest::newRow("Qt ") << QString("Qt ") << -2 << 3; - QTest::newRow("Qt ") << QString("Qt ") << 0 << 3; - QTest::newRow("Qt by") << QString("Qt by") << 0 << 1; - QTest::newRow("Qt by Nokia") << QString("Qt by Nokia") << 0 << 1; -} - - -void tst_QWebEnginePage::inputMethodsTextFormat() -{ -#if !defined(QINPUTMETHODEVENT_TEXTFORMAT) - QSKIP("QINPUTMETHODEVENT_TEXTFORMAT"); -#else - QWebEnginePage* page = new QWebEnginePage; - QWebEngineView* view = new QWebEngineView; - view->setPage(page); - page->settings()->setFontFamily(QWebEngineSettings::SerifFont, "FooSerifFont"); - page->setHtml("" \ - ""); - evaluateJavaScriptSync(page, "document.getElementById('input1').focus()"); - page->mainFrame()->setFocus(); - view->show(); - - QFETCH(QString, string); - QFETCH(int, start); - QFETCH(int, length); - - QList attrs; - QTextCharFormat format; - format.setUnderlineStyle(QTextCharFormat::SingleUnderline); - format.setUnderlineColor(Qt::red); - attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format)); - QInputMethodEvent im(string, attrs); - page->event(&im); - - QTest::qWait(1000); - - delete view; -#endif -} - void tst_QWebEnginePage::protectBindingsRuntimeObjectsFromCollector() { #if !defined(QWEBENGINEPAGE_CREATEPLUGIN) diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index ac142bb38..156c56933 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -80,6 +80,8 @@ private Q_SLOTS: void focusOnNavigation(); void changeLocale(); + void inputMethodsTextFormat_data(); + void inputMethodsTextFormat(); }; // This will be called before the first test function is executed. @@ -859,5 +861,68 @@ void tst_QWebEngineView::changeLocale() QCOMPARE(viewDE.title(), QStringLiteral("Nicht verf\u00FCgbar: %1").arg(url.toString())); } +void tst_QWebEngineView::inputMethodsTextFormat_data() +{ + QTest::addColumn("string"); + QTest::addColumn("start"); + QTest::addColumn("length"); + QTest::addColumn("underlineStyle"); + QTest::addColumn("underlineColor"); + QTest::addColumn("backgroundColor"); + + QTest::newRow("") << QString("") << 0 << 0 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Q") << QString("Q") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 0 << 2 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt") << QString("Qt") << 1 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 1 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 2 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 2 << -1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << -2 << 3 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << -1 << -1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("Qt ") << QString("Qt ") << 0 << 3 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt") << QString("The Qt") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 0 << 1 << static_cast(QTextCharFormat::SingleUnderline) << QColor("red") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 0 << 3 << static_cast(QTextCharFormat::SingleUnderline) << QColor("green") << QColor(); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 4 << 2 << static_cast(QTextCharFormat::SingleUnderline) << QColor("green") << QColor("red"); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 7 << 7 << static_cast(QTextCharFormat::NoUnderline) << QColor("green") << QColor("red"); + QTest::newRow("The Qt Company") << QString("The Qt Company") << 7 << 7 << static_cast(QTextCharFormat::NoUnderline) << QColor() << QColor("red"); +} + + +void tst_QWebEngineView::inputMethodsTextFormat() +{ + QWebEngineView view; + QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); + + view.setHtml("" + " " + ""); + QTRY_COMPARE(loadFinishedSpy.count(), 1); + + evaluateJavaScriptSync(view.page(), "document.getElementById('input1').focus()"); + view.show(); + + QFETCH(QString, string); + QFETCH(int, start); + QFETCH(int, length); + QFETCH(int, underlineStyle); + QFETCH(QColor, underlineColor); + QFETCH(QColor, backgroundColor); + + QList attrs; + QTextCharFormat format; + format.setUnderlineStyle(static_cast(underlineStyle)); + format.setUnderlineColor(underlineColor); + if (backgroundColor.isValid()) + format.setBackground(QBrush(backgroundColor)); + attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format)); + + QInputMethodEvent im(string, attrs); + QVERIFY(QApplication::sendEvent(view.focusProxy(), &im)); + QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), string); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro new file mode 100644 index 000000000..16f56dbe9 --- /dev/null +++ b/tests/manual/manual.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + widgets + +!qtHaveModule(webenginewidgets): SUBDIRS -= widgets diff --git a/tests/manual/widgets/inputmethods/colorpicker.cpp b/tests/manual/widgets/inputmethods/colorpicker.cpp new file mode 100644 index 000000000..f279eb418 --- /dev/null +++ b/tests/manual/widgets/inputmethods/colorpicker.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "colorpicker.h" + +#include +#include +#include +#include + +ColorPicker::ColorPicker(QWidget *parent) + : QWidget(parent) + , m_colorInput(new QLineEdit) + , m_chooseButton(new QPushButton) +{ + m_chooseButton->setText(tr("Choose")); + + QHBoxLayout *layout = new QHBoxLayout; + layout->setMargin(0); + layout->addWidget(m_colorInput); + layout->addWidget(m_chooseButton); + setLayout(layout); + + connect(m_colorInput, &QLineEdit::textChanged, this, &ColorPicker::colorStringChanged); + connect(m_chooseButton, &QPushButton::clicked, this, &ColorPicker::selectButtonClicked); +} + +QColor ColorPicker::color() const +{ + return QColor(m_colorInput->text()); +} + +void ColorPicker::setColor(const QColor &color) +{ + if (color.isValid()) + m_colorInput->setText(color.name(QColor::HexArgb)); +} + +void ColorPicker::colorStringChanged(const QString &colorString) +{ + QColor color(colorString); + QPalette palette; + + palette.setColor(QPalette::Base, color.isValid() ? color : QColor(Qt::white)); + m_colorInput->setPalette(palette); +} + +void ColorPicker::selectButtonClicked() +{ + QColor selectedColor = QColorDialog::getColor(color().isValid() ? color() : Qt::white, + this, + "Select Color", + QColorDialog::ShowAlphaChannel); + setColor(selectedColor); +} diff --git a/tests/manual/widgets/inputmethods/colorpicker.h b/tests/manual/widgets/inputmethods/colorpicker.h new file mode 100644 index 000000000..f5448ad2d --- /dev/null +++ b/tests/manual/widgets/inputmethods/colorpicker.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLORPICKER_H +#define COLORPICKER_H + +#include +#include + +class QLineEdit; +class QPushButton; + +class ColorPicker : public QWidget +{ + Q_OBJECT +public: + explicit ColorPicker(QWidget *parent = 0); + + QColor color() const; + void setColor(const QColor &); + +public slots: + void colorStringChanged(const QString &); + void selectButtonClicked(); + +private: + QLineEdit *m_colorInput; + QPushButton *m_chooseButton; +}; + +#endif // COLORPICKER_H diff --git a/tests/manual/widgets/inputmethods/controlview.cpp b/tests/manual/widgets/inputmethods/controlview.cpp new file mode 100644 index 000000000..4538ced4b --- /dev/null +++ b/tests/manual/widgets/inputmethods/controlview.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "controlview.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "colorpicker.h" + +ControlView::ControlView(QWidget *parent) + : QWidget(parent) + , m_underlineStyleCombo(new QComboBox) + , m_underlineColorPicker(new ColorPicker) + , m_backgroundColorPicker(new ColorPicker) + , m_startSpin(new QSpinBox) + , m_lengthSpin(new QSpinBox) + , m_inputLine(new QLineEdit) + , m_sendEventButton(new QPushButton) +{ + m_underlineStyleCombo->addItem(tr("No Underline"), QVariant(QTextCharFormat::NoUnderline)); + m_underlineStyleCombo->addItem(tr("Single Underline"), QVariant(QTextCharFormat::SingleUnderline)); + + m_startSpin->setMinimum(-99); + m_lengthSpin->setMinimum(-99); + + m_sendEventButton->setText(tr("Send Input Method Event")); + + QFormLayout *layout = new QFormLayout; + layout->addRow(tr("Underline Style:"), m_underlineStyleCombo); + layout->addRow(tr("Underline Color:"), m_underlineColorPicker); + layout->addRow(tr("Background Color:"), m_backgroundColorPicker); + layout->addRow(tr("Start:"), m_startSpin); + layout->addRow(tr("Length:"), m_lengthSpin); + layout->addRow(tr("Input:"), m_inputLine); + layout->addRow(m_sendEventButton); + setLayout(layout); + + connect(m_sendEventButton, &QPushButton::clicked, this, &ControlView::createAndSendInputMethodEvent); +} + +void ControlView::receiveInputMethodData(int start, + int length, + QTextCharFormat::UnderlineStyle underlineStyle, + const QColor &underlineColor, + const QColor &backgroundColor, + const QString &input) +{ + m_startSpin->setValue(start); + m_lengthSpin->setValue(length); + m_underlineStyleCombo->setCurrentIndex(m_underlineStyleCombo->findData(underlineStyle)); + m_underlineColorPicker->setColor(underlineColor); + m_backgroundColorPicker->setColor(backgroundColor); + m_inputLine->setText(input); +} + +void ControlView::createAndSendInputMethodEvent() +{ + int start = m_startSpin->value(); + int length = m_lengthSpin->value(); + + QTextCharFormat format; + format.setUnderlineStyle(static_cast(m_underlineStyleCombo->currentData().toInt())); + format.setUnderlineColor(m_underlineColorPicker->color()); + + const QColor &backgroundColor = m_backgroundColorPicker->color(); + if (backgroundColor.isValid()) + format.setBackground(QBrush(backgroundColor)); + + QList attrs; + attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format)); + QInputMethodEvent im(m_inputLine->text(), attrs); + + emit sendInputMethodEvent(im); +} diff --git a/tests/manual/widgets/inputmethods/controlview.h b/tests/manual/widgets/inputmethods/controlview.h new file mode 100644 index 000000000..0ef10f6a8 --- /dev/null +++ b/tests/manual/widgets/inputmethods/controlview.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONTROLVIEW_H +#define CONTROLVIEW_H + +#include +#include +#include + +class ColorPicker; +class QComboBox; +class QLabel; +class QLineEdit; +class QPushButton; +class QSpinBox; + +class ControlView : public QWidget +{ + Q_OBJECT +public: + explicit ControlView(QWidget *parent = 0); + +public slots: + void receiveInputMethodData(int, int, QTextCharFormat::UnderlineStyle, const QColor &, const QColor &, const QString &); + void createAndSendInputMethodEvent(); + +signals: + void sendInputMethodEvent(QInputMethodEvent); + +private: + QComboBox *m_underlineStyleCombo; + ColorPicker *m_underlineColorPicker; + ColorPicker *m_backgroundColorPicker; + QSpinBox *m_startSpin; + QSpinBox *m_lengthSpin; + QLineEdit *m_inputLine; + QPushButton *m_sendEventButton; +}; + +#endif // CONTROLVIEW_H diff --git a/tests/manual/widgets/inputmethods/inputmethods.pro b/tests/manual/widgets/inputmethods/inputmethods.pro new file mode 100644 index 000000000..72e8e12f9 --- /dev/null +++ b/tests/manual/widgets/inputmethods/inputmethods.pro @@ -0,0 +1,26 @@ +QT += core gui widgets webenginewidgets testlib + +TARGET = inputmethods +TEMPLATE = app + + +SOURCES += \ + colorpicker.cpp \ + controlview.cpp \ + main.cpp \ + referenceview.cpp \ + testview.cpp \ + webview.cpp + +HEADERS += \ + colorpicker.h \ + controlview.h \ + referenceview.h \ + testview.h \ + webview.h + +RESOURCES += \ + test.qrc + +DISTFILES += \ + testdata.csv diff --git a/tests/manual/widgets/inputmethods/main.cpp b/tests/manual/widgets/inputmethods/main.cpp new file mode 100644 index 000000000..a96deb83a --- /dev/null +++ b/tests/manual/widgets/inputmethods/main.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "controlview.h" +#include "referenceview.h" +#include "testview.h" +#include "webview.h" + +// Test for input method events for QWebEngineView. This makes possible to +// manually customize QInputMethodEvent and validate that it is rendered +// properly in a web view. + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit MainWindow(QWidget *parent = 0); + +private: + ControlView *m_controlView; + ReferenceView *m_referenceView; + WebView *m_webView; + TestView *m_testView; + + QLabel *m_referenceProcessed; + QLabel *m_webProcessed; +}; + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , m_controlView(new ControlView) + , m_referenceView(new ReferenceView) + , m_webView(new WebView) + , m_testView(new TestView) + , m_referenceProcessed(new QLabel) + , m_webProcessed(new QLabel) +{ + m_controlView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_controlView->setFixedWidth(300); + + m_webView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_webView->setFixedWidth(280); + m_webView->setFixedHeight(150); + + m_testView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_testView->setMinimumWidth(400); + + QWidget *centralWidget = new QWidget; + + QGroupBox *referenceGroup = new QGroupBox(tr("Reference")); + referenceGroup->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); + referenceGroup->setMinimumWidth(300); + QFormLayout *referenceProcessedForm = new QFormLayout; + referenceProcessedForm->addRow(tr("Processed:"), m_referenceProcessed); + QVBoxLayout *referenceLayout = new QVBoxLayout; + referenceLayout->addWidget(m_referenceView); + referenceLayout->addLayout(referenceProcessedForm); + referenceGroup->setLayout(referenceLayout); + + QGroupBox *webGroup = new QGroupBox(tr("Web")); + webGroup->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); + webGroup->setMinimumWidth(300); + QFormLayout *webProcessedForm = new QFormLayout; + webProcessedForm->addRow(tr("Processed:"), m_webProcessed); + QVBoxLayout *webLayout = new QVBoxLayout; + webLayout->addWidget(m_webView); + webLayout->addLayout(webProcessedForm); + webGroup->setLayout(webLayout); + + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(m_controlView); + leftLayout->addWidget(referenceGroup); + leftLayout->addWidget(webGroup); + + QHBoxLayout *centralLayout = new QHBoxLayout; + centralLayout->addLayout(leftLayout); + centralLayout->addWidget(m_testView); + + connect(m_testView, &TestView::sendInputMethodData, m_controlView, &ControlView::receiveInputMethodData); + connect(m_testView, &TestView::requestInputMethodEvent, m_controlView, &ControlView::createAndSendInputMethodEvent); + + connect(m_controlView, &ControlView::sendInputMethodEvent, [=](QInputMethodEvent im) { + bool processed; + QString resultText; + + processed = QApplication::sendEvent(m_referenceView->referenceInput(), &im); + resultText = processed ? QStringLiteral("TRUE") + : QStringLiteral("FALSE"); + m_referenceProcessed->setText(resultText); + + processed = QApplication::sendEvent(m_webView->focusProxy(), &im); + resultText = processed ? QStringLiteral("TRUE") + : QStringLiteral("FALSE"); + m_webProcessed->setText(resultText); + }); + + centralWidget->setLayout(centralLayout); + setCentralWidget(centralWidget); + setWindowTitle(tr("Input Methods Format Manual Test")); +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} + +#include "main.moc" diff --git a/tests/manual/widgets/inputmethods/referenceview.cpp b/tests/manual/widgets/inputmethods/referenceview.cpp new file mode 100644 index 000000000..906a3001e --- /dev/null +++ b/tests/manual/widgets/inputmethods/referenceview.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "referenceview.h" + +#include + +ReferenceView::ReferenceView(QWidget *parent) + : QWidget(parent) + , m_referenceInput(new QLineEdit) +{ + m_referenceInput->setMinimumHeight(50); + m_referenceInput->setMaximumWidth(250); + m_referenceInput->setFont(QFont(QStringLiteral("Serif"), 28)); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(m_referenceInput); + setLayout(layout); +} + +QLineEdit *ReferenceView::referenceInput() +{ + return m_referenceInput; +} diff --git a/tests/manual/widgets/inputmethods/referenceview.h b/tests/manual/widgets/inputmethods/referenceview.h new file mode 100644 index 000000000..4025d4886 --- /dev/null +++ b/tests/manual/widgets/inputmethods/referenceview.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REFERENCEVIEW_H +#define REFERENCEVIEW_H + +#include +#include + +class ReferenceView : public QWidget +{ + Q_OBJECT +public: + explicit ReferenceView(QWidget *parent = 0); + QLineEdit *referenceInput(); + +private: + QLineEdit *m_referenceInput; +}; + +#endif // REFERENCEVIEW_H diff --git a/tests/manual/widgets/inputmethods/test.qrc b/tests/manual/widgets/inputmethods/test.qrc new file mode 100644 index 000000000..bee4bec74 --- /dev/null +++ b/tests/manual/widgets/inputmethods/test.qrc @@ -0,0 +1,5 @@ + + + testdata.csv + + diff --git a/tests/manual/widgets/inputmethods/testdata.csv b/tests/manual/widgets/inputmethods/testdata.csv new file mode 100644 index 000000000..4d57e19e8 --- /dev/null +++ b/tests/manual/widgets/inputmethods/testdata.csv @@ -0,0 +1,21 @@ +"", 0, 0, 1, "red", "" + +"Q", 0, 1, 1, "red", "" +"Qt", 0, 1, 1, "red", "" +"Qt", 0, 2, 1, "red", "" +"Qt", 1, 1, 1, "red", "" + +"Qt ", 0, 1, 1, "red", "" +"Qt ", 1, 1, 1, "red", "" +"Qt ", 2, 1, 1, "red", "" +"Qt ", 2, -1, 1, "red", "" +"Qt ", -2, 3, 1, "red", "" +"Qt ", -1, -1, 1, "red", "" + +"The Qt", 0, 1, 1, "red", "" +"The Qt Company", 0, 1, 1, "red", "" + +"The Qt Company", 0, 3, 1, "green", "" +"The Qt Company", 4, 2, 1, "green", "red" +"The Qt Company", 7, 7, 0, "green", "red" +"The Qt Company", 7, 7, 0, "", "red" diff --git a/tests/manual/widgets/inputmethods/testview.cpp b/tests/manual/widgets/inputmethods/testview.cpp new file mode 100644 index 000000000..d41734c2d --- /dev/null +++ b/tests/manual/widgets/inputmethods/testview.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testview.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +TestView::TestView(QWidget *parent) + : QWidget(parent) + , m_tableView(new QTableView) + , m_testButton(new QPushButton) + , m_testRunning(false) +{ + m_testButton->setText(tr("Start Test")); + connect(m_testButton, &QPushButton::clicked, this, &TestView::startOrCancelTest); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(m_tableView); + layout->addWidget(m_testButton); + setLayout(layout); + + QStandardItemModel *model = new QStandardItemModel(0, 6, this); + model->setHorizontalHeaderItem(0, new QStandardItem(tr("Input"))); + model->setHorizontalHeaderItem(1, new QStandardItem(tr("Start"))); + model->setHorizontalHeaderItem(2, new QStandardItem(tr("Length"))); + model->setHorizontalHeaderItem(3, new QStandardItem(tr("Underline"))); + model->setHorizontalHeaderItem(4, new QStandardItem(tr("Underline Color"))); + model->setHorizontalHeaderItem(5, new QStandardItem(tr("Background Color"))); + + m_tableView->setModel(model); + connect(m_tableView, &QTableView::clicked, this, &TestView::collectAndSendData); + + loadTestData(":/testdata.csv"); +} + +void TestView::loadTestData(const QString &testDataPath) +{ + QFile testDataFile(testDataPath); + if (!testDataFile.open(QIODevice::ReadOnly)) { + qWarning() << "Unable to open " << testDataFile.fileName() << ":" << testDataFile.errorString(); + return; + } + + QTextStream testDataStream(&testDataFile); + while (!testDataStream.atEnd()) { + QString line = testDataStream.readLine(); + QRegExp data("^\"(.*)\"\\s*,\\s*(-?\\d+)\\s*,\\s*(-?\\d+)\\s*,\\s*(\\d+)\\s*,\\s*\"(.*)\"\\s*,\\s*\"(.*)\"\\s*$"); + if (!data.exactMatch(line)) + continue; + + QStandardItemModel *model = qobject_cast(m_tableView->model()); + + QList row; + for (int i = 1; i <= data.captureCount(); ++i) + row.append(new QStandardItem(data.cap(i))); + + model->appendRow(row); + } + + testDataFile.close(); +} + +void TestView::startOrCancelTest() +{ + if (m_testRunning) { + m_testRunning = false; + m_testButton->setText(tr("Start Test")); + return; + } + + m_testRunning = true; + m_testButton->setText(tr("Cancel Test")); + + int firstRowIndex = m_tableView->currentIndex().row() + 1; + if (firstRowIndex == m_tableView->model()->rowCount()) + firstRowIndex = 0; + + for (int row = firstRowIndex; row < m_tableView->model()->rowCount(); ++row) { + if (!m_testRunning) + break; + + m_tableView->selectRow(row); + collectAndSendData(); + emit requestInputMethodEvent(); + + QTest::qWait(1000); + } + + if (m_testRunning) { + m_testRunning = false; + m_testButton->setText(tr("Start Test")); + } +} + +void TestView::collectAndSendData() +{ + int row = m_tableView->currentIndex().row(); + QStandardItemModel *model = static_cast(m_tableView->model()); + + const QString &input = model->data(model->index(row, 0)).toString(); + const int start = model->data(model->index(row, 1)).toInt(); + const int length = model->data(model->index(row, 2)).toInt(); + const QTextCharFormat::UnderlineStyle underlineStyle = static_cast(model->data(model->index(row, 3)).toInt()); + const QColor &underlineColor = qvariant_cast(model->data(model->index(row, 4))); + const QColor &backgroundColor = qvariant_cast(model->data(model->index(row, 5))); + + emit sendInputMethodData(start, length, underlineStyle, underlineColor, backgroundColor.isValid() ? backgroundColor : Qt::white, input); +} diff --git a/tests/manual/widgets/inputmethods/testview.h b/tests/manual/widgets/inputmethods/testview.h new file mode 100644 index 000000000..4934a5f87 --- /dev/null +++ b/tests/manual/widgets/inputmethods/testview.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTVIEW_H +#define TESTVIEW_H + +#include +#include + +class QPushButton; +class QTableView; + +class TestView : public QWidget +{ + Q_OBJECT +public: + explicit TestView(QWidget *parent = 0); + +public slots: + void loadTestData(const QString &); + void startOrCancelTest(); + void collectAndSendData(); + +signals: + void sendInputMethodData(int, int, QTextCharFormat::UnderlineStyle, const QColor &, const QColor &, const QString &); + void requestInputMethodEvent(); + +private: + QTableView *m_tableView; + QPushButton *m_testButton; + + bool m_testRunning; +}; + +#endif // TESTVIEW_H diff --git a/tests/manual/widgets/inputmethods/webview.cpp b/tests/manual/widgets/inputmethods/webview.cpp new file mode 100644 index 000000000..ac5dadce1 --- /dev/null +++ b/tests/manual/widgets/inputmethods/webview.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "webview.h" + +WebView::WebView(QWidget *parent) + : QWebEngineView(parent) +{ + const QString html = QStringLiteral( + "" + " " + "" + "" + " " + ""); + + setHtml(html); +} diff --git a/tests/manual/widgets/inputmethods/webview.h b/tests/manual/widgets/inputmethods/webview.h new file mode 100644 index 000000000..be57fbf29 --- /dev/null +++ b/tests/manual/widgets/inputmethods/webview.h @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef WEBVIEW_H +#define WEBVIEW_H + +#include + +class WebView : public QWebEngineView +{ + Q_OBJECT +public: + explicit WebView(QWidget *parent = 0); +}; + +#endif // WEBVIEW_H diff --git a/tests/manual/widgets/widgets.pro b/tests/manual/widgets/widgets.pro new file mode 100644 index 000000000..f06d3e1c3 --- /dev/null +++ b/tests/manual/widgets/widgets.pro @@ -0,0 +1,4 @@ +TEMPLATE= subdirs + +SUBDIRS += \ + inputmethods -- cgit v1.2.3