return; PRBool done = PR_FALSE; #if 1 printf("select frames"); if (!aSelect) printf("deselect \n"); else printf("select \n"); #endif while (!done) { if (aBegin == aEnd) { aBegin->SetSelected(aSelect, aBeginOffset, aEndOffset, PR_TRUE); done = PR_TRUE; } else {  aBegin->SetSelected(aSelect, aBeginOffset, -1, PR_TRUE); aBeginOffset = -1; if (NS_FAILED(aBegin->GetNextSibling(aBegin)) || !aBegin) { done = PR_TRUE; }
return 0; nsCOMPtr<nsIContent> beginContent; if (NS_SUCCEEDED(aBegin->GetContent(*getter_AddRefs(beginContent)))){ nsCOMPtr<nsIDOMNode>beginNode (beginContent); nsCOMPtr<nsIContent> endContent; if (NS_SUCCEEDED(aEnd->GetContent(*getter_AddRefs(endContent)))){ nsCOMPtr<nsIDOMNode>endNode (endContent); PRBool storage; PRInt32 int1; PRInt32 int2; PRInt32 contentOffset1; PRInt32 contentOffset2; aBegin->GetSelected(&storage,&int1,&int2,&contentOffset1); aEnd->GetSelected(&storage,&int1,&int2,&contentOffset2); return ComparePoints(beginNode, contentOffset1, endNode, contentOffset2);
compareFrames(nsIFrame *aBegin, nsIFrame *aEnd){  if (frame && NS_SUCCEEDED(frame->GetContent(*getter_AddRefs(beginContent)))){    nsCOMPtr<nsIDOMNode>oldDomNode = oldContent;}//the idea of this helper method is to select, deselect "top to bootom" traversing through the framesvoidselectFrames(nsIFrame *aBegin, PRInt32 aBeginOffset, nsIFrame *aEnd, PRInt32 aEndOffset, PRBool aSelect){  if (!aBegin || !aEnd)    return;  PRBool done = PR_FALSE;#if 1  printf("select frames");  if (!aSelect)    printf("deselect \n");  else    printf("select \n");#endif  while (!done)  {    if (aBegin == aEnd)    {      aBegin->SetSelected(aSelect, aBeginOffset, aEndOffset, PR_TRUE);      done = PR_TRUE;    }    else {      //else we neeed to select from begin to end       aBegin->SetSelected(aSelect, aBeginOffset, -1, PR_TRUE);      aBeginOffset = -1;      if (NS_FAILED(aBegin->GetNextSibling(aBegin)) || !aBegin)      {        done = PR_TRUE;      }    }  }}/**hard to go from nodes to frames, easy the other way! */nsresultnsRangeList::TakeFocus(nsIFocusTracker *aTracker, nsIFrame *aFrame, PRInt32 aOffset, PRInt32 aContentOffset, PRBool aContinueSelection){  if (!aTracker || !aFrame)    return NS_ERROR_NULL_POINTER;  nsIFrame *frame;  nsIFrame *anchor;  nsCOMPtr<nsIContent> content;  nsCOMPtr<nsIDOMNode> domNode;  if (NS_SUCCEEDED(aFrame->GetContent(*getter_AddRefs(content)))){    domNode = (nsIContent *)content;    if (domNode && NS_SUCCEEDED(aTracker->GetFocus(&frame, &anchor))){      //traverse through document and unselect crap here      if (!aContinueSelection){        if (anchor && frame && anchor != frame && aFrame != frame)//selected across frames, must "deselect" frames between in correct order        {          PRInt32 compareResult = compareFrames(anchor,frame);          if ( compareResult < 0 )            selectFrames(anchor,0,frame,-1,PR_FALSE); //unselect all between          else if (compareResult > 0 )            selectFrames(frame,0,anchor,-1,PR_FALSE); //unselect all between//          else real bad put in assert here        }//DEBUG CRAP#if 1        nsCOMPtr<nsIContent>oldContent;        if (frame && NS_SUCCEEDED(frame->GetContent(*getter_AddRefs(oldContent)))){          nsCOMPtr<nsIDOMNode>oldDomNode = oldContent;          if (oldDomNode  && oldDomNode == mFocusNode) {            PRInt32 result1 = ComparePoints(domNode, aOffset + aContentOffset, mFocusNode, mFocusOffset);            printf("result1 = %i\n",result1);          }        }#endif                        aFrame->SetSelected(PR_TRUE,aOffset,aOffset,PR_FALSE);        aTracker->SetFocus(aFrame,aFrame);        nsCOMPtr<nsIDOMRange> range;        if (NS_SUCCEEDED(nsRepository::CreateInstance(kRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange          if (domNode) {//get the node interface for the range object            mFocusNode = domNode;            mFocusOffset = aOffset + aContentOffset;            mAnchorNode = domNode;            mAnchorOffset = aOffset + aContentOffset;            range->SetStart(domNode,aOffset + aContentOffset);            range->SetEnd(domNode,aOffset + aContentOffset);            nsCOMPtr<nsISupports> rangeISupports;            rangeISupports = range;            if (rangeISupports) {              AddItem(rangeISupports);            }          }        }      }      else {        if (aFrame == frame){ //drag to same frame          PRInt32 beginoffset;          PRInt32 begincontentoffset;          PRInt32 endoffset;          PRBool selected;          if (NS_SUCCEEDED(aFrame->GetSelected(&selected,&beginoffset,&endoffset, &begincontentoffset))){            aFrame->SetSelected(PR_TRUE,beginoffset,aOffset,PR_FALSE);            aTracker->SetFocus(aFrame,anchor);          }              nsCOMPtr<nsIContent>anchorContent;            if (anchor && NS_SUCCEEDED(anchor->GetContent(*getter_AddRefs(anchorContent)))){              nsCOMPtr<nsIDOMNode>anchorDomNode;              if ((anchorDomNode = anchorContent) && anchorDomNode == mAnchorNode) {                nsCOMPtr<nsIDOMRange> range;                if (NS_SUCCEEDED(nsRepository::CreateInstance(kRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange                  if (domNode){                    mFocusNode = domNode;                    mFocusOffset = aOffset + aContentOffset;                    range->SetStart(anchorDomNode,mAnchorOffset);                    range->SetEnd(domNode,aOffset + aContentOffset);                    nsCOMPtr<nsISupports> rangeISupports;                    if (rangeISupports = range) {                      AddItem(rangeISupports);                      return NS_OK;                    }                  }                }              }            }          }        }        else if (frame){ //we need to check to see what the order is.          nsCOMPtr<nsIContent>oldContent;          if (NS_SUCCEEDED(frame->GetContent(*getter_AddRefs(oldContent)))){            nsCOMPtr<nsIDOMNode>oldDomNode;            if ((oldDomNode =  oldContent) && oldDomNode == mFocusNode) {              nsCOMPtr<nsIContent>anchorContent;              if (NS_SUCCEEDED(anchor->GetContent(*getter_AddRefs(anchorContent)))){                nsCOMPtr<nsIDOMNode>anchorDomNode;                if ((anchorDomNode = anchorContent) && anchorDomNode == mAnchorNode) {                  //get offsets                  PRBool selected = PR_FALSE;                  PRInt32 anchorFrameOffsetBegin = 0;                  PRInt32 anchorFrameOffsetEnd = 0;                  PRInt32 anchorFrameContentOffset = 0;                  if (NS_FAILED(anchor->GetSelected(&selected, &anchorFrameOffsetBegin, &anchorFrameOffsetEnd, &anchorFrameContentOffset)) || !selected)                    return NS_ERROR_FAILURE;                  selected = PR_FALSE;                  PRInt32 focusFrameOffsetBegin = 0;                  PRInt32 focusFrameOffsetEnd = 0;                  PRInt32 focusFrameContentOffset = 0;                  if (NS_FAILED(frame->GetSelected(&selected, &focusFrameOffsetBegin, &focusFrameOffsetEnd, &focusFrameContentOffset)) || !selected)                    return NS_ERROR_FAILURE;                  //compare anchor to old cursor.                  PRInt32 result1 = ComparePoints(mAnchorNode, mAnchorOffset, mFocusNode, mFocusOffset);                  printf("result1 = %i\n",result1);                  //compare old cursor to new cursor                  PRInt32 result2 = ComparePoints(mFocusNode, mFocusOffset, domNode, aOffset + aContentOffset);                  printf("result2 = %i\n",result2);                  //compare anchor to new cursor                  PRInt32 result3 = ComparePoints(mAnchorNode, mAnchorOffset ,domNode , aOffset + aContentOffset);                  printf("result3 = %i\n",result3);                  //heuristic babble                  if (result1 <= 0 && result2 <= 0) {//a,1,2 or a1,2 or a,12 or a12                    //continue selection from 1 to 2                    printf("continue selection from OLD FOCUS point to NEW FOCUS (growth)\n");                    selectFrames(frame,focusFrameOffsetEnd, aFrame, aOffset, PR_TRUE);                  }                  else if (result3 <= 0 && result2 >= 0) {//a,2,1 or a2,1 or a,21 or a21                    //deselect from 2 to 1                    printf("deselect from NEW FOCUS point to OLD FOCUS ( shrinkage) \n");                    selectFrames(aFrame, aOffset, frame,focusFrameOffsetEnd, PR_FALSE);                  }                  else if (result1 >= 0 && result3 <= 0) {//1,a,2 or 1a,2 or 1,a2 or 1a2                    //deselect from 1 to a                    printf("deselect from OLD FOCUS to ANCHOR\n");                    selectFrames(frame, focusFrameOffsetEnd, anchor, anchorFrameOffsetBegin, PR_FALSE);                    //select from a to 2                    printf("select from ANCHOR to NEW FOCUS point \n");                    selectFrames(anchor, anchorFrameOffsetBegin, aFrame, aOffset, PR_TRUE);                  }                  else if (result2 <= 0 && result3 >= 0) {//1,2,a or 12,a or 1,2a or 12a                    //deselect from 1 to 2                    printf("deselect from OLD FOCUS to NEW FOCUS (shrinkage)\n");                    selectFrames(frame, focusFrameOffsetEnd, aFrame, aOffset, PR_FALSE);                  }                  else if (result3 >= 0 && result1 <= 0) {//2,a,1 or 2a,1 or 2,a1 or 2a1                    //deselect from a to 1                    printf("deselect from ANCHOR to OLD FOCUS \n");                    selectFrames(anchor, anchorFrameOffsetBegin, frame, focusFrameOffsetEnd, PR_FALSE);                    //select from 2 to a                    printf("select from NEW FOCUS to ANCHOR \n");                    selectFrames(aFrame, aOffset, anchor, anchorFrameOffsetBegin, PR_TRUE);                  }                  else if (result2 <= 0 && result1 >= 0) {//2,1,a or 21,a or 2,1a or 21a                    //continue selection from 2 to 1                    printf("select from NEW FOCUS to OLD FOCUS (growth)\n");                    selectFrames(aFrame, aOffset, frame,focusFrameOffsetEnd, PR_TRUE);                  }                  mFocusNode = domNode;                  mFocusOffset = aOffset + aContentOffset;                  aTracker->SetFocus(aFrame,anchor);                }              }            }          }        }/*#1 figure out the orderwe can tell the direction of the selection by asking for the anchors selectionif the begin is less than the end then we know the selection is to the "right".else it is a backwards selection.a = anchor1 = old cursor2 = new cursor  if (a <= 1 && 1 <=2)    a,1,2  or (a1,2)  if (a < 2 && 1 > 2)     a,2,1  if (1 < a && a <2)      1,a,2  if (a > 2 && 2 >1)      1,2,a  if (2 < a && a <1)      2,a,1  if (a > 1 && 1 >2)      2,1,athen executea  1  2 select from 1 to 2a  2  1 deselect from 2 to 11  a  2 deselect from 1 to a select from a to 21  2  a deselect from 1 to 22  1  a = continue selection from 2 to 1      */      }    }  }  return NS_OK;}