Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsXFormsContextContainer.cpp File Reference
#include "nsXFormsContextContainer.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMSerializer.h"
#include "nsIDOMXPathResult.h"
#include "nsIModelElementPrivate.h"
#include "nsIXFormsContextControl.h"
#include "nsIXFormsRepeatElement.h"
#include "nsXFormsUtils.h"

Go to the source code of this file.

Functions

 NS_IMPL_ISUPPORTS_INHERITED1 (nsXFormsContextContainer, nsXFormsBindableControlStub, nsIXFormsRepeatItemElement) nsresult nsXFormsContextContainer
 NS_NewXFormsContextContainer (nsIXTFElement **aResult)

Function Documentation

Definition at line 64 of file nsXFormsContextContainer.cpp.

{
  if (!aEvent || !mElement)
    return NS_OK;

  if (!nsXFormsUtils::EventHandlingAllowed(aEvent, mElement))
    return NS_OK;

  // Need to explicitly create the parent chain. This ensures that this code
  // works both in 1.8, which has the old event dispatching code, and also in
  // the later versions of Gecko with the new event dispatching.
  // See also Bug 331081.
  nsCOMPtr<nsIDOMNSEvent> event = do_QueryInterface(aEvent);
  NS_ENSURE_STATE(event);
  nsCOMPtr<nsIDOMEventTarget> target;
  event->GetOriginalTarget(getter_AddRefs(target));
  nsCOMPtr<nsIDOMNode> currentNode = do_QueryInterface(target);

  nsCOMArray<nsIDOMNode> containerStack(4);
  while (currentNode) {
    nsCOMPtr<nsIXFormsRepeatItemElement> repeatItem =
      do_QueryInterface(currentNode);
    if (repeatItem) {
      containerStack.AppendObject(currentNode);
    }
    nsCOMPtr<nsIDOMNode> parent;
    currentNode->GetParentNode(getter_AddRefs(parent));
    currentNode.swap(parent);
  }

  for (PRInt32 i = containerStack.Count() - 1; i >= 0; --i) {
    nsCOMPtr<nsIDOMNode> node = containerStack[i];
    if (node) {
      // Either we, or an element we contain, has gotten focus, so we need to
      // set the repeat index. This is done through the <repeat> the
      // nsXFormsContextContainer belongs to.
      //
      // Start by finding the <repeat> (our grandparent):
      // <repeat> <-- gParent
      //   <div>
      //     <contextcontainer> <-- this
      //   </div>
      // </repeat>
      nsCOMPtr<nsIDOMNode> parent;
      node->GetParentNode(getter_AddRefs(parent));
      if (parent) {
        nsCOMPtr<nsIDOMNode> grandParent;
        parent->GetParentNode(getter_AddRefs(grandParent));
        nsCOMPtr<nsIXFormsRepeatElement> repeat =
          do_QueryInterface(grandParent);
        nsCOMPtr<nsIXFormsRepeatItemElement> repeatItem =
          do_QueryInterface(node);
        if (repeat && repeatItem) {
          PRInt32 position = 1;
          repeatItem->GetContextPosition(&position);
          // Tell <repeat> about the new index position
          PRUint32 tmp = position;
          repeat->SetIndex(&tmp, PR_FALSE);
        }
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 287 of file nsXFormsContextContainer.cpp.

{
  *aResult = new nsXFormsContextContainer();
  if (!*aResult)
    return NS_ERROR_OUT_OF_MEMORY;

  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function: