if (sysID == eSystemAttr_Font_Field) { font->mFont.name.AssignWithConversion("monospace"); } else if (sysID == eSystemAttr_Font_Button || sysID == eSystemAttr_Font_Caption) { font->mFont.name.AssignWithConversion("sans-serif"); }
MapDeclarationFontInto(nsICSSDeclaration* aDeclaration,                        nsIMutableStyleContext* aContext, nsIPresContext* aPresContext){  if (nsnull != aDeclaration) {    nsIStyleContext* parentContext = aContext->GetParent();    nsStyleFont*  font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);    const nsStyleFont* parentFont = font;    if (nsnull != parentContext) {      parentFont = (const nsStyleFont*)parentContext->GetStyleData(eStyleStruct_Font);    }    nsCSSFont*  ourFont;    if (NS_OK == aDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {      if (nsnull != ourFont) {        const nsFont& defaultFont = aPresContext->GetDefaultFontDeprecated();        const nsFont& defaultFixedFont = aPresContext->GetDefaultFixedFontDeprecated();        // font-family: string list, enum, inherit        if (eCSSUnit_String == ourFont->mFamily.GetUnit()) {          nsCOMPtr<nsIDeviceContext> dc;          aPresContext->GetDeviceContext(getter_AddRefs(dc));          if (dc) {            nsAutoString  familyList;            ourFont->mFamily.GetStringValue(familyList);            font->mFont.name = familyList;            nsAutoString  face;            if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {              if (face.EqualsIgnoreCase("-moz-fixed")) {                font->mFlags |= NS_STYLE_FONT_USE_FIXED;              }							else {								font->mFlags &= ~NS_STYLE_FONT_USE_FIXED;							}            }            else {              font->mFont.name = defaultFont.name;              font->mFixedFont.name = defaultFixedFont.name;            }            font->mFlags |= NS_STYLE_FONT_FACE_EXPLICIT;          }        }        else if (eCSSUnit_Enumerated == ourFont->mFamily.GetUnit()) {        	nsSystemAttrID sysID;          switch (ourFont->mFamily.GetIntValue()) {            case NS_STYLE_FONT_CAPTION:       sysID = eSystemAttr_Font_Caption;       break;    // css2            case NS_STYLE_FONT_ICON:          sysID = eSystemAttr_Font_Icon;          break;            case NS_STYLE_FONT_MENU:          sysID = eSystemAttr_Font_Menu;          break;            case NS_STYLE_FONT_MESSAGE_BOX:   sysID = eSystemAttr_Font_MessageBox;    break;            case NS_STYLE_FONT_SMALL_CAPTION: sysID = eSystemAttr_Font_SmallCaption;  break;            case NS_STYLE_FONT_STATUS_BAR:    sysID = eSystemAttr_Font_StatusBar;     break;            case NS_STYLE_FONT_WINDOW:        sysID = eSystemAttr_Font_Window;        break;    // css3            case NS_STYLE_FONT_DOCUMENT:      sysID = eSystemAttr_Font_Document;      break;            case NS_STYLE_FONT_WORKSPACE:     sysID = eSystemAttr_Font_Workspace;     break;            case NS_STYLE_FONT_DESKTOP:       sysID = eSystemAttr_Font_Desktop;       break;            case NS_STYLE_FONT_INFO:          sysID = eSystemAttr_Font_Info;          break;            case NS_STYLE_FONT_DIALOG:        sysID = eSystemAttr_Font_Dialog;        break;            case NS_STYLE_FONT_BUTTON:        sysID = eSystemAttr_Font_Button;        break;            case NS_STYLE_FONT_PULL_DOWN_MENU:sysID = eSystemAttr_Font_PullDownMenu;  break;            case NS_STYLE_FONT_LIST:          sysID = eSystemAttr_Font_List;          break;            case NS_STYLE_FONT_FIELD:         sysID = eSystemAttr_Font_Field;         break;          }          nsCompatibility mode;          aPresContext->GetCompatibilityMode(&mode);				  nsCOMPtr<nsIDeviceContext> dc;          aPresContext->GetDeviceContext(getter_AddRefs(dc));          if (dc) {          	SystemAttrStruct sysInfo;          	sysInfo.mFont = &font->mFont;          	if (NS_FAILED(dc->GetSystemAttribute(sysID, &sysInfo))) {              font->mFont.name = defaultFont.name;              font->mFixedFont.name = defaultFixedFont.name;          	}            font->mFlags |= NS_STYLE_FONT_FACE_EXPLICIT;          }          // NavQuirks uses sans-serif instead of whatever the native font is          if (eCompatibility_NavQuirks == mode) {            if (sysID == eSystemAttr_Font_Field) {              font->mFont.name.AssignWithConversion("monospace");            } else if (sysID == eSystemAttr_Font_Button ||                       sysID == eSystemAttr_Font_Caption) {              font->mFont.name.AssignWithConversion("sans-serif");            }          }        }        else if (eCSSUnit_Inherit == ourFont->mFamily.GetUnit()) {          font->mFont.name = parentFont->mFont.name;          font->mFixedFont.name = parentFont->mFixedFont.name;          font->mFlags &= ~(NS_STYLE_FONT_FACE_EXPLICIT | NS_STYLE_FONT_USE_FIXED);          font->mFlags |= (parentFont->mFlags & (NS_STYLE_FONT_FACE_EXPLICIT | NS_STYLE_FONT_USE_FIXED));        }        // font-style: enum, normal, inherit        if (eCSSUnit_Enumerated == ourFont->mStyle.GetUnit()) {          font->mFont.style = ourFont->mStyle.GetIntValue();          font->mFixedFont.style = ourFont->mStyle.GetIntValue();        }        else if (eCSSUnit_Normal == ourFont->mStyle.GetUnit()) {          font->mFont.style = NS_STYLE_FONT_STYLE_NORMAL;          font->mFixedFont.style = NS_STYLE_FONT_STYLE_NORMAL;        }        else if (eCSSUnit_Inherit == ourFont->mStyle.GetUnit()) {          font->mFont.style = parentFont->mFont.style;          font->mFixedFont.style = parentFont->mFixedFont.style;        }        // font-variant: enum, normal, inherit        if (eCSSUnit_Enumerated == ourFont->mVariant.GetUnit()) {          font->mFont.variant = ourFont->mVariant.GetIntValue();          font->mFixedFont.variant = ourFont->mVariant.GetIntValue();        }        else if (eCSSUnit_Normal == ourFont->mVariant.GetUnit()) {          font->mFont.variant = NS_STYLE_FONT_VARIANT_NORMAL;          font->mFixedFont.variant = NS_STYLE_FONT_VARIANT_NORMAL;        }        else if (eCSSUnit_Inherit == ourFont->mVariant.GetUnit()) {          font->mFont.variant = parentFont->mFont.variant;          font->mFixedFont.variant = parentFont->mFixedFont.variant;        }        // font-weight: int, enum, normal, inherit        if (eCSSUnit_Integer == ourFont->mWeight.GetUnit()) {          font->mFont.weight = ourFont->mWeight.GetIntValue();          font->mFixedFont.weight = ourFont->mWeight.GetIntValue();        }        else if (eCSSUnit_Enumerated == ourFont->mWeight.GetUnit()) {          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 = nsStyleUtil::ConstrainFontWeight(parentFont->mFont.weight + value);              font->mFixedFont.weight = nsStyleUtil::ConstrainFontWeight(parentFont->mFixedFont.weight + value);              break;          }        }        else if (eCSSUnit_Normal == ourFont->mWeight.GetUnit()) {          font->mFont.weight = NS_STYLE_FONT_WEIGHT_NORMAL;          font->mFixedFont.weight = NS_STYLE_FONT_WEIGHT_NORMAL;        }        else if (eCSSUnit_Inherit == ourFont->mWeight.GetUnit()) {          font->mFont.weight = parentFont->mFont.weight;          font->mFixedFont.weight = parentFont->mFixedFont.weight;        }        // font-size: enum, length, percent, inherit        if (eCSSUnit_Enumerated == ourFont->mSize.GetUnit()) {          PRInt32 value = ourFont->mSize.GetIntValue();          PRInt32 scaler;          aPresContext->GetFontScaler(&scaler);          float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);          if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&               (value <= NS_STYLE_FONT_SIZE_XXLARGE)) {            font->mFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);            font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS);          }          else if (NS_STYLE_FONT_SIZE_LARGER == value) {            PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);            font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);            font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS);          }          else if (NS_STYLE_FONT_SIZE_SMALLER == value) {            PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);            font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);            font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS);          }          // this does NOT explicitly set font size          font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT;        }        else if (ourFont->mSize.IsLengthUnit()) {          font->mFont.size = CalcLength(ourFont->mSize, parentFont->mFont, aPresContext);          font->mFixedFont.size = CalcLength(ourFont->mSize, parentFont->mFixedFont, aPresContext);          font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;        }        else if (eCSSUnit_Percent == ourFont->mSize.GetUnit()) {          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;        }        else if (eCSSUnit_Inherit == ourFont->mSize.GetUnit()) {          font->mFont.size = parentFont->mFont.size;          font->mFixedFont.size = parentFont->mFixedFont.size;          font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT;          font->mFlags |= (parentFont->mFlags & NS_STYLE_FONT_SIZE_EXPLICIT);        }      }    }    NS_IF_RELEASE(parentContext);  }}