1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsCSSProps.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,670 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * methods for dealing with CSS properties and tables of the keyword 1.11 + * values they accept 1.12 + */ 1.13 + 1.14 +#ifndef nsCSSProps_h___ 1.15 +#define nsCSSProps_h___ 1.16 + 1.17 +#include "nsString.h" 1.18 +#include "nsCSSProperty.h" 1.19 +#include "nsStyleStructFwd.h" 1.20 +#include "nsCSSKeywords.h" 1.21 + 1.22 +// Length of the "--" prefix on custom names (such as custom property names, 1.23 +// and, in the future, custom media query names). 1.24 +#define CSS_CUSTOM_NAME_PREFIX_LENGTH 2 1.25 + 1.26 +// Flags for ParseVariant method 1.27 +#define VARIANT_KEYWORD 0x000001 // K 1.28 +#define VARIANT_LENGTH 0x000002 // L 1.29 +#define VARIANT_PERCENT 0x000004 // P 1.30 +#define VARIANT_COLOR 0x000008 // C eCSSUnit_*Color, eCSSUnit_Ident (e.g. "red") 1.31 +#define VARIANT_URL 0x000010 // U 1.32 +#define VARIANT_NUMBER 0x000020 // N 1.33 +#define VARIANT_INTEGER 0x000040 // I 1.34 +#define VARIANT_ANGLE 0x000080 // G 1.35 +#define VARIANT_FREQUENCY 0x000100 // F 1.36 +#define VARIANT_TIME 0x000200 // T 1.37 +#define VARIANT_STRING 0x000400 // S 1.38 +#define VARIANT_COUNTER 0x000800 // 1.39 +#define VARIANT_ATTR 0x001000 // 1.40 +#define VARIANT_IDENTIFIER 0x002000 // D 1.41 +#define VARIANT_IDENTIFIER_NO_INHERIT 0x004000 // like above, but excluding 1.42 +// 'inherit' and 'initial' 1.43 +#define VARIANT_AUTO 0x010000 // A 1.44 +#define VARIANT_INHERIT 0x020000 // H eCSSUnit_Initial, eCSSUnit_Inherit, eCSSUnit_Unset 1.45 +#define VARIANT_NONE 0x040000 // O 1.46 +#define VARIANT_NORMAL 0x080000 // M 1.47 +#define VARIANT_SYSFONT 0x100000 // eCSSUnit_System_Font 1.48 +#define VARIANT_GRADIENT 0x200000 // eCSSUnit_Gradient 1.49 +#define VARIANT_TIMING_FUNCTION 0x400000 // cubic-bezier() and steps() 1.50 +#define VARIANT_ALL 0x800000 // 1.51 +#define VARIANT_IMAGE_RECT 0x01000000 // eCSSUnit_Function 1.52 +// This is an extra bit that says that a VARIANT_ANGLE allows unitless zero: 1.53 +#define VARIANT_ZERO_ANGLE 0x02000000 // unitless zero for angles 1.54 +#define VARIANT_CALC 0x04000000 // eCSSUnit_Calc 1.55 +#define VARIANT_ELEMENT 0x08000000 // eCSSUnit_Element 1.56 +#define VARIANT_POSITIVE_DIMENSION 0x10000000 // Only lengths greater than 0.0 1.57 +#define VARIANT_NONNEGATIVE_DIMENSION 0x20000000 // Only lengths greater than or equal to 0.0 1.58 +// Keyword used iff gfx.font_rendering.opentype_svg.enabled is true: 1.59 +#define VARIANT_OPENTYPE_SVG_KEYWORD 0x40000000 1.60 + 1.61 +// Common combinations of variants 1.62 +#define VARIANT_AL (VARIANT_AUTO | VARIANT_LENGTH) 1.63 +#define VARIANT_LP (VARIANT_LENGTH | VARIANT_PERCENT) 1.64 +#define VARIANT_LN (VARIANT_LENGTH | VARIANT_NUMBER) 1.65 +#define VARIANT_AH (VARIANT_AUTO | VARIANT_INHERIT) 1.66 +#define VARIANT_AHLP (VARIANT_AH | VARIANT_LP) 1.67 +#define VARIANT_AHI (VARIANT_AH | VARIANT_INTEGER) 1.68 +#define VARIANT_AHK (VARIANT_AH | VARIANT_KEYWORD) 1.69 +#define VARIANT_AHKLP (VARIANT_AHLP | VARIANT_KEYWORD) 1.70 +#define VARIANT_AHL (VARIANT_AH | VARIANT_LENGTH) 1.71 +#define VARIANT_AHKL (VARIANT_AHK | VARIANT_LENGTH) 1.72 +#define VARIANT_HK (VARIANT_INHERIT | VARIANT_KEYWORD) 1.73 +#define VARIANT_HKF (VARIANT_HK | VARIANT_FREQUENCY) 1.74 +#define VARIANT_HKI (VARIANT_HK | VARIANT_INTEGER) 1.75 +#define VARIANT_HKL (VARIANT_HK | VARIANT_LENGTH) 1.76 +#define VARIANT_HKLP (VARIANT_HK | VARIANT_LP) 1.77 +#define VARIANT_HKLPO (VARIANT_HKLP | VARIANT_NONE) 1.78 +#define VARIANT_HL (VARIANT_INHERIT | VARIANT_LENGTH) 1.79 +#define VARIANT_HI (VARIANT_INHERIT | VARIANT_INTEGER) 1.80 +#define VARIANT_HLP (VARIANT_HL | VARIANT_PERCENT) 1.81 +#define VARIANT_HLPN (VARIANT_HLP | VARIANT_NUMBER) 1.82 +#define VARIANT_HLPO (VARIANT_HLP | VARIANT_NONE) 1.83 +#define VARIANT_HTP (VARIANT_INHERIT | VARIANT_TIME | VARIANT_PERCENT) 1.84 +#define VARIANT_HMK (VARIANT_HK | VARIANT_NORMAL) 1.85 +#define VARIANT_HC (VARIANT_INHERIT | VARIANT_COLOR) 1.86 +#define VARIANT_HCK (VARIANT_HK | VARIANT_COLOR) 1.87 +#define VARIANT_HUK (VARIANT_HK | VARIANT_URL) 1.88 +#define VARIANT_HUO (VARIANT_INHERIT | VARIANT_URL | VARIANT_NONE) 1.89 +#define VARIANT_AHUO (VARIANT_AUTO | VARIANT_HUO) 1.90 +#define VARIANT_HPN (VARIANT_INHERIT | VARIANT_PERCENT | VARIANT_NUMBER) 1.91 +#define VARIANT_PN (VARIANT_PERCENT | VARIANT_NUMBER) 1.92 +#define VARIANT_ALPN (VARIANT_AL | VARIANT_PN) 1.93 +#define VARIANT_HN (VARIANT_INHERIT | VARIANT_NUMBER) 1.94 +#define VARIANT_HON (VARIANT_HN | VARIANT_NONE) 1.95 +#define VARIANT_HOS (VARIANT_INHERIT | VARIANT_NONE | VARIANT_STRING) 1.96 +#define VARIANT_LPN (VARIANT_LP | VARIANT_NUMBER) 1.97 +#define VARIANT_UK (VARIANT_URL | VARIANT_KEYWORD) 1.98 +#define VARIANT_UO (VARIANT_URL | VARIANT_NONE) 1.99 +#define VARIANT_ANGLE_OR_ZERO (VARIANT_ANGLE | VARIANT_ZERO_ANGLE) 1.100 +#define VARIANT_LCALC (VARIANT_LENGTH | VARIANT_CALC) 1.101 +#define VARIANT_LPCALC (VARIANT_LCALC | VARIANT_PERCENT) 1.102 +#define VARIANT_LNCALC (VARIANT_LCALC | VARIANT_NUMBER) 1.103 +#define VARIANT_LPNCALC (VARIANT_LNCALC | VARIANT_PERCENT) 1.104 +#define VARIANT_IMAGE (VARIANT_URL | VARIANT_NONE | VARIANT_GRADIENT | \ 1.105 + VARIANT_IMAGE_RECT | VARIANT_ELEMENT) 1.106 + 1.107 +// Flags for the kFlagsTable bitfield (flags_ in nsCSSPropList.h) 1.108 + 1.109 +// A property that is a *-ltr-source or *-rtl-source property for one of 1.110 +// the directional pseudo-shorthand properties. 1.111 +#define CSS_PROPERTY_DIRECTIONAL_SOURCE (1<<0) 1.112 + 1.113 +#define CSS_PROPERTY_VALUE_LIST_USES_COMMAS (1<<1) /* otherwise spaces */ 1.114 + 1.115 +#define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER (1<<2) 1.116 +#define CSS_PROPERTY_APPLIES_TO_FIRST_LINE (1<<3) 1.117 +#define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE \ 1.118 + (CSS_PROPERTY_APPLIES_TO_FIRST_LETTER | CSS_PROPERTY_APPLIES_TO_FIRST_LINE) 1.119 + 1.120 +// Note that 'background-color' is ignored differently from the other 1.121 +// properties that have this set, but that's just special-cased. 1.122 +#define CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED (1<<4) 1.123 + 1.124 +// A property that needs to have image loads started when a URL value 1.125 +// for the property is used for an element. This is supported only 1.126 +// for a few possible value formats: image directly in the value; list 1.127 +// of images; and with CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0, image in slot 1.128 +// 0 of an array, or list of such arrays. 1.129 +#define CSS_PROPERTY_START_IMAGE_LOADS (1<<5) 1.130 + 1.131 +// Should be set only for properties with START_IMAGE_LOADS. Indicates 1.132 +// that the property has an array value with a URL/image value at index 1.133 +// 0 in the array, rather than the URL/image being in the value or value 1.134 +// list. 1.135 +#define CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0 (1<<6) 1.136 + 1.137 +// This is a property for which the computed value should generally be 1.138 +// reported as the computed value of a property of a different name. In 1.139 +// particular, the directional box properties (margin-left-value, etc.) 1.140 +// should be reported as being margin-left, etc. Call 1.141 +// nsCSSProps::OtherNameFor to get the other property. 1.142 +#define CSS_PROPERTY_REPORT_OTHER_NAME (1<<7) 1.143 + 1.144 +// This property allows calc() between lengths and percentages and 1.145 +// stores such calc() expressions in its style structs (typically in an 1.146 +// nsStyleCoord, although this is not the case for 'background-position' 1.147 +// and 'background-size'). 1.148 +#define CSS_PROPERTY_STORES_CALC (1<<8) 1.149 + 1.150 +// Define what mechanism the CSS parser uses for parsing the property. 1.151 +// See CSSParserImpl::ParseProperty(nsCSSProperty). Don't use 0 so that 1.152 +// we can verify that every property sets one of the values. 1.153 +// 1.154 +// CSS_PROPERTY_PARSE_FUNCTION must be used for shorthand properties, 1.155 +// since it's the only mechanism that allows appending values for 1.156 +// separate properties. Longhand properties that require custom parsing 1.157 +// functions should prefer using CSS_PROPERTY_PARSE_VALUE (or 1.158 +// CSS_PROPERTY_PARSE_VALUE_LIST) and 1.159 +// CSS_PROPERTY_VALUE_PARSER_FUNCTION, though a number of existing 1.160 +// longhand properties use CSS_PROPERTY_PARSE_FUNCTION instead. 1.161 +#define CSS_PROPERTY_PARSE_PROPERTY_MASK (7<<9) 1.162 +#define CSS_PROPERTY_PARSE_INACCESSIBLE (1<<9) 1.163 +#define CSS_PROPERTY_PARSE_FUNCTION (2<<9) 1.164 +#define CSS_PROPERTY_PARSE_VALUE (3<<9) 1.165 +#define CSS_PROPERTY_PARSE_VALUE_LIST (4<<9) 1.166 + 1.167 +// See CSSParserImpl::ParseSingleValueProperty and comment above 1.168 +// CSS_PROPERTY_PARSE_FUNCTION (which is different). 1.169 +#define CSS_PROPERTY_VALUE_PARSER_FUNCTION (1<<12) 1.170 +static_assert((CSS_PROPERTY_PARSE_PROPERTY_MASK & 1.171 + CSS_PROPERTY_VALUE_PARSER_FUNCTION) == 0, 1.172 + "didn't leave enough room for the parse property constants"); 1.173 + 1.174 +#define CSS_PROPERTY_VALUE_RESTRICTION_MASK (3<<13) 1.175 +// The parser (in particular, CSSParserImpl::ParseSingleValueProperty) 1.176 +// should enforce that the value of this property must be 0 or larger. 1.177 +#define CSS_PROPERTY_VALUE_NONNEGATIVE (1<<13) 1.178 +// The parser (in particular, CSSParserImpl::ParseSingleValueProperty) 1.179 +// should enforce that the value of this property must be 1 or larger. 1.180 +#define CSS_PROPERTY_VALUE_AT_LEAST_ONE (2<<13) 1.181 + 1.182 +// Does this property support the hashless hex color quirk in quirks mode? 1.183 +#define CSS_PROPERTY_HASHLESS_COLOR_QUIRK (1<<15) 1.184 + 1.185 +// Does this property support the unitless length quirk in quirks mode? 1.186 +#define CSS_PROPERTY_UNITLESS_LENGTH_QUIRK (1<<16) 1.187 + 1.188 +// Is this property (which must be a shorthand) really an alias? 1.189 +#define CSS_PROPERTY_IS_ALIAS (1<<17) 1.190 + 1.191 +// Does the property apply to ::-moz-placeholder? 1.192 +#define CSS_PROPERTY_APPLIES_TO_PLACEHOLDER (1<<18) 1.193 + 1.194 +// This property is allowed in an @page rule. 1.195 +#define CSS_PROPERTY_APPLIES_TO_PAGE_RULE (1<<19) 1.196 + 1.197 +// This property's getComputedStyle implementation requires layout to be 1.198 +// flushed. 1.199 +#define CSS_PROPERTY_GETCS_NEEDS_LAYOUT_FLUSH (1<<20) 1.200 + 1.201 +// This property requires a stacking context. 1.202 +#define CSS_PROPERTY_CREATES_STACKING_CONTEXT (1<<21) 1.203 + 1.204 +// This property is always enabled in UA sheets. This is meant to be used 1.205 +// together with a pref that enables the property for non-UA sheets. 1.206 +// Note that if such a property has an alias, then any use of that alias 1.207 +// in an UA sheet will still be ignored unless the pref is enabled. 1.208 +// In other words, this bit has no effect on the use of aliases. 1.209 +#define CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS (1<<22) 1.210 + 1.211 +// This property is always enabled in chrome and in certified apps. This is 1.212 +// meant to be used together with a pref that enables the property for 1.213 +// non-privileged content. Note that if such a property has an alias, then any 1.214 +// use of that alias in privileged content will still be ignored unless the 1.215 +// pref is enabled. In other words, this bit has no effect on the use of 1.216 +// aliases. 1.217 +#define CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP (1<<23) 1.218 + 1.219 +/** 1.220 + * Types of animatable values. 1.221 + */ 1.222 +enum nsStyleAnimType { 1.223 + // requires a custom implementation in 1.224 + // nsStyleAnimation::ExtractComputedValue 1.225 + eStyleAnimType_Custom, 1.226 + 1.227 + // nsStyleCoord with animatable values 1.228 + eStyleAnimType_Coord, 1.229 + 1.230 + // same as Coord, except for one side of an nsStyleSides 1.231 + // listed in the same order as the NS_STYLE_* constants 1.232 + eStyleAnimType_Sides_Top, 1.233 + eStyleAnimType_Sides_Right, 1.234 + eStyleAnimType_Sides_Bottom, 1.235 + eStyleAnimType_Sides_Left, 1.236 + 1.237 + // similar, but for the *pair* of coord members of an nsStyleCorners 1.238 + // for the relevant corner 1.239 + eStyleAnimType_Corner_TopLeft, 1.240 + eStyleAnimType_Corner_TopRight, 1.241 + eStyleAnimType_Corner_BottomRight, 1.242 + eStyleAnimType_Corner_BottomLeft, 1.243 + 1.244 + // nscoord values 1.245 + eStyleAnimType_nscoord, 1.246 + 1.247 + // enumerated values (stored in a uint8_t) 1.248 + // In order for a property to use this unit, _all_ of its enumerated values 1.249 + // must be listed in its keyword table, so that any enumerated value can be 1.250 + // converted into a string via a nsCSSValue of type eCSSUnit_Enumerated. 1.251 + eStyleAnimType_EnumU8, 1.252 + 1.253 + // float values 1.254 + eStyleAnimType_float, 1.255 + 1.256 + // nscolor values 1.257 + eStyleAnimType_Color, 1.258 + 1.259 + // nsStyleSVGPaint values 1.260 + eStyleAnimType_PaintServer, 1.261 + 1.262 + // nsRefPtr<nsCSSShadowArray> values 1.263 + eStyleAnimType_Shadow, 1.264 + 1.265 + // property not animatable 1.266 + eStyleAnimType_None 1.267 +}; 1.268 + 1.269 +class nsCSSProps { 1.270 +public: 1.271 + typedef int16_t KTableValue; 1.272 + 1.273 + static void AddRefTable(void); 1.274 + static void ReleaseTable(void); 1.275 + 1.276 + enum EnabledState { 1.277 + // The default EnabledState: only enable what's enabled for all content, 1.278 + // given the current values of preferences. 1.279 + eEnabledForAllContent = 0, 1.280 + // Enable a property in UA sheets. 1.281 + eEnabledInUASheets = 0x01, 1.282 + // Enable a property in privileged content, i.e. chrome or Certified Apps 1.283 + eEnabledInChromeOrCertifiedApp = 0x02, 1.284 + // Special value to unconditionally enable a property. This implies all the 1.285 + // bits above, but is strictly more than just their OR-ed union. 1.286 + // This just skips any test so a property will be enabled even if it would 1.287 + // have been disabled with all the bits above set. 1.288 + eIgnoreEnabledState = 0xff 1.289 + }; 1.290 + 1.291 + // Looks up the property with name aProperty and returns its corresponding 1.292 + // nsCSSProperty value. If aProperty is the name of a custom property, 1.293 + // then eCSSPropertyExtra_variable will be returned. 1.294 + static nsCSSProperty LookupProperty(const nsAString& aProperty, 1.295 + EnabledState aEnabled); 1.296 + static nsCSSProperty LookupProperty(const nsACString& aProperty, 1.297 + EnabledState aEnabled); 1.298 + // Returns whether aProperty is a custom property name, i.e. begins with 1.299 + // "--". This assumes that the CSS Variables pref has been enabled. 1.300 + static bool IsCustomPropertyName(const nsAString& aProperty); 1.301 + static bool IsCustomPropertyName(const nsACString& aProperty); 1.302 + 1.303 + static inline bool IsShorthand(nsCSSProperty aProperty) { 1.304 + NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, 1.305 + "out of range"); 1.306 + return (aProperty >= eCSSProperty_COUNT_no_shorthands); 1.307 + } 1.308 + 1.309 + // Must be given a longhand property. 1.310 + static bool IsInherited(nsCSSProperty aProperty); 1.311 + 1.312 + // Same but for @font-face descriptors 1.313 + static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty); 1.314 + static nsCSSFontDesc LookupFontDesc(const nsACString& aProperty); 1.315 + 1.316 + // Given a property enum, get the string value 1.317 + static const nsAFlatCString& GetStringValue(nsCSSProperty aProperty); 1.318 + static const nsAFlatCString& GetStringValue(nsCSSFontDesc aFontDesc); 1.319 + 1.320 + // Get the property to report the computed value of aProperty as being 1.321 + // the computed value of. aProperty must have the 1.322 + // CSS_PROPERTY_REPORT_OTHER_NAME bit set. 1.323 + static nsCSSProperty OtherNameFor(nsCSSProperty aProperty); 1.324 + 1.325 + // Given a CSS Property and a Property Enum Value 1.326 + // Return back a const nsString& representation of the 1.327 + // value. Return back nullstr if no value is found 1.328 + static const nsAFlatCString& LookupPropertyValue(nsCSSProperty aProperty, int32_t aValue); 1.329 + 1.330 + // Get a color name for a predefined color value like buttonhighlight or activeborder 1.331 + // Sets the aStr param to the name of the propertyID 1.332 + static bool GetColorName(int32_t aPropID, nsCString &aStr); 1.333 + 1.334 + // Returns the index of |aKeyword| in |aTable|, if it exists there; 1.335 + // otherwise, returns -1. 1.336 + // NOTE: Generally, clients should call FindKeyword() instead of this method. 1.337 + static int32_t FindIndexOfKeyword(nsCSSKeyword aKeyword, 1.338 + const KTableValue aTable[]); 1.339 + 1.340 + // Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value. 1.341 + // If not found, return false and do not set |aValue|. 1.342 + static bool FindKeyword(nsCSSKeyword aKeyword, const KTableValue aTable[], 1.343 + int32_t& aValue); 1.344 + // Return the first keyword in |aTable| that has the corresponding value |aValue|. 1.345 + // Return |eCSSKeyword_UNKNOWN| if not found. 1.346 + static nsCSSKeyword ValueToKeywordEnum(int32_t aValue, 1.347 + const KTableValue aTable[]); 1.348 + // Ditto but as a string, return "" when not found. 1.349 + static const nsAFlatCString& ValueToKeyword(int32_t aValue, 1.350 + const KTableValue aTable[]); 1.351 + 1.352 + static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands]; 1.353 + static const KTableValue* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands]; 1.354 + static const nsStyleAnimType kAnimTypeTable[eCSSProperty_COUNT_no_shorthands]; 1.355 + static const ptrdiff_t 1.356 + kStyleStructOffsetTable[eCSSProperty_COUNT_no_shorthands]; 1.357 + 1.358 +private: 1.359 + static const uint32_t kFlagsTable[eCSSProperty_COUNT]; 1.360 + 1.361 +public: 1.362 + static inline bool PropHasFlags(nsCSSProperty aProperty, uint32_t aFlags) 1.363 + { 1.364 + NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, 1.365 + "out of range"); 1.366 + MOZ_ASSERT(!(aFlags & CSS_PROPERTY_PARSE_PROPERTY_MASK), 1.367 + "The CSS_PROPERTY_PARSE_* values are not bitflags; don't pass " 1.368 + "them to PropHasFlags. You probably want PropertyParseType " 1.369 + "instead."); 1.370 + return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags; 1.371 + } 1.372 + 1.373 + static inline uint32_t PropertyParseType(nsCSSProperty aProperty) 1.374 + { 1.375 + NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, 1.376 + "out of range"); 1.377 + return nsCSSProps::kFlagsTable[aProperty] & 1.378 + CSS_PROPERTY_PARSE_PROPERTY_MASK; 1.379 + } 1.380 + 1.381 + static inline uint32_t ValueRestrictions(nsCSSProperty aProperty) 1.382 + { 1.383 + NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, 1.384 + "out of range"); 1.385 + return nsCSSProps::kFlagsTable[aProperty] & 1.386 + CSS_PROPERTY_VALUE_RESTRICTION_MASK; 1.387 + } 1.388 + 1.389 +private: 1.390 + // Lives in nsCSSParser.cpp for the macros it depends on. 1.391 + static const uint32_t kParserVariantTable[eCSSProperty_COUNT_no_shorthands]; 1.392 + 1.393 +public: 1.394 + static inline uint32_t ParserVariant(nsCSSProperty aProperty) { 1.395 + NS_ABORT_IF_FALSE(0 <= aProperty && 1.396 + aProperty < eCSSProperty_COUNT_no_shorthands, 1.397 + "out of range"); 1.398 + return nsCSSProps::kParserVariantTable[aProperty]; 1.399 + } 1.400 + 1.401 +private: 1.402 + // A table for shorthand properties. The appropriate index is the 1.403 + // property ID minus eCSSProperty_COUNT_no_shorthands. 1.404 + static const nsCSSProperty *const 1.405 + kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands]; 1.406 + 1.407 +public: 1.408 + static inline 1.409 + const nsCSSProperty * SubpropertyEntryFor(nsCSSProperty aProperty) { 1.410 + NS_ABORT_IF_FALSE(eCSSProperty_COUNT_no_shorthands <= aProperty && 1.411 + aProperty < eCSSProperty_COUNT, 1.412 + "out of range"); 1.413 + return nsCSSProps::kSubpropertyTable[aProperty - 1.414 + eCSSProperty_COUNT_no_shorthands]; 1.415 + } 1.416 + 1.417 + // Returns an eCSSProperty_UNKNOWN-terminated array of the shorthand 1.418 + // properties containing |aProperty|, sorted from those that contain 1.419 + // the most properties to those that contain the least. 1.420 + static const nsCSSProperty * ShorthandsContaining(nsCSSProperty aProperty) { 1.421 + NS_ABORT_IF_FALSE(gShorthandsContainingPool, "uninitialized"); 1.422 + NS_ABORT_IF_FALSE(0 <= aProperty && 1.423 + aProperty < eCSSProperty_COUNT_no_shorthands, 1.424 + "out of range"); 1.425 + return gShorthandsContainingTable[aProperty]; 1.426 + } 1.427 +private: 1.428 + // gShorthandsContainingTable is an array of the return values for 1.429 + // ShorthandsContaining (arrays of nsCSSProperty terminated by 1.430 + // eCSSProperty_UNKNOWN) pointing into memory in 1.431 + // gShorthandsContainingPool (which contains all of those arrays in a 1.432 + // single allocation, and is the one pointer that should be |free|d). 1.433 + static nsCSSProperty *gShorthandsContainingTable[eCSSProperty_COUNT_no_shorthands]; 1.434 + static nsCSSProperty* gShorthandsContainingPool; 1.435 + static bool BuildShorthandsContainingTable(); 1.436 + 1.437 +private: 1.438 + static const size_t gPropertyCountInStruct[nsStyleStructID_Length]; 1.439 + static const size_t gPropertyIndexInStruct[eCSSProperty_COUNT_no_shorthands]; 1.440 +public: 1.441 + /** 1.442 + * Return the number of properties that must be cascaded when 1.443 + * nsRuleNode builds the nsStyle* for aSID. 1.444 + */ 1.445 + static size_t PropertyCountInStruct(nsStyleStructID aSID) { 1.446 + NS_ABORT_IF_FALSE(0 <= aSID && aSID < nsStyleStructID_Length, 1.447 + "out of range"); 1.448 + return gPropertyCountInStruct[aSID]; 1.449 + } 1.450 + /** 1.451 + * Return an index for aProperty that is unique within its SID and in 1.452 + * the range 0 <= index < PropertyCountInStruct(aSID). 1.453 + */ 1.454 + static size_t PropertyIndexInStruct(nsCSSProperty aProperty) { 1.455 + NS_ABORT_IF_FALSE(0 <= aProperty && 1.456 + aProperty < eCSSProperty_COUNT_no_shorthands, 1.457 + "out of range"); 1.458 + return gPropertyIndexInStruct[aProperty]; 1.459 + } 1.460 + 1.461 +private: 1.462 + static bool gPropertyEnabled[eCSSProperty_COUNT_with_aliases]; 1.463 + 1.464 +public: 1.465 + 1.466 + static bool IsEnabled(nsCSSProperty aProperty) { 1.467 + NS_ABORT_IF_FALSE(0 <= aProperty && 1.468 + aProperty < eCSSProperty_COUNT_with_aliases, 1.469 + "out of range"); 1.470 + return gPropertyEnabled[aProperty]; 1.471 + } 1.472 + 1.473 + static bool IsEnabled(nsCSSProperty aProperty, EnabledState aEnabled) 1.474 + { 1.475 + if (IsEnabled(aProperty)) { 1.476 + return true; 1.477 + } 1.478 + if (aEnabled == eIgnoreEnabledState) { 1.479 + return true; 1.480 + } 1.481 + if ((aEnabled & eEnabledInUASheets) && 1.482 + PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS)) 1.483 + { 1.484 + return true; 1.485 + } 1.486 + if ((aEnabled & eEnabledInChromeOrCertifiedApp) && 1.487 + PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP)) 1.488 + { 1.489 + return true; 1.490 + } 1.491 + return false; 1.492 + } 1.493 + 1.494 +public: 1.495 + 1.496 +#define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \ 1.497 + for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \ 1.498 + *iter_ != eCSSProperty_UNKNOWN; ++iter_) \ 1.499 + if (nsCSSProps::IsEnabled(*iter_)) 1.500 + 1.501 + // Keyword/Enum value tables 1.502 + static const KTableValue kAnimationDirectionKTable[]; 1.503 + static const KTableValue kAnimationFillModeKTable[]; 1.504 + static const KTableValue kAnimationIterationCountKTable[]; 1.505 + static const KTableValue kAnimationPlayStateKTable[]; 1.506 + static const KTableValue kAnimationTimingFunctionKTable[]; 1.507 + static const KTableValue kAppearanceKTable[]; 1.508 + static const KTableValue kAzimuthKTable[]; 1.509 + static const KTableValue kBackfaceVisibilityKTable[]; 1.510 + static const KTableValue kTransformStyleKTable[]; 1.511 + static const KTableValue kBackgroundAttachmentKTable[]; 1.512 + static const KTableValue kBackgroundInlinePolicyKTable[]; 1.513 + static const KTableValue kBackgroundOriginKTable[]; 1.514 + static const KTableValue kBackgroundPositionKTable[]; 1.515 + static const KTableValue kBackgroundRepeatKTable[]; 1.516 + static const KTableValue kBackgroundRepeatPartKTable[]; 1.517 + static const KTableValue kBackgroundSizeKTable[]; 1.518 + static const KTableValue kBlendModeKTable[]; 1.519 + static const KTableValue kBorderCollapseKTable[]; 1.520 + static const KTableValue kBorderColorKTable[]; 1.521 + static const KTableValue kBorderImageRepeatKTable[]; 1.522 + static const KTableValue kBorderImageSliceKTable[]; 1.523 + static const KTableValue kBorderStyleKTable[]; 1.524 + static const KTableValue kBorderWidthKTable[]; 1.525 + static const KTableValue kBoxAlignKTable[]; 1.526 + static const KTableValue kBoxDirectionKTable[]; 1.527 + static const KTableValue kBoxOrientKTable[]; 1.528 + static const KTableValue kBoxPackKTable[]; 1.529 + static const KTableValue kDominantBaselineKTable[]; 1.530 + static const KTableValue kFillRuleKTable[]; 1.531 + static const KTableValue kFilterFunctionKTable[]; 1.532 + static const KTableValue kImageRenderingKTable[]; 1.533 + static const KTableValue kShapeRenderingKTable[]; 1.534 + static const KTableValue kStrokeLinecapKTable[]; 1.535 + static const KTableValue kStrokeLinejoinKTable[]; 1.536 + static const KTableValue kStrokeContextValueKTable[]; 1.537 + static const KTableValue kVectorEffectKTable[]; 1.538 + static const KTableValue kTextAnchorKTable[]; 1.539 + static const KTableValue kTextRenderingKTable[]; 1.540 + static const KTableValue kColorInterpolationKTable[]; 1.541 + static const KTableValue kColumnFillKTable[]; 1.542 + static const KTableValue kBoxPropSourceKTable[]; 1.543 + static const KTableValue kBoxShadowTypeKTable[]; 1.544 + static const KTableValue kBoxSizingKTable[]; 1.545 + static const KTableValue kCaptionSideKTable[]; 1.546 + static const KTableValue kClearKTable[]; 1.547 + static const KTableValue kColorKTable[]; 1.548 + static const KTableValue kContentKTable[]; 1.549 + static const KTableValue kControlCharacterVisibilityKTable[]; 1.550 + static const KTableValue kCursorKTable[]; 1.551 + static const KTableValue kDirectionKTable[]; 1.552 + // Not const because we modify its entries when the pref 1.553 + // "layout.css.grid.enabled" changes: 1.554 + static KTableValue kDisplayKTable[]; 1.555 + static const KTableValue kElevationKTable[]; 1.556 + static const KTableValue kEmptyCellsKTable[]; 1.557 + static const KTableValue kAlignContentKTable[]; 1.558 + static const KTableValue kAlignItemsKTable[]; 1.559 + static const KTableValue kAlignSelfKTable[]; 1.560 + static const KTableValue kFlexDirectionKTable[]; 1.561 + static const KTableValue kFlexWrapKTable[]; 1.562 + static const KTableValue kJustifyContentKTable[]; 1.563 + static const KTableValue kFloatKTable[]; 1.564 + static const KTableValue kFloatEdgeKTable[]; 1.565 + static const KTableValue kFontKTable[]; 1.566 + static const KTableValue kFontKerningKTable[]; 1.567 + static const KTableValue kFontSizeKTable[]; 1.568 + static const KTableValue kFontSmoothingKTable[]; 1.569 + static const KTableValue kFontStretchKTable[]; 1.570 + static const KTableValue kFontStyleKTable[]; 1.571 + static const KTableValue kFontSynthesisKTable[]; 1.572 + static const KTableValue kFontVariantKTable[]; 1.573 + static const KTableValue kFontVariantAlternatesKTable[]; 1.574 + static const KTableValue kFontVariantAlternatesFuncsKTable[]; 1.575 + static const KTableValue kFontVariantCapsKTable[]; 1.576 + static const KTableValue kFontVariantEastAsianKTable[]; 1.577 + static const KTableValue kFontVariantLigaturesKTable[]; 1.578 + static const KTableValue kFontVariantNumericKTable[]; 1.579 + static const KTableValue kFontVariantPositionKTable[]; 1.580 + static const KTableValue kFontWeightKTable[]; 1.581 + static const KTableValue kGridAutoFlowKTable[]; 1.582 + static const KTableValue kGridTrackBreadthKTable[]; 1.583 + static const KTableValue kImageOrientationKTable[]; 1.584 + static const KTableValue kImageOrientationFlipKTable[]; 1.585 + static const KTableValue kIMEModeKTable[]; 1.586 + static const KTableValue kLineHeightKTable[]; 1.587 + static const KTableValue kListStylePositionKTable[]; 1.588 + static const KTableValue kListStyleKTable[]; 1.589 + static const KTableValue kMaskTypeKTable[]; 1.590 + static const KTableValue kMathVariantKTable[]; 1.591 + static const KTableValue kMathDisplayKTable[]; 1.592 + static const KTableValue kContextOpacityKTable[]; 1.593 + static const KTableValue kContextPatternKTable[]; 1.594 + static const KTableValue kOrientKTable[]; 1.595 + static const KTableValue kOutlineStyleKTable[]; 1.596 + static const KTableValue kOutlineColorKTable[]; 1.597 + static const KTableValue kOverflowKTable[]; 1.598 + static const KTableValue kOverflowSubKTable[]; 1.599 + static const KTableValue kOverflowClipBoxKTable[]; 1.600 + static const KTableValue kPageBreakKTable[]; 1.601 + static const KTableValue kPageBreakInsideKTable[]; 1.602 + static const KTableValue kPageMarksKTable[]; 1.603 + static const KTableValue kPageSizeKTable[]; 1.604 + static const KTableValue kPitchKTable[]; 1.605 + static const KTableValue kPointerEventsKTable[]; 1.606 + // Not const because we modify its entries when the pref 1.607 + // "layout.css.sticky.enabled" changes: 1.608 + static KTableValue kPositionKTable[]; 1.609 + static const KTableValue kRadialGradientShapeKTable[]; 1.610 + static const KTableValue kRadialGradientSizeKTable[]; 1.611 + static const KTableValue kRadialGradientLegacySizeKTable[]; 1.612 + static const KTableValue kResizeKTable[]; 1.613 + static const KTableValue kSpeakKTable[]; 1.614 + static const KTableValue kSpeakHeaderKTable[]; 1.615 + static const KTableValue kSpeakNumeralKTable[]; 1.616 + static const KTableValue kSpeakPunctuationKTable[]; 1.617 + static const KTableValue kSpeechRateKTable[]; 1.618 + static const KTableValue kStackSizingKTable[]; 1.619 + static const KTableValue kTableLayoutKTable[]; 1.620 + // Not const because we modify its entries when the pref 1.621 + // "layout.css.text-align-true-value.enabled" changes: 1.622 + static KTableValue kTextAlignKTable[]; 1.623 + static KTableValue kTextAlignLastKTable[]; 1.624 + static const KTableValue kTextCombineUprightKTable[]; 1.625 + static const KTableValue kTextDecorationLineKTable[]; 1.626 + static const KTableValue kTextDecorationStyleKTable[]; 1.627 + static const KTableValue kTextOrientationKTable[]; 1.628 + static const KTableValue kTextOverflowKTable[]; 1.629 + static const KTableValue kTextTransformKTable[]; 1.630 + static const KTableValue kTouchActionKTable[]; 1.631 + static const KTableValue kTransitionTimingFunctionKTable[]; 1.632 + static const KTableValue kUnicodeBidiKTable[]; 1.633 + static const KTableValue kUserFocusKTable[]; 1.634 + static const KTableValue kUserInputKTable[]; 1.635 + static const KTableValue kUserModifyKTable[]; 1.636 + static const KTableValue kUserSelectKTable[]; 1.637 + static const KTableValue kVerticalAlignKTable[]; 1.638 + static const KTableValue kVisibilityKTable[]; 1.639 + static const KTableValue kVolumeKTable[]; 1.640 + static const KTableValue kWhitespaceKTable[]; 1.641 + static const KTableValue kWidthKTable[]; // also min-width, max-width 1.642 + static const KTableValue kWindowShadowKTable[]; 1.643 + static const KTableValue kWordBreakKTable[]; 1.644 + static const KTableValue kWordWrapKTable[]; 1.645 + static const KTableValue kWritingModeKTable[]; 1.646 + static const KTableValue kHyphensKTable[]; 1.647 +}; 1.648 + 1.649 +inline nsCSSProps::EnabledState operator|(nsCSSProps::EnabledState a, 1.650 + nsCSSProps::EnabledState b) 1.651 +{ 1.652 + return nsCSSProps::EnabledState(int(a) | int(b)); 1.653 +} 1.654 + 1.655 +inline nsCSSProps::EnabledState operator&(nsCSSProps::EnabledState a, 1.656 + nsCSSProps::EnabledState b) 1.657 +{ 1.658 + return nsCSSProps::EnabledState(int(a) & int(b)); 1.659 +} 1.660 + 1.661 +inline nsCSSProps::EnabledState& operator|=(nsCSSProps::EnabledState& a, 1.662 + nsCSSProps::EnabledState b) 1.663 +{ 1.664 + return a = a | b; 1.665 +} 1.666 + 1.667 +inline nsCSSProps::EnabledState& operator&=(nsCSSProps::EnabledState& a, 1.668 + nsCSSProps::EnabledState b) 1.669 +{ 1.670 + return a = a & b; 1.671 +} 1.672 + 1.673 +#endif /* nsCSSProps_h___ */