Skip to content

Commit

Permalink
Update qcssscanner so it can parse our normal offline documentation CSS
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
carewolf authored and Allan Sandfeld Jensen committed Jul 26, 2016
1 parent a12cc29 commit b3959b5
Show file tree
Hide file tree
Showing 6 changed files with 512 additions and 434 deletions.
2 changes: 1 addition & 1 deletion doc/global/template/style/offline.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tt {
text-align: left
}

.main {
.main {
display: none;
}
/*
Expand Down
48 changes: 37 additions & 11 deletions src/gui/text/qcssparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions src/gui/text/qcssparser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,11 @@ struct AttributeSelector
enum ValueMatchType {
NoMatch,
MatchEqual,
MatchContains,
MatchBeginsWith
MatchIncludes,
MatchDashMatch,
MatchBeginsWith,
MatchEndsWith,
MatchContains
};
inline AttributeSelector() : valueMatchCriterium(NoMatch) {}

Expand Down Expand Up @@ -679,6 +682,9 @@ enum TokenType {
CDC,
INCLUDES,
DASHMATCH,
BEGINSWITH,
ENDSWITH,
CONTAINS,

LBRACE,
PLUS,
Expand Down
Loading

0 comments on commit b3959b5

Please sign in to comment.