nsCompatibility mode; aPresContext->GetCompatibilityMode(&mode); if (eCompatibility_NavQuirks == mode) {
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode()) {
nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext,                                  nsStyleContext* aStyleContext,                                  nsIPresContext* aPresContext,                                  TextStyle& aTextStyle,                                  nscoord aX, nscoord aY, nscoord aWidth,                                  PRUnichar *aText, /*=nsnull*/                                  SelectionDetails *aDetails,/*= nsnull*/                                  PRUint32 aIndex,  /*= 0*/                                  PRUint32 aLength, /*= 0*/                                  const nscoord* aSpacing /* = nsnull*/ ){  // Quirks mode text  decoration are rendered by children; see bug 1777  // In non-quirks mode, nsHTMLContainer::Paint and nsBlockFrame::Paint  // does the painting of text decorations.  nsCompatibility mode;  aPresContext->GetCompatibilityMode(&mode);  if (eCompatibility_NavQuirks == mode) {    nscolor overColor, underColor, strikeColor;      PRBool useOverride = PR_FALSE;    nscolor overrideColor;    PRUint8 decorations = NS_STYLE_TEXT_DECORATION_NONE;    // A mask of all possible decorations.    PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_UNDERLINE |                         NS_STYLE_TEXT_DECORATION_OVERLINE |                        NS_STYLE_TEXT_DECORATION_LINE_THROUGH;        nsStyleContext* context = aStyleContext;    PRBool hasDecorations = context->HasTextDecorations();    while (hasDecorations) {      const nsStyleTextReset* styleText = context->GetStyleTextReset();      if (!useOverride &&           (NS_STYLE_TEXT_DECORATION_OVERRIDE_ALL &            styleText->mTextDecoration)) {        // This handles the <a href="blah.html"><font color="green">La         // la la</font></a> case. The link underline should be green.        useOverride = PR_TRUE;        overrideColor = context->GetStyleColor()->mColor;                }      PRUint8 useDecorations = decorMask & styleText->mTextDecoration;      if (useDecorations) {// a decoration defined here        nscolor color = context->GetStyleColor()->mColor;            if (NS_STYLE_TEXT_DECORATION_UNDERLINE & useDecorations) {          underColor = useOverride ? overrideColor : color;          decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE;          decorations |= NS_STYLE_TEXT_DECORATION_UNDERLINE;        }        if (NS_STYLE_TEXT_DECORATION_OVERLINE & useDecorations) {          overColor = useOverride ? overrideColor : color;          decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE;          decorations |= NS_STYLE_TEXT_DECORATION_OVERLINE;        }        if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & useDecorations) {          strikeColor = useOverride ? overrideColor : color;          decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH;          decorations |= NS_STYLE_TEXT_DECORATION_LINE_THROUGH;        }      }      if (0 == decorMask)        break;      context = context->GetParent();      if (!context)        break;      hasDecorations = context->HasTextDecorations();    }    nscoord offset;    nscoord size;    nscoord baseline = mAscent;    if (decorations & (NS_FONT_DECORATION_OVERLINE |                       NS_FONT_DECORATION_UNDERLINE)) {      aTextStyle.mNormalFont->GetUnderline(offset, size);      if (decorations & NS_FONT_DECORATION_OVERLINE) {        aRenderingContext.SetColor(overColor);        aRenderingContext.FillRect(aX, aY, aWidth, size);      }      if (decorations & NS_FONT_DECORATION_UNDERLINE) {        aRenderingContext.SetColor(underColor);        aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);      }    }    if (decorations & NS_FONT_DECORATION_LINE_THROUGH) {      aTextStyle.mNormalFont->GetStrikeout(offset, size);      aRenderingContext.SetColor(strikeColor);      aRenderingContext.FillRect(aX, aY + baseline - offset, aWidth, size);    }  }  if (aDetails){    nsRect rect = GetRect();    while(aDetails){      const nscoord* sp= aSpacing;      PRInt32 startOffset = 0;      PRInt32 textWidth = 0;      PRInt32 start = PR_MAX(0,(aDetails->mStart - (PRInt32)aIndex));      PRInt32 end = PR_MIN((PRInt32)aLength,(aDetails->mEnd - (PRInt32)aIndex));      PRInt32 i;      if ((start < end) && ((aLength - start) > 0))      {        //aDetails allready processed to have offsets from frame start not content offsets        if (start < end){          if (aLength == 1)            textWidth = aWidth;          else {            if (aDetails->mStart > 0){              if (sp)              {                for (i = 0; i < start;i ++){                  startOffset += *sp ++;                }              }              else                aRenderingContext.GetWidth(aText, start, startOffset);            }            if (sp){              for (i = start; i < end;i ++){                textWidth += *sp ++;              }            }            else              aRenderingContext.GetWidth(aText + start,                                           PRUint32(end - start), textWidth);            }          nscoord offset, size;          nscoord baseline = mAscent;          switch (aDetails->mType)          {          case nsISelectionController::SELECTION_NORMAL:#if 0            {            //using new selectionpainting now//// XOR InvertRect is currently implemented only in the unix and windows// rendering contexts.  When other platforms implement InvertRect(), they// can be added here.  Eventually this #ifdef should die.//// For platforms that dont implement InvertRect(), the selection will be // a non-filled rectangle.#ifdef USE_INVERT_FOR_SELECTION              aRenderingContext.SetColor(NS_RGB(255,255,255));              aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);#else              aRenderingContext.SetColor(NS_RGB(0,0,0));              aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);#endif            }#endif //0                                break;           case nsISelectionController::SELECTION_SPELLCHECK:{              aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(NS_RGB(255,0,0));              aRenderingContext.FillRect(aX + startOffset, aY + baseline - offset, textWidth, size);                                }break;          case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT:{#ifdef USE_INVERT_FOR_SELECTION              aRenderingContext.SetColor(NS_RGB(255,255,255));              aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);#else              aRenderingContext.SetColor(NS_RGB(255,255,128));              aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);#endif                      aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(IME_RAW_COLOR);              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size);                                }break;          case nsISelectionController::SELECTION_IME_RAWINPUT:{              aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(IME_RAW_COLOR);              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size);                                }break;          case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT:{#ifdef USE_INVERT_FOR_SELECTION              aRenderingContext.SetColor(NS_RGB(255,255,255));              aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);#else              aRenderingContext.SetColor(NS_RGB(255,255,128));              aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);#endif        			  aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(IME_CONVERTED_COLOR);              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size);                                }break;          case nsISelectionController::SELECTION_IME_CONVERTEDTEXT:{              aTextStyle.mNormalFont->GetUnderline(offset, size);              aRenderingContext.SetColor(IME_CONVERTED_COLOR);              aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size);                                }break;          default:            NS_ASSERTION(0,"what type of selection do i not know about?");            break;          }        }      }      aDetails = aDetails->mNext;    }  }}