OLD | NEW |
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/css/CSSSyntaxDescriptor.h" | 7 #include "core/css/CSSSyntaxDescriptor.h" |
| 8 #include "core/css/CSSValueList.h" |
8 #include "core/css/CSSVariableReferenceValue.h" | 9 #include "core/css/CSSVariableReferenceValue.h" |
9 #include "core/css/PropertyDescriptor.h" | 10 #include "core/css/PropertyDescriptor.h" |
10 #include "core/css/PropertyRegistry.h" | 11 #include "core/css/PropertyRegistry.h" |
11 #include "core/css/parser/CSSVariableParser.h" | 12 #include "core/css/parser/CSSVariableParser.h" |
12 #include "core/dom/Document.h" | 13 #include "core/dom/Document.h" |
13 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
14 #include "core/dom/StyleChangeReason.h" | 15 #include "core/dom/StyleChangeReason.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 static bool computationallyIdempotent(const CSSValue& value) | 19 static bool computationallyIndependent(const CSSValue& value) |
19 { | 20 { |
20 // TODO(timloh): Implement this | 21 DCHECK(!value.isCSSWideKeyword()); |
| 22 |
| 23 if (value.isVariableReferenceValue()) |
| 24 return !toCSSVariableReferenceValue(value).variableDataValue()->needsVar
iableResolution(); |
| 25 |
| 26 if (value.isValueList()) { |
| 27 for (const CSSValue* innerValue : toCSSValueList(value)) { |
| 28 if (!computationallyIndependent(*innerValue)) |
| 29 return false; |
| 30 } |
| 31 return true; |
| 32 } |
| 33 |
| 34 if (value.isPrimitiveValue()) { |
| 35 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 36 if (!primitiveValue.isLength() && !primitiveValue.isCalculatedPercentage
WithLength()) |
| 37 return true; |
| 38 |
| 39 CSSPrimitiveValue::CSSLengthArray lengthArray; |
| 40 primitiveValue.accumulateLengthArray(lengthArray); |
| 41 for (size_t i = 0; i < lengthArray.values.size(); i++) { |
| 42 if (lengthArray.typeFlags.get(i) |
| 43 && i != CSSPrimitiveValue::UnitTypePixels |
| 44 && i != CSSPrimitiveValue::UnitTypePercentage) |
| 45 return false; |
| 46 } |
| 47 return true; |
| 48 } |
| 49 |
| 50 // TODO(timloh): Images and transform-function values can also contain lengt
hs. |
| 51 |
21 return true; | 52 return true; |
22 } | 53 } |
23 | 54 |
24 void PropertyRegistration::registerProperty(ExecutionContext* executionContext,
const PropertyDescriptor& descriptor, ExceptionState& exceptionState) | 55 void PropertyRegistration::registerProperty(ExecutionContext* executionContext,
const PropertyDescriptor& descriptor, ExceptionState& exceptionState) |
25 { | 56 { |
26 // Bindings code ensures these are set. | 57 // Bindings code ensures these are set. |
27 DCHECK(descriptor.hasName()); | 58 DCHECK(descriptor.hasName()); |
28 DCHECK(descriptor.hasInherits()); | 59 DCHECK(descriptor.hasInherits()); |
29 DCHECK(descriptor.hasSyntax()); | 60 DCHECK(descriptor.hasSyntax()); |
30 | 61 |
(...skipping 15 matching lines...) Expand all Loading... |
46 exceptionState.throwDOMException(SyntaxError, "The syntax provided is no
t a valid custom property syntax."); | 77 exceptionState.throwDOMException(SyntaxError, "The syntax provided is no
t a valid custom property syntax."); |
47 return; | 78 return; |
48 } | 79 } |
49 | 80 |
50 if (descriptor.hasInitialValue()) { | 81 if (descriptor.hasInitialValue()) { |
51 const CSSValue* initial = syntaxDescriptor.parse(descriptor.initialValue
()); | 82 const CSSValue* initial = syntaxDescriptor.parse(descriptor.initialValue
()); |
52 if (!initial) { | 83 if (!initial) { |
53 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided does not parse for the given syntax."); | 84 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided does not parse for the given syntax."); |
54 return; | 85 return; |
55 } | 86 } |
56 if (!computationallyIdempotent(*initial)) { | 87 if (!computationallyIndependent(*initial)) { |
57 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided is not computationally idempotent."); | 88 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided is not computationally independent."); |
58 return; | 89 return; |
59 } | 90 } |
60 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), initial); | 91 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), initial); |
61 } else { | 92 } else { |
62 if (!syntaxDescriptor.isTokenStream()) { | 93 if (!syntaxDescriptor.isTokenStream()) { |
63 exceptionState.throwDOMException(SyntaxError, "An initial value must
be provided if the syntax is not '*'"); | 94 exceptionState.throwDOMException(SyntaxError, "An initial value must
be provided if the syntax is not '*'"); |
64 return; | 95 return; |
65 } | 96 } |
66 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), nullptr); | 97 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), nullptr); |
67 } | 98 } |
(...skipping 10 matching lines...) Expand all Loading... |
78 if (!registry.registration(atomicProperty)) { | 109 if (!registry.registration(atomicProperty)) { |
79 exceptionState.throwDOMException(NotFoundError, "CSS.unregisterProperty(
) called with non-registered property " + property); | 110 exceptionState.throwDOMException(NotFoundError, "CSS.unregisterProperty(
) called with non-registered property " + property); |
80 return; | 111 return; |
81 } | 112 } |
82 registry.unregisterProperty(atomicProperty); | 113 registry.unregisterProperty(atomicProperty); |
83 | 114 |
84 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::PropertyUnregistration)); | 115 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::PropertyUnregistration)); |
85 } | 116 } |
86 | 117 |
87 } // namespace blink | 118 } // namespace blink |
OLD | NEW |