Chromium Code Reviews| Index: third_party/WebKit/Source/build/scripts/templates/CSSPropertyDescriptor.cpp.tmpl |
| diff --git a/third_party/WebKit/Source/build/scripts/templates/CSSPropertyDescriptor.cpp.tmpl b/third_party/WebKit/Source/build/scripts/templates/CSSPropertyDescriptor.cpp.tmpl |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d8a1bd99e3cc9c854f8157f40a4c3d00b9e40bfa |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/build/scripts/templates/CSSPropertyDescriptor.cpp.tmpl |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#include "core/css/properties/CSSPropertyDescriptor.h" |
| + |
| +{% for api_class in api_classes %} |
| +#include "core/css/properties/{{api_class.classname}}.h" |
| +{% endfor %} |
| + |
| +namespace blink { |
| + |
| +// Initialises a CSSPropertyDescriptor. When functions are added to |
| +// CSSPropertyAPI, also add them to the struct initaliser below. |
| +#define GET_DESCRIPTOR(X) \ |
| + { X::parseSingleValue, true } |
| + |
| +// Initialises an invalid CSSPropertyDescriptor. When functions are added to |
| +// CSSPropertyAPI, add a nullptr to represent their function pointers in the |
| +// struct initaliser. |
| +#define GET_INVALID_DESCRIPTOR() \ |
| + { 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 :)
|
| + |
| +static_assert( |
| + std::is_pod<CSSPropertyDescriptor>::value, |
| + "CSSPropertyDescriptor must be a POD to support using initializer lists."); |
| + |
| +static CSSPropertyDescriptor cssPropertyDescriptors[] = { |
| + GET_INVALID_DESCRIPTOR(), |
| + {% for api_class in api_classes %} |
| + GET_DESCRIPTOR({{api_class.classname}}), |
| + {% endfor %} |
| +}; |
| + |
| +const CSSPropertyDescriptor& CSSPropertyDescriptor::get(CSSPropertyID id) { |
| + // TODO(aazzam): We are currently using hard-coded indexes for |
| + // cssPropertyDescriptor since we have only implemented a few properties. |
| + // Later, generate this switch statement, or alternatively return |
| + // cssPropertyDescriptors[id], and generate the cssPropertyDescriptors array |
| + // to hold invalid descriptors for methods which haven't been implemented yet. |
| + switch (id) { |
| + {% for api_class in api_classes %} |
| + {% for propertyID in api_class.propertyIDs %} |
| + case {{propertyID}}: |
| + {% endfor %} |
| + return cssPropertyDescriptors[{{api_class.index}}]; |
| + {% endfor %} |
| + default: |
| + return cssPropertyDescriptors[0]; |
| + } |
| +} |
| + |
| +} // namespace blink |