Ensure CSS rules are inherited from the parent tags

When CSS was set in the head tag then it was not being inherited by the
child tags. This ensures that the inhertiance happens and that the deeper
the CSS is set then it will ensure that it has precedence over the ones
set on the parent.

A test is added that shows the standard inheritance from the head tag and
the precedence from child tags in effect too.

Task-number: QTBUG-28770

Change-Id: I30be3ec141b2cd8d6e0db8a92669aed34da93b33
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Andy Shaw 2013-10-09 20:59:45 +02:00 committed by The Qt Project
parent c16dbfbdde
commit 6f65466137
2 changed files with 35 additions and 2 deletions

View File

@ -1896,7 +1896,11 @@ QVector<QCss::Declaration> QTextHtmlParser::declarationsForNode(int node) const
if (nodes.at(node).id == Html_a && nodes.at(node).hasHref)
extraPseudo = "link";
decls = selector.declarationsForNode(n, extraPseudo);
n = selector.parentNode(n);
while (!selector.isNullNode(n)) {
decls = selector.declarationsForNode(n, extraPseudo) + decls;
n = selector.parentNode(n);
}
return decls;
}

View File

@ -185,7 +185,7 @@ private slots:
void htmlExportImportBlockCount();
void QTBUG27354_spaceAndSoftSpace();
void cssInheritance();
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
@ -2925,5 +2925,34 @@ void tst_QTextDocument::QTBUG27354_spaceAndSoftSpace()
}
}
void tst_QTextDocument::cssInheritance()
{
{
QTextDocument td;
td.setHtml("<html><head><style type=\"text/css\">body { line-height: 200% }</style></head><body>"
"<p>Foo</p><p>Bar</p><p>Baz</p></body></html>");
QTextBlock block = td.begin();
while (block.isValid()) {
QTextBlockFormat fmt = block.blockFormat();
QVERIFY(fmt.lineHeightType() == QTextBlockFormat::ProportionalHeight);
QVERIFY(fmt.lineHeight() == 200);
block = block.next();
}
}
{
QTextDocument td;
td.setHtml("<html><head><style type=\"text/css\">body { line-height: 200% } p { line-height: 300% }</style></head><body>"
"<p style=\"line-height: 40px\">Foo</p><p>Bar</p><p>Baz</p></body></html>");
QTextBlock block = td.begin();
QTextBlockFormat fmt = block.blockFormat();
QVERIFY(fmt.lineHeightType() == QTextBlockFormat::FixedHeight);
QVERIFY(fmt.lineHeight() == 40);
block = block.next();
fmt = block.blockFormat();
QVERIFY(fmt.lineHeightType() == QTextBlockFormat::ProportionalHeight);
QVERIFY(fmt.lineHeight() == 300);
}
}
QTEST_MAIN(tst_QTextDocument)
#include "tst_qtextdocument.moc"