Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Types | Private Member Functions | Private Attributes
DrawSelectionIterator Class Reference
Collaboration diagram for DrawSelectionIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DrawSelectionIterator (nsIContent *aContent, const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextPaintStyle &aTextStyle, PRInt16 aSelectionStatus, nsPresContext *aPresContext, nsStyleContext *aStyleContext)
 ~DrawSelectionIterator ()
PRBool First ()
PRBool Next ()
PRBool IsDone ()
PRBool IsLast ()
PRUnicharCurrentTextUnicharPtr ()
char * CurrentTextCStrPtr ()
PRUint32 CurrentLength ()
nsTextFrame::TextPaintStyleCurrentStyle ()
PRBool IsBeforeOrAfter ()
PRBool GetSelectionColors (nscolor *aForeColor, nscolor *aBackColor, PRBool *aBackIsTransparent)
 Get foreground color, background color, whether the background is transparent, and whether the current range is the normal selection.

Private Types

enum  { SELECTION_TYPES_WE_CARE_ABOUT = nsISelectionController::SELECTION_NONE+nsISelectionController::SELECTION_NORMAL }

Private Member Functions

void FillCurrentData ()

Private Attributes

union {
PRUnicharmUniStr
char * mCStr
}; 
PRUint32 mLength
PRUint32 mCurrentIdx
PRUint32 mCurrentLength
nsTextFrame::TextPaintStylemOldStyle
const SelectionDetailsmDetails
PRBool mDone
PRUint8mTypes
PRBool mInit
PRInt16 mSelectionStatus
nscolor mFrameBackgroundColor
PRInt32 mSufficientContrast
nscolor mDisabledColor
nscolor mAttentionColor
PRBool mSelectionPseudoStyle
nscolor mSelectionPseudoFGcolor
nscolor mSelectionPseudoBGcolor
PRBool mSelectionPseudoBGIsTransparent

Detailed Description

Definition at line 1051 of file nsTextFrame.cpp.


Member Enumeration Documentation

anonymous enum [private]

Constructor & Destructor Documentation

DrawSelectionIterator::DrawSelectionIterator ( nsIContent aContent,
const SelectionDetails aSelDetails,
PRUnichar aText,
PRUint32  aTextLength,
nsTextFrame::TextPaintStyle aTextStyle,
PRInt16  aSelectionStatus,
nsPresContext aPresContext,
nsStyleContext aStyleContext 
)

