summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-08-24 00:50:36 +0200
committerMoonchild <moonchild@palemoon.org>2022-08-24 00:50:36 +0200
commit0488d0b40bce4965483b05821c33317adda4dd30 (patch)
treeb1aa5ed44ec0e4465e3042d39dcee6078d11208c
parent50bd3acb5b664fab9a78e5cf160ad92cdb577a6e (diff)
downloaduxp-0488d0b40bce4965483b05821c33317adda4dd30.tar.gz
Issue #1994 - Align CSS.supports with the current spec.
The current spec makes "implicit" parentheses a thing for feeding css strings to CSS.supports() The current spec also implies CSS is a namespace, not an interface
-rw-r--r--dom/bindings/Bindings.conf4
-rw-r--r--dom/webidl/CSS.webidl10
-rw-r--r--layout/style/CSS.cpp13
-rw-r--r--layout/style/nsCSSParser.cpp19
-rw-r--r--layout/style/nsCSSParser.h14
-rw-r--r--layout/style/test/test_css_supports.html2
6 files changed, 35 insertions, 27 deletions
diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf
index 989757548a..146bf8d15b 100644
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -170,10 +170,6 @@ DOMInterfaces = {
'headerFile': 'Crypto.h'
},
-'CSS': {
- 'concrete': False,
-},
-
'CSS2Properties': {
'nativeType': 'nsDOMCSSDeclaration'
},
diff --git a/dom/webidl/CSS.webidl b/dom/webidl/CSS.webidl
index b5cdab2d18..2a9746e2c9 100644
--- a/dom/webidl/CSS.webidl
+++ b/dom/webidl/CSS.webidl
@@ -10,15 +10,15 @@
* liability, trademark and document use rules apply.
*/
-interface CSS {
+namespace CSS {
[Throws]
- static boolean supports(DOMString property, DOMString value);
+ boolean supports(DOMString property, DOMString value);
[Throws]
- static boolean supports(DOMString conditionText);
+ boolean supports(DOMString conditionText);
};
// http://dev.w3.org/csswg/cssom/#the-css.escape%28%29-method
-partial interface CSS {
- static DOMString escape(DOMString ident);
+partial namespace CSS {
+ DOMString escape(DOMString ident);
};
diff --git a/layout/style/CSS.cpp b/layout/style/CSS.cpp
index b70f67a505..1078945ee5 100644
--- a/layout/style/CSS.cpp
+++ b/layout/style/CSS.cpp
@@ -62,12 +62,6 @@ CSS::Supports(const GlobalObject& aGlobal,
return false;
}
- if (info.mStyleBackendType == StyleBackendType::Servo) {
- NS_ConvertUTF16toUTF8 property(aProperty);
- NS_ConvertUTF16toUTF8 value(aValue);
- return Servo_CSSSupports(&property, &value);
- }
-
nsCSSParser parser;
return parser.EvaluateSupportsDeclaration(aProperty, aValue, info.mDocURI,
info.mBaseURI, info.mPrincipal);
@@ -86,13 +80,10 @@ CSS::Supports(const GlobalObject& aGlobal,
return false;
}
- if (info.mStyleBackendType == StyleBackendType::Servo) {
- MOZ_CRASH("stylo: CSS.supports() with arguments is not yet implemented");
- }
-
nsCSSParser parser;
return parser.EvaluateSupportsCondition(aCondition, info.mDocURI,
- info.mBaseURI, info.mPrincipal);
+ info.mBaseURI, info.mPrincipal,
+ css::SupportsParsingSettings::ImpliedParentheses);
}
/* static */ void
diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp
index 6a65f06646..b981a553f3 100644
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -257,7 +257,8 @@ public:
bool EvaluateSupportsCondition(const nsAString& aCondition,
nsIURI* aDocURL,
nsIURI* aBaseURL,
- nsIPrincipal* aDocPrincipal);
+ nsIPrincipal* aDocPrincipal,
+ SupportsParsingSettings aSettings = SupportsParsingSettings::Normal);
bool ParseCounterStyleName(const nsAString& aBuffer,
nsIURI* aURL,
@@ -2457,7 +2458,8 @@ bool
CSSParserImpl::EvaluateSupportsCondition(const nsAString& aDeclaration,
nsIURI* aDocURL,
nsIURI* aBaseURL,
- nsIPrincipal* aDocPrincipal)
+ nsIPrincipal* aDocPrincipal,
+ SupportsParsingSettings aSettings)
{
nsCSSScanner scanner(aDeclaration, 0);
css::ErrorReporter reporter(scanner, mSheet, mChildLoader, aDocURL);
@@ -2465,7 +2467,13 @@ CSSParserImpl::EvaluateSupportsCondition(const nsAString& aDeclaration,
nsAutoSuppressErrors suppressErrors(this);
bool conditionMet;
- bool parsedOK = ParseSupportsCondition(conditionMet) && !GetToken(true);
+ bool parsedOK;
+
+ if (aSettings == SupportsParsingSettings::ImpliedParentheses) {
+ parsedOK = ParseSupportsConditionInParensInsideParens(conditionMet) && !GetToken(true);
+ } else {
+ parsedOK = ParseSupportsCondition(conditionMet) && !GetToken(true);
+ }
CLEAR_ERROR();
ReleaseScanner();
@@ -18245,10 +18253,11 @@ bool
nsCSSParser::EvaluateSupportsCondition(const nsAString& aCondition,
nsIURI* aDocURL,
nsIURI* aBaseURL,
- nsIPrincipal* aDocPrincipal)
+ nsIPrincipal* aDocPrincipal,
+ SupportsParsingSettings aSettings)
{
return static_cast<CSSParserImpl*>(mImpl)->
- EvaluateSupportsCondition(aCondition, aDocURL, aBaseURL, aDocPrincipal);
+ EvaluateSupportsCondition(aCondition, aDocURL, aBaseURL, aDocPrincipal, aSettings);
}
bool
diff --git a/layout/style/nsCSSParser.h b/layout/style/nsCSSParser.h
index 37cd325f20..e3d526659d 100644
--- a/layout/style/nsCSSParser.h
+++ b/layout/style/nsCSSParser.h
@@ -34,6 +34,12 @@ namespace css {
class Rule;
class Declaration;
class StyleRule;
+
+enum class SupportsParsingSettings {
+ Normal,
+ ImpliedParentheses
+};
+
} // namespace css
} // namespace mozilla
@@ -257,11 +263,17 @@ public:
/**
* Parse an @supports condition and returns the result of evaluating the
* condition.
+ *
+ * The one-argument CSS.supports() allows for providing an @supports condition
+ * without parentheses, i.e. the parentheses are "implied". In such a case,
+ * aSettings can be set to ImpliedParentheses.
*/
bool EvaluateSupportsCondition(const nsAString& aCondition,
nsIURI* aDocURL,
nsIURI* aBaseURL,
- nsIPrincipal* aDocPrincipal);
+ nsIPrincipal* aDocPrincipal,
+ mozilla::css::SupportsParsingSettings aSettings
+ = mozilla::css::SupportsParsingSettings::Normal);
typedef void (*VariableEnumFunc)(const nsAString&, void*);
diff --git a/layout/style/test/test_css_supports.html b/layout/style/test/test_css_supports.html
index fa5b3fdcba..a500a3798b 100644
--- a/layout/style/test/test_css_supports.html
+++ b/layout/style/test/test_css_supports.html
@@ -22,6 +22,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=779917
function runTest()
{
var passingConditions = [
+ "color: green",
"(color: green)",
"((color: green))",
"(color: green !important)",
@@ -69,7 +70,6 @@ function runTest()
"(color: green) or an-extension(that is [unbalanced)",
"not(unknown: unknown)",
"(color: green) or(color: blue)",
- "color: green",
"(color: green;)",
"(font-family: 'Helvetica\n",
"(font-family: 'Helvetica\n')",