summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/build/scripts/core/css/templates/style_property_shorthand.cc.tmpl
blob: f17e0f58f036f7f5ab4498f9f898195950426a98 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
 * Copyright (C) 2013 Intel Corporation. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

{% 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/style_property_shorthand.h"

#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"

namespace blink {
{% for property in properties %}

const StylePropertyShorthand& {{property.name.to_lower_camel_case()}}Shorthand() {
  static const CSSProperty* {{property.name.to_lower_camel_case()}}Properties[] = {
    {% for longhand_id in property.longhand_property_ids %}
    &Get{{longhand_id}}(),
    {% endfor %}
  };

  static StylePropertyShorthand {{property.name.to_lower_camel_case()}}Longhands(
    {{property.property_id}},
    {{property.name.to_lower_camel_case()}}Properties,
    arraysize({{property.name.to_lower_camel_case()}}Properties));
  return {{property.name.to_lower_camel_case()}}Longhands;
}
{% endfor %}

// TODO(ericwilligers): Retire this when offset-position and offset-anchor ship
const StylePropertyShorthand& offsetShorthandWithoutPositionAnchor() {
  static const CSSProperty* offsetProperties[] = {
    &GetCSSPropertyOffsetPath(),
    &GetCSSPropertyOffsetDistance(),
    &GetCSSPropertyOffsetRotate(),
  };
  DEFINE_STATIC_LOCAL(StylePropertyShorthand, offsetLonghands, (CSSPropertyOffset, offsetProperties, arraysize(offsetProperties)));
  return offsetLonghands;
}

// Returns an empty list if the property is not a shorthand
const StylePropertyShorthand& shorthandForProperty(CSSPropertyID propertyID) {
  // FIXME: We shouldn't switch between shorthand/not shorthand based on a runtime flag
  static StylePropertyShorthand emptyShorthand;

  if (propertyID == CSSPropertyOffset &&
      !RuntimeEnabledFeatures::CSSOffsetPositionAnchorEnabled())
    return offsetShorthandWithoutPositionAnchor();
  switch (propertyID) {
    {% for property in properties %}
    case {{property.property_id}}:
      return {{property.name.to_lower_camel_case()}}Shorthand();
    {% endfor %}
    default: {
      return emptyShorthand;
    }
  }
}

void getMatchingShorthandsForLonghand(
    CSSPropertyID propertyID, Vector<StylePropertyShorthand, 4>* result) {
  DCHECK(!result->size());
  switch (propertyID) {
  {% for longhand_id, shorthands in longhands_dictionary.items() %}
    case {{longhand_id}}: {
      {% for shorthand in shorthands %}
      if (CSSProperty::Get({{shorthand.property_id}}).IsEnabled())
        result->UncheckedAppend({{shorthand.name.to_lower_camel_case()}}Shorthand());
      {% endfor %}
      break;
    }
    {% endfor %}
    default:
      break;
  }
}

} // namespace blink