if (ourPosition->mPosition.GetUnit() == eCSSUnit_Enumerated) {
if (ourPosition->mPosition.GetUnit() == eCSSUnit_Normal) { position->mPosition = NS_STYLE_POSITION_NORMAL; } else if (ourPosition->mPosition.GetUnit() == eCSSUnit_Enumerated) {
void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext){  if (nsnull != mDeclaration) {    nsStyleFont*  font = (nsStyleFont*)aContext->GetData(kStyleFontSID);    nsCSSFont*  ourFont;    if (NS_OK == mDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {      if (nsnull != ourFont) {        nsStyleFont* parentFont = font;        nsIStyleContext* parentContext = aContext->GetParent();        if (nsnull != parentContext) {          parentFont = (nsStyleFont*)parentContext->GetData(kStyleFontSID);        }        // font-family: string list        if (ourFont->mFamily.GetUnit() == eCSSUnit_String) {          nsAutoString familyList;          ourFont->mFamily.GetStringValue(familyList);          // XXX meeds font support to determine usable fonts          // parse up the CSS string & remove the quotes          // XXX only does first until we can tell what are installed fonts          nsAutoString family;          PRInt32 index = familyList.Find(PRUnichar(','));          if (-1 < index) {            familyList.Left(family, index);          }          else {            family.Append(familyList);          }          family.StripChars("\"");          family.StripWhitespace();          font->mFont.name = family;        }        // font-style: enum        if (ourFont->mStyle.GetUnit() == eCSSUnit_Enumerated) {          font->mFont.style = ourFont->mStyle.GetIntValue();        }        // font-variant: enum        if (ourFont->mVariant.GetUnit() == eCSSUnit_Enumerated) {          font->mFont.variant = ourFont->mVariant.GetIntValue();        }        // font-weight: abs, enum        if (ourFont->mWeight.GetUnit() == eCSSUnit_Integer) {          font->mFont.style = ourFont->mWeight.GetIntValue();        }        else if (ourFont->mWeight.GetUnit() == eCSSUnit_Enumerated) {          PRInt32 value = ourFont->mWeight.GetIntValue();          switch (value) {            case NS_STYLE_FONT_WEIGHT_NORMAL:            case NS_STYLE_FONT_WEIGHT_BOLD:              font->mFont.weight = value;              break;            case NS_STYLE_FONT_WEIGHT_BOLDER:            case NS_STYLE_FONT_WEIGHT_LIGHTER:              font->mFont.weight = (parentFont->mFont.weight + value);              break;          }        }        // font-size: enum, length, percent        if (ourFont->mSize.GetUnit() == eCSSUnit_Enumerated) {          static float kFontScale[7] = {            0.5f,                 // xx-small            0.666667f,            // x-small            0.833333f,            // small            1.0f,                 // medium            1.5f,                 // large            1.5f * 1.5f,          // x-large            1.5f * 1.5f * 1.5f,   // xx-large          };          PRInt32 value = ourFont->mSize.GetIntValue();          const nsFont& normal = aPresContext->GetDefaultFont();  // use normal font or body font??          if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&               (value <= NS_STYLE_FONT_SIZE_XXLARGE)) {            font->mFont.size = (nscoord)((float)normal.size * kFontScale[value]);          }          else if (NS_STYLE_FONT_SIZE_LARGER == value) {            PRInt32 index;            for (index = NS_STYLE_FONT_SIZE_XXSMALL;                 index < NS_STYLE_FONT_SIZE_XXLARGE; index++)              if (parentFont->mFont.size < (nscoord)((float)normal.size * kFontScale[index]))                break;            font->mFont.size = (nscoord)((float)normal.size * kFontScale[index]);          }          else if (NS_STYLE_FONT_SIZE_SMALLER == value) {            PRInt32 index;            for (index = NS_STYLE_FONT_SIZE_XXLARGE;                 index > NS_STYLE_FONT_SIZE_XXSMALL; index--)              if (parentFont->mFont.size > (nscoord)((float)normal.size * kFontScale[index]))                break;            font->mFont.size = (nscoord)((float)normal.size * kFontScale[index]);          }        }        else if (ourFont->mSize.IsLengthUnit()) {          font->mFont.size = CalcLength(ourFont->mSize, parentFont, aPresContext);        }        else if (ourFont->mSize.GetUnit() == eCSSUnit_Percent) {          font->mFont.size = (nscoord)((float)(parentFont->mFont.size) * ourFont->mSize.GetPercentValue());        }        NS_IF_RELEASE(parentContext);      }    }    nsCSSText*  ourText;    if (NS_OK == mDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {      if (nsnull != ourText) {        // Get our text style and our parent's text style        nsStyleText* text = (nsStyleText*) aContext->GetData(kStyleTextSID);        // letter-spacing        SetCoord(ourText->mLetterSpacing, text->mLetterSpacing, SETCOORD_LH | SETCOORD_NORMAL,                  font, aPresContext);        // line-height        SetCoord(ourText->mLineHeight, text->mLineHeight, SETCOORD_LPFHN, font, aPresContext);        // text-align        if (ourText->mTextAlign.GetUnit() == eCSSUnit_Enumerated) {          text->mTextAlign = ourText->mTextAlign.GetIntValue();        }        // text-indent        SetCoord(ourText->mTextIndent, text->mTextIndent, SETCOORD_LPH, font, aPresContext);        // text-decoration: enum, int (bit field)        if ((ourText->mDecoration.GetUnit() == eCSSUnit_Enumerated) ||            (ourText->mDecoration.GetUnit() == eCSSUnit_Integer)) {          PRInt32 td = ourText->mDecoration.GetIntValue();          font->mFont.decorations = td;          text->mTextDecoration = td;        }        // text-transform        if (ourText->mTextTransform.GetUnit() == eCSSUnit_Enumerated) {          text->mTextTransform = ourText->mTextTransform.GetIntValue();        }        // vertical-align        SetCoord(ourText->mVerticalAlign, text->mVerticalAlign, SETCOORD_LPEH,                 font, aPresContext);        // white-space        if (ourText->mWhiteSpace.GetUnit() == eCSSUnit_Enumerated) {          text->mWhiteSpace = ourText->mWhiteSpace.GetIntValue();        }        // word-spacing        SetCoord(ourText->mWordSpacing, text->mWordSpacing, SETCOORD_LH | SETCOORD_NORMAL,                 font, aPresContext);      }    }    nsCSSDisplay*  ourDisplay;    if (NS_OK == mDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {      if (nsnull != ourDisplay) {        // Get our style and our parent's style        nsStyleDisplay* display = (nsStyleDisplay*)          aContext->GetData(kStyleDisplaySID);        // display        if (ourDisplay->mDisplay.GetUnit() == eCSSUnit_Enumerated) {          display->mDisplay = ourDisplay->mDisplay.GetIntValue();        }        // direction: enum        if (ourDisplay->mDirection.GetUnit() == eCSSUnit_Enumerated) {          display->mDirection = ourDisplay->mDirection.GetIntValue();        }        // clear: enum        if (ourDisplay->mClear.GetUnit() == eCSSUnit_Enumerated) {          display->mBreakType = ourDisplay->mClear.GetIntValue();        }        // float: enum        if (ourDisplay->mFloat.GetUnit() == eCSSUnit_Enumerated) {          display->mFloats = ourDisplay->mFloat.GetIntValue();        }      }    }    nsCSSColor*  ourColor;    if (NS_OK == mDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {      if (nsnull != ourColor) {        nsStyleColor* color = (nsStyleColor*)aContext->GetData(kStyleColorSID);        // color: color        if (ourColor->mColor.GetUnit() == eCSSUnit_Color) {          color->mColor = ourColor->mColor.GetColorValue();        }        // cursor: enum, auto, inherit        if (ourColor->mCursor.GetUnit() == eCSSUnit_Enumerated) {          color->mCursor = ourColor->mCursor.GetIntValue();        }        else if (ourColor->mCursor.GetUnit() == eCSSUnit_Auto) {          color->mCursor = NS_STYLE_CURSOR_AUTO;        }        else if (ourColor->mCursor.GetUnit() == eCSSUnit_Inherit) {          color->mCursor = NS_STYLE_CURSOR_INHERIT;        }        // cursor-image: string        if (ourColor->mCursorImage.GetUnit() == eCSSUnit_String) {          ourColor->mCursorImage.GetStringValue(color->mCursorImage);        }        // background-color: color, enum (flags)        if (ourColor->mBackColor.GetUnit() == eCSSUnit_Color) {          color->mBackgroundColor = ourColor->mBackColor.GetColorValue();          color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;        }        else if (ourColor->mBackColor.GetUnit() == eCSSUnit_Enumerated) {          color->mBackgroundFlags |= NS_STYLE_BG_COLOR_TRANSPARENT;        }        // background-image: string (url), none        if (ourColor->mBackImage.GetUnit() == eCSSUnit_String) {          ourColor->mBackImage.GetStringValue(color->mBackgroundImage);          color->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE;        }        else if (ourColor->mBackImage.GetUnit() == eCSSUnit_None) {          color->mBackgroundImage.Truncate();          color->mBackgroundFlags |= NS_STYLE_BG_IMAGE_NONE;        }        // background-repeat: enum        if (ourColor->mBackRepeat.GetUnit() == eCSSUnit_Enumerated) {          color->mBackgroundRepeat = ourColor->mBackRepeat.GetIntValue();        }        // background-attachment: enum        if (ourColor->mBackAttachment.GetUnit() == eCSSUnit_Enumerated) {          color->mBackgroundAttachment = ourColor->mBackAttachment.GetIntValue();        }        // background-position: length, percent (flags)        if (ourColor->mBackPositionX.GetUnit() == eCSSUnit_Percent) {          color->mBackgroundXPosition = (nscoord)(100.0f * ourColor->mBackPositionX.GetPercentValue());          color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT;          color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;        }        else if (ourColor->mBackPositionX.IsLengthUnit()) {          color->mBackgroundXPosition = CalcLength(ourColor->mBackPositionX,                                                   font, aPresContext);          color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_LENGTH;          color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_PERCENT;        }        if (ourColor->mBackPositionY.GetUnit() == eCSSUnit_Percent) {          color->mBackgroundYPosition = (nscoord)(100.0f * ourColor->mBackPositionY.GetPercentValue());          color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT;          color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;        }        else if (ourColor->mBackPositionY.IsLengthUnit()) {          color->mBackgroundYPosition = CalcLength(ourColor->mBackPositionY,                                                   font, aPresContext);          color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_LENGTH;          color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_PERCENT;        }  // XXX: NYI        nsCSSValue mBackFilter;      }    }    nsCSSMargin*  ourMargin;    if (NS_OK == mDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {      if (nsnull != ourMargin) {        nsStyleSpacing* spacing = (nsStyleSpacing*)          aContext->GetData(kStyleSpacingSID);        // margin: length, percent, auto, inherit        if (nsnull != ourMargin->mMargin) {          nsStyleCoord  coord;          if (SetCoord(ourMargin->mMargin->mLeft, coord, SETCOORD_LPAH, font, aPresContext)) {            spacing->mMargin.SetLeft(coord);          }          if (SetCoord(ourMargin->mMargin->mTop, coord, SETCOORD_LPAH, font, aPresContext)) {            spacing->mMargin.SetTop(coord);          }          if (SetCoord(ourMargin->mMargin->mRight, coord, SETCOORD_LPAH, font, aPresContext)) {            spacing->mMargin.SetRight(coord);          }          if (SetCoord(ourMargin->mMargin->mBottom, coord, SETCOORD_LPAH, font, aPresContext)) {            spacing->mMargin.SetBottom(coord);          }        }        // padding: length, percent, inherit        if (nsnull != ourMargin->mPadding) {          nsStyleCoord  coord;          if (SetCoord(ourMargin->mPadding->mLeft, coord, SETCOORD_LPH, font, aPresContext)) {            spacing->mPadding.SetLeft(coord);          }          if (SetCoord(ourMargin->mPadding->mTop, coord, SETCOORD_LPH, font, aPresContext)) {            spacing->mPadding.SetTop(coord);          }          if (SetCoord(ourMargin->mPadding->mRight, coord, SETCOORD_LPH, font, aPresContext)) {            spacing->mPadding.SetRight(coord);          }          if (SetCoord(ourMargin->mPadding->mBottom, coord, SETCOORD_LPH, font, aPresContext)) {            spacing->mPadding.SetBottom(coord);          }        }        // border-size: length, enum (percent), inherit        if (nsnull != ourMargin->mBorder) {          nsStyleCoord  coord;          if (SetCoord(ourMargin->mBorder->mLeft, coord, SETCOORD_LPEH, font, aPresContext)) {            spacing->mBorder.SetLeft(coord);          }          if (SetCoord(ourMargin->mBorder->mTop, coord, SETCOORD_LPEH, font, aPresContext)) {            spacing->mBorder.SetTop(coord);          }          if (SetCoord(ourMargin->mBorder->mRight, coord, SETCOORD_LPEH, font, aPresContext)) {            spacing->mBorder.SetRight(coord);          }          if (SetCoord(ourMargin->mBorder->mBottom, coord, SETCOORD_LPEH, font, aPresContext)) {            spacing->mBorder.SetBottom(coord);          }        }        // border-style        if (nsnull != ourMargin->mStyle) {          nsCSSRect* ourStyle = ourMargin->mStyle;          if (ourStyle->mTop.GetUnit() == eCSSUnit_Enumerated) {            spacing->mBorderStyle[NS_SIDE_TOP] = ourStyle->mTop.GetIntValue();          }          if (ourStyle->mRight.GetUnit() == eCSSUnit_Enumerated) {            spacing->mBorderStyle[NS_SIDE_RIGHT] = ourStyle->mRight.GetIntValue();          }          if (ourStyle->mBottom.GetUnit() == eCSSUnit_Enumerated) {            spacing->mBorderStyle[NS_SIDE_BOTTOM] = ourStyle->mBottom.GetIntValue();          }          if (ourStyle->mLeft.GetUnit() == eCSSUnit_Enumerated) {            spacing->mBorderStyle[NS_SIDE_LEFT] = ourStyle->mLeft.GetIntValue();          }        }        // border-color        nsStyleColor* color = (nsStyleColor*)aContext->GetData(kStyleColorSID);        if (nsnull != ourMargin->mColor) {          nsCSSRect* ourColor = ourMargin->mColor;          if (ourColor->mTop.GetUnit() == eCSSUnit_Color) {            spacing->mBorderColor[NS_SIDE_TOP] = ourColor->mTop.GetColorValue();          }          if (ourColor->mRight.GetUnit() == eCSSUnit_Color) {            spacing->mBorderColor[NS_SIDE_RIGHT] = ourColor->mRight.GetColorValue();          }          if (ourColor->mBottom.GetUnit() == eCSSUnit_Color) {            spacing->mBorderColor[NS_SIDE_BOTTOM] = ourColor->mBottom.GetColorValue();          }          if (ourColor->mLeft.GetUnit() == eCSSUnit_Color) {            spacing->mBorderColor[NS_SIDE_LEFT] = ourColor->mLeft.GetColorValue();          }        }      }    }    nsCSSPosition*  ourPosition;    if (NS_OK == mDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {      if (nsnull != ourPosition) {        nsStylePosition* position = (nsStylePosition*)aContext->GetData(kStylePositionSID);        // positioning scheme        if (ourPosition->mPosition.GetUnit() == eCSSUnit_Enumerated) {          position->mPosition = ourPosition->mPosition.GetIntValue();        }        // overflow        if (ourPosition->mOverflow.GetUnit() == eCSSUnit_Enumerated) {          position->mOverflow = ourPosition->mOverflow.GetIntValue();        }        // box offsets: length, percent, auto, inherit        SetCoord(ourPosition->mLeft, position->mLeftOffset, SETCOORD_LPAH, font, aPresContext);        SetCoord(ourPosition->mTop, position->mTopOffset, SETCOORD_LPAH, font, aPresContext);        SetCoord(ourPosition->mWidth, position->mWidth, SETCOORD_LPAH, font, aPresContext);        SetCoord(ourPosition->mHeight, position->mHeight, SETCOORD_LPAH, font, aPresContext);        // z-index        SetCoord(ourPosition->mZIndex, position->mZIndex, SETCOORD_IAH, nsnull, nsnull);        // clip property: length, auto, inherit        if (nsnull != ourPosition->mClip) {          if (ourPosition->mClip->mTop.GetUnit() == eCSSUnit_Inherit) { // if one is inherit, they all are            position->mClipFlags = NS_STYLE_CLIP_INHERIT;          }          else {            PRBool  fullAuto = PR_TRUE;            position->mClipFlags = 0; // clear it            if (ourPosition->mClip->mTop.GetUnit() == eCSSUnit_Auto) {              position->mClip.top = 0;              position->mClipFlags |= NS_STYLE_CLIP_TOP_AUTO;            } else if (ourPosition->mClip->mTop.IsLengthUnit()) {              position->mClip.top = CalcLength(ourPosition->mClip->mTop, font, aPresContext);              fullAuto = PR_FALSE;            }            if (ourPosition->mClip->mRight.GetUnit() == eCSSUnit_Auto) {              position->mClip.right = 0;              position->mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO;            } else if (ourPosition->mClip->mRight.IsLengthUnit()) {              position->mClip.right = CalcLength(ourPosition->mClip->mRight, font, aPresContext);              fullAuto = PR_FALSE;            }            if (ourPosition->mClip->mBottom.GetUnit() == eCSSUnit_Auto) {              position->mClip.bottom = 0;              position->mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO;            } else if (ourPosition->mClip->mBottom.IsLengthUnit()) {              position->mClip.bottom = CalcLength(ourPosition->mClip->mBottom, font, aPresContext);              fullAuto = PR_FALSE;            }            if (ourPosition->mClip->mLeft.GetUnit() == eCSSUnit_Auto) {              position->mClip.left = 0;              position->mClipFlags |= NS_STYLE_CLIP_LEFT_AUTO;            } else if (ourPosition->mClip->mLeft.IsLengthUnit()) {              position->mClip.left = CalcLength(ourPosition->mClip->mLeft, font, aPresContext);              fullAuto = PR_FALSE;            }            position->mClipFlags &= ~NS_STYLE_CLIP_TYPE_MASK;            if (fullAuto) {              position->mClipFlags |= NS_STYLE_CLIP_AUTO;            }            else {              position->mClipFlags |= NS_STYLE_CLIP_RECT;            }          }        }      }    }    nsCSSList* ourList;    if (NS_OK == mDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {      if (nsnull != ourList) {        nsStyleList* list = (nsStyleList*)aContext->GetData(kStyleListSID);        // list-style-type: enum        if (ourList->mType.GetUnit() == eCSSUnit_Enumerated) {          list->mListStyleType = ourList->mType.GetIntValue();        }        if (ourList->mImage.GetUnit() == eCSSUnit_String) {          // list-style-image: string          ourList->mImage.GetStringValue(list->mListStyleImage);        }        else if (ourList->mImage.GetUnit() == eCSSUnit_Enumerated) {          // list-style-image: none          list->mListStyleImage = "";        }        // list-style-position: enum        if (ourList->mPosition.GetUnit() == eCSSUnit_Enumerated) {          list->mListStylePosition = ourList->mPosition.GetIntValue();        }      }    }  }}