AtkAttributeSet *
getRunAttributesCB(AtkText *aText, gint aOffset,
                   gint *aStartOffset,
                   gint *aEndOffset)
{
    *aStartOffset = -1;
    *aEndOffset = -1;

    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    if (!accWrap)
        return nsnull;

    nsCOMPtr<nsIAccessibleText> accText;
    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                            getter_AddRefs(accText));
    NS_ENSURE_TRUE(accText, nsnull);

    nsCOMPtr<nsIPersistentProperties> attributes;
    PRInt32 startOffset = 0, endOffset = 0;
    nsresult rv = accText->GetTextAttributes(false, aOffset,
                                             &startOffset, &endOffset,
                                             getter_AddRefs(attributes));
    NS_ENSURE_SUCCESS(rv, nsnull);

    *aStartOffset = startOffset;
    *aEndOffset = endOffset;

    return ConvertToAtkAttributeSet(attributes);
}
AtkAttributeSet *
getDefaultAttributesCB(AtkText *aText)
{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    if (!accWrap)
        return nsnull;

    nsCOMPtr<nsIAccessibleText> accText;
    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                            getter_AddRefs(accText));
    NS_ENSURE_TRUE(accText, nsnull);

    nsCOMPtr<nsIPersistentProperties> attributes;
    nsresult rv = accText->GetDefaultTextAttributes(getter_AddRefs(attributes));
    if (NS_FAILED(rv))
        return nsnull;

    return ConvertToAtkAttributeSet(attributes);
}
AtkAttributeSet *
GetAttributeSet(nsIAccessible* aAccessible)
{
    nsCOMPtr<nsIPersistentProperties> attributes;
    aAccessible->GetAttributes(getter_AddRefs(attributes));

    if (attributes) {
        // Deal with attributes that we only need to expose in ATK
        PRUint32 state;
        aAccessible->GetState(&state, nsnull);
        if (state & nsIAccessibleStates::STATE_HASPOPUP) {
            // There is no ATK state for haspopup, must use object attribute to expose the same info
            nsAutoString oldValueUnused;
            attributes->SetStringProperty(NS_LITERAL_CSTRING("haspopup"), NS_LITERAL_STRING("true"),
                                          oldValueUnused);
        }

        return ConvertToAtkAttributeSet(attributes);
    }

    return nsnull;
}