const PRInt32 numResetProps = 2; static const nsCSSProperty kBackgroundResetIDs[numResetProps] = { eCSSProperty__moz_background_clip, eCSSProperty__moz_background_origin };  nsCSSValue initial; initial.SetInitialValue(); for (index = 0; index < numResetProps; ++index) { AppendValue(aDeclaration, kBackgroundResetIDs[index], initial, aChangeHint); }
PRBool CSSParserImpl::ParseBackground(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,                                       nsChangeHint& aChangeHint){  const PRInt32 numProps = 6;  static const nsCSSProperty kBackgroundIDs[numProps] = {    eCSSProperty_background_color,    eCSSProperty_background_image,    eCSSProperty_background_repeat,    eCSSProperty_background_attachment,    eCSSProperty_background_x_position,    eCSSProperty_background_y_position  };  nsCSSValue  values[numProps];  PRInt32 found = ParseChoice(aErrorCode, values, kBackgroundIDs, numProps);  if ((found < 1) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {    return PR_FALSE;  }  if (0 != (found & 0x30)) {  // found one or more position values, validate them    if (0 == (found & 0x20)) {  // x value only      if (eCSSUnit_Enumerated == values[4].GetUnit()) {        switch (values[4].GetIntValue()) {          case BG_CENTER:            values[4].SetIntValue(50, eCSSUnit_Enumerated);            values[5].SetIntValue(50, eCSSUnit_Enumerated);            break;          case BG_TOP:            values[4].SetIntValue(50, eCSSUnit_Enumerated);            values[5].SetIntValue(0, eCSSUnit_Enumerated);            break;          case BG_BOTTOM:            values[4].SetIntValue(50, eCSSUnit_Enumerated);            values[5].SetIntValue(100, eCSSUnit_Enumerated);            break;          case BG_LEFT:            values[4].SetIntValue(0, eCSSUnit_Enumerated);            values[5].SetIntValue(50, eCSSUnit_Enumerated);            break;          case BG_RIGHT:            values[4].SetIntValue(100, eCSSUnit_Enumerated);            values[5].SetIntValue(50, eCSSUnit_Enumerated);            break;        }      }      else if (eCSSUnit_Inherit == values[4].GetUnit()) {        values[5].SetInheritValue();      }      else if (eCSSUnit_Initial == values[4].GetUnit()) {        values[5].SetInitialValue();      }      else {        values[5].SetPercentValue(0.5f);      }    }    else { // both x & y values      nsCSSUnit xUnit = values[4].GetUnit();      nsCSSUnit yUnit = values[5].GetUnit();      if (eCSSUnit_Enumerated == xUnit) { // if one is enumerated, both must be        if (eCSSUnit_Enumerated == yUnit) {          PRInt32 xValue = values[4].GetIntValue();          PRInt32 yValue = values[5].GetIntValue();          if (0 != (xValue & (BG_LEFT | BG_RIGHT)) &&  // x is really an x value              0 != (yValue & (BG_LEFT | BG_RIGHT))) {  // y is also an x value            return PR_FALSE;          }          if (0 != (xValue & (BG_TOP | BG_BOTTOM)) &&  // x is really an y value              0 != (yValue & (BG_TOP | BG_BOTTOM))) {  // y is also an y value            return PR_FALSE;          }          if (0 != (xValue & (BG_TOP | BG_BOTTOM)) ||  // x is really a y value              0 != (yValue & (BG_LEFT | BG_RIGHT))) {  // or y is really an x value            PRInt32 holdXValue = xValue;            xValue = yValue;            yValue = holdXValue;          }          switch (xValue) {            case BG_LEFT:              values[4].SetIntValue(0, eCSSUnit_Enumerated);              break;            case BG_CENTER:              values[4].SetIntValue(50, eCSSUnit_Enumerated);              break;            case BG_RIGHT:              values[4].SetIntValue(100, eCSSUnit_Enumerated);              break;            default:              NS_ERROR("bad x value");          }          switch (yValue) {            case BG_TOP:              values[5].SetIntValue(0, eCSSUnit_Enumerated);              break;            case BG_CENTER:              values[5].SetIntValue(50, eCSSUnit_Enumerated);              break;            case BG_BOTTOM:              values[5].SetIntValue(100, eCSSUnit_Enumerated);              break;            default:              NS_ERROR("bad y value");          }        }        else {          return PR_FALSE;        }      }      else {        if (eCSSUnit_Enumerated == yUnit) {          return PR_FALSE;        }      }    }  }  // Provide missing values  if ((found & 0x01) == 0) {    values[0].SetIntValue(NS_STYLE_BG_COLOR_TRANSPARENT, eCSSUnit_Enumerated);  }  if ((found & 0x02) == 0) {    values[1].SetNoneValue();  }  if ((found & 0x04) == 0) {    values[2].SetIntValue(NS_STYLE_BG_REPEAT_XY, eCSSUnit_Enumerated);  }  if ((found & 0x08) == 0) {    values[3].SetIntValue(NS_STYLE_BG_ATTACHMENT_SCROLL, eCSSUnit_Enumerated);  }  if ((found & 0x30) == 0) {    values[4].SetPercentValue(0.0f);    values[5].SetPercentValue(0.0f);  }  PRInt32 index;  for (index = 0; index < numProps; index++) {    AppendValue(aDeclaration, kBackgroundIDs[index], values[index], aChangeHint);  }  return PR_TRUE;}