mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 17:59:34 +00:00
Bug 342288. Initial support for ATK object attributes. Patch by Ming Gao. r=aaronlev, sr=neil
This commit is contained in:
parent
c198b58e7f
commit
23b19693d1
@ -39,6 +39,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
interface nsIPersistentProperties;
|
||||
|
||||
/**
|
||||
* A cross-platform interface that supports platform-specific
|
||||
@ -52,7 +53,7 @@
|
||||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
[scriptable, uuid(DB717DB4-37E9-42F1-A3B0-2579DD7C3814)]
|
||||
[scriptable, uuid(c27c44b9-9455-48f2-b5f4-2897e54a8d69)]
|
||||
interface nsIAccessible : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -163,6 +164,11 @@ interface nsIAccessible : nsISupports
|
||||
*/
|
||||
readonly attribute nsIAccessible focusedChild;
|
||||
|
||||
/**
|
||||
* Attributes of accessible
|
||||
*/
|
||||
readonly attribute nsIPersistentProperties attributes;
|
||||
|
||||
/**
|
||||
* Accessible child which contains the coordinate at (x, y) in screen pixels.
|
||||
*/
|
||||
|
@ -55,6 +55,9 @@
|
||||
#include "nsMaiInterfaceHypertext.h"
|
||||
#include "nsMaiInterfaceHyperlinkImpl.h"
|
||||
#include "nsMaiInterfaceTable.h"
|
||||
#include "nsXPCOMStrings.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsMaiInterfaceDocument.h"
|
||||
|
||||
extern "C" GType g_atk_hyperlink_impl_type; //defined in nsAppRootAccessible.cpp
|
||||
@ -171,6 +174,7 @@ static void finalizeCB(GObject *aObj);
|
||||
static const gchar* getNameCB (AtkObject *aAtkObj);
|
||||
static const gchar* getDescriptionCB (AtkObject *aAtkObj);
|
||||
static AtkRole getRoleCB(AtkObject *aAtkObj);
|
||||
static AtkAttributeSet* getAttributesCB(AtkObject *aAtkObj);
|
||||
static AtkObject* getParentCB(AtkObject *aAtkObj);
|
||||
static gint getChildCountCB(AtkObject *aAtkObj);
|
||||
static AtkObject* refChildCB(AtkObject *aAtkObj, gint aChildIndex);
|
||||
@ -630,6 +634,7 @@ classInitCB(AtkObjectClass *aClass)
|
||||
aClass->ref_child = refChildCB;
|
||||
aClass->get_index_in_parent = getIndexInParentCB;
|
||||
aClass->get_role = getRoleCB;
|
||||
aClass->get_attributes = getAttributesCB;
|
||||
aClass->ref_state_set = refStateSetCB;
|
||||
aClass->ref_relation_set = refRelationSetCB;
|
||||
|
||||
@ -821,6 +826,47 @@ getRoleCB(AtkObject *aAtkObj)
|
||||
return aAtkObj->role;
|
||||
}
|
||||
|
||||
AtkAttributeSet *
|
||||
getAttributesCB(AtkObject *aAtkObj)
|
||||
{
|
||||
NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull);
|
||||
nsAccessibleWrap *accWrap =
|
||||
NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
|
||||
|
||||
AtkAttributeSet *objAttributeSet = nsnull;
|
||||
nsCOMPtr<nsIPersistentProperties> attributes;
|
||||
accWrap->GetAttributes(getter_AddRefs(attributes));
|
||||
if (attributes) {
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> propEnum;
|
||||
nsresult rv = attributes->Enumerate(getter_AddRefs(propEnum));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
PRBool hasMore;
|
||||
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
|
||||
nsCOMPtr<nsISupports> sup;
|
||||
rv = propEnum->GetNext(getter_AddRefs(sup));
|
||||
nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup));
|
||||
NS_ENSURE_TRUE(propElem, nsnull);
|
||||
|
||||
nsCAutoString name;
|
||||
rv = propElem->GetKey(name);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
nsAutoString value;
|
||||
rv = propElem->GetValue(value);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
AtkAttribute *objAttribute = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
|
||||
objAttribute->name = g_strdup(name.get());
|
||||
objAttribute->value = g_strdup(NS_ConvertUTF16toUTF8(value).get());
|
||||
objAttributeSet = g_slist_prepend(objAttributeSet, objAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
return objAttributeSet;
|
||||
}
|
||||
|
||||
AtkObject *
|
||||
getParentCB(AtkObject *aAtkObj)
|
||||
{
|
||||
|
@ -90,6 +90,7 @@
|
||||
#include "nsIImageLoadingContent.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIMutableArray.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
#include "nsIFrameDebug.h"
|
||||
@ -1875,6 +1876,32 @@ NS_IMETHODIMP nsAccessible::GetFinalRole(PRUint32 *aRole)
|
||||
return mDOMNode ? GetRole(aRole) : NS_ERROR_FAILURE; // Node already shut down
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
|
||||
{
|
||||
*aAttributes = nsnull;
|
||||
|
||||
if (!mDOMNode) {
|
||||
return NS_ERROR_FAILURE; // Node already shut down
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
|
||||
NS_ENSURE_TRUE(element, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIPersistentProperties> attributes =
|
||||
do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
|
||||
NS_ENSURE_TRUE(attributes, NS_ERROR_NULL_POINTER);
|
||||
|
||||
nsAutoString tagName;
|
||||
nsresult result = element->GetTagName(tagName);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsAutoString oldValueUnused;
|
||||
attributes->SetStringProperty(NS_LITERAL_CSTRING("tag"), tagName, oldValueUnused);
|
||||
}
|
||||
attributes.swap(*aAttributes);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool nsAccessible::MappedAttrState(nsIContent *aContent, PRUint32 *aStateInOut,
|
||||
nsStateMapEntry *aStateMapEntry)
|
||||
{
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include "nsIPlaintextEditor.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsTextFragment.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
@ -727,6 +728,48 @@ NS_IMETHODIMP nsHyperTextAccessible::GetAttributeRange(PRInt32 aOffset, PRInt32
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHyperTextAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
|
||||
{
|
||||
if (!mDOMNode) {
|
||||
return NS_ERROR_FAILURE; // Node already shut down
|
||||
}
|
||||
|
||||
nsAccessibleWrap::GetAttributes(aAttributes);
|
||||
NS_ENSURE_TRUE(*aAttributes, NS_ERROR_NULL_POINTER);
|
||||
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
||||
NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED);
|
||||
nsIAtom *tag = content->Tag();
|
||||
|
||||
PRInt32 headLevel = 0;
|
||||
if (tag == nsAccessibilityAtoms::h1) {
|
||||
headLevel = 1;
|
||||
}
|
||||
else if (tag == nsAccessibilityAtoms::h2) {
|
||||
headLevel = 2;
|
||||
}
|
||||
else if (tag == nsAccessibilityAtoms::h3) {
|
||||
headLevel = 3;
|
||||
}
|
||||
else if (tag == nsAccessibilityAtoms::h4) {
|
||||
headLevel = 4;
|
||||
}
|
||||
else if (tag == nsAccessibilityAtoms::h5) {
|
||||
headLevel = 5;
|
||||
}
|
||||
else if (tag == nsAccessibilityAtoms::h6) {
|
||||
headLevel = 6;
|
||||
}
|
||||
if (headLevel) {
|
||||
nsAutoString valueString;
|
||||
valueString.AppendInt(headLevel);
|
||||
nsAutoString oldValueUnused;
|
||||
(*aAttributes)->SetStringProperty(NS_LITERAL_CSTRING("level"), valueString, oldValueUnused);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Given an offset, the x, y, width, and height values are filled appropriately.
|
||||
*/
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
|
||||
NS_IMETHOD GetRole(PRUint32 *aRole);
|
||||
NS_IMETHOD GetExtState(PRUint32 *aState);
|
||||
NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
|
||||
|
||||
protected:
|
||||
PRBool IsHyperText();
|
||||
|
Loading…
x
Reference in New Issue
Block a user