1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QTEXTDOCUMENTFRAGMENT_P_H
43 #define QTEXTDOCUMENTFRAGMENT_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "QtGui/qtextdocument.h"
57 #include "private/qtexthtmlparser_p.h"
58 #include "private/qtextdocument_p.h"
59 #include "QtGui/qtexttable.h"
60 #include "QtCore/qatomic.h"
61 #include "QtCore/qlist.h"
62 #include "QtCore/qmap.h"
63 #include "QtCore/qpointer.h"
64 #include "QtCore/qvarlengtharray.h"
65 #include "QtCore/qdatastream.h"
69 class QTextDocumentFragmentPrivate;
74 QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat = false, const QTextCharFormat &fmt = QTextCharFormat());
79 void appendFragments(int pos, int endPos);
80 int appendFragment(int pos, int endPos, int objectIndex = -1);
81 int convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet = -1);
82 inline int convertFormatIndex(int oldFormatIndex, int objectIndexToSet = -1)
83 { return convertFormatIndex(src->formatCollection()->format(oldFormatIndex), objectIndexToSet); }
84 inline QTextFormat convertFormat(const QTextFormat &fmt)
85 { return dst->formatCollection()->format(convertFormatIndex(fmt)); }
90 int primaryCharFormatIndex;
93 QTextDocumentPrivate *dst;
94 QTextDocumentPrivate *src;
95 QTextFormatCollection &formatCollection;
96 const QString originalText;
97 QMap<int, int> objectIndexMap;
100 class QTextDocumentFragmentPrivate
103 QTextDocumentFragmentPrivate(const QTextCursor &cursor = QTextCursor());
104 inline ~QTextDocumentFragmentPrivate() { delete doc; }
106 void insert(QTextCursor &cursor) const;
111 uint importedFromPlainText : 1;
113 Q_DISABLE_COPY(QTextDocumentFragmentPrivate)
116 #ifndef QT_NO_TEXTHTMLPARSER
118 class QTextHtmlImporter : public QTextHtmlParser
127 QTextHtmlImporter(QTextDocument *_doc, const QString &html,
129 const QTextDocument *resourceProvider = 0);
136 Table scanTable(int tableNodeIdx);
138 enum ProcessNodeResult { ContinueWithNextNode, ContinueWithCurrentNode, ContinueWithNextSibling };
140 void appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt = QTextCharFormat());
141 bool appendNodeText();
143 ProcessNodeResult processBlockNode();
144 ProcessNodeResult processSpecialNodes();
148 inline List() : listNode(0) {}
149 QTextListFormat format;
151 QPointer<QTextList> list;
156 // insert a named anchor the next time we emit a char format,
157 // either in a block or in regular text
158 QStringList namedAnchors;
161 friend struct QTextHtmlImporter::Table;
163 struct TableCellIterator
165 inline TableCellIterator(QTextTable *t = 0) : table(t), row(0), column(0) {}
167 inline TableCellIterator &operator++() {
171 const QTextTableCell cell = table->cellAt(row, column);
174 column += cell.columnSpan();
175 if (column >= table->columns()) {
179 } while (row < table->rows() && table->cellAt(row, column).row() != row);
184 inline bool atEnd() const { return table == 0 || row >= table->rows(); }
186 QTextTableCell cell() const { return table->cellAt(row, column); }
196 Table() : isTextFrame(false), rows(0), columns(0), currentRow(0), lastIndent(0) {}
197 QPointer<QTextFrame> frame;
201 int currentRow; // ... for buggy html (see html_skipCell testcase)
202 TableCellIterator currentCell;
205 QVector<Table> tables;
207 struct RowColSpanInfo
210 int rowSpan, colSpan;
220 WhiteSpace compressNextWhitespace;
224 QTextHtmlParserNode::WhiteSpaceMode wsm;
225 ImportMode importMode;
227 bool forceBlockMerging;
230 const QTextHtmlParserNode *currentNode;
234 #endif // QT_NO_TEXTHTMLPARSER
236 #endif // QTEXTDOCUMENTFRAGMENT_P_H