Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsMaiInterfaceAction.cpp File Reference
#include "nsMaiInterfaceAction.h"
#include "nsAccessibleWrap.h"
#include "nsString.h"

Go to the source code of this file.

Functions

static G_BEGIN_DECLS void interfaceInitCB (AtkActionIface *aIface)
static gboolean doActionCB (AtkAction *aAction, gint aActionIndex)
static gint getActionCountCB (AtkAction *aAction)
static const gchar * getDescriptionCB (AtkAction *aAction, gint aActionIndex)
static const gchar * getNameCB (AtkAction *aAction, gint aActionIndex)
static const gchar * getKeyBindingCB (AtkAction *aAction, gint aActionIndex)
static gboolean setDescriptionCB (AtkAction *aAction, gint aActionIndex, const gchar *aDesc)

Function Documentation

gboolean doActionCB ( AtkAction *  aAction,
gint  aActionIndex 
) [static]

Definition at line 103 of file nsMaiInterfaceAction.cpp.

{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
    NS_ENSURE_TRUE(accWrap, FALSE);
 
    nsresult rv = accWrap->DoAction(aActionIndex);
    return (NS_FAILED(rv)) ? FALSE : TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint getActionCountCB ( AtkAction *  aAction) [static]

Definition at line 113 of file nsMaiInterfaceAction.cpp.

{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
    NS_ENSURE_TRUE(accWrap, 0);

    PRUint8 num = 0;
    nsresult rv = accWrap->GetNumActions(&num);
    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, num);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar * getDescriptionCB ( AtkAction *  aAction,
gint  aActionIndex 
) [static]

Definition at line 124 of file nsMaiInterfaceAction.cpp.

{
    // the interface in nsIAccessibleAction is empty
    // use getName as default description
    return getNameCB(aAction, aActionIndex);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar * getKeyBindingCB ( AtkAction *  aAction,
gint  aActionIndex 
) [static]

Definition at line 150 of file nsMaiInterfaceAction.cpp.

{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
    NS_ENSURE_TRUE(accWrap, nsnull);

    MaiInterfaceAction *action =
        NS_STATIC_CAST(MaiInterfaceAction *,
                       accWrap->GetMaiInterface(MAI_INTERFACE_ACTION));
    NS_ENSURE_TRUE(action, nsnull);

    if (*action->GetKeyBinding())
        return action->GetKeyBinding();

    //return all KeyBindings including accesskey and shortcut
    
    nsAutoString allKeyBinding;

    //get accesskey
    nsAutoString accessKey;
    nsresult rv = accWrap->GetKeyboardShortcut(accessKey);

    if (NS_SUCCEEDED(rv) && !accessKey.IsEmpty()) {
        nsCOMPtr<nsIAccessible> parentAccessible;
        accWrap->GetParent(getter_AddRefs(parentAccessible));
        if (parentAccessible) {
            PRUint32 role;
            parentAccessible->GetRole(&role);

            if (role == ATK_ROLE_MENU_BAR) {
                //it is topmenu, change from "Alt+f" to "f;<Alt>f"
                nsAutoString rightChar;
                accessKey.Right(rightChar, 1);
                allKeyBinding = rightChar + NS_LITERAL_STRING(";<Alt>") +
                                rightChar;
            }
            else if ((role == ATK_ROLE_MENU) || (role == ATK_ROLE_MENU_ITEM)) {
                //it is submenu, change from "s" to "s;<Alt>f:s"
                nsAutoString allKey = accessKey;
                nsCOMPtr<nsIAccessible> grandParentAcc = parentAccessible;

                while ((grandParentAcc) && (role != ATK_ROLE_MENU_BAR)) {
                    nsAutoString grandParentKey;
                    grandParentAcc->GetKeyboardShortcut(grandParentKey);

                    if (!grandParentKey.IsEmpty()) {
                        nsAutoString rightChar;
                        grandParentKey.Right(rightChar, 1);
                        allKey = rightChar + NS_LITERAL_STRING(":") + allKey;
                    }

                    nsCOMPtr<nsIAccessible> tempAcc = grandParentAcc;
                    tempAcc->GetParent(getter_AddRefs(grandParentAcc));
                    if (grandParentAcc)
                        grandParentAcc->GetRole(&role);
                }
                allKeyBinding = accessKey + NS_LITERAL_STRING(";<Alt>") +
                                allKey;
            }
        }
        else {
            //default process, rarely happens.
            nsAutoString rightChar;
            accessKey.Right(rightChar, 1);
            allKeyBinding = rightChar + NS_LITERAL_STRING(";<Alt>") + rightChar;
        }
    }
    else  //don't have accesskey
        allKeyBinding.AssignLiteral(";");

    //get shortcut
    nsAutoString keyBinding, subShortcut;
    rv = accWrap->GetKeyBinding(keyBinding);

    if (NS_SUCCEEDED(rv) && !keyBinding.IsEmpty()) {
        //change the shortcut from "Ctrl+Shift+L" to "<Control><Shift>L"
        PRInt32 oldPos, curPos=0;
        while ((curPos != -1) && (curPos < (PRInt32)keyBinding.Length())) {
            oldPos = curPos;
            nsAutoString subString;
            curPos = keyBinding.FindChar('+', oldPos);
            if (curPos == -1) {
                keyBinding.Mid(subString, oldPos, keyBinding.Length() - oldPos);
                subShortcut += subString;
            }
            else {
                keyBinding.Mid(subString, oldPos, curPos - oldPos);
      
                //change "Ctrl" to "Control"
                if (subString.LowerCaseEqualsLiteral("ctrl"))
                    subString.AssignLiteral("Control");
      
                subShortcut += NS_LITERAL_STRING("<") + subString +
                               NS_LITERAL_STRING(">");
                curPos++;
            }
        }
    }

    allKeyBinding += NS_LITERAL_STRING(";") + subShortcut;
    action->SetKeyBinding(allKeyBinding);
    return action->GetKeyBinding();
}

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar * getNameCB ( AtkAction *  aAction,
gint  aActionIndex 
) [static]

Definition at line 132 of file nsMaiInterfaceAction.cpp.

{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
    NS_ENSURE_TRUE(accWrap, nsnull);

    MaiInterfaceAction *action =
        NS_STATIC_CAST(MaiInterfaceAction *,
                       accWrap->GetMaiInterface(MAI_INTERFACE_ACTION));
    NS_ENSURE_TRUE(action, nsnull);

    nsAutoString autoStr;
    nsresult rv = accWrap->GetActionName(aActionIndex, autoStr);
    NS_ENSURE_SUCCESS(rv, nsnull);
    action->SetName(autoStr);
    return action->GetName();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void interfaceInitCB ( AtkActionIface *  aIface) [static]

Definition at line 88 of file nsMaiInterfaceAction.cpp.

{
    NS_ASSERTION(aIface, "Invalid aIface");
    if (!aIface)
        return;

    aIface->do_action = doActionCB;
    aIface->get_n_actions = getActionCountCB;
    aIface->get_description = getDescriptionCB;
    aIface->get_keybinding = getKeyBindingCB;
    aIface->get_name = getNameCB;
    aIface->set_description = setDescriptionCB;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean setDescriptionCB ( AtkAction *  aAction,
gint  aActionIndex,
const gchar *  aDesc 
) [static]

Definition at line 254 of file nsMaiInterfaceAction.cpp.

{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
    NS_ENSURE_TRUE(accWrap, nsnull);

    /* this is not supported in nsIAccessible yet */
    return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function: