if (eCompatibility_NavQuirks == mode) { aFont->mFont.name.Assign(NS_LITERAL_STRING("sans-serif")); }
SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,        nscoord aMinFontSize, PRBool aUseDocumentFonts, PRBool aChromeOverride,        PRBool aIsGeneric, const nsCSSFont& aFontData,        const nsFont& aDefaultFont, const nsStyleFont* aParentFont,        nsStyleFont* aFont, PRBool aZoom, PRBool& aInherited){  const nsFont* defaultVariableFont;  const nsFont* defaultFixedFont;  aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultVariableFont);  aPresContext->GetDefaultFont(kPresContext_DefaultFixedFont_ID, &defaultFixedFont);  // font-family: string list, enum, inherit  if (eCSSUnit_String == aFontData.mFamily.GetUnit()) {    // set the correct font if we are using DocumentFonts OR we are overriding for XUL    // MJA: bug 31816    if (aChromeOverride || aUseDocumentFonts) {      if (!aIsGeneric) {        // only bother appending fallback fonts if this isn't a fallback generic font itself        aFont->mFont.name.Append((PRUnichar)',');        aFont->mFont.name.Append(aDefaultFont.name);      }    }    else {      // now set to defaults      aFont->mFont.name = aDefaultFont.name;    }  }  else if (eCSSUnit_Enumerated == aFontData.mFamily.GetUnit()) {    nsSystemFontID sysID;    switch (aFontData.mFamily.GetIntValue()) {      // If you add fonts to this list, you need to also patch the list      // in CheckFontCallback (also in this file).      case NS_STYLE_FONT_CAPTION:       sysID = eSystemFont_Caption;      break;    // css2      case NS_STYLE_FONT_ICON:          sysID = eSystemFont_Icon;         break;      case NS_STYLE_FONT_MENU:          sysID = eSystemFont_Menu;         break;      case NS_STYLE_FONT_MESSAGE_BOX:   sysID = eSystemFont_MessageBox;   break;      case NS_STYLE_FONT_SMALL_CAPTION: sysID = eSystemFont_SmallCaption; break;      case NS_STYLE_FONT_STATUS_BAR:    sysID = eSystemFont_StatusBar;    break;      case NS_STYLE_FONT_WINDOW:        sysID = eSystemFont_Window;       break;    // css3      case NS_STYLE_FONT_DOCUMENT:      sysID = eSystemFont_Document;     break;      case NS_STYLE_FONT_WORKSPACE:     sysID = eSystemFont_Workspace;    break;      case NS_STYLE_FONT_DESKTOP:       sysID = eSystemFont_Desktop;      break;      case NS_STYLE_FONT_INFO:          sysID = eSystemFont_Info;         break;      case NS_STYLE_FONT_DIALOG:        sysID = eSystemFont_Dialog;       break;      case NS_STYLE_FONT_BUTTON:        sysID = eSystemFont_Button;       break;      case NS_STYLE_FONT_PULL_DOWN_MENU:sysID = eSystemFont_PullDownMenu; break;      case NS_STYLE_FONT_LIST:          sysID = eSystemFont_List;         break;      case NS_STYLE_FONT_FIELD:         sysID = eSystemFont_Field;        break;      case NS_STYLE_FONT_THEME:         sysID = eSystemFont_Theme;        break;    }    nsCompatibility mode = eCompatibility_Standard;    if (sysID == eSystemFont_Field ||        sysID == eSystemFont_List ||        sysID == eSystemFont_Button) {      nsCOMPtr<nsIPref> prefService(do_GetService(NS_PREF_CONTRACTID));      if (prefService) {        PRBool useEitherMode;        if (NS_SUCCEEDED(prefService->GetBoolPref("layout.forms.use_standard_or_quirks", &useEitherMode))) {          if (useEitherMode) {            aPresContext->GetCompatibilityMode(&mode);          }        }      }    }    nsCOMPtr<nsIDeviceContext> dc;    aPresContext->GetDeviceContext(getter_AddRefs(dc));    if (dc) {      // GetSystemFont sets the font face but not necessarily the size      aFont->mFont.size = defaultVariableFont->size;      if (NS_FAILED(dc->GetSystemFont(sysID, &aFont->mFont))) {        aFont->mFont.name = defaultVariableFont->name;      }      aFont->mSize = aFont->mFont.size; // this becomes our cascading size    }    // NavQuirks uses sans-serif instead of whatever the native font is#if defined(XP_MAC) || defined(XP_MACOSX)    if (eCompatibility_NavQuirks == mode) {      switch (sysID) {        case eSystemFont_Field:        case eSystemFont_List:          aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));          aFont->mSize = defaultFixedFont->size;          break;        case eSystemFont_Button:          aFont->mFont.name.Assign(NS_LITERAL_STRING("serif"));          aFont->mSize = defaultVariableFont->size;          break;      }    }#endif#if defined(XP_OS2)      switch (sysID) {        case eSystemFont_List:        case eSystemFont_Button:          aFont->mFont.name = defaultVariableFont->name;          break;        case eSystemFont_Field:          if (eCompatibility_NavQuirks == mode)             aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));          else             aFont->mFont.name = defaultVariableFont->name;          break;    }#endif#ifdef XP_WIN    //    // As far as I can tell the system default fonts and sizes for    // on MS-Windows for Buttons, Listboxes/Comboxes and Text Fields are     // all pre-determined and cannot be changed by either the control panel     // or programmtically.    //    switch (sysID) {      // Fields (text fields)      //      // For NavQuirks:      //   We always use the monospace font and whatever      //   the "fixed" font size this that is set by the browser      //      // For Standard/Strict Mode:      //    We use whatever font is defined by the system. Which it appears      //    (and the assumption is) it is always a proportional font. Then we      //    always use 2 points smaller than what the browser has defined as      //    the default proportional font.      case eSystemFont_Field:        if (eCompatibility_NavQuirks == mode) {          aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));          aFont->mSize = defaultFixedFont->size;        } else {          // Assumption: system defined font is proportional          aFont->mSize = PR_MAX(defaultVariableFont->size - NSIntPointsToTwips(2), 0);        }        break;      //      // Button and Selects (listboxes/comboboxes)      //      // For NavQuirks:      //   We always use the sans-serif font and 2 point point sizes smaller      //   that whatever the "proportional" font size this that is set by the browser      //      // For Standard/Strict Mode:      //    We use whatever font is defined by the system. Which it appears      //    (and the assumption is) it is always a proportional font. Then we      //    always use 2 points smaller than what the browser has defined as      //    the default proportional font.      case eSystemFont_Button:      case eSystemFont_List:        if (eCompatibility_NavQuirks == mode) {          aFont->mFont.name.Assign(NS_LITERAL_STRING("sans-serif"));        }        // Assumption: system defined font is proportional        aFont->mSize = PR_MAX(defaultVariableFont->size - NSIntPointsToTwips(2), 0);        break;    }#endif#if defined(XP_UNIX) && !defined(XP_MACOSX)    if (eCompatibility_NavQuirks == mode) {      switch (sysID) {        case eSystemFont_Field:          aFont->mFont.name.Assign(NS_LITERAL_STRING("monospace"));          aFont->mSize = defaultFixedFont->size;          break;        case eSystemFont_Button:        case eSystemFont_List:          aFont->mFont.name.Assign(NS_LITERAL_STRING("serif"));          aFont->mSize = defaultVariableFont->size;          break;        default:          NS_ERROR("unexpected SID");      }    }#endif  }  else if (eCSSUnit_Inherit == aFontData.mFamily.GetUnit()) {    aInherited = PR_TRUE;    aFont->mFont.name = aParentFont->mFont.name;  }  else if (eCSSUnit_Initial == aFontData.mFamily.GetUnit()) {    aFont->mFont.name = aDefaultFont.name;  }  // font-style: enum, normal, inherit  if (eCSSUnit_Enumerated == aFontData.mStyle.GetUnit()) {    aFont->mFont.style = aFontData.mStyle.GetIntValue();  }  else if (eCSSUnit_Normal == aFontData.mStyle.GetUnit()) {    aFont->mFont.style = NS_STYLE_FONT_STYLE_NORMAL;  }  else if (eCSSUnit_Inherit == aFontData.mStyle.GetUnit()) {    aInherited = PR_TRUE;    aFont->mFont.style = aParentFont->mFont.style;  }  else if (eCSSUnit_Initial == aFontData.mStyle.GetUnit()) {    aFont->mFont.style = aDefaultFont.style;  }  // font-variant: enum, normal, inherit  if (eCSSUnit_Enumerated == aFontData.mVariant.GetUnit()) {    aFont->mFont.variant = aFontData.mVariant.GetIntValue();  }  else if (eCSSUnit_Normal == aFontData.mVariant.GetUnit()) {    aFont->mFont.variant = NS_STYLE_FONT_VARIANT_NORMAL;  }  else if (eCSSUnit_Inherit == aFontData.mVariant.GetUnit()) {    aInherited = PR_TRUE;    aFont->mFont.variant = aParentFont->mFont.variant;  }  else if (eCSSUnit_Initial == aFontData.mVariant.GetUnit()) {    aFont->mFont.variant = aDefaultFont.variant;  }  // font-weight: int, enum, normal, inherit  if (eCSSUnit_Integer == aFontData.mWeight.GetUnit()) {    aFont->mFont.weight = aFontData.mWeight.GetIntValue();  }  else if (eCSSUnit_Enumerated == aFontData.mWeight.GetUnit()) {    PRInt32 value = aFontData.mWeight.GetIntValue();    switch (value) {      case NS_STYLE_FONT_WEIGHT_NORMAL:      case NS_STYLE_FONT_WEIGHT_BOLD:        aFont->mFont.weight = value;        break;      case NS_STYLE_FONT_WEIGHT_BOLDER:      case NS_STYLE_FONT_WEIGHT_LIGHTER:        aInherited = PR_TRUE;        aFont->mFont.weight = nsStyleUtil::ConstrainFontWeight(aParentFont->mFont.weight + value);        break;    }  }  else if (eCSSUnit_Normal == aFontData.mWeight.GetUnit()) {    aFont->mFont.weight = NS_STYLE_FONT_WEIGHT_NORMAL;  }  else if (eCSSUnit_Inherit == aFontData.mWeight.GetUnit()) {    aInherited = PR_TRUE;    aFont->mFont.weight = aParentFont->mFont.weight;  }  else if (eCSSUnit_Initial == aFontData.mWeight.GetUnit()) {    aFont->mFont.weight = aDefaultFont.weight;  }  // font-size: enum, length, percent, inherit  PRBool zoom = aZoom;  if (eCSSUnit_Enumerated == aFontData.mSize.GetUnit()) {    PRInt32 value = aFontData.mSize.GetIntValue();    PRInt32 scaler;    aPresContext->GetFontScaler(&scaler);    float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);    zoom = PR_TRUE;    if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&         (value <= NS_STYLE_FONT_SIZE_XXLARGE)) {      aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);    }    else if (NS_STYLE_FONT_SIZE_XXXLARGE == value) {      // <font size="7"> is not specified in CSS, so we don't use eFontSize_CSS.      aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext);    }    else if (NS_STYLE_FONT_SIZE_LARGER == value ||             NS_STYLE_FONT_SIZE_SMALLER == value) {      aInherited = PR_TRUE;      // Un-zoom so we use the tables correctly.  We'll then rezoom due      // to the |zoom = PR_TRUE| above.      nsCOMPtr<nsIDeviceContext> dc;      aPresContext->GetDeviceContext(getter_AddRefs(dc));      float textZoom;      dc->GetTextZoom(textZoom);      nscoord parentSize = nscoord(aParentFont->mSize / textZoom);      if (NS_STYLE_FONT_SIZE_LARGER == value) {        PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);        nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);        aFont->mSize = PR_MAX(largerSize, aParentFont->mSize);      } else {        PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);        nscoord smallerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);        aFont->mSize = PR_MIN(smallerSize, aParentFont->mSize);      }    } else {      NS_NOTREACHED("unexpected value");    }  }  else if (aFontData.mSize.IsLengthUnit()) {    aFont->mSize = CalcLength(aFontData.mSize, &aParentFont->mFont, nsnull, aPresContext, aInherited);    zoom = aFontData.mSize.IsFixedLengthUnit() ||           aFontData.mSize.GetUnit() == eCSSUnit_Pixel;  }  else if (eCSSUnit_Percent == aFontData.mSize.GetUnit()) {    aInherited = PR_TRUE;    aFont->mSize = (nscoord)((float)(aParentFont->mSize) * aFontData.mSize.GetPercentValue());    zoom = PR_FALSE;  }  else if (eCSSUnit_Inherit == aFontData.mSize.GetUnit()) {    aInherited = PR_TRUE;    aFont->mSize = aParentFont->mSize;    zoom = PR_FALSE;  }  else if (eCSSUnit_Initial == aFontData.mSize.GetUnit()) {    aFont->mSize = aDefaultFont.size;    zoom = PR_TRUE;  }  // We want to zoom the cascaded size so that em-based measurements,  // line-heights, etc., work.  if (zoom)    aFont->mSize = ZoomFont(aPresContext, aFont->mSize);  // enforce the user' specified minimum font-size on the value that we expose  if (aChromeOverride) {    // the chrome is unconstrained, it always uses our cascading size    aFont->mFont.size = aFont->mSize;  }  else {    aFont->mFont.size = PR_MAX(aFont->mSize, aMinFontSize);  }  // font-size-adjust: number, none, inherit  if (eCSSUnit_Number == aFontData.mSizeAdjust.GetUnit()) {    aFont->mFont.sizeAdjust = aFontData.mSizeAdjust.GetFloatValue();  }  else if (eCSSUnit_None == aFontData.mSizeAdjust.GetUnit()) {    aFont->mFont.sizeAdjust = 0.0f;  }  else if (eCSSUnit_Inherit == aFontData.mSizeAdjust.GetUnit()) {    aInherited = PR_TRUE;    aFont->mFont.sizeAdjust = aParentFont->mFont.sizeAdjust;  }  else if (eCSSUnit_Initial == aFontData.mSizeAdjust.GetUnit()) {    aFont->mFont.sizeAdjust = 0.0f;  }}