mHint = HINTRIGHT;
nsRangeList::HandleKeyEvent(nsGUIEvent *aGuiEvent){  if (!aGuiEvent)    return NS_ERROR_NULL_POINTER;  STATUS_CHECK_RETURN_MACRO();  nsresult result = NS_ERROR_FAILURE;  if (NS_KEY_DOWN == aGuiEvent->message) {    nsKeyEvent *keyEvent = (nsKeyEvent *)aGuiEvent; //this is ok. It really is a keyevent    switch (keyEvent->keyCode)    {        case nsIDOMUIEvent::DOM_VK_LEFT  :         case nsIDOMUIEvent::DOM_VK_UP    :        case nsIDOMUIEvent::DOM_VK_DOWN  :         case nsIDOMUIEvent::DOM_VK_RIGHT    :        case nsIDOMUIEvent::DOM_VK_HOME  :         case nsIDOMUIEvent::DOM_VK_END    :          break;        default:           return NS_ERROR_FAILURE;    }    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::DOM_VK_UP || keyEvent->keyCode == nsIDOMUIEvent::DOM_VK_DOWN)    {      desiredX= FetchDesiredX();      SetDesiredX(desiredX);    }    if (!isCollapsed && !keyEvent->isShift) {      switch (keyEvent->keyCode){        case nsIDOMUIEvent::DOM_VK_LEFT  :         case nsIDOMUIEvent::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);           } break;        case nsIDOMUIEvent::DOM_VK_RIGHT :         case nsIDOMUIEvent::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);           } break;              }      if (keyEvent->keyCode == nsIDOMUIEvent::DOM_VK_UP || keyEvent->keyCode == nsIDOMUIEvent::DOM_VK_DOWN)        SetDesiredX(desiredX);      return NS_OK;    }    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, amount, eDirPrevious, offsetused, PR_FALSE,PR_TRUE);    mHint = HINTRIGHT;//stick to opposite of movement    switch (keyEvent->keyCode){      case nsIDOMUIEvent::DOM_VK_RIGHT :           pos.mDirection = eDirNext;          mHint = HINTLEFT;//stick to this line      case nsIDOMUIEvent::DOM_VK_LEFT  : //no break          InvalidateDesiredX();        break;      case nsIDOMUIEvent::DOM_VK_DOWN :           pos.mDirection = eDirNext;//no break here          mHint = HINTLEFT;//stick to this line      case nsIDOMUIEvent::DOM_VK_UP :           pos.mAmount = eSelectLine;        break;      case nsIDOMUIEvent::DOM_VK_HOME :          pos.mAmount = eSelectBeginLine;          InvalidateDesiredX();        break;      case nsIDOMUIEvent::DOM_VK_END :          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(&pos)) && pos.mResultContent)      result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, keyEvent->isShift, PR_FALSE);    if (NS_SUCCEEDED(result))      result = mDomSelections[SELECTION_NORMAL]->ScrollIntoView();  }  return result;}