public static bool FindKeyword(nsCSSKeyword aKeyword, int[] aTable, ref int aResult) { int32_t index = FindIndexOfKeyword(aKeyword, aTable); if (index >= 0) { aResult = aTable[index + 1]; return true; } return false; }
/** * Given a token, determines the minimum and maximum number of function * parameters to read, along with the mask that should be used to read * those function parameters. If the token isn't a transform function, * returns an error. * * @param aToken The token identifying the function. * @param aMinElems [out] The minimum number of elements to read. * @param aMaxElems [out] The maximum number of elements to read * @param aVariantMask [out] The variant mask to use during parsing * @return Whether the information was loaded successfully. */ static bool GetFunctionParseInformation(nsCSSKeyword aToken, bool aIsPrefixed, ref uint16_t aMinElems, ref uint16_t aMaxElems, ref int32_t[] aVariantMask, ref bool aIs3D) { /* These types represent the common variant masks that will be used to * parse out the individual functions. The order in the enumeration * must match the order in which the masks are declared. */ const int eLengthPercentCalc = 0; const int eLengthCalc = 1; const int eTwoLengthPercentCalcs = 2; const int eTwoLengthPercentCalcsOneLengthCalc = 3; const int eAngle = 4; const int eTwoAngles = 5; const int eNumber = 6; const int ePositiveLength = 7; const int eTwoNumbers = 8; const int eThreeNumbers = 9; const int eThreeNumbersOneAngle = 10; const int eMatrix = 11; const int eMatrixPrefixed = 12; const int eMatrix3d = 13; const int eMatrix3dPrefixed = 14; const int eNumVariantMasks = 15; const int32_t kMaxElemsPerFunction = 16; /*TODO: static*/ int32_t[][] kVariantMasks = { new[] {VARIANT_LPCALC}, new[] {VARIANT_LENGTH|VARIANT_CALC}, new[] {VARIANT_LPCALC, VARIANT_LPCALC}, new[] {VARIANT_LPCALC, VARIANT_LPCALC, VARIANT_LENGTH|VARIANT_CALC}, new[] {VARIANT_ANGLE_OR_ZERO}, new[] {VARIANT_ANGLE_OR_ZERO, VARIANT_ANGLE_OR_ZERO}, new[] {VARIANT_NUMBER}, new[] {VARIANT_LENGTH|VARIANT_POSITIVE_DIMENSION}, new[] {VARIANT_NUMBER, VARIANT_NUMBER}, new[] {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER}, new[] {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_ANGLE_OR_ZERO}, new[] {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER}, new[] {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_LPNCALC, VARIANT_LPNCALC}, new[] {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER}, new[] {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_LPNCALC, VARIANT_LPNCALC, VARIANT_LNCALC, VARIANT_NUMBER}}; #if DEBUG /*TODO: static*/ uint8_t[] kVariantMaskLengths = {1, 1, 2, 3, 1, 2, 1, 1, 2, 3, 4, 6, 6, 16, 16}; #endif int32_t variantIndex = eNumVariantMasks; aIs3D = false; switch (aToken) { case nsCSSKeyword.translatex: case nsCSSKeyword.translatey: /* Exactly one length or percent. */ variantIndex = eLengthPercentCalc; aMinElems = 1; aMaxElems = 1; break; case nsCSSKeyword.translatez: /* Exactly one length */ variantIndex = eLengthCalc; aMinElems = 1; aMaxElems = 1; aIs3D = true; break; case nsCSSKeyword.translate3d: /* Exactly two lengthds or percents and a number */ variantIndex = eTwoLengthPercentCalcsOneLengthCalc; aMinElems = 3; aMaxElems = 3; aIs3D = true; break; case nsCSSKeyword.scalez: aIs3D = true; goto case nsCSSKeyword.scalex; case nsCSSKeyword.scalex: case nsCSSKeyword.scaley: /* Exactly one scale factor. */ variantIndex = eNumber; aMinElems = 1; aMaxElems = 1; break; case nsCSSKeyword.scale3d: /* Exactly three scale factors. */ variantIndex = eThreeNumbers; aMinElems = 3; aMaxElems = 3; aIs3D = true; break; case nsCSSKeyword.rotatex: case nsCSSKeyword.rotatey: aIs3D = true; goto case nsCSSKeyword.rotate; case nsCSSKeyword.rotate: case nsCSSKeyword.rotatez: /* Exactly one angle. */ variantIndex = eAngle; aMinElems = 1; aMaxElems = 1; break; case nsCSSKeyword.rotate3d: variantIndex = eThreeNumbersOneAngle; aMinElems = 4; aMaxElems = 4; aIs3D = true; break; case nsCSSKeyword.translate: /* One or two lengths or percents. */ variantIndex = eTwoLengthPercentCalcs; aMinElems = 1; aMaxElems = 2; break; case nsCSSKeyword.skew: /* Exactly one or two angles. */ variantIndex = eTwoAngles; aMinElems = 1; aMaxElems = 2; break; case nsCSSKeyword.scale: /* One or two scale factors. */ variantIndex = eTwoNumbers; aMinElems = 1; aMaxElems = 2; break; case nsCSSKeyword.skewx: /* Exactly one angle. */ variantIndex = eAngle; aMinElems = 1; aMaxElems = 1; break; case nsCSSKeyword.skewy: /* Exactly one angle. */ variantIndex = eAngle; aMinElems = 1; aMaxElems = 1; break; case nsCSSKeyword.matrix: /* Six values, all numbers. */ variantIndex = aIsPrefixed ? eMatrixPrefixed : eMatrix; aMinElems = 6; aMaxElems = 6; break; case nsCSSKeyword.matrix3d: /* 16 matrix values, all numbers */ variantIndex = aIsPrefixed ? eMatrix3dPrefixed : eMatrix3d; aMinElems = 6; aMaxElems = 6; aIs3D = true; break; case nsCSSKeyword.perspective: /* Exactly one scale number. */ variantIndex = ePositiveLength; aMinElems = 1; aMaxElems = 1; aIs3D = true; break; default: /* Oh dear, we didn't match. Report an error. */ return false; } Debug.Assert(aMinElems > 0, "Didn't update minimum elements!"); Debug.Assert(aMaxElems > 0, "Didn't update maximum elements!"); Debug.Assert(aMinElems <= aMaxElems, "aMinElems > aMaxElems!"); Debug.Assert(variantIndex >= 0, "Invalid variant mask!"); Debug.Assert(variantIndex < eNumVariantMasks, "Invalid variant mask!"); #if DEBUG Debug.Assert(aMaxElems <= kVariantMaskLengths[variantIndex], "Invalid aMaxElems for this variant mask."); #endif // Convert the index into a mask. aVariantMask = kVariantMasks[variantIndex]; return true; }
private static int FindIndexOfKeyword(nsCSSKeyword aKeyword, int[] aTable) { int32_t index = 0; while ((nsCSSKeyword)(aTable[index]) != nsCSSKeyword.UNKNOWN) { if ((nsCSSKeyword)(aTable[index]) == aKeyword) return index; index += 2; } return -1; }
public static string GetStringValue(nsCSSKeyword aKeyword) { return kCSSRawKeywords[(int)aKeyword]; }