bug 779520 - get rid of Accessible::Init() r=surkov
authorTrevor Saunders <trev.saunders@gmail.com>
Tue, 20 Nov 2012 10:33:30 -0500
changeset 114322 16777b16f524b5604b9caee140f94086335a704f
parent 114321 11d3d401116b95fed0e0c41a1c9c57ef38534d3e
child 114323 336e86d2e1999ac90cec3f644b2e26949757563e
push id23913
push useremorley@mozilla.com
push dateWed, 28 Nov 2012 17:11:31 +0000
treeherdermozilla-central@17c267a881cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs779520
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 779520 - get rid of Accessible::Init() r=surkov
accessible/src/atk/ApplicationAccessibleWrap.cpp
accessible/src/atk/ApplicationAccessibleWrap.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/generic/Accessible.cpp
accessible/src/generic/Accessible.h
accessible/src/generic/ApplicationAccessible.cpp
accessible/src/generic/ApplicationAccessible.h
accessible/src/generic/DocAccessible.cpp
accessible/src/generic/RootAccessible.cpp
accessible/src/xul/XULTreeAccessible.cpp
accessible/src/xul/XULTreeAccessible.h
accessible/src/xul/XULTreeGridAccessible.cpp
accessible/src/xul/XULTreeGridAccessible.h
--- a/accessible/src/atk/ApplicationAccessibleWrap.cpp
+++ b/accessible/src/atk/ApplicationAccessibleWrap.cpp
@@ -506,22 +506,64 @@ add_listener (GSignalEmissionHook listen
     else {
         g_warning("Invalid object type %s\n", object_type);
     }
     return rc;
 }
 
 static nsresult LoadGtkModule(GnomeAccessibilityModule& aModule);
 
+static gboolean toplevel_event_watcher(GSignalInvocationHint*, guint,
+                                       const GValue*, gpointer);
+
 // ApplicationAccessibleWrap
 
 ApplicationAccessibleWrap::ApplicationAccessibleWrap():
   ApplicationAccessible()
 {
   MAI_LOG_DEBUG(("======Create AppRootAcc=%p\n", (void*)this));
+
+  if (ShouldA11yBeEnabled()) {
+      // Load and initialize gail library.
+      nsresult rv = LoadGtkModule(sGail);
+      if (NS_SUCCEEDED(rv)) {
+          (*sGail.init)();
+      } else {
+          MAI_LOG_DEBUG(("Fail to load lib: %s\n", sGail.libName));
+      }
+
+      MAI_LOG_DEBUG(("Mozilla Atk Implementation initializing\n"));
+
+      // Initialize the MAI Utility class, it will overwrite gail_util.
+      g_type_class_unref(g_type_class_ref(MAI_TYPE_UTIL));
+
+      // Init atk-bridge now
+      PR_SetEnv("NO_AT_BRIDGE=0");
+
+      // load and initialize atk-bridge library
+      rv = LoadGtkModule(sAtkBridge);
+      if (NS_SUCCEEDED(rv)) {
+          (*sAtkBridge.init)();
+      } else {
+          MAI_LOG_DEBUG(("Fail to load lib: %s\n", sAtkBridge.libName));
+      }
+
+      if (!sToplevel_event_hook_added) {
+        sToplevel_event_hook_added = true;
+        sToplevel_show_hook =
+          g_signal_add_emission_hook(g_signal_lookup("show", GTK_TYPE_WINDOW),
+            0, toplevel_event_watcher,
+            reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW), NULL);
+        sToplevel_hide_hook =
+          g_signal_add_emission_hook(g_signal_lookup("hide", GTK_TYPE_WINDOW),
+            0, toplevel_event_watcher,
+            reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_HIDE), NULL);
+      }
+  }
+
 }
 
 ApplicationAccessibleWrap::~ApplicationAccessibleWrap()
 {
   MAI_LOG_DEBUG(("======Destory AppRootAcc=%p\n", (void*)this));
   AccessibleWrap::ShutdownAtkObject();
 }
 
@@ -569,62 +611,16 @@ toplevel_event_watcher(GSignalInvocation
 
     }
   }
 
   return TRUE;
 }
 
 void
-ApplicationAccessibleWrap::Init()
-{
-    if (ShouldA11yBeEnabled()) {
-        // load and initialize gail library
-        nsresult rv = LoadGtkModule(sGail);
-        if (NS_SUCCEEDED(rv)) {
-            (*sGail.init)();
-        }
-        else {
-            MAI_LOG_DEBUG(("Fail to load lib: %s\n", sGail.libName));
-        }
-
-        MAI_LOG_DEBUG(("Mozilla Atk Implementation initializing\n"));
-        // Initialize the MAI Utility class
-        // it will overwrite gail_util
-        g_type_class_unref(g_type_class_ref(MAI_TYPE_UTIL));
-
-        // Init atk-bridge now
-        PR_SetEnv("NO_AT_BRIDGE=0");
-
-        // load and initialize atk-bridge library
-        rv = LoadGtkModule(sAtkBridge);
-        if (NS_SUCCEEDED(rv)) {
-            // init atk-bridge
-            (*sAtkBridge.init)();
-        } else {
-            MAI_LOG_DEBUG(("Fail to load lib: %s\n", sAtkBridge.libName));
-        }
-
-        if (!sToplevel_event_hook_added) {
-          sToplevel_event_hook_added = true;
-          sToplevel_show_hook =
-            g_signal_add_emission_hook(g_signal_lookup("show", GTK_TYPE_WINDOW),
-              0, toplevel_event_watcher,
-              reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW), NULL);
-          sToplevel_hide_hook =
-            g_signal_add_emission_hook(g_signal_lookup("hide", GTK_TYPE_WINDOW),
-              0, toplevel_event_watcher,
-              reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_HIDE), NULL);
-        }
-    }
-
-    ApplicationAccessible::Init();
-}
-
-void
 ApplicationAccessibleWrap::Unload()
 {
     if (sToplevel_event_hook_added) {
       sToplevel_event_hook_added = false;
       g_signal_remove_emission_hook(g_signal_lookup("show", GTK_TYPE_WINDOW),
                                     sToplevel_show_hook);
       g_signal_remove_emission_hook(g_signal_lookup("hide", GTK_TYPE_WINDOW),
                                     sToplevel_hide_hook);
--- a/accessible/src/atk/ApplicationAccessibleWrap.h
+++ b/accessible/src/atk/ApplicationAccessibleWrap.h
@@ -17,19 +17,16 @@ class ApplicationAccessibleWrap: public 
 public:
   static void Unload();
   static void PreCreate();
 
 public:
   ApplicationAccessibleWrap();
   virtual ~ApplicationAccessibleWrap();
 
-  // nsAccessNode
-  virtual void Init();
-
   // Accessible
   virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
   virtual bool AppendChild(Accessible* aChild);
   virtual bool RemoveChild(Accessible* aChild);
 
   /**
    * Return the atk object for app root accessible.
    */
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -975,17 +975,16 @@ nsAccessibilityService::Init()
 #ifdef A11Y_LOG
   logging::CheckEnv();
 #endif
 
   // Create and initialize the application accessible.
   ApplicationAccessibleWrap::PreCreate();
   gApplicationAccessible = new ApplicationAccessibleWrap();
   NS_ADDREF(gApplicationAccessible); // will release in Shutdown()
-  gApplicationAccessible->Init();
 
   // Initialize accessibility.
   nsAccessNodeWrap::InitAccessibility();
 
 #ifdef MOZ_CRASHREPORTER
   CrashReporter::
     AnnotateCrashReport(NS_LITERAL_CSTRING("Accessibility"),
                         NS_LITERAL_CSTRING("Active"));
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -185,21 +185,16 @@ Accessible::Accessible(nsIContent* aCont
 
 //-----------------------------------------------------
 // destruction
 //-----------------------------------------------------
 Accessible::~Accessible()
 {
 }
 
-void
-Accessible::Init()
-{
-}
-
 NS_IMETHODIMP
 Accessible::GetDocument(nsIAccessibleDocument** aDocument)
 {
   NS_ENSURE_ARG_POINTER(aDocument);
 
   NS_IF_ADDREF(*aDocument = Document());
   return NS_OK;
 }
--- a/accessible/src/generic/Accessible.h
+++ b/accessible/src/generic/Accessible.h
@@ -122,21 +122,16 @@ public:
   // nsAccessNode
 
   virtual void Shutdown();
 
   //////////////////////////////////////////////////////////////////////////////
   // Public methods
 
   /**
-   * Initialize the accessible.
-   */
-  virtual void Init();
-
-  /**
    * Get the description of this accessible.
    */
   virtual void Description(nsString& aDescription);
 
   /**
    * Get the value of this accessible.
    */
   virtual void Value(nsString& aValue);
--- a/accessible/src/generic/ApplicationAccessible.cpp
+++ b/accessible/src/generic/ApplicationAccessible.cpp
@@ -22,16 +22,17 @@
 #include "nsIStringBundle.h"
 
 using namespace mozilla::a11y;
 
 ApplicationAccessible::ApplicationAccessible() :
   AccessibleWrap(nullptr, nullptr)
 {
   mFlags |= eApplicationAccessible;
+  mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 NS_IMPL_ISUPPORTS_INHERITED1(ApplicationAccessible, Accessible,
                              nsIAccessibleApplication)
 
@@ -262,22 +263,16 @@ ApplicationAccessible::GetPlatformVersio
   AppendUTF8toUTF16(cversion, aVersion);
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessNode public methods
 
 void
-ApplicationAccessible::Init()
-{
-  mAppInfo = do_GetService("@mozilla.org/xre/app-info;1");
-}
-
-void
 ApplicationAccessible::Shutdown()
 {
   mAppInfo = nullptr;
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // Accessible public methods
--- a/accessible/src/generic/ApplicationAccessible.h
+++ b/accessible/src/generic/ApplicationAccessible.h
@@ -53,17 +53,16 @@ public:
   NS_IMETHOD GetActionName(uint8_t aIndex, nsAString &aName);
   NS_IMETHOD GetActionDescription(uint8_t aIndex, nsAString &aDescription);
   NS_IMETHOD DoAction(uint8_t aIndex);
 
   // nsIAccessibleApplication
   NS_DECL_NSIACCESSIBLEAPPLICATION
 
   // nsAccessNode
-  virtual void Init();
   virtual void Shutdown();
 
   // Accessible
   virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE;
   virtual GroupPos GroupPosition();
   virtual ENameValueFlag Name(nsString& aName);
   virtual void ApplyARIAState(uint64_t* aState) const;
   virtual void Description(nsString& aDescription);
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -708,52 +708,36 @@ DocAccessible::GetBoundsRect(nsRect& aBo
     document = parentDoc = document->GetParentDocument();
   }
 }
 
 // DocAccessible protected member
 nsresult
 DocAccessible::AddEventListeners()
 {
-  // 1) Set up scroll position listener
-  // 2) Check for editor and listen for changes to editor
-
-  NS_ENSURE_TRUE(mPresShell, NS_ERROR_FAILURE);
-
   nsCOMPtr<nsISupports> container = mDocumentNode->GetContainer();
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(container));
-  NS_ENSURE_TRUE(docShellTreeItem, NS_ERROR_FAILURE);
 
-  // Make sure we're a content docshell
-  // We don't want to listen to chrome progress
+  // We want to add a command observer only if the document is content and has
+  // an editor.
   int32_t itemType;
   docShellTreeItem->GetItemType(&itemType);
-
-  bool isContent = (itemType == nsIDocShellTreeItem::typeContent);
-
-  if (isContent) {
-    // We're not an editor yet, but we might become one
+  if (itemType == nsIDocShellTreeItem::typeContent) {
     nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
-    if (commandManager) {
+    if (commandManager)
       commandManager->AddCommandObserver(this, "obs_documentCreated");
-    }
   }
 
-  nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
-  docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
-  if (rootTreeItem) {
-    a11y::RootAccessible* rootAccessible = RootAccessible();
-    NS_ENSURE_TRUE(rootAccessible, NS_ERROR_FAILURE);
-    nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
-    if (caretAccessible) {
-      caretAccessible->AddDocSelectionListener(mPresShell);
-    }
-  }
+  a11y::RootAccessible* rootAccessible = RootAccessible();
+  NS_ENSURE_TRUE(rootAccessible, NS_ERROR_FAILURE);
+  nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
+  if (caretAccessible)
+    caretAccessible->AddDocSelectionListener(mPresShell);
 
-  // add document observer
+  // Add document observer.
   mDocumentNode->AddObserver(this);
   return NS_OK;
 }
 
 // DocAccessible protected member
 nsresult
 DocAccessible::RemoveEventListeners()
 {
@@ -1370,19 +1354,16 @@ DocAccessible::BindToDocument(Accessible
 
   // Put into DOM node cache.
   if (aAccessible->IsNodeMapEntry())
     mNodeToAccessibleMap.Put(aAccessible->GetNode(), aAccessible);
 
   // Put into unique ID cache.
   mAccessibleCache.Put(aAccessible->UniqueID(), aAccessible);
 
-  // Initialize the accessible.
-  aAccessible->Init();
-
   aAccessible->SetRoleMapEntry(aRoleMapEntry);
   if (aAccessible->IsElement())
     AddDependentIDsFor(aAccessible);
 
   return true;
 }
 
 void
--- a/accessible/src/generic/RootAccessible.cpp
+++ b/accessible/src/generic/RootAccessible.cpp
@@ -146,27 +146,26 @@ RootAccessible::NativeState()
 
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
   if (fm && fm->GetActiveWindow() == mDocumentNode->GetWindow())
     state |= states::ACTIVE;
 
   return state;
 }
 
-const char* const docEvents[] = {
+const char* const kEventTypes[] = {
 #ifdef DEBUG_DRAGDROPSTART
   // Capture mouse over events and fire fake DRAGDROPSTART event to simplify
-  // debugging a11y objects with event viewers
+  // debugging a11y objects with event viewers.
   "mouseover",
 #endif
-  // capture Form change events 
+  // Fired when list or tree selection changes.
   "select",
-  // capture ValueChange events (fired whenever value changes, immediately after, whether focus moves or not)
+  // Fired when value changes immediately, wether or not focused changed.
   "ValueChange",
-  // capture AlertActive events (fired whenever alert pops up)
   "AlertActive",
   "TreeRowCountChanged",
   "TreeInvalidated",
   // add ourself as a OpenStateChange listener (custom event fired in tree.xml)
   "OpenStateChange",
   // add ourself as a CheckboxStateChange listener (custom event fired in nsHTMLInputElement.cpp)
   "CheckboxStateChange",
   // add ourself as a RadioStateChange Listener ( custom event fired in in nsHTMLInputElement.cpp  & radio.xml)
@@ -185,18 +184,18 @@ RootAccessible::AddEventListeners()
 {
   // nsIDOMEventTarget interface allows to register event listeners to
   // receive untrusted events (synthetic events generated by untrusted code).
   // For example, XBL bindings implementations for elements that are hosted in
   // non chrome document fire untrusted events.
   nsCOMPtr<nsIDOMEventTarget> nstarget(do_QueryInterface(mDocumentNode));
 
   if (nstarget) {
-    for (const char* const* e = docEvents,
-                   * const* e_end = ArrayEnd(docEvents);
+    for (const char* const* e = kEventTypes,
+                   * const* e_end = ArrayEnd(kEventTypes);
          e < e_end; ++e) {
       nsresult rv = nstarget->AddEventListener(NS_ConvertASCIItoUTF16(*e),
                                                this, true, true, 2);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   if (!mCaretAccessible) {
@@ -206,18 +205,18 @@ RootAccessible::AddEventListeners()
   return DocAccessible::AddEventListeners();
 }
 
 nsresult
 RootAccessible::RemoveEventListeners()
 {
   nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mDocumentNode));
   if (target) { 
-    for (const char* const* e = docEvents,
-                   * const* e_end = ArrayEnd(docEvents);
+    for (const char* const* e = kEventTypes,
+                   * const* e_end = ArrayEnd(kEventTypes);
          e < e_end; ++e) {
       nsresult rv = target->RemoveEventListener(NS_ConvertASCIItoUTF16(*e), this, true);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // Do this before removing clearing caret accessible, so that it can use
   // shutdown the caret accessible's selection listener
--- a/accessible/src/xul/XULTreeAccessible.cpp
+++ b/accessible/src/xul/XULTreeAccessible.cpp
@@ -1095,16 +1095,17 @@ XULTreeItemAccessibleBase::GetCellName(n
 
 XULTreeItemAccessible::
   XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc,
                         Accessible* aParent, nsITreeBoxObject* aTree,
                         nsITreeView* aTreeView, int32_t aRow) :
   XULTreeItemAccessibleBase(aContent, aDoc, aParent, aTree, aTreeView, aRow)
 {
   mColumn = nsCoreUtils::GetFirstSensibleColumn(mTree);
+  GetCellName(mColumn, mCachedName);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULTreeItemAccessible: nsISupports implementation
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(XULTreeItemAccessible)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XULTreeItemAccessible,
@@ -1133,23 +1134,16 @@ XULTreeItemAccessible::Name(nsString& aN
   GetCellName(mColumn, aName);
   return eNameOK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULTreeItemAccessible: nsAccessNode implementation
 
 void
-XULTreeItemAccessible::Init()
-{
-  XULTreeItemAccessibleBase::Init();
-  Name(mCachedName);
-}
-
-void
 XULTreeItemAccessible::Shutdown()
 {
   mColumn = nullptr;
   XULTreeItemAccessibleBase::Shutdown();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULTreeItemAccessible: Accessible implementation
--- a/accessible/src/xul/XULTreeAccessible.h
+++ b/accessible/src/xul/XULTreeAccessible.h
@@ -228,17 +228,16 @@ public:
                         nsITreeView* aTreeView, int32_t aRow);
 
   // nsISupports and cycle collection
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible,
                                            XULTreeItemAccessibleBase)
 
   // nsAccessNode
-  virtual void Init();
   virtual void Shutdown();
 
   // Accessible
   virtual ENameValueFlag Name(nsString& aName);
   virtual a11y::role NativeRole();
 
   // XULTreeItemAccessibleBase
   virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx);
--- a/accessible/src/xul/XULTreeGridAccessible.cpp
+++ b/accessible/src/xul/XULTreeGridAccessible.cpp
@@ -464,16 +464,25 @@ XULTreeGridCellAccessible::
                             XULTreeGridRowAccessible* aRowAcc,
                             nsITreeBoxObject* aTree, nsITreeView* aTreeView,
                             int32_t aRow, nsITreeColumn* aColumn) :
   LeafAccessible(aContent, aDoc), xpcAccessibleTableCell(this), mTree(aTree),
   mTreeView(aTreeView), mRow(aRow), mColumn(aColumn)
 {
   mParent = aRowAcc;
   mFlags |= eSharedNode;
+
+  NS_ASSERTION(mTreeView, "mTreeView is null");
+
+  int16_t type = -1;
+  mColumn->GetType(&type);
+  if (type == nsITreeColumn::TYPE_CHECKBOX)
+    mTreeView->GetCellValue(mRow, mColumn, mCachedTextEquiv);
+  else
+    mTreeView->GetCellText(mRow, mColumn, mCachedTextEquiv);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULTreeGridCellAccessible: nsISupports implementation
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(XULTreeGridCellAccessible)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XULTreeGridCellAccessible,
@@ -701,34 +710,16 @@ XULTreeGridCellAccessible::Selected()
   NS_ENSURE_SUCCESS(rv, false);
 
   bool selected = false;
   selection->IsSelected(mRow, &selected);
   return selected;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-// XULTreeGridCellAccessible: nsAccessNode implementation
-
-void
-XULTreeGridCellAccessible::Init()
-{
-  LeafAccessible::Init();
-
-  NS_ASSERTION(mTreeView, "mTreeView is null");
-
-  int16_t type;
-  mColumn->GetType(&type);
-  if (type == nsITreeColumn::TYPE_CHECKBOX)
-    mTreeView->GetCellValue(mRow, mColumn, mCachedTextEquiv);
-  else
-    mTreeView->GetCellText(mRow, mColumn, mCachedTextEquiv);
-}
-
-////////////////////////////////////////////////////////////////////////////////
 // XULTreeGridCellAccessible: Accessible public implementation
 
 already_AddRefed<nsIPersistentProperties>
 XULTreeGridCellAccessible::NativeAttributes()
 {
   nsCOMPtr<nsIPersistentProperties> attributes =
     do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
 
--- a/accessible/src/xul/XULTreeGridAccessible.h
+++ b/accessible/src/xul/XULTreeGridAccessible.h
@@ -145,19 +145,16 @@ public:
                        int32_t* aWidth, int32_t* aHeight);
 
   NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName);
   NS_IMETHOD DoAction(uint8_t aIndex);
 
   // nsIAccessibleTableCell
   NS_FORWARD_NSIACCESSIBLETABLECELL(xpcAccessibleTableCell::)
 
-  // nsAccessNode
-  virtual void Init();
-
   // Accessible
   virtual TableCellAccessible* AsTableCell() { return this; }
   virtual void Shutdown();
   virtual ENameValueFlag Name(nsString& aName);
   virtual Accessible* FocusedChild();
   virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE;
   virtual int32_t IndexInParent() const;
   virtual Relation RelationByType(uint32_t aType);