summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/build/scripts/core/css/templates/cssom_keywords.cc.tmpl
blob: 59c505707216362d3a3b662a6a531398b8f5009e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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.

{% from 'templates/macros.tmpl' import source_files_for_generated_file %}
{{source_files_for_generated_file(template_file, input_files)}}

#include "third_party/blink/renderer/core/css/cssom/cssom_keywords.h"

#include "third_party/blink/renderer/core/css/css_property_id_templates.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"

namespace blink {

bool CSSOMKeywords::ValidKeywordForProperty(CSSPropertyID id,
                                            const CSSKeywordValue& keyword) {
  CSSValueID valueID = keyword.KeywordValueID();
  if (!IsValidCSSValueID(valueID)) {
    return false;
  }

  if (css_parsing_utils::IsCSSWideKeyword(valueID)) {
    // TODO(crbug.com/1310761): Support CSS-wide keywords in custom props.
    return id != CSSPropertyID::kVariable;
  }

  switch (id) {
  {% for property in properties if property.keywordIDs and 'Keyword' in property.typedom_types %}
  case CSSPropertyID::{{property.enum_key}}: {
    switch (valueID) {
    {% for keywordValueID in property.keywordIDs %}
    case CSSValueID::{{keywordValueID}}:
    {% endfor %}
      return true;
    default:
      return false;
    }
  }
  {% endfor %}
  default:
    return false;
  }
}

} // namespace blink