Back to index

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

This class is used to walk the DOM tree. More...

#include <nsAccessibleTreeWalker.h>

Collaboration diagram for nsAccessibleTreeWalker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsAccessibleTreeWalker (nsIWeakReference *aShell, nsIDOMNode *aContent, PRBool mWalkAnonymousContent)
virtual ~nsAccessibleTreeWalker ()
NS_IMETHOD GetNextSibling ()
NS_IMETHOD GetParent ()
NS_IMETHOD GetFirstChild ()

Public Attributes

WalkState mState

Protected Member Functions

PRBool GetAccessible ()
 If the DOM node's frame has an accessible or the DOMNode itself implements nsIAccessible return it.
NS_IMETHOD GetFullTreeParentNode (nsIDOMNode *aChildNode, nsIDOMNode **aParentNodeOut)
void GetKids (nsIDOMNode *aParent)
void ClearState ()
NS_IMETHOD PushState ()
NS_IMETHOD PopState ()
void UpdateFrame (PRBool aTryFirstChild)
void GetNextDOMNode ()

Protected Attributes

nsCOMPtr< nsIWeakReferencemWeakShell
nsCOMPtr< nsIAccessibilityServicemAccService
nsCOMPtr< nsIBindingManagermBindingManager

Detailed Description

This class is used to walk the DOM tree.

It skips everything but nodes that either implement nsIAccessibleProvider or have primary frames that implement "GetAccessible"

Definition at line 71 of file nsAccessibleTreeWalker.h.


Constructor & Destructor Documentation

nsAccessibleTreeWalker::nsAccessibleTreeWalker ( nsIWeakReference aShell,
nsIDOMNode aContent,
PRBool  mWalkAnonymousContent 
)

Definition at line 49 of file nsAccessibleTreeWalker.cpp.

                                                                                                                      : 
  mWeakShell(aPresShell), 
  mAccService(do_GetService("@mozilla.org/accessibilityService;1"))
{
  mState.domNode = aNode;
  mState.prevState = nsnull;
  mState.siblingIndex = eSiblingsUninitialized;
  mState.siblingList = nsnull;
  mState.isHidden = false;
  mState.frame = nsnull;

  if (aWalkAnonContent) {
    nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
    if (presShell)
      mBindingManager = presShell->GetDocument()->BindingManager();
  }
  MOZ_COUNT_CTOR(nsAccessibleTreeWalker);
}

Here is the call graph for this function:

Definition at line 68 of file nsAccessibleTreeWalker.cpp.

