summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qcssparser.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-07-19 17:27:44 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-07-26 13:26:00 +0000
commitb3959b515fce642b4f873a25f1c13c604512d9fe (patch)
tree9ddf427069c5740953c7feb7aba33ebc8e213826 /src/gui/text/qcssparser.cpp
parenta12cc29cf542cb7c325da6b266d1179d13c3b831 (diff)
Update qcssscanner so it can parse our normal offline documentation CSS
Adds the three CSS3 attribute selectors. During this the internal naming of the existing attribute-selectors have been changed to be more clear, and the dash-matching has been fixed to not just be beginsWith. A non-breaking space have also been removed from the CSS. Change-Id: Ia4db4a5a19e3ceee8c3c8a4b744149edd1d32bdc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/gui/text/qcssparser.cpp')
-rw-r--r--src/gui/text/qcssparser.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index 940de87eee..5138f7e94c 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -1914,18 +1914,38 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node)
if (attrValue.isNull())
return false;
- if (a.valueMatchCriterium == QCss::AttributeSelector::MatchContains) {
+ switch (a.valueMatchCriterium) {
+ case QCss::AttributeSelector::NoMatch:
+ break;
+ case QCss::AttributeSelector::MatchEqual:
+ if (attrValue != a.value)
+ return false;
+ break;
+ case QCss::AttributeSelector::MatchIncludes: {
const auto lst = attrValue.splitRef(QLatin1Char(' '));
if (!lst.contains(QStringRef(&a.value)))
return false;
- } else if (
- (a.valueMatchCriterium == QCss::AttributeSelector::MatchEqual
- && attrValue != a.value)
- ||
- (a.valueMatchCriterium == QCss::AttributeSelector::MatchBeginsWith
- && !attrValue.startsWith(a.value))
- )
- return false;
+ break;
+ }
+ case QCss::AttributeSelector::MatchDashMatch: {
+ const QString dashPrefix = a.value + QLatin1Char('-');
+ if (attrValue != a.value && !attrValue.startsWith(dashPrefix))
+ return false;
+ break;
+ }
+ case QCss::AttributeSelector::MatchBeginsWith:
+ if (!attrValue.startsWith(a.value))
+ return false;
+ break;
+ case QCss::AttributeSelector::MatchEndsWith:
+ if (!attrValue.endsWith(a.value))
+ return false;
+ break;
+ case QCss::AttributeSelector::MatchContains:
+ if (!attrValue.contains(a.value))
+ return false;
+ break;
+ }
}
}
@@ -2439,7 +2459,7 @@ bool Parser::parseSimpleSelector(BasicSelector *basicSel)
onceMore = true;
AttributeSelector a;
a.name = QLatin1String("class");
- a.valueMatchCriterium = AttributeSelector::MatchContains;
+ a.valueMatchCriterium = AttributeSelector::MatchIncludes;
if (!parseClass(&a.value)) return false;
basicSel->attributeSelectors.append(a);
} else if (testAttrib()) {
@@ -2485,9 +2505,15 @@ bool Parser::parseAttrib(AttributeSelector *attr)
if (test(EQUAL)) {
attr->valueMatchCriterium = AttributeSelector::MatchEqual;
} else if (test(INCLUDES)) {
- attr->valueMatchCriterium = AttributeSelector::MatchContains;
+ attr->valueMatchCriterium = AttributeSelector::MatchIncludes;
} else if (test(DASHMATCH)) {
+ attr->valueMatchCriterium = AttributeSelector::MatchDashMatch;
+ } else if (test(BEGINSWITH)) {
attr->valueMatchCriterium = AttributeSelector::MatchBeginsWith;
+ } else if (test(ENDSWITH)) {
+ attr->valueMatchCriterium = AttributeSelector::MatchEndsWith;
+ } else if (test(CONTAINS)) {
+ attr->valueMatchCriterium = AttributeSelector::MatchContains;
} else {
return next(RBRACKET);
}