Commit 6fcd7788 authored by aaronleventhal%moonset.net's avatar aaronleventhal%moonset.net
Browse files

Bug 344896. Refactor accessibility events handling. Part 1 of fix, add...

Bug 344896. Refactor accessibility events handling. Part 1 of fix, add nsPIAccessible::allowsAnonChildAccessibles(). Patch by Alexander Surkov. r=aaronlev
parent 8b65ce02
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -52,4 +52,11 @@ interface nsPIAccessible : nsISupports
   */
  [noscript] void invalidateChildren();
  [noscript] void fireToolkitEvent(in unsigned long aEvent, in nsIAccessible aTarget, in voidPtr aData);

  /**
   * Return true if there are accessible children in anonymous content
   */
  [noscript] readonly attribute boolean allowsAnonChildAccessibles;

};
+20 −10
Original line number Diff line number Diff line
@@ -76,6 +76,18 @@ PRBool nsAccessNode::gIsAccessibilityActive = PR_FALSE;
PRBool nsAccessNode::gIsCacheDisabled = PR_FALSE;
nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> nsAccessNode::gGlobalDocAccessibleCache;

nsIAccessibilityService *nsAccessNode::sAccService = nsnull;
nsIAccessibilityService *nsAccessNode::GetAccService()
{
  if (!sAccService) {
    nsresult rv = CallGetService("@mozilla.org/accessibilityService;1",
                                 &sAccService);
    NS_ASSERTION(NS_SUCCEEDED(rv), "No accessibility service");
  }

  return sAccService;
}

/*
 * Class nsAccessNode
 */
@@ -120,9 +132,7 @@ NS_IMETHODIMP nsAccessNode::Init()
    if (presShell) {
      nsCOMPtr<nsIDOMNode> docNode(do_QueryInterface(presShell->GetDocument()));
      if (docNode) {
        nsCOMPtr<nsIAccessibilityService> accService = 
          do_GetService("@mozilla.org/accessibilityService;1");
        NS_ASSERTION(accService, "No accessibility service");
        nsIAccessibilityService *accService = GetAccService();
        if (accService) {
          nsCOMPtr<nsIAccessible> accessible;
          accService->GetAccessibleInShell(docNode, presShell,
@@ -212,6 +222,7 @@ void nsAccessNode::ShutdownXPAccessibility()
  NS_IF_RELEASE(gKeyStringBundle);
  NS_IF_RELEASE(gDoCommandTimer);
  NS_IF_RELEASE(gLastFocusedNode);
  NS_IF_RELEASE(sAccService);

  ClearCache(gGlobalDocAccessibleCache);

@@ -339,8 +350,7 @@ nsAccessNode::GetInnerHTML(nsAString& aInnerHTML)
nsresult
nsAccessNode::MakeAccessNode(nsIDOMNode *aNode, nsIAccessNode **aAccessNode)
{
  nsCOMPtr<nsIAccessibilityService> accService = 
    do_GetService("@mozilla.org/accessibilityService;1");
  nsIAccessibilityService *accService = GetAccService();
  NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);

  nsCOMPtr<nsIAccessNode> accessNode;
+5 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#include "nsIStringBundle.h"
#include "nsWeakReference.h"
#include "nsInterfaceHashtable.h"
#include "nsIAccessibilityService.h"

class nsIPresShell;
class nsPresContext;
@@ -146,6 +147,7 @@ class nsAccessNode: public nsIAccessNode, public nsPIAccessNode
    already_AddRefed<nsRootAccessible> GetRootAccessible();

    static nsIDOMNode *gLastFocusedNode;
    static nsIAccessibilityService* GetAccService();

protected:
    nsresult MakeAccessNode(nsIDOMNode *aNode, nsIAccessNode **aAccessNode);
@@ -168,6 +170,9 @@ protected:
    static PRBool gIsCacheDisabled;

    static nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> gGlobalDocAccessibleCache;

private:
  static nsIAccessibilityService *sAccService;
};

#endif
+11 −3
Original line number Diff line number Diff line
@@ -642,7 +642,7 @@ nsIAccessible *nsAccessible::NextChild(nsCOMPtr<nsIAccessible>& aAccessible)
  return (aAccessible = nextChild);
}

void nsAccessible::CacheChildren(PRBool aWalkAnonContent)
void nsAccessible::CacheChildren()
{
  if (!mWeakShell) {
    // This node has been shut down
@@ -651,7 +651,9 @@ void nsAccessible::CacheChildren(PRBool aWalkAnonContent)
  }

  if (mAccChildCount == eChildCountUninitialized) {
    nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, aWalkAnonContent);
    PRBool allowsAnonChildren = PR_FALSE;
    GetAllowsAnonChildAccessibles(&allowsAnonChildren);
    nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, allowsAnonChildren);
    // Seed the frame hint early while we're still on a container node.
    // This is better than doing the GetPrimaryFrameFor() later on
    // a text node, because text nodes aren't in the frame map.
@@ -672,10 +674,16 @@ void nsAccessible::CacheChildren(PRBool aWalkAnonContent)
  }
}

NS_IMETHODIMP nsAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
{
  *aAllowsAnonChildren = PR_TRUE;
  return NS_OK;
}

/* readonly attribute long childCount; */
NS_IMETHODIMP nsAccessible::GetChildCount(PRInt32 *aAccChildCount) 
{
  CacheChildren(PR_TRUE);
  CacheChildren();
  *aAccChildCount = mAccChildCount;
  return NS_OK;  
}
+1 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ protected:
  nsresult AppendFlatStringFromSubtreeRecurse(nsIContent *aContent, nsAString *aFlatString);

  // Helpers for dealing with children
  virtual void CacheChildren(PRBool aWalkAnonContent);
  virtual void CacheChildren();
  nsIAccessible *NextChild(nsCOMPtr<nsIAccessible>& aAccessible);
  already_AddRefed<nsIAccessible> GetNextWithState(nsIAccessible *aStart, PRUint32 matchState);

Loading