{
  // Clear state stack from memory
  while (NS_SUCCEEDED(PopState()))
    /* do nothing */ ;
   MOZ_COUNT_DTOR(nsAccessibleTreeWalker);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 185 of file nsAccessibleTreeWalker.cpp.

Here is the caller graph for this function:

If the DOM node's frame has an accessible or the DOMNode itself implements nsIAccessible return it.

Definition at line 292 of file nsAccessibleTreeWalker.cpp.

{
  if (!mAccService) {
    return false;
  }
  mState.accessible = nsnull;
  nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));

  if (NS_SUCCEEDED(mAccService->GetAccessible(mState.domNode, presShell, mWeakShell, 
                                              &mState.frame, &mState.isHidden,
                                              getter_AddRefs(mState.accessible)))) {
    NS_ASSERTION(mState.accessible, "No accessible but no failure return code");
    return true;
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 251 of file nsAccessibleTreeWalker.cpp.

{
  mState.accessible = nsnull;
  if (mState.isHidden || !mState.domNode) {
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsIDOMNode> parent(mState.domNode);
  GetKids(parent); // Side effects change our state (mState)

  // Recursive loop: depth first search for first accessible child
  while (mState.domNode) {
    if ((mState.domNode != parent && GetAccessible()) || NS_SUCCEEDED(GetFirstChild()))
      return NS_OK;
    UpdateFrame(PR_FALSE);
    GetNextDOMNode();
  }

  PopState();  // Return to previous state
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsAccessibleTreeWalker::GetFullTreeParentNode ( nsIDOMNode aChildNode,
nsIDOMNode **  aParentNodeOut 
) [protected]

Definition at line 80 of file nsAccessibleTreeWalker.cpp.

{
  nsCOMPtr<nsIContent> childContent(do_QueryInterface(aChildNode));
  nsCOMPtr<nsIContent> bindingParentContent;
  nsCOMPtr<nsIDOMNode> parentNode;

  if (mState.prevState)
    parentNode = mState.prevState->domNode;
  else {
    if (mBindingManager) {
      mBindingManager->GetInsertionParent(childContent, getter_AddRefs(bindingParentContent));
      if (bindingParentContent) 
        parentNode = do_QueryInterface(bindingParentContent);
    }

    if (!parentNode) 
      aChildNode->GetParentNode(getter_AddRefs(parentNode));
  }

  if (parentNode) {
    *aParentNodeOut = parentNode;
    NS_ADDREF(*aParentNodeOut);
    return NS_OK;
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAccessibleTreeWalker::GetKids ( nsIDOMNode aParent) [protected]

Definition at line 107 of file nsAccessibleTreeWalker.cpp.

{
  nsCOMPtr<nsIContent> parentContent(do_QueryInterface(aParentNode));
  if (!parentContent || !parentContent->IsContentOfType(nsIContent::eHTML)) {
    mState.frame = nsnull;  // Don't walk frames in non-HTML content, just walk the DOM.
  }

  PushState();
  UpdateFrame(PR_TRUE);

  // Walk frames? UpdateFrame() sets this when it sees anonymous frames
  if (mState.siblingIndex == eSiblingsWalkFrames) {
    return;
  }

  // Walk anonymous content? Not currently used for HTML -- anonymous content there uses frame walking
  mState.siblingIndex = 0;   // Indicates our index into the sibling list
  if (parentContent) {
    if (mBindingManager && !parentContent->IsContentOfType(nsIContent::eHTML)) {
      // Walk anonymous content
      mBindingManager->GetXBLChildNodesFor(parentContent, getter_AddRefs(mState.siblingList)); // returns null if no anon nodes
    }
    if (!mState.siblingList) {
      // Walk normal DOM. Just use nsIContent -- it doesn't require 
      // the mallocs that GetChildNodes() needs
      //aParentNode->GetChildNodes(getter_AddRefs(mState.siblingList));
      mState.parentContent = parentContent;
      mState.domNode = do_QueryInterface(parentContent->GetChildAt(0 /* 0 == mState.siblingIndex */));
      return;
    }
  }
  else {
    // We're on document node, that's why we could not QI to nsIContent.
    // So, use nsIDOMNodeList method to walk content.
    aParentNode->GetChildNodes(getter_AddRefs(mState.siblingList));
    if (!mState.siblingList) {
      return;
    }
  }

  mState.siblingList->Item(0 /* 0 == mState.siblingIndex */, getter_AddRefs(mState.domNode));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 206 of file nsAccessibleTreeWalker.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 224 of file nsAccessibleTreeWalker.cpp.

{
  // Make sure mState.prevState and mState.siblingIndex are initialized so we can walk forward
  NS_ASSERTION(mState.prevState && mState.siblingIndex != eSiblingsUninitialized,
               "Error - GetNextSibling() only works after a GetFirstChild(), so we must have a prevState.");
  mState.accessible = nsnull;

  while (PR_TRUE) {
    // Get next frame
    UpdateFrame(PR_FALSE);
    GetNextDOMNode();

    if (!mState.domNode) {  // Done with current siblings
      PopState();   // Use parent - go up in stack. Can always pop state because we have to start with a GetFirstChild().
      if (!mState.prevState) {
        mState.accessible = nsnull;
        break; // Back to original accessible that we did GetFirstChild() from
      }
    }
    else if ((mState.domNode != mState.prevState->domNode && GetAccessible()) || 
             NS_SUCCEEDED(GetFirstChild())) {
      return NS_OK; // if next is accessible, use it 
    }
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 150 of file nsAccessibleTreeWalker.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 166 of file nsAccessibleTreeWalker.cpp.

{
  nsIFrame *frameParent = mState.frame? mState.frame->GetParent(): nsnull;
  if (mState.prevState) {
    WalkState *toBeDeleted = mState.prevState;
    mState = *mState.prevState; // deep copy
    mState.isHidden = PR_FALSE; // If we were in a child, the parent wasn't hidden
    if (!mState.frame) {
      mState.frame = frameParent;
    }
    delete toBeDeleted;
    return NS_OK;
  }
  ClearState();
  mState.frame = frameParent;
  mState.isHidden = PR_FALSE;
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 194 of file nsAccessibleTreeWalker.cpp.

{
  // Duplicate mState and put right before end; reset mState; make mState the new end of the stack
  WalkState* nextToLastState= new WalkState();
  if (!nextToLastState)
    return NS_ERROR_OUT_OF_MEMORY;
  *nextToLastState = mState;  // Deep copy - copy contents of struct to new state that will be added to end of our stack
  ClearState();
  mState.prevState = nextToLastState;   // Link to previous state
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsAccessibleTreeWalker::UpdateFrame ( PRBool  aTryFirstChild) [protected]

Definition at line 273 of file nsAccessibleTreeWalker.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 96 of file nsAccessibleTreeWalker.h.

Definition at line 97 of file nsAccessibleTreeWalker.h.

Definition at line 81 of file nsAccessibleTreeWalker.h.

Definition at line 95 of file nsAccessibleTreeWalker.h.


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