QTextHtmlParser: parse border color correctly
Use QCss::Declaration::brushValues to parse the values into a list. This will not only lead to correctly parsing the values, but also prevent an an assertion from firing when ValueExtractor::extractBorder is called. Fixes: QTBUG-126381 Pick-to: 6.7 6.5 6.2 Change-Id: Ic6f3d722ffe0d72dcb5faa9916a23c804211ce49 Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> (cherry picked from commit a37ca7c85933979351d99f1bb22191763a78de46) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f0f9cc602f
commit
28b9a653ea
@ -1213,7 +1213,13 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d
|
|||||||
identifier = static_cast<QCss::KnownValue>(decl.d->values.constFirst().variant.toInt());
|
identifier = static_cast<QCss::KnownValue>(decl.d->values.constFirst().variant.toInt());
|
||||||
|
|
||||||
switch (decl.d->propertyId) {
|
switch (decl.d->propertyId) {
|
||||||
case QCss::BorderColor: borderBrush = QBrush(decl.colorValue()); break;
|
case QCss::BorderColor: {
|
||||||
|
QBrush bordersBrush[4];
|
||||||
|
decl.brushValues(bordersBrush);
|
||||||
|
if (bordersBrush[0].color().isValid())
|
||||||
|
borderBrush = bordersBrush[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QCss::BorderStyles:
|
case QCss::BorderStyles:
|
||||||
if (decl.styleValue() != QCss::BorderStyle_Unknown && decl.styleValue() != QCss::BorderStyle_Native)
|
if (decl.styleValue() != QCss::BorderStyle_Unknown && decl.styleValue() != QCss::BorderStyle_Native)
|
||||||
borderStyle = static_cast<QTextFrameFormat::BorderStyle>(decl.styleValue() - 1);
|
borderStyle = static_cast<QTextFrameFormat::BorderStyle>(decl.styleValue() - 1);
|
||||||
|
@ -60,6 +60,8 @@ private slots:
|
|||||||
void strokeLineCapValues();
|
void strokeLineCapValues();
|
||||||
void strokeLineJoinValues_data();
|
void strokeLineJoinValues_data();
|
||||||
void strokeLineJoinValues();
|
void strokeLineJoinValues();
|
||||||
|
void borderColor_data();
|
||||||
|
void borderColor();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QCssParser::scanner_data()
|
void tst_QCssParser::scanner_data()
|
||||||
@ -1814,6 +1816,57 @@ void tst_QCssParser::strokeLineJoinValues()
|
|||||||
QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value);
|
QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QCssParser::borderColor_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("css");
|
||||||
|
QTest::addColumn<QColor>("expectedTopColor");
|
||||||
|
QTest::addColumn<QColor>("expectedRightColor");
|
||||||
|
QTest::addColumn<QColor>("expectedBottomColor");
|
||||||
|
QTest::addColumn<QColor>("expectedLeftColor");
|
||||||
|
|
||||||
|
QTest::newRow("four values") << "border-color: red green blue white" << QColor("red") << QColor("green") << QColor("blue") << QColor("white");
|
||||||
|
QTest::newRow("three values") << "border-color: red green blue" << QColor("red") << QColor("green") << QColor("blue") << QColor("green");
|
||||||
|
QTest::newRow("two values") << "border-color: red green" << QColor("red") << QColor("green") << QColor("red") << QColor("green");
|
||||||
|
QTest::newRow("one value") << "border-color: red" << QColor("red") << QColor("red") << QColor("red") << QColor("red");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QCssParser::borderColor()
|
||||||
|
{
|
||||||
|
QFETCH(QString, css);
|
||||||
|
QFETCH(QColor, expectedTopColor);
|
||||||
|
QFETCH(QColor, expectedRightColor);
|
||||||
|
QFETCH(QColor, expectedBottomColor);
|
||||||
|
QFETCH(QColor, expectedLeftColor);
|
||||||
|
|
||||||
|
css.prepend("dummy {");
|
||||||
|
css.append(QLatin1Char('}'));
|
||||||
|
|
||||||
|
QCss::Parser parser(css);
|
||||||
|
QCss::StyleSheet sheet;
|
||||||
|
QVERIFY(parser.parse(&sheet));
|
||||||
|
|
||||||
|
QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1);
|
||||||
|
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
|
||||||
|
sheet.styleRules.at(0) : *sheet.nameIndex.begin();
|
||||||
|
const QList<QCss::Declaration> decls = rule.declarations;
|
||||||
|
QVERIFY(decls.size() == 1);
|
||||||
|
QVERIFY(decls[0].d->propertyId == QCss::BorderColor);
|
||||||
|
|
||||||
|
QBrush colors[4];
|
||||||
|
|
||||||
|
decls[0].brushValues(colors);
|
||||||
|
QCOMPARE(colors[QCss::TopEdge].color(), expectedTopColor);
|
||||||
|
QCOMPARE(colors[QCss::RightEdge].color(), expectedRightColor);
|
||||||
|
QCOMPARE(colors[QCss::BottomEdge].color(), expectedBottomColor);
|
||||||
|
QCOMPARE(colors[QCss::LeftEdge].color(), expectedLeftColor);
|
||||||
|
|
||||||
|
//QTBUG-126381 : a second evaluation should give the same results
|
||||||
|
QCOMPARE(colors[QCss::TopEdge].color(), expectedTopColor);
|
||||||
|
QCOMPARE(colors[QCss::RightEdge].color(), expectedRightColor);
|
||||||
|
QCOMPARE(colors[QCss::BottomEdge].color(), expectedBottomColor);
|
||||||
|
QCOMPARE(colors[QCss::LeftEdge].color(), expectedLeftColor);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QCssParser)
|
QTEST_MAIN(tst_QCssParser)
|
||||||
#include "tst_qcssparser.moc"
|
#include "tst_qcssparser.moc"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user