Fix for bug 377756 - move property change events code to atk, r=ginn.chen
authorsurkov.alexander@gmail.com
Fri, 20 Apr 2007 00:29:08 -0700
changeset 667 c440163b799a1b0a21b93ebd7a27e629b1b19d1f
parent 666 d2d98446305961142cade0e4fb9b9ff9d0e8d8a0
child 668 e5e4eabd10b7676267124f0e06cfb8cb1ce7ab95
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersginn
bugs377756
milestone1.9a4pre
Fix for bug 377756 - move property change events code to atk, r=ginn.chen
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsAccessibleWrap.h
accessible/src/atk/nsDocAccessibleWrap.cpp
accessible/src/base/nsAccessibleEventData.h
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -248,16 +248,36 @@ mai_atk_object_get_type(void)
         };
 
         type = g_type_register_static(ATK_TYPE_OBJECT,
                                       "MaiAtkObject", &tinfo, GTypeFlags(0));
     }
     return type;
 }
 
+/*
+ * Must keep sychronization with enumerate AtkProperty in 
+ * accessible/src/base/nsAccessibleEventData.h
+ */
+static char * sAtkPropertyNameArray[PROP_LAST] = {
+    0,
+    "accessible-name",
+    "accessible-description",
+    "accessible-parent",
+    "accessible-role",
+    "accessible-layer",
+    "accessible-mdi-zorder",
+    "accessible-table-caption",
+    "accessible-table-column-description",
+    "accessible-table-column-header",
+    "accessible-table-row-description",
+    "accessible-table-row-header",
+    "accessible-table-summary"
+};
+
 #ifdef MAI_LOGGING
 PRInt32 nsAccessibleWrap::mAccWrapCreated = 0;
 PRInt32 nsAccessibleWrap::mAccWrapDeleted = 0;
 #endif
 
 nsAccessibleWrap::nsAccessibleWrap(nsIDOMNode* aNode,
                                    nsIWeakReference *aShell)
     : nsAccessible(aNode, aShell),
@@ -1034,73 +1054,160 @@ nsAccessibleWrap::FireAccessibleEvent(ns
     NS_ENSURE_TRUE(atkObj, NS_ERROR_FAILURE);
 
     PRUint32 type = 0;
     rv = aEvent->GetEventType(&type);
     NS_ENSURE_SUCCESS(rv, rv);
 
     switch (type) {
     case nsIAccessibleEvent::EVENT_STATE_CHANGE:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_STATE_CHANGE\n"));
-
-        nsCOMPtr<nsIAccessibleStateChangeEvent> event =
-          do_QueryInterface(aEvent);
-        NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
-
-        PRUint32 state = 0;
-        event->GetState(&state);
-
-        PRBool isExtra;
-        event->IsExtraState(&isExtra);
-
-        PRBool isEnabled;
-        event->IsEnabled(&isEnabled);
-
-        PRInt32 stateIndex = AtkStateMap::GetStateIndexFor(state);
-        if (stateIndex >= 0) {
-            const AtkStateMap *atkStateMap = isExtra ? gAtkStateMapExt : gAtkStateMap;
-            NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoSuchState,
-                         "No such state");
-
-            if (atkStateMap[stateIndex].atkState != kNone) {
-                NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoStateChange,
-                             "State changes should not fired for this state");
-
-              if (atkStateMap[stateIndex].stateMapEntryType == kMapOpposite)
-                  isEnabled = !isEnabled;
-
-              // Fire state change for first state if there is one to map
-              atk_object_notify_state_change(atkObj,
-                                             atkStateMap[stateIndex].atkState,
-                                             isEnabled);
-            }
-        }
-        break;
-      }
+        return FireAtkStateChangeEvent(aEvent, atkObj);
 
     case nsIAccessibleEvent::EVENT_TEXT_CHANGED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_CHANGED\n"));
+        return FireAtkTextChangedEvent(aEvent, atkObj);
+
+    case nsIAccessibleEvent::EVENT_PROPERTY_CHANGED:
+        return FireAtkPropChangedEvent(aEvent, atkObj);
+    }
+
+    return NS_OK;
+}
 
