if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(context, &pos)) && pos.mResultContent)
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(result = frame->PeekOffset(context, &pos)) && pos.mResultContent)
nsRangeList::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aAmount){  nsCOMPtr<nsIPresContext> context;  nsresult result = mTracker->GetPresContext(getter_AddRefs(context));  if (NS_FAILED(result) || !context)    return result?result:NS_ERROR_FAILURE;  nsCOMPtr<nsIDOMNode> weakNodeUsed;  PRInt32 offsetused = 0;  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 (aKeycode == nsIDOMKeyEvent::DOM_VK_UP || aKeycode == nsIDOMKeyEvent::DOM_VK_DOWN)  {    desiredX= FetchDesiredX();    SetDesiredX(desiredX);  }  if (!isCollapsed && !aContinue) {    switch (aKeycode){      case nsIDOMKeyEvent::DOM_VK_LEFT  :       case nsIDOMKeyEvent::DOM_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);          return NS_OK;         } break;      case nsIDOMKeyEvent::DOM_VK_RIGHT :       case nsIDOMKeyEvent::DOM_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);          return NS_OK;         } break;          }//      if (keyEvent->keyCode == nsIDOMKeyEvent::DOM_VK_UP || keyEvent->keyCode == nsIDOMKeyEvent::DOM_VK_DOWN)//        SetDesiredX(desiredX);  }  offsetused = mDomSelections[SELECTION_NORMAL]->FetchFocusOffset();  weakNodeUsed = mDomSelections[SELECTION_NORMAL]->FetchFocusNode();  nsIFrame *frame;  result = mDomSelections[SELECTION_NORMAL]->GetPrimaryFrameForFocusNode(&frame);  if (NS_FAILED(result))    return result;  nsPeekOffsetStruct pos;  pos.SetData(mTracker, desiredX, aAmount, eDirPrevious, offsetused, PR_FALSE,PR_TRUE, PR_TRUE);  switch (aKeycode){    case nsIDOMKeyEvent::DOM_VK_RIGHT :         InvalidateDesiredX();        pos.mDirection = eDirNext;        mHint = HINTLEFT;//stick to this line      break;    case nsIDOMKeyEvent::DOM_VK_LEFT  : //no break        InvalidateDesiredX();        mHint = HINTRIGHT;//stick to opposite of movement      break;    case nsIDOMKeyEvent::DOM_VK_DOWN :         pos.mAmount = eSelectLine;        pos.mDirection = eDirNext;//no break here      break;    case nsIDOMKeyEvent::DOM_VK_UP :         pos.mAmount = eSelectLine;      break;    case nsIDOMKeyEvent::DOM_VK_HOME :        InvalidateDesiredX();        pos.mAmount = eSelectBeginLine;        InvalidateDesiredX();        mHint = HINTRIGHT;//stick to opposite of movement      break;    case nsIDOMKeyEvent::DOM_VK_END :        InvalidateDesiredX();        pos.mAmount = eSelectEndLine;        InvalidateDesiredX();        mHint = HINTLEFT;//stick to this line     break;  default :return NS_ERROR_FAILURE;  }  pos.mPreferLeft = mHint;  if (NS_SUCCEEDED(result) && NS_SUCCEEDED(frame->PeekOffset(context, &pos)) && pos.mResultContent)  {    mHint = (HINT)pos.mPreferLeft;    result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinue, PR_FALSE);  }  if (NS_SUCCEEDED(result))    result = mDomSelections[SELECTION_NORMAL]->ScrollIntoView();  return result;}