Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 #include "core/css/properties/CSSPropertyDescriptor.h" | |
| 5 | |
| 6 {% for api_class in api_classes %} | |
| 7 #include "core/css/properties/{{api_class.classname}}.h" | |
| 8 {% endfor %} | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 // Initialises a CSSPropertyDescriptor. When functions are added to | |
| 13 // CSSPropertyAPI, also add them to the struct initaliser below. | |
| 14 #define GET_DESCRIPTOR(X) \ | |
| 15 { X::parseSingleValue, true } | |
| 16 | |
| 17 // Initialises an invalid CSSPropertyDescriptor. When functions are added to | |
| 18 // CSSPropertyAPI, add a nullptr to represent their function pointers in the | |
| 19 // struct initaliser. | |
| 20 #define GET_INVALID_DESCRIPTOR() \ | |
| 21 { nullptr, false } | |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Again I don't think we should use macros in jinja
aazzam
2016/12/13 05:01:09
done :)
| |
| 22 | |
| 23 static_assert( | |
| 24 std::is_pod<CSSPropertyDescriptor>::value, | |
| 25 "CSSPropertyDescriptor must be a POD to support using initializer lists."); | |
| 26 | |
| 27 static CSSPropertyDescriptor cssPropertyDescriptors[] = { | |
| 28 GET_INVALID_DESCRIPTOR(), | |
| 29 {% for api_class in api_classes %} | |
| 30 GET_DESCRIPTOR({{api_class.classname}}), | |
| 31 {% endfor %} | |
| 32 }; | |
| 33 | |
| 34 const CSSPropertyDescriptor& CSSPropertyDescriptor::get(CSSPropertyID id) { | |
| 35 // TODO(aazzam): We are currently using hard-coded indexes for | |
| 36 // cssPropertyDescriptor since we have only implemented a few properties. | |
| 37 // Later, generate this switch statement, or alternatively return | |
| 38 // cssPropertyDescriptors[id], and generate the cssPropertyDescriptors array | |
| 39 // to hold invalid descriptors for methods which haven't been implemented yet. | |
| 40 switch (id) { | |
| 41 {% for api_class in api_classes %} | |
| 42 {% for propertyID in api_class.propertyIDs %} | |
| 43 case {{propertyID}}: | |
| 44 {% endfor %} | |
| 45 return cssPropertyDescriptors[{{api_class.index}}]; | |
| 46 {% endfor %} | |
| 47 default: | |
| 48 return cssPropertyDescriptors[0]; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 } // namespace blink | |
| OLD | NEW |