if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && resultFrame){
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, 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;    nsIFrame *resultFrame;    nsSelectionAmount amount = eSelectCharacter;    if (keyEvent->isControl)      amount = eSelectWord;    switch (keyEvent->keyCode){      case nsIDOMUIEvent::VK_LEFT  :         //we need to look for the previous PAINTED location to move the cursor to.#ifdef DEBUG_NAVIGATION        printf("debug vk left\n");#endif        if (keyEvent->isShift || (GetDirection() == eDirPrevious)) { //f,a          offsetused = FetchFocusOffset();          weakNodeUsed = FetchFocusNode();        }        else {          offsetused = FetchAnchorOffset();          weakNodeUsed = FetchAnchorNode();        }        if (weakNodeUsed && offsetused >=0){          nsIFrame *frame;          nsCOMPtr<nsIContent> content = do_QueryInterface(weakNodeUsed);          if (content){            result = mTracker->GetPrimaryFrameFor(content, &frame);            if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(amount, eDirPrevious, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && resultFrame){              result = TakeFocus(content, offsetused, offsetused, keyEvent->isShift);            }            result = ScrollIntoView();          }        }        break;      case nsIDOMUIEvent::VK_RIGHT :         //we need to look for the previous PAINTED location to move the cursor to.#ifdef DEBUG_NAVIGATION        printf("debug vk left\n");#endif        if (keyEvent->isShift || (GetDirection() == eDirPrevious)) { //f,a          offsetused = FetchFocusOffset();          weakNodeUsed = FetchFocusNode();        }        else {          offsetused = FetchAnchorOffset();          weakNodeUsed = FetchAnchorNode();        }        if (weakNodeUsed && offsetused >=0){          nsIFrame *frame;          nsCOMPtr<nsIContent> content = do_QueryInterface(weakNodeUsed);          if (content){            result = mTracker->GetPrimaryFrameFor(content, &frame);            if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(amount, eDirNext, offsetused, getter_AddRefs(content), &offsetused, PR_FALSE)) && resultFrame){              result = TakeFocus(content, offsetused, offsetused, keyEvent->isShift);            }            result = ScrollIntoView();          }        }       break;      case nsIDOMUIEvent::VK_UP : #ifdef DEBUG_NAVIGATION        printf("debug vk up\n");#endif        break;      case nsIDOMUIEvent::VK_DOWN : #ifdef DEBUG_NAVIGATION        printf("debug vk down\n");#endif        break;    default :break;    }  }  return result;}