Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Enumerations | Functions | Variables
nsAccessibleWrap.cpp File Reference
#include "nsMai.h"
#include "nsAccessibleWrap.h"
#include "nsAppRootAccessible.h"
#include "nsString.h"
#include "prprf.h"
#include "nsMaiInterfaceComponent.h"
#include "nsMaiInterfaceAction.h"
#include "nsMaiInterfaceText.h"
#include "nsMaiInterfaceEditableText.h"
#include "nsMaiInterfaceSelection.h"
#include "nsMaiInterfaceValue.h"
#include "nsMaiInterfaceHypertext.h"
#include "nsMaiInterfaceTable.h"

Go to the source code of this file.

Classes

struct  MaiAtkObject
 This MaiAtkObject is a thin wrapper, in the MAI namespace, for AtkObject. More...
struct  MaiAtkObjectClass

Defines

#define MAI_ATK_TYPE_NAME_LEN   (30) /* 10+sizeof(PRUint16)*8/4+1 < 30 */

Enumerations

enum  {
  ACTIVATE, CREATE, DEACTIVATE, DESTROY,
  MAXIMIZE, MINIMIZE, RESIZE, RESTORE,
  LAST_SIGNAL
}

Functions

static G_BEGIN_DECLS void classInitCB (AtkObjectClass *aClass)
static void initializeCB (AtkObject *aAtkObj, gpointer aData)
static void finalizeCB (GObject *aObj)
static const gchar * getNameCB (AtkObject *aAtkObj)
static const gchar * getDescriptionCB (AtkObject *aAtkObj)
static AtkRole getRoleCB (AtkObject *aAtkObj)
static AtkObject * getParentCB (AtkObject *aAtkObj)
static gint getChildCountCB (AtkObject *aAtkObj)
static AtkObject * refChildCB (AtkObject *aAtkObj, gint aChildIndex)
static gint getIndexInParentCB (AtkObject *aAtkObj)
static AtkStateSet * refStateSetCB (AtkObject *aAtkObj)
static AtkRelationSet * refRelationSetCB (AtkObject *aAtkObj)
static G_END_DECLS GType GetMaiAtkType (const PRUint32 &interfaceCount, MaiInterface **interfaces)
static const char * GetUniqueMaiAtkTypeName (MaiInterface **interfaces)
GType mai_atk_object_get_type (void)
nsresult CheckMaiAtkObject (AtkObject *aAtkObj)
nsAccessibleWrapGetAccessibleWrap (AtkObject *aAtkObj)

Variables

static guint mai_atk_object_signals [LAST_SIGNAL] = { 0, }
static gpointer parent_class = NULL

Class Documentation

struct MaiAtkObject

This MaiAtkObject is a thin wrapper, in the MAI namespace, for AtkObject.

Definition at line 74 of file nsAccessibleWrap.cpp.

Collaboration diagram for MaiAtkObject:
Class Members
nsAccessibleWrap * accWrap
AtkObject parent
struct MaiAtkObjectClass

Definition at line 84 of file nsAccessibleWrap.cpp.

Class Members
AtkObjectClass parent_class

Define Documentation

#define MAI_ATK_TYPE_NAME_LEN   (30) /* 10+sizeof(PRUint16)*8/4+1 < 30 */

Enumeration Type Documentation

anonymous enum
Enumerator:
ACTIVATE 
CREATE 
DEACTIVATE 
DESTROY 
MAXIMIZE 
MINIMIZE 
RESIZE 
RESTORE 
LAST_SIGNAL 

Definition at line 59 of file nsAccessibleWrap.cpp.


Function Documentation

nsresult CheckMaiAtkObject ( AtkObject *  aAtkObj)

Definition at line 980 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_ARG(MAI_IS_ATK_OBJECT(aAtkObj));
    nsAccessibleWrap * tmpAccWrap = MAI_ATK_OBJECT(aAtkObj)->accWrap;
    if (tmpAccWrap == nsnull)
        return NS_ERROR_INVALID_POINTER;
    if (tmpAccWrap != nsAppRootAccessible::Create() && !tmpAccWrap->IsValidObject())
        return NS_ERROR_INVALID_POINTER;
    if (tmpAccWrap->GetAtkObject() != aAtkObj)
        return NS_ERROR_FAILURE;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void classInitCB ( AtkObjectClass *  aClass) [static]

Definition at line 617 of file nsAccessibleWrap.cpp.

{
    GObjectClass *gobject_class = G_OBJECT_CLASS(aClass);

    parent_class = g_type_class_peek_parent(aClass);

    aClass->get_name = getNameCB;
    aClass->get_description = getDescriptionCB;
    aClass->get_parent = getParentCB;
    aClass->get_n_children = getChildCountCB;
    aClass->ref_child = refChildCB;
    aClass->get_index_in_parent = getIndexInParentCB;
    aClass->get_role = getRoleCB;
    aClass->ref_state_set = refStateSetCB;
    aClass->ref_relation_set = refRelationSetCB;

    aClass->initialize = initializeCB;

    gobject_class->finalize = finalizeCB;

    mai_atk_object_signals [ACTIVATE] =
    g_signal_new ("activate",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [CREATE] =
    g_signal_new ("create",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [DEACTIVATE] =
    g_signal_new ("deactivate",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [DESTROY] =
    g_signal_new ("destroy",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [MAXIMIZE] =
    g_signal_new ("maximize",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [MINIMIZE] =
    g_signal_new ("minimize",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [RESIZE] =
    g_signal_new ("resize",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
    mai_atk_object_signals [RESTORE] =
    g_signal_new ("restore",
                  MAI_TYPE_ATK_OBJECT,
                  G_SIGNAL_RUN_LAST,
                  0, /* default signal handler */
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);

}

Here is the call graph for this function:

Here is the caller graph for this function:

void finalizeCB ( GObject *  aObj) [static]

Definition at line 733 of file nsAccessibleWrap.cpp.

{
    if (!MAI_IS_ATK_OBJECT(aObj))
        return;
    NS_ASSERTION(MAI_ATK_OBJECT(aObj)->accWrap == nsnull, "AccWrap NOT null");

#ifdef MAI_LOGGING
    ++sMaiAtkObjDeleted;
#endif
    MAI_LOG_DEBUG(("MaiAtkObj Delete obj=%p, all=%d, left=%d\n",
                   (void*)aObj, sMaiAtkObjCreated,
                   (sMaiAtkObjCreated-sMaiAtkObjDeleted)));

    // call parent finalize function
    // finalize of GObjectClass will unref the accessible parent if has
    if (G_OBJECT_CLASS (parent_class)->finalize)
        G_OBJECT_CLASS (parent_class)->finalize(aObj);
}

Here is the caller graph for this function:

nsAccessibleWrap* GetAccessibleWrap ( AtkObject *  aAtkObj)

Definition at line 995 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_TRUE(MAI_IS_ATK_OBJECT(aAtkObj), nsnull);
    nsAccessibleWrap * tmpAccWrap = MAI_ATK_OBJECT(aAtkObj)->accWrap;
    NS_ENSURE_TRUE(tmpAccWrap != nsnull, nsnull);
    NS_ENSURE_TRUE(tmpAccWrap->GetAtkObject() == aAtkObj, nsnull);
    return tmpAccWrap;
}

Here is the call graph for this function:

gint getChildCountCB ( AtkObject *  aAtkObj) [static]

Definition at line 868 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), 0);
    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    PRInt32 count = 0;
    accWrap->GetChildCount(&count);
    return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar * getDescriptionCB ( AtkObject *  aAtkObj) [static]

Definition at line 777 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull);

    if (!aAtkObj->description) {
        gint len;
        nsAutoString uniDesc;

        nsAccessibleWrap *accWrap =
            NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

        /* 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_ConvertUCS2toUTF8(uniDesc).get());
        }
    }
    return aAtkObj->description;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint getIndexInParentCB ( AtkObject *  aAtkObj) [static]

Definition at line 909 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), -1);
    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    PRInt32 currentIndex = -1;
    accWrap->GetIndexInParent(&currentIndex);
    return currentIndex;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GType GetMaiAtkType ( const PRUint32 interfaceCount,
MaiInterface **  interfaces 
) [static]

Definition at line 405 of file nsAccessibleWrap.cpp.

{
    GType type;
    static const GTypeInfo tinfo = {
        sizeof(MaiAtkObjectClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) NULL,
        (GClassFinalizeFunc) NULL,
        NULL, /* class data */
        sizeof(MaiAtkObject), /* instance size */
        0, /* nb preallocs */
        (GInstanceInitFunc) NULL,
        NULL /* value table */
    };

    if (interfaceCount == 0)
        return MAI_TYPE_ATK_OBJECT;

    /*
     * The members we used to register a GType are MaiInterface::GetAtkType()
     * and MaiInterface::GetInterfaceInfo(), which is the same with different
     * MaiInterface objects. So we can reuse the registered GType when having
     * the same MaiInterface types.
     */
    const char *atkTypeName = GetUniqueMaiAtkTypeName(interfaces);
    type = g_type_from_name(atkTypeName);
    if (type) {
        return type;
    }

    /*
     * gobject limits the number of types that can directly derive from any
     * given object type to 4095.
     */
    static PRUint16 typeRegCount = 0;
    if (typeRegCount++ < 4095) {
        type = g_type_register_static(MAI_TYPE_ATK_OBJECT,
                                      atkTypeName,
                                      &tinfo, GTypeFlags(0));
    }
    else {
        return 0;
    }

    for (int index = 0; index < MAI_INTERFACE_NUM; index++) {
        if (!interfaces[index])
            continue;
        g_type_add_interface_static(type,
                                    interfaces[index]->GetAtkType(),
                                    interfaces[index]->GetInterfaceInfo());
    }
    return type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar * getNameCB ( AtkObject *  aAtkObj) [static]

Definition at line 753 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull);

    nsAutoString uniName;

    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    /* nsIAccessible is responsible for the non-NULL name */
    nsresult rv = accWrap->GetName(uniName);
    NS_ENSURE_SUCCESS(rv, nsnull);

    if (uniName.Length() > 0) {
        NS_ConvertUTF8toUCS2 objName(aAtkObj->name);
        if (!uniName.Equals(objName)) {
            atk_object_set_name(aAtkObj,
                                NS_ConvertUCS2toUTF8(uniName).get());
        }
    }
    return aAtkObj->name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AtkObject * getParentCB ( AtkObject *  aAtkObj) [static]

Definition at line 846 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull);
    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    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);

    AtkObject *parentAtkObj = accWrapParent->GetAtkObject();
    if (parentAtkObj && !aAtkObj->accessible_parent) {
        atk_object_set_parent(aAtkObj, parentAtkObj);
    }
    return parentAtkObj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AtkRole getRoleCB ( AtkObject *  aAtkObj) [static]

Definition at line 801 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), ATK_ROLE_INVALID);

    if (aAtkObj->role == ATK_ROLE_INVALID) {
        nsAccessibleWrap *accWrap =
            NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

        PRUint32 accRole;
        nsresult rv = accWrap->GetFinalRole(&accRole);
        NS_ENSURE_SUCCESS(rv, ATK_ROLE_INVALID);

        //the cross-platform Accessible object returns the same value for
        //both "ROLE_MENUITEM" and "ROLE_MENUPOPUP"
        if (accRole == nsIAccessible::ROLE_MENUITEM) {
            PRInt32 childCount = 0;
            accWrap->GetChildCount(&childCount);
            if (childCount > 0)
                accRole = nsIAccessible::ROLE_MENUPOPUP;
        }
        else if (accRole == nsIAccessible::ROLE_LINK) {
            //ATK doesn't have role-link now
            //register it on runtime
            static AtkRole linkRole = (AtkRole)0;
            if (linkRole == 0) {
                linkRole = atk_role_register("hyper link");
            }
            accRole = linkRole;
        }
#ifndef ATK_ROLE_AUTOCOMPLETE
        else if (accRole == nsIAccessible::ROLE_AUTOCOMPLETE) {
                     accRole = ATK_ROLE_COMBO_BOX;
              }
#endif
#ifndef ATK_ROLE_CAPTION
        else if (accRole == nsIAccessible::ROLE_CAPTION) {
                     accRole = ATK_ROLE_LABEL;
              }
#endif
        aAtkObj->role = NS_STATIC_CAST(AtkRole, accRole);
    }
    return aAtkObj->role;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const char * GetUniqueMaiAtkTypeName ( MaiInterface **  interfaces) [static]

Definition at line 461 of file nsAccessibleWrap.cpp.

{
#define MAI_ATK_TYPE_NAME_LEN (30)     /* 10+sizeof(PRUint16)*8/4+1 < 30 */

    PRUint16 atkTypeNameId = 0;
    static gchar namePrefix[] = "MaiAtkType";   /* size = 10 */
    static gchar name[MAI_ATK_TYPE_NAME_LEN + 1];

    for (int index = 0; index < MAI_INTERFACE_NUM; index++) {
        if (interfaces[index])
            atkTypeNameId |= 1 << index;
    }
    PR_snprintf(name, MAI_ATK_TYPE_NAME_LEN, "%s%x", namePrefix, atkTypeNameId);
    name[MAI_ATK_TYPE_NAME_LEN] = '\0';

    MAI_LOG_DEBUG(("MaiWidget::LastedTypeName=%s\n", name));

    return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void initializeCB ( AtkObject *  aAtkObj,
gpointer  aData 
) [static]

Definition at line 705 of file nsAccessibleWrap.cpp.

{
    NS_ASSERTION((MAI_IS_ATK_OBJECT(aAtkObj)), "Invalid AtkObject");
    NS_ASSERTION(aData, "Invalid Data to init AtkObject");
    if (!aAtkObj || !aData)
        return;

    /* call parent init function */
    /* AtkObjectClass has not a "initialize" function now,
     * maybe it has later
     */

    if (ATK_OBJECT_CLASS(parent_class)->initialize)
        ATK_OBJECT_CLASS(parent_class)->initialize(aAtkObj, aData);

    /* initialize object */
    MAI_ATK_OBJECT(aAtkObj)->accWrap =
        NS_STATIC_CAST(nsAccessibleWrap*, aData);

#ifdef MAI_LOGGING
    ++sMaiAtkObjCreated;
#endif
    MAI_LOG_DEBUG(("MaiAtkObj Create obj=%p for AccWrap=%p, all=%d, left=%d\n",
                   (void*)aAtkObj, (void*)aData, sMaiAtkObjCreated,
                   (sMaiAtkObjCreated-sMaiAtkObjDeleted)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 154 of file nsAccessibleWrap.cpp.

{
    static GType type = 0;

    if (!type) {
        static const GTypeInfo tinfo = {
            sizeof(MaiAtkObjectClass),
            (GBaseInitFunc)NULL,
            (GBaseFinalizeFunc)NULL,
            (GClassInitFunc)classInitCB,
            (GClassFinalizeFunc)NULL,
            NULL, /* class data */
            sizeof(MaiAtkObject), /* instance size */
            0, /* nb preallocs */
            (GInstanceInitFunc)NULL,
            NULL /* value table */
        };

        type = g_type_register_static(ATK_TYPE_OBJECT,
                                      "MaiAtkObject", &tinfo, GTypeFlags(0));
    }
    return type;
}

Here is the call graph for this function:

AtkObject * refChildCB ( AtkObject *  aAtkObj,
gint  aChildIndex 
) [static]

Definition at line 880 of file nsAccessibleWrap.cpp.

{
    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull);
    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    nsresult rv;
    nsCOMPtr<nsIAccessible> accChild;
    rv = accWrap->GetChildAt(aChildIndex, getter_AddRefs(accChild));

    if (NS_FAILED(rv) || !accChild)
        return nsnull;

    nsIAccessible *tmpAccChild = accChild;
    nsAccessibleWrap *accWrapChild =
        NS_STATIC_CAST(nsAccessibleWrap*, tmpAccChild);

    //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());
    g_object_ref(childAtkObj);
    return childAtkObj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AtkRelationSet * refRelationSetCB ( AtkObject *  aAtkObj) [static]

Definition at line 946 of file nsAccessibleWrap.cpp.

{
    AtkRelationSet *relation_set = nsnull;
    relation_set = ATK_OBJECT_CLASS(parent_class)->ref_relation_set(aAtkObj);

    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), relation_set);
    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    AtkObject *accessible_array[1];
    AtkRelation* relation;
    
    PRUint32 relationType[] = {nsIAccessible::RELATION_LABELLED_BY,
                               nsIAccessible::RELATION_LABEL_FOR,
                               nsIAccessible::RELATION_NODE_CHILD_OF};

    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(relationType); i++) { 
      if (!atk_relation_set_contains(relation_set, NS_STATIC_CAST(AtkRelationType, relationType[i]))) {
          nsIAccessible* accRelated;
          nsresult rv = accWrap->GetAccessibleRelated(relationType[i], &accRelated);
          if (NS_SUCCEEDED(rv) && accRelated) {
              accessible_array[0] = NS_STATIC_CAST(nsAccessibleWrap*, accRelated)->GetAtkObject();
              relation = atk_relation_new(accessible_array, 1,
                                           NS_STATIC_CAST(AtkRelationType, relationType[i]));
              atk_relation_set_add(relation_set, relation);
          }
      }
    }

    return relation_set;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AtkStateSet * refStateSetCB ( AtkObject *  aAtkObj) [static]

Definition at line 921 of file nsAccessibleWrap.cpp.

{
    AtkStateSet *state_set = nsnull;
    state_set = ATK_OBJECT_CLASS(parent_class)->ref_state_set(aAtkObj);

    NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), state_set);
    nsAccessibleWrap *accWrap =
        NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;

    PRUint32 accState = 0;
    nsresult rv = accWrap->GetFinalState(&accState);
    NS_ENSURE_SUCCESS(rv, state_set);

    PRUint32 accExtState = 0;
    rv = accWrap->GetExtState(&accExtState);
    NS_ENSURE_SUCCESS(rv, state_set);

    if ((accState == 0) && (accExtState == 0))
      return state_set;

    nsAccessibleWrap::TranslateStates(accState, accExtState, state_set);
    return state_set;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

guint mai_atk_object_signals[LAST_SIGNAL] = { 0, } [static]

Definition at line 89 of file nsAccessibleWrap.cpp.

gpointer parent_class = NULL [static]

Definition at line 151 of file nsAccessibleWrap.cpp.