accessible/src/atk/nsMaiInterfaceDocument.cpp
author Trevor Saunders <trev.saunders@gmail.com>
Fri, 27 May 2011 15:37:24 -0700
changeset 70953 78ad95eaf1f140ec71b81c6701652b91f167e95a
parent 68670 f9a978db810270a3ce6a10e4e581740c14997325
child 77039 d8e48951c3ef10bacd28172a581d03f2ed8d3b30
permissions -rw-r--r--
Bug 653086 - clean up editor configuration in a11y files r=fernando From 4a69f14cec60e25aca096b75b1be265b11a31244 Mon Sep 17 00:00:00 2001 --- accessible/src/atk/AtkSocketAccessible.cpp | 3 +-- accessible/src/atk/AtkSocketAccessible.h | 3 +-- accessible/src/atk/nsARIAGridAccessibleWrap.h | 2 +- accessible/src/atk/nsAccessNodeWrap.cpp | 2 +- accessible/src/atk/nsAccessNodeWrap.h | 2 +- accessible/src/atk/nsAccessibleRelationWrap.h | 2 +- accessible/src/atk/nsAccessibleWrap.cpp | 2 +- accessible/src/atk/nsAccessibleWrap.h | 2 +- accessible/src/atk/nsApplicationAccessibleWrap.cpp | 2 +- accessible/src/atk/nsApplicationAccessibleWrap.h | 2 +- accessible/src/atk/nsDocAccessibleWrap.cpp | 2 +- accessible/src/atk/nsDocAccessibleWrap.h | 2 +- accessible/src/atk/nsHTMLImageAccessibleWrap.h | 2 +- accessible/src/atk/nsHTMLTableAccessibleWrap.h | 2 +- accessible/src/atk/nsHyperTextAccessibleWrap.h | 2 +- accessible/src/atk/nsMai.h | 2 +- accessible/src/atk/nsMaiHyperlink.cpp | 2 +- accessible/src/atk/nsMaiHyperlink.h | 2 +- accessible/src/atk/nsMaiInterfaceAction.cpp | 2 +- accessible/src/atk/nsMaiInterfaceAction.h | 2 +- accessible/src/atk/nsMaiInterfaceComponent.cpp | 3 +-- accessible/src/atk/nsMaiInterfaceComponent.h | 3 +-- accessible/src/atk/nsMaiInterfaceDocument.cpp | 2 +- accessible/src/atk/nsMaiInterfaceDocument.h | 2 +- accessible/src/atk/nsMaiInterfaceEditableText.cpp | 2 +- accessible/src/atk/nsMaiInterfaceEditableText.h | 2 +- accessible/src/atk/nsMaiInterfaceHyperlinkImpl.cpp | 2 +- accessible/src/atk/nsMaiInterfaceHyperlinkImpl.h | 2 +- accessible/src/atk/nsMaiInterfaceHypertext.cpp | 2 +- accessible/src/atk/nsMaiInterfaceHypertext.h | 2 +- accessible/src/atk/nsMaiInterfaceImage.cpp | 2 +- accessible/src/atk/nsMaiInterfaceImage.h | 2 +- accessible/src/atk/nsMaiInterfaceSelection.cpp | 2 +- accessible/src/atk/nsMaiInterfaceSelection.h | 2 +- accessible/src/atk/nsMaiInterfaceTable.cpp | 2 +- accessible/src/atk/nsMaiInterfaceTable.h | 2 +- accessible/src/atk/nsMaiInterfaceText.cpp | 2 +- accessible/src/atk/nsMaiInterfaceText.h | 2 +- accessible/src/atk/nsMaiInterfaceValue.cpp | 2 +- accessible/src/atk/nsMaiInterfaceValue.h | 2 +- accessible/src/atk/nsRoleMap.h | 2 +- accessible/src/atk/nsRootAccessibleWrap.cpp | 2 +- accessible/src/atk/nsRootAccessibleWrap.h | 2 +- accessible/src/atk/nsStateMap.h | 2 +- accessible/src/atk/nsTextAccessibleWrap.h | 2 +- accessible/src/atk/nsXULListboxAccessibleWrap.h | 2 +- accessible/src/atk/nsXULMenuAccessibleWrap.h | 2 +- accessible/src/atk/nsXULTreeGridAccessibleWrap.h | 2 +- 48 files changed, 48 insertions(+), 52 deletions(-)

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is
 * Sun Microsystems, Inc.
 * Portions created by the Initial Developer are Copyright (C) 2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Evan Yan (evan.yan@sun.com)
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsAccessibleWrap.h"
#include "nsMaiInterfaceDocument.h"
#include "nsAccessibilityAtoms.h"

const char *const kDocTypeName = "W3C-doctype";
const char *const kDocUrlName = "DocURL";
const char *const kMimeTypeName = "MimeType";

void
documentInterfaceInitCB(AtkDocumentIface *aIface)
{
    NS_ASSERTION(aIface, "Invalid Interface");
    if(!aIface)
        return;

    /*
     * We don't support get_document or set_attribute right now.
     * get_document_type is deprecated, we return DocType in
     * get_document_attribute_value and get_document_attributes instead.
     */
    aIface->get_document_attributes = getDocumentAttributesCB;
    aIface->get_document_attribute_value = getDocumentAttributeValueCB;
    aIface->get_document_locale = getDocumentLocaleCB;
}

const gchar *
getDocumentLocaleCB(AtkDocument *aDocument)
{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
    if (!accWrap)
        return nsnull;

    nsCOMPtr<nsIAccessNode> docAccessNode;
    accWrap->QueryInterface(NS_GET_IID(nsIAccessNode),
                            getter_AddRefs(docAccessNode));
    NS_ENSURE_TRUE(docAccessNode, nsnull);

    nsAutoString locale;
    docAccessNode->GetLanguage(locale);
    if (locale.IsEmpty()) {
      return nsnull;
    }
    return nsAccessibleWrap::ReturnString(locale);
}

const gchar *
getDocumentTypeCB(AtkDocument *aDocument)
{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
    if (!accWrap)
        return nsnull;

    nsCOMPtr<nsIAccessibleDocument> accDocument;
    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                            getter_AddRefs(accDocument));
    NS_ENSURE_TRUE(accDocument, nsnull);

    nsAutoString mimeType;
    nsresult rv = accDocument->GetMimeType(mimeType);
    NS_ENSURE_SUCCESS(rv, nsnull);
    return nsAccessibleWrap::ReturnString(mimeType);
}

static inline GSList *
prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue)
{
    // libspi will free these
    AtkAttribute *atkAttr = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
    atkAttr->name = g_strdup(aName);
    atkAttr->value = g_strdup(NS_ConvertUTF16toUTF8(aValue).get());
    return g_slist_prepend(aList, atkAttr);
}

AtkAttributeSet *
getDocumentAttributesCB(AtkDocument *aDocument)
{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
    if (!accWrap)
        return nsnull;

    nsCOMPtr<nsIAccessibleDocument> accDocument;
    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                            getter_AddRefs(accDocument));
    NS_ENSURE_TRUE(accDocument, nsnull);

    // according to atkobject.h, AtkAttributeSet is a GSList
    GSList *attributes = nsnull;

    nsAutoString aURL;
    nsresult rv = accDocument->GetURL(aURL);
    if (NS_SUCCEEDED(rv)) {
        attributes = prependToList(attributes, kDocUrlName, aURL);
    }
    nsAutoString aW3CDocType;
    rv = accDocument->GetDocType(aW3CDocType);
    if (NS_SUCCEEDED(rv)) {
        attributes = prependToList(attributes, kDocTypeName, aW3CDocType);
    }
    nsAutoString aMimeType;
    rv = accDocument->GetMimeType(aMimeType);
    if (NS_SUCCEEDED(rv)) {
        attributes = prependToList(attributes, kMimeTypeName, aMimeType);
    }
    
    return attributes;
}

const gchar *
getDocumentAttributeValueCB(AtkDocument *aDocument,
                            const gchar *aAttrName)
{
    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
    if (!accWrap)
        return nsnull;

    nsCOMPtr<nsIAccessibleDocument> accDocument;
    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                            getter_AddRefs(accDocument));
    NS_ENSURE_TRUE(accDocument, nsnull);

    nsresult rv;
    nsAutoString attrValue;
    if (!g_ascii_strcasecmp(aAttrName, kDocTypeName)) {
        rv = accDocument->GetDocType(attrValue);
        NS_ENSURE_SUCCESS(rv, nsnull);
    }
    else if (!g_ascii_strcasecmp(aAttrName, kDocUrlName)) {
        rv = accDocument->GetURL(attrValue);
        NS_ENSURE_SUCCESS(rv, nsnull);
    }
    else if (!g_ascii_strcasecmp(aAttrName, kMimeTypeName)) {
        rv = accDocument->GetMimeType(attrValue);
        NS_ENSURE_SUCCESS(rv, nsnull);
    }
    else {
        return nsnull;
    }
    return nsAccessibleWrap::ReturnString(attrValue);
}