Definition at line 1112 of file nsTextFrame.cpp.

                                             :mOldStyle(aTextStyle)
{
    mDetails = aSelDetails;
    mCurrentIdx = 0;
    mUniStr = aText;
    mLength = aTextLength;
    mTypes = nsnull;
    mInit = PR_FALSE;
    mSelectionStatus = aSelectionStatus;
    mSelectionPseudoStyle = PR_FALSE;
    mSelectionPseudoBGIsTransparent = PR_FALSE;

    const nsStyleBackground* bg =
      nsCSSRendering::FindNonTransparentBackground(aStyleContext);
    NS_ASSERTION(bg, "Cannot find NonTransparentBackground.");
    mFrameBackgroundColor = bg->mBackgroundColor;

    if (aContent) {
      nsRefPtr<nsStyleContext> sc;
      sc = aPresContext->StyleSet()->
        ProbePseudoStyleFor(aContent->GetParent(),
                            nsCSSPseudoElements::mozSelection, aStyleContext);
      if (sc) {
        mSelectionPseudoStyle = PR_TRUE;
        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();
    nscolor defaultWindowBackgroundColor;
    look->GetColor(nsILookAndFeel::eColor_WindowBackground,
                   defaultWindowBackgroundColor);
    look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention,
                   mAttentionColor);
    look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled,
                   mDisabledColor);
    mDisabledColor  = EnsureDifferentColors(mDisabledColor,
                                            mOldStyle.mSelectionBGColor);
    mAttentionColor = EnsureDifferentColors(mAttentionColor,
                                            mOldStyle.mSelectionBGColor);

    mSufficientContrast =
      PR_MIN(PR_MIN(NS_SUFFICIENT_LUMINOSITY_DIFFERENCE,
                    NS_LUMINOSITY_DIFFERENCE(mOldStyle.mSelectionTextColor,
                                             mOldStyle.mSelectionBGColor)),
                    NS_LUMINOSITY_DIFFERENCE(defaultWindowBackgroundColor,
                                             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;
}

Here is the call graph for this function:

Definition at line 1228 of file nsTextFrame.cpp.

{
  if (mTypes)
    delete [] mTypes;
}

Member Function Documentation

Definition at line 1327 of file nsTextFrame.cpp.

{
  return mCurrentLength;
}

Here is the caller graph for this function:

Definition at line 1333 of file nsTextFrame.cpp.

{
  return mOldStyle;
}

Definition at line 1321 of file nsTextFrame.cpp.

{
  return mCStr+mCurrentIdx;
}

Here is the caller graph for this function:

Definition at line 1315 of file nsTextFrame.cpp.

{
  return mUniStr+mCurrentIdx;
}

Here is the caller graph for this function:

Definition at line 1235 of file nsTextFrame.cpp.

{
  if (mDone)
    return;
  mCurrentIdx += mCurrentLength; // advance to this chunk
  mCurrentLength = 0;
  if (mCurrentIdx >= mLength)
  {
    mDone = PR_TRUE;
    return;
  }
  if (!mTypes)
  {
    if (mCurrentIdx < (PRUint32)mDetails->mStart)
    {
      mCurrentLength = mDetails->mStart;
    }
    else if (mCurrentIdx == (PRUint32)mDetails->mStart)
    {//start
        mCurrentLength = mDetails->mEnd-mCurrentIdx;
    }
    else if (mCurrentIdx > (PRUint32)mDetails->mStart)//last unselected part
    {
      mCurrentLength = mLength - mDetails->mEnd;
    }
  }
  else
  {
    uint8 typevalue = mTypes[mCurrentIdx];
    while (mCurrentIdx+mCurrentLength < mLength && typevalue == mTypes[mCurrentIdx+mCurrentLength])
    {
      mCurrentLength++;
    }
  }
  // never overrun past mLength
  if (mCurrentIdx+mCurrentLength > mLength)
  {
    mCurrentLength = mLength - mCurrentIdx;
  }
}

Here is the caller graph for this function:

Definition at line 1277 of file nsTextFrame.cpp.

{
  if (!mInit)
    return PR_FALSE;
  mCurrentIdx = 0;
  mCurrentLength = 0;
  if (!mTypes && mDetails->mStart == mDetails->mEnd)//no collapsed selections here!
    mDone = PR_TRUE;
  mDone = (mCurrentIdx+mCurrentLength) >= mLength;
  FillCurrentData();
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool DrawSelectionIterator::GetSelectionColors ( nscolor aForeColor,
nscolor aBackColor,
PRBool aBackIsTransparent 
)

Get foreground color, background color, whether the background is transparent, and whether the current range is the normal selection.

Parameters:
aForeColor[out] returns the foreground color of the current range.
aBackColor[out] returns the background color of the current range. Note that this value is undefined if aBackIsTransparent is true or if
Returns:
is false.
Parameters:
aBackIsTransparent[out] returns whether the background is transparent. If true, the background is transparent. Otherwise, it isn't so.
Returns:
whether the current range is a normal selection.

Definition at line 1339 of file nsTextFrame.cpp.

{
  *aBackIsTransparent = PR_FALSE;
  PRBool isSelection =
    (mTypes && (mTypes[mCurrentIdx] & nsISelectionController::SELECTION_NORMAL)) ||
    (!mTypes && mCurrentIdx == (PRUint32)mDetails->mStart);
  if (!isSelection) {
    *aForeColor = mOldStyle.mColor->mColor;
    return PR_FALSE;
  }

  if (mSelectionPseudoStyle &&
      mSelectionStatus == nsISelectionController::SELECTION_ON) {
    *aForeColor = mSelectionPseudoFGcolor;
    *aBackColor = mSelectionPseudoBGcolor;
    *aBackIsTransparent = mSelectionPseudoBGIsTransparent;
    return PR_TRUE;
  }

  PRBool dontChangeTextColor =
           mOldStyle.mSelectionTextColor == NS_DONT_CHANGE_COLOR;

  if (dontChangeTextColor)
    *aForeColor = mOldStyle.mColor->mColor;
  else
    *aForeColor = mOldStyle.mSelectionTextColor;

  if (mSelectionStatus == nsISelectionController::SELECTION_ATTENTION)
    *aBackColor = mAttentionColor;
  else if (mSelectionStatus != nsISelectionController::SELECTION_ON)
    *aBackColor = mDisabledColor;
  else
    *aBackColor = mOldStyle.mSelectionBGColor;

  // We don't support selection color exchanging when selection text color is
  // NS_DONT_CHANGE_COLOR. Because the text color should not be background color.
  if (dontChangeTextColor) {
    *aForeColor = EnsureDifferentColors(*aForeColor, *aBackColor);
    return PR_TRUE;
  }

  // If the combination of selection background color and frame background color
  // is sufficient contrast, don't exchange the selection colors.
  PRInt32 backLuminosityDifference =
            NS_LUMINOSITY_DIFFERENCE(*aBackColor, mFrameBackgroundColor);
  if (backLuminosityDifference >= mSufficientContrast)
    return PR_TRUE;

  // Otherwise, we should use the higher-contrast color for the selection
  // background color.
  PRInt32 foreLuminosityDifference =
            NS_LUMINOSITY_DIFFERENCE(*aForeColor, mFrameBackgroundColor);
  if (backLuminosityDifference < foreLuminosityDifference) {
    nscolor tmpColor = *aForeColor;
    *aForeColor = *aBackColor;
    *aBackColor = tmpColor;
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1402 of file nsTextFrame.cpp.

Here is the caller graph for this function:

Definition at line 1308 of file nsTextFrame.cpp.

{
    return mDone || !mInit;
}

Here is the caller graph for this function:

Definition at line 1302 of file nsTextFrame.cpp.

{
 return mDone || !mInit || mCurrentIdx + mCurrentLength >= mLength;
}

Here is the caller graph for this function:

Definition at line 1293 of file nsTextFrame.cpp.

{
  if (mDone || !mInit)
    return PR_FALSE;
  FillCurrentData();//advances to next chunk
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

union { ... } [private]

Definition at line 1102 of file nsTextFrame.cpp.

Definition at line 1091 of file nsTextFrame.cpp.

Definition at line 1092 of file nsTextFrame.cpp.

Definition at line 1094 of file nsTextFrame.cpp.

Definition at line 1101 of file nsTextFrame.cpp.

Definition at line 1095 of file nsTextFrame.cpp.

Definition at line 1099 of file nsTextFrame.cpp.

Definition at line 1097 of file nsTextFrame.cpp.

Definition at line 1090 of file nsTextFrame.cpp.

Definition at line 1093 of file nsTextFrame.cpp.

Definition at line 1106 of file nsTextFrame.cpp.

Definition at line 1107 of file nsTextFrame.cpp.

Definition at line 1105 of file nsTextFrame.cpp.

Definition at line 1104 of file nsTextFrame.cpp.

Definition at line 1098 of file nsTextFrame.cpp.

Definition at line 1100 of file nsTextFrame.cpp.

Definition at line 1096 of file nsTextFrame.cpp.


The documentation for this class was generated from the following file: