summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/css/resolver/css_property_priority.h
blob: 6e5676a5756700d3c5c1c605354eb6e85d961235 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2015 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_CSS_PROPERTY_PRIORITY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_CSS_PROPERTY_PRIORITY_H_

#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"

namespace blink {

// The values of high priority properties affect the values of low priority
// properties. For example, the value of the high priority property 'font-size'
// decides the pixel value of low priority properties with 'em' units.

// TODO(sashab): Generate the methods in this file.

enum CSSPropertyPriority {
  kResolveVariables = 0,
  kAnimationPropertyPriority,
  kHighPropertyPriority,
  kLowPropertyPriority,
  kPropertyPriorityCount,
};

template <CSSPropertyPriority priority>
class CSSPropertyPriorityData {
  STATIC_ONLY(CSSPropertyPriorityData);

 public:
  static constexpr CSSPropertyID First();
  static constexpr CSSPropertyID Last();
  static constexpr bool PropertyHasPriority(CSSPropertyID prop) {
    return First() <= prop && prop <= Last();
  }
};

template <>
constexpr CSSPropertyID CSSPropertyPriorityData<kResolveVariables>::First() {
  static_assert(
      static_cast<int>(CSSPropertyID::kVariable) == kIntFirstCSSProperty - 1,
      "CSSPropertyID::kVariable should be directly before the first CSS "
      "property.");
  return CSSPropertyID::kVariable;
}

template <>
constexpr CSSPropertyID CSSPropertyPriorityData<kResolveVariables>::Last() {
  return CSSPropertyID::kVariable;
}

template <>
constexpr CSSPropertyID
CSSPropertyPriorityData<kAnimationPropertyPriority>::First() {
  static_assert(CSSPropertyID::kAnimationDelay == firstCSSProperty,
                "CSSPropertyID::kAnimationDelay should be the first animation "
                "priority property");
  return CSSPropertyID::kAnimationDelay;
}

template <>
constexpr CSSPropertyID
CSSPropertyPriorityData<kAnimationPropertyPriority>::Last() {
  static_assert(
      static_cast<int>(CSSPropertyID::kTransitionTimingFunction) ==
          static_cast<int>(CSSPropertyID::kAnimationDelay) + 11,
      "CSSPropertyID::kTransitionTimingFunction should be the end of the high "
      "priority property range");
  static_assert(
      static_cast<int>(CSSPropertyID::kColor) ==
          static_cast<int>(CSSPropertyID::kTransitionTimingFunction) + 1,
      "CSSPropertyID::kTransitionTimingFunction should be immediately before "
      "CSSPropertyID::kColor");
  return CSSPropertyID::kTransitionTimingFunction;
}

template <>
constexpr CSSPropertyID
CSSPropertyPriorityData<kHighPropertyPriority>::First() {
  static_assert(
      static_cast<int>(CSSPropertyID::kColor) ==
          static_cast<int>(CSSPropertyID::kTransitionTimingFunction) + 1,
      "CSSPropertyID::kColor should be the first high priority property");
  return CSSPropertyID::kColor;
}

template <>
constexpr CSSPropertyID CSSPropertyPriorityData<kHighPropertyPriority>::Last() {
  static_assert(static_cast<int>(CSSPropertyID::kZoom) ==
                    static_cast<int>(CSSPropertyID::kColor) + 27,
                "CSSPropertyID::kZoom should be the end of the high priority "
                "property range");
  static_assert(static_cast<int>(CSSPropertyID::kWritingMode) ==
                    static_cast<int>(CSSPropertyID::kZoom) - 1,
                "CSSPropertyID::kWritingMode should be immediately before "
                "CSSPropertyID::kZoom");
  return CSSPropertyID::kZoom;
}

template <>
constexpr CSSPropertyID CSSPropertyPriorityData<kLowPropertyPriority>::First() {
  static_assert(
      static_cast<int>(CSSPropertyID::kAlignContent) ==
          static_cast<int>(CSSPropertyID::kZoom) + 1,
      "CSSPropertyID::kAlignContent should be the first low priority property");
  return CSSPropertyID::kAlignContent;
}

template <>
constexpr CSSPropertyID CSSPropertyPriorityData<kLowPropertyPriority>::Last() {
  return static_cast<CSSPropertyID>(lastCSSProperty);
}

constexpr CSSPropertyPriority PriorityForProperty(CSSPropertyID property) {
  if (CSSPropertyPriorityData<kLowPropertyPriority>::PropertyHasPriority(
          property)) {
    return kLowPropertyPriority;
  }
  if (CSSPropertyPriorityData<kHighPropertyPriority>::PropertyHasPriority(
          property)) {
    return kHighPropertyPriority;
  }
  if (CSSPropertyPriorityData<kAnimationPropertyPriority>::PropertyHasPriority(
          property)) {
    return kAnimationPropertyPriority;
  }
  DCHECK(CSSPropertyPriorityData<kResolveVariables>::PropertyHasPriority(
      property));
  return kResolveVariables;
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_CSS_PROPERTY_PRIORITY_H_