Back to index

lightning-sunbird  0.9+nobinonly
nsTextFrame.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


PRBool BinarySearchForPosition (nsIRenderingContext *acx, const PRUnichar *aText, PRInt32 aBaseWidth, PRInt32 aBaseInx, PRInt32 aStartInx, PRInt32 aEndInx, PRInt32 aCursorPos, PRInt32 &aIndex, PRInt32 &aTextWidth)

Function Documentation

PRBool BinarySearchForPosition ( nsIRenderingContext acx,
const PRUnichar aText,
PRInt32  aBaseWidth,
PRInt32  aBaseInx,
PRInt32  aStartInx,
PRInt32  aEndInx,
PRInt32  aCursorPos,
PRInt32 aIndex,
PRInt32 aTextWidth 

Definition at line 3814 of file nsTextFrame.cpp.

  PRInt32 range = aEndInx - aStartInx;
  if ((range == 1) || (range == 2 && IS_HIGH_SURROGATE(aText[aStartInx]))) {
    aIndex   = aStartInx + aBaseInx;
    aRendContext->GetWidth(aText, aIndex, aTextWidth);
    return PR_TRUE;

  PRInt32 inx = aStartInx + (range / 2);

  // Make sure we don't leave a dangling low surrogate
  if (IS_HIGH_SURROGATE(aText[inx-1]))

  PRInt32 textWidth = 0;
  aRendContext->GetWidth(aText, inx, textWidth);

  PRInt32 fullWidth = aBaseWidth + textWidth;
  if (fullWidth == aCursorPos) {
    aTextWidth = textWidth;
    aIndex = inx;
    return PR_TRUE;
  } else if (aCursorPos < fullWidth) {
    aTextWidth = aBaseWidth;
    if (BinarySearchForPosition(aRendContext, aText, aBaseWidth, aBaseInx, aStartInx, inx, aCursorPos, aIndex, aTextWidth)) {
      return PR_TRUE;
  } else {
    aTextWidth = fullWidth;
    if (BinarySearchForPosition(aRendContext, aText, aBaseWidth, aBaseInx, inx, aEndInx, aCursorPos, aIndex, aTextWidth)) {
      return PR_TRUE;
  return PR_FALSE;

Here is the call graph for this function:

Here is the caller graph for this function: