Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / layout / style / nsCSSProps.h
blob5613a0507b6c6787e273c9d78530a5cfd4cb0e3a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * methods for dealing with CSS properties and tables of the keyword
8 * values they accept
9 */
11 #ifndef nsCSSProps_h___
12 #define nsCSSProps_h___
14 #include "nsString.h"
15 #include "nsCSSProperty.h"
16 #include "nsStyleStructFwd.h"
17 #include "nsCSSKeywords.h"
19 // Length of the "--" prefix on custom names (such as custom property names,
20 // and, in the future, custom media query names).
21 #define CSS_CUSTOM_NAME_PREFIX_LENGTH 2
23 // Flags for ParseVariant method
24 #define VARIANT_KEYWORD 0x000001 // K
25 #define VARIANT_LENGTH 0x000002 // L
26 #define VARIANT_PERCENT 0x000004 // P
27 #define VARIANT_COLOR 0x000008 // C eCSSUnit_*Color, eCSSUnit_Ident (e.g. "red")
28 #define VARIANT_URL 0x000010 // U
29 #define VARIANT_NUMBER 0x000020 // N
30 #define VARIANT_INTEGER 0x000040 // I
31 #define VARIANT_ANGLE 0x000080 // G
32 #define VARIANT_FREQUENCY 0x000100 // F
33 #define VARIANT_TIME 0x000200 // T
34 #define VARIANT_STRING 0x000400 // S
35 #define VARIANT_COUNTER 0x000800 //
36 #define VARIANT_ATTR 0x001000 //
37 #define VARIANT_IDENTIFIER 0x002000 // D
38 #define VARIANT_IDENTIFIER_NO_INHERIT 0x004000 // like above, but excluding
39 // 'inherit' and 'initial'
40 #define VARIANT_AUTO 0x010000 // A
41 #define VARIANT_INHERIT 0x020000 // H eCSSUnit_Initial, eCSSUnit_Inherit, eCSSUnit_Unset
42 #define VARIANT_NONE 0x040000 // O
43 #define VARIANT_NORMAL 0x080000 // M
44 #define VARIANT_SYSFONT 0x100000 // eCSSUnit_System_Font
45 #define VARIANT_GRADIENT 0x200000 // eCSSUnit_Gradient
46 #define VARIANT_TIMING_FUNCTION 0x400000 // cubic-bezier() and steps()
47 #define VARIANT_ALL 0x800000 //
48 #define VARIANT_IMAGE_RECT 0x01000000 // eCSSUnit_Function
49 // This is an extra bit that says that a VARIANT_ANGLE allows unitless zero:
50 #define VARIANT_ZERO_ANGLE 0x02000000 // unitless zero for angles
51 #define VARIANT_CALC 0x04000000 // eCSSUnit_Calc
52 #define VARIANT_ELEMENT 0x08000000 // eCSSUnit_Element
53 #define VARIANT_POSITIVE_DIMENSION 0x10000000 // Only lengths greater than 0.0
54 #define VARIANT_NONNEGATIVE_DIMENSION 0x20000000 // Only lengths greater than or equal to 0.0
55 // Keyword used iff gfx.font_rendering.opentype_svg.enabled is true:
56 #define VARIANT_OPENTYPE_SVG_KEYWORD 0x40000000
58 // Common combinations of variants
59 #define VARIANT_AL (VARIANT_AUTO | VARIANT_LENGTH)
60 #define VARIANT_LP (VARIANT_LENGTH | VARIANT_PERCENT)
61 #define VARIANT_LN (VARIANT_LENGTH | VARIANT_NUMBER)
62 #define VARIANT_AH (VARIANT_AUTO | VARIANT_INHERIT)
63 #define VARIANT_AHLP (VARIANT_AH | VARIANT_LP)
64 #define VARIANT_AHI (VARIANT_AH | VARIANT_INTEGER)
65 #define VARIANT_AHK (VARIANT_AH | VARIANT_KEYWORD)
66 #define VARIANT_AHKLP (VARIANT_AHLP | VARIANT_KEYWORD)
67 #define VARIANT_AHL (VARIANT_AH | VARIANT_LENGTH)
68 #define VARIANT_AHKL (VARIANT_AHK | VARIANT_LENGTH)
69 #define VARIANT_HK (VARIANT_INHERIT | VARIANT_KEYWORD)
70 #define VARIANT_HKF (VARIANT_HK | VARIANT_FREQUENCY)
71 #define VARIANT_HKI (VARIANT_HK | VARIANT_INTEGER)
72 #define VARIANT_HKL (VARIANT_HK | VARIANT_LENGTH)
73 #define VARIANT_HKLP (VARIANT_HK | VARIANT_LP)
74 #define VARIANT_HKLPO (VARIANT_HKLP | VARIANT_NONE)
75 #define VARIANT_HL (VARIANT_INHERIT | VARIANT_LENGTH)
76 #define VARIANT_HI (VARIANT_INHERIT | VARIANT_INTEGER)
77 #define VARIANT_HLP (VARIANT_HL | VARIANT_PERCENT)
78 #define VARIANT_HLPN (VARIANT_HLP | VARIANT_NUMBER)
79 #define VARIANT_HLPO (VARIANT_HLP | VARIANT_NONE)
80 #define VARIANT_HTP (VARIANT_INHERIT | VARIANT_TIME | VARIANT_PERCENT)
81 #define VARIANT_HMK (VARIANT_HK | VARIANT_NORMAL)
82 #define VARIANT_HC (VARIANT_INHERIT | VARIANT_COLOR)
83 #define VARIANT_HCK (VARIANT_HK | VARIANT_COLOR)
84 #define VARIANT_HUK (VARIANT_HK | VARIANT_URL)
85 #define VARIANT_HUO (VARIANT_INHERIT | VARIANT_URL | VARIANT_NONE)
86 #define VARIANT_AHUO (VARIANT_AUTO | VARIANT_HUO)
87 #define VARIANT_HPN (VARIANT_INHERIT | VARIANT_PERCENT | VARIANT_NUMBER)
88 #define VARIANT_PN (VARIANT_PERCENT | VARIANT_NUMBER)
89 #define VARIANT_ALPN (VARIANT_AL | VARIANT_PN)
90 #define VARIANT_HN (VARIANT_INHERIT | VARIANT_NUMBER)
91 #define VARIANT_HON (VARIANT_HN | VARIANT_NONE)
92 #define VARIANT_HOS (VARIANT_INHERIT | VARIANT_NONE | VARIANT_STRING)
93 #define VARIANT_LPN (VARIANT_LP | VARIANT_NUMBER)
94 #define VARIANT_UK (VARIANT_URL | VARIANT_KEYWORD)
95 #define VARIANT_UO (VARIANT_URL | VARIANT_NONE)
96 #define VARIANT_ANGLE_OR_ZERO (VARIANT_ANGLE | VARIANT_ZERO_ANGLE)
97 #define VARIANT_LCALC (VARIANT_LENGTH | VARIANT_CALC)
98 #define VARIANT_LPCALC (VARIANT_LCALC | VARIANT_PERCENT)
99 #define VARIANT_LNCALC (VARIANT_LCALC | VARIANT_NUMBER)
100 #define VARIANT_LPNCALC (VARIANT_LNCALC | VARIANT_PERCENT)
101 #define VARIANT_IMAGE (VARIANT_URL | VARIANT_NONE | VARIANT_GRADIENT | \
102 VARIANT_IMAGE_RECT | VARIANT_ELEMENT)
104 // Flags for the kFlagsTable bitfield (flags_ in nsCSSPropList.h)
106 // A property that is a *-ltr-source or *-rtl-source property for one of
107 // the directional pseudo-shorthand properties.
108 #define CSS_PROPERTY_DIRECTIONAL_SOURCE (1<<0)
110 #define CSS_PROPERTY_VALUE_LIST_USES_COMMAS (1<<1) /* otherwise spaces */
112 #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER (1<<2)
113 #define CSS_PROPERTY_APPLIES_TO_FIRST_LINE (1<<3)
114 #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE \
115 (CSS_PROPERTY_APPLIES_TO_FIRST_LETTER | CSS_PROPERTY_APPLIES_TO_FIRST_LINE)
117 // Note that 'background-color' is ignored differently from the other
118 // properties that have this set, but that's just special-cased.
119 #define CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED (1<<4)
121 // A property that needs to have image loads started when a URL value
122 // for the property is used for an element. This is supported only
123 // for a few possible value formats: image directly in the value; list
124 // of images; and with CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0, image in slot
125 // 0 of an array, or list of such arrays.
126 #define CSS_PROPERTY_START_IMAGE_LOADS (1<<5)
128 // Should be set only for properties with START_IMAGE_LOADS. Indicates
129 // that the property has an array value with a URL/image value at index
130 // 0 in the array, rather than the URL/image being in the value or value
131 // list.
132 #define CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0 (1<<6)
134 // This is a property for which the computed value should generally be
135 // reported as the computed value of a property of a different name. In
136 // particular, the directional box properties (margin-left-value, etc.)
137 // should be reported as being margin-left, etc. Call
138 // nsCSSProps::OtherNameFor to get the other property.
139 #define CSS_PROPERTY_REPORT_OTHER_NAME (1<<7)
141 // This property allows calc() between lengths and percentages and
142 // stores such calc() expressions in its style structs (typically in an
143 // nsStyleCoord, although this is not the case for 'background-position'
144 // and 'background-size').
145 #define CSS_PROPERTY_STORES_CALC (1<<8)
147 // Define what mechanism the CSS parser uses for parsing the property.
148 // See CSSParserImpl::ParseProperty(nsCSSProperty). Don't use 0 so that
149 // we can verify that every property sets one of the values.
151 // CSS_PROPERTY_PARSE_FUNCTION must be used for shorthand properties,
152 // since it's the only mechanism that allows appending values for
153 // separate properties. Longhand properties that require custom parsing
154 // functions should prefer using CSS_PROPERTY_PARSE_VALUE (or
155 // CSS_PROPERTY_PARSE_VALUE_LIST) and
156 // CSS_PROPERTY_VALUE_PARSER_FUNCTION, though a number of existing
157 // longhand properties use CSS_PROPERTY_PARSE_FUNCTION instead.
158 #define CSS_PROPERTY_PARSE_PROPERTY_MASK (7<<9)
159 #define CSS_PROPERTY_PARSE_INACCESSIBLE (1<<9)
160 #define CSS_PROPERTY_PARSE_FUNCTION (2<<9)
161 #define CSS_PROPERTY_PARSE_VALUE (3<<9)
162 #define CSS_PROPERTY_PARSE_VALUE_LIST (4<<9)
164 // See CSSParserImpl::ParseSingleValueProperty and comment above
165 // CSS_PROPERTY_PARSE_FUNCTION (which is different).
166 #define CSS_PROPERTY_VALUE_PARSER_FUNCTION (1<<12)
167 static_assert((CSS_PROPERTY_PARSE_PROPERTY_MASK &
168 CSS_PROPERTY_VALUE_PARSER_FUNCTION) == 0,
169 "didn't leave enough room for the parse property constants");
171 #define CSS_PROPERTY_VALUE_RESTRICTION_MASK (3<<13)
172 // The parser (in particular, CSSParserImpl::ParseSingleValueProperty)
173 // should enforce that the value of this property must be 0 or larger.
174 #define CSS_PROPERTY_VALUE_NONNEGATIVE (1<<13)
175 // The parser (in particular, CSSParserImpl::ParseSingleValueProperty)
176 // should enforce that the value of this property must be 1 or larger.
177 #define CSS_PROPERTY_VALUE_AT_LEAST_ONE (2<<13)
179 // Does this property support the hashless hex color quirk in quirks mode?
180 #define CSS_PROPERTY_HASHLESS_COLOR_QUIRK (1<<15)
182 // Does this property support the unitless length quirk in quirks mode?
183 #define CSS_PROPERTY_UNITLESS_LENGTH_QUIRK (1<<16)
185 // Is this property (which must be a shorthand) really an alias?
186 #define CSS_PROPERTY_IS_ALIAS (1<<17)
188 // Does the property apply to ::-moz-placeholder?
189 #define CSS_PROPERTY_APPLIES_TO_PLACEHOLDER (1<<18)
191 // This property is allowed in an @page rule.
192 #define CSS_PROPERTY_APPLIES_TO_PAGE_RULE (1<<19)
194 // This property's getComputedStyle implementation requires layout to be
195 // flushed.
196 #define CSS_PROPERTY_GETCS_NEEDS_LAYOUT_FLUSH (1<<20)
198 // This property requires a stacking context.
199 #define CSS_PROPERTY_CREATES_STACKING_CONTEXT (1<<21)
201 // This property is always enabled in UA sheets. This is meant to be used
202 // together with a pref that enables the property for non-UA sheets.
203 // Note that if such a property has an alias, then any use of that alias
204 // in an UA sheet will still be ignored unless the pref is enabled.
205 // In other words, this bit has no effect on the use of aliases.
206 #define CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS (1<<22)
208 // This property is always enabled in chrome and in certified apps. This is
209 // meant to be used together with a pref that enables the property for
210 // non-privileged content. Note that if such a property has an alias, then any
211 // use of that alias in privileged content will still be ignored unless the
212 // pref is enabled. In other words, this bit has no effect on the use of
213 // aliases.
214 #define CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP (1<<23)
216 // This property's unitless values are pixels.
217 #define CSS_PROPERTY_NUMBERS_ARE_PIXELS (1<<24)
220 * Types of animatable values.
222 enum nsStyleAnimType {
223 // requires a custom implementation in
224 // StyleAnimationValue::ExtractComputedValue
225 eStyleAnimType_Custom,
227 // nsStyleCoord with animatable values
228 eStyleAnimType_Coord,
230 // same as Coord, except for one side of an nsStyleSides
231 // listed in the same order as the NS_STYLE_* constants
232 eStyleAnimType_Sides_Top,
233 eStyleAnimType_Sides_Right,
234 eStyleAnimType_Sides_Bottom,
235 eStyleAnimType_Sides_Left,
237 // similar, but for the *pair* of coord members of an nsStyleCorners
238 // for the relevant corner
239 eStyleAnimType_Corner_TopLeft,
240 eStyleAnimType_Corner_TopRight,
241 eStyleAnimType_Corner_BottomRight,
242 eStyleAnimType_Corner_BottomLeft,
244 // nscoord values
245 eStyleAnimType_nscoord,
247 // enumerated values (stored in a uint8_t)
248 // In order for a property to use this unit, _all_ of its enumerated values
249 // must be listed in its keyword table, so that any enumerated value can be
250 // converted into a string via a nsCSSValue of type eCSSUnit_Enumerated.
251 eStyleAnimType_EnumU8,
253 // float values
254 eStyleAnimType_float,
256 // nscolor values
257 eStyleAnimType_Color,
259 // nsStyleSVGPaint values
260 eStyleAnimType_PaintServer,
262 // nsRefPtr<nsCSSShadowArray> values
263 eStyleAnimType_Shadow,
265 // property not animatable
266 eStyleAnimType_None
269 class nsCSSProps {
270 public:
271 typedef int16_t KTableValue;
273 static void AddRefTable(void);
274 static void ReleaseTable(void);
276 enum EnabledState {
277 // The default EnabledState: only enable what's enabled for all content,
278 // given the current values of preferences.
279 eEnabledForAllContent = 0,
280 // Enable a property in UA sheets.
281 eEnabledInUASheets = 0x01,
282 // Enable a property in privileged content, i.e. chrome or Certified Apps
283 eEnabledInChromeOrCertifiedApp = 0x02,
284 // Special value to unconditionally enable a property. This implies all the
285 // bits above, but is strictly more than just their OR-ed union.
286 // This just skips any test so a property will be enabled even if it would
287 // have been disabled with all the bits above set.
288 eIgnoreEnabledState = 0xff
291 // Looks up the property with name aProperty and returns its corresponding
292 // nsCSSProperty value. If aProperty is the name of a custom property,
293 // then eCSSPropertyExtra_variable will be returned.
294 static nsCSSProperty LookupProperty(const nsAString& aProperty,
295 EnabledState aEnabled);
296 static nsCSSProperty LookupProperty(const nsACString& aProperty,
297 EnabledState aEnabled);
298 // Returns whether aProperty is a custom property name, i.e. begins with
299 // "--". This assumes that the CSS Variables pref has been enabled.
300 static bool IsCustomPropertyName(const nsAString& aProperty);
301 static bool IsCustomPropertyName(const nsACString& aProperty);
303 static inline bool IsShorthand(nsCSSProperty aProperty) {
304 NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
305 "out of range");
306 return (aProperty >= eCSSProperty_COUNT_no_shorthands);
309 // Must be given a longhand property.
310 static bool IsInherited(nsCSSProperty aProperty);
312 // Same but for @font-face descriptors
313 static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty);
314 static nsCSSFontDesc LookupFontDesc(const nsACString& aProperty);
316 // For @counter-style descriptors
317 static nsCSSCounterDesc LookupCounterDesc(const nsAString& aProperty);
318 static nsCSSCounterDesc LookupCounterDesc(const nsACString& aProperty);
320 // For predefined counter styles which need to be lower-cased during parse
321 static bool IsPredefinedCounterStyle(const nsAString& aStyle);
322 static bool IsPredefinedCounterStyle(const nsACString& aStyle);
324 // Given a property enum, get the string value
325 static const nsAFlatCString& GetStringValue(nsCSSProperty aProperty);
326 static const nsAFlatCString& GetStringValue(nsCSSFontDesc aFontDesc);
327 static const nsAFlatCString& GetStringValue(nsCSSCounterDesc aCounterDesc);
329 // Get the property to report the computed value of aProperty as being
330 // the computed value of. aProperty must have the
331 // CSS_PROPERTY_REPORT_OTHER_NAME bit set.
332 static nsCSSProperty OtherNameFor(nsCSSProperty aProperty);
334 // Given a CSS Property and a Property Enum Value
335 // Return back a const nsString& representation of the
336 // value. Return back nullstr if no value is found
337 static const nsAFlatCString& LookupPropertyValue(nsCSSProperty aProperty, int32_t aValue);
339 // Get a color name for a predefined color value like buttonhighlight or activeborder
340 // Sets the aStr param to the name of the propertyID
341 static bool GetColorName(int32_t aPropID, nsCString &aStr);
343 // Returns the index of |aKeyword| in |aTable|, if it exists there;
344 // otherwise, returns -1.
345 // NOTE: Generally, clients should call FindKeyword() instead of this method.
346 static int32_t FindIndexOfKeyword(nsCSSKeyword aKeyword,
347 const KTableValue aTable[]);
349 // Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value.
350 // If not found, return false and do not set |aValue|.
351 static bool FindKeyword(nsCSSKeyword aKeyword, const KTableValue aTable[],
352 int32_t& aValue);
353 // Return the first keyword in |aTable| that has the corresponding value |aValue|.
354 // Return |eCSSKeyword_UNKNOWN| if not found.
355 static nsCSSKeyword ValueToKeywordEnum(int32_t aValue,
356 const KTableValue aTable[]);
357 // Ditto but as a string, return "" when not found.
358 static const nsAFlatCString& ValueToKeyword(int32_t aValue,
359 const KTableValue aTable[]);
361 static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands];
362 static const KTableValue* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands];
363 static const nsStyleAnimType kAnimTypeTable[eCSSProperty_COUNT_no_shorthands];
364 static const ptrdiff_t
365 kStyleStructOffsetTable[eCSSProperty_COUNT_no_shorthands];
367 private:
368 static const uint32_t kFlagsTable[eCSSProperty_COUNT];
370 public:
371 static inline bool PropHasFlags(nsCSSProperty aProperty, uint32_t aFlags)
373 NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
374 "out of range");
375 MOZ_ASSERT(!(aFlags & CSS_PROPERTY_PARSE_PROPERTY_MASK),
376 "The CSS_PROPERTY_PARSE_* values are not bitflags; don't pass "
377 "them to PropHasFlags. You probably want PropertyParseType "
378 "instead.");
379 return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags;
382 static inline uint32_t PropertyParseType(nsCSSProperty aProperty)
384 NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
385 "out of range");
386 return nsCSSProps::kFlagsTable[aProperty] &
387 CSS_PROPERTY_PARSE_PROPERTY_MASK;
390 static inline uint32_t ValueRestrictions(nsCSSProperty aProperty)
392 NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
393 "out of range");
394 return nsCSSProps::kFlagsTable[aProperty] &
395 CSS_PROPERTY_VALUE_RESTRICTION_MASK;
398 private:
399 // Lives in nsCSSParser.cpp for the macros it depends on.
400 static const uint32_t kParserVariantTable[eCSSProperty_COUNT_no_shorthands];
402 public:
403 static inline uint32_t ParserVariant(nsCSSProperty aProperty) {
404 NS_ABORT_IF_FALSE(0 <= aProperty &&
405 aProperty < eCSSProperty_COUNT_no_shorthands,
406 "out of range");
407 return nsCSSProps::kParserVariantTable[aProperty];
410 private:
411 // A table for shorthand properties. The appropriate index is the
412 // property ID minus eCSSProperty_COUNT_no_shorthands.
413 static const nsCSSProperty *const
414 kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
416 public:
417 static inline
418 const nsCSSProperty * SubpropertyEntryFor(nsCSSProperty aProperty) {
419 NS_ABORT_IF_FALSE(eCSSProperty_COUNT_no_shorthands <= aProperty &&
420 aProperty < eCSSProperty_COUNT,
421 "out of range");
422 return nsCSSProps::kSubpropertyTable[aProperty -
423 eCSSProperty_COUNT_no_shorthands];
426 // Returns an eCSSProperty_UNKNOWN-terminated array of the shorthand
427 // properties containing |aProperty|, sorted from those that contain
428 // the most properties to those that contain the least.
429 static const nsCSSProperty * ShorthandsContaining(nsCSSProperty aProperty) {
430 NS_ABORT_IF_FALSE(gShorthandsContainingPool, "uninitialized");
431 NS_ABORT_IF_FALSE(0 <= aProperty &&
432 aProperty < eCSSProperty_COUNT_no_shorthands,
433 "out of range");
434 return gShorthandsContainingTable[aProperty];
436 private:
437 // gShorthandsContainingTable is an array of the return values for
438 // ShorthandsContaining (arrays of nsCSSProperty terminated by
439 // eCSSProperty_UNKNOWN) pointing into memory in
440 // gShorthandsContainingPool (which contains all of those arrays in a
441 // single allocation, and is the one pointer that should be |free|d).
442 static nsCSSProperty *gShorthandsContainingTable[eCSSProperty_COUNT_no_shorthands];
443 static nsCSSProperty* gShorthandsContainingPool;
444 static bool BuildShorthandsContainingTable();
446 private:
447 static const size_t gPropertyCountInStruct[nsStyleStructID_Length];
448 static const size_t gPropertyIndexInStruct[eCSSProperty_COUNT_no_shorthands];
449 public:
451 * Return the number of properties that must be cascaded when
452 * nsRuleNode builds the nsStyle* for aSID.
454 static size_t PropertyCountInStruct(nsStyleStructID aSID) {
455 NS_ABORT_IF_FALSE(0 <= aSID && aSID < nsStyleStructID_Length,
456 "out of range");
457 return gPropertyCountInStruct[aSID];
460 * Return an index for aProperty that is unique within its SID and in
461 * the range 0 <= index < PropertyCountInStruct(aSID).
463 static size_t PropertyIndexInStruct(nsCSSProperty aProperty) {
464 NS_ABORT_IF_FALSE(0 <= aProperty &&
465 aProperty < eCSSProperty_COUNT_no_shorthands,
466 "out of range");
467 return gPropertyIndexInStruct[aProperty];
470 private:
471 static bool gPropertyEnabled[eCSSProperty_COUNT_with_aliases];
473 public:
475 static bool IsEnabled(nsCSSProperty aProperty) {
476 NS_ABORT_IF_FALSE(0 <= aProperty &&
477 aProperty < eCSSProperty_COUNT_with_aliases,
478 "out of range");
479 return gPropertyEnabled[aProperty];
482 static bool IsEnabled(nsCSSProperty aProperty, EnabledState aEnabled)
484 if (IsEnabled(aProperty)) {
485 return true;
487 if (aEnabled == eIgnoreEnabledState) {
488 return true;
490 if ((aEnabled & eEnabledInUASheets) &&
491 PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS))
493 return true;
495 if ((aEnabled & eEnabledInChromeOrCertifiedApp) &&
496 PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP))
498 return true;
500 return false;
503 public:
505 #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \
506 for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \
507 *iter_ != eCSSProperty_UNKNOWN; ++iter_) \
508 if (nsCSSProps::IsEnabled(*iter_))
510 // Keyword/Enum value tables
511 static const KTableValue kAnimationDirectionKTable[];
512 static const KTableValue kAnimationFillModeKTable[];
513 static const KTableValue kAnimationIterationCountKTable[];
514 static const KTableValue kAnimationPlayStateKTable[];
515 static const KTableValue kAnimationTimingFunctionKTable[];
516 static const KTableValue kAppearanceKTable[];
517 static const KTableValue kAzimuthKTable[];
518 static const KTableValue kBackfaceVisibilityKTable[];
519 static const KTableValue kTransformStyleKTable[];
520 static const KTableValue kBackgroundAttachmentKTable[];
521 static const KTableValue kBackgroundOriginKTable[];
522 static const KTableValue kBackgroundPositionKTable[];
523 static const KTableValue kBackgroundRepeatKTable[];
524 static const KTableValue kBackgroundRepeatPartKTable[];
525 static const KTableValue kBackgroundSizeKTable[];
526 static const KTableValue kBlendModeKTable[];
527 static const KTableValue kBorderCollapseKTable[];
528 static const KTableValue kBorderColorKTable[];
529 static const KTableValue kBorderImageRepeatKTable[];
530 static const KTableValue kBorderImageSliceKTable[];
531 static const KTableValue kBorderStyleKTable[];
532 static const KTableValue kBorderWidthKTable[];
533 static const KTableValue kBoxAlignKTable[];
534 static const KTableValue kBoxDecorationBreakKTable[];
535 static const KTableValue kBoxDirectionKTable[];
536 static const KTableValue kBoxOrientKTable[];
537 static const KTableValue kBoxPackKTable[];
538 static const KTableValue kClipShapeSizingKTable[];
539 static const KTableValue kCounterRangeKTable[];
540 static const KTableValue kCounterSpeakAsKTable[];
541 static const KTableValue kCounterSymbolsSystemKTable[];
542 static const KTableValue kCounterSystemKTable[];
543 static const KTableValue kDominantBaselineKTable[];
544 static const KTableValue kShapeRadiusKTable[];
545 static const KTableValue kFillRuleKTable[];
546 static const KTableValue kFilterFunctionKTable[];
547 static const KTableValue kImageRenderingKTable[];
548 static const KTableValue kShapeRenderingKTable[];
549 static const KTableValue kStrokeLinecapKTable[];
550 static const KTableValue kStrokeLinejoinKTable[];
551 static const KTableValue kStrokeContextValueKTable[];
552 static const KTableValue kVectorEffectKTable[];
553 static const KTableValue kTextAnchorKTable[];
554 static const KTableValue kTextRenderingKTable[];
555 static const KTableValue kColorInterpolationKTable[];
556 static const KTableValue kColumnFillKTable[];
557 static const KTableValue kBoxPropSourceKTable[];
558 static const KTableValue kBoxShadowTypeKTable[];
559 static const KTableValue kBoxSizingKTable[];
560 static const KTableValue kCaptionSideKTable[];
561 static const KTableValue kClearKTable[];
562 static const KTableValue kColorKTable[];
563 static const KTableValue kContentKTable[];
564 static const KTableValue kControlCharacterVisibilityKTable[];
565 static const KTableValue kCursorKTable[];
566 static const KTableValue kDirectionKTable[];
567 // Not const because we modify its entries when various
568 // "layout.css.*.enabled" prefs changes:
569 static KTableValue kDisplayKTable[];
570 static const KTableValue kElevationKTable[];
571 static const KTableValue kEmptyCellsKTable[];
572 static const KTableValue kAlignContentKTable[];
573 static const KTableValue kAlignItemsKTable[];
574 static const KTableValue kAlignSelfKTable[];
575 static const KTableValue kFlexDirectionKTable[];
576 static const KTableValue kFlexWrapKTable[];
577 static const KTableValue kJustifyContentKTable[];
578 static const KTableValue kFloatKTable[];
579 static const KTableValue kFloatEdgeKTable[];
580 static const KTableValue kFontKTable[];
581 static const KTableValue kFontKerningKTable[];
582 static const KTableValue kFontSizeKTable[];
583 static const KTableValue kFontSmoothingKTable[];
584 static const KTableValue kFontStretchKTable[];
585 static const KTableValue kFontStyleKTable[];
586 static const KTableValue kFontSynthesisKTable[];
587 static const KTableValue kFontVariantKTable[];
588 static const KTableValue kFontVariantAlternatesKTable[];
589 static const KTableValue kFontVariantAlternatesFuncsKTable[];
590 static const KTableValue kFontVariantCapsKTable[];
591 static const KTableValue kFontVariantEastAsianKTable[];
592 static const KTableValue kFontVariantLigaturesKTable[];
593 static const KTableValue kFontVariantNumericKTable[];
594 static const KTableValue kFontVariantPositionKTable[];
595 static const KTableValue kFontWeightKTable[];
596 static const KTableValue kGridAutoFlowKTable[];
597 static const KTableValue kGridTrackBreadthKTable[];
598 static const KTableValue kHyphensKTable[];
599 static const KTableValue kImageOrientationKTable[];
600 static const KTableValue kImageOrientationFlipKTable[];
601 static const KTableValue kIsolationKTable[];
602 static const KTableValue kIMEModeKTable[];
603 static const KTableValue kLineHeightKTable[];
604 static const KTableValue kListStylePositionKTable[];
605 static const KTableValue kListStyleKTable[];
606 static const KTableValue kMaskTypeKTable[];
607 static const KTableValue kMathVariantKTable[];
608 static const KTableValue kMathDisplayKTable[];
609 static const KTableValue kContextOpacityKTable[];
610 static const KTableValue kContextPatternKTable[];
611 static const KTableValue kObjectFitKTable[];
612 static const KTableValue kOrientKTable[];
613 static const KTableValue kOutlineStyleKTable[];
614 static const KTableValue kOutlineColorKTable[];
615 static const KTableValue kOverflowKTable[];
616 static const KTableValue kOverflowSubKTable[];
617 static const KTableValue kOverflowClipBoxKTable[];
618 static const KTableValue kPageBreakKTable[];
619 static const KTableValue kPageBreakInsideKTable[];
620 static const KTableValue kPageMarksKTable[];
621 static const KTableValue kPageSizeKTable[];
622 static const KTableValue kPitchKTable[];
623 static const KTableValue kPointerEventsKTable[];
624 // Not const because we modify its entries when the pref
625 // "layout.css.sticky.enabled" changes:
626 static KTableValue kPositionKTable[];
627 static const KTableValue kRadialGradientShapeKTable[];
628 static const KTableValue kRadialGradientSizeKTable[];
629 static const KTableValue kRadialGradientLegacySizeKTable[];
630 static const KTableValue kResizeKTable[];
631 static const KTableValue kRubyPositionKTable[];
632 static const KTableValue kScrollBehaviorKTable[];
633 static const KTableValue kSpeakKTable[];
634 static const KTableValue kSpeakHeaderKTable[];
635 static const KTableValue kSpeakNumeralKTable[];
636 static const KTableValue kSpeakPunctuationKTable[];
637 static const KTableValue kSpeechRateKTable[];
638 static const KTableValue kStackSizingKTable[];
639 static const KTableValue kTableLayoutKTable[];
640 // Not const because we modify its entries when the pref
641 // "layout.css.text-align-true-value.enabled" changes:
642 static KTableValue kTextAlignKTable[];
643 static KTableValue kTextAlignLastKTable[];
644 static const KTableValue kTextCombineUprightKTable[];
645 static const KTableValue kTextDecorationLineKTable[];
646 static const KTableValue kTextDecorationStyleKTable[];
647 static const KTableValue kTextOrientationKTable[];
648 static const KTableValue kTextOverflowKTable[];
649 static const KTableValue kTextTransformKTable[];
650 static const KTableValue kTouchActionKTable[];
651 static const KTableValue kTransitionTimingFunctionKTable[];
652 static const KTableValue kUnicodeBidiKTable[];
653 static const KTableValue kUserFocusKTable[];
654 static const KTableValue kUserInputKTable[];
655 static const KTableValue kUserModifyKTable[];
656 static const KTableValue kUserSelectKTable[];
657 static const KTableValue kVerticalAlignKTable[];
658 static const KTableValue kVisibilityKTable[];
659 static const KTableValue kVolumeKTable[];
660 static const KTableValue kWhitespaceKTable[];
661 static const KTableValue kWidthKTable[]; // also min-width, max-width
662 static const KTableValue kWindowDraggingKTable[];
663 static const KTableValue kWindowShadowKTable[];
664 static const KTableValue kWordBreakKTable[];
665 static const KTableValue kWordWrapKTable[];
666 static const KTableValue kWritingModeKTable[];
669 inline nsCSSProps::EnabledState operator|(nsCSSProps::EnabledState a,
670 nsCSSProps::EnabledState b)
672 return nsCSSProps::EnabledState(int(a) | int(b));
675 inline nsCSSProps::EnabledState operator&(nsCSSProps::EnabledState a,
676 nsCSSProps::EnabledState b)
678 return nsCSSProps::EnabledState(int(a) & int(b));
681 inline nsCSSProps::EnabledState& operator|=(nsCSSProps::EnabledState& a,
682 nsCSSProps::EnabledState b)
684 return a = a | b;
687 inline nsCSSProps::EnabledState& operator&=(nsCSSProps::EnabledState& a,
688 nsCSSProps::EnabledState b)
690 return a = a & b;
693 #endif /* nsCSSProps_h___ */