Qt 4.8
qtexthtmlparser_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTEXTHTMLPARSER_P_H
43 #define QTEXTHTMLPARSER_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
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.
52 //
53 // We mean it.
54 //
55 
56 #include "QtCore/qvector.h"
57 #include "QtGui/qbrush.h"
58 #include "QtGui/qcolor.h"
59 #include "QtGui/qfont.h"
60 #include "QtGui/qtextdocument.h"
61 #include "QtGui/qtextcursor.h"
62 #include "private/qtextformat_p.h"
63 #include "private/qtextdocument_p.h"
64 #include "private/qcssparser_p.h"
65 
66 #ifndef QT_NO_TEXTHTMLPARSER
67 
69 
72  Html_qt = 0,
74 
86 
95 
97 
101 
106 
110 
113 
125 
126  // tables
135 
136  // misc...
143 
145 };
146 
148 {
149  const char *name;
152 };
153 
154 class QTextHtmlParser;
155 
163  };
164 
169  int parent;
180  uint displayMode : 3; // QTextHtmlElement::DisplayMode
198 
200 
202 
203  inline bool isListStart() const
204  { return id == Html_ol || id == Html_ul; }
205  inline bool isTableCell() const
206  { return id == Html_td || id == Html_th; }
207  inline bool isBlock() const
209 
210  inline bool isNotSelfNesting() const
211  { return id == Html_p || id == Html_li; }
212 
213  inline bool allowedInContext(int parentId) const
214  {
215  switch (id) {
216  case Html_dd:
217  case Html_dt: return (parentId == Html_dl);
218  case Html_tr: return (parentId == Html_table
219  || parentId == Html_thead
220  || parentId == Html_tbody
221  || parentId == Html_tfoot
222  );
223  case Html_th:
224  case Html_td: return (parentId == Html_tr);
225  case Html_thead:
226  case Html_tbody:
227  case Html_tfoot: return (parentId == Html_table);
228  case Html_caption: return (parentId == Html_table);
229  case Html_body: return parentId != Html_head;
230  default: break;
231  }
232  return true;
233  }
234 
235  inline bool mayNotHaveChildren() const
236  { return id == Html_img || id == Html_hr || id == Html_br || id == Html_meta; }
237 
238  void initializeProperties(const QTextHtmlParserNode *parent, const QTextHtmlParser *parser);
239 
240  inline int uncollapsedMargin(int mar) const { return margin[mar]; }
241 
242  bool isNestedList(const QTextHtmlParser *parser) const;
243 
244  void parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider);
245 
246 #ifndef QT_NO_CSSPARSER
247  void applyCssDeclarations(const QVector<QCss::Declaration> &declarations, const QTextDocument *resourceProvider);
248 
249  void setListStyle(const QVector<QCss::Value> &cssValues);
250 #endif
251 
252  void applyBackgroundImage(const QString &url, const QTextDocument *resourceProvider);
253 
254  bool hasOnlyWhitespace() const;
255 
256  int margin[4];
257  int padding[4];
258 
259  friend class QTextHtmlParser;
260 };
262 
263 
265 {
266 public:
267  enum Margin {
272  };
273 
274  inline const QTextHtmlParserNode &at(int i) const { return nodes.at(i); }
275  inline QTextHtmlParserNode &operator[](int i) { return nodes[i]; }
276  inline int count() const { return nodes.count(); }
277  inline int last() const { return nodes.count()-1; }
278  int depth(int i) const;
279  int topMargin(int i) const;
280  int bottomMargin(int i) const;
281  inline int leftMargin(int i) const { return margin(i, MarginLeft); }
282  inline int rightMargin(int i) const { return margin(i, MarginRight); }
283 
284  inline int topPadding(int i) const { return at(i).padding[MarginTop]; }
285  inline int bottomPadding(int i) const { return at(i).padding[MarginBottom]; }
286  inline int leftPadding(int i) const { return at(i).padding[MarginLeft]; }
287  inline int rightPadding(int i) const { return at(i).padding[MarginRight]; }
288 
289  void dumpHtml();
290 
291  void parse(const QString &text, const QTextDocument *resourceProvider);
292 
293  static int lookupElement(const QString &element);
294 protected:
295  QTextHtmlParserNode *newNode(int parent);
298  int pos, len;
299 
301 
302  void parse();
303  void parseTag();
304  void parseCloseTag();
305  void parseExclamationTag();
306  QString parseEntity();
307  QString parseWord();
308  QTextHtmlParserNode *resolveParent();
309  void resolveNode();
310  QStringList parseAttributes();
311  void applyAttributes(const QStringList &attributes);
312  void eatSpace();
313  inline bool hasPrefix(QChar c, int lookahead = 0) const
314  {return pos + lookahead < len && txt.at(pos) == c; }
315  int margin(int i, int mar) const;
316 
317  bool nodeIsChildOf(int i, QTextHTMLElements id) const;
318 
319 
320 #ifndef QT_NO_CSSPARSER
321  QVector<QCss::Declaration> declarationsForNode(int node) const;
322  void resolveStyleSheetImports(const QCss::StyleSheet &sheet);
323  void importStyleSheet(const QString &href);
324 
326  {
327  inline ExternalStyleSheet() {}
328  inline ExternalStyleSheet(const QString &_url, const QCss::StyleSheet &_sheet)
329  : url(_url), sheet(_sheet) {}
332  };
335 #endif
336 
338 };
339 
341 
342 #endif // QT_NO_TEXTHTMLPARSER
343 
344 #endif // QTEXTHTMLPARSER_P_H
bool mayNotHaveChildren() const
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
QTextFrameFormat::BorderStyle borderStyle
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QTextDocument * resourceProvider
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int rightMargin(int i) const
QVector< int > children
#define at(className, varName)
const QTextHtmlParserNode & at(int i) const
QTextHTMLElements id
The QString class provides a Unicode character string.
Definition: qstring.h:83
ExternalStyleSheet(const QString &_url, const QCss::StyleSheet &_sheet)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QTextListFormat::Style listStyle
int topPadding(int i) const
int leftMargin(int i) const
QTextHtmlParserNode & operator[](int i)
QTextCharFormat charFormat
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Style
This enum describes the symbols used to decorate list items:
Definition: qtextformat.h:649
int uncollapsedMargin(int mar) const
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QTextBlockFormat blockFormat
static QVector< Declaration > declarations(const QVector< StyleRule > &styleRules, const QString &part, quint64 pseudoClass=PseudoClass_Unspecified)
unsigned int uint
Definition: qglobal.h:996
int bottomPadding(int i) const
QTextHTMLElements id
QVector< QTextHtmlParserNode > nodes
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
Q_DECLARE_TYPEINFO(QTextHtmlParserNode, Q_MOVABLE_TYPE)
QTextHTMLElements
QVector< QCss::StyleSheet > inlineStyleSheets
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
int leftPadding(int i) const
enum QTextHtmlElement::DisplayMode displayMode
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool hasPrefix(QChar c, int lookahead=0) const
BorderStyle
This enum describes different border styles for the text frame.
Definition: qtextformat.h:742
int rightPadding(int i) const
bool allowedInContext(int parentId) const
QVector< ExternalStyleSheet > externalStyleSheets
#define text
Definition: qobjectdefs.h:80
bool isNotSelfNesting() const