Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
nsFocusController Class Reference

#include <nsFocusController.h>

Inheritance diagram for nsFocusController:
Inheritance graph
[legend]
Collaboration diagram for nsFocusController:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_IMETHOD GetFocusedElement (nsIDOMElement **aResult)
NS_IMETHOD SetFocusedElement (nsIDOMElement *aElement)
NS_IMETHOD GetFocusedWindow (nsIDOMWindowInternal **aResult)
NS_IMETHOD SetFocusedWindow (nsIDOMWindowInternal *aResult)
NS_IMETHOD GetSuppressFocus (PRBool *aSuppressFlag)
NS_IMETHOD SetSuppressFocus (PRBool aSuppressFlag, const char *aReason)
NS_IMETHOD GetSuppressFocusScroll (PRBool *aSuppressFlag)
NS_IMETHOD SetSuppressFocusScroll (PRBool aSuppressFlag)
NS_IMETHOD GetActive (PRBool *aActive)
NS_IMETHOD SetActive (PRBool aActive)
NS_IMETHOD GetPopupNode (nsIDOMNode **aNode)
NS_IMETHOD SetPopupNode (nsIDOMNode *aNode)
NS_IMETHOD GetPopupEvent (nsIDOMEvent **aEvent)
NS_IMETHOD SetPopupEvent (nsIDOMEvent *aEvent)
NS_IMETHOD GetControllerForCommand (const char *aCommand, nsIController **aResult)
NS_IMETHOD GetControllers (nsIControllers **aResult)
NS_IMETHOD MoveFocus (PRBool aForward, nsIDOMElement *aElt)
NS_IMETHOD RewindFocusState ()
NS_IMETHOD ResetElementFocus ()
NS_IMETHOD Focus (nsIDOMEvent *aEvent)
 Processes a focus event.
NS_IMETHOD Blur (nsIDOMEvent *aEvent)
 Processes a blur event.
NS_IMETHOD HandleEvent (nsIDOMEvent *anEvent)
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Static Public Member Functions

static NS_IMETHODIMP Create (nsIFocusController **aResult)
static nsPIDOMWindowGetWindowFromDocument (nsIDOMDocument *aElement)

Protected Member Functions

 nsFocusController (void)
virtual ~nsFocusController (void)
void UpdateCommands ()
void UpdateWWActiveWindow ()

Protected Attributes

nsCOMPtr< nsIDOMElementmCurrentElement
nsCOMPtr< nsIDOMElementmPreviousElement
nsCOMPtr< nsIDOMWindowInternalmCurrentWindow
nsCOMPtr< nsIDOMWindowInternalmPreviousWindow
nsCOMPtr< nsIDOMNodemPopupNode
nsCOMPtr< nsIDOMEventmPopupEvent
PRUint32 mSuppressFocus
PRPackedBool mSuppressFocusScroll
PRPackedBool mActive
PRPackedBool mUpdateWindowWatcher
PRPackedBool mNeedUpdateCommands

Detailed Description

Definition at line 57 of file nsFocusController.h.


Constructor & Destructor Documentation

nsFocusController::~nsFocusController ( void  ) [protected, virtual]

Definition at line 84 of file nsFocusController.cpp.

{
}

Member Function Documentation

nsresult nsFocusController::Blur ( nsIDOMEvent aEvent) [virtual]

Processes a blur event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMFocusListener.

Definition at line 375 of file nsFocusController.cpp.

{
  if (mSuppressFocus)
    return NS_OK;

  nsCOMPtr<nsIDOMEventTarget> t;

  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));

  if (nsevent) {
    nsevent->GetOriginalTarget(getter_AddRefs(t));
  }

  nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(t);
  if (domElement) {
    SetFocusedElement(nsnull);
  }
  
  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(t);
  if (domDoc) {
    nsCOMPtr<nsIDOMWindowInternal> domWindow = GetWindowFromDocument(domDoc);
    if (domWindow)
      SetFocusedWindow(nsnull);
  }

  return NS_OK;
}

Here is the call graph for this function:

Processes a focus event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMFocusListener.

Definition at line 318 of file nsFocusController.cpp.

{
  if (mSuppressFocus)
    return NS_OK;

  nsCOMPtr<nsIDOMEventTarget> t;

  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
  if (nsevent) {
    nsevent->GetOriginalTarget(getter_AddRefs(t));
  }

  nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(t);
  if (domElement && (domElement != mCurrentElement)) {
    SetFocusedElement(domElement);

    // Also set focus to our innermost window.
    // XXX Must be done for the Ender case, since ender causes a blur,
    // but we don't hear the subsequent focus to the Ender window.
    nsCOMPtr<nsIDOMDocument> ownerDoc;
    domElement->GetOwnerDocument(getter_AddRefs(ownerDoc));
    nsCOMPtr<nsIDOMWindowInternal> domWindow = GetWindowFromDocument(ownerDoc);
    if (domWindow)
      SetFocusedWindow(domWindow);
  }
  else {
    // We're focusing a window.  We only want to do an update commands
    // if no element is focused.
    nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(t);
    if (domDoc) {
      nsCOMPtr<nsIDOMWindowInternal> domWindow = GetWindowFromDocument(domDoc);
      if (domWindow) {
        SetFocusedWindow(domWindow);
        if (mCurrentElement) {
          // Make sure this element is in our window. If not, we
          // should clear this field.
          nsCOMPtr<nsIDOMDocument> ownerDoc;
          mCurrentElement->GetOwnerDocument(getter_AddRefs(ownerDoc));
          nsCOMPtr<nsIDOMDocument> windowDoc;
          mCurrentWindow->GetDocument(getter_AddRefs(windowDoc));
          if (ownerDoc != windowDoc)
            mCurrentElement = mPreviousElement = nsnull;
        }
        else
          mPreviousElement = nsnull;

        if (!mCurrentElement) {
          UpdateCommands();
        }
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Implements nsIFocusController.

Definition at line 530 of file nsFocusController.cpp.

{
  *aActive = mActive;
  return NS_OK;
}
NS_IMETHODIMP nsFocusController::GetControllerForCommand ( const char *  aCommand,
nsIController **  aResult 
) [virtual]

Implements nsIFocusController.

Definition at line 421 of file nsFocusController.cpp.

{
  NS_ENSURE_ARG_POINTER(_retval);  
  *_retval = nsnull;

  nsCOMPtr<nsIControllers> controllers;
  nsCOMPtr<nsIController> controller;

  GetControllers(getter_AddRefs(controllers));
  if(controllers) {
    controllers->GetControllerForCommand(aCommand, getter_AddRefs(controller));
    if(controller) {
      controller.swap(*_retval);
      return NS_OK;
    }
  }
  
  nsCOMPtr<nsPIDOMWindow> currentWindow;
  if (mCurrentElement) {
    // Move up to the window.
    nsCOMPtr<nsIDOMDocument> domDoc;
    mCurrentElement->GetOwnerDocument(getter_AddRefs(domDoc));
    currentWindow = do_QueryInterface(GetWindowFromDocument(domDoc));
  }
  else if (mCurrentWindow) {
    nsGlobalWindow *win =
      NS_STATIC_CAST(nsGlobalWindow *,
                     NS_STATIC_CAST(nsIDOMWindowInternal *, mCurrentWindow));
    currentWindow = win->GetPrivateParent();
  }
  else return NS_OK;

  while(currentWindow) {
    nsCOMPtr<nsIDOMWindowInternal> domWindow(do_QueryInterface(currentWindow));

    nsCOMPtr<nsIControllers> controllers2;
    domWindow->GetControllers(getter_AddRefs(controllers2));
    if(controllers2) {
      controllers2->GetControllerForCommand(aCommand,
                                            getter_AddRefs(controller));
      if(controller) {
        controller.swap(*_retval);
        return NS_OK;
      }
    }

    nsGlobalWindow *win =
      NS_STATIC_CAST(nsGlobalWindow *,
                     NS_STATIC_CAST(nsIDOMWindowInternal *, currentWindow));
    currentWindow = win->GetPrivateParent();
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Implements nsIFocusController.

Definition at line 230 of file nsFocusController.cpp.

{
  // XXX: we should fix this so there's a generic interface that
  // describes controllers, so this code would have no special
  // knowledge of what object might have controllers.
  if (mCurrentElement) {

#ifdef MOZ_XUL
    nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(mCurrentElement));
    if (xulElement)
      return xulElement->GetControllers(aResult);
#endif

    nsCOMPtr<nsIDOMNSHTMLTextAreaElement> htmlTextArea =
      do_QueryInterface(mCurrentElement);
    if (htmlTextArea)
      return htmlTextArea->GetControllers(aResult);

    nsCOMPtr<nsIDOMNSHTMLInputElement> htmlInputElement =
      do_QueryInterface(mCurrentElement);
    if (htmlInputElement)
      return htmlInputElement->GetControllers(aResult);
  }
  else if (mCurrentWindow) {
    nsCOMPtr<nsIDOMWindowInternal> domWindow =
      do_QueryInterface(mCurrentWindow);
    if (domWindow)
      return domWindow->GetControllers(aResult);
  }

  *aResult = nsnull;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIFocusController.

Definition at line 109 of file nsFocusController.cpp.

{
  *aElement = mCurrentElement;
  NS_IF_ADDREF(*aElement);
  return NS_OK;
}

Implements nsIFocusController.

Definition at line 117 of file nsFocusController.cpp.

{
  *aWindow = mCurrentWindow;
  NS_IF_ADDREF(*aWindow);
  return NS_OK;
}

Implements nsIFocusController_MOZILLA_1_8_BRANCH.

Definition at line 610 of file nsFocusController.cpp.

{
  *aEvent = mPopupEvent;
  NS_IF_ADDREF(*aEvent);
  return NS_OK;
}

Implements nsIFocusController.

Definition at line 587 of file nsFocusController.cpp.

{
#ifdef DEBUG_dr
  printf("dr :: nsFocusController::GetPopupNode\n");
#endif

  *aNode = mPopupNode;
  NS_IF_ADDREF(*aNode);
  return NS_OK;
}

Implements nsIFocusController.

Definition at line 492 of file nsFocusController.cpp.

{
  *aSuppressFocus = (mSuppressFocus > 0);
  return NS_OK;
}

Implements nsIFocusController.

Definition at line 478 of file nsFocusController.cpp.

{
  *aSuppressFocusScroll = mSuppressFocusScroll;
  return NS_OK;
}

Definition at line 404 of file nsFocusController.cpp.

{
  nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDocument);
  if (!doc)
    return NS_OK;

  nsCOMPtr<nsPIDOMWindow> win =
    do_QueryInterface(doc->GetScriptGlobalObject());

  if (win && win->IsInnerWindow()) {
    return win->GetOuterWindow();
  }

  return win;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.

Definition at line 105 of file nsFocusController.h.

{ return NS_OK; };
NS_IMETHODIMP nsFocusController::MoveFocus ( PRBool  aForward,
nsIDOMElement aElt 
) [virtual]

Implements nsIFocusController.

Definition at line 265 of file nsFocusController.cpp.

{
  // Obtain the doc that we'll be shifting focus inside.
  nsCOMPtr<nsIDocument> doc;
  nsCOMPtr<nsIContent> content;
  if (aElt) {
    content = do_QueryInterface(aElt);
    doc = content->GetDocument();
  }
  else {
    if (mCurrentElement) {
      content = do_QueryInterface(mCurrentElement);
      doc = content->GetDocument();
      content = nsnull;
    }
    else if (mCurrentWindow) {
      nsCOMPtr<nsIDOMDocument> domDoc;
      mCurrentWindow->GetDocument(getter_AddRefs(domDoc));
      doc = do_QueryInterface(domDoc);
    }
  }

  if (!doc)
    // No way to obtain an event state manager.  Give up.
    return NS_OK;


  // Obtain a presentation context
  PRInt32 count = doc->GetNumberOfShells();
  if (count == 0)
    return NS_OK;

  nsIPresShell *shell = doc->GetShellAt(0);
  if (!shell)
    return NS_OK;

  // Make sure frames have been constructed before shifting focus, bug 273092.
  shell->FlushPendingNotifications(Flush_Frames);

  // Retrieve the context
  nsCOMPtr<nsPresContext> presContext = shell->GetPresContext();

  // Make this ESM shift the focus per our instructions.
  presContext->EventStateManager()->ShiftFocus(aForward, content);

  return NS_OK;
}

Here is the call graph for this function:

Implements nsIFocusController.

Definition at line 558 of file nsFocusController.cpp.

Implements nsIFocusController.

Definition at line 537 of file nsFocusController.cpp.

{
  mActive = aActive;

  // We may be activated before we ever have a focused window set.
  // This happens on window creation, where the FocusController
  // is activated just prior to setting the focused window.
  // (see nsEventStateManager::PreHandleEvent/NS_ACTIVATE)
  // If this is the case, we need to queue a notification of the
  // WindowWatcher until SetFocusedWindow is called.
  if (mActive) {
    if (mCurrentWindow)
      UpdateWWActiveWindow();
    else
      mUpdateWindowWatcher = PR_TRUE;
  }

  return NS_OK;
}

Here is the call graph for this function:

Implements nsIFocusController.

Definition at line 125 of file nsFocusController.cpp.

{
  if (mCurrentElement) 
    mPreviousElement = mCurrentElement;
  else if (aElement) 
    mPreviousElement = aElement;

  mNeedUpdateCommands = mNeedUpdateCommands || mCurrentElement != aElement;
  mCurrentElement = aElement;

  if (!mSuppressFocus) {
    // Need to update focus commands when focus switches from
    // an element to no element, so don't test mCurrentElement
    // before updating.
    UpdateCommands();
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIFocusController.

Definition at line 154 of file nsFocusController.cpp.

{
  nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(aWindow);

  if (pwin) {
    pwin = pwin->GetOuterWindow();
  }

  NS_ASSERTION(!pwin || !pwin->IsInnerWindow(),
               "Uh, inner window can't have focus!");

  nsCOMPtr<nsIDOMWindowInternal> win = do_QueryInterface(pwin);

  if (win && (mCurrentWindow != win)) {
    nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(win);
    if (sgo) {
      nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(sgo->GetDocShell());
      if (basewin)
        basewin->SetFocus();
    }
  }

  if (mCurrentWindow) {
    mPreviousWindow = mCurrentWindow;
  } else if (win) {
    mPreviousWindow = win;
  }

  mNeedUpdateCommands = mNeedUpdateCommands || mCurrentWindow != win;
  mCurrentWindow = win;

  if (mUpdateWindowWatcher) {
    NS_ASSERTION(mActive, "This shouldn't happen");
    if (mCurrentWindow)
      UpdateWWActiveWindow();
    mUpdateWindowWatcher = PR_FALSE;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIFocusController_MOZILLA_1_8_BRANCH.

Definition at line 618 of file nsFocusController.cpp.

{
  mPopupEvent = aEvent;
  return NS_OK;
}

Implements nsIFocusController.

Definition at line 599 of file nsFocusController.cpp.

{
#ifdef DEBUG_dr
  printf("dr :: nsFocusController::SetPopupNode\n");
#endif

  mPopupNode = aNode;
  return NS_OK;
}
NS_IMETHODIMP nsFocusController::SetSuppressFocus ( PRBool  aSuppressFlag,
const char *  aReason 
) [virtual]

Implements nsIFocusController.

Definition at line 499 of file nsFocusController.cpp.

{
  if(aSuppressFocus) {
    ++mSuppressFocus;
    //#ifdef DEBUG_hyatt
    //printf("[%p] SuppressFocus incremented to %d. The reason is %s.\n", this, mSuppressFocus, aReason);
    //#endif
  }
  else if(mSuppressFocus > 0) {
    --mSuppressFocus;
    //#ifdef DEBUG_hyatt
    //printf("[%p] SuppressFocus decremented to %d. The reason is %s.\n", this, mSuppressFocus, aReason);
    //#endif
  }
  else 
    NS_ASSERTION(PR_FALSE, "Attempt to decrement focus controller's suppression when no suppression active!\n");

  // we are unsuppressing after activating, so update focus-related commands
  // we need this to update command, including the case where there is no element
  // because nsPresShell::UnsuppressPainting may have just now unsuppressed
  // focus on the currently focused window
  if (!mSuppressFocus) {
    // Always update commands if we have a current element
    mNeedUpdateCommands = mNeedUpdateCommands || mCurrentElement;
    UpdateCommands();
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Implements nsIFocusController.

Definition at line 485 of file nsFocusController.cpp.

{
  mSuppressFocusScroll = aSuppressFocusScroll;
  return NS_OK;
}

Definition at line 197 of file nsFocusController.cpp.

{
  if (!mNeedUpdateCommands) {
    return;
  }
  nsCOMPtr<nsIDOMWindowInternal> window;
  nsCOMPtr<nsIDocument> doc;
  if (mCurrentWindow) {
    window = mCurrentWindow;
    nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(window));
    nsCOMPtr<nsIDOMDocument> domDoc;
    domWin->GetDocument(getter_AddRefs(domDoc));
    doc = do_QueryInterface(domDoc);
  }
  else if (mCurrentElement) {
    nsCOMPtr<nsIDOMDocument> domDoc;
    mCurrentElement->GetOwnerDocument(getter_AddRefs(domDoc));
    if (domDoc) {
      doc = do_QueryInterface(domDoc);
      window = do_QueryInterface(doc->GetScriptGlobalObject());
    }
  }

  // If there is no presshell, it's a zombie document which can't handle the command updates
  if (window && doc && doc->GetNumberOfShells()) {
    // Not a zombie document, so we can handle the command update
    window->UpdateCommands(NS_LITERAL_STRING("focus"));
    mNeedUpdateCommands = PR_FALSE;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 565 of file nsFocusController.cpp.

{
  // Inform the window watcher of the new active window.
  nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1");
  if (!wwatch) return;

  // This gets the toplevel DOMWindow
  nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(mCurrentWindow);

  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
    do_QueryInterface(sgo->GetDocShell());
  if (!docShellAsItem) return;

  nsCOMPtr<nsIDocShellTreeItem> rootItem;
  docShellAsItem->GetRootTreeItem(getter_AddRefs(rootItem));
  NS_ASSERTION(rootItem, "Invalid docshell tree - no root!");

  nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(rootItem);
  wwatch->SetActiveWindow(domWin);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 125 of file nsFocusController.h.

Definition at line 116 of file nsFocusController.h.

Definition at line 118 of file nsFocusController.h.

Definition at line 127 of file nsFocusController.h.

Definition at line 121 of file nsFocusController.h.

Definition at line 120 of file nsFocusController.h.

Definition at line 117 of file nsFocusController.h.

Definition at line 119 of file nsFocusController.h.

Definition at line 123 of file nsFocusController.h.

Definition at line 124 of file nsFocusController.h.

Definition at line 126 of file nsFocusController.h.


The documentation for this class was generated from the following files: