else mPresShell = 0;
PresShell::HandleEvent(nsIView         *aView,                       nsGUIEvent*     aEvent,                       nsEventStatus*  aEventStatus,											 PRBool          aForceHandle,                       PRBool&         aHandled){  void*     clientData;  nsIFrame* frame;  nsresult  rv = NS_OK;    NS_ASSERTION(!(nsnull == aView), "null view");  aHandled = PR_TRUE;  if (mIsDestroying || mIsReflowing) {    return NS_OK;  }  if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT)    return HandleEventInternal(aEvent, aView, NS_EVENT_FLAG_INIT, aEventStatus);  aView->GetClientData(clientData);  frame = (nsIFrame *)clientData;/*  if (mSelection && aEvent->eventStructType == NS_KEY_EVENT)  {//KEY HANDLERS WILL GET RID OF THIS     if (mDisplayNonTextSelection && NS_SUCCEEDED(mSelection->HandleKeyEvent(mPresContext, aEvent)))    {        return NS_OK;    }  }*/  if (nsnull != frame) {    PushCurrentEventInfo(nsnull, nsnull);    nsIEventStateManager *manager;    if (NS_OK == mPresContext->GetEventStateManager(&manager)) {      //change 6-01-00 mjudge,ftang adding ime as an event that needs focused element      if (NS_IS_KEY_EVENT(aEvent) || NS_IS_IME_EVENT(aEvent) || aEvent->message == NS_CONTEXTMENU_KEY) {         //Key events go to the focused frame, not point based.        manager->GetFocusedContent(&mCurrentEventContent);        if (mCurrentEventContent)          GetPrimaryFrameFor(mCurrentEventContent, &mCurrentEventFrame);        else {          // XXX This is the way key events seem to work?  Why?????          // They spend time doing calls to GetFrameForPoint with the          // point as (0,0) (or sometimes something else).          // XXX If this code is really going to stay, it should          // probably go into a separate function, because its just          // a duplicate of the code a few lines below:          // This is because we want to give the point in the same          // coordinates as the frame's own Rect, so mRect.Contains(aPoint)          // works.  However, this point is relative to the frame's rect, so          // we need to add on the origin of the rect./*          nsPoint eventPoint;          frame->GetOrigin(eventPoint);          eventPoint += aEvent->point;          rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_FOREGROUND, &mCurrentEventFrame);          if (rv != NS_OK) {            rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_FLOATERS, &mCurrentEventFrame);            if (rv != NS_OK) {              rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_BACKGROUND, &mCurrentEventFrame);              if (rv != NS_OK) {#ifdef XP_MAC*/                // On the Mac it is possible to be running with no windows open, only the native menu bar.                // In this situation, we need to handle key board events but there are no frames, so                // we set mCurrentEventContent and that works itself out in HandleEventInternal.                mCurrentEventContent = mDocument->GetRootContent();                mCurrentEventFrame = nsnull;/*#else								if (aForceHandle) {									mCurrentEventFrame = frame;								}								else {									mCurrentEventFrame = nsnull;								}                aHandled = PR_FALSE;#endif                rv = NS_OK;              }            }          }          */        }      }      else {        // This is because we want to give the point in the same        // coordinates as the frame's own Rect, so mRect.Contains(aPoint)        // works.  However, this point is relative to the frame's rect, so        // we need to add on the origin of the rect.        nsPoint eventPoint;        frame->GetOrigin(eventPoint);        eventPoint += aEvent->point;        rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_FOREGROUND, &mCurrentEventFrame);        if (rv != NS_OK) {          rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_FLOATERS, &mCurrentEventFrame);          if (rv != NS_OK) {            rv = frame->GetFrameForPoint(mPresContext, eventPoint, NS_FRAME_PAINT_LAYER_BACKGROUND, &mCurrentEventFrame);            if (rv != NS_OK) {							if (aForceHandle) {								mCurrentEventFrame = frame;							}							else {								mCurrentEventFrame = nsnull;							}              aHandled = PR_FALSE;              rv = NS_OK;            }          }        }      }      if (GetCurrentEventFrame()) {        rv = HandleEventInternal(aEvent, aView, NS_EVENT_FLAG_INIT, aEventStatus);      }      NS_RELEASE(manager);    }#ifdef NS_DEBUG    if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) && (GetCurrentEventFrame())) {      nsIView *oldView = mCurrentTargetView;      nsPoint offset(0,0);      nsRect oldTargetRect(mCurrentTargetRect);      mCurrentEventFrame->GetRect(mCurrentTargetRect);      mCurrentEventFrame->GetView(mPresContext, &mCurrentTargetView);      if ( ! mCurrentTargetView ) {        mCurrentEventFrame->GetOffsetFromView(mPresContext, offset, &mCurrentTargetView);      }      if (mCurrentTargetView) {        mCurrentTargetRect.x = offset.x;        mCurrentTargetRect.y = offset.y;        // use aView or mCurrentTargetView??        if ( (mCurrentTargetRect != oldTargetRect) || (mCurrentTargetView != oldView)) {          nsIViewManager *vm;          if ((NS_OK == GetViewManager(&vm)) && vm) {            vm->UpdateView(mCurrentTargetView,mCurrentTargetRect,0);            if (oldView)              vm->UpdateView(oldView,oldTargetRect,0);            NS_IF_RELEASE(vm);          }        }      }    }#endif    PopCurrentEventInfo();  }  else {    aHandled = PR_FALSE;    rv = NS_OK;  }  return rv;}