Bug 1293590 - Part 1. Fix basic-shape position serialization.
MozReview-Commit-ID: 5PE9NUefvkE
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -12772,28 +12772,28 @@ AdjustEdgeOffsetPairForBasicShape(nsCSSV
nsCSSValue& aOffset,
uint8_t aDefaultEdge)
{
// 0 length offsets are 0%
if (aOffset.IsLengthUnit() && aOffset.GetFloatValue() == 0.0) {
aOffset.SetPercentValue(0);
}
- // Default edge is top/left in the 4-value case
- // In case of 1 or 0 values, the default is center,
- // but ParsePositionValue already handles this case
- if (eCSSUnit_Null == aEdge.GetUnit()) {
- aEdge.SetIntValue(aDefaultEdge, eCSSUnit_Enumerated);
- }
// Default offset is 0%
if (eCSSUnit_Null == aOffset.GetUnit()) {
aOffset.SetPercentValue(0.0);
}
- if (eCSSUnit_Enumerated == aEdge.GetUnit() &&
- eCSSUnit_Percent == aOffset.GetUnit()) {
+
+ if (eCSSUnit_Percent == aOffset.GetUnit()) {
+ // Default edge is top/left in the 4-value case
+ // In case of 1 or 0 values, the default is center,
+ // but ParsePositionValue already handles this case
+ if (eCSSUnit_Null == aEdge.GetUnit()) {
+ aEdge.SetIntValue(aDefaultEdge, eCSSUnit_Enumerated);
+ }
switch (aEdge.GetIntValue()) {
case NS_STYLE_IMAGELAYER_POSITION_CENTER:
aEdge.SetIntValue(aDefaultEdge, eCSSUnit_Enumerated);
MOZ_ASSERT(aOffset.GetPercentValue() == 0.0,
"center cannot be used with an offset");
aOffset.SetPercentValue(0.5);
break;
case NS_STYLE_IMAGELAYER_POSITION_BOTTOM:
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -988,32 +988,41 @@ void
nsCSSValue::AppendBasicShapePositionToString(nsAString& aResult,
Serialization aSerialization) const
{
const nsCSSValue::Array* array = GetArrayValue();
// We always parse these into an array of four elements
MOZ_ASSERT(array->Count() == 4,
"basic-shape position value doesn't have enough elements");
- const nsCSSValue &xEdge = array->Item(0);
+ nsCSSValue xEdge = array->Item(0);
const nsCSSValue &xOffset = array->Item(1);
- const nsCSSValue &yEdge = array->Item(2);
+ nsCSSValue yEdge = array->Item(2);
const nsCSSValue &yOffset = array->Item(3);
- MOZ_ASSERT(xEdge.GetUnit() == eCSSUnit_Enumerated &&
- yEdge.GetUnit() == eCSSUnit_Enumerated &&
- xOffset.IsLengthPercentCalcUnit() &&
- yOffset.IsLengthPercentCalcUnit() &&
- xEdge.GetIntValue() != NS_STYLE_IMAGELAYER_POSITION_CENTER &&
- yEdge.GetIntValue() != NS_STYLE_IMAGELAYER_POSITION_CENTER,
- "Ensure invariants from ParsePositionValueBasicShape "
- "haven't been modified");
+ // Ensure invariants from ParsePositionValueBasicShape aven't been modified.
+ MOZ_ASSERT_IF(xOffset.GetUnit() == eCSSUnit_Percent,
+ xEdge.GetUnit() == eCSSUnit_Enumerated &&
+ xEdge.GetIntValue() != NS_STYLE_IMAGELAYER_POSITION_CENTER);
+ MOZ_ASSERT_IF(yOffset.GetUnit() == eCSSUnit_Percent,
+ yEdge.GetUnit() == eCSSUnit_Enumerated &&
+ yEdge.GetIntValue() != NS_STYLE_IMAGELAYER_POSITION_CENTER);
+
+ // Give default value to these edges.
+ if (xEdge.GetUnit() == eCSSUnit_Null) {
+ xEdge.SetIntValue(NS_STYLE_IMAGELAYER_POSITION_LEFT, eCSSUnit_Enumerated);
+ }
+ if (yEdge.GetUnit() == eCSSUnit_Null) {
+ yEdge.SetIntValue(NS_STYLE_IMAGELAYER_POSITION_TOP, eCSSUnit_Enumerated);
+ }
+
if (xEdge.GetIntValue() == NS_STYLE_IMAGELAYER_POSITION_LEFT &&
yEdge.GetIntValue() == NS_STYLE_IMAGELAYER_POSITION_TOP) {
- // We can omit these defaults
+ // We should omit these defaults since 2-value form is preferred in
+ // basic-shape serialization.
xOffset.AppendToString(eCSSProperty_UNKNOWN, aResult, aSerialization);
aResult.Append(' ');
yOffset.AppendToString(eCSSProperty_UNKNOWN, aResult, aSerialization);
} else {
// We only serialize to the two or four valued form
xEdge.AppendToString(eCSSProperty_object_position, aResult, aSerialization);
aResult.Append(' ');
xOffset.AppendToString(eCSSProperty_UNKNOWN, aResult, aSerialization);