OLD | NEW |
1 {% from 'macros.tmpl' import license %} | 1 {% from 'macros.tmpl' import license %} |
2 {{license()}} | 2 {{license()}} |
3 | 3 |
4 #ifndef ComputedStyleBase_h | 4 #ifndef ComputedStyleBase_h |
5 #define ComputedStyleBase_h | 5 #define ComputedStyleBase_h |
6 | 6 |
7 #include "core/ComputedStyleBaseConstants.h" | 7 #include "core/ComputedStyleBaseConstants.h" |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "wtf/RefCounted.h" | 9 #include "wtf/RefCounted.h" |
10 | 10 |
11 {# Returns the default value for the field, converted to fit in the storage cont
ainer. #} | 11 {# Returns the default value for the field, converted to fit in the storage cont
ainer. #} |
12 {% macro default_value(field) %} | 12 {% macro default_value(field) %} |
13 {# We only support enum fields for now. #} | 13 {# We only support enum fields for now. #} |
14 static_cast<unsigned>({{field.default_value}}){% endmacro %} | 14 static_cast<unsigned>({{field.default_value}}){% endmacro %} |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 // The generated portion of ComputedStyle. For more info, see the header comment | 18 // The generated portion of ComputedStyle. For more info, see the header comment |
19 // in ComputedStyle.h. | 19 // in ComputedStyle.h. |
20 class CORE_EXPORT ComputedStyleBase : public RefCounted<ComputedStyleBase> { | 20 class CORE_EXPORT ComputedStyleBase : public RefCounted<ComputedStyleBase> { |
21 public: | 21 public: |
| 22 // Empty constructor. |
22 ALWAYS_INLINE ComputedStyleBase() : | 23 ALWAYS_INLINE ComputedStyleBase() : |
23 RefCounted<ComputedStyleBase>(), | 24 RefCounted<ComputedStyleBase>(), |
24 {% for field in fields %} | 25 {% for field in fields %} |
25 {% set trailing_comma = "," if field != fields[-1] else "" %} | 26 {% set trailing_comma = "," if field != fields[-1] else "" %} |
26 {{field.name}}({{default_value(field)}}){{trailing_comma}} | 27 {{field.name}}({{default_value(field)}}){{trailing_comma}} |
27 {% endfor %} | 28 {% endfor %} |
28 {} | 29 {} |
29 ~ComputedStyleBase() {} | 30 ~ComputedStyleBase() {} |
30 | 31 |
| 32 // Copy constructor. |
31 ALWAYS_INLINE ComputedStyleBase(const ComputedStyleBase& o) : | 33 ALWAYS_INLINE ComputedStyleBase(const ComputedStyleBase& o) : |
32 {% for field in fields %} | 34 {% for field in fields %} |
33 {% set trailing_comma = "," if field != fields[-1] else "" %} | 35 {% set trailing_comma = "," if field != fields[-1] else "" %} |
34 {{field.name}}(o.{{field.name}}){{trailing_comma}} | 36 {{field.name}}(o.{{field.name}}){{trailing_comma}} |
35 {% endfor %} | 37 {% endfor %} |
36 {} | 38 {} |
37 | 39 |
| 40 // Comparison functions. |
38 bool operator==(const ComputedStyleBase& o) const | 41 bool operator==(const ComputedStyleBase& o) const |
39 { | 42 { |
40 return true | 43 return true |
41 {% for field in fields %} | 44 {% for field in fields %} |
42 && {{field.name}} == o.{{field.name}} | 45 && {{field.name}} == o.{{field.name}} |
43 {% endfor %} | 46 {% endfor %} |
44 && true; | 47 && true; |
45 } | 48 } |
46 | 49 |
47 bool operator!=(const ComputedStyleBase& o) const { return !(*this == o); } | 50 bool operator!=(const ComputedStyleBase& o) const { return !(*this == o); } |
48 | 51 |
49 inline bool inheritedEqual(const ComputedStyleBase& o) const | 52 inline bool inheritedEqual(const ComputedStyleBase& o) const |
50 { | 53 { |
51 return true | 54 return true |
52 {% for field in fields if field.property['inherited'] %} | 55 {% for field in fields if field.comparison_function_independent_inherite
d or field.comparison_function_non_independent_inherited %} |
53 && {{field.name}} == o.{{field.name}} | 56 && {{field.name}} == o.{{field.name}} |
54 {% endfor %} | 57 {% endfor %} |
55 && true; | 58 && true; |
56 } | 59 } |
57 | 60 |
58 inline bool independentInheritedEqual(const ComputedStyleBase& o) const | 61 inline bool independentInheritedEqual(const ComputedStyleBase& o) const |
59 { | 62 { |
60 return true | 63 return true |
61 {% for field in fields if field.property['inherited'] and field.property
['independent'] %} | 64 {% for field in fields if field.comparison_function_independent_inherite
d %} |
62 && {{field.name}} == o.{{field.name}} | 65 && {{field.name}} == o.{{field.name}} |
63 {% endfor %} | 66 {% endfor %} |
64 && true; | 67 && true; |
65 } | 68 } |
66 | 69 |
67 inline bool nonIndependentInheritedEqual(const ComputedStyleBase& o) const | 70 inline bool nonIndependentInheritedEqual(const ComputedStyleBase& o) const |
68 { | 71 { |
69 return true | 72 return true |
70 {% for field in fields if field.property['inherited'] and not field.prop
erty['independent'] %} | 73 {% for field in fields if field.comparison_function_non_independent_inhe
rited %} |
71 && {{field.name}} == o.{{field.name}} | 74 && {{field.name}} == o.{{field.name}} |
72 {% endfor %} | 75 {% endfor %} |
73 && true; | 76 && true; |
74 } | 77 } |
75 | 78 |
76 inline bool nonInheritedEqual(const ComputedStyleBase& o) const | 79 inline bool nonInheritedEqual(const ComputedStyleBase& o) const |
77 { | 80 { |
78 return true | 81 return true |
79 {% for field in fields if not field.property['inherited'] %} | 82 {% for field in fields if field.comparison_function_non_inherited %} |
80 && {{field.name}} == o.{{field.name}} | 83 && {{field.name}} == o.{{field.name}} |
81 {% endfor %} | 84 {% endfor %} |
82 && true; | 85 && true; |
83 } | 86 } |
84 | 87 |
| 88 // Resets all fields to their default values. |
85 void setBitDefaults() | 89 void setBitDefaults() |
86 { | 90 { |
87 {% for field in fields %} | 91 {% for field in fields %} |
88 reset{{field.property['upper_camel_name']}}(); | 92 reset{{field.upper_camel_name}}(); |
89 {% endfor %} | 93 {% endfor %} |
90 } | 94 } |
91 | 95 |
92 enum IsAtShadowBoundary { | 96 enum IsAtShadowBoundary { |
93 AtShadowBoundary, | 97 AtShadowBoundary, |
94 NotAtShadowBoundary, | 98 NotAtShadowBoundary, |
95 }; | 99 }; |
96 void inheritFrom(const ComputedStyleBase& inheritParent, IsAtShadowBoundary
isAtShadowBoundary = NotAtShadowBoundary); | 100 void inheritFrom(const ComputedStyleBase& inheritParent, IsAtShadowBoundary
isAtShadowBoundary = NotAtShadowBoundary); |
| 101 void copyNonInheritedFromCached(const ComputedStyleBase&); |
| 102 void propagateIndependentInheritedProperties(const ComputedStyleBase& parent
Style); |
97 | 103 |
98 // Fields. | 104 // Fields. |
99 // TODO(sashab): Remove initialFoo() static methods and update callers to | 105 // TODO(sashab): Remove initialFoo() static methods and update callers to us
e |
100 // use resetFoo(), which can be more efficient. | 106 // resetFoo(), which can be made more efficient. |
| 107 |
| 108 {% for property_name, fields in fields_per_property.items() if fields %} |
| 109 // {{property_name}} |
101 {% for field in fields %} | 110 {% for field in fields %} |
102 // {{field.property['name']}} | 111 inline static {{field.type}} initial{{field.upper_camel_name}}() { return {{
field.default_value}}; } |
103 inline static {{field.type}} initial{{field.property['upper_camel_name']}}()
{ return {{field.default_value}}; } | 112 {{field.type}} {{field.lower_camel_name}}() const { return static_cast<{{fie
ld.type}}>({{field.name}}); } |
104 {{field.type}} {{field.property['lower_camel_name']}}() const { return stati
c_cast<{{field.type}}>({{field.name}}); } | 113 void set{{field.upper_camel_name}}({{field.type}} v) { {{field.name}} = stat
ic_cast<unsigned>(v); } |
105 void set{{field.property['upper_camel_name']}}({{field.type}} v) { {{field.n
ame}} = static_cast<unsigned>(v); } | 114 inline void reset{{field.upper_camel_name}}() { {{field.name}} = {{default_v
alue(field)}}; } |
106 inline void reset{{field.property['upper_camel_name']}}() { {{field.name}} =
{{default_value(field)}}; } | |
107 | 115 |
108 {% endfor %} | 116 {% endfor %} |
| 117 {% endfor %} |
109 protected: | 118 protected: |
110 // Storage. | 119 // Storage. |
111 {% for field in fields %} | 120 {% for field in fields %} |
112 unsigned {{field.name}} : {{field.size}}; // {{field.type}} | 121 unsigned {{field.name}} : {{field.size}}; // {{field.type}} |
113 {% endfor %} | 122 {% endfor %} |
114 }; | 123 }; |
115 | 124 |
116 } // namespace blink | 125 } // namespace blink |
117 | 126 |
118 #endif // ComputedStyleBase_h | 127 #endif // ComputedStyleBase_h |
OLD | NEW |