nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(node); if (bodyElement) { nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(bodyElement); if (bodyContent) { nsIFrame *frame = nsnull; result = GetPrimaryFrameFor(bodyContent, &frame); if (frame) { PRInt8  outsideLimit = -1; nsPeekOffsetStruct pos; pos.mAmount = eSelectLine; pos.mTracker = this; pos.mContentOffset = 0; pos.mContentOffsetEnd = 0; pos.mScrollViewStop = PR_FALSE; if (aForward) { outsideLimit = 1; nsRect rect; frame->GetRect(rect); pos.mDesiredX = rect.width * 2; pos.mDirection = eDirPrevious; } else { pos.mDesiredX = -1; pos.mDirection = eDirNext; }  do { result = nsFrame::GetNextPrevLineFromeBlockFrame(mPresContext, &pos, frame, 0, outsideLimit ); if (NS_COMFALSE == result) break; if (NS_OK != result || !pos.mResultFrame ) return result?result:NS_ERROR_FAILURE; nsCOMPtr<nsILineIteratorNavigator> newIt;  result = pos.mResultFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(newIt)); if (NS_SUCCEEDED(result) && newIt) frame = pos.mResultFrame; } while (NS_SUCCEEDED(result));  result = mSelection->HandleClick(pos.mResultContent ,pos.mContentOffset ,pos.mContentOffsetEnd ,aExtend, PR_FALSE, pos.mPreferLeft); }  CompleteScroll(aForward); } }
outsideLimit = 1; nsRect rect; frame->GetRect(rect); pos.mDesiredX = rect.width * 2; pos.mDirection = eDirPrevious;
PresShell::CompleteMove(PRBool aForward, PRBool aExtend){  nsCOMPtr<nsIDocument> document;  if (NS_FAILED(GetDocument(getter_AddRefs(document))) || !document)    return NS_ERROR_FAILURE;    nsCOMPtr<nsIDOMNodeList>nodeList;   NS_NAMED_LITERAL_STRING(bodyTag, "body");  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(document);  if (!doc)     return NS_ERROR_FAILURE;  nsresult result = doc->GetElementsByTagName(bodyTag, getter_AddRefs(nodeList));  if (NS_FAILED(result) ||!nodeList)    return result?result:NS_ERROR_FAILURE;  PRUint32 count;   nodeList->GetLength(&count);  if (count < 1)    return NS_ERROR_FAILURE;  // Use the first body node in the list:  nsCOMPtr<nsIDOMNode> node;  result = nodeList->Item(0, getter_AddRefs(node));   if (NS_SUCCEEDED(result) && node)  {    //return node->QueryInterface(NS_GET_IID(nsIDOMElement), (void **)aBodyElement);    // Is above equivalent to this:    nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(node);    if (bodyElement)    {      nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(bodyElement);      if (bodyContent)      {        nsIFrame *frame = nsnull;        result = GetPrimaryFrameFor(bodyContent, &frame);        if (frame)        {          PRInt8  outsideLimit = -1;//search from beginning          nsPeekOffsetStruct pos;          pos.mAmount = eSelectLine;          pos.mTracker = this;          pos.mContentOffset = 0;          pos.mContentOffsetEnd = 0;          pos.mScrollViewStop = PR_FALSE;//dont stop on scrolled views.          if (aForward)          {            outsideLimit = 1;//search from end            nsRect rect;            frame->GetRect(rect);            pos.mDesiredX = rect.width * 2;//search way off to right of line            pos.mDirection = eDirPrevious; //seach backwards from the end          }          else          {            pos.mDesiredX = -1; //start before line            pos.mDirection = eDirNext; //search forwards from before beginning          }          do          {            result = nsFrame::GetNextPrevLineFromeBlockFrame(mPresContext,                                        &pos,                                        frame,                                         0, //irrelavent since we set outsidelimit                                         outsideLimit                                        );            if (NS_COMFALSE == result) //NS_COMFALSE should ALSO break              break;            if (NS_OK != result || !pos.mResultFrame )               return result?result:NS_ERROR_FAILURE;            nsCOMPtr<nsILineIteratorNavigator> newIt;             //check to see if this is ANOTHER blockframe inside the other one if so then call into its lines            result = pos.mResultFrame->QueryInterface(NS_GET_IID(nsILineIteratorNavigator),getter_AddRefs(newIt));            if (NS_SUCCEEDED(result) && newIt)              frame = pos.mResultFrame;          }          while (NS_SUCCEEDED(result));//end 'do'                    result = mSelection->HandleClick(pos.mResultContent ,pos.mContentOffset ,pos.mContentOffsetEnd ,aExtend, PR_FALSE, pos.mPreferLeft);        }        // if we got this far, attempt to scroll no matter what the above result is        CompleteScroll(aForward);      }    }  }  return result;}