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 | |
5 #include "core/css/properties/CSSPropertyDescriptor.h" | 4 #include "core/css/properties/CSSPropertyDescriptor.h" |
6 | 5 |
7 #include "core/css/properties/CSSPropertyAPIPadding.h" | 6 {% for api_class in api_classes %} |
| 7 #include "core/css/properties/{{api_class.classname}}.h" |
| 8 {% endfor %} |
8 | 9 |
9 namespace blink { | 10 namespace blink { |
10 | 11 |
11 // Initialises a CSSPropertyDescriptor. When functions are added to | |
12 // CSSPropertyAPI, also add them to the struct initaliser below. | |
13 #define GET_DESCRIPTOR(X) \ | |
14 { X::parseSingleValue, true } | |
15 | |
16 // Initialises an invalid CSSPropertyDescriptor. When functions are added to | |
17 // CSSPropertyAPI, add a nullptr to represent their function pointers in the | |
18 // struct initaliser. | |
19 #define GET_INVALID_DESCRIPTOR() \ | |
20 { nullptr, false } | |
21 | |
22 static_assert( | 12 static_assert( |
23 std::is_pod<CSSPropertyDescriptor>::value, | 13 std::is_pod<CSSPropertyDescriptor>::value, |
24 "CSSPropertyDescriptor must be a POD to support using initializer lists."); | 14 "CSSPropertyDescriptor must be a POD to support using initializer lists."); |
25 | 15 |
26 static CSSPropertyDescriptor cssPropertyDescriptors[] = { | 16 static CSSPropertyDescriptor cssPropertyDescriptors[] = { |
27 GET_INVALID_DESCRIPTOR(), GET_DESCRIPTOR(CSSPropertyAPIWebkitPadding), | 17 // An invalid CSSPropertyDescriptor. When functions are added to |
| 18 // CSSPropertyAPI, add a nullptr to represent their function pointers in the |
| 19 // struct initaliser. |
| 20 { nullptr, false }, |
| 21 {% for api_class in api_classes %} |
| 22 // For each class we add a CSSPropertyDescriptor to the array. When function
s |
| 23 // are added to CSSPropertyAPI, also add them to the struct initaliser below
. |
| 24 { {{api_class.classname}}::parseSingleValue, true } |
| 25 {% endfor %} |
28 }; | 26 }; |
29 | 27 |
30 const CSSPropertyDescriptor& CSSPropertyDescriptor::get(CSSPropertyID id) { | 28 const CSSPropertyDescriptor& CSSPropertyDescriptor::get(CSSPropertyID id) { |
31 // TODO(aazzam): We are currently using hard-coded indexes for | 29 // TODO(aazzam): We are currently using hard-coded indexes for |
32 // cssPropertyDescriptor since we have only implemented a few properties. | 30 // cssPropertyDescriptor since we have only implemented a few properties. |
33 // Later, generate this switch statement, or alternatively return | 31 // Later, generate this switch statement, or alternatively return |
34 // cssPropertyDescriptors[id], and generate the cssPropertyDescriptors array | 32 // cssPropertyDescriptors[id], and generate the cssPropertyDescriptors array |
35 // to hold invalid descriptors for methods which haven't been implemented yet. | 33 // to hold invalid descriptors for methods which haven't been implemented yet. |
36 switch (id) { | 34 switch (id) { |
37 case CSSPropertyWebkitPaddingEnd: | 35 {% for api_class in api_classes %} |
38 return cssPropertyDescriptors[1]; | 36 {% for property_id in api_class.property_ids %} |
39 case CSSPropertyWebkitPaddingStart: | 37 case {{property_id}}: |
40 return cssPropertyDescriptors[1]; | 38 {% endfor %} |
41 case CSSPropertyWebkitPaddingBefore: | 39 return cssPropertyDescriptors[{{api_class.index}}]; |
42 return cssPropertyDescriptors[1]; | 40 {% endfor %} |
43 case CSSPropertyWebkitPaddingAfter: | |
44 return cssPropertyDescriptors[1]; | |
45 default: | 41 default: |
46 return cssPropertyDescriptors[0]; | 42 return cssPropertyDescriptors[0]; |
47 } | 43 } |
48 } | 44 } |
49 | 45 |
50 } // namespace blink | 46 } // namespace blink |
OLD | NEW |