-        nsCOMPtr<nsIAccessibleTextChangeEvent> event =
-          do_QueryInterface(aEvent);
-        NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
+nsresult
+nsAccessibleWrap::FireAtkStateChangeEvent(nsIAccessibleEvent *aEvent,
+                                          AtkObject *aObject)
+{
+    MAI_LOG_DEBUG(("\n\nReceived: EVENT_STATE_CHANGE\n"));
 
-        PRInt32 start = 0;
-        event->GetStart(&start);
+    nsCOMPtr<nsIAccessibleStateChangeEvent> event =
+        do_QueryInterface(aEvent);
+    NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
+
+    PRUint32 state = 0;
+    event->GetState(&state);
 
-        PRUint32 length = 0;
-        event->GetLength(&length);
+    PRBool isExtra;
+    event->IsExtraState(&isExtra);
+
+    PRBool isEnabled;
+    event->IsEnabled(&isEnabled);
 
-        PRBool isInserted;
-        event->IsInserted(&isInserted);
+    PRInt32 stateIndex = AtkStateMap::GetStateIndexFor(state);
+    if (stateIndex >= 0) {
+        const AtkStateMap *atkStateMap = isExtra ? gAtkStateMapExt : gAtkStateMap;
+        NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoSuchState,
+                     "No such state");
 
-        g_signal_emit_by_name (atkObj,
-                               isInserted ? \
-                               "text_changed::insert":"text_changed::delete",
-                               start,
-                               length);
-        break;
+        if (atkStateMap[stateIndex].atkState != kNone) {
+            NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoStateChange,
+                         "State changes should not fired for this state");
+
+            if (atkStateMap[stateIndex].stateMapEntryType == kMapOpposite)
+                isEnabled = !isEnabled;
+
+            // Fire state change for first state if there is one to map
+            atk_object_notify_state_change(aObject,
+                                           atkStateMap[stateIndex].atkState,
+                                           isEnabled);
+        }
     }
 
     return NS_OK;
 }
 
