From 2e4a107e7e97a2dc36471cbd795ec94096f1a771 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 4 Dec 2014 11:00:30 +0100 Subject: Ensure that CSS rules are inherited from the parent tags When CSS is set in a head tag then it was not being inherited by the child tags when the CSS specification indicates that the properties are in fact inherited. This ensures that those properties are inherited and the non inheritable ones are unchanged. A test is added to cover the different situations with inheritance and a fix is done for the QTextDocumentFragment test which was passing despite having incorrect defaults. Task-number: QTBUG-28770 Task-number: QTBUG-34153 Change-Id: I55966240845a885852a04ecb82c61926dea9f800 Reviewed-by: Simon Hausmann --- .../gui/text/qtextdocument/tst_qtextdocument.cpp | 138 ++++++++++++++++++++- 1 file changed, 137 insertions(+), 1 deletion(-) (limited to 'tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp') diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index c51d33487e..5e6b606d83 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -187,7 +187,7 @@ private slots: void QTBUG28998_linkColor(); void textCursorUsageWithinContentsChange(); - + void cssInheritance(); private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); void buildRegExpData(); @@ -3006,6 +3006,37 @@ void tst_QTextDocument::QTBUG27354_spaceAndSoftSpace() QPainter p(&image); document.drawContents(&p, image.rect()); } + { + // If no p tag is specified it should not be inheriting it + QTextDocument td; + td.setHtml("Foo"); + QTextBlock block = td.begin(); + while (block.isValid()) { + QTextBlockFormat fmt = block.blockFormat(); + QVERIFY(fmt.lineHeightType() == QTextBlockFormat::SingleHeight); + QVERIFY(fmt.lineHeight() == 0); + block = block.next(); + } + } + { + QTextDocument td; + td.setHtml("

Foo

"); + QList originalMargins; + QTextBlock block = td.begin(); + while (block.isValid()) { + originalMargins << block.blockFormat().topMargin(); + block = block.next(); + } + originalMargins[0] = 85; + td.setHtml("

Foo

  • First
"); + block = td.begin(); + int count = 0; + while (block.isValid()) { + QTextBlockFormat fmt = block.blockFormat(); + QCOMPARE(fmt.topMargin(), originalMargins.at(count++)); + block = block.next(); + } + } } class BaseDocument : public QTextDocument @@ -3124,5 +3155,110 @@ void tst_QTextDocument::textCursorUsageWithinContentsChange() QCOMPARE(handler.verticalMovementX, -1); } +void tst_QTextDocument::cssInheritance() +{ + { + QTextDocument td; + td.setHtml("" + "

Foo

Bar

Baz

"); + 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("" + "

Foo

Bar

Baz

"); + 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); + } + { + QTextDocument td; + td.setHtml("" + "

Foo

Bar

Baz

"); + QTextBlock block = td.begin(); + while (block.isValid()) { + QVERIFY(block.blockFormat().background() == QBrush()); + QVERIFY(block.charFormat().font().bold()); + block = block.next(); + } + } + { + QTextDocument td; + td.setHtml("" + "
Foo
Bar
"); + QTextBlock block = td.begin(); + // First is the table + QTextCharFormat fmt = block.charFormat(); + QVERIFY(!fmt.font().bold()); + QVERIFY(fmt.font().italic()); + // Then the th + block = block.next(); + fmt = block.charFormat(); + QVERIFY(fmt.font().bold()); + QVERIFY(fmt.font().italic()); + // Then the td + block = block.next(); + fmt = block.charFormat(); + QVERIFY(!fmt.font().bold()); + QVERIFY(fmt.font().italic()); + } + { + QTextDocument td; + td.setHtml("" + "

This should be bold

"); + QTextBlock block = td.begin(); + // First is the p + QTextCharFormat fmt = block.charFormat(); + QVERIFY(!fmt.font().bold()); + QTextBlock::iterator it = block.begin(); + // The non bold text is first + QTextFragment currentFragment = it.fragment(); + QVERIFY(currentFragment.isValid()); + fmt = currentFragment.charFormat(); + QVERIFY(!fmt.font().bold()); + ++it; + QVERIFY(!it.atEnd()); + // Now check the "bold" text + currentFragment = it.fragment(); + QVERIFY(currentFragment.isValid()); + fmt = currentFragment.charFormat(); + QVERIFY(!fmt.font().bold()); + QVERIFY(fmt.font().italic()); + } + { + QTextDocument td; + td.setHtml("" + "

This should be bold

"); + QTextBlock block = td.begin(); + // First is the p + QTextCharFormat fmt = block.charFormat(); + QVERIFY(!fmt.font().bold()); + QTextBlock::iterator it = block.begin(); + // The non bold text is first + QTextFragment currentFragment = it.fragment(); + QVERIFY(currentFragment.isValid()); + fmt = currentFragment.charFormat(); + QVERIFY(!fmt.font().bold()); + ++it; + QVERIFY(!it.atEnd()); + // Now check the bold text + currentFragment = it.fragment(); + QVERIFY(currentFragment.isValid()); + fmt = currentFragment.charFormat(); + QVERIFY(fmt.font().bold()); + } +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" -- cgit v1.2.3