| 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/CSSValueList.h" |
| 9 #include "core/css/CSSVariableReferenceValue.h" | 9 #include "core/css/CSSVariableReferenceValue.h" |
| 10 #include "core/css/PropertyDescriptor.h" | 10 #include "core/css/PropertyDescriptor.h" |
| 11 #include "core/css/PropertyRegistry.h" | 11 #include "core/css/PropertyRegistry.h" |
| 12 #include "core/css/parser/CSSTokenizer.h" |
| 12 #include "core/css/parser/CSSVariableParser.h" | 13 #include "core/css/parser/CSSVariableParser.h" |
| 13 #include "core/dom/Document.h" | 14 #include "core/dom/Document.h" |
| 14 #include "core/dom/ExceptionCode.h" | 15 #include "core/dom/ExceptionCode.h" |
| 15 #include "core/dom/StyleChangeReason.h" | 16 #include "core/dom/StyleChangeReason.h" |
| 16 | 17 |
| 17 namespace blink { | 18 namespace blink { |
| 18 | 19 |
| 19 static bool computationallyIndependent(const CSSValue& value) | 20 static bool computationallyIndependent(const CSSValue& value) |
| 20 { | 21 { |
| 21 DCHECK(!value.isCSSWideKeyword()); | 22 DCHECK(!value.isCSSWideKeyword()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 | 75 |
| 75 CSSSyntaxDescriptor syntaxDescriptor(descriptor.syntax()); | 76 CSSSyntaxDescriptor syntaxDescriptor(descriptor.syntax()); |
| 76 if (!syntaxDescriptor.isValid()) { | 77 if (!syntaxDescriptor.isValid()) { |
| 77 exceptionState.throwDOMException(SyntaxError, "The syntax provided is no
t a valid custom property syntax."); | 78 exceptionState.throwDOMException(SyntaxError, "The syntax provided is no
t a valid custom property syntax."); |
| 78 return; | 79 return; |
| 79 } | 80 } |
| 80 | 81 |
| 81 if (descriptor.hasInitialValue()) { | 82 if (descriptor.hasInitialValue()) { |
| 82 const CSSValue* initial = syntaxDescriptor.parse(descriptor.initialValue
()); | 83 CSSTokenizer::Scope scope(descriptor.initialValue()); |
| 84 const CSSValue* initial = syntaxDescriptor.parse(scope.tokenRange()); |
| 83 if (!initial) { | 85 if (!initial) { |
| 84 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided does not parse for the given syntax."); | 86 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided does not parse for the given syntax."); |
| 85 return; | 87 return; |
| 86 } | 88 } |
| 87 if (!computationallyIndependent(*initial)) { | 89 if (!computationallyIndependent(*initial)) { |
| 88 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided is not computationally independent."); | 90 exceptionState.throwDOMException(SyntaxError, "The initial value pro
vided is not computationally independent."); |
| 89 return; | 91 return; |
| 90 } | 92 } |
| 91 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), initial); | 93 RefPtr<CSSVariableData> initialVariableData = CSSVariableData::create(sc
ope.tokenRange(), false); |
| 94 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), initial, initialVariableData.release()); |
| 92 } else { | 95 } else { |
| 93 if (!syntaxDescriptor.isTokenStream()) { | 96 if (!syntaxDescriptor.isTokenStream()) { |
| 94 exceptionState.throwDOMException(SyntaxError, "An initial value must
be provided if the syntax is not '*'"); | 97 exceptionState.throwDOMException(SyntaxError, "An initial value must
be provided if the syntax is not '*'"); |
| 95 return; | 98 return; |
| 96 } | 99 } |
| 97 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), nullptr); | 100 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher
its(), nullptr, nullptr); |
| 98 } | 101 } |
| 99 | 102 |
| 100 // TODO(timloh): Invalidate only elements with this custom property set | 103 // TODO(timloh): Invalidate only elements with this custom property set |
| 101 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::PropertyRegistration)); | 104 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::PropertyRegistration)); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void PropertyRegistration::unregisterProperty(ExecutionContext* executionContext
, const String& property, ExceptionState& exceptionState) | 107 void PropertyRegistration::unregisterProperty(ExecutionContext* executionContext
, const String& property, ExceptionState& exceptionState) |
| 105 { | 108 { |
| 106 Document* document = toDocument(executionContext); | 109 Document* document = toDocument(executionContext); |
| 107 PropertyRegistry& registry = *document->propertyRegistry(); | 110 PropertyRegistry& registry = *document->propertyRegistry(); |
| 108 AtomicString atomicProperty(property); | 111 AtomicString atomicProperty(property); |
| 109 if (!registry.registration(atomicProperty)) { | 112 if (!registry.registration(atomicProperty)) { |
| 110 exceptionState.throwDOMException(NotFoundError, "CSS.unregisterProperty(
) called with non-registered property " + property); | 113 exceptionState.throwDOMException(NotFoundError, "CSS.unregisterProperty(
) called with non-registered property " + property); |
| 111 return; | 114 return; |
| 112 } | 115 } |
| 113 registry.unregisterProperty(atomicProperty); | 116 registry.unregisterProperty(atomicProperty); |
| 114 | 117 |
| 115 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::PropertyUnregistration)); | 118 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::PropertyUnregistration)); |
| 116 } | 119 } |
| 117 | 120 |
| 118 } // namespace blink | 121 } // namespace blink |
| OLD | NEW |