diff options
author | Kai Koehne <kai.koehne@qt.io> | 2018-12-14 12:36:22 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2019-02-13 08:14:47 +0000 |
commit | d6c474b49b349dc6c30ea059040285221e712217 (patch) | |
tree | 04dc52f4ef2db85959bfbc51789eea080c6a10d6 | |
parent | 81fd7f4c8af260d753a834480f790c82fb161889 (diff) | |
download | qtbase-d6c474b49b349dc6c30ea059040285221e712217.tar.gz |
QTextDocument: Do respect white-space:nowrap
Prevent automatic insertion of line-breaks in blocks formatted with 'white-space:nowrap'.
This follows the example of white-space:pre.
Fixes: QTBUG-54787
Change-Id: If26f6a54106a02fe0e388947f6368ae4e86acf63
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/gui/text/qtextdocumentfragment.cpp | 3 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp | 22 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index e7eaa54a45..6b3604afb5 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -1139,7 +1139,8 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() // #################### // block.setFloatPosition(node->cssFloat); - if (wsm == QTextHtmlParserNode::WhiteSpacePre) { + if (wsm == QTextHtmlParserNode::WhiteSpacePre + || wsm == QTextHtmlParserNode::WhiteSpaceNoWrap) { block.setNonBreakableLines(true); modifiedBlockFormat = true; } diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index 3e354b7523..d652bb066d 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -195,6 +195,8 @@ private slots: void css_linkPseudo(); void css_pageBreaks(); void css_cellPaddings(); + void css_whiteSpace_data(); + void css_whiteSpace(); void universalSelectors_data(); void universalSelectors(); void screenMedia(); @@ -1770,6 +1772,26 @@ void tst_QTextDocumentFragment::css_cellPaddings() QCOMPARE(cell.format().toTableCellFormat().bottomPadding(), qreal(15)); } +void tst_QTextDocumentFragment::css_whiteSpace_data() +{ + QTest::addColumn<QString>("htmlText"); + QTest::addColumn<bool>("nowrap"); + + QTest::newRow("default") << QString("<p>Normal Text</p>") << false; + QTest::newRow("white-space:nowrap") << QString("<p style=white-space:nowrap>Normal Text</p>") << true; + QTest::newRow("white-space:pre") << QString("<p style=white-space:pre>Normal Text</p>") << true; +} + +void tst_QTextDocumentFragment::css_whiteSpace() +{ + QFETCH(QString, htmlText); + QFETCH(bool, nowrap); + + doc->setHtml(htmlText); + QCOMPARE(doc->blockCount(), 1); + QCOMPARE(doc->begin().blockFormat().nonBreakableLines(), nowrap); +} + void tst_QTextDocumentFragment::html_blockLevelDiv() { const char html[] = "<div align=right><b>Hello World"; |