Bug 708144 - Make sure to update the Mac accessible tree. r=tbsaunde landing on a CLOSED TREE
authorHub Figuière <hfiguiere@mozilla.com>
Thu, 22 Dec 2011 14:31:06 -0800
changeset 84519 3d0cf1dd0a5abeee38844fab56b8bea2946b2f32
parent 84495 2a1f2758ad0d92bb355e29c75b8d9f63ea9df509
child 84520 56ceeff7cfb8ed3d94e5a03929ce8b539a447978
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs708144
milestone12.0a1
Bug 708144 - Make sure to update the Mac accessible tree. r=tbsaunde landing on a CLOSED TREE
accessible/src/base/nsOuterDocAccessible.cpp
accessible/src/mac/mozAccessible.h
accessible/src/mac/mozAccessible.mm
accessible/src/mac/nsAccessibleWrap.h
accessible/src/mac/nsAccessibleWrap.mm
--- a/accessible/src/base/nsOuterDocAccessible.cpp
+++ b/accessible/src/base/nsOuterDocAccessible.cpp
@@ -182,17 +182,17 @@ nsOuterDocAccessible::AppendChild(nsAcce
   // We keep showing the old document for a bit after creating the new one,
   // and while building the new DOM and frame tree. That's done on purpose
   // to avoid weird flashes of default background color.
   // The old viewer will be destroyed after the new one is created.
   // For a11y, it should be safe to shut down the old document now.
   if (mChildren.Length())
     mChildren[0]->Shutdown();
 
-  if (!nsAccessible::AppendChild(aAccessible))
+  if (!nsAccessibleWrap::AppendChild(aAccessible))
     return false;
 
   NS_LOG_ACCDOCCREATE("append document to outerdoc",
                       aAccessible->GetDocumentNode())
   NS_LOG_ACCDOCCREATE_ACCADDRESS("outerdoc", this)
 
   return true;
 }
@@ -205,17 +205,17 @@ nsOuterDocAccessible::RemoveChild(nsAcce
     NS_ERROR("Wrong child to remove!");
     return false;
   }
 
   NS_LOG_ACCDOCDESTROY_FOR("remove document from outerdoc",
                            child->GetDocumentNode(), child)
   NS_LOG_ACCDOCDESTROY_ACCADDRESS("outerdoc", this)
 
-  bool wasRemoved = nsAccessible::RemoveChild(child);
+  bool wasRemoved = nsAccessibleWrap::RemoveChild(child);
 
   NS_ASSERTION(!mChildren.Length(),
                "This child document of outerdoc accessible wasn't removed!");
 
   return wasRemoved;
 }
 
 
--- a/accessible/src/mac/mozAccessible.h
+++ b/accessible/src/mac/mozAccessible.h
@@ -125,16 +125,21 @@
 - (void)didReceiveFocus;
 - (void)valueDidChange;
 
 #pragma mark -
 
 // invalidates and removes all our children from our cached array.
 - (void)invalidateChildren;
 
+/** 
+ * Append a child if they are already cached.
+ */
+- (void)appendChild:(nsAccessible*)aAccessible;
+
 // invalidates the cached parent, used by invalidateChildren.
 - (void)invalidateParent;
 
 // makes ourselves "expired". after this point, we might be around if someone
 // has retained us (e.g., a third-party), but we really contain no information.
 - (void)expire;
 - (BOOL)isExpired;
 
