if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(mTracker, desiredX, amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && content){
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(mTracker, desiredX, amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, &resultFrame, PR_FALSE)) && content){
nsRangeList::HandleKeyEvent(nsGUIEvent *aGuiEvent){  if (!aGuiEvent)    return NS_ERROR_NULL_POINTER;  STATUS_CHECK_RETURN_MACRO();  nsresult result = NS_OK;  if (NS_KEY_DOWN == aGuiEvent->message) {    nsKeyEvent *keyEvent = (nsKeyEvent *)aGuiEvent; //this is ok. It really is a keyevent    nsCOMPtr<nsIDOMNode> weakNodeUsed;    PRInt32 offsetused = 0;    nsSelectionAmount amount = eSelectCharacter;    if (keyEvent->isControl)      amount = eSelectWord;    PRBool isCollapsed;    nscoord desiredX; //we must keep this around and revalidate it when its just UP/DOWN    result = mDomSelections[SELECTION_NORMAL]->GetIsCollapsed(&isCollapsed);    if (NS_FAILED(result))      return result;    if (keyEvent->keyCode == nsIDOMUIEvent::VK_UP || keyEvent->keyCode == nsIDOMUIEvent::VK_DOWN)      desiredX= FetchDesiredX();    if (!isCollapsed && !keyEvent->isShift) {      switch (keyEvent->keyCode){        case nsIDOMUIEvent::VK_LEFT  :         case nsIDOMUIEvent::VK_UP    : {            if ((mDomSelections[SELECTION_NORMAL]->GetDirection() == eDirPrevious)) { //f,a              offsetused = mDomSelections[SELECTION_NORMAL]->FetchFocusOffset();              weakNodeUsed = mDomSelections[SELECTION_NORMAL]->FetchFocusNode();            }            else {              offsetused = mDomSelections[SELECTION_NORMAL]->FetchAnchorOffset();              weakNodeUsed = mDomSelections[SELECTION_NORMAL]->FetchAnchorNode();            }            result = mDomSelections[SELECTION_NORMAL]->Collapse(weakNodeUsed,offsetused);                                       } break;        case nsIDOMUIEvent::VK_RIGHT :         case nsIDOMUIEvent::VK_DOWN  : {            if ((mDomSelections[SELECTION_NORMAL]->GetDirection() == eDirPrevious)) { //f,a              offsetused = mDomSelections[SELECTION_NORMAL]->FetchAnchorOffset();              weakNodeUsed = mDomSelections[SELECTION_NORMAL]->FetchAnchorNode();            }            else {              offsetused = mDomSelections[SELECTION_NORMAL]->FetchFocusOffset();              weakNodeUsed = mDomSelections[SELECTION_NORMAL]->FetchFocusNode();            }            result = mDomSelections[SELECTION_NORMAL]->Collapse(weakNodeUsed,offsetused);                                       } break;      }      if (keyEvent->keyCode == nsIDOMUIEvent::VK_UP || keyEvent->keyCode == nsIDOMUIEvent::VK_DOWN)        SetDesiredX(desiredX);      return NS_OK;    }    offsetused = mDomSelections[SELECTION_NORMAL]->FetchFocusOffset();    weakNodeUsed = mDomSelections[SELECTION_NORMAL]->FetchFocusNode();    nsIFrame *frame;    nsCOMPtr<nsIContent> content;    result = mDomSelections[SELECTION_NORMAL]->GetPrimaryFrameForFocusNode(&frame);    if (NS_FAILED(result))      return result;    switch (keyEvent->keyCode){      case nsIDOMUIEvent::VK_LEFT  :         {        //we need to look for the previous PAINTED location to move the cursor to.          if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(mTracker, desiredX, amount, eDirPrevious, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && content){            result = TakeFocus(content, offsetused, offsetused, keyEvent->isShift, PR_FALSE);          }          result = mDomSelections[SELECTION_NORMAL]->ScrollIntoView();        }        break;      case nsIDOMUIEvent::VK_RIGHT :         {        //we need to look for the previous PAINTED location to move the cursor to.          if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(mTracker, desiredX, amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && content){            result = TakeFocus(content, offsetused, offsetused, keyEvent->isShift, PR_FALSE);          }          result = mDomSelections[SELECTION_NORMAL]->ScrollIntoView();        }       break;      case nsIDOMUIEvent::VK_UP :       case nsIDOMUIEvent::VK_DOWN :         {  //we need to look for the previous PAINTED location to move the cursor to.          amount = eSelectLine;          if (nsIDOMUIEvent::VK_UP == keyEvent->keyCode)          {            if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(mTracker, desiredX, amount, eDirPrevious, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && content){              result = TakeFocus(content, offsetused, offsetused, keyEvent->isShift, PR_FALSE);            }          }          else            if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(mTracker, desiredX, amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && content){              result = TakeFocus(content, offsetused, offsetused, keyEvent->isShift, PR_FALSE);            }          result = mDomSelections[SELECTION_NORMAL]->ScrollIntoView();          SetDesiredX(desiredX);        }        break;#ifdef DEBUG_NAVIGATION        printf("debug vk down\n");#endif        break;    default :break;    }  }  return result;}