Diff
Modified: trunk/LayoutTests/ChangeLog (236378 => 236379)
--- trunk/LayoutTests/ChangeLog 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/LayoutTests/ChangeLog 2018-09-22 01:03:48 UTC (rev 236379)
@@ -1,3 +1,18 @@
+2018-09-21 Justin Michaud <justin_mich...@apple.com>
+
+ Implement initialValue support for CSS Custom Properties and Values API
+ https://bugs.webkit.org/show_bug.cgi?id=189819
+
+ Reviewed by Simon Fraser.
+
+ * css-custom-properties-api/initialValue-expected.html: Added.
+ * css-custom-properties-api/initialValue.html: Added.
+ * css-custom-properties-api/initialValueJS-expected.txt: Added.
+ * css-custom-properties-api/initialValueJS.html: Added.
+ * css-custom-properties-api/registerProperty-expected.txt:
+ * css-custom-properties-api/registerProperty.html:
+ * platform/win/TestExpectations:
+
2018-09-21 Ryan Haddad <ryanhad...@apple.com>
[macOS EWS] Layout test accessibility/smart-invert-reference.html is a flaky failure
Added: trunk/LayoutTests/css-custom-properties-api/initialValue-expected.html (0 => 236379)
--- trunk/LayoutTests/css-custom-properties-api/initialValue-expected.html (rev 0)
+++ trunk/LayoutTests/css-custom-properties-api/initialValue-expected.html 2018-09-22 01:03:48 UTC (rev 236379)
@@ -0,0 +1,88 @@
+<html>
+<head>
+ <style>
+ html {
+ background: grey;
+ }
+ .parent1 {
+ width: 500px;
+ background: blue;
+ }
+ .child1 {
+ background: green;
+ width: 100px;
+ }
+
+ .parent2 {
+ width: 500px;
+ background: blue;
+ }
+ .child2 {
+ background: green;
+ width: 200px;
+ }
+
+ .parent3 {
+ width: 500px;
+ background: blue;
+ }
+ .child3 {
+ background: green;
+ width: 500px;
+ }
+
+ .parent4 {
+ width: 500px;
+ background: blue;
+ }
+ .child4 {
+ background: green;
+ width: 200px;
+ }
+
+ .parent5 {
+ width: 500px;
+ background: blue;
+ }
+ .child5 {
+ background: green;
+ width: 300px;
+ }
+
+ .parent6 {
+ width: 500px;
+ background: blue;
+ }
+ .child6 {
+ background: green;
+ width: 500px;
+ }
+
+ .parent7 {
+ width: 500px;
+ background: blue;
+ }
+ .child7 {
+ background: green;
+ width: 500px;
+ }
+ </style>
+</head>
+<body>
+ <p> Single values </p>
+ <p> Specified </p>
+ <div class="parent1"><div class="child1"><p>100px green</p></div> </div>
+ <p> Not specified, use initial value </p>
+ <div class="parent2"><div class="child2"><p>200px green</p></div> </div>
+ <p> Not specified, but not registered so use initial value for width </p>
+ <div class="parent3"><div class="child3"><p>500px green</p></div> </div>
+ <p> Has a fallback for registered property </p>
+ <div class="parent4"><div class="child4"><p>200px green</p></div> </div>
+ <p> Has a fallback for unregistered property </p>
+ <div class="parent5"><div class="child5"><p>300px green</p></div> </div>
+ <p> Having a fallback for a registered property that is a variable should not work</p>
+ <div class="parent6"><div class="child6"><p>500px green</p></div> </div>
+ <p> Having a variable in the initial value should not work</p>
+ <div class="parent7"><div class="child7"><p>500px green</p></div> </div>
+</body>
+</html>
Added: trunk/LayoutTests/css-custom-properties-api/initialValue.html (0 => 236379)
--- trunk/LayoutTests/css-custom-properties-api/initialValue.html (rev 0)
+++ trunk/LayoutTests/css-custom-properties-api/initialValue.html 2018-09-22 01:03:48 UTC (rev 236379)
@@ -0,0 +1,113 @@
+<html>
+<head>
+ <style>
+ html {
+ background: grey;
+ }
+ .parent1 {
+ width: 500px;
+ background: blue;
+ }
+ .child1 {
+ background: green;
+ --my-custom-prop: 100px;
+ width: var(--my-custom-prop);
+ }
+
+ .parent2 {
+ width: 500px;
+ background: blue;
+ }
+ .child2 {
+ background: green;
+ width: var(--my-custom-prop2);
+ }
+
+ .parent3 {
+ width: 500px;
+ background: blue;
+ }
+ .child3 {
+ background: green;
+ width: var(--my-custom-prop3);
+ }
+
+ .parent4 {
+ width: 500px;
+ background: blue;
+ }
+ .child4 {
+ background: green;
+ width: var(--my-custom-prop2, 300px);
+ }
+
+ .parent5 {
+ width: 500px;
+ background: blue;
+ }
+ .child5 {
+ background: green;
+ width: var(--my-custom-prop3, 300px);
+ }
+
+ .parent6 {
+ width: 500px;
+ background: blue;
+ }
+ .child6 {
+ background: green;
+ --my-custom-prop: 100px;
+ width: var(--my-custom-prop3, --my-custom-prop1);
+ }
+
+ .parent7 {
+ width: 500px;
+ background: blue;
+ }
+ .child7 {
+ background: green;
+ --my-custom-prop: 100px;
+ width: var(--my-custom-prop4);
+ }
+ </style>
+ <script>
+ CSS.registerProperty({
+ name: '--my-custom-prop',
+ syntax: '<length>',
+ inherits: false,
+ initialValue: '200px'
+ })
+
+ CSS.registerProperty({
+ name: '--my-custom-prop2',
+ syntax: '<length>',
+ inherits: false,
+ initialValue: '200px'
+ })
+
+ CSS.registerProperty({
+ name: '--my-custom-prop4',
+ syntax: '<length>',
+ inherits: false,
+ initialValue: 'var(--my-custom-prop)'
+ })
+ </script>
+</head>
+<body>
+ <p> Single values </p>
+ <p> Specified </p>
+ <div class="parent1"><div class="child1"><p>100px green</p></div> </div>
+ <p> Not specified, use initial value </p>
+ <div class="parent2"><div class="child2"><p>200px green</p></div> </div>
+ <p> Not specified, but not registered so use initial value for width </p>
+ <div class="parent3"><div class="child3"><p>500px green</p></div> </div>
+ <p> Has a fallback for registered property </p>
+ <div class="parent4"><div class="child4"><p>200px green</p></div> </div>
+ <p> Has a fallback for unregistered property </p>
+ <div class="parent5"><div class="child5"><p>300px green</p></div> </div>
+ <p> Having a fallback for a registered property that is a variable should not work</p>
+ <div class="parent6"><div class="child6"><p>500px green</p></div> </div>
+ <p> Having a variable in the initial value should not work</p>
+ <div class="parent7"><div class="child7"><p>500px green</p></div> </div>
+</body>
+</html>
Added: trunk/LayoutTests/css-custom-properties-api/initialValueJS-expected.txt (0 => 236379)
--- trunk/LayoutTests/css-custom-properties-api/initialValueJS-expected.txt (rev 0)
+++ trunk/LayoutTests/css-custom-properties-api/initialValueJS-expected.txt 2018-09-22 01:03:48 UTC (rev 236379)
@@ -0,0 +1,27 @@
+Specified
+
+100px green
+
+Not specified, use initial value
+
+200px green
+
+Not specified, but not registered so use initial value for width
+
+500px green
+
+Has a fallback for unregistered property
+
+300px green
+
+Has a fallback for a registered property
+
+200px green
+
+
+PASS Registration is successful
+PASS JS Attributes are valid for element 1
+PASS JS Attributes are valid for element 2
+PASS JS Attributes are valid for element 3
+PASS JS Attributes are valid for element 4 and 5
+
Added: trunk/LayoutTests/css-custom-properties-api/initialValueJS.html (0 => 236379)
--- trunk/LayoutTests/css-custom-properties-api/initialValueJS.html (rev 0)
+++ trunk/LayoutTests/css-custom-properties-api/initialValueJS.html 2018-09-22 01:03:48 UTC (rev 236379)
@@ -0,0 +1,107 @@
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:CSSCustomPropertiesAndValuesEnabled=true ] -->
+<!-- https://chromium.googlesource.com/chromium/src/+/01ce431409e3a019858677626a983c55168da6dc/third_party/WebKit/LayoutTests/custom-properties/register-property.html -->
+<script src=""
+<script src=""
+
+<style>
+ #parent1 {
+ width: 500px;
+ background: blue;
+ }
+ #child1 {
+ background: green;
+ --my-custom-prop: 100px;
+ width: var(--my-custom-prop);
+ }
+
+ #parent2 {
+ width: 500px;
+ background: blue;
+ }
+ #child2 {
+ background: green;
+ width: var(--my-custom-prop2);
+ }
+
+ #parent3 {
+ width: 500px;
+ background: blue;
+ }
+ #child3 {
+ background: green;
+ width: var(--my-custom-prop3);
+ }
+
+ #parent4 {
+ width: 500px;
+ background: blue;
+ }
+ #child4 {
+ background: green;
+ width: var(--my-custom-prop3, 300px);
+ }
+
+ #parent5 {
+ width: 500px;
+ background: blue;
+ }
+ #child5 {
+ background: green;
+ width: var(--my-custom-prop2, 300px);
+ }
+</style>
+<div>
+ <p> Specified </p>
+ <div id="parent1"><div id="child1"><p>100px green</p></div> </div>
+ <p> Not specified, use initial value </p>
+ <div id="parent2"><div id="child2"><p>200px green</p></div> </div>
+ <p> Not specified, but not registered so use initial value for width </p>
+ <div id="parent3"><div id="child3"><p>500px green</p></div> </div>
+ <p> Has a fallback for unregistered property </p>
+ <div id="parent4"><div id="child4"><p>300px green</p></div> </div>
+ <p> Has a fallback for a registered property </p>
+ <div id="parent5"><div id="child5"><p>200px green</p></div> </div>
+</div>
+<script>
+
+function test_prop(id, prop, expected) {
+ assert_equals(window.getComputedStyle(document.getElementById(id)).getPropertyValue(prop).trim(), expected);
+}
+
+test(function() {
+ CSS.registerProperty({
+ name: '--my-custom-prop',
+ syntax: '<length>',
+ inherits: false,
+ initialValue: '200px'
+ })
+
+ CSS.registerProperty({
+ name: '--my-custom-prop2',
+ syntax: '<length>',
+ inherits: false,
+ initialValue: '200px'
+ })
+}, "Registration is successful");
+test(function() {
+ test_prop('child1', 'width', '100px');
+ test_prop('child1', '--my-custom-prop', '100px');
+ test_prop('child1', '--my-custom-prop2', '200px');
+}, "JS Attributes are valid for element 1");
+test(function() {
+ test_prop('child2', 'width', '200px');
+ test_prop('child2', '--my-custom-prop', '200px');
+ test_prop('child2', '--my-custom-prop2', '200px');
+}, "JS Attributes are valid for element 2");
+test(function() {
+ test_prop('child3', 'width', '500px');
+ test_prop('child3', '--my-custom-prop3', '');
+ test_prop('child3', '--my-custom-prop2', '200px');
+}, "JS Attributes are valid for element 3");
+test(function() {
+ test_prop('child4', 'width', '300px');
+ test_prop('child5', 'width', '200px');
+ test_prop('child4', '--my-custom-prop2', '200px');
+ test_prop('child5', '--my-custom-prop2', '200px');
+}, "JS Attributes are valid for element 4 and 5");
+</script>
Modified: trunk/LayoutTests/css-custom-properties-api/registerProperty-expected.txt (236378 => 236379)
--- trunk/LayoutTests/css-custom-properties-api/registerProperty-expected.txt 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/LayoutTests/css-custom-properties-api/registerProperty-expected.txt 2018-09-22 01:03:48 UTC (rev 236379)
@@ -1,5 +1,6 @@
PASS registerProperty requires a Dictionary type
PASS registerProperty requires a name matching <custom-property-name>
-PASS registerProperty only allows omitting initialValue is syntax is '*'
+PASS registerProperty always allows omitting initialValue and syntax, requires name and inherits
+PASS registerProperty requires inherits and name
Modified: trunk/LayoutTests/css-custom-properties-api/registerProperty.html (236378 => 236379)
--- trunk/LayoutTests/css-custom-properties-api/registerProperty.html 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/LayoutTests/css-custom-properties-api/registerProperty.html 2018-09-22 01:03:48 UTC (rev 236379)
@@ -18,8 +18,6 @@
CSS.registerProperty({name: '--name2, no need for escapes', inherits: false});
CSS.registerProperty({name: ['--name', 3], inherits: false});
// Invalid property names
- assert_throws(new TypeError(), () => CSS.registerProperty({}));
- assert_throws(new TypeError(), () => CSS.registerProperty({name: '--no-inherits'}));
//assert_throws(new SyntaxError(), () => CSS.registerProperty({name: 'no-leading-dash', inherits: false}));
//assert_throws(new SyntaxError(), () => CSS.registerProperty({name: '', inherits: false}));
//assert_throws(new SyntaxError(), () => CSS.registerProperty({name: '\\--name', inherits: false}));
@@ -27,7 +25,16 @@
test(function() {
CSS.registerProperty({name: '--syntax-test-1', inherits: false, syntax: '*'});
CSS.registerProperty({name: '--syntax-test-2', inherits: false, syntax: ' * '});
- /*assert_throws(new SyntaxError(),
- () => CSS.registerProperty({name: '--syntax-test-3', syntax: 'length'}));*/
-}, "registerProperty only allows omitting initialValue is syntax is '*'");
+ CSS.registerProperty({name: '--syntax-test-3', inherits: false, initialValue: '500px'});
+ assert_throws(new TypeError(), () => CSS.registerProperty({}));
+ assert_throws(new TypeError(), () => CSS.registerProperty({name: '--no-inherits'}));
+ assert_throws(new TypeError(), () => CSS.registerProperty({inherits: false}));
+ // Repeated name
+ assert_throws(null,
+ () => CSS.registerProperty({name: '--syntax-test-3', inherits: false, initialValue: '500px'}));
+}, "registerProperty always allows omitting initialValue and syntax, requires name and inherits");
+test(function() {
+ CSS.registerProperty({name: '--syntax-test-4', inherits: false, syntax: '*'});
+ CSS.registerProperty({name: '--syntax-test-5', inherits: false, syntax: ' * '});
+}, "registerProperty requires inherits and name");
</script>
Modified: trunk/LayoutTests/platform/win/TestExpectations (236378 => 236379)
--- trunk/LayoutTests/platform/win/TestExpectations 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/LayoutTests/platform/win/TestExpectations 2018-09-22 01:03:48 UTC (rev 236379)
@@ -4160,6 +4160,9 @@
imported/blink/http/tests/websocket [ Skip ]
imported/blink/http/tests/security/mixedContent/websocket [ Skip ]
+# Feature flag only enabled for wk2
+css-custom-properties-api [ Skip ]
+
editing/pasteboard/drag-and-drop-color-input-events.html [ Skip ]
webkit.org/b/188853 http/tests/security/contentSecurityPolicy/userAgentShadowDOM/allow-video.html [ Crash Pass ]
Modified: trunk/Source/WebCore/ChangeLog (236378 => 236379)
--- trunk/Source/WebCore/ChangeLog 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/ChangeLog 2018-09-22 01:03:48 UTC (rev 236379)
@@ -1,3 +1,38 @@
+2018-09-21 Justin Michaud <justin_mich...@apple.com>
+
+ Implement initialValue support for CSS Custom Properties and Values API
+ https://bugs.webkit.org/show_bug.cgi?id=189819
+
+ Reviewed by Simon Fraser.
+
+ * css/CSSComputedStyleDeclaration.cpp:
+ (WebCore::ComputedStyleExtractor::customPropertyValue):
+ * css/CSSCustomPropertyValue.cpp:
+ (WebCore::CSSCustomPropertyValue::resolveVariableReferences const):
+ * css/CSSCustomPropertyValue.h:
+ * css/CSSRegisteredCustomProperty.h:
+ * css/CSSVariableData.cpp:
+ (WebCore::CSSVariableData::resolveVariableFallback const):
+ (WebCore::CSSVariableData::resolveVariableReference const):
+ (WebCore::CSSVariableData::resolveVariableReferences const):
+ (WebCore::CSSVariableData::resolveTokenRange const):
+ * css/CSSVariableData.h:
+ * css/DOMCSSRegisterCustomProperty.cpp:
+ (WebCore::DOMCSSRegisterCustomProperty::registerProperty):
+ * css/DOMCSSRegisterCustomProperty.h:
+ * css/DOMCSSRegisterCustomProperty.idl:
+ * css/StyleResolver.cpp:
+ (WebCore::StyleResolver::resolvedVariableValue):
+ (WebCore::StyleResolver::applyCascadedProperties):
+ * css/parser/CSSParser.cpp:
+ (WebCore::CSSParser::parseValueWithVariableReferences):
+ * css/parser/CSSParser.h:
+ * dom/Document.h:
+ (WebCore::Document::getCSSRegisteredCustomPropertySet const):
+ * rendering/style/RenderStyle.cpp:
+ (WebCore::RenderStyle::checkVariablesInCustomProperties):
+ * rendering/style/RenderStyle.h:
+
2018-09-21 Dean Jackson <d...@apple.com>
Add PointerEvent, plus feature flag, plus Web Platform Tests
Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (236378 => 236379)
--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -2624,7 +2624,15 @@
if (!style)
return nullptr;
- return style->customProperties().get(propertyName);
+ auto* value = style->customProperties().get(propertyName);
+ if (value)
+ return value;
+
+ auto* registered = styledElement->document().getCSSRegisteredCustomPropertySet().get(propertyName);
+ if (registered && registered->initialValue)
+ return registered->initialValue;
+
+ return nullptr;
}
String ComputedStyleExtractor::customPropertyText(const String& propertyName)
Modified: trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp (236378 => 236379)
--- trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -37,7 +37,7 @@
return true;
}
-void CSSCustomPropertyValue::resolveVariableReferences(const CustomPropertyValueMap& customProperties, Vector<Ref<CSSCustomPropertyValue>>& resolvedValues) const
+void CSSCustomPropertyValue::resolveVariableReferences(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, Vector<Ref<CSSCustomPropertyValue>>& resolvedValues) const
{
ASSERT(containsVariables());
if (!m_value)
@@ -44,7 +44,7 @@
return;
ASSERT(m_value->needsVariableResolution());
- RefPtr<CSSVariableData> resolvedData = m_value->resolveVariableReferences(customProperties);
+ RefPtr<CSSVariableData> resolvedData = m_value->resolveVariableReferences(customProperties, registeredProperties);
if (resolvedData)
resolvedValues.append(CSSCustomPropertyValue::createWithVariableData(m_name, resolvedData.releaseNonNull()));
else
Modified: trunk/Source/WebCore/css/CSSCustomPropertyValue.h (236378 => 236379)
--- trunk/Source/WebCore/css/CSSCustomPropertyValue.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/CSSCustomPropertyValue.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -25,6 +25,7 @@
#pragma once
+#include "CSSRegisteredCustomProperty.h"
#include "CSSValue.h"
#include "CSSVariableData.h"
#include <wtf/RefPtr.h>
@@ -70,7 +71,7 @@
bool containsVariables() const { return m_containsVariables; }
bool checkVariablesForCycles(const AtomicString& name, CustomPropertyValueMap&, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const;
- void resolveVariableReferences(const CustomPropertyValueMap&, Vector<Ref<CSSCustomPropertyValue>>&) const;
+ void resolveVariableReferences(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, Vector<Ref<CSSCustomPropertyValue>>&) const;
CSSValueID valueID() const { return m_valueId; }
CSSVariableData* value() const { return m_value.get(); }
Modified: trunk/Source/WebCore/css/CSSRegisteredCustomProperty.h (236378 => 236379)
--- trunk/Source/WebCore/css/CSSRegisteredCustomProperty.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/CSSRegisteredCustomProperty.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -29,9 +29,14 @@
namespace WebCore {
+class CSSCustomPropertyValue;
+
struct CSSRegisteredCustomProperty {
const String name;
- /* TODO syntax, inherits, initialValue */
+ /* TODO syntax, inherits */
+ const RefPtr<CSSCustomPropertyValue> initialValue;
};
+using CSSRegisteredCustomPropertySet = HashMap<String, std::unique_ptr<CSSRegisteredCustomProperty>>;
+
}
Modified: trunk/Source/WebCore/css/CSSVariableData.cpp (236378 => 236379)
--- trunk/Source/WebCore/css/CSSVariableData.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/CSSVariableData.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -125,16 +125,16 @@
return true;
}
-bool CSSVariableData::resolveVariableFallback(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const
+bool CSSVariableData::resolveVariableFallback(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const
{
if (range.atEnd())
return false;
ASSERT(range.peek().type() == CommaToken);
range.consume();
- return resolveTokenRange(customProperties, range, result);
+ return resolveTokenRange(customProperties, registeredProperties, range, result);
}
-
-bool CSSVariableData::resolveVariableReference(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const
+
+bool CSSVariableData::resolveVariableReference(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const
{
range.consumeWhitespace();
ASSERT(range.peek().type() == IdentToken);
@@ -142,12 +142,18 @@
ASSERT(range.atEnd() || (range.peek().type() == CommaToken));
RefPtr<CSSCustomPropertyValue> property = customProperties.get(variableName);
- if (!property || !property->value())
- return resolveVariableFallback(customProperties, range, result);
+ if (!property || !property->value()) {
+ auto* registered = registeredProperties.get(variableName);
+ if (registered && registered->initialValue)
+ property = registered->initialValue;
+ else
+ return resolveVariableFallback(customProperties, registeredProperties, range, result);
+ }
+ ASSERT(property);
if (property->containsVariables()) {
// FIXME: Avoid doing this work more than once.
- RefPtr<CSSVariableData> resolvedData = property->value()->resolveVariableReferences(customProperties);
+ RefPtr<CSSVariableData> resolvedData = property->value()->resolveVariableReferences(customProperties, registeredProperties);
if (!resolvedData)
return false;
result.appendVector(resolvedData->tokens());
@@ -157,21 +163,21 @@
return true;
}
-RefPtr<CSSVariableData> CSSVariableData::resolveVariableReferences(const CustomPropertyValueMap& customProperties) const
+RefPtr<CSSVariableData> CSSVariableData::resolveVariableReferences(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties) const
{
Vector<CSSParserToken> resolvedTokens;
CSSParserTokenRange range = m_tokens;
- if (!resolveTokenRange(customProperties, range, resolvedTokens))
+ if (!resolveTokenRange(customProperties, registeredProperties, range, resolvedTokens))
return nullptr;
return CSSVariableData::createResolved(resolvedTokens, *this);
}
-bool CSSVariableData::resolveTokenRange(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const
+bool CSSVariableData::resolveTokenRange(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const
{
bool success = true;
while (!range.atEnd()) {
if (range.peek().functionId() == CSSValueVar || range.peek().functionId() == CSSValueEnv)
- success &= resolveVariableReference(customProperties, range.consumeBlock(), result);
+ success &= resolveVariableReference(customProperties, registeredProperties, range.consumeBlock(), result);
else
result.append(range.consume());
}
Modified: trunk/Source/WebCore/css/CSSVariableData.h (236378 => 236379)
--- trunk/Source/WebCore/css/CSSVariableData.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/CSSVariableData.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -31,6 +31,7 @@
#include "CSSParserToken.h"
#include "CSSParserTokenRange.h"
+#include "CSSRegisteredCustomProperty.h"
#include <wtf/HashSet.h>
#include <wtf/text/WTFString.h>
@@ -62,8 +63,8 @@
bool checkVariablesForCycles(const AtomicString& name, CustomPropertyValueMap&, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const;
- RefPtr<CSSVariableData> resolveVariableReferences(const CustomPropertyValueMap& customProperties) const;
- bool resolveTokenRange(const CustomPropertyValueMap&, CSSParserTokenRange, Vector<CSSParserToken>&) const;
+ RefPtr<CSSVariableData> resolveVariableReferences(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet&) const;
+ bool resolveTokenRange(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, CSSParserTokenRange, Vector<CSSParserToken>&) const;
private:
CSSVariableData(const CSSParserTokenRange&, bool needsVariableResolution);
@@ -82,8 +83,8 @@
template<typename CharacterType> void updateTokens(const CSSParserTokenRange&);
bool checkVariablesForCyclesWithRange(CSSParserTokenRange, CustomPropertyValueMap&, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const;
- bool resolveVariableReference(const CustomPropertyValueMap&, CSSParserTokenRange, Vector<CSSParserToken>&) const;
- bool resolveVariableFallback(const CustomPropertyValueMap&, CSSParserTokenRange, Vector<CSSParserToken>&) const;
+ bool resolveVariableReference(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, CSSParserTokenRange, Vector<CSSParserToken>&) const;
+ bool resolveVariableFallback(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, CSSParserTokenRange, Vector<CSSParserToken>&) const;
String m_backingString;
Vector<CSSParserToken> m_tokens;
Modified: trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp (236378 => 236379)
--- trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -26,7 +26,9 @@
#include "config.h"
#include "DOMCSSRegisterCustomProperty.h"
+#include "CSSCustomPropertyValue.h"
#include "CSSRegisteredCustomProperty.h"
+#include "CSSTokenizer.h"
#include "DOMCSSNamespace.h"
#include "Document.h"
#include <wtf/text/WTFString.h>
@@ -33,13 +35,18 @@
namespace WebCore {
-void DOMCSSRegisterCustomProperty::registerProperty(Document& document, const DOMCSSCustomPropertyDescriptor& descriptor)
+ExceptionOr<void> DOMCSSRegisterCustomProperty::registerProperty(Document& document, const DOMCSSCustomPropertyDescriptor& descriptor)
{
- CSSRegisteredCustomProperty property { descriptor.name };
- if (!document.registerCSSProperty(WTFMove(property))) {
- /* TODO throw JS exception */
- return;
- }
+ CSSTokenizer tokenizer(descriptor.initialValue);
+ RefPtr<CSSCustomPropertyValue> initialValue;
+ if (!tokenizer.tokenRange().atEnd())
+ initialValue = CSSCustomPropertyValue::createWithVariableData(descriptor.name, CSSVariableData::create(tokenizer.tokenRange(), false));
+
+ CSSRegisteredCustomProperty property { descriptor.name, WTFMove(initialValue) };
+ if (!document.registerCSSProperty(WTFMove(property)))
+ return Exception { InvalidModificationError, "This property has already been registered." };
+
+ return { };
}
DOMCSSRegisterCustomProperty* DOMCSSRegisterCustomProperty::from(DOMCSSNamespace& css)
Modified: trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.h (236378 => 236379)
--- trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -26,6 +26,7 @@
#pragma once
#include "DOMCSSCustomPropertyDescriptor.h"
+#include "ExceptionOr.h"
#include "Supplementable.h"
namespace WebCore {
@@ -37,7 +38,7 @@
public:
explicit DOMCSSRegisterCustomProperty(DOMCSSNamespace&) { }
- static void registerProperty(Document&, const DOMCSSCustomPropertyDescriptor&);
+ static ExceptionOr<void> registerProperty(Document&, const DOMCSSCustomPropertyDescriptor&);
private:
static DOMCSSRegisterCustomProperty* from(DOMCSSNamespace&);
Modified: trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.idl (236378 => 236379)
--- trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.idl 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.idl 2018-09-22 01:03:48 UTC (rev 236379)
@@ -26,5 +26,5 @@
[
EnabledAtRuntime=CSSCustomPropertiesAndValues
] partial interface DOMCSSNamespace {
- [CallWith=Document] static void registerProperty(DOMCSSCustomPropertyDescriptor descriptor);
+ [CallWith=Document, MayThrowException] static void registerProperty(DOMCSSCustomPropertyDescriptor descriptor);
};
Modified: trunk/Source/WebCore/css/StyleResolver.cpp (236378 => 236379)
--- trunk/Source/WebCore/css/StyleResolver.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/StyleResolver.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -1708,7 +1708,7 @@
RefPtr<CSSValue> StyleResolver::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value)
{
CSSParser parser(document());
- return parser.parseValueWithVariableReferences(propID, value, m_state.style()->customProperties(), m_state.style()->direction(), m_state.style()->writingMode());
+ return parser.parseValueWithVariableReferences(propID, value, m_state.style()->customProperties(), document().getCSSRegisteredCustomPropertySet(), m_state.style()->direction(), m_state.style()->writingMode());
}
RefPtr<StyleImage> StyleResolver::styleImage(CSSValue& value)
@@ -2285,7 +2285,7 @@
}
if (firstProperty == CSSPropertyCustom)
- m_state.style()->checkVariablesInCustomProperties();
+ m_state.style()->checkVariablesInCustomProperties(document().getCSSRegisteredCustomPropertySet());
}
} // namespace WebCore
Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (236378 => 236379)
--- trunk/Source/WebCore/css/parser/CSSParser.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -175,7 +175,7 @@
CSSParserImpl::parseDeclarationListForInspector(string, context, observer);
}
-RefPtr<CSSValue> CSSParser::parseValueWithVariableReferences(CSSPropertyID propID, const CSSValue& value, const CustomPropertyValueMap& customProperties, TextDirection direction, WritingMode writingMode)
+RefPtr<CSSValue> CSSParser::parseValueWithVariableReferences(CSSPropertyID propID, const CSSValue& value, const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, TextDirection direction, WritingMode writingMode)
{
if (value.isPendingSubstitutionValue()) {
// FIXME: Should have a resolvedShorthands cache to stop this from being done
@@ -189,7 +189,7 @@
ASSERT(variableData);
Vector<CSSParserToken> resolvedTokens;
- if (!variableData->resolveTokenRange(customProperties, variableData->tokens(), resolvedTokens))
+ if (!variableData->resolveTokenRange(customProperties, registeredProperties, variableData->tokens(), resolvedTokens))
return nullptr;
ParsedPropertyVector parsedProperties;
@@ -210,7 +210,7 @@
ASSERT(variableData);
Vector<CSSParserToken> resolvedTokens;
- if (!variableData->resolveTokenRange(customProperties, variableData->tokens(), resolvedTokens))
+ if (!variableData->resolveTokenRange(customProperties, registeredProperties, variableData->tokens(), resolvedTokens))
return nullptr;
return CSSPropertyParser::parseSingleValue(propID, resolvedTokens, m_context);
Modified: trunk/Source/WebCore/css/parser/CSSParser.h (236378 => 236379)
--- trunk/Source/WebCore/css/parser/CSSParser.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/css/parser/CSSParser.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -23,6 +23,7 @@
#pragma once
#include "CSSParserContext.h"
+#include "CSSRegisteredCustomProperty.h"
#include "CSSValue.h"
#include "WritingMode.h"
#include <wtf/text/WTFString.h>
@@ -75,7 +76,7 @@
void parseSelector(const String&, CSSSelectorList&);
- RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, const CustomPropertyValueMap& customProperties, TextDirection, WritingMode);
+ RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, TextDirection, WritingMode);
static Color parseColor(const String&, bool strict = false);
static Color parseSystemColor(const String&, const CSSParserContext*);
Modified: trunk/Source/WebCore/dom/Document.h (236378 => 236379)
--- trunk/Source/WebCore/dom/Document.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/dom/Document.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -1492,6 +1492,7 @@
void updateMainArticleElementAfterLayout();
bool hasMainArticleElement() const { return !!m_mainArticleElement; }
+ const CSSRegisteredCustomPropertySet& getCSSRegisteredCustomPropertySet() const { return m_CSSRegisteredPropertySet; }
bool registerCSSProperty(CSSRegisteredCustomProperty&&);
void setAsRunningUserScripts() { m_isRunningUserScripts = true; }
@@ -2026,7 +2027,7 @@
std::unique_ptr<UserGestureIndicator> m_temporaryUserGesture;
- HashMap<String, std::unique_ptr<CSSRegisteredCustomProperty>> m_CSSRegisteredPropertySet;
+ CSSRegisteredCustomPropertySet m_CSSRegisteredPropertySet;
bool m_isRunningUserScripts { false };
};
Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (236378 => 236379)
--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp 2018-09-22 01:03:48 UTC (rev 236379)
@@ -2242,7 +2242,7 @@
return filterOperations.size() == 1 && filterOperations.at(0)->type() == FilterOperation::REFERENCE;
}
-void RenderStyle::checkVariablesInCustomProperties()
+void RenderStyle::checkVariablesInCustomProperties(const CSSRegisteredCustomPropertySet& registeredProperties)
{
if (!m_rareInheritedData->customProperties->containsVariables)
return;
@@ -2273,7 +2273,7 @@
for (auto entry : customProperties) {
if (!entry.value->containsVariables())
continue;
- entry.value->resolveVariableReferences(customProperties, resolvedValues);
+ entry.value->resolveVariableReferences(customProperties, registeredProperties, resolvedValues);
}
// With all results computed, we can now mutate our table to eliminate the variables and
Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (236378 => 236379)
--- trunk/Source/WebCore/rendering/style/RenderStyle.h 2018-09-22 00:51:47 UTC (rev 236378)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h 2018-09-22 01:03:48 UTC (rev 236379)
@@ -792,7 +792,7 @@
ApplePayButtonType applePayButtonType() const { return static_cast<ApplePayButtonType>(m_rareNonInheritedData->applePayButtonType); }
#endif
- void checkVariablesInCustomProperties();
+ void checkVariablesInCustomProperties(const CSSRegisteredCustomPropertySet&);
// attribute setter methods