mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-25 16:47:29 +09:00
Issue #2691: Adjusted the function to use ParseSelectorGroup
This commit is contained in:
parent
8be86514f0
commit
e9a7190529
1 changed files with 83 additions and 45 deletions
|
|
@ -4862,8 +4862,7 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
|
||||||
bool foundClosingParen = false;
|
bool foundClosingParen = false;
|
||||||
bool hasContent = false;
|
bool hasContent = false;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
for (;;) {
|
|
||||||
if (!GetToken(true)) {
|
if (!GetToken(true)) {
|
||||||
return false; // fail unexpected EOF
|
return false; // fail unexpected EOF
|
||||||
}
|
}
|
||||||
|
|
@ -4883,38 +4882,47 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mToken.mType == eCSSToken_Ident) {
|
switch (mToken.mType) {
|
||||||
if (needSpace) selectorText.Append(' ');
|
case eCSSToken_Ident:
|
||||||
selectorText.Append(mToken.mIdent);
|
|
||||||
|
|
||||||
} else if (mToken.mType == eCSSToken_AtKeyword) {
|
|
||||||
if (needSpace) selectorText.Append(' ');
|
|
||||||
selectorText.Append('@');
|
|
||||||
selectorText.Append(mToken.mIdent);
|
|
||||||
|
|
||||||
} else if (mToken.mType == eCSSToken_Hash) {
|
|
||||||
if (needSpace) selectorText.Append(' ');
|
|
||||||
selectorText.Append('#');
|
|
||||||
selectorText.Append(mToken.mIdent);
|
|
||||||
|
|
||||||
} else if (mToken.mType == eCSSToken_Symbol) {
|
|
||||||
selectorText.Append(mToken.mSymbol);
|
|
||||||
|
|
||||||
} else if (mToken.mType == eCSSToken_String) {
|
|
||||||
if (needSpace) selectorText.Append(' ');
|
|
||||||
selectorText.Append('"');
|
|
||||||
selectorText.Append(mToken.mIdent);
|
|
||||||
selectorText.Append('"');
|
|
||||||
|
|
||||||
} else if (mToken.mType == eCSSToken_Function) {
|
|
||||||
if (needSpace) selectorText.Append(' ');
|
|
||||||
selectorText.Append(mToken.mIdent);
|
|
||||||
selectorText.Append('(');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (!mToken.mIdent.IsEmpty()) {
|
|
||||||
if (needSpace) selectorText.Append(' ');
|
if (needSpace) selectorText.Append(' ');
|
||||||
selectorText.Append(mToken.mIdent);
|
selectorText.Append(mToken.mIdent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCSSToken_AtKeyword:
|
||||||
|
if (needSpace) selectorText.Append(' ');
|
||||||
|
selectorText.Append('@');
|
||||||
|
selectorText.Append(mToken.mIdent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCSSToken_Hash:
|
||||||
|
if (needSpace) selectorText.Append(' ');
|
||||||
|
selectorText.Append('#');
|
||||||
|
selectorText.Append(mToken.mIdent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCSSToken_Symbol:
|
||||||
|
selectorText.Append(mToken.mSymbol);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCSSToken_String:
|
||||||
|
if (needSpace) selectorText.Append(' ');
|
||||||
|
selectorText.Append('"');
|
||||||
|
selectorText.Append(mToken.mIdent);
|
||||||
|
selectorText.Append('"');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case eCSSToken_Function:
|
||||||
|
if (needSpace) selectorText.Append(' ');
|
||||||
|
selectorText.Append(mToken.mIdent);
|
||||||
|
selectorText.Append('(');
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (!mToken.mIdent.IsEmpty()) {
|
||||||
|
if (needSpace) selectorText.Append(' ');
|
||||||
|
selectorText.Append(mToken.mIdent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4930,21 +4938,53 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
|
||||||
|
|
||||||
selectorText.CompressWhitespace(true, true);
|
selectorText.CompressWhitespace(true, true);
|
||||||
|
|
||||||
// basic validation
|
if (selectorText.IsEmpty()) {
|
||||||
// reject issues like multiple selectors (comma-separated)
|
|
||||||
if (selectorText.FindChar(',') >= 0) {
|
|
||||||
aConditionMet = false;
|
aConditionMet = false;
|
||||||
} else if (selectorText.IsEmpty()) {
|
return true;
|
||||||
aConditionMet = false;
|
}
|
||||||
} else {
|
|
||||||
// assume basic selectors, pseudo-elements, and compound selectors to be true
|
int32_t parenDepth = 0;
|
||||||
aConditionMet = true;
|
for (uint32_t i = 0; i < selectorText.Length(); i++) {
|
||||||
|
char16_t c = selectorText.CharAt(i);
|
||||||
// special case: reject obviously unsupported pseudo-elements
|
if (c == '(') {
|
||||||
if (selectorText.Find(NS_LITERAL_STRING("::-webkit-")) >= 0) {
|
parenDepth++;
|
||||||
|
} else if (c == ')') {
|
||||||
|
if (parenDepth > 0) {
|
||||||
|
parenDepth--;
|
||||||
|
}
|
||||||
|
} else if (c == ',' && parenDepth == 0) { // top-level comma found
|
||||||
aConditionMet = false;
|
aConditionMet = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectorText.Find(NS_LITERAL_STRING("::-webkit-")) >= 0) {
|
||||||
|
aConditionMet = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCSSScanner tempScanner(selectorText, 0);
|
||||||
|
css::ErrorReporter tempReporter(tempScanner, mSheet, mChildLoader, mSheetURI);
|
||||||
|
|
||||||
|
nsCSSScanner* savedScanner = mScanner;
|
||||||
|
css::ErrorReporter* savedReporter = mReporter;
|
||||||
|
|
||||||
|
mScanner = &tempScanner;
|
||||||
|
mReporter = &tempReporter;
|
||||||
|
|
||||||
|
nsCSSSelectorList* selectorList = nullptr;
|
||||||
|
SelectorParsingFlags flags = SelectorParsingFlags::eNone;
|
||||||
|
bool parseSuccess = ParseSelectorGroup(selectorList, flags);
|
||||||
|
|
||||||
|
mScanner = savedScanner;
|
||||||
|
mReporter = savedReporter;
|
||||||
|
|
||||||
|
if (parseSuccess && selectorList) {
|
||||||
|
aConditionMet = true;
|
||||||
|
delete selectorList;
|
||||||
|
} else {
|
||||||
|
aConditionMet = false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -5017,8 +5057,6 @@ CSSParserImpl::ParseSupportsConditionInParensInsideParens(bool& aConditionMet)
|
||||||
ParseSupportsConditionTerms(aConditionMet);
|
ParseSupportsConditionTerms(aConditionMet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// supports_condition_terms
|
// supports_condition_terms
|
||||||
// : S+ 'and' supports_condition_terms_after_operator('and')
|
// : S+ 'and' supports_condition_terms_after_operator('and')
|
||||||
// | S+ 'or' supports_condition_terms_after_operator('or')
|
// | S+ 'or' supports_condition_terms_after_operator('or')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue