diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-03 12:21:23 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-05-08 13:02:26 +0000 |
commit | b275c5b1baa7df8704d1842ae0f1ff4ba99fb580 (patch) | |
tree | d63fc7d098321f195278724dda9d8562d1146d22 /tests | |
parent | 70c1f674cae33d59c0e5b3c1ca5c4d523ddeff40 (diff) |
Allow background inheritance between non-body block elements
Most nested block elements are merged together, so while we shouldn't
do real inheritance we need to do it when block elements are combined.
Fixes: QTBUG-91236
Change-Id: I9e37b15f705db92c79a620d0d772f25d0ee72b8d
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit f94b0e1dd999a6bb8dfa4471fd63c395fc8e2302)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index a7408fcc8e..08ec74b5d4 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -142,6 +142,7 @@ private slots: void html_doNotInheritBackground(); void html_inheritBackgroundToInlineElements(); void html_doNotInheritBackgroundFromBlockElements(); + void html_inheritBackgroundFromBlockElements(); void html_nobr(); void fromPlainText(); void fromPlainText2(); @@ -2070,7 +2071,7 @@ void tst_QTextDocumentFragment::html_inheritBackgroundToInlineElements() void tst_QTextDocumentFragment::html_doNotInheritBackgroundFromBlockElements() { - const char html[] = "<p style=\"background: blue\"><span>Foo</span></span>"; + const char html[] = "<p style=\"background: blue\"><span>Foo</span></p>"; doc->setHtml(html); int fragmentCount = 0; @@ -2088,6 +2089,31 @@ void tst_QTextDocumentFragment::html_doNotInheritBackgroundFromBlockElements() QCOMPARE(fragmentCount, 1); } + +void tst_QTextDocumentFragment::html_inheritBackgroundFromBlockElements() +{ + const char html[] = "<div style=\"background: blue\"><p>Foo</p><p>Bar</p></div>"; + doc->setHtml(html); + + int fragmentCount = 0; + + QTextBlock block = doc->begin(); + for (QTextBlock::Iterator it = block.begin(); + !it.atEnd(); ++it, ++fragmentCount) { + + const QTextFragment fragment = it.fragment(); + if (fragmentCount == 0) { + QCOMPARE(fragment.text(), QString("Foo")); + QVERIFY(fragment.charFormat().hasProperty(QTextFormat::BackgroundBrush)); + } else { + QCOMPARE(fragment.text(), QString("Bar")); + QVERIFY(fragment.charFormat().hasProperty(QTextFormat::BackgroundBrush)); + } + } + + QCOMPARE(fragmentCount, 1); +} + void tst_QTextDocumentFragment::html_nobr() { const QString input = "Blah Foo Bar"; |