diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-31 18:47:56 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-04-01 09:10:26 +0200 |
commit | 0e6ee136c91432d4ceeeda64e5a5fa88231398d4 (patch) | |
tree | 6060e002af2900007895f6efa757989dd4c190c9 /src/gui/text | |
parent | 418869d9158ea5cd998ba30778b0b7173b48161b (diff) | |
parent | 17294c5e4d15d5776f6e414b03671a4a9ed4993d (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
src/testlib/qtestblacklist.cpp
src/widgets/accessible/qaccessiblewidgets.cpp
Change-Id: If032adb9296428f62384ed835dbf41ee7a0b886c
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qcssparser.cpp | 24 | ||||
-rw-r--r-- | src/gui/text/qcssparser_p.h | 5 | ||||
-rw-r--r-- | src/gui/text/qharfbuzzng.cpp | 41 | ||||
-rw-r--r-- | src/gui/text/qplatformfontdatabase.cpp | 14 | ||||
-rw-r--r-- | src/gui/text/qtextengine.cpp | 50 | ||||
-rw-r--r-- | src/gui/text/qtextformat.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/qtexthtmlparser.cpp | 270 |
7 files changed, 324 insertions, 86 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index f9e6a7e335..3c98cb568d 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -364,6 +364,29 @@ static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, return prop->id; } +static inline bool isInheritable(Property propertyId) +{ + switch (propertyId) { + case Font: + case FontFamily: + case FontSize: + case FontStyle: + case FontWeight: + case TextIndent: + case Whitespace: + case ListStyleType: + case ListStyle: + case TextAlignment: + case FontVariant: + case TextTransform: + case LineHeight: + return true; + default: + break; + } + return false; +} + /////////////////////////////////////////////////////////////////////////////// // Value Extractor ValueExtractor::ValueExtractor(const QVector<Declaration> &decls, const QPalette &pal) @@ -2317,6 +2340,7 @@ bool Parser::parseProperty(Declaration *decl) { decl->d->property = lexem(); decl->d->propertyId = static_cast<Property>(findKnownValue(decl->d->property, properties, NumProperties)); + decl->d->inheritable = isInheritable(decl->d->propertyId); skipSpace(); return true; } diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h index ebd9904762..75802ba36a 100644 --- a/src/gui/text/qcssparser_p.h +++ b/src/gui/text/qcssparser_p.h @@ -426,12 +426,13 @@ struct Q_GUI_EXPORT Declaration { struct DeclarationData : public QSharedData { - inline DeclarationData() : propertyId(UnknownProperty), important(false) {} + inline DeclarationData() : propertyId(UnknownProperty), important(false), inheritable(false) {} QString property; Property propertyId; QVector<Value> values; QVariant parsed; - bool important; + bool important:1; + bool inheritable:1; }; QExplicitlySharedDataPointer<DeclarationData> d; inline Declaration() : d(new DeclarationData()) {} diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp index 4baf1fd03c..102c62ea8a 100644 --- a/src/gui/text/qharfbuzzng.cpp +++ b/src/gui/text/qharfbuzzng.cpp @@ -94,6 +94,8 @@ static const hb_script_t _qtscript_to_hbscript[] = { HB_SCRIPT_BUHID, HB_SCRIPT_TAGBANWA, HB_SCRIPT_COPTIC, + + // Unicode 4.0 additions HB_SCRIPT_LIMBU, HB_SCRIPT_TAI_LE, HB_SCRIPT_LINEAR_B, @@ -102,6 +104,8 @@ static const hb_script_t _qtscript_to_hbscript[] = { HB_SCRIPT_OSMANYA, HB_SCRIPT_CYPRIOT, HB_SCRIPT_BRAILLE, + + // Unicode 4.1 additions HB_SCRIPT_BUGINESE, HB_SCRIPT_NEW_TAI_LUE, HB_SCRIPT_GLAGOLITIC, @@ -109,11 +113,15 @@ static const hb_script_t _qtscript_to_hbscript[] = { HB_SCRIPT_SYLOTI_NAGRI, HB_SCRIPT_OLD_PERSIAN, HB_SCRIPT_KHAROSHTHI, + + // Unicode 5.0 additions HB_SCRIPT_BALINESE, HB_SCRIPT_CUNEIFORM, HB_SCRIPT_PHOENICIAN, HB_SCRIPT_PHAGS_PA, HB_SCRIPT_NKO, + + // Unicode 5.1 additions HB_SCRIPT_SUNDANESE, HB_SCRIPT_LEPCHA, HB_SCRIPT_OL_CHIKI, @@ -125,6 +133,8 @@ static const hb_script_t _qtscript_to_hbscript[] = { HB_SCRIPT_CARIAN, HB_SCRIPT_LYDIAN, HB_SCRIPT_CHAM, + + // Unicode 5.2 additions HB_SCRIPT_TAI_THAM, HB_SCRIPT_TAI_VIET, HB_SCRIPT_AVESTAN, @@ -140,16 +150,45 @@ static const hb_script_t _qtscript_to_hbscript[] = { HB_SCRIPT_INSCRIPTIONAL_PAHLAVI, HB_SCRIPT_OLD_TURKIC, HB_SCRIPT_KAITHI, + + // Unicode 6.0 additions HB_SCRIPT_BATAK, HB_SCRIPT_BRAHMI, HB_SCRIPT_MANDAIC, + + // Unicode 6.1 additions HB_SCRIPT_CHAKMA, HB_SCRIPT_MEROITIC_CURSIVE, HB_SCRIPT_MEROITIC_HIEROGLYPHS, HB_SCRIPT_MIAO, HB_SCRIPT_SHARADA, HB_SCRIPT_SORA_SOMPENG, - HB_SCRIPT_TAKRI + HB_SCRIPT_TAKRI, + + // Unicode 7.0 additions + HB_SCRIPT_CAUCASIAN_ALBANIAN, + HB_SCRIPT_BASSA_VAH, + HB_SCRIPT_DUPLOYAN, + HB_SCRIPT_ELBASAN, + HB_SCRIPT_GRANTHA, + HB_SCRIPT_PAHAWH_HMONG, + HB_SCRIPT_KHOJKI, + HB_SCRIPT_LINEAR_A, + HB_SCRIPT_MAHAJANI, + HB_SCRIPT_MANICHAEAN, + HB_SCRIPT_MENDE_KIKAKUI, + HB_SCRIPT_MODI, + HB_SCRIPT_MRO, + HB_SCRIPT_OLD_NORTH_ARABIAN, + HB_SCRIPT_NABATAEAN, + HB_SCRIPT_PALMYRENE, + HB_SCRIPT_PAU_CIN_HAU, + HB_SCRIPT_OLD_PERMIC, + HB_SCRIPT_PSALTER_PAHLAVI, + HB_SCRIPT_SIDDHAM, + HB_SCRIPT_KHUDAWADI, + HB_SCRIPT_TIRHUTA, + HB_SCRIPT_WARANG_CITI }; Q_STATIC_ASSERT(QChar::ScriptCount == sizeof(_qtscript_to_hbscript) / sizeof(_qtscript_to_hbscript[0])); diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp index 3c3000da4d..5fa43948aa 100644 --- a/src/gui/text/qplatformfontdatabase.cpp +++ b/src/gui/text/qplatformfontdatabase.cpp @@ -522,9 +522,11 @@ enum { VietnameseCsbBit = 8, SimplifiedChineseCsbBit = 18, TraditionalChineseCsbBit = 20, + ThaiCsbBit = 16, JapaneseCsbBit = 17, KoreanCsbBit = 19, - KoreanJohabCsbBit = 21 + KoreanJohabCsbBit = 21, + SymbolCsbBit = 31 }; /*! @@ -579,6 +581,11 @@ QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(q hasScript = true; //qDebug("font %s supports Arabic", familyName.latin1()); } + if (codePageRange[0] & (1 << ThaiCsbBit)) { + writingSystems.setSupported(QFontDatabase::Thai); + hasScript = true; + //qDebug("font %s supports Thai", familyName.latin1()); + } if (codePageRange[0] & (1 << VietnameseCsbBit)) { writingSystems.setSupported(QFontDatabase::Vietnamese); hasScript = true; @@ -604,6 +611,11 @@ QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(q hasScript = true; //qDebug("font %s supports Korean", familyName.latin1()); } + if (codePageRange[0] & (1 << SymbolCsbBit)) { + writingSystems = QSupportedWritingSystems(); + hasScript = false; + } + if (!hasScript) writingSystems.setSupported(QFontDatabase::Symbol); diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 076b6bbde4..10a61d3c84 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -881,16 +881,22 @@ static inline void qt_getJustificationOpportunities(const ushort *string, int le int spaceAs; switch (si.analysis.script) { + case QChar::Script_Arabic: + case QChar::Script_Syriac: case QChar::Script_Nko: case QChar::Script_Mandaic: case QChar::Script_Mongolian: case QChar::Script_PhagsPa: + case QChar::Script_Manichaean: + case QChar::Script_PsalterPahlavi: // same as default but inter character justification takes precedence spaceAs = Justification_Arabic_Space; break; + case QChar::Script_Tibetan: case QChar::Script_Hiragana: case QChar::Script_Katakana: + case QChar::Script_Bopomofo: case QChar::Script_Han: // same as default but inter character justification is the only option spaceAs = Justification_Character; @@ -1201,20 +1207,7 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st uint cluster = infos->cluster; if (Q_LIKELY(last_cluster != cluster)) { - if (Q_UNLIKELY(g.glyphs[i] == 0)) { - // hide characters that should normally be invisible - switch (string[item_pos + str_pos]) { - case QChar::LineFeed: - case 0x000c: // FormFeed - case QChar::CarriageReturn: - case QChar::LineSeparator: - case QChar::ParagraphSeparator: - g.attributes[i].dontPrint = true; - break; - default: - break; - } - } + g.attributes[i].clusterStart = true; // fix up clusters so that the cluster indices will be monotonic // and thus we never return out-of-order indices @@ -1222,7 +1215,32 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st log_clusters[str_pos++] = last_glyph_pos; last_glyph_pos = i + glyphs_shaped; last_cluster = cluster; - g.attributes[i].clusterStart = true; + + // hide characters that should normally be invisible + switch (string[item_pos + str_pos]) { + case QChar::LineFeed: + case 0x000c: // FormFeed + case QChar::CarriageReturn: + case QChar::LineSeparator: + case QChar::ParagraphSeparator: + g.attributes[i].dontPrint = true; + break; + case QChar::SoftHyphen: + if (!actualFontEngine->symbol) { + // U+00AD [SOFT HYPHEN] is a default ignorable codepoint, + // so we replace its glyph and metrics with ones for + // U+002D [HYPHEN-MINUS] and make it visible if it appears at line-break + g.glyphs[i] = actualFontEngine->glyphIndex('-'); + if (Q_LIKELY(g.glyphs[i] != 0)) { + QGlyphLayout tmp = g.mid(i, 1); + actualFontEngine->recalcAdvances(&tmp, 0); + } + g.attributes[i].dontPrint = true; + } + break; + default: + break; + } } } while (str_pos < item_length) @@ -1618,10 +1636,10 @@ void QTextEngine::itemize() const for (int i = 0; i < length; ++i) { switch (analysis[i].script) { case QChar::Script_Latin: - case QChar::Script_Han: case QChar::Script_Hiragana: case QChar::Script_Katakana: case QChar::Script_Bopomofo: + case QChar::Script_Han: analysis[i].script = QChar::Script_Common; break; default: diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index efd12b2b15..c60d0cc775 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -3458,14 +3458,16 @@ void QTextFormatCollection::setDefaultFont(const QFont &f) #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QTextLength &l) { + QDebugStateSaver saver(dbg); dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))"; - return dbg.space(); + return dbg; } QDebug operator<<(QDebug dbg, const QTextFormat &f) { + QDebugStateSaver saver(dbg); dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))"; - return dbg.space(); + return dbg; } #endif diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index edace3d13c..f8f41bb53d 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1050,25 +1050,14 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent // set element specific attributes switch (id) { case Html_a: - charFormat.setAnchor(true); for (int i = 0; i < attributes.count(); i += 2) { const QString key = attributes.at(i); if (key.compare(QLatin1String("href"), Qt::CaseInsensitive) == 0 && !attributes.at(i + 1).isEmpty()) { hasHref = true; - charFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); - charFormat.setForeground(QGuiApplication::palette().link()); } } - - break; - case Html_em: - case Html_i: - case Html_cite: - case Html_address: - case Html_var: - case Html_dfn: - charFormat.setFontItalic(true); + charFormat.setAnchor(true); break; case Html_big: charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(1)); @@ -1076,36 +1065,27 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent case Html_small: charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(-1)); break; - case Html_strong: - case Html_b: - charFormat.setFontWeight(QFont::Bold); - break; case Html_h1: - charFormat.setFontWeight(QFont::Bold); charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(3)); margin[QTextHtmlParser::MarginTop] = 18; margin[QTextHtmlParser::MarginBottom] = 12; break; case Html_h2: - charFormat.setFontWeight(QFont::Bold); charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(2)); margin[QTextHtmlParser::MarginTop] = 16; margin[QTextHtmlParser::MarginBottom] = 12; break; case Html_h3: - charFormat.setFontWeight(QFont::Bold); charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(1)); margin[QTextHtmlParser::MarginTop] = 14; margin[QTextHtmlParser::MarginBottom] = 12; break; case Html_h4: - charFormat.setFontWeight(QFont::Bold); charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(0)); margin[QTextHtmlParser::MarginTop] = 12; margin[QTextHtmlParser::MarginBottom] = 12; break; case Html_h5: - charFormat.setFontWeight(QFont::Bold); charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(-1)); margin[QTextHtmlParser::MarginTop] = 12; margin[QTextHtmlParser::MarginBottom] = 4; @@ -1114,11 +1094,7 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent margin[QTextHtmlParser::MarginTop] = 12; margin[QTextHtmlParser::MarginBottom] = 12; break; - case Html_center: - blockFormat.setAlignment(Qt::AlignCenter); - break; case Html_ul: - listStyle = QTextListFormat::ListDisc; // nested lists don't have margins, except for the toplevel one if (!isNestedList(parser)) { margin[QTextHtmlParser::MarginTop] = 12; @@ -1127,7 +1103,6 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent // no left margin as we use indenting instead break; case Html_ol: - listStyle = QTextListFormat::ListDecimal; // nested lists don't have margins, except for the toplevel one if (!isNestedList(parser)) { margin[QTextHtmlParser::MarginTop] = 12; @@ -1135,26 +1110,12 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent } // no left margin as we use indenting instead break; - case Html_code: - case Html_tt: - case Html_kbd: - case Html_samp: - charFormat.setFontFamily(QString::fromLatin1("Courier New,courier")); - // <tt> uses a fixed font, so set the property - charFormat.setFontFixedPitch(true); - break; case Html_br: text = QChar(QChar::LineSeparator); - wsm = QTextHtmlParserNode::WhiteSpacePre; break; - // ##### sub / sup case Html_pre: - charFormat.setFontFamily(QString::fromLatin1("Courier New,courier")); - wsm = WhiteSpacePre; margin[QTextHtmlParser::MarginTop] = 12; margin[QTextHtmlParser::MarginBottom] = 12; - // <pre> uses a fixed font - charFormat.setFontFixedPitch(true); break; case Html_blockquote: margin[QTextHtmlParser::MarginTop] = 12; @@ -1169,28 +1130,6 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent case Html_dd: margin[QTextHtmlParser::MarginLeft] = 30; break; - case Html_u: - charFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); - break; - case Html_s: - charFormat.setFontStrikeOut(true); - break; - case Html_nobr: - wsm = WhiteSpaceNoWrap; - break; - case Html_th: - charFormat.setFontWeight(QFont::Bold); - blockFormat.setAlignment(Qt::AlignCenter); - break; - case Html_td: - blockFormat.setAlignment(Qt::AlignLeft); - break; - case Html_sub: - charFormat.setVerticalAlignment(QTextCharFormat::AlignSubScript); - break; - case Html_sup: - charFormat.setVerticalAlignment(QTextCharFormat::AlignSuperScript); - break; default: break; } } @@ -1345,6 +1284,14 @@ void QTextHtmlParserNode::applyCssDeclarations(const QVector<QCss::Declaration> case QCss::QtListNumberSuffix: textListNumberSuffix = decl.d->values.first().variant.toString(); break; + case QCss::TextAlignment: + switch (identifier) { + case QCss::Value_Left: blockFormat.setAlignment(Qt::AlignLeft); break; + case QCss::Value_Center: blockFormat.setAlignment(Qt::AlignCenter); break; + case QCss::Value_Right: blockFormat.setAlignment(Qt::AlignRight); break; + default: break; + } + break; default: break; } } @@ -1833,6 +1780,189 @@ void QTextHtmlParser::importStyleSheet(const QString &href) } } +QVector<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &node) +{ + QVector<QCss::Declaration> decls; + QCss::Declaration decl; + QCss::Value val; + switch (node.id) { + case Html_a: + case Html_u: { + bool needsUnderline = (node.id == Html_u) ? true : false; + if (node.id == Html_a) { + for (int i = 0; i < node.attributes.count(); i += 2) { + const QString key = node.attributes.at(i); + if (key.compare(QLatin1String("href"), Qt::CaseInsensitive) == 0 + && !node.attributes.at(i + 1).isEmpty()) { + needsUnderline = true; + decl.d->property = QLatin1String("color"); + decl.d->propertyId = QCss::Color; + val.type = QCss::Value::Color; + val.variant = QVariant(QGuiApplication::palette().link()); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + } + } + } + if (needsUnderline) { + decl = QCss::Declaration(); + decl.d->property = QLatin1String("text-decoration"); + decl.d->propertyId = QCss::TextDecoration; + val.type = QCss::Value::KnownIdentifier; + val.variant = QVariant(QCss::Value_Underline); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + } + break; + } + case Html_b: + case Html_strong: + case Html_h1: + case Html_h2: + case Html_h3: + case Html_h4: + case Html_h5: + case Html_th: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("font-weight"); + decl.d->propertyId = QCss::FontWeight; + val.type = QCss::Value::KnownIdentifier; + val.variant = QVariant(QCss::Value_Bold); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + if (node.id == Html_b || node.id == Html_strong) + break; + // Delibrate fall through + case Html_big: + case Html_small: + if (node.id != Html_th) { + decl = QCss::Declaration(); + decl.d->property = QLatin1String("font-size"); + decl.d->propertyId = QCss::FontSize; + decl.d->inheritable = false; + val.type = QCss::Value::KnownIdentifier; + switch (node.id) { + case Html_h1: val.variant = QVariant(QCss::Value_XXLarge); break; + case Html_h2: val.variant = QVariant(QCss::Value_XLarge); break; + case Html_h3: case Html_big: val.variant = QVariant(QCss::Value_Large); break; + case Html_h4: val.variant = QVariant(QCss::Value_Medium); break; + case Html_h5: case Html_small: val.variant = QVariant(QCss::Value_Small); break; + default: break; + } + decl.d->values = QVector<QCss::Value>() << val; + decls << decl; + break; + } + // Delibrate fall through + case Html_center: + case Html_td: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("text-align"); + decl.d->propertyId = QCss::TextAlignment; + val.type = QCss::Value::KnownIdentifier; + val.variant = (node.id == Html_td) ? QVariant(QCss::Value_Left) : QVariant(QCss::Value_Center); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + case Html_s: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("text-decoration"); + decl.d->propertyId = QCss::TextDecoration; + val.type = QCss::Value::KnownIdentifier; + val.variant = QVariant(QCss::Value_LineThrough); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + case Html_em: + case Html_i: + case Html_cite: + case Html_address: + case Html_var: + case Html_dfn: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("font-style"); + decl.d->propertyId = QCss::FontStyle; + val.type = QCss::Value::KnownIdentifier; + val.variant = QVariant(QCss::Value_Italic); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + case Html_sub: + case Html_sup: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("vertical-align"); + decl.d->propertyId = QCss::VerticalAlignment; + val.type = QCss::Value::KnownIdentifier; + val.variant = (node.id == Html_sub) ? QVariant(QCss::Value_Sub) : QVariant(QCss::Value_Super); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + case Html_ul: + case Html_ol: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("list-style"); + decl.d->propertyId = QCss::ListStyle; + val.type = QCss::Value::KnownIdentifier; + val.variant = (node.id == Html_ul) ? QVariant(QCss::Value_Disc) : QVariant(QCss::Value_Decimal); + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + case Html_code: + case Html_tt: + case Html_kbd: + case Html_samp: + case Html_pre: { + decl = QCss::Declaration(); + decl.d->property = QLatin1String("font-family"); + decl.d->propertyId = QCss::FontFamily; + QVector<QCss::Value> values; + val.type = QCss::Value::String; + val.variant = QLatin1String("Courier New"); + values << val; + val.type = QCss::Value::TermOperatorComma; + val.variant = QVariant(); + values << val; + val.type = QCss::Value::String; + val.variant = QLatin1String("courier"); + values << val; + decl.d->values = values; + decl.d->inheritable = true; + decls << decl; + } + if (node.id != Html_pre) + break; + // Delibrate fall through + case Html_br: + case Html_nobr: + decl = QCss::Declaration(); + decl.d->property = QLatin1String("whitespace"); + decl.d->propertyId = QCss::Whitespace; + val.type = QCss::Value::KnownIdentifier; + switch (node.id) { + case Html_br: val.variant = QVariant(QCss::Value_PreWrap); break; + case Html_nobr: val.variant = QVariant(QCss::Value_NoWrap); break; + case Html_pre: val.variant = QVariant(QCss::Value_Pre); break; + default: break; + } + decl.d->values = QVector<QCss::Value>() << val; + decl.d->inheritable = true; + decls << decl; + break; + default: + break; + } + return decls; +} + QVector<QCss::Declaration> QTextHtmlParser::declarationsForNode(int node) const { QVector<QCss::Declaration> decls; @@ -1860,8 +1990,20 @@ QVector<QCss::Declaration> QTextHtmlParser::declarationsForNode(int node) const const char *extraPseudo = 0; if (nodes.at(node).id == Html_a && nodes.at(node).hasHref) extraPseudo = "link"; - decls = selector.declarationsForNode(n, extraPseudo); - + // Ensure that our own style is taken into consideration + decls = standardDeclarationForNode(nodes.at(node)); + decls += selector.declarationsForNode(n, extraPseudo); + n = selector.parentNode(n); + while (!selector.isNullNode(n)) { + QVector<QCss::Declaration> inheritedDecls; + inheritedDecls = selector.declarationsForNode(n, extraPseudo); + for (int i = 0; i < inheritedDecls.size(); ++i) { + const QCss::Declaration &decl = inheritedDecls.at(i); + if (decl.d->inheritable) + decls.prepend(decl); + } + n = selector.parentNode(n); + } return decls; } |