Fix empty lines in Qt HTML when displayed in external browsers (again)
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Mon, 20 Jun 2011 08:40:01 +0000 (10:40 +0200)
committerQt Continuous Integration System <qt-info@nokia.com>
Mon, 20 Jun 2011 13:27:17 +0000 (15:27 +0200)
This redoes f541c78e1bc5b293466b40e6f10496199a4a5d73 in a way which
should be more compliant with different browsers. In particular,
Outlook didn't support the CSS trick in the last fix, so we need the
somewhat larger patch which adds an extra line break node to the tree
and then ignores it when re-importing the document.

Task-number: QTBUG-3669
Reviewed-by: Simon Hausmann
(cherry picked from commit cb760eaef631abd49836ae5c8dc12a61ef5eff0d)

Change-Id: Ia55bf39d52461aa9445a9a5d0bfb5b4c5bf1e9bd
Reviewed-on: http://codereview.qt.nokia.com/492
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
src/gui/text/qtextdocument.cpp
src/gui/text/qtextdocumentfragment.cpp
src/gui/text/qtextdocumentfragment_p.h

index 41b6fe2..0abafb8 100644 (file)
@@ -2553,7 +2553,7 @@ void QTextHtmlExporter::emitBlockAttributes(const QTextBlock &block)
 
     const bool emptyBlock = block.begin().atEnd();
     if (emptyBlock) {
-        html += QLatin1String("-qt-paragraph-type:empty; height:1em;");
+        html += QLatin1String("-qt-paragraph-type:empty;");
     }
 
     emitMargins(QString::number(format.topMargin()),
@@ -2709,6 +2709,8 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block)
     emitBlockAttributes(block);
 
     html += QLatin1Char('>');
+    if (block.begin().atEnd())
+        html += "<br />";
 
     QTextBlock::Iterator it = block.begin();
     if (fragmentMarkers && !it.atEnd() && block == doc->begin())
index 042b1d0..0c8860e 100644 (file)
@@ -545,8 +545,13 @@ void QTextHtmlImporter::import()
         }
 
         if (currentNode->isBlock()) {
-            if (processBlockNode() == ContinueWithNextNode)
+            QTextHtmlImporter::ProcessNodeResult result = processBlockNode();
+            if (result == ContinueWithNextNode) {
                 continue;
+            } else if (result == ContinueWithNextSibling) {
+                currentNodeIdx += currentNode->children.size();
+                continue;
+            }
         }
 
         if (currentNode->charFormat.isAnchor() && !currentNode->charFormat.anchorName().isEmpty()) {
@@ -1157,7 +1162,7 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode()
 
     if (currentNode->isEmptyParagraph) {
         hasBlock = false;
-        return ContinueWithNextNode;
+        return ContinueWithNextSibling;
     }
 
     hasBlock = true;
index bfbec30..227123e 100644 (file)
@@ -135,7 +135,7 @@ private:
 
     Table scanTable(int tableNodeIdx);
 
-    enum ProcessNodeResult { ContinueWithNextNode, ContinueWithCurrentNode };
+    enum ProcessNodeResult { ContinueWithNextNode, ContinueWithCurrentNode, ContinueWithNextSibling };
 
     void appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt = QTextCharFormat());
     bool appendNodeText();