layout/style/nsCSSProps.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial