if (node != weakNodeUsed) offsetused = 0;
nsCOMPtr<nsIDOMNode> parentNode;   result = node->GetParentNode(getter_AddRefs(parentNode)); if ((NS_FAILED(result) || parentNode != weakNodeUsed) && node != weakNodeUsed) offsetused = -1;
nsSelection::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  PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL);  result = mDomSelections[index]->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[index]->GetDirection() == eDirPrevious)) { //f,a            offsetused = mDomSelections[index]->FetchFocusOffset();            weakNodeUsed = mDomSelections[index]->FetchFocusNode();          }          else {            offsetused = mDomSelections[index]->FetchAnchorOffset();            weakNodeUsed = mDomSelections[index]->FetchAnchorNode();          }          result = mDomSelections[index]->Collapse(weakNodeUsed,offsetused);          mDomSelections[index]->ScrollIntoView();          return NS_OK;         } break;      case nsIDOMKeyEvent::DOM_VK_RIGHT :       case nsIDOMKeyEvent::DOM_VK_DOWN  : {          if ((mDomSelections[index]->GetDirection() == eDirPrevious)) { //f,a            offsetused = mDomSelections[index]->FetchAnchorOffset();            weakNodeUsed = mDomSelections[index]->FetchAnchorNode();          }          else {            offsetused = mDomSelections[index]->FetchFocusOffset();            weakNodeUsed = mDomSelections[index]->FetchFocusNode();          }          result = mDomSelections[index]->Collapse(weakNodeUsed,offsetused);          mDomSelections[index]->ScrollIntoView();          return NS_OK;         } break;          }//      if (keyEvent->keyCode == nsIDOMKeyEvent::DOM_VK_UP || keyEvent->keyCode == nsIDOMKeyEvent::DOM_VK_DOWN)//        SetDesiredX(desiredX);  }  offsetused = mDomSelections[index]->FetchFocusOffset();  weakNodeUsed = mDomSelections[index]->FetchFocusNode();  nsIFrame *frame;  result = mDomSelections[index]->GetPrimaryFrameForFocusNode(&frame);  if (NS_FAILED(result) || !frame)    return result?result:NS_ERROR_FAILURE;  nsCOMPtr<nsIContent> content;  result = frame->GetContent(getter_AddRefs(content));  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(content);  if (node != weakNodeUsed) //we are not pointing to same node! offset is meaningless    offsetused = 0;//0 because when grabbing a child content we grab the IDX'th object or: body has 2 children,                    //index 0 of parent is the first child so if we say the first child is the frame then say offset is 0 we are correct    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(result = frame->PeekOffset(context, &pos)) && pos.mResultContent)  {    mHint = (HINT)pos.mPreferLeft;    result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinue, PR_FALSE);  }  else if (NS_FAILED(result))  {    if (nsIDOMKeyEvent::DOM_VK_UP == aKeycode)    {      pos.mPreferLeft = HINTRIGHT;      pos.mAmount = eSelectBeginLine;      InvalidateDesiredX();    }    else if(nsIDOMKeyEvent::DOM_VK_DOWN == aKeycode)    {      pos.mPreferLeft = HINTLEFT;      pos.mAmount = eSelectEndLine;      InvalidateDesiredX();    }    if (nsIDOMKeyEvent::DOM_VK_UP == aKeycode || nsIDOMKeyEvent::DOM_VK_DOWN == aKeycode )    {      if (NS_SUCCEEDED(result = 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[index]->ScrollIntoView();  return result;}