Chromium Code Reviews| 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) |
|
alancutter (OOO until 2018)
2016/09/20 00:15:55
What happens to CSS wide keywords? Either check th
Timothy Loh
2016/09/21 01:12:04
This is tested in register-property-syntax-parsing
| |
| 19 { | 20 { |
| 20 // TODO(timloh): Implement this | 21 if (value.isVariableReferenceValue()) |
| 22 return !toCSSVariableReferenceValue(value).variableDataValue()->needsVar iableResolution(); | |
|
sashab
2016/09/19 23:25:03
Can variables not have percentages etc in them? It
alancutter (OOO until 2018)
2016/09/20 00:15:55
It's very weird to be checking needsVariableResolu
Timothy Loh
2016/09/21 01:12:04
If there are variable references then this returns
Timothy Loh
2016/09/21 01:12:04
There's no CSSTokenStreamValue class -- CSSVariabl
| |
| 23 | |
| 24 // TODO(timloh): Images and transform-function values can also contain lengt hs. | |
|
sashab
2016/09/19 23:25:03
Are there tests that fail because of this?
Timothy Loh
2016/09/21 01:12:04
Nope I'll add them when I resolve the TODO.
| |
| 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()) | |
|
sashab
2016/09/19 23:25:03
Just to prevent the kind of mess we currently have
alancutter (OOO until 2018)
2016/09/20 00:15:55
I think it's preferred to exit functions early on
Timothy Loh
2016/09/21 01:12:04
I'll change this, it probably made more sense befo
| |
| 35 return true; | |
| 36 | |
| 37 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); | |
| 38 if (!primitiveValue.isLength() && !primitiveValue.isCalculatedPercentageWith Length()) | |
| 39 return true; | |
| 40 | |
| 41 CSSPrimitiveValue::CSSLengthArray lengthArray; | |
| 42 primitiveValue.accumulateLengthArray(lengthArray); | |
| 43 for (size_t i = 0; i < lengthArray.values.size(); i++) { | |
| 44 if (lengthArray.typeFlags.get(i) | |
| 45 && i != CSSPrimitiveValue::UnitTypePixels | |
| 46 && i != CSSPrimitiveValue::UnitTypePercentage) | |
| 47 return false; | |
| 48 } | |
| 21 return true; | 49 return true; |
| 22 } | 50 } |
| 23 | 51 |
| 24 void PropertyRegistration::registerProperty(ExecutionContext* executionContext, const PropertyDescriptor& descriptor, ExceptionState& exceptionState) | 52 void PropertyRegistration::registerProperty(ExecutionContext* executionContext, const PropertyDescriptor& descriptor, ExceptionState& exceptionState) |
| 25 { | 53 { |
| 26 // Bindings code ensures these are set. | 54 // Bindings code ensures these are set. |
| 27 DCHECK(descriptor.hasName()); | 55 DCHECK(descriptor.hasName()); |
| 28 DCHECK(descriptor.hasInherits()); | 56 DCHECK(descriptor.hasInherits()); |
| 29 DCHECK(descriptor.hasSyntax()); | 57 DCHECK(descriptor.hasSyntax()); |
| 30 | 58 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 46 exceptionState.throwDOMException(SyntaxError, "The syntax provided is no t a valid custom property syntax."); | 74 exceptionState.throwDOMException(SyntaxError, "The syntax provided is no t a valid custom property syntax."); |
| 47 return; | 75 return; |
| 48 } | 76 } |
| 49 | 77 |
| 50 if (descriptor.hasInitialValue()) { | 78 if (descriptor.hasInitialValue()) { |
| 51 const CSSValue* initial = syntaxDescriptor.parse(descriptor.initialValue ()); | 79 const CSSValue* initial = syntaxDescriptor.parse(descriptor.initialValue ()); |
| 52 if (!initial) { | 80 if (!initial) { |
| 53 exceptionState.throwDOMException(SyntaxError, "The initial value pro vided does not parse for the given syntax."); | 81 exceptionState.throwDOMException(SyntaxError, "The initial value pro vided does not parse for the given syntax."); |
| 54 return; | 82 return; |
| 55 } | 83 } |
| 56 if (!computationallyIdempotent(*initial)) { | 84 if (!computationallyIndependent(*initial)) { |
| 57 exceptionState.throwDOMException(SyntaxError, "The initial value pro vided is not computationally idempotent."); | 85 exceptionState.throwDOMException(SyntaxError, "The initial value pro vided is not computationally independent."); |
| 58 return; | 86 return; |
| 59 } | 87 } |
| 60 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher its(), initial); | 88 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher its(), initial); |
| 61 } else { | 89 } else { |
| 62 if (!syntaxDescriptor.isTokenStream()) { | 90 if (!syntaxDescriptor.isTokenStream()) { |
| 63 exceptionState.throwDOMException(SyntaxError, "An initial value must be provided if the syntax is not '*'"); | 91 exceptionState.throwDOMException(SyntaxError, "An initial value must be provided if the syntax is not '*'"); |
| 64 return; | 92 return; |
| 65 } | 93 } |
| 66 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher its(), nullptr); | 94 registry.registerProperty(atomicName, syntaxDescriptor, descriptor.inher its(), nullptr); |
| 67 } | 95 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 78 if (!registry.registration(atomicProperty)) { | 106 if (!registry.registration(atomicProperty)) { |
| 79 exceptionState.throwDOMException(NotFoundError, "CSS.unregisterProperty( ) called with non-registered property " + property); | 107 exceptionState.throwDOMException(NotFoundError, "CSS.unregisterProperty( ) called with non-registered property " + property); |
| 80 return; | 108 return; |
| 81 } | 109 } |
| 82 registry.unregisterProperty(atomicProperty); | 110 registry.unregisterProperty(atomicProperty); |
| 83 | 111 |
| 84 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin g::create(StyleChangeReason::PropertyUnregistration)); | 112 document->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracin g::create(StyleChangeReason::PropertyUnregistration)); |
| 85 } | 113 } |
| 86 | 114 |
| 87 } // namespace blink | 115 } // namespace blink |
| OLD | NEW |