Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/core/css/PropertyRegistration.cpp

Issue 2654783004: Store PropertyRegistry::Registrations on CSSInterpolationTypes for registered custom properties (Closed)
Patch Set: Rebased Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/PropertyRegistration.h" 5 #include "core/css/PropertyRegistration.h"
6 6
7 #include "core/animation/CSSInterpolationTypesMap.h"
7 #include "core/css/CSSStyleSheet.h" 8 #include "core/css/CSSStyleSheet.h"
8 #include "core/css/CSSSyntaxDescriptor.h" 9 #include "core/css/CSSSyntaxDescriptor.h"
9 #include "core/css/CSSValueList.h" 10 #include "core/css/CSSValueList.h"
10 #include "core/css/CSSVariableReferenceValue.h" 11 #include "core/css/CSSVariableReferenceValue.h"
11 #include "core/css/PropertyDescriptor.h" 12 #include "core/css/PropertyDescriptor.h"
12 #include "core/css/PropertyRegistry.h" 13 #include "core/css/PropertyRegistry.h"
13 #include "core/css/StyleSheetContents.h" 14 #include "core/css/StyleSheetContents.h"
14 #include "core/css/parser/CSSParserContext.h" 15 #include "core/css/parser/CSSParserContext.h"
15 #include "core/css/parser/CSSTokenizer.h" 16 #include "core/css/parser/CSSTokenizer.h"
16 #include "core/css/parser/CSSVariableParser.h" 17 #include "core/css/parser/CSSVariableParser.h"
17 #include "core/css/resolver/StyleBuilderConverter.h" 18 #include "core/css/resolver/StyleBuilderConverter.h"
18 #include "core/dom/Document.h" 19 #include "core/dom/Document.h"
19 #include "core/dom/ExceptionCode.h" 20 #include "core/dom/ExceptionCode.h"
20 #include "core/dom/StyleChangeReason.h" 21 #include "core/dom/StyleChangeReason.h"
21 22
22 namespace blink { 23 namespace blink {
23 24
25 static InterpolationTypes setRegistrationOnCSSInterpolationTypes(
26 CSSInterpolationTypes cssInterpolationTypes,
27 const PropertyRegistration& registration) {
28 InterpolationTypes result;
29 for (auto& cssInterpolationType : cssInterpolationTypes) {
30 cssInterpolationType->setCustomPropertyRegistration(registration);
31 result.push_back(std::move(cssInterpolationType));
32 }
33 return result;
34 }
35
36 PropertyRegistration::PropertyRegistration(
37 const CSSSyntaxDescriptor& syntax,
38 bool inherits,
39 const CSSValue* initial,
40 PassRefPtr<CSSVariableData> initialVariableData,
41 CSSInterpolationTypes cssInterpolationTypes)
42 : m_syntax(syntax),
43 m_inherits(inherits),
44 m_initial(initial),
45 m_initialVariableData(initialVariableData),
46 m_interpolationTypes(setRegistrationOnCSSInterpolationTypes(
47 std::move(cssInterpolationTypes),
48 *this)) {}
49
24 static bool computationallyIndependent(const CSSValue& value) { 50 static bool computationallyIndependent(const CSSValue& value) {
25 DCHECK(!value.isCSSWideKeyword()); 51 DCHECK(!value.isCSSWideKeyword());
26 52
27 if (value.isVariableReferenceValue()) 53 if (value.isVariableReferenceValue())
28 return !toCSSVariableReferenceValue(value) 54 return !toCSSVariableReferenceValue(value)
29 .variableDataValue() 55 .variableDataValue()
30 ->needsVariableResolution(); 56 ->needsVariableResolution();
31 57
32 if (value.isValueList()) { 58 if (value.isValueList()) {
33 for (const CSSValue* innerValue : toCSSValueList(value)) { 59 for (const CSSValue* innerValue : toCSSValueList(value)) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 112 }
87 113
88 CSSSyntaxDescriptor syntaxDescriptor(descriptor.syntax()); 114 CSSSyntaxDescriptor syntaxDescriptor(descriptor.syntax());
89 if (!syntaxDescriptor.isValid()) { 115 if (!syntaxDescriptor.isValid()) {
90 exceptionState.throwDOMException( 116 exceptionState.throwDOMException(
91 SyntaxError, 117 SyntaxError,
92 "The syntax provided is not a valid custom property syntax."); 118 "The syntax provided is not a valid custom property syntax.");
93 return; 119 return;
94 } 120 }
95 121
96 InterpolationTypes interpolationTypes = 122 CSSInterpolationTypes cssInterpolationTypes =
97 syntaxDescriptor.createInterpolationTypes(atomicName); 123 CSSInterpolationTypesMap::createCSSInterpolationTypesForSyntax(
124 atomicName, syntaxDescriptor);
98 125
99 if (descriptor.hasInitialValue()) { 126 if (descriptor.hasInitialValue()) {
100 CSSTokenizer tokenizer(descriptor.initialValue()); 127 CSSTokenizer tokenizer(descriptor.initialValue());
101 bool isAnimationTainted = false; 128 bool isAnimationTainted = false;
102 const CSSValue* initial = syntaxDescriptor.parse( 129 const CSSValue* initial = syntaxDescriptor.parse(
103 tokenizer.tokenRange(), 130 tokenizer.tokenRange(),
104 document->elementSheet().contents()->parserContext(), 131 document->elementSheet().contents()->parserContext(),
105 isAnimationTainted); 132 isAnimationTainted);
106 if (!initial) { 133 if (!initial) {
107 exceptionState.throwDOMException( 134 exceptionState.throwDOMException(
108 SyntaxError, 135 SyntaxError,
109 "The initial value provided does not parse for the given syntax."); 136 "The initial value provided does not parse for the given syntax.");
110 return; 137 return;
111 } 138 }
112 if (!computationallyIndependent(*initial)) { 139 if (!computationallyIndependent(*initial)) {
113 exceptionState.throwDOMException( 140 exceptionState.throwDOMException(
114 SyntaxError, 141 SyntaxError,
115 "The initial value provided is not computationally independent."); 142 "The initial value provided is not computationally independent.");
116 return; 143 return;
117 } 144 }
118 initial = 145 initial =
119 &StyleBuilderConverter::convertRegisteredPropertyInitialValue(*initial); 146 &StyleBuilderConverter::convertRegisteredPropertyInitialValue(*initial);
120 RefPtr<CSSVariableData> initialVariableData = CSSVariableData::create( 147 RefPtr<CSSVariableData> initialVariableData = CSSVariableData::create(
121 tokenizer.tokenRange(), isAnimationTainted, false); 148 tokenizer.tokenRange(), isAnimationTainted, false);
122 registry.registerProperty( 149 registry.registerProperty(
123 atomicName, syntaxDescriptor, descriptor.inherits(), initial, 150 atomicName, syntaxDescriptor, descriptor.inherits(), initial,
124 std::move(initialVariableData), std::move(interpolationTypes)); 151 std::move(initialVariableData), std::move(cssInterpolationTypes));
125 } else { 152 } else {
126 if (!syntaxDescriptor.isTokenStream()) { 153 if (!syntaxDescriptor.isTokenStream()) {
127 exceptionState.throwDOMException( 154 exceptionState.throwDOMException(
128 SyntaxError, 155 SyntaxError,
129 "An initial value must be provided if the syntax is not '*'"); 156 "An initial value must be provided if the syntax is not '*'");
130 return; 157 return;
131 } 158 }
132 registry.registerProperty(atomicName, syntaxDescriptor, 159 registry.registerProperty(atomicName, syntaxDescriptor,
133 descriptor.inherits(), nullptr, nullptr, 160 descriptor.inherits(), nullptr, nullptr,
134 std::move(interpolationTypes)); 161 std::move(cssInterpolationTypes));
135 } 162 }
136 163
137 // TODO(timloh): Invalidate only elements with this custom property set 164 // TODO(timloh): Invalidate only elements with this custom property set
138 document->setNeedsStyleRecalc(SubtreeStyleChange, 165 document->setNeedsStyleRecalc(SubtreeStyleChange,
139 StyleChangeReasonForTracing::create( 166 StyleChangeReasonForTracing::create(
140 StyleChangeReason::PropertyRegistration)); 167 StyleChangeReason::PropertyRegistration));
141 } 168 }
142 169
143 } // namespace blink 170 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/PropertyRegistration.h ('k') | third_party/WebKit/Source/core/css/PropertyRegistry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698