/work/obj-fuzz/dist/include/mozilla/MappedDeclarations.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* Representation of a declaration block used for attribute mapping */ |
8 | | |
9 | | #ifndef mozilla_MappedDeclarations_h |
10 | | #define mozilla_MappedDeclarations_h |
11 | | |
12 | | #include "mozilla/FontPropertyTypes.h" |
13 | | #include "mozilla/ServoBindingTypes.h" |
14 | | #include "mozilla/ServoBindings.h" |
15 | | #include "nsCSSPropertyID.h" |
16 | | #include "nsCSSValue.h" |
17 | | #include "nsColor.h" |
18 | | |
19 | | class nsAttrValue; |
20 | | |
21 | | namespace mozilla { |
22 | | |
23 | | // This provides a convenient interface for attribute mappers |
24 | | // (MapAttributesIntoRule) to modify the presentation attribute declaration |
25 | | // block for a given element. |
26 | | class MappedDeclarations final |
27 | | { |
28 | | public: |
29 | | explicit MappedDeclarations(nsIDocument* aDoc, |
30 | | already_AddRefed<RawServoDeclarationBlock> aDecls) |
31 | | : mDocument(aDoc) |
32 | | , mDecl(aDecls) |
33 | 0 | { |
34 | 0 | MOZ_ASSERT(mDecl); |
35 | 0 | } |
36 | | |
37 | | ~MappedDeclarations() |
38 | 0 | { |
39 | 0 | MOZ_ASSERT(!mDecl, "Forgot to take the block?"); |
40 | 0 | } |
41 | | |
42 | | nsIDocument* Document() |
43 | 0 | { |
44 | 0 | return mDocument; |
45 | 0 | } |
46 | | |
47 | | already_AddRefed<RawServoDeclarationBlock> TakeDeclarationBlock() |
48 | 0 | { |
49 | 0 | MOZ_ASSERT(mDecl); |
50 | 0 | return mDecl.forget(); |
51 | 0 | } |
52 | | |
53 | | // Check if we already contain a certain longhand |
54 | | bool PropertyIsSet(nsCSSPropertyID aId) const |
55 | 0 | { |
56 | 0 | return Servo_DeclarationBlock_PropertyIsSet(mDecl, aId); |
57 | 0 | } |
58 | | |
59 | | // Set a property to an identifier (string) |
60 | | void SetIdentStringValue(nsCSSPropertyID aId, const nsString& aValue) |
61 | 0 | { |
62 | 0 | RefPtr<nsAtom> atom = NS_AtomizeMainThread(aValue); |
63 | 0 | SetIdentAtomValue(aId, atom); |
64 | 0 | } |
65 | | |
66 | | void SetIdentStringValueIfUnset(nsCSSPropertyID aId, const nsString& aValue) |
67 | 0 | { |
68 | 0 | if (!PropertyIsSet(aId)) { |
69 | 0 | SetIdentStringValue(aId, aValue); |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | void SetIdentAtomValue(nsCSSPropertyID aId, nsAtom* aValue); |
74 | | |
75 | | void SetIdentAtomValueIfUnset(nsCSSPropertyID aId, nsAtom* aValue) |
76 | 0 | { |
77 | 0 | if (!PropertyIsSet(aId)) { |
78 | 0 | SetIdentAtomValue(aId, aValue); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | // Set a property to a keyword (usually NS_STYLE_* or StyleFoo::*) |
83 | | void SetKeywordValue(nsCSSPropertyID aId, int32_t aValue) |
84 | 0 | { |
85 | 0 | Servo_DeclarationBlock_SetKeywordValue(mDecl, aId, aValue); |
86 | 0 | } |
87 | | |
88 | | void SetKeywordValueIfUnset(nsCSSPropertyID aId, int32_t aValue) |
89 | 0 | { |
90 | 0 | if (!PropertyIsSet(aId)) { |
91 | 0 | SetKeywordValue(aId, aValue); |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | | template<typename T, |
96 | | typename = typename std::enable_if<std::is_enum<T>::value>::type> |
97 | | void SetKeywordValue(nsCSSPropertyID aId, T aValue) |
98 | 0 | { |
99 | 0 | static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value, |
100 | 0 | "aValue must be an enum that fits within 32 bits"); |
101 | 0 | SetKeywordValue(aId, static_cast<int32_t>(aValue)); |
102 | 0 | } Unexecuted instantiation: void mozilla::MappedDeclarations::SetKeywordValue<mozilla::StyleWhiteSpace, void>(nsCSSPropertyID, mozilla::StyleWhiteSpace) Unexecuted instantiation: void mozilla::MappedDeclarations::SetKeywordValue<mozilla::StyleUserModify, void>(nsCSSPropertyID, mozilla::StyleUserModify) Unexecuted instantiation: void mozilla::MappedDeclarations::SetKeywordValue<mozilla::StyleDisplay, void>(nsCSSPropertyID, mozilla::StyleDisplay) Unexecuted instantiation: void mozilla::MappedDeclarations::SetKeywordValue<mozilla::StyleFloat, void>(nsCSSPropertyID, mozilla::StyleFloat) |
103 | | template<typename T, |
104 | | typename = typename std::enable_if<std::is_enum<T>::value>::type> |
105 | | void SetKeywordValueIfUnset(nsCSSPropertyID aId, T aValue) |
106 | | { |
107 | | static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value, |
108 | | "aValue must be an enum that fits within 32 bits"); |
109 | | SetKeywordValueIfUnset(aId, static_cast<int32_t>(aValue)); |
110 | | } |
111 | | |
112 | | // Set a property to an integer value |
113 | | void SetIntValue(nsCSSPropertyID aId, int32_t aValue) |
114 | 0 | { |
115 | 0 | Servo_DeclarationBlock_SetIntValue(mDecl, aId, aValue); |
116 | 0 | } |
117 | | |
118 | | // Set a property to a pixel value |
119 | | void SetPixelValue(nsCSSPropertyID aId, float aValue) |
120 | 0 | { |
121 | 0 | Servo_DeclarationBlock_SetPixelValue(mDecl, aId, aValue); |
122 | 0 | } |
123 | | |
124 | | void SetPixelValueIfUnset(nsCSSPropertyID aId, float aValue) |
125 | 0 | { |
126 | 0 | if (!PropertyIsSet(aId)) { |
127 | 0 | SetPixelValue(aId, aValue); |
128 | 0 | } |
129 | 0 | } |
130 | | |
131 | | void SetLengthValue(nsCSSPropertyID aId, const nsCSSValue& aValue) |
132 | 0 | { |
133 | 0 | MOZ_ASSERT(aValue.IsLengthUnit()); |
134 | 0 | Servo_DeclarationBlock_SetLengthValue( |
135 | 0 | mDecl, aId, aValue.GetFloatValue(), aValue.GetUnit()); |
136 | 0 | } |
137 | | |
138 | | // Set a property to a number value |
139 | | void SetNumberValue(nsCSSPropertyID aId, float aValue) |
140 | 0 | { |
141 | 0 | Servo_DeclarationBlock_SetNumberValue(mDecl, aId, aValue); |
142 | 0 | } |
143 | | |
144 | | // Set a property to a percent value |
145 | | void SetPercentValue(nsCSSPropertyID aId, float aValue) |
146 | 0 | { |
147 | 0 | Servo_DeclarationBlock_SetPercentValue(mDecl, aId, aValue); |
148 | 0 | } |
149 | | |
150 | | void SetPercentValueIfUnset(nsCSSPropertyID aId, float aValue) |
151 | 0 | { |
152 | 0 | if (!PropertyIsSet(aId)) { |
153 | 0 | SetPercentValue(aId, aValue); |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | | // Set a property to `auto` |
158 | | void SetAutoValue(nsCSSPropertyID aId) |
159 | 0 | { |
160 | 0 | Servo_DeclarationBlock_SetAutoValue(mDecl, aId); |
161 | 0 | } |
162 | | |
163 | | void SetAutoValueIfUnset(nsCSSPropertyID aId) |
164 | 0 | { |
165 | 0 | if (!PropertyIsSet(aId)) { |
166 | 0 | SetAutoValue(aId); |
167 | 0 | } |
168 | 0 | } |
169 | | |
170 | | // Set a property to `currentcolor` |
171 | | void SetCurrentColor(nsCSSPropertyID aId) |
172 | 0 | { |
173 | 0 | Servo_DeclarationBlock_SetCurrentColor(mDecl, aId); |
174 | 0 | } |
175 | | |
176 | | void SetCurrentColorIfUnset(nsCSSPropertyID aId) |
177 | 0 | { |
178 | 0 | if (!PropertyIsSet(aId)) { |
179 | 0 | SetCurrentColor(aId); |
180 | 0 | } |
181 | 0 | } |
182 | | |
183 | | // Set a property to an RGBA nscolor value |
184 | | void SetColorValue(nsCSSPropertyID aId, nscolor aValue) |
185 | 0 | { |
186 | 0 | Servo_DeclarationBlock_SetColorValue(mDecl, aId, aValue); |
187 | 0 | } |
188 | | |
189 | | void SetColorValueIfUnset(nsCSSPropertyID aId, nscolor aValue) |
190 | 0 | { |
191 | 0 | if (!PropertyIsSet(aId)) { |
192 | 0 | SetColorValue(aId, aValue); |
193 | 0 | } |
194 | 0 | } |
195 | | |
196 | | // Set font-family to a string |
197 | | void SetFontFamily(const nsString& aValue) |
198 | 0 | { |
199 | 0 | Servo_DeclarationBlock_SetFontFamily(mDecl, aValue); |
200 | 0 | } |
201 | | |
202 | | // Add a quirks-mode override to the decoration color of elements nested in <a> |
203 | | void SetTextDecorationColorOverride() |
204 | 0 | { |
205 | 0 | Servo_DeclarationBlock_SetTextDecorationColorOverride(mDecl); |
206 | 0 | } |
207 | | |
208 | | void SetBackgroundImage(const nsAttrValue& value); |
209 | | |
210 | | private: |
211 | | nsIDocument* const mDocument; |
212 | | RefPtr<RawServoDeclarationBlock> mDecl; |
213 | | }; |
214 | | |
215 | | } // namespace mozilla |
216 | | |
217 | | #endif // mozilla_MappedDeclarations_h |