Bug 382567 Use GetNativeInterface, GetAccessibleWrap instead of CASTr=surkov.alexander
authorginn.chen@sun.com
Mon, 04 Jun 2007 02:39:15 -0700
changeset 2092 45c1e5de31283a7cce996c14b6989a5cb841d73c
parent 2091 8dd6463fc0aba92bd6c1c0e30747138cd5243b49
child 2093 888f506ae2cd906e39e9ba358ca812541507dc87
push idunknown
push userunknown
push dateunknown
bugs382567
milestone1.9a6pre
Bug 382567 Use GetNativeInterface, GetAccessibleWrap instead of CASTr=surkov.alexander
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsDocAccessibleWrap.cpp
accessible/src/atk/nsMaiHyperlink.cpp
accessible/src/atk/nsMaiInterfaceComponent.cpp
accessible/src/atk/nsMaiInterfaceSelection.cpp
accessible/src/atk/nsMaiInterfaceTable.cpp
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -708,18 +708,17 @@ const gchar *
 getNameCB(AtkObject *aAtkObj)
 {
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return nsnull;
     }
 
     nsAutoString uniName;
 
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     /* nsIAccessible is responsible for the non-NULL name */
     nsresult rv = accWrap->GetName(uniName);
     NS_ENSURE_SUCCESS(rv, nsnull);
 
     if (uniName.Length() > 0) {
         NS_ConvertUTF8toUTF16 objName(aAtkObj->name);
         if (!uniName.Equals(objName)) {
@@ -736,18 +735,17 @@ getDescriptionCB(AtkObject *aAtkObj)
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return nsnull;
     }
 
     if (!aAtkObj->description) {
         gint len;
         nsAutoString uniDesc;
 
-        nsAccessibleWrap *accWrap =
-            NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+        nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
         /* nsIAccessible is responsible for the non-NULL description */
         nsresult rv = accWrap->GetDescription(uniDesc);
         NS_ENSURE_SUCCESS(rv, nsnull);
         len = uniDesc.Length();
         if (len > 0) {
             atk_object_set_description(aAtkObj,
                                        NS_ConvertUTF16toUTF8(uniDesc).get());
@@ -759,24 +757,22 @@ getDescriptionCB(AtkObject *aAtkObj)
 AtkRole
 getRoleCB(AtkObject *aAtkObj)
 {
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return ATK_ROLE_INVALID;
     }
 
 #ifdef DEBUG_A11Y
-        nsAccessibleWrap *testAccWrap =
-            NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+        nsAccessibleWrap *testAccWrap = GetAccessibleWrap(aAtkObj);
         NS_ASSERTION(nsAccessible::IsTextInterfaceSupportCorrect(testAccWrap), "Does not support nsIAccessibleText when it should");
 #endif
 
     if (aAtkObj->role == ATK_ROLE_INVALID) {
-        nsAccessibleWrap *accWrap =
-            NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+        nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
         PRUint32 accRole, atkRole;
         nsresult rv = accWrap->GetFinalRole(&accRole);
         NS_ENSURE_SUCCESS(rv, ATK_ROLE_INVALID);
 
         atkRole = atkRoleMap[accRole]; // map to the actual value
         NS_ASSERTION(atkRoleMap[nsIAccessibleRole::ROLE_LAST_ENTRY] ==
                      kROLE_ATK_LAST_ENTRY, "ATK role map skewed");
@@ -823,54 +819,50 @@ GetAttributeSet(nsIAccessible* aAccessib
 }
 
 AtkAttributeSet *
 getAttributesCB(AtkObject *aAtkObj)
 {
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return nsnull;
     }
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     return GetAttributeSet(accWrap);
 }
 
 AtkObject *
 getParentCB(AtkObject *aAtkObj)
 {
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return nsnull;
     }
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     nsCOMPtr<nsIAccessible> accParent;
     nsresult rv = accWrap->GetParent(getter_AddRefs(accParent));
     if (NS_FAILED(rv) || !accParent)
         return nsnull;
-    nsIAccessible *tmpParent = accParent;
-    nsAccessibleWrap *accWrapParent = NS_STATIC_CAST(nsAccessibleWrap *,
-                                                     tmpParent);
+
+    void *parentAtkObj = nsnull;
+    accParent->GetNativeInterface(&parentAtkObj);
 
-    AtkObject *parentAtkObj = accWrapParent->GetAtkObject();
     if (parentAtkObj && !aAtkObj->accessible_parent) {
-        atk_object_set_parent(aAtkObj, parentAtkObj);
+        atk_object_set_parent(aAtkObj, ATK_OBJECT(parentAtkObj));
     }
-    return parentAtkObj;
+    return aAtkObj->accessible_parent;
 }
 
 gint
 getChildCountCB(AtkObject *aAtkObj)
 {
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return 0;
     }
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     PRInt32 count = 0;
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
     if (hyperText) {
         // If HyperText, then number of links matches number of children
         hyperText->GetLinks(&count);
     }
@@ -894,18 +886,17 @@ refChildCB(AtkObject *aAtkObj, gint aChi
 
     // XXX Fix this so it is not O(n^2) to walk through the children!
     // Either we can cache the last accessed child so that we can just GetNextSibling()
     // or we should cache an array of children in each nsAccessible
     // (instead of mNextSibling on the children)
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return nsnull;
     }
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     nsresult rv;
     nsCOMPtr<nsIAccessible> accChild;
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
     if (hyperText) {
         // If HyperText, then number of links matches number of children
         nsCOMPtr<nsIAccessibleHyperLink> hyperLink;
@@ -918,41 +909,39 @@ refChildCB(AtkObject *aAtkObj, gint aChi
         if (!accText) {  // Accessible Text that is not HyperText has no children
             rv = accWrap->GetChildAt(aChildIndex, getter_AddRefs(accChild));
         }
     }
 
     if (NS_FAILED(rv) || !accChild)
         return nsnull;
 
-    nsIAccessible *tmpAccChild = accChild;
-    nsAccessibleWrap *accWrapChild =
-        NS_STATIC_CAST(nsAccessibleWrap*, tmpAccChild);
+    void* childAtkObjPtr = nsnull;
+    accChild->GetNativeInterface(&childAtkObjPtr);
 
+    NS_ASSERTION(childAtkObjPtr, "Fail to get AtkObj");
+    if (!childAtkObjPtr)
+        return nsnull;
+    
+    AtkObject* childAtkObj = ATK_OBJECT(childAtkObjPtr);
     //this will addref parent
-    AtkObject *childAtkObj = accWrapChild->GetAtkObject();
-    NS_ASSERTION(childAtkObj, "Fail to get AtkObj");
-    if (!childAtkObj)
-        return nsnull;
-    atk_object_set_parent(childAtkObj,
-                          accWrap->GetAtkObject());
+    atk_object_set_parent(childAtkObj, aAtkObj);
     g_object_ref(childAtkObj);
     return childAtkObj;
 }
 
 gint
 getIndexInParentCB(AtkObject *aAtkObj)
 {
     // We don't use nsIAccessible::GetIndexInParent() because
     // for ATK we don't want to include text leaf nodes as children
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return -1;
     }
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     nsCOMPtr<nsIAccessible> parent;
     accWrap->GetParent(getter_AddRefs(parent));
     if (!parent) {
         return -1; // No parent
     }
 
     nsCOMPtr<nsIAccessible> sibling;
@@ -1012,18 +1001,17 @@ refStateSetCB(AtkObject *aAtkObj)
     state_set = ATK_OBJECT_CLASS(parent_class)->ref_state_set(aAtkObj);
 
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
         TranslateStates(nsIAccessibleStates::EXT_STATE_DEFUNCT,
                         gAtkStateMapExt, state_set);
         return state_set;
     }
 
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     // Map states
     PRUint32 accState = 0, accExtState = 0;
     nsresult rv = accWrap->GetFinalState(&accState, &accExtState);
     NS_ENSURE_SUCCESS(rv, state_set);
 
     TranslateStates(accState, gAtkStateMap, state_set);
     TranslateStates(accExtState, gAtkStateMapExt, state_set);
@@ -1035,18 +1023,17 @@ AtkRelationSet *
 refRelationSetCB(AtkObject *aAtkObj)
 {
     AtkRelationSet *relation_set = nsnull;
     relation_set = ATK_OBJECT_CLASS(parent_class)->ref_relation_set(aAtkObj);
 
     if (NS_FAILED(CheckMaiAtkObject(aAtkObj))) {
       return relation_set;
     }
-    nsAccessibleWrap *accWrap =
-        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
 
     AtkObject *accessible_array[1];
     AtkRelation* relation;
     
     PRUint32 relationType[] = {nsIAccessibleRelation::RELATION_LABELLED_BY,
                                nsIAccessibleRelation::RELATION_LABEL_FOR,
                                nsIAccessibleRelation::RELATION_NODE_CHILD_OF,
                                nsIAccessibleRelation::RELATION_CONTROLLED_BY,
@@ -1062,33 +1049,35 @@ refRelationSetCB(AtkObject *aAtkObj)
         relation = atk_relation_set_get_relation_by_type(relation_set, NS_STATIC_CAST(AtkRelationType, relationType[i]));
         if (relation) {
             atk_relation_set_remove(relation_set, relation);
         }
 
         nsIAccessible* accRelated;
         nsresult rv = accWrap->GetAccessibleRelated(relationType[i], &accRelated);
         if (NS_SUCCEEDED(rv) && accRelated) {
-            accessible_array[0] = NS_STATIC_CAST(nsAccessibleWrap*, accRelated)->GetAtkObject();
+            void *relatedAtkObj = nsnull;
+            accRelated->GetNativeInterface(&relatedAtkObj);
+            accessible_array[0] = ATK_OBJECT(relatedAtkObj);
             relation = atk_relation_new(accessible_array, 1,
                                         NS_STATIC_CAST(AtkRelationType, relationType[i]));
             atk_relation_set_add(relation_set, relation);
             g_object_unref(relation);
         }
     }
 
     return relation_set;
 }
 
 // Check if aAtkObj is a valid MaiAtkObject
 nsresult
 CheckMaiAtkObject(AtkObject *aAtkObj)
 {
     NS_ENSURE_ARG(IS_MAI_OBJECT(aAtkObj));
-    nsAccessibleWrap * tmpAccWrap = MAI_ATK_OBJECT(aAtkObj)->accWrap;
+    nsAccessibleWrap * tmpAccWrap = GetAccessibleWrap(aAtkObj);
 
     // Check if AccessibleWrap was deconstructed
     if (tmpAccWrap == nsnull) {
         return NS_ERROR_NULL_POINTER;
     }
 
     nsRefPtr<nsApplicationAccessibleWrap> appAccWrap =
         nsAccessNode::GetApplicationAccessible();
@@ -1116,21 +1105,22 @@ nsAccessibleWrap *GetAccessibleWrap(AtkO
 NS_IMETHODIMP
 nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
     nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIAccessible> accessible;
     aEvent->GetAccessible(getter_AddRefs(accessible));
-    nsIAccessible *tmpAccessible = accessible;
-    nsAccessibleWrap *accWrap = NS_STATIC_CAST(nsAccessibleWrap*, tmpAccessible);
-    NS_ENSURE_TRUE(accWrap, NS_ERROR_FAILURE);
+    NS_ENSURE_TRUE(accessible, NS_ERROR_FAILURE);
 
-    AtkObject *atkObj = accWrap->GetAtkObject();
+    void *atkObjPtr = nsnull;
+    accessible->GetNativeInterface(&atkObjPtr);
+
+    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
     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:
--- a/accessible/src/atk/nsDocAccessibleWrap.cpp
+++ b/accessible/src/atk/nsDocAccessibleWrap.cpp
@@ -71,26 +71,27 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireT
 {
     NS_ENSURE_ARG_POINTER(aAccessible);
 
     // First fire nsIObserver event for internal xpcom accessibility clients
     nsDocAccessible::FireToolkitEvent(aEvent, aAccessible, aEventData);
 
     nsresult rv = NS_ERROR_FAILURE;
 
-    nsAccessibleWrap *accWrap =
-        NS_STATIC_CAST(nsAccessibleWrap *, aAccessible);
     MAI_LOG_DEBUG(("\n\nReceived event: aEvent=%u, obj=0x%x, data=0x%x \n",
                    aEvent, aAccessible, aEventData));
+    void *atkObjPtr = nsnull;
+    aAccessible->GetNativeInterface(&atkObjPtr);
     // We don't create ATK objects for nsIAccessible plain text leaves,
     // just return NS_OK in such case
-    AtkObject *atkObj = accWrap->GetAtkObject();
-    if (!atkObj) {
+    if (!atkObjPtr) {
       return NS_OK;
     }
+    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(atkObj);
 
     AtkTableChange * pAtkTableChange = nsnull;
 
     switch (aEvent) {
     case nsIAccessibleEvent::EVENT_FOCUS:
       {
         MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
         nsRefPtr<nsRootAccessible> rootAccWrap = accWrap->GetRootAccessible();
--- a/accessible/src/atk/nsMaiHyperlink.cpp
+++ b/accessible/src/atk/nsMaiHyperlink.cpp
@@ -238,26 +238,26 @@ getUriCB(AtkHyperlink *aLink, gint aLink
 
 AtkObject *
 getObjectCB(AtkHyperlink *aLink, gint aLinkIndex)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, nsnull);
 
     nsCOMPtr<nsIAccessible> accObj;
-    nsresult rv = accHyperlink->GetObject(aLinkIndex, getter_AddRefs(accObj));
-    NS_ENSURE_SUCCESS(rv, nsnull);
-    AtkObject *atkObj = nsnull;
-    if (accObj) {
-        nsIAccessible *tmpObj = accObj;
-        nsAccessibleWrap *accWrap = NS_STATIC_CAST(nsAccessibleWrap *, tmpObj);
-        atkObj = accWrap->GetAtkObject();
+    accHyperlink->GetObject(aLinkIndex, getter_AddRefs(accObj));
+    NS_ENSURE_TRUE(accObj, nsnull);
+
+    void *atkObj = nsnull;
+    accObj->GetNativeInterface(&atkObj);
+    if (!atkObj) {
+        return nsnull;
     }
-    //no need to add ref it, because it is "get" not "ref" ???
-    return atkObj;
+    //no need to add ref it, because it is "get" not "ref"
+    return ATK_OBJECT(atkObj);
 }
 
 gint
 getEndIndexCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, -1);
 
--- a/accessible/src/atk/nsMaiInterfaceComponent.cpp
+++ b/accessible/src/atk/nsMaiInterfaceComponent.cpp
@@ -72,26 +72,27 @@ refAccessibleAtPointCB(AtkComponent *aCo
     NS_ENSURE_TRUE(accWrap, nsnull);
 
     // or ATK_XY_SCREEN  what is definition this in nsIAccessible ???
     if (aCoordType == ATK_XY_WINDOW) {
         /* deal with the coord type */
     }
 
     nsCOMPtr<nsIAccessible> pointAcc;
-    nsresult rv = accWrap->GetChildAtPoint(aAccX, aAccY, getter_AddRefs(pointAcc));
-    if (NS_FAILED(rv))
+    accWrap->GetChildAtPoint(aAccX, aAccY, getter_AddRefs(pointAcc));
+    if (!pointAcc) {
         return nsnull;
+    }
 
-    nsIAccessible *tmpAcc = pointAcc;
-    nsAccessibleWrap *tmpAccWrap =
-        NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
-    AtkObject *atkObj = tmpAccWrap->GetAtkObject();
-    if (!atkObj)
+    void *atkObjPtr = nsnull;
+    pointAcc->GetNativeInterface(&atkObjPtr);
+    if (!atkObjPtr) {
         return nsnull;
+    }
+    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
     g_object_ref(atkObj);
     return atkObj;
 }
 
 void
 getExtentsCB(AtkComponent *aComponent,
              gint *aAccX,
              gint *aAccY,
--- a/accessible/src/atk/nsMaiInterfaceSelection.cpp
+++ b/accessible/src/atk/nsMaiInterfaceSelection.cpp
@@ -90,27 +90,28 @@ refSelectionCB(AtkSelection *aSelection,
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
     NS_ENSURE_TRUE(accWrap, nsnull);
 
     nsCOMPtr<nsIAccessibleSelectable> accSelection;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleSelectable),
                             getter_AddRefs(accSelection));
     NS_ENSURE_TRUE(accSelection, nsnull);
 
-    AtkObject *atkObj = nsnull;
     nsCOMPtr<nsIAccessible> accSelect;
-    nsresult rv = accSelection->RefSelection(i, getter_AddRefs(accSelect));
-    if (NS_SUCCEEDED(rv) && accSelect) {
-        nsIAccessible *tmpAcc = accSelect;
-        nsAccessibleWrap *refAccWrap =
-            NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
-        atkObj = refAccWrap->GetAtkObject();
-        if (atkObj)
-            g_object_ref(atkObj);
+    accSelection->RefSelection(i, getter_AddRefs(accSelect));
+    if (!accSelect) {
+        return nsnull;
     }
+    void *atkObjPtr = nsnull;
+    accSelect->GetNativeInterface(&atkObjPtr);
+    if (!atkObjPtr) {
+        return nsnull;
+    }
+    AtkObject *atkObj = ATK_OBJECT(atkObjPtr);
+    g_object_ref(atkObj);
     return atkObj;
 }
 
 gint
 getSelectionCountCB(AtkSelection *aSelection)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
     NS_ENSURE_TRUE(accWrap, -1);
--- a/accessible/src/atk/nsMaiInterfaceTable.cpp
+++ b/accessible/src/atk/nsMaiInterfaceTable.cpp
@@ -79,23 +79,24 @@ refAtCB(AtkTable *aTable, gint aRow, gin
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessible> cell;
     nsresult rv = accTable->CellRefAt(aRow, aColumn,getter_AddRefs(cell));
     if (NS_FAILED(rv) || !cell)
         return nsnull;
 
-    nsIAccessible *tmpAcc = cell;
-    nsAccessibleWrap *cellAccWrap = NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
+    void *cellAtkObjPtr = nsnull;
+    cell->GetNativeInterface(&cellAtkObjPtr);
+    if (!cellAtkObjPtr)
+        return nsnull;
 
-    AtkObject *atkObj = cellAccWrap->GetAtkObject();
-    if (atkObj)
-        g_object_ref(atkObj);
-    return atkObj;
+    AtkObject *cellAtkObj = ATK_OBJECT(cellAtkObjPtr);
+    g_object_ref(cellAtkObj);
+    return cellAtkObj;
 }
 
 gint
 getIndexAtCB(AtkTable *aTable, gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     NS_ENSURE_TRUE(accWrap, -1);
 
@@ -232,21 +233,19 @@ getCaptionCB(AtkTable *aTable)
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessible> caption;
     nsresult rv = accTable->GetCaption(getter_AddRefs(caption));
     if (NS_FAILED(rv) || !caption)
         return nsnull;
 
-    nsIAccessible *tmpAcc = caption;
-    nsAccessibleWrap *captionAccWrap =
-        NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
-
-    return captionAccWrap->GetAtkObject();
+    void *captionAtkObj = nsnull;
+    caption->GetNativeInterface(&captionAtkObj);
+    return ATK_OBJECT(captionAtkObj);
 }
 
 const gchar*
 getColumnDescriptionCB(AtkTable *aTable, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     NS_ENSURE_TRUE(accWrap, nsnull);
 
@@ -286,21 +285,19 @@ getColumnHeaderCB(AtkTable *aTable, gint
     //
     // 2. "GetColumnHeader" defined in nsIAccessibleTable returns
     // nsXULTreeColumnsAccessibleWrap, which exports nsIAccessibleTable and is
     // "ROLE_LIST".
     nsCOMPtr<nsIAccessible> accHeader;
     header->CellRefAt(0, aColumn, getter_AddRefs(accHeader));
     NS_ENSURE_TRUE(accHeader, nsnull);
 
-    nsIAccessible *tmpAcc = accHeader;
-    nsAccessibleWrap *headerAccWrap =
-        NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
-
-    return headerAccWrap->GetAtkObject();
+    void *headerAtkObj = nsnull;
+    accHeader->GetNativeInterface(&headerAtkObj);
+    return ATK_OBJECT(headerAtkObj);
 }
 
 const gchar*
 getRowDescriptionCB(AtkTable *aTable, gint aRow)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     NS_ENSURE_TRUE(accWrap, nsnull);
 
@@ -327,23 +324,21 @@ getRowHeaderCB(AtkTable *aTable, gint aR
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, nsnull);
 
     nsCOMPtr<nsIAccessibleTable> header;
     nsresult rv = accTable->GetRowHeader(getter_AddRefs(header));
     NS_ENSURE_SUCCESS(rv, nsnull);
 
     nsCOMPtr<nsIAccessible> accHeader(do_QueryInterface(header));
-    NS_ENSURE_TRUE(accTable, nsnull);
+    NS_ENSURE_TRUE(accHeader, nsnull);
 
-    nsIAccessible *tmpAcc = accHeader;
-    nsAccessibleWrap *headerAccWrap =
-        NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
-
-    return headerAccWrap->GetAtkObject();
+    void *headerAtkObj = nsnull;
+    accHeader->GetNativeInterface(&headerAtkObj);
+    return ATK_OBJECT(headerAtkObj);
 }
 
 AtkObject*
 getSummaryCB(AtkTable *aTable)
 {
     /* ??? in nsIAccessibleTable, it returns a nsAString */
     return nsnull;
 }