font->mFont.decorations = td; font->mFixedFont.decorations = td; text->mTextDecoration = td;
if (NS_STYLE_TEXT_DECORATION_NONE == td) { font->mFont.decorations = td; font->mFixedFont.decorations = td; text->mTextDecoration = td; } else { font->mFont.decorations |= td; font->mFixedFont.decorations |= td; text->mTextDecoration |= td; }
void MapDeclarationInto(nsICSSDeclaration* aDeclaration,                         nsIStyleContext* aContext, nsIPresContext* aPresContext){  if (nsnull != aDeclaration) {    nsStyleFont*  font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);    nsCSSFont*  ourFont;    if (NS_OK == aDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {      if (nsnull != ourFont) {        const nsStyleFont* parentFont = font;        nsIStyleContext* parentContext = aContext->GetParent();        if (nsnull != parentContext) {          parentFont = (const nsStyleFont*)parentContext->GetStyleData(eStyleStruct_Font);        }        const nsFont& defaultFont = aPresContext->GetDefaultFont();        const nsFont& defaultFixedFont = aPresContext->GetDefaultFixedFont();        // font-family: string list        if (ourFont->mFamily.GetUnit() == eCSSUnit_String) {          nsIDeviceContext* dc = aPresContext->GetDeviceContext();          if (nsnull != dc) {            nsAutoString  familyList;            ourFont->mFamily.GetStringValue(familyList);            font->mFont.name = familyList;            nsAutoString  face;            if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {              if (face.EqualsIgnoreCase("monospace")) {                font->mFont = font->mFixedFont;              }              else {                font->mFixedFont.name = familyList;              }            }            else {              font->mFont.name = defaultFont.name;              font->mFixedFont.name = defaultFixedFont.name;            }            font->mFlags |= NS_STYLE_FONT_FACE_EXPLICIT;            NS_RELEASE(dc);          }        }        // font-style: enum        if (ourFont->mStyle.GetUnit() == eCSSUnit_Enumerated) {          font->mFont.style = ourFont->mStyle.GetIntValue();          font->mFixedFont.style = ourFont->mStyle.GetIntValue();        }        // font-variant: enum        if (ourFont->mVariant.GetUnit() == eCSSUnit_Enumerated) {          font->mFont.variant = ourFont->mVariant.GetIntValue();          font->mFixedFont.variant = ourFont->mVariant.GetIntValue();        }        // font-weight: abs, enum        if (ourFont->mWeight.GetUnit() == eCSSUnit_Integer) {          font->mFont.weight = ourFont->mWeight.GetIntValue();          font->mFixedFont.weight = 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;              font->mFixedFont.weight = value;              break;            case NS_STYLE_FONT_WEIGHT_BOLDER:            case NS_STYLE_FONT_WEIGHT_LIGHTER:              font->mFont.weight = (parentFont->mFont.weight + value);              font->mFixedFont.weight = (parentFont->mFixedFont.weight + value);              break;          }        }        // font-size: enum, length, percent        if (ourFont->mSize.GetUnit() == eCSSUnit_Enumerated) {          PRInt32 value = ourFont->mSize.GetIntValue();          PRInt32 scaler = aPresContext->GetFontScaler();          float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);          if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&               (value <= NS_STYLE_FONT_SIZE_XXLARGE)) {            font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)defaultFont.size, scaleFactor);            font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)defaultFixedFont.size, scaleFactor);          }          else if (NS_STYLE_FONT_SIZE_LARGER == value) {            PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor);            font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor);            font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor);          }          else if (NS_STYLE_FONT_SIZE_SMALLER == value) {            PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor);            font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor);            font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor);          }          // this does NOT explicitly set font size        }        else if (ourFont->mSize.IsLengthUnit()) {          font->mFont.size = CalcLength(ourFont->mSize, parentFont, aPresContext);          font->mFixedFont.size = CalcLength(ourFont->mSize, parentFont, aPresContext);          font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;        }        else if (ourFont->mSize.GetUnit() == eCSSUnit_Percent) {          font->mFont.size = (nscoord)((float)(parentFont->mFont.size) * ourFont->mSize.GetPercentValue());          font->mFixedFont.size = (nscoord)((float)(parentFont->mFixedFont.size) * ourFont->mSize.GetPercentValue());          font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;        }        NS_IF_RELEASE(parentContext);      }    }    nsCSSText*  ourText;    if (NS_OK == aDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {      if (nsnull != ourText) {        // Get our text style and our parent's text style        nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);        // 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;          font->mFixedFont.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 == aDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {      if (nsnull != ourDisplay) {        // Get our style and our parent's style        nsStyleDisplay* display = (nsStyleDisplay*)          aContext->GetMutableStyleData(eStyleStruct_Display);        const nsStyleDisplay* parentDisplay = display;        nsIStyleContext* parentContext = aContext->GetParent();        if (nsnull != parentContext) {          parentDisplay = (const nsStyleDisplay*)parentContext->GetStyleData(eStyleStruct_Display);        }        // 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();        }        // visibility: enum, inherit        if (ourDisplay->mVisibility.GetUnit() == eCSSUnit_Enumerated) {          display->mVisible = PRBool (NS_STYLE_VISIBILITY_VISIBLE == ourDisplay->mVisibility.GetIntValue());        }        else if (ourDisplay->mVisibility.GetUnit() == eCSSUnit_Inherit) {          display->mVisible = parentDisplay->mVisible;        }        // overflow        if (ourDisplay->mOverflow.GetUnit() == eCSSUnit_Enumerated) {          display->mOverflow = ourDisplay->mOverflow.GetIntValue();        }        // clip property: length, auto, inherit        if (nsnull != ourDisplay->mClip) {          if (ourDisplay->mClip->mTop.GetUnit() == eCSSUnit_Inherit) { // if one is inherit, they all are            display->mClipFlags = NS_STYLE_CLIP_INHERIT;          }          else {            PRBool  fullAuto = PR_TRUE;            display->mClipFlags = 0; // clear it            if (ourDisplay->mClip->mTop.GetUnit() == eCSSUnit_Auto) {              display->mClip.top = 0;              display->mClipFlags |= NS_STYLE_CLIP_TOP_AUTO;            } else if (ourDisplay->mClip->mTop.IsLengthUnit()) {              display->mClip.top = CalcLength(ourDisplay->mClip->mTop, font, aPresContext);              fullAuto = PR_FALSE;            }            if (ourDisplay->mClip->mRight.GetUnit() == eCSSUnit_Auto) {              display->mClip.right = 0;              display->mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO;            } else if (ourDisplay->mClip->mRight.IsLengthUnit()) {              display->mClip.right = CalcLength(ourDisplay->mClip->mRight, font, aPresContext);              fullAuto = PR_FALSE;            }            if (ourDisplay->mClip->mBottom.GetUnit() == eCSSUnit_Auto) {              display->mClip.bottom = 0;              display->mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO;            } else if (ourDisplay->mClip->mBottom.IsLengthUnit()) {              display->mClip.bottom = CalcLength(ourDisplay->mClip->mBottom, font, aPresContext);              fullAuto = PR_FALSE;            }            if (ourDisplay->mClip->mLeft.GetUnit() == eCSSUnit_Auto) {              display->mClip.left = 0;              display->mClipFlags |= NS_STYLE_CLIP_LEFT_AUTO;            } else if (ourDisplay->mClip->mLeft.IsLengthUnit()) {              display->mClip.left = CalcLength(ourDisplay->mClip->mLeft, font, aPresContext);              fullAuto = PR_FALSE;            }            display->mClipFlags &= ~NS_STYLE_CLIP_TYPE_MASK;            if (fullAuto) {              display->mClipFlags |= NS_STYLE_CLIP_AUTO;            }            else {              display->mClipFlags |= NS_STYLE_CLIP_RECT;            }          }        }        NS_IF_RELEASE(parentContext);      }    }    nsCSSColor*  ourColor;    if (NS_OK == aDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {      if (nsnull != ourColor) {        nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);        // 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;        }        // opacity: factor, percent, enum        if (ourColor->mOpacity.GetUnit() == eCSSUnit_Percent) {          color->mOpacity = ourColor->mOpacity.GetPercentValue();        }        else if (ourColor->mOpacity.GetUnit() == eCSSUnit_Number) {          color->mOpacity = ourColor->mOpacity.GetFloatValue();        }        else if (ourColor->mOpacity.GetUnit() == eCSSUnit_Inherit) {          const nsStyleColor* parentColor = color;          nsIStyleContext* parentContext = aContext->GetParent();          if (nsnull != parentContext) {            parentColor = (const nsStyleColor*)parentContext->GetStyleData(eStyleStruct_Color);            color->mOpacity = parentColor->mOpacity;            NS_RELEASE(parentContext);          }                  }  // XXX: NYI        nsCSSValue mBackFilter;      }    }    nsCSSMargin*  ourMargin;    if (NS_OK == aDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {      if (nsnull != ourMargin) {        nsStyleSpacing* spacing = (nsStyleSpacing*)          aContext->GetMutableStyleData(eStyleStruct_Spacing);        // 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        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 == aDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {      if (nsnull != ourPosition) {        nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);        // position: normal, enum, inherit        if (ourPosition->mPosition.GetUnit() == eCSSUnit_Normal) {          position->mPosition = NS_STYLE_POSITION_NORMAL;        }        else if (ourPosition->mPosition.GetUnit() == eCSSUnit_Enumerated) {          position->mPosition = ourPosition->mPosition.GetIntValue();        }        else if (ourPosition->mPosition.GetUnit() == eCSSUnit_Inherit) {          // explicit inheritance          nsIStyleContext* parentContext = aContext->GetParent();          if (nsnull != parentContext) {            const nsStylePosition* parentPosition = (const nsStylePosition*)parentContext->GetStyleData(eStyleStruct_Position);            position->mPosition = parentPosition->mPosition;          }        }        // 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);      }    }    nsCSSList* ourList;    if (NS_OK == aDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {      if (nsnull != ourList) {        nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);        // 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();        }      }    }  }}