--- a/accessible/src/mac/mozAccessible.mm
+++ b/accessible/src/mac/mozAccessible.mm
@@ -610,16 +610,27 @@ GetNativeFromGeckoAccessible(nsIAccessib
 
   // make room for new children
   [mChildren release];
   mChildren = nil;
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
+- (void)appendChild:(nsAccessible*)aAccessible
+{
+  // if mChildren is nil, then we don't even need to bother
+  if (!mChildren)
+    return;
+    
+  mozAccessible *curNative = GetNativeFromGeckoAccessible(aAccessible);
+  if (curNative)
+    [mChildren addObject:GetObjectOrRepresentedView(curNative)];
+}
+
 - (void)invalidateParent
 {
   mParent = nil;
 }
 
 - (void)expire
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
--- a/accessible/src/mac/nsAccessibleWrap.h
+++ b/accessible/src/mac/nsAccessibleWrap.h
@@ -56,44 +56,56 @@
 #include "nsAutoPtr.h"
 
 #if defined(__OBJC__)
 @class mozAccessible;
 #endif
 
 class nsAccessibleWrap : public nsAccessible
 {
-  public: // construction, destruction
-    nsAccessibleWrap(nsIContent *aContent, nsIWeakReference *aShell);
-    virtual ~nsAccessibleWrap();
+public: // construction, destruction
+  nsAccessibleWrap(nsIContent* aContent, nsIWeakReference* aShell);
+  virtual ~nsAccessibleWrap();
     
-    // get the native obj-c object (mozAccessible)
-    NS_IMETHOD GetNativeInterface (void **aOutAccessible);
-    
-    // the objective-c |Class| type that this accessible's native object
-    // should be instantied with.   used on runtime to determine the
-    // right type for this accessible's associated native object.
-    virtual Class GetNativeType ();
+  /**
+   * Get the native Obj-C object (mozAccessible).
+   */
+  NS_IMETHOD GetNativeInterface (void** aOutAccessible);
+  
+  /**
+   * The objective-c |Class| type that this accessible's native object
+   * should be instantied with.   used on runtime to determine the
+   * right type for this accessible's associated native object.
+   */
+  virtual Class GetNativeType ();
+
+  virtual void Shutdown ();
+  virtual void InvalidateChildren();
 
-    virtual void Shutdown ();
-    virtual void InvalidateChildren();
+  virtual bool AppendChild(nsAccessible* aAccessible);
+  virtual bool RemoveChild(nsAccessible* aAccessible);
 
-    virtual nsresult HandleAccEvent(AccEvent* aEvent);
+  virtual nsresult HandleAccEvent(AccEvent* aEvent);
 
-    // ignored means that the accessible might still have children, but is not displayed
-    // to the user. it also has no native accessible object represented for it.
-    bool IsIgnored();
-    
-    bool HasPopup () {
-      return (NativeState() & mozilla::a11y::states::HASPOPUP);
-    }
-    
-    // return this accessible's all children, adhering to "flat" accessibles by not returning their children.
-    void GetUnignoredChildren(nsTArray<nsRefPtr<nsAccessibleWrap> > &aChildrenArray);
-    virtual already_AddRefed<nsIAccessible> GetUnignoredParent();
+  /**
+   * Ignored means that the accessible might still have children, but is not
+   * displayed to the user. it also has no native accessible object represented
+   * for it.
+   */
+  bool IsIgnored();
+  
+  inline bool HasPopup () 
+    { return (NativeState() & mozilla::a11y::states::HASPOPUP); }
+  
+  /**
+   * Returns this accessible's all children, adhering to "flat" accessibles by 
+   * not returning their children.
+   */
+  void GetUnignoredChildren(nsTArray<nsRefPtr<nsAccessibleWrap> >& aChildrenArray);
+  virtual already_AddRefed<nsIAccessible> GetUnignoredParent();
     
 protected:
 
   virtual nsresult FirePlatformEvent(AccEvent* aEvent);
 
   /**
    * Return true if the parent doesn't have children to expose to AT.
    */
@@ -107,17 +119,18 @@ protected:
 #else
   id GetNativeObject();
 #endif
 
 private:
 
   /**
    * Our native object. Private because its creation is done lazily.
-   * Don't access it directly. Ever. Unless you are GetNativeObject() or Shutdown()
+   * Don't access it directly. Ever. Unless you are GetNativeObject() or 
+   * Shutdown()
    */
 #if defined(__OBJC__)
   // if we are in Objective-C, we use the actual Obj-C class.
   mozAccessible* mNativeObject;
 #else
   id mNativeObject;
 #endif
 
--- a/accessible/src/mac/nsAccessibleWrap.mm
+++ b/accessible/src/mac/nsAccessibleWrap.mm
@@ -203,16 +203,38 @@ nsAccessibleWrap::InvalidateChildren()
 
   [GetNativeObject() invalidateChildren];
 
   nsAccessible::InvalidateChildren();
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
+bool
+nsAccessibleWrap::AppendChild(nsAccessible *aAccessible)
+{
+  bool appended = nsAccessible::AppendChild(aAccessible);
+  
+  if (appended && mNativeObject)
+    [mNativeObject appendChild:aAccessible];
+
+  return appended;
+}
+
+bool
+nsAccessibleWrap::RemoveChild(nsAccessible *aAccessible)
+{
+  bool removed = nsAccessible::RemoveChild(aAccessible);
+
+  if (removed && mNativeObject)
+    [mNativeObject invalidateChildren];
+
+  return removed;
+}
+
 // if we for some reason have no native accessible, we should be skipped over (and traversed)
 // when fetching all unignored children, etc.  when counting unignored children, we will not be counted.
 bool 
 nsAccessibleWrap::IsIgnored() 
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
   
   mozAccessible* nativeObject = GetNativeObject();