Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
nsTreeUtils Class Reference

#include <nsTreeUtils.h>

List of all members.

Static Public Member Functions

static nsresult TokenizeProperties (const nsAString &aProperties, nsISupportsArray *aPropertiesArray)
 Parse a whitespace separated list of properties into an array of atoms.
static nsresult GetImmediateChild (nsIContent *aContainer, nsIAtom *aTag, nsIContent **aResult)
static nsresult GetDescendantChild (nsIContent *aContainer, nsIAtom *aTag, nsIContent **aResult)
static nsresult UpdateSortIndicators (nsIContent *aColumn, const nsAString &aDirection)
static nsresult GetColumnIndex (nsIContent *aColumn, PRInt32 *aResult)

Detailed Description

Definition at line 48 of file nsTreeUtils.h.


Member Function Documentation

nsresult nsTreeUtils::GetColumnIndex ( nsIContent aColumn,
PRInt32 aResult 
) [static]

Definition at line 168 of file nsTreeUtils.cpp.

{
  nsIContent* parentContent = aColumn->GetParent();
  if (parentContent) {
    nsINodeInfo *ni = parentContent->GetNodeInfo();

    if (ni && ni->Equals(nsXULAtoms::treecols, kNameSpaceID_XUL)) {
      PRUint32 numChildren = parentContent->GetChildCount();
      PRInt32 colIndex = 0;
      for (PRUint32 i = 0; i < numChildren; ++i) {
        nsIContent *childContent = parentContent->GetChildAt(i);

        if (childContent) {
          ni = childContent->GetNodeInfo();

          if (ni && ni->Equals(nsXULAtoms::treecol, kNameSpaceID_XUL)) {

            if (childContent == aColumn) {
              *aResult = colIndex;
             return NS_OK;
            }
            colIndex++;
          }
        }
      }
    }
  }

  *aResult = -1;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTreeUtils::GetDescendantChild ( nsIContent aContainer,
nsIAtom aTag,
nsIContent **  aResult 
) [static]

Definition at line 110 of file nsTreeUtils.cpp.

{
  ChildIterator iter, last;
  for (ChildIterator::Init(aContainer, &iter, &last); iter != last; ++iter) {
    nsCOMPtr<nsIContent> child = *iter;
    if (child->Tag() == aTag) {
      NS_ADDREF(*aResult = child);
      return NS_OK;
    }
    else {
      nsresult rv = GetDescendantChild(child, aTag, aResult);
      if(NS_FAILED(rv))
        return rv;

      if(*aResult)
        return NS_OK;
    }
  }

  *aResult = nsnull;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTreeUtils::GetImmediateChild ( nsIContent aContainer,
nsIAtom aTag,
nsIContent **  aResult 
) [static]

Definition at line 92 of file nsTreeUtils.cpp.

{
  ChildIterator iter, last;
  for (ChildIterator::Init(aContainer, &iter, &last); iter != last; ++iter) {
    nsCOMPtr<nsIContent> child = *iter;

    if (child->Tag() == aTag) {
      NS_ADDREF(*aResult = child);
      return NS_OK;
    }
  }

  *aResult = nsnull;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTreeUtils::TokenizeProperties ( const nsAString &  aProperties,
nsISupportsArray aPropertiesArray 
) [static]

Parse a whitespace separated list of properties into an array of atoms.

Definition at line 51 of file nsTreeUtils.cpp.

{
  NS_PRECONDITION(aPropertiesArray != nsnull, "null ptr");
  if (! aPropertiesArray)
     return NS_ERROR_NULL_POINTER;

  nsAString::const_iterator end;
  aProperties.EndReading(end);

  nsAString::const_iterator iter;
  aProperties.BeginReading(iter);

  do {
    // Skip whitespace
    while (iter != end && nsCRT::IsAsciiSpace(*iter))
      ++iter;

    // If only whitespace, we're done
    if (iter == end)
      break;

    // Note the first non-whitespace character
    nsAString::const_iterator first = iter;

    // Advance to the next whitespace character
    while (iter != end && ! nsCRT::IsAsciiSpace(*iter))
      ++iter;

    // XXX this would be nonsensical
    NS_ASSERTION(iter != first, "eh? something's wrong here");
    if (iter == first)
      break;

    nsCOMPtr<nsIAtom> atom = do_GetAtom(Substring(first, iter));
    aPropertiesArray->AppendElement(atom);
  } while (iter != end);

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsTreeUtils::UpdateSortIndicators ( nsIContent aColumn,
const nsAString &  aDirection 
) [static]

Definition at line 134 of file nsTreeUtils.cpp.

{
  aColumn->SetAttr(kNameSpaceID_None, nsXULAtoms::sortDirection, aDirection, PR_TRUE);
  aColumn->SetAttr(kNameSpaceID_None, nsXULAtoms::sortActive, NS_LITERAL_STRING("true"), PR_TRUE);

  // Unset sort attribute(s) on the other columns
  nsCOMPtr<nsIContent> parentContent = aColumn->GetParent();
  if (parentContent) {
    nsINodeInfo *ni = parentContent->GetNodeInfo();

    if (ni && ni->Equals(nsXULAtoms::treecols, kNameSpaceID_XUL)) {
      PRUint32 numChildren = parentContent->GetChildCount();
      for (PRUint32 i = 0; i < numChildren; ++i) {
        nsCOMPtr<nsIContent> childContent = parentContent->GetChildAt(i);

        if (childContent) {
          ni = childContent->GetNodeInfo();

          if (ni && ni->Equals(nsXULAtoms::treecol, kNameSpaceID_XUL) &&
              childContent != aColumn) {
            childContent->UnsetAttr(kNameSpaceID_None,
                                    nsXULAtoms::sortDirection, PR_TRUE);
            childContent->UnsetAttr(kNameSpaceID_None,
                                    nsXULAtoms::sortActive, PR_TRUE);
          }
        }
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:


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