+nsresult
+nsAccessibleWrap::FireAtkTextChangedEvent(nsIAccessibleEvent *aEvent,
+                                          AtkObject *aObject)
+{
+    MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_CHANGED\n"));
+
+    nsCOMPtr<nsIAccessibleTextChangeEvent> event =
+        do_QueryInterface(aEvent);
+    NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
+
+    PRInt32 start = 0;
+    event->GetStart(&start);
+
+    PRUint32 length = 0;
+    event->GetLength(&length);
+
+    PRBool isInserted;
+    event->IsInserted(&isInserted);
+
+    g_signal_emit_by_name (aObject,
+                           isInserted ? \
+                           "text_changed::insert":"text_changed::delete",
+                           start,
+                           length);
+
+    return NS_OK;
+}
+
+nsresult
+nsAccessibleWrap::FireAtkPropChangedEvent(nsIAccessibleEvent *aEvent,
+                                          AtkObject *aObject)
+{
+    MAI_LOG_DEBUG(("\n\nReceived: EVENT_PROPERTY_CHANGED\n"));
+
+    AtkPropertyChange *pAtkPropChange;
+    AtkPropertyValues values = { NULL };
+    nsAccessibleWrap *oldAccWrap = nsnull, *newAccWrap = nsnull;
+
+    nsAccEvent *event = NS_REINTERPRET_CAST(nsAccEvent*, aEvent);
+
+    pAtkPropChange = NS_REINTERPRET_CAST(AtkPropertyChange *, event->mEventData);
+    values.property_name = sAtkPropertyNameArray[pAtkPropChange->type];
+
+    NS_ASSERTION(pAtkPropChange, "Event needs event data");
+    if (!pAtkPropChange)
+        return NS_OK;
+
+    MAI_LOG_DEBUG(("\n\nthe type of EVENT_PROPERTY_CHANGED: %d\n\n",
+                   pAtkPropChange->type));
+
+    switch (pAtkPropChange->type) {
+    case PROP_TABLE_CAPTION:
+    case PROP_TABLE_SUMMARY:
+
+        if (pAtkPropChange->oldvalue)
+            oldAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *,
+                                             pAtkPropChange->oldvalue);
+
+        if (pAtkPropChange->newvalue)
+            newAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *,
+                                             pAtkPropChange->newvalue);
+
+        if (oldAccWrap && newAccWrap) {
+            g_value_init(&values.old_value, G_TYPE_POINTER);
+            g_value_set_pointer(&values.old_value,
+                                oldAccWrap->GetAtkObject());
+            g_value_init(&values.new_value, G_TYPE_POINTER);
+            g_value_set_pointer(&values.new_value,
+                                newAccWrap->GetAtkObject());
+        }
+        break;
+
+    case PROP_TABLE_COLUMN_DESCRIPTION:
+    case PROP_TABLE_COLUMN_HEADER:
+    case PROP_TABLE_ROW_HEADER:
+    case PROP_TABLE_ROW_DESCRIPTION:
+        g_value_init(&values.new_value, G_TYPE_INT);
+        g_value_set_int(&values.new_value,
+                        *NS_REINTERPRET_CAST(gint *,
+                                             pAtkPropChange->newvalue));
+        break;
+
+        //Perhaps need more cases in the future
+    default:
+        g_value_init (&values.old_value, G_TYPE_POINTER);
+        g_value_set_pointer (&values.old_value, pAtkPropChange->oldvalue);
+        g_value_init (&values.new_value, G_TYPE_POINTER);
+        g_value_set_pointer (&values.new_value, pAtkPropChange->newvalue);
+    }
+
+    char *signal_name = g_strconcat("property_change::",
+                                    values.property_name, NULL);
+    g_signal_emit_by_name(aObject, signal_name, &values, NULL);
+    g_free (signal_name);
+
+    return NS_OK;
+}
+
--- a/accessible/src/atk/nsAccessibleWrap.h
+++ b/accessible/src/atk/nsAccessibleWrap.h
@@ -48,16 +48,39 @@
 
 #ifdef PR_LOGGING
 #define MAI_LOGGING
 #endif /* #ifdef PR_LOGGING */
 
 struct _AtkObject;
 typedef struct _AtkObject AtkObject;
 
+enum AtkProperty {
+  PROP_0,           // gobject convention
+  PROP_NAME,
+  PROP_DESCRIPTION,
+  PROP_PARENT,      // ancestry has changed
+  PROP_ROLE,
+  PROP_LAYER,
+  PROP_MDI_ZORDER,
+  PROP_TABLE_CAPTION,
+  PROP_TABLE_COLUMN_DESCRIPTION,
+  PROP_TABLE_COLUMN_HEADER,
+  PROP_TABLE_ROW_DESCRIPTION,
+  PROP_TABLE_ROW_HEADER,
+  PROP_TABLE_SUMMARY,
+  PROP_LAST         // gobject convention
+};
+
+struct AtkPropertyChange {
+  PRInt32 type;     // property type as listed above
+  void *oldvalue;
+  void *newvalue;
+};
+
 /**
  * nsAccessibleWrap, and its descendents in atk directory provide the
  * implementation of AtkObject.
  */
 class nsAccessibleWrap: public nsAccessible
 {
 public:
     nsAccessibleWrap(nsIDOMNode*, nsIWeakReference *aShell);
@@ -80,15 +103,22 @@ public:
 
     static const char * ReturnString(nsAString &aString) {
       static nsCString returnedString;
       returnedString = NS_ConvertUTF16toUTF8(aString);
       return returnedString.get();
     }
     
 protected:
+    nsresult FireAtkStateChangeEvent(nsIAccessibleEvent *aEvent,
+                                     AtkObject *aObject);
+    nsresult FireAtkTextChangedEvent(nsIAccessibleEvent *aEvent,
+                                     AtkObject *aObject);
+    nsresult FireAtkPropChangedEvent(nsIAccessibleEvent *aEvent,
+                                     AtkObject *aObject);
+
     AtkObject *mAtkObject;
 
 private:
     PRUint16 CreateMaiInterfaces(void);
 };
 
 #endif /* __NS_ACCESSIBLE_WRAP_H__ */
