1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Mats Palmgren <matspal@gmail.com>
24 : * Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>, Collabora Ltd.
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : /*
41 : * methods for dealing with CSS properties and tables of the keyword
42 : * values they accept
43 : */
44 :
45 : #ifndef nsCSSProps_h___
46 : #define nsCSSProps_h___
47 :
48 : #include "nsString.h"
49 : #include "nsChangeHint.h"
50 : #include "nsCSSProperty.h"
51 : #include "nsStyleStruct.h"
52 : #include "nsCSSKeywords.h"
53 :
54 : // Flags for the kFlagsTable bitfield (flags_ in nsCSSPropList.h)
55 :
56 : // A property that is a *-ltr-source or *-rtl-source property for one of
57 : // the directional pseudo-shorthand properties.
58 : #define CSS_PROPERTY_DIRECTIONAL_SOURCE (1<<0)
59 :
60 : #define CSS_PROPERTY_VALUE_LIST_USES_COMMAS (1<<1) /* otherwise spaces */
61 :
62 : #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER (1<<2)
63 : #define CSS_PROPERTY_APPLIES_TO_FIRST_LINE (1<<3)
64 : #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE \
65 : (CSS_PROPERTY_APPLIES_TO_FIRST_LETTER | CSS_PROPERTY_APPLIES_TO_FIRST_LINE)
66 :
67 : // Note that 'background-color' is ignored differently from the other
68 : // properties that have this set, but that's just special-cased.
69 : #define CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED (1<<4)
70 :
71 : // A property that needs to have image loads started when a URL value
72 : // for the property is used for an element. This is supported only
73 : // for a few possible value formats: image directly in the value; list
74 : // of images; and with CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0, image in slot
75 : // 0 of an array, or list of such arrays.
76 : #define CSS_PROPERTY_START_IMAGE_LOADS (1<<5)
77 :
78 : // Should be set only for properties with START_IMAGE_LOADS. Indicates
79 : // that the property has an array value with a URL/image value at index
80 : // 0 in the array, rather than the URL/image being in the value or value
81 : // list.
82 : #define CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0 (1<<6)
83 :
84 : // This is a property for which the computed value should generally be
85 : // reported as the computed value of a property of a different name. In
86 : // particular, the directional box properties (margin-left-value, etc.)
87 : // should be reported as being margin-left, etc. Call
88 : // nsCSSProps::OtherNameFor to get the other property.
89 : #define CSS_PROPERTY_REPORT_OTHER_NAME (1<<7)
90 :
91 : // This property allows calc() between lengths and percentages and
92 : // stores such calc() expressions in its style structs (typically in an
93 : // nsStyleCoord, although this is not the case for 'background-position'
94 : // and 'background-size').
95 : #define CSS_PROPERTY_STORES_CALC (1<<8)
96 :
97 : // Define what mechanism the CSS parser uses for parsing the property.
98 : // See CSSParserImpl::ParseProperty(nsCSSProperty). Don't use 0 so that
99 : // we can verify that every property sets one of the values.
100 : #define CSS_PROPERTY_PARSE_PROPERTY_MASK (7<<9)
101 : #define CSS_PROPERTY_PARSE_INACCESSIBLE (1<<9)
102 : #define CSS_PROPERTY_PARSE_FUNCTION (2<<9)
103 : #define CSS_PROPERTY_PARSE_VALUE (3<<9)
104 : #define CSS_PROPERTY_PARSE_VALUE_LIST (4<<9)
105 :
106 : // See CSSParserImpl::ParseSingleValueProperty
107 : #define CSS_PROPERTY_VALUE_PARSER_FUNCTION (1<<12)
108 : MOZ_STATIC_ASSERT((CSS_PROPERTY_PARSE_PROPERTY_MASK &
109 : CSS_PROPERTY_VALUE_PARSER_FUNCTION) == 0,
110 : "didn't leave enough room for the parse property constants");
111 :
112 : #define CSS_PROPERTY_VALUE_RESTRICTION_MASK (3<<13)
113 : // The parser (in particular, CSSParserImpl::ParseSingleValueProperty)
114 : // should enforce that the value of this property must be 0 or larger.
115 : #define CSS_PROPERTY_VALUE_NONNEGATIVE (1<<13)
116 : // The parser (in particular, CSSParserImpl::ParseSingleValueProperty)
117 : // should enforce that the value of this property must be 1 or larger.
118 : #define CSS_PROPERTY_VALUE_AT_LEAST_ONE (2<<13)
119 :
120 : // NOTE: next free bit is (1<<15)
121 :
122 : /**
123 : * Types of animatable values.
124 : */
125 : enum nsStyleAnimType {
126 : // requires a custom implementation in
127 : // nsStyleAnimation::ExtractComputedValue
128 : eStyleAnimType_Custom,
129 :
130 : // nsStyleCoord with animatable values
131 : eStyleAnimType_Coord,
132 :
133 : // same as Coord, except for one side of an nsStyleSides
134 : // listed in the same order as the NS_STYLE_* constants
135 : eStyleAnimType_Sides_Top,
136 : eStyleAnimType_Sides_Right,
137 : eStyleAnimType_Sides_Bottom,
138 : eStyleAnimType_Sides_Left,
139 :
140 : // similar, but for the *pair* of coord members of an nsStyleCorners
141 : // for the relevant corner
142 : eStyleAnimType_Corner_TopLeft,
143 : eStyleAnimType_Corner_TopRight,
144 : eStyleAnimType_Corner_BottomRight,
145 : eStyleAnimType_Corner_BottomLeft,
146 :
147 : // nscoord values
148 : eStyleAnimType_nscoord,
149 :
150 : // enumerated values (stored in a PRUint8)
151 : // In order for a property to use this unit, _all_ of its enumerated values
152 : // must be listed in its keyword table, so that any enumerated value can be
153 : // converted into a string via a nsCSSValue of type eCSSUnit_Enumerated.
154 : eStyleAnimType_EnumU8,
155 :
156 : // float values
157 : eStyleAnimType_float,
158 :
159 : // nscolor values
160 : eStyleAnimType_Color,
161 :
162 : // nsStyleSVGPaint values
163 : eStyleAnimType_PaintServer,
164 :
165 : // nsRefPtr<nsCSSShadowArray> values
166 : eStyleAnimType_Shadow,
167 :
168 : // property not animatable
169 : eStyleAnimType_None
170 : };
171 :
172 : class nsCSSProps {
173 : public:
174 : static void AddRefTable(void);
175 : static void ReleaseTable(void);
176 :
177 : // Given a property string, return the enum value
178 : static nsCSSProperty LookupProperty(const nsAString& aProperty);
179 : static nsCSSProperty LookupProperty(const nsACString& aProperty);
180 :
181 0 : static inline bool IsShorthand(nsCSSProperty aProperty) {
182 0 : NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
183 : "out of range");
184 0 : return (aProperty >= eCSSProperty_COUNT_no_shorthands);
185 : }
186 :
187 : // Same but for @font-face descriptors
188 : static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty);
189 : static nsCSSFontDesc LookupFontDesc(const nsACString& aProperty);
190 :
191 : // Given a property enum, get the string value
192 : static const nsAFlatCString& GetStringValue(nsCSSProperty aProperty);
193 : static const nsAFlatCString& GetStringValue(nsCSSFontDesc aFontDesc);
194 :
195 : // Get the property to report the computed value of aProperty as being
196 : // the computed value of. aProperty must have the
197 : // CSS_PROPERTY_REPORT_OTHER_NAME bit set.
198 : static nsCSSProperty OtherNameFor(nsCSSProperty aProperty);
199 :
200 : // Given a CSS Property and a Property Enum Value
201 : // Return back a const nsString& representation of the
202 : // value. Return back nullstr if no value is found
203 : static const nsAFlatCString& LookupPropertyValue(nsCSSProperty aProperty, PRInt32 aValue);
204 :
205 : // Get a color name for a predefined color value like buttonhighlight or activeborder
206 : // Sets the aStr param to the name of the propertyID
207 : static bool GetColorName(PRInt32 aPropID, nsCString &aStr);
208 :
209 : // Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value.
210 : // If not found, return false and do not set |aValue|.
211 : static bool FindKeyword(nsCSSKeyword aKeyword, const PRInt32 aTable[], PRInt32& aValue);
212 : // Return the first keyword in |aTable| that has the corresponding value |aValue|.
213 : // Return |eCSSKeyword_UNKNOWN| if not found.
214 : static nsCSSKeyword ValueToKeywordEnum(PRInt32 aValue, const PRInt32 aTable[]);
215 : // Ditto but as a string, return "" when not found.
216 : static const nsAFlatCString& ValueToKeyword(PRInt32 aValue, const PRInt32 aTable[]);
217 :
218 : static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands];
219 : static const PRInt32* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands];
220 : static const nsStyleAnimType kAnimTypeTable[eCSSProperty_COUNT_no_shorthands];
221 : static const ptrdiff_t
222 : kStyleStructOffsetTable[eCSSProperty_COUNT_no_shorthands];
223 :
224 : private:
225 : static const PRUint32 kFlagsTable[eCSSProperty_COUNT];
226 :
227 : public:
228 0 : static inline bool PropHasFlags(nsCSSProperty aProperty, PRUint32 aFlags)
229 : {
230 0 : NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
231 : "out of range");
232 0 : return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags;
233 : }
234 :
235 0 : static inline PRUint32 PropertyParseType(nsCSSProperty aProperty)
236 : {
237 0 : NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
238 : "out of range");
239 0 : return nsCSSProps::kFlagsTable[aProperty] &
240 0 : CSS_PROPERTY_PARSE_PROPERTY_MASK;
241 : }
242 :
243 0 : static inline PRUint32 ValueRestrictions(nsCSSProperty aProperty)
244 : {
245 0 : NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
246 : "out of range");
247 0 : return nsCSSProps::kFlagsTable[aProperty] &
248 0 : CSS_PROPERTY_VALUE_RESTRICTION_MASK;
249 : }
250 :
251 : private:
252 : // Lives in nsCSSParser.cpp for the macros it depends on.
253 : static const PRUint32 kParserVariantTable[eCSSProperty_COUNT_no_shorthands];
254 :
255 : public:
256 0 : static inline PRUint32 ParserVariant(nsCSSProperty aProperty) {
257 0 : NS_ABORT_IF_FALSE(0 <= aProperty &&
258 : aProperty < eCSSProperty_COUNT_no_shorthands,
259 : "out of range");
260 0 : return nsCSSProps::kParserVariantTable[aProperty];
261 : }
262 :
263 : private:
264 : // A table for shorthand properties. The appropriate index is the
265 : // property ID minus eCSSProperty_COUNT_no_shorthands.
266 : static const nsCSSProperty *const
267 : kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
268 :
269 : public:
270 : static inline
271 511056 : const nsCSSProperty * SubpropertyEntryFor(nsCSSProperty aProperty) {
272 511056 : NS_ABORT_IF_FALSE(eCSSProperty_COUNT_no_shorthands <= aProperty &&
273 : aProperty < eCSSProperty_COUNT,
274 : "out of range");
275 : return nsCSSProps::kSubpropertyTable[aProperty -
276 511056 : eCSSProperty_COUNT_no_shorthands];
277 : }
278 :
279 : // Returns an eCSSProperty_UNKNOWN-terminated array of the shorthand
280 : // properties containing |aProperty|, sorted from those that contain
281 : // the most properties to those that contain the least.
282 650052 : static const nsCSSProperty * ShorthandsContaining(nsCSSProperty aProperty) {
283 650052 : NS_ABORT_IF_FALSE(gShorthandsContainingPool, "uninitialized");
284 650052 : NS_ABORT_IF_FALSE(0 <= aProperty &&
285 : aProperty < eCSSProperty_COUNT_no_shorthands,
286 : "out of range");
287 650052 : return gShorthandsContainingTable[aProperty];
288 : }
289 : private:
290 : // gShorthandsContainingTable is an array of the return values for
291 : // ShorthandsContaining (arrays of nsCSSProperty terminated by
292 : // eCSSProperty_UNKNOWN) pointing into memory in
293 : // gShorthandsContainingPool (which contains all of those arrays in a
294 : // single allocation, and is the one pointer that should be |free|d).
295 : static nsCSSProperty *gShorthandsContainingTable[eCSSProperty_COUNT_no_shorthands];
296 : static nsCSSProperty* gShorthandsContainingPool;
297 : static bool BuildShorthandsContainingTable();
298 :
299 : private:
300 : static const size_t gPropertyCountInStruct[nsStyleStructID_Length];
301 : static const size_t gPropertyIndexInStruct[eCSSProperty_COUNT_no_shorthands];
302 : public:
303 : /**
304 : * Return the number of properties that must be cascaded when
305 : * nsRuleNode builds the nsStyle* for aSID.
306 : */
307 0 : static size_t PropertyCountInStruct(nsStyleStructID aSID) {
308 0 : NS_ABORT_IF_FALSE(0 <= aSID && aSID < nsStyleStructID_Length,
309 : "out of range");
310 0 : return gPropertyCountInStruct[aSID];
311 : }
312 : /**
313 : * Return an index for aProperty that is unique within its SID and in
314 : * the range 0 <= index < PropertyCountInStruct(aSID).
315 : */
316 0 : static size_t PropertyIndexInStruct(nsCSSProperty aProperty) {
317 0 : NS_ABORT_IF_FALSE(0 <= aProperty &&
318 : aProperty < eCSSProperty_COUNT_no_shorthands,
319 : "out of range");
320 0 : return gPropertyIndexInStruct[aProperty];
321 : }
322 :
323 : public:
324 :
325 : #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \
326 : for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \
327 : *iter_ != eCSSProperty_UNKNOWN; ++iter_)
328 :
329 : // Keyword/Enum value tables
330 : static const PRInt32 kAnimationDirectionKTable[];
331 : static const PRInt32 kAnimationFillModeKTable[];
332 : static const PRInt32 kAnimationIterationCountKTable[];
333 : static const PRInt32 kAnimationPlayStateKTable[];
334 : static const PRInt32 kAnimationTimingFunctionKTable[];
335 : static const PRInt32 kAppearanceKTable[];
336 : static const PRInt32 kAzimuthKTable[];
337 : static const PRInt32 kBackfaceVisibilityKTable[];
338 : static const PRInt32 kTransformStyleKTable[];
339 : static const PRInt32 kBackgroundAttachmentKTable[];
340 : static const PRInt32 kBackgroundInlinePolicyKTable[];
341 : static const PRInt32 kBackgroundOriginKTable[];
342 : static const PRInt32 kBackgroundPositionKTable[];
343 : static const PRInt32 kBackgroundRepeatKTable[];
344 : static const PRInt32 kBackgroundRepeatPartKTable[];
345 : static const PRInt32 kBackgroundSizeKTable[];
346 : static const PRInt32 kBorderCollapseKTable[];
347 : static const PRInt32 kBorderColorKTable[];
348 : static const PRInt32 kBorderImageKTable[];
349 : static const PRInt32 kBorderStyleKTable[];
350 : static const PRInt32 kBorderWidthKTable[];
351 : static const PRInt32 kBoxAlignKTable[];
352 : static const PRInt32 kBoxDirectionKTable[];
353 : static const PRInt32 kBoxOrientKTable[];
354 : static const PRInt32 kBoxPackKTable[];
355 : static const PRInt32 kDominantBaselineKTable[];
356 : static const PRInt32 kFillRuleKTable[];
357 : static const PRInt32 kImageRenderingKTable[];
358 : static const PRInt32 kShapeRenderingKTable[];
359 : static const PRInt32 kStrokeLinecapKTable[];
360 : static const PRInt32 kStrokeLinejoinKTable[];
361 : static const PRInt32 kTextAnchorKTable[];
362 : static const PRInt32 kTextRenderingKTable[];
363 : static const PRInt32 kColorInterpolationKTable[];
364 : static const PRInt32 kColumnFillKTable[];
365 : static const PRInt32 kBoxPropSourceKTable[];
366 : static const PRInt32 kBoxShadowTypeKTable[];
367 : static const PRInt32 kBoxSizingKTable[];
368 : static const PRInt32 kCaptionSideKTable[];
369 : static const PRInt32 kClearKTable[];
370 : static const PRInt32 kColorKTable[];
371 : static const PRInt32 kContentKTable[];
372 : static const PRInt32 kCursorKTable[];
373 : static const PRInt32 kDirectionKTable[];
374 : static const PRInt32 kDisplayKTable[];
375 : static const PRInt32 kElevationKTable[];
376 : static const PRInt32 kEmptyCellsKTable[];
377 : static const PRInt32 kFloatKTable[];
378 : static const PRInt32 kFloatEdgeKTable[];
379 : static const PRInt32 kFontKTable[];
380 : static const PRInt32 kFontSizeKTable[];
381 : static const PRInt32 kFontStretchKTable[];
382 : static const PRInt32 kFontStyleKTable[];
383 : static const PRInt32 kFontVariantKTable[];
384 : static const PRInt32 kFontWeightKTable[];
385 : static const PRInt32 kIMEModeKTable[];
386 : static const PRInt32 kLineHeightKTable[];
387 : static const PRInt32 kListStylePositionKTable[];
388 : static const PRInt32 kListStyleKTable[];
389 : static const PRInt32 kOrientKTable[];
390 : static const PRInt32 kOutlineStyleKTable[];
391 : static const PRInt32 kOutlineColorKTable[];
392 : static const PRInt32 kOverflowKTable[];
393 : static const PRInt32 kOverflowSubKTable[];
394 : static const PRInt32 kPageBreakKTable[];
395 : static const PRInt32 kPageBreakInsideKTable[];
396 : static const PRInt32 kPageMarksKTable[];
397 : static const PRInt32 kPageSizeKTable[];
398 : static const PRInt32 kPitchKTable[];
399 : static const PRInt32 kPointerEventsKTable[];
400 : static const PRInt32 kPositionKTable[];
401 : static const PRInt32 kRadialGradientShapeKTable[];
402 : static const PRInt32 kRadialGradientSizeKTable[];
403 : static const PRInt32 kResizeKTable[];
404 : static const PRInt32 kSpeakKTable[];
405 : static const PRInt32 kSpeakHeaderKTable[];
406 : static const PRInt32 kSpeakNumeralKTable[];
407 : static const PRInt32 kSpeakPunctuationKTable[];
408 : static const PRInt32 kSpeechRateKTable[];
409 : static const PRInt32 kStackSizingKTable[];
410 : static const PRInt32 kTableLayoutKTable[];
411 : static const PRInt32 kTextAlignKTable[];
412 : static const PRInt32 kTextAlignLastKTable[];
413 : static const PRInt32 kTextBlinkKTable[];
414 : static const PRInt32 kTextDecorationLineKTable[];
415 : static const PRInt32 kTextDecorationStyleKTable[];
416 : static const PRInt32 kTextOverflowKTable[];
417 : static const PRInt32 kTextTransformKTable[];
418 : static const PRInt32 kTransitionTimingFunctionKTable[];
419 : static const PRInt32 kUnicodeBidiKTable[];
420 : static const PRInt32 kUserFocusKTable[];
421 : static const PRInt32 kUserInputKTable[];
422 : static const PRInt32 kUserModifyKTable[];
423 : static const PRInt32 kUserSelectKTable[];
424 : static const PRInt32 kVerticalAlignKTable[];
425 : static const PRInt32 kVisibilityKTable[];
426 : static const PRInt32 kVolumeKTable[];
427 : static const PRInt32 kWhitespaceKTable[];
428 : static const PRInt32 kWidthKTable[]; // also min-width, max-width
429 : static const PRInt32 kWindowShadowKTable[];
430 : static const PRInt32 kWordwrapKTable[];
431 : static const PRInt32 kHyphensKTable[];
432 : };
433 :
434 : #endif /* nsCSSProps_h___ */
|