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>
This commit is contained in:
parent
70c1f674ca
commit
b275c5b1ba
@ -1032,8 +1032,11 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent
|
||||
// we don't paint per-row background colors, yet. so as an
|
||||
// exception inherit the background color here
|
||||
// we also inherit the background between inline elements
|
||||
// we also inherit from non-body block elements since we merge them together
|
||||
if ((parent->id != Html_tr || !isTableCell())
|
||||
&& (displayMode != QTextHtmlElement::DisplayInline || parent->displayMode != QTextHtmlElement::DisplayInline)) {
|
||||
&& (displayMode != QTextHtmlElement::DisplayInline || parent->displayMode != QTextHtmlElement::DisplayInline)
|
||||
&& (parent->id == Html_body || displayMode != QTextHtmlElement::DisplayBlock || parent->displayMode != QTextHtmlElement::DisplayBlock)
|
||||
) {
|
||||
charFormat.clearProperty(QTextFormat::BackgroundBrush);
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user