--- a/accessible/src/atk/nsDocAccessibleWrap.cpp
+++ b/accessible/src/atk/nsDocAccessibleWrap.cpp
@@ -50,36 +50,16 @@
 #include <atk/atk.h>
 #include <glib.h>
 #include <glib-object.h>
 
 #include "nsStateMap.h"
 
 //----- nsDocAccessibleWrap -----
 
-/*
- * Must keep sychronization with enumerate AtkProperty in 
- * accessible/src/base/nsAccessibleEventData.h
- */
-static char * sAtkPropertyNameArray[PROP_LAST] = {
-    0,
-    "accessible-name",
-    "accessible-description",
-    "accessible-parent",
-    "accessible-role",
-    "accessible-layer",
-    "accessible-mdi-zorder",
-    "accessible-table-caption",
-    "accessible-table-column-description",
-    "accessible-table-column-header",
-    "accessible-table-row-description",
-    "accessible-table-row-header",
-    "accessible-table-summary"
-};
-
 nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode,
                                          nsIWeakReference *aShell): 
   nsDocAccessible(aDOMNode, aShell), mActivated(PR_FALSE)
 {
 }
 
 nsDocAccessibleWrap::~nsDocAccessibleWrap()
 {
@@ -102,17 +82,16 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireT
                    aEvent, aAccessible, aEventData));
     // We don't create ATK objects for nsIAccessible plain text leaves,
     // just return NS_OK in such case
     AtkObject *atkObj = accWrap->GetAtkObject();
     if (!atkObj) {
       return NS_OK;
     }
 
-    nsAccessibleWrap *oldAccWrap = nsnull, *newAccWrap = nsnull;
     AtkTableChange * pAtkTableChange = nsnull;
 
     switch (aEvent) {
     case nsIAccessibleEvent::EVENT_FOCUS:
       {
         MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
         nsRefPtr<nsRootAccessible> rootAccWrap = accWrap->GetRootAccessible();
         if (rootAccWrap && rootAccWrap->mActivated) {
@@ -126,86 +105,16 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireT
         nsCOMPtr<nsIAccessibleValue> value(do_QueryInterface(aAccessible));
         if (value) {    // Make sure this is a numeric value
           // Don't fire for MSAA string value changes (e.g. text editing)
           // ATK values are always numeric
           g_object_notify( (GObject*)atkObj, "accessible-value" );
         }
       }
       break;
-        
-    /*
-     * Need handle each type of property change separately.
-     */        
-    case nsIAccessibleEvent::EVENT_PROPERTY_CHANGED :
-      {
-        AtkPropertyChange *pAtkPropChange;
-        AtkPropertyValues values = { NULL };
-
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_PROPERTY_CHANGED\n"));
-        NS_ASSERTION(aEventData, "Event needs event data");
-        if (!aEventData)
-            break;
-
-        pAtkPropChange = NS_REINTERPRET_CAST(AtkPropertyChange *, aEventData);
-        values.property_name = sAtkPropertyNameArray[pAtkPropChange->type];
-        
-        MAI_LOG_DEBUG(("\n\nthe type of EVENT_PROPERTY_CHANGED: %d\n\n",
-                       pAtkPropChange->type));
-
-        switch (pAtkPropChange->type) {
-        case PROP_TABLE_CAPTION:
-        case PROP_TABLE_SUMMARY:
-
-            if (pAtkPropChange->oldvalue)
-                oldAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *,
-                                                 pAtkPropChange->oldvalue);
-
-            if (pAtkPropChange->newvalue)
-                newAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *,
-                                                 pAtkPropChange->newvalue);
-
-            if (oldAccWrap && newAccWrap) {
-                g_value_init(&values.old_value, G_TYPE_POINTER);
-                g_value_set_pointer(&values.old_value,
-                                    oldAccWrap->GetAtkObject());
-                g_value_init(&values.new_value, G_TYPE_POINTER);
-                g_value_set_pointer(&values.new_value,
-                                    newAccWrap->GetAtkObject());
-                rv = NS_OK;
-            }
-            break;
-
-        case PROP_TABLE_COLUMN_DESCRIPTION:
-        case PROP_TABLE_COLUMN_HEADER:
-        case PROP_TABLE_ROW_HEADER:
-        case PROP_TABLE_ROW_DESCRIPTION:
-            g_value_init(&values.new_value, G_TYPE_INT);
-            g_value_set_int(&values.new_value,
-                            *NS_REINTERPRET_CAST(gint *,
-                                                 pAtkPropChange->newvalue));
-            rv = NS_OK;
-            break;
-  
-            //Perhaps need more cases in the future
-        default:
-            g_value_init (&values.old_value, G_TYPE_POINTER);
-            g_value_set_pointer (&values.old_value, pAtkPropChange->oldvalue);
-            g_value_init (&values.new_value, G_TYPE_POINTER);
-            g_value_set_pointer (&values.new_value, pAtkPropChange->newvalue);
-            rv = NS_OK;
-        }
-        if (NS_SUCCEEDED(rv)) {
-            char *signal_name = g_strconcat("property_change::",
-                                            values.property_name, NULL);
-            g_signal_emit_by_name(atkObj, signal_name, &values, NULL);
-            g_free (signal_name);
-        }
-      }
-        break;
 
     case nsIAccessibleEvent::EVENT_SELECTION_CHANGED:
         MAI_LOG_DEBUG(("\n\nReceived: EVENT_SELECTION_CHANGED\n"));
         g_signal_emit_by_name(atkObj, "selection_changed");
         rv = NS_OK;
         break;
 
     case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
--- a/accessible/src/base/nsAccessibleEventData.h
+++ b/accessible/src/base/nsAccessibleEventData.h
@@ -58,16 +58,18 @@ public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIACCESSIBLEEVENT
 
 private:
   PRUint32 mEventType;
   nsCOMPtr<nsIAccessible> mAccessible;
   nsCOMPtr<nsIDOMNode> mDOMNode;
   nsCOMPtr<nsIAccessibleDocument> mDocAccessible;
+
+public:
   void *mEventData;
 };
 
 class nsAccStateChangeEvent: public nsAccEvent,
                              public nsIAccessibleStateChangeEvent
 {
 public:
   nsAccStateChangeEvent(nsIAccessible *aAccessible,
@@ -106,39 +108,16 @@ private:
   PRInt32 mStart;
   PRUint32 mLength;
   PRBool mIsInserted;
 };
 
 // XXX todo: We might want to use XPCOM interfaces instead of structs
 //     e.g., nsAccessibleTextChangeEvent: public nsIAccessibleTextChangeEvent
 
-enum AtkProperty {
-  PROP_0,           // gobject convention
-  PROP_NAME,
-  PROP_DESCRIPTION,
-  PROP_PARENT,      // ancestry has changed
-  PROP_ROLE,
-  PROP_LAYER,
-  PROP_MDI_ZORDER,
-  PROP_TABLE_CAPTION,
-  PROP_TABLE_COLUMN_DESCRIPTION,
-  PROP_TABLE_COLUMN_HEADER,
-  PROP_TABLE_ROW_DESCRIPTION,
-  PROP_TABLE_ROW_HEADER,
-  PROP_TABLE_SUMMARY,
-  PROP_LAST         // gobject convention
-};
-
-struct AtkPropertyChange {
-  PRInt32 type;     // property type as listed above 
-  void *oldvalue;  
-  void *newvalue;
-};
-
 struct AtkChildrenChange {
   PRInt32      index;  // index of child in parent 
   nsIAccessible *child;   
   PRBool        add;    // true for add, false for delete
 };
 
 struct AtkTableChange {
   PRUint32 index;   // the start row/column after which the rows are inserted/deleted.