Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Attributes
nsFormControlList Class Reference
Inheritance diagram for nsFormControlList:
Inheritance graph
[legend]
Collaboration diagram for nsFormControlList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsFormControlList (nsIDOMHTMLFormElement *aForm)
virtual ~nsFormControlList ()
nsresult Init ()
void Clear ()
void SetForm (nsIDOMHTMLFormElement *aForm)
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMHTMLCOLLECTION
NS_DECL_NSIDOMNSHTMLFORMCONTROLLIST
nsresult 
GetNamedObject (const nsAString &aName, nsISupports **aResult)
nsresult AddElementToTable (nsIFormControl *aChild, const nsAString &aName)
nsresult RemoveElementFromTable (nsIFormControl *aChild, const nsAString &aName)
nsresult IndexOfControl (nsIFormControl *aControl, PRInt32 *aIndex)
nsISupports namedItem (in DOMString name)
nsIDOMNode item (in unsigned long index)
nsIDOMNode namedItem (in DOMString name)

Public Attributes

nsIDOMHTMLFormElementmForm
nsAutoVoidArray mElements
nsSmallVoidArray mNotInElements
readonly attribute unsigned long length

Protected Attributes

nsInterfaceHashtable
< nsStringHashKey, nsISupports > 
mNameLookupTable

Detailed Description

Definition at line 308 of file nsHTMLFormElement.cpp.


Constructor & Destructor Documentation

Definition at line 1773 of file nsHTMLFormElement.cpp.

                                                                 :
  mForm(aForm)
{
}

Definition at line 1778 of file nsHTMLFormElement.cpp.

{
  mForm = nsnull;
  Clear();
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsFormControlList::AddElementToTable ( nsIFormControl aChild,
const nsAString &  aName 
)

Definition at line 1922 of file nsHTMLFormElement.cpp.

{
  if (!ShouldBeInElements(aChild)) {
    return NS_OK;
  }

  nsCOMPtr<nsISupports> supports;
  mNameLookupTable.Get(aName, getter_AddRefs(supports));

  if (!supports) {
    // No entry found, add the form control
    nsCOMPtr<nsISupports> child(do_QueryInterface(aChild));

    NS_ENSURE_TRUE( mNameLookupTable.Put(aName, child), NS_ERROR_FAILURE );
  } else {
    // Found something in the hash, check its type
    nsCOMPtr<nsIContent> content(do_QueryInterface(supports));
    nsCOMPtr<nsIContent> newChild(do_QueryInterface(aChild));

    if (content) {
      // Check if the new content is the same as the one we found in the
      // hash, if it is then we leave it in the hash as it is, this will
      // happen if a form control has both a name and an id with the same
      // value
      if (content == newChild) {
        return NS_OK;
      }

      // Found an element, create a list, add the element to the list and put
      // the list in the hash
      nsBaseContentList *list = new nsBaseContentList();
      NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);

      list->AppendElement(content);

      // Add the new child too
      list->AppendElement(newChild);

      nsCOMPtr<nsISupports> listSupports = do_QueryInterface(list);

      // Replace the element with the list.
      NS_ENSURE_TRUE(mNameLookupTable.Put(aName, listSupports),
                     NS_ERROR_FAILURE);
    } else {
      // There's already a list in the hash, add the child to the list
      nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(supports));
      NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);

      // Upcast, uggly, but it works!
      nsBaseContentList *list = NS_STATIC_CAST(nsBaseContentList *,
                                               (nsIDOMNodeList *)nodeList.get());

      PRInt32 oldIndex = list->IndexOf(newChild, PR_FALSE);
      
      // Add the new child only if it's not in our list already
      if (oldIndex < 0) {
        list->AppendElement(newChild);
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1800 of file nsHTMLFormElement.cpp.

{
  // Null out childrens' pointer to me.  No refcounting here
  PRInt32 i;
  for (i = mElements.Count()-1; i >= 0; i--) {
    nsIFormControl* f = NS_STATIC_CAST(nsIFormControl *,
                                       mElements.ElementAt(i));
    if (f) {
      f->SetForm(nsnull, PR_FALSE); 
    }
  }
  mElements.Clear();

  for (i = mNotInElements.Count()-1; i >= 0; i--) {
    nsIFormControl* f = NS_STATIC_CAST(nsIFormControl*,
                                       mNotInElements.ElementAt(i));
    if (f) {
      f->SetForm(nsnull, PR_FALSE);
    }
  }
  mNotInElements.Clear();

  mNameLookupTable.Clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFormControlList::GetNamedObject ( const nsAString &  aName,
nsISupports **  aResult 
)

Definition at line 1863 of file nsHTMLFormElement.cpp.

{
  *aResult = nsnull;

  if (!mForm) {
    // No form, no named objects
    return NS_OK;
  }
  
  // Get the hash entry
  mNameLookupTable.Get(aName, aResult);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1988 of file nsHTMLFormElement.cpp.

{
  NS_ENSURE_ARG_POINTER(aIndex);

  *aIndex = mElements.IndexOf(aControl);

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 1784 of file nsHTMLFormElement.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsIDOMNode nsIDOMHTMLCollection::item ( in unsigned long  index) [inherited]
nsISupports nsIDOMNSHTMLFormControlList::namedItem ( in DOMString  name) [inherited]
nsIDOMNode nsIDOMHTMLCollection::namedItem ( in DOMString  name) [inherited]

Definition at line 1999 of file nsHTMLFormElement.cpp.

{
  if (!ShouldBeInElements(aChild)) {
    return NS_OK;
  }

  nsCOMPtr<nsIContent> content = do_QueryInterface(aChild);  
  if (!content) {
    return NS_OK;
  }

  nsCOMPtr<nsISupports> supports;

  if (!mNameLookupTable.Get(aName, getter_AddRefs(supports)))
    return NS_OK;

  nsCOMPtr<nsIFormControl> fctrl(do_QueryInterface(supports));

  if (fctrl) {
    // Single element in the hash, just remove it if it's the one
    // we're trying to remove...
    if (fctrl == aChild) {
      mNameLookupTable.Remove(aName);
    }

    return NS_OK;
  }

  nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(supports));
  NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);

  // Upcast, uggly, but it works!
  nsBaseContentList *list = NS_STATIC_CAST(nsBaseContentList *,
                                           (nsIDOMNodeList *)nodeList.get());

  list->RemoveElement(content);

  PRUint32 length = 0;
  list->GetLength(&length);

  if (!length) {
    // If the list is empty we remove if from our hash, this shouldn't
    // happen tho
    mNameLookupTable.Remove(aName);
  } else if (length == 1) {
    // Only one element left, replace the list in the hash with the
    // single element.
    nsCOMPtr<nsIDOMNode> node;
    list->Item(0, getter_AddRefs(node));

    if (node) {
      nsCOMPtr<nsISupports> tmp(do_QueryInterface(node));
      NS_ENSURE_TRUE(mNameLookupTable.Put(aName, tmp),NS_ERROR_FAILURE);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1794 of file nsHTMLFormElement.cpp.

{
  mForm = aForm; // WEAK - the form owns me
}

Here is the caller graph for this function:


Member Data Documentation

readonly attribute unsigned long nsIDOMHTMLCollection::length [inherited]

Definition at line 55 of file nsIDOMHTMLCollection.idl.

Definition at line 340 of file nsHTMLFormElement.cpp.

Definition at line 338 of file nsHTMLFormElement.cpp.

Definition at line 356 of file nsHTMLFormElement.cpp.

Definition at line 347 of file nsHTMLFormElement.cpp.


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