internal bool ParseRect(nsCSSProperty aPropID) { if (! GetToken(true)) { return false; } var val = new nsCSSValue(); if (mToken.mType == nsCSSTokenType.Ident) { nsCSSKeyword keyword = nsCSSKeywords.LookupKeyword(mToken.mIdentStr); switch (keyword) { case nsCSSKeyword.auto: if (!ExpectEndProperty()) { return false; } val.SetAutoValue(); break; case nsCSSKeyword.inherit: if (!ExpectEndProperty()) { return false; } val.SetInheritValue(); break; case nsCSSKeyword.initial: case nsCSSKeyword._moz_initial: if (!ExpectEndProperty()) { return false; } val.SetInitialValue(); break; default: UngetToken(); return false; } } else if (mToken.mType == nsCSSTokenType.Function && mToken.mIdentStr.LowerCaseEqualsLiteral("rect")) { nsCSSRect rect = val.SetRectValue(); bool useCommas = false; for (Side side = nsStyle.SIDE_TOP; side <= nsStyle.SIDE_LEFT; side++) { if (! ParseVariant(rect.GetSide(side), v => rect.SetSide(side, v), VARIANT_AL, null)) { return false; } if (side == 0) { useCommas = ExpectSymbol(',', true); } else if (useCommas && (int)side < 3) { // Skip optional commas between elements, but only if the first // separator was a comma. if (!ExpectSymbol(',', true)) { return false; } } } if (!ExpectSymbol(')', true)) { return false; } if (!ExpectEndProperty()) { return false; } } else { UngetToken(); return false; } AppendValue(aPropID, val); return true; }
internal void SetBorderImageInitialValues() { // border-image-source: none var source = new nsCSSValue(); source.SetNoneValue(); AppendValue(nsCSSProperty.BorderImageSource, source); // border-image-slice: 100% var sliceBoxValue = new nsCSSValue(); nsCSSRect sliceBox = sliceBoxValue.SetRectValue(); sliceBox.SetAllSidesTo(new nsCSSValue(1.0f, nsCSSUnit.Percent)); var slice = new nsCSSValue(); nsCSSValueList sliceList = slice.SetListValue(); sliceList.mValue = sliceBoxValue; AppendValue(nsCSSProperty.BorderImageSlice, slice); // border-image-width: 1 var width = new nsCSSValue(); nsCSSRect widthBox = width.SetRectValue(); widthBox.SetAllSidesTo(new nsCSSValue(1.0f, nsCSSUnit.Number)); AppendValue(nsCSSProperty.BorderImageWidth, width); // border-image-outset: 0 var outset = new nsCSSValue(); nsCSSRect outsetBox = outset.SetRectValue(); outsetBox.SetAllSidesTo(new nsCSSValue(0.0f, nsCSSUnit.Number)); AppendValue(nsCSSProperty.BorderImageOutset, outset); // border-image-repeat: repeat var repeat = new nsCSSValue(); var repeatPair = new nsCSSValuePair(); repeatPair.SetBothValuesTo(new nsCSSValue(nsStyle.BORDER_IMAGE_REPEAT_STRETCH, nsCSSUnit.Enumerated)); repeat.SetPairValue(repeatPair); AppendValue(nsCSSProperty.BorderImageRepeat, repeat); }
// Similar to ParseBoxProperties, except there is only one property // with the result as its value, not four. Requires values be nonnegative. internal bool ParseGroupedBoxProperty(int32_t aVariantMask, /** outparam */ ref nsCSSValue aValue) { nsCSSRect result = aValue.SetRectValue(); int32_t count = 0; for (Side index = nsStyle.SIDE_TOP; index <= nsStyle.SIDE_LEFT; index++) { if (!ParseNonNegativeVariant(result.GetSide(index), v => result.SetSide(index, v), aVariantMask, null)) { break; } count++; } if (count == 0) { return false; } // Provide missing values by replicating some of the values found switch (count) { case 1: // Make right == top result.mRight = result.mTop; goto case 2; case 2: // Make bottom == top result.mBottom = result.mTop; goto case 3; case 3: // Make left == right result.mLeft = result.mRight; break; } return true; }