const nsStyleBackground* bg = sc->GetStyleBackground();
bg = sc->GetStyleBackground();
DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent,                                             const SelectionDetails *aSelDetails,                                              PRUnichar *aText,                                              PRUint32 aTextLength,                                              nsTextFrame::TextPaintStyle &aTextStyle,                                              PRInt16 aSelectionStatus,                                              nsPresContext *aPresContext,                                             nsStyleContext *aStyleContext)                                             :mOldStyle(aTextStyle){    mDetails = aSelDetails;    mCurrentIdx = 0;    mUniStr = aText;    mLength = aTextLength;    mTypes = nsnull;    mInit = PR_FALSE;    mSelectionStatus = aSelectionStatus;    mSelectionPseudoStyle = PR_FALSE;    mSelectionPseudoBGIsTransparent = PR_FALSE;    if (aContent) {      nsRefPtr<nsStyleContext> sc;      sc = aPresContext->StyleSet()->        ProbePseudoStyleFor(aContent->GetParent(),                            nsCSSPseudoElements::mozSelection, aStyleContext);      if (sc) {        mSelectionPseudoStyle = PR_TRUE;        const nsStyleBackground* bg = sc->GetStyleBackground();        mSelectionPseudoBGIsTransparent = PRBool(bg->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT);        if (!mSelectionPseudoBGIsTransparent )          mSelectionPseudoBGcolor = bg->mBackgroundColor;        mSelectionPseudoFGcolor = sc->GetStyleColor()->mColor;      }    }    // Get background colors for disabled selection at attention-getting selection (used with type ahead find)    nsILookAndFeel *look = aPresContext->LookAndFeel();    look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention,                   mAttentionColor);    look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled,                   mDisabledColor);    mDisabledColor  = EnsureDifferentColors(mDisabledColor,                                            mOldStyle.mSelectionBGColor);    mAttentionColor = EnsureDifferentColors(mAttentionColor,                                            mOldStyle.mSelectionBGColor);    if (!aSelDetails)    {      mDone = PR_TRUE;      return;    }    mDone = (PRBool)(mCurrentIdx>=mLength);    if (mDone)      return;    //special case for 1 selection. later    const SelectionDetails *details = aSelDetails;    if (details->mNext)    {      mTypes = new PRUint8[mLength];      if (!mTypes)        return;      memset(mTypes,0,mLength);//initialize to 0      while (details)      {        if ((details->mType & SELECTION_TYPES_WE_CARE_ABOUT ) &&           (details->mStart != details->mEnd))        {          mInit = PR_TRUE;//WE FOUND SOMETHING WE CARE ABOUT          for (int i = details->mStart; i < details->mEnd; i++)          {              if ((PRUint32)i>=mLength)              {                NS_ASSERTION(0,"Selection Details out of range?");                return;//eh              }              mTypes[i]|=details->mType;//add this bit          }        }        details= details->mNext;      }      if (!mInit && mTypes) //we have details but none that we care about.      {        delete [] mTypes;        mTypes = nsnull;        mDone = PR_TRUE;//we are finished      }    }    else if (details->mStart == details->mEnd)//no collapsed selections here!    {      mDone = PR_TRUE;      return;    }    else if (!(details->mType & SELECTION_TYPES_WE_CARE_ABOUT ))//if all we have is selection we DONT care about, do nothing    {        mDone = PR_TRUE;        return;    }    mInit = PR_TRUE;}