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); }
bool ParseTransformOrigin(bool aPerspective) { var position = new nsCSSValuePair(); if (!ParseBoxPositionValues(ref position, true)) return false; nsCSSProperty prop = nsCSSProperty.TransformOrigin; if (aPerspective) { if (!ExpectEndProperty()) { return false; } prop = nsCSSProperty.PerspectiveOrigin; } // Unlike many other uses of pairs, this position should always be stored // as a pair, even if the values are the same, so it always serializes as // a pair, and to keep the computation code simple. if (position.mXValue.GetUnit() == nsCSSUnit.Inherit || position.mXValue.GetUnit() == nsCSSUnit.Initial) { Debug.Assert(position.mXValue == position.mYValue, "inherit/initial only half?"); AppendValue(prop, position.mXValue); } else { var value = new nsCSSValue(); if (aPerspective) { value.SetPairValue(position.mXValue, position.mYValue); } else { var depth = new nsCSSValue(); if (!nsLayoutUtils.Are3DTransformsEnabled() || // only try parsing if 3-D transforms are enabled !ParseVariant(ref depth, VARIANT_LENGTH | VARIANT_CALC, null)) { depth.SetFloatValue(0.0f, nsCSSUnit.Pixel); } value.SetTripletValue(position.mXValue, position.mYValue, depth); } AppendValue(prop, value); } return true; }
internal bool ParseSize() { nsCSSValue width = new nsCSSValue(), height = new nsCSSValue(); if (!ParseVariant(ref width, VARIANT_AHKL, nsCSSProps.kPageSizeKTable)) { return false; } if (width.IsLengthUnit()) { ParseVariant(ref height, VARIANT_LENGTH, null); } if (!ExpectEndProperty()) { return false; } if (width == height || height.GetUnit() == nsCSSUnit.Null) { AppendValue(nsCSSProperty.Size, width); } else { var pair = new nsCSSValue(); pair.SetPairValue(width, height); AppendValue(nsCSSProperty.Size, pair); } return true; }
internal bool ParseTextOverflow(ref nsCSSValue aValue) { if (ParseVariant(ref aValue, VARIANT_INHERIT, null)) { // 'inherit' and 'initial' must be alone return true; } var left = new nsCSSValue(); if (!ParseVariant(ref left, VARIANT_KEYWORD | VARIANT_STRING, nsCSSProps.kTextOverflowKTable)) return false; var right = new nsCSSValue(); if (ParseVariant(ref right, VARIANT_KEYWORD | VARIANT_STRING, nsCSSProps.kTextOverflowKTable)) aValue.SetPairValue(left, right); else { aValue = left; } return true; }
internal bool ParsePaint(nsCSSProperty aPropID) { nsCSSValue x = new nsCSSValue(), y = new nsCSSValue(); if (!ParseVariant(ref x, VARIANT_HCK | VARIANT_NONE | VARIANT_URL, nsCSSProps.kObjectPatternKTable)) { return false; } bool canHaveFallback = x.GetUnit() == nsCSSUnit.Url || x.GetUnit() == nsCSSUnit.Enumerated; if (canHaveFallback) { if (!ParseVariant(ref y, VARIANT_COLOR | VARIANT_NONE, null)) y.SetNoneValue(); } if (!ExpectEndProperty()) return false; if (!canHaveFallback) { AppendValue(aPropID, x); } else { var val = new nsCSSValue(); val.SetPairValue(x, y); AppendValue(aPropID, val); } return true; }
internal bool ParseBoxCornerRadius(nsCSSProperty aPropID) { nsCSSValue dimenX = new nsCSSValue(), dimenY = new nsCSSValue(); // required first value if (! ParseNonNegativeVariant(ref dimenX, VARIANT_HLP | VARIANT_CALC, null)) return false; // optional second value (forbidden if first value is inherit/initial) if (dimenX.GetUnit() != nsCSSUnit.Inherit && dimenX.GetUnit() != nsCSSUnit.Initial) { ParseNonNegativeVariant(ref dimenY, VARIANT_LP | VARIANT_CALC, null); } if (dimenX == dimenY || dimenY.GetUnit() == nsCSSUnit.Null) { AppendValue(aPropID, dimenX); } else { var value = new nsCSSValue(); value.SetPairValue(dimenX, dimenY); AppendValue(aPropID, value); } return true; }
internal bool ParseBoxCornerRadii(nsCSSProperty[] aPropIDs) { // Rectangles are used as scratch storage. // top => top-left, right => top-right, // bottom => bottom-right, left => bottom-left. nsCSSRect dimenX = new nsCSSRect(), dimenY = new nsCSSRect(); int32_t countX = 0, countY = 0; for (Side side = nsStyle.SIDE_TOP; side <= nsStyle.SIDE_LEFT; side++) { if (! ParseNonNegativeVariant(dimenX.GetSide(side), v => dimenX.SetSide(side, v), (side > 0 ? 0 : VARIANT_INHERIT) | VARIANT_LP | VARIANT_CALC, null)) break; countX++; } if (countX == 0) return false; if (ExpectSymbol('/', true)) { for (Side side = nsStyle.SIDE_TOP; side <= nsStyle.SIDE_LEFT; side++) { if (! ParseNonNegativeVariant(dimenY.GetSide(side), v => dimenY.SetSide(side, v), VARIANT_LP | VARIANT_CALC, null)) break; countY++; } if (countY == 0) return false; } if (!ExpectEndProperty()) return false; // if 'initial' or 'inherit' was used, it must be the only value if (countX > 1 || countY > 0) { nsCSSUnit unit = dimenX.mTop.GetUnit(); if (nsCSSUnit.Inherit == unit || nsCSSUnit.Initial == unit) return false; } // if we have no Y-values, use the X-values if (countY == 0) { dimenY = dimenX; countY = countX; } // Provide missing values by replicating some of the values found switch (countX) { case 1: dimenX.mRight = dimenX.mTop; // top-right same as top-left, and goto case 2; case 2: dimenX.mBottom = dimenX.mTop; // bottom-right same as top-left, and goto case 3; case 3: dimenX.mLeft = dimenX.mRight; // bottom-left same as top-right break; } switch (countY) { case 1: dimenY.mRight = dimenY.mTop; // top-right same as top-left, and goto case 2; case 2: dimenY.mBottom = dimenY.mTop; // bottom-right same as top-left, and goto case 3; case 3: dimenY.mLeft = dimenY.mRight; // bottom-left same as top-right break; } for (Side side = nsStyle.SIDE_TOP; side <= nsStyle.SIDE_LEFT; side++) { nsCSSValue x = dimenX.GetSide(side); nsCSSValue y = dimenY.GetSide(side); if (x == y) { AppendValue(aPropIDs[(int)side], x); } else { var pair = new nsCSSValue(); pair.SetPairValue(x, y); AppendValue(aPropIDs[(int)side], pair); } } return true; }
internal bool ParseBorderSpacing() { nsCSSValue xValue = new nsCSSValue(), yValue = new nsCSSValue(); if (!ParseNonNegativeVariant(ref xValue, VARIANT_HL | VARIANT_CALC, null)) { return false; } // If we have one length, get the optional second length. // set the second value equal to the first. if (xValue.IsLengthUnit() || xValue.IsCalcUnit()) { ParseNonNegativeVariant(ref yValue, VARIANT_LENGTH | VARIANT_CALC, null); } if (!ExpectEndProperty()) { return false; } if (yValue == xValue || yValue.GetUnit() == nsCSSUnit.Null) { AppendValue(nsCSSProperty.BorderSpacing, xValue); } else { var pair = new nsCSSValue(); pair.SetPairValue(xValue, yValue); AppendValue(nsCSSProperty.BorderSpacing, pair); } return true; }
internal bool ParseBorderImageRepeat(bool aAcceptsInherit) { var value = new nsCSSValue(); if (aAcceptsInherit && ParseVariant(ref value, VARIANT_INHERIT, null)) { // Keyword "inherit" can not be mixed, so we are done. AppendValue(nsCSSProperty.BorderImageRepeat, value); return true; } var result = new nsCSSValuePair(); if (!ParseEnum(ref result.mXValue, nsCSSProps.kBorderImageRepeatKTable)) { return false; } // optional second keyword, defaults to first if (!ParseEnum(ref result.mYValue, nsCSSProps.kBorderImageRepeatKTable)) { result.mYValue = result.mXValue; } value.SetPairValue(result); AppendValue(nsCSSProperty.BorderImageRepeat, value); return true; }