layout/style/nsCSSProps.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial