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>
This commit is contained in:
Kai Koehne 2018-12-14 12:36:22 +01:00
parent 81fd7f4c8a
commit d6c474b49b
2 changed files with 24 additions and 1 deletions

View File

@ -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;
}

View File

@ -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";