michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * methods for dealing with CSS properties and tables of the keyword michael@0: * values they accept michael@0: */ michael@0: michael@0: #ifndef nsCSSProps_h___ michael@0: #define nsCSSProps_h___ michael@0: michael@0: #include "nsString.h" michael@0: #include "nsCSSProperty.h" michael@0: #include "nsStyleStructFwd.h" michael@0: #include "nsCSSKeywords.h" michael@0: michael@0: // Length of the "--" prefix on custom names (such as custom property names, michael@0: // and, in the future, custom media query names). michael@0: #define CSS_CUSTOM_NAME_PREFIX_LENGTH 2 michael@0: michael@0: // Flags for ParseVariant method michael@0: #define VARIANT_KEYWORD 0x000001 // K michael@0: #define VARIANT_LENGTH 0x000002 // L michael@0: #define VARIANT_PERCENT 0x000004 // P michael@0: #define VARIANT_COLOR 0x000008 // C eCSSUnit_*Color, eCSSUnit_Ident (e.g. "red") michael@0: #define VARIANT_URL 0x000010 // U michael@0: #define VARIANT_NUMBER 0x000020 // N michael@0: #define VARIANT_INTEGER 0x000040 // I michael@0: #define VARIANT_ANGLE 0x000080 // G michael@0: #define VARIANT_FREQUENCY 0x000100 // F michael@0: #define VARIANT_TIME 0x000200 // T michael@0: #define VARIANT_STRING 0x000400 // S michael@0: #define VARIANT_COUNTER 0x000800 // michael@0: #define VARIANT_ATTR 0x001000 // michael@0: #define VARIANT_IDENTIFIER 0x002000 // D michael@0: #define VARIANT_IDENTIFIER_NO_INHERIT 0x004000 // like above, but excluding michael@0: // 'inherit' and 'initial' michael@0: #define VARIANT_AUTO 0x010000 // A michael@0: #define VARIANT_INHERIT 0x020000 // H eCSSUnit_Initial, eCSSUnit_Inherit, eCSSUnit_Unset michael@0: #define VARIANT_NONE 0x040000 // O michael@0: #define VARIANT_NORMAL 0x080000 // M michael@0: #define VARIANT_SYSFONT 0x100000 // eCSSUnit_System_Font michael@0: #define VARIANT_GRADIENT 0x200000 // eCSSUnit_Gradient michael@0: #define VARIANT_TIMING_FUNCTION 0x400000 // cubic-bezier() and steps() michael@0: #define VARIANT_ALL 0x800000 // michael@0: #define VARIANT_IMAGE_RECT 0x01000000 // eCSSUnit_Function michael@0: // This is an extra bit that says that a VARIANT_ANGLE allows unitless zero: michael@0: #define VARIANT_ZERO_ANGLE 0x02000000 // unitless zero for angles michael@0: #define VARIANT_CALC 0x04000000 // eCSSUnit_Calc michael@0: #define VARIANT_ELEMENT 0x08000000 // eCSSUnit_Element michael@0: #define VARIANT_POSITIVE_DIMENSION 0x10000000 // Only lengths greater than 0.0 michael@0: #define VARIANT_NONNEGATIVE_DIMENSION 0x20000000 // Only lengths greater than or equal to 0.0 michael@0: // Keyword used iff gfx.font_rendering.opentype_svg.enabled is true: michael@0: #define VARIANT_OPENTYPE_SVG_KEYWORD 0x40000000 michael@0: michael@0: // Common combinations of variants michael@0: #define VARIANT_AL (VARIANT_AUTO | VARIANT_LENGTH) michael@0: #define VARIANT_LP (VARIANT_LENGTH | VARIANT_PERCENT) michael@0: #define VARIANT_LN (VARIANT_LENGTH | VARIANT_NUMBER) michael@0: #define VARIANT_AH (VARIANT_AUTO | VARIANT_INHERIT) michael@0: #define VARIANT_AHLP (VARIANT_AH | VARIANT_LP) michael@0: #define VARIANT_AHI (VARIANT_AH | VARIANT_INTEGER) michael@0: #define VARIANT_AHK (VARIANT_AH | VARIANT_KEYWORD) michael@0: #define VARIANT_AHKLP (VARIANT_AHLP | VARIANT_KEYWORD) michael@0: #define VARIANT_AHL (VARIANT_AH | VARIANT_LENGTH) michael@0: #define VARIANT_AHKL (VARIANT_AHK | VARIANT_LENGTH) michael@0: #define VARIANT_HK (VARIANT_INHERIT | VARIANT_KEYWORD) michael@0: #define VARIANT_HKF (VARIANT_HK | VARIANT_FREQUENCY) michael@0: #define VARIANT_HKI (VARIANT_HK | VARIANT_INTEGER) michael@0: #define VARIANT_HKL (VARIANT_HK | VARIANT_LENGTH) michael@0: #define VARIANT_HKLP (VARIANT_HK | VARIANT_LP) michael@0: #define VARIANT_HKLPO (VARIANT_HKLP | VARIANT_NONE) michael@0: #define VARIANT_HL (VARIANT_INHERIT | VARIANT_LENGTH) michael@0: #define VARIANT_HI (VARIANT_INHERIT | VARIANT_INTEGER) michael@0: #define VARIANT_HLP (VARIANT_HL | VARIANT_PERCENT) michael@0: #define VARIANT_HLPN (VARIANT_HLP | VARIANT_NUMBER) michael@0: #define VARIANT_HLPO (VARIANT_HLP | VARIANT_NONE) michael@0: #define VARIANT_HTP (VARIANT_INHERIT | VARIANT_TIME | VARIANT_PERCENT) michael@0: #define VARIANT_HMK (VARIANT_HK | VARIANT_NORMAL) michael@0: #define VARIANT_HC (VARIANT_INHERIT | VARIANT_COLOR) michael@0: #define VARIANT_HCK (VARIANT_HK | VARIANT_COLOR) michael@0: #define VARIANT_HUK (VARIANT_HK | VARIANT_URL) michael@0: #define VARIANT_HUO (VARIANT_INHERIT | VARIANT_URL | VARIANT_NONE) michael@0: #define VARIANT_AHUO (VARIANT_AUTO | VARIANT_HUO) michael@0: #define VARIANT_HPN (VARIANT_INHERIT | VARIANT_PERCENT | VARIANT_NUMBER) michael@0: #define VARIANT_PN (VARIANT_PERCENT | VARIANT_NUMBER) michael@0: #define VARIANT_ALPN (VARIANT_AL | VARIANT_PN) michael@0: #define VARIANT_HN (VARIANT_INHERIT | VARIANT_NUMBER) michael@0: #define VARIANT_HON (VARIANT_HN | VARIANT_NONE) michael@0: #define VARIANT_HOS (VARIANT_INHERIT | VARIANT_NONE | VARIANT_STRING) michael@0: #define VARIANT_LPN (VARIANT_LP | VARIANT_NUMBER) michael@0: #define VARIANT_UK (VARIANT_URL | VARIANT_KEYWORD) michael@0: #define VARIANT_UO (VARIANT_URL | VARIANT_NONE) michael@0: #define VARIANT_ANGLE_OR_ZERO (VARIANT_ANGLE | VARIANT_ZERO_ANGLE) michael@0: #define VARIANT_LCALC (VARIANT_LENGTH | VARIANT_CALC) michael@0: #define VARIANT_LPCALC (VARIANT_LCALC | VARIANT_PERCENT) michael@0: #define VARIANT_LNCALC (VARIANT_LCALC | VARIANT_NUMBER) michael@0: #define VARIANT_LPNCALC (VARIANT_LNCALC | VARIANT_PERCENT) michael@0: #define VARIANT_IMAGE (VARIANT_URL | VARIANT_NONE | VARIANT_GRADIENT | \ michael@0: VARIANT_IMAGE_RECT | VARIANT_ELEMENT) michael@0: michael@0: // Flags for the kFlagsTable bitfield (flags_ in nsCSSPropList.h) michael@0: michael@0: // A property that is a *-ltr-source or *-rtl-source property for one of michael@0: // the directional pseudo-shorthand properties. michael@0: #define CSS_PROPERTY_DIRECTIONAL_SOURCE (1<<0) michael@0: michael@0: #define CSS_PROPERTY_VALUE_LIST_USES_COMMAS (1<<1) /* otherwise spaces */ michael@0: michael@0: #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER (1<<2) michael@0: #define CSS_PROPERTY_APPLIES_TO_FIRST_LINE (1<<3) michael@0: #define CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE \ michael@0: (CSS_PROPERTY_APPLIES_TO_FIRST_LETTER | CSS_PROPERTY_APPLIES_TO_FIRST_LINE) michael@0: michael@0: // Note that 'background-color' is ignored differently from the other michael@0: // properties that have this set, but that's just special-cased. michael@0: #define CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED (1<<4) michael@0: michael@0: // A property that needs to have image loads started when a URL value michael@0: // for the property is used for an element. This is supported only michael@0: // for a few possible value formats: image directly in the value; list michael@0: // of images; and with CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0, image in slot michael@0: // 0 of an array, or list of such arrays. michael@0: #define CSS_PROPERTY_START_IMAGE_LOADS (1<<5) michael@0: michael@0: // Should be set only for properties with START_IMAGE_LOADS. Indicates michael@0: // that the property has an array value with a URL/image value at index michael@0: // 0 in the array, rather than the URL/image being in the value or value michael@0: // list. michael@0: #define CSS_PROPERTY_IMAGE_IS_IN_ARRAY_0 (1<<6) michael@0: michael@0: // This is a property for which the computed value should generally be michael@0: // reported as the computed value of a property of a different name. In michael@0: // particular, the directional box properties (margin-left-value, etc.) michael@0: // should be reported as being margin-left, etc. Call michael@0: // nsCSSProps::OtherNameFor to get the other property. michael@0: #define CSS_PROPERTY_REPORT_OTHER_NAME (1<<7) michael@0: michael@0: // This property allows calc() between lengths and percentages and michael@0: // stores such calc() expressions in its style structs (typically in an michael@0: // nsStyleCoord, although this is not the case for 'background-position' michael@0: // and 'background-size'). michael@0: #define CSS_PROPERTY_STORES_CALC (1<<8) michael@0: michael@0: // Define what mechanism the CSS parser uses for parsing the property. michael@0: // See CSSParserImpl::ParseProperty(nsCSSProperty). Don't use 0 so that michael@0: // we can verify that every property sets one of the values. michael@0: // michael@0: // CSS_PROPERTY_PARSE_FUNCTION must be used for shorthand properties, michael@0: // since it's the only mechanism that allows appending values for michael@0: // separate properties. Longhand properties that require custom parsing michael@0: // functions should prefer using CSS_PROPERTY_PARSE_VALUE (or michael@0: // CSS_PROPERTY_PARSE_VALUE_LIST) and michael@0: // CSS_PROPERTY_VALUE_PARSER_FUNCTION, though a number of existing michael@0: // longhand properties use CSS_PROPERTY_PARSE_FUNCTION instead. michael@0: #define CSS_PROPERTY_PARSE_PROPERTY_MASK (7<<9) michael@0: #define CSS_PROPERTY_PARSE_INACCESSIBLE (1<<9) michael@0: #define CSS_PROPERTY_PARSE_FUNCTION (2<<9) michael@0: #define CSS_PROPERTY_PARSE_VALUE (3<<9) michael@0: #define CSS_PROPERTY_PARSE_VALUE_LIST (4<<9) michael@0: michael@0: // See CSSParserImpl::ParseSingleValueProperty and comment above michael@0: // CSS_PROPERTY_PARSE_FUNCTION (which is different). michael@0: #define CSS_PROPERTY_VALUE_PARSER_FUNCTION (1<<12) michael@0: static_assert((CSS_PROPERTY_PARSE_PROPERTY_MASK & michael@0: CSS_PROPERTY_VALUE_PARSER_FUNCTION) == 0, michael@0: "didn't leave enough room for the parse property constants"); michael@0: michael@0: #define CSS_PROPERTY_VALUE_RESTRICTION_MASK (3<<13) michael@0: // The parser (in particular, CSSParserImpl::ParseSingleValueProperty) michael@0: // should enforce that the value of this property must be 0 or larger. michael@0: #define CSS_PROPERTY_VALUE_NONNEGATIVE (1<<13) michael@0: // The parser (in particular, CSSParserImpl::ParseSingleValueProperty) michael@0: // should enforce that the value of this property must be 1 or larger. michael@0: #define CSS_PROPERTY_VALUE_AT_LEAST_ONE (2<<13) michael@0: michael@0: // Does this property support the hashless hex color quirk in quirks mode? michael@0: #define CSS_PROPERTY_HASHLESS_COLOR_QUIRK (1<<15) michael@0: michael@0: // Does this property support the unitless length quirk in quirks mode? michael@0: #define CSS_PROPERTY_UNITLESS_LENGTH_QUIRK (1<<16) michael@0: michael@0: // Is this property (which must be a shorthand) really an alias? michael@0: #define CSS_PROPERTY_IS_ALIAS (1<<17) michael@0: michael@0: // Does the property apply to ::-moz-placeholder? michael@0: #define CSS_PROPERTY_APPLIES_TO_PLACEHOLDER (1<<18) michael@0: michael@0: // This property is allowed in an @page rule. michael@0: #define CSS_PROPERTY_APPLIES_TO_PAGE_RULE (1<<19) michael@0: michael@0: // This property's getComputedStyle implementation requires layout to be michael@0: // flushed. michael@0: #define CSS_PROPERTY_GETCS_NEEDS_LAYOUT_FLUSH (1<<20) michael@0: michael@0: // This property requires a stacking context. michael@0: #define CSS_PROPERTY_CREATES_STACKING_CONTEXT (1<<21) michael@0: michael@0: // This property is always enabled in UA sheets. This is meant to be used michael@0: // together with a pref that enables the property for non-UA sheets. michael@0: // Note that if such a property has an alias, then any use of that alias michael@0: // in an UA sheet will still be ignored unless the pref is enabled. michael@0: // In other words, this bit has no effect on the use of aliases. michael@0: #define CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS (1<<22) michael@0: michael@0: // This property is always enabled in chrome and in certified apps. This is michael@0: // meant to be used together with a pref that enables the property for michael@0: // non-privileged content. Note that if such a property has an alias, then any michael@0: // use of that alias in privileged content will still be ignored unless the michael@0: // pref is enabled. In other words, this bit has no effect on the use of michael@0: // aliases. michael@0: #define CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP (1<<23) michael@0: michael@0: /** michael@0: * Types of animatable values. michael@0: */ michael@0: enum nsStyleAnimType { michael@0: // requires a custom implementation in michael@0: // nsStyleAnimation::ExtractComputedValue michael@0: eStyleAnimType_Custom, michael@0: michael@0: // nsStyleCoord with animatable values michael@0: eStyleAnimType_Coord, michael@0: michael@0: // same as Coord, except for one side of an nsStyleSides michael@0: // listed in the same order as the NS_STYLE_* constants michael@0: eStyleAnimType_Sides_Top, michael@0: eStyleAnimType_Sides_Right, michael@0: eStyleAnimType_Sides_Bottom, michael@0: eStyleAnimType_Sides_Left, michael@0: michael@0: // similar, but for the *pair* of coord members of an nsStyleCorners michael@0: // for the relevant corner michael@0: eStyleAnimType_Corner_TopLeft, michael@0: eStyleAnimType_Corner_TopRight, michael@0: eStyleAnimType_Corner_BottomRight, michael@0: eStyleAnimType_Corner_BottomLeft, michael@0: michael@0: // nscoord values michael@0: eStyleAnimType_nscoord, michael@0: michael@0: // enumerated values (stored in a uint8_t) michael@0: // In order for a property to use this unit, _all_ of its enumerated values michael@0: // must be listed in its keyword table, so that any enumerated value can be michael@0: // converted into a string via a nsCSSValue of type eCSSUnit_Enumerated. michael@0: eStyleAnimType_EnumU8, michael@0: michael@0: // float values michael@0: eStyleAnimType_float, michael@0: michael@0: // nscolor values michael@0: eStyleAnimType_Color, michael@0: michael@0: // nsStyleSVGPaint values michael@0: eStyleAnimType_PaintServer, michael@0: michael@0: // nsRefPtr values michael@0: eStyleAnimType_Shadow, michael@0: michael@0: // property not animatable michael@0: eStyleAnimType_None michael@0: }; michael@0: michael@0: class nsCSSProps { michael@0: public: michael@0: typedef int16_t KTableValue; michael@0: michael@0: static void AddRefTable(void); michael@0: static void ReleaseTable(void); michael@0: michael@0: enum EnabledState { michael@0: // The default EnabledState: only enable what's enabled for all content, michael@0: // given the current values of preferences. michael@0: eEnabledForAllContent = 0, michael@0: // Enable a property in UA sheets. michael@0: eEnabledInUASheets = 0x01, michael@0: // Enable a property in privileged content, i.e. chrome or Certified Apps michael@0: eEnabledInChromeOrCertifiedApp = 0x02, michael@0: // Special value to unconditionally enable a property. This implies all the michael@0: // bits above, but is strictly more than just their OR-ed union. michael@0: // This just skips any test so a property will be enabled even if it would michael@0: // have been disabled with all the bits above set. michael@0: eIgnoreEnabledState = 0xff michael@0: }; michael@0: michael@0: // Looks up the property with name aProperty and returns its corresponding michael@0: // nsCSSProperty value. If aProperty is the name of a custom property, michael@0: // then eCSSPropertyExtra_variable will be returned. michael@0: static nsCSSProperty LookupProperty(const nsAString& aProperty, michael@0: EnabledState aEnabled); michael@0: static nsCSSProperty LookupProperty(const nsACString& aProperty, michael@0: EnabledState aEnabled); michael@0: // Returns whether aProperty is a custom property name, i.e. begins with michael@0: // "--". This assumes that the CSS Variables pref has been enabled. michael@0: static bool IsCustomPropertyName(const nsAString& aProperty); michael@0: static bool IsCustomPropertyName(const nsACString& aProperty); michael@0: michael@0: static inline bool IsShorthand(nsCSSProperty aProperty) { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, michael@0: "out of range"); michael@0: return (aProperty >= eCSSProperty_COUNT_no_shorthands); michael@0: } michael@0: michael@0: // Must be given a longhand property. michael@0: static bool IsInherited(nsCSSProperty aProperty); michael@0: michael@0: // Same but for @font-face descriptors michael@0: static nsCSSFontDesc LookupFontDesc(const nsAString& aProperty); michael@0: static nsCSSFontDesc LookupFontDesc(const nsACString& aProperty); michael@0: michael@0: // Given a property enum, get the string value michael@0: static const nsAFlatCString& GetStringValue(nsCSSProperty aProperty); michael@0: static const nsAFlatCString& GetStringValue(nsCSSFontDesc aFontDesc); michael@0: michael@0: // Get the property to report the computed value of aProperty as being michael@0: // the computed value of. aProperty must have the michael@0: // CSS_PROPERTY_REPORT_OTHER_NAME bit set. michael@0: static nsCSSProperty OtherNameFor(nsCSSProperty aProperty); michael@0: michael@0: // Given a CSS Property and a Property Enum Value michael@0: // Return back a const nsString& representation of the michael@0: // value. Return back nullstr if no value is found michael@0: static const nsAFlatCString& LookupPropertyValue(nsCSSProperty aProperty, int32_t aValue); michael@0: michael@0: // Get a color name for a predefined color value like buttonhighlight or activeborder michael@0: // Sets the aStr param to the name of the propertyID michael@0: static bool GetColorName(int32_t aPropID, nsCString &aStr); michael@0: michael@0: // Returns the index of |aKeyword| in |aTable|, if it exists there; michael@0: // otherwise, returns -1. michael@0: // NOTE: Generally, clients should call FindKeyword() instead of this method. michael@0: static int32_t FindIndexOfKeyword(nsCSSKeyword aKeyword, michael@0: const KTableValue aTable[]); michael@0: michael@0: // Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value. michael@0: // If not found, return false and do not set |aValue|. michael@0: static bool FindKeyword(nsCSSKeyword aKeyword, const KTableValue aTable[], michael@0: int32_t& aValue); michael@0: // Return the first keyword in |aTable| that has the corresponding value |aValue|. michael@0: // Return |eCSSKeyword_UNKNOWN| if not found. michael@0: static nsCSSKeyword ValueToKeywordEnum(int32_t aValue, michael@0: const KTableValue aTable[]); michael@0: // Ditto but as a string, return "" when not found. michael@0: static const nsAFlatCString& ValueToKeyword(int32_t aValue, michael@0: const KTableValue aTable[]); michael@0: michael@0: static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands]; michael@0: static const KTableValue* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands]; michael@0: static const nsStyleAnimType kAnimTypeTable[eCSSProperty_COUNT_no_shorthands]; michael@0: static const ptrdiff_t michael@0: kStyleStructOffsetTable[eCSSProperty_COUNT_no_shorthands]; michael@0: michael@0: private: michael@0: static const uint32_t kFlagsTable[eCSSProperty_COUNT]; michael@0: michael@0: public: michael@0: static inline bool PropHasFlags(nsCSSProperty aProperty, uint32_t aFlags) michael@0: { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, michael@0: "out of range"); michael@0: MOZ_ASSERT(!(aFlags & CSS_PROPERTY_PARSE_PROPERTY_MASK), michael@0: "The CSS_PROPERTY_PARSE_* values are not bitflags; don't pass " michael@0: "them to PropHasFlags. You probably want PropertyParseType " michael@0: "instead."); michael@0: return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags; michael@0: } michael@0: michael@0: static inline uint32_t PropertyParseType(nsCSSProperty aProperty) michael@0: { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, michael@0: "out of range"); michael@0: return nsCSSProps::kFlagsTable[aProperty] & michael@0: CSS_PROPERTY_PARSE_PROPERTY_MASK; michael@0: } michael@0: michael@0: static inline uint32_t ValueRestrictions(nsCSSProperty aProperty) michael@0: { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT, michael@0: "out of range"); michael@0: return nsCSSProps::kFlagsTable[aProperty] & michael@0: CSS_PROPERTY_VALUE_RESTRICTION_MASK; michael@0: } michael@0: michael@0: private: michael@0: // Lives in nsCSSParser.cpp for the macros it depends on. michael@0: static const uint32_t kParserVariantTable[eCSSProperty_COUNT_no_shorthands]; michael@0: michael@0: public: michael@0: static inline uint32_t ParserVariant(nsCSSProperty aProperty) { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && michael@0: aProperty < eCSSProperty_COUNT_no_shorthands, michael@0: "out of range"); michael@0: return nsCSSProps::kParserVariantTable[aProperty]; michael@0: } michael@0: michael@0: private: michael@0: // A table for shorthand properties. The appropriate index is the michael@0: // property ID minus eCSSProperty_COUNT_no_shorthands. michael@0: static const nsCSSProperty *const michael@0: kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands]; michael@0: michael@0: public: michael@0: static inline michael@0: const nsCSSProperty * SubpropertyEntryFor(nsCSSProperty aProperty) { michael@0: NS_ABORT_IF_FALSE(eCSSProperty_COUNT_no_shorthands <= aProperty && michael@0: aProperty < eCSSProperty_COUNT, michael@0: "out of range"); michael@0: return nsCSSProps::kSubpropertyTable[aProperty - michael@0: eCSSProperty_COUNT_no_shorthands]; michael@0: } michael@0: michael@0: // Returns an eCSSProperty_UNKNOWN-terminated array of the shorthand michael@0: // properties containing |aProperty|, sorted from those that contain michael@0: // the most properties to those that contain the least. michael@0: static const nsCSSProperty * ShorthandsContaining(nsCSSProperty aProperty) { michael@0: NS_ABORT_IF_FALSE(gShorthandsContainingPool, "uninitialized"); michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && michael@0: aProperty < eCSSProperty_COUNT_no_shorthands, michael@0: "out of range"); michael@0: return gShorthandsContainingTable[aProperty]; michael@0: } michael@0: private: michael@0: // gShorthandsContainingTable is an array of the return values for michael@0: // ShorthandsContaining (arrays of nsCSSProperty terminated by michael@0: // eCSSProperty_UNKNOWN) pointing into memory in michael@0: // gShorthandsContainingPool (which contains all of those arrays in a michael@0: // single allocation, and is the one pointer that should be |free|d). michael@0: static nsCSSProperty *gShorthandsContainingTable[eCSSProperty_COUNT_no_shorthands]; michael@0: static nsCSSProperty* gShorthandsContainingPool; michael@0: static bool BuildShorthandsContainingTable(); michael@0: michael@0: private: michael@0: static const size_t gPropertyCountInStruct[nsStyleStructID_Length]; michael@0: static const size_t gPropertyIndexInStruct[eCSSProperty_COUNT_no_shorthands]; michael@0: public: michael@0: /** michael@0: * Return the number of properties that must be cascaded when michael@0: * nsRuleNode builds the nsStyle* for aSID. michael@0: */ michael@0: static size_t PropertyCountInStruct(nsStyleStructID aSID) { michael@0: NS_ABORT_IF_FALSE(0 <= aSID && aSID < nsStyleStructID_Length, michael@0: "out of range"); michael@0: return gPropertyCountInStruct[aSID]; michael@0: } michael@0: /** michael@0: * Return an index for aProperty that is unique within its SID and in michael@0: * the range 0 <= index < PropertyCountInStruct(aSID). michael@0: */ michael@0: static size_t PropertyIndexInStruct(nsCSSProperty aProperty) { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && michael@0: aProperty < eCSSProperty_COUNT_no_shorthands, michael@0: "out of range"); michael@0: return gPropertyIndexInStruct[aProperty]; michael@0: } michael@0: michael@0: private: michael@0: static bool gPropertyEnabled[eCSSProperty_COUNT_with_aliases]; michael@0: michael@0: public: michael@0: michael@0: static bool IsEnabled(nsCSSProperty aProperty) { michael@0: NS_ABORT_IF_FALSE(0 <= aProperty && michael@0: aProperty < eCSSProperty_COUNT_with_aliases, michael@0: "out of range"); michael@0: return gPropertyEnabled[aProperty]; michael@0: } michael@0: michael@0: static bool IsEnabled(nsCSSProperty aProperty, EnabledState aEnabled) michael@0: { michael@0: if (IsEnabled(aProperty)) { michael@0: return true; michael@0: } michael@0: if (aEnabled == eIgnoreEnabledState) { michael@0: return true; michael@0: } michael@0: if ((aEnabled & eEnabledInUASheets) && michael@0: PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS)) michael@0: { michael@0: return true; michael@0: } michael@0: if ((aEnabled & eEnabledInChromeOrCertifiedApp) && michael@0: PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP)) michael@0: { michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: public: michael@0: michael@0: #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_) \ michael@0: for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_); \ michael@0: *iter_ != eCSSProperty_UNKNOWN; ++iter_) \ michael@0: if (nsCSSProps::IsEnabled(*iter_)) michael@0: michael@0: // Keyword/Enum value tables michael@0: static const KTableValue kAnimationDirectionKTable[]; michael@0: static const KTableValue kAnimationFillModeKTable[]; michael@0: static const KTableValue kAnimationIterationCountKTable[]; michael@0: static const KTableValue kAnimationPlayStateKTable[]; michael@0: static const KTableValue kAnimationTimingFunctionKTable[]; michael@0: static const KTableValue kAppearanceKTable[]; michael@0: static const KTableValue kAzimuthKTable[]; michael@0: static const KTableValue kBackfaceVisibilityKTable[]; michael@0: static const KTableValue kTransformStyleKTable[]; michael@0: static const KTableValue kBackgroundAttachmentKTable[]; michael@0: static const KTableValue kBackgroundInlinePolicyKTable[]; michael@0: static const KTableValue kBackgroundOriginKTable[]; michael@0: static const KTableValue kBackgroundPositionKTable[]; michael@0: static const KTableValue kBackgroundRepeatKTable[]; michael@0: static const KTableValue kBackgroundRepeatPartKTable[]; michael@0: static const KTableValue kBackgroundSizeKTable[]; michael@0: static const KTableValue kBlendModeKTable[]; michael@0: static const KTableValue kBorderCollapseKTable[]; michael@0: static const KTableValue kBorderColorKTable[]; michael@0: static const KTableValue kBorderImageRepeatKTable[]; michael@0: static const KTableValue kBorderImageSliceKTable[]; michael@0: static const KTableValue kBorderStyleKTable[]; michael@0: static const KTableValue kBorderWidthKTable[]; michael@0: static const KTableValue kBoxAlignKTable[]; michael@0: static const KTableValue kBoxDirectionKTable[]; michael@0: static const KTableValue kBoxOrientKTable[]; michael@0: static const KTableValue kBoxPackKTable[]; michael@0: static const KTableValue kDominantBaselineKTable[]; michael@0: static const KTableValue kFillRuleKTable[]; michael@0: static const KTableValue kFilterFunctionKTable[]; michael@0: static const KTableValue kImageRenderingKTable[]; michael@0: static const KTableValue kShapeRenderingKTable[]; michael@0: static const KTableValue kStrokeLinecapKTable[]; michael@0: static const KTableValue kStrokeLinejoinKTable[]; michael@0: static const KTableValue kStrokeContextValueKTable[]; michael@0: static const KTableValue kVectorEffectKTable[]; michael@0: static const KTableValue kTextAnchorKTable[]; michael@0: static const KTableValue kTextRenderingKTable[]; michael@0: static const KTableValue kColorInterpolationKTable[]; michael@0: static const KTableValue kColumnFillKTable[]; michael@0: static const KTableValue kBoxPropSourceKTable[]; michael@0: static const KTableValue kBoxShadowTypeKTable[]; michael@0: static const KTableValue kBoxSizingKTable[]; michael@0: static const KTableValue kCaptionSideKTable[]; michael@0: static const KTableValue kClearKTable[]; michael@0: static const KTableValue kColorKTable[]; michael@0: static const KTableValue kContentKTable[]; michael@0: static const KTableValue kControlCharacterVisibilityKTable[]; michael@0: static const KTableValue kCursorKTable[]; michael@0: static const KTableValue kDirectionKTable[]; michael@0: // Not const because we modify its entries when the pref michael@0: // "layout.css.grid.enabled" changes: michael@0: static KTableValue kDisplayKTable[]; michael@0: static const KTableValue kElevationKTable[]; michael@0: static const KTableValue kEmptyCellsKTable[]; michael@0: static const KTableValue kAlignContentKTable[]; michael@0: static const KTableValue kAlignItemsKTable[]; michael@0: static const KTableValue kAlignSelfKTable[]; michael@0: static const KTableValue kFlexDirectionKTable[]; michael@0: static const KTableValue kFlexWrapKTable[]; michael@0: static const KTableValue kJustifyContentKTable[]; michael@0: static const KTableValue kFloatKTable[]; michael@0: static const KTableValue kFloatEdgeKTable[]; michael@0: static const KTableValue kFontKTable[]; michael@0: static const KTableValue kFontKerningKTable[]; michael@0: static const KTableValue kFontSizeKTable[]; michael@0: static const KTableValue kFontSmoothingKTable[]; michael@0: static const KTableValue kFontStretchKTable[]; michael@0: static const KTableValue kFontStyleKTable[]; michael@0: static const KTableValue kFontSynthesisKTable[]; michael@0: static const KTableValue kFontVariantKTable[]; michael@0: static const KTableValue kFontVariantAlternatesKTable[]; michael@0: static const KTableValue kFontVariantAlternatesFuncsKTable[]; michael@0: static const KTableValue kFontVariantCapsKTable[]; michael@0: static const KTableValue kFontVariantEastAsianKTable[]; michael@0: static const KTableValue kFontVariantLigaturesKTable[]; michael@0: static const KTableValue kFontVariantNumericKTable[]; michael@0: static const KTableValue kFontVariantPositionKTable[]; michael@0: static const KTableValue kFontWeightKTable[]; michael@0: static const KTableValue kGridAutoFlowKTable[]; michael@0: static const KTableValue kGridTrackBreadthKTable[]; michael@0: static const KTableValue kImageOrientationKTable[]; michael@0: static const KTableValue kImageOrientationFlipKTable[]; michael@0: static const KTableValue kIMEModeKTable[]; michael@0: static const KTableValue kLineHeightKTable[]; michael@0: static const KTableValue kListStylePositionKTable[]; michael@0: static const KTableValue kListStyleKTable[]; michael@0: static const KTableValue kMaskTypeKTable[]; michael@0: static const KTableValue kMathVariantKTable[]; michael@0: static const KTableValue kMathDisplayKTable[]; michael@0: static const KTableValue kContextOpacityKTable[]; michael@0: static const KTableValue kContextPatternKTable[]; michael@0: static const KTableValue kOrientKTable[]; michael@0: static const KTableValue kOutlineStyleKTable[]; michael@0: static const KTableValue kOutlineColorKTable[]; michael@0: static const KTableValue kOverflowKTable[]; michael@0: static const KTableValue kOverflowSubKTable[]; michael@0: static const KTableValue kOverflowClipBoxKTable[]; michael@0: static const KTableValue kPageBreakKTable[]; michael@0: static const KTableValue kPageBreakInsideKTable[]; michael@0: static const KTableValue kPageMarksKTable[]; michael@0: static const KTableValue kPageSizeKTable[]; michael@0: static const KTableValue kPitchKTable[]; michael@0: static const KTableValue kPointerEventsKTable[]; michael@0: // Not const because we modify its entries when the pref michael@0: // "layout.css.sticky.enabled" changes: michael@0: static KTableValue kPositionKTable[]; michael@0: static const KTableValue kRadialGradientShapeKTable[]; michael@0: static const KTableValue kRadialGradientSizeKTable[]; michael@0: static const KTableValue kRadialGradientLegacySizeKTable[]; michael@0: static const KTableValue kResizeKTable[]; michael@0: static const KTableValue kSpeakKTable[]; michael@0: static const KTableValue kSpeakHeaderKTable[]; michael@0: static const KTableValue kSpeakNumeralKTable[]; michael@0: static const KTableValue kSpeakPunctuationKTable[]; michael@0: static const KTableValue kSpeechRateKTable[]; michael@0: static const KTableValue kStackSizingKTable[]; michael@0: static const KTableValue kTableLayoutKTable[]; michael@0: // Not const because we modify its entries when the pref michael@0: // "layout.css.text-align-true-value.enabled" changes: michael@0: static KTableValue kTextAlignKTable[]; michael@0: static KTableValue kTextAlignLastKTable[]; michael@0: static const KTableValue kTextCombineUprightKTable[]; michael@0: static const KTableValue kTextDecorationLineKTable[]; michael@0: static const KTableValue kTextDecorationStyleKTable[]; michael@0: static const KTableValue kTextOrientationKTable[]; michael@0: static const KTableValue kTextOverflowKTable[]; michael@0: static const KTableValue kTextTransformKTable[]; michael@0: static const KTableValue kTouchActionKTable[]; michael@0: static const KTableValue kTransitionTimingFunctionKTable[]; michael@0: static const KTableValue kUnicodeBidiKTable[]; michael@0: static const KTableValue kUserFocusKTable[]; michael@0: static const KTableValue kUserInputKTable[]; michael@0: static const KTableValue kUserModifyKTable[]; michael@0: static const KTableValue kUserSelectKTable[]; michael@0: static const KTableValue kVerticalAlignKTable[]; michael@0: static const KTableValue kVisibilityKTable[]; michael@0: static const KTableValue kVolumeKTable[]; michael@0: static const KTableValue kWhitespaceKTable[]; michael@0: static const KTableValue kWidthKTable[]; // also min-width, max-width michael@0: static const KTableValue kWindowShadowKTable[]; michael@0: static const KTableValue kWordBreakKTable[]; michael@0: static const KTableValue kWordWrapKTable[]; michael@0: static const KTableValue kWritingModeKTable[]; michael@0: static const KTableValue kHyphensKTable[]; michael@0: }; michael@0: michael@0: inline nsCSSProps::EnabledState operator|(nsCSSProps::EnabledState a, michael@0: nsCSSProps::EnabledState b) michael@0: { michael@0: return nsCSSProps::EnabledState(int(a) | int(b)); michael@0: } michael@0: michael@0: inline nsCSSProps::EnabledState operator&(nsCSSProps::EnabledState a, michael@0: nsCSSProps::EnabledState b) michael@0: { michael@0: return nsCSSProps::EnabledState(int(a) & int(b)); michael@0: } michael@0: michael@0: inline nsCSSProps::EnabledState& operator|=(nsCSSProps::EnabledState& a, michael@0: nsCSSProps::EnabledState b) michael@0: { michael@0: return a = a | b; michael@0: } michael@0: michael@0: inline nsCSSProps::EnabledState& operator&=(nsCSSProps::EnabledState& a, michael@0: nsCSSProps::EnabledState b) michael@0: { michael@0: return a = a & b; michael@0: } michael@0: michael@0: #endif /* nsCSSProps_h___ */