bug 1088628 - implement Accessible::Attributes for proxies r=davidb

This commit is contained in:
Trevor Saunders 2014-10-24 05:29:48 -04:00
parent 9c6679d172
commit 90ff4f44c0
7 changed files with 86 additions and 1 deletions

View File

@ -10,6 +10,7 @@
#include "ApplicationAccessibleWrap.h"
#include "InterfaceInitFuncs.h"
#include "nsAccUtils.h"
#include "mozilla/a11y/PDocAccessible.h"
#include "ProxyAccessible.h"
#include "RootAccessible.h"
#include "nsMai.h"
@ -771,7 +772,27 @@ AtkAttributeSet *
getAttributesCB(AtkObject *aAtkObj)
{
AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj);
return accWrap ? GetAttributeSet(accWrap) : nullptr;
if (accWrap)
return GetAttributeSet(accWrap);
ProxyAccessible* proxy = GetProxy(aAtkObj);
if (!proxy)
return nullptr;
nsAutoTArray<Attribute, 10> attrs;
proxy->Attributes(&attrs);
if (attrs.IsEmpty())
return nullptr;
AtkAttributeSet* objAttributeSet = nullptr;
for (uint32_t i = 0; i < attrs.Length(); i++) {
AtkAttribute *objAttr = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
objAttr->name = g_strdup(attrs[i].Name().get());
objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(attrs[i].Value()).get());
objAttributeSet = g_slist_prepend(objAttributeSet, objAttr);
}
return objAttributeSet;
}
const gchar*

View File

@ -49,3 +49,5 @@ if CONFIG['MOZ_ENABLE_GTK']:
if CONFIG['MOZ_ENABLE_DBUS']:
CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
include('/ipc/chromium/chromium-config.mozbuild')

View File

@ -8,6 +8,9 @@
#include "Accessible-inl.h"
#include "nsIPersistentProperties2.h"
#include "nsISimpleEnumerator.h"
namespace mozilla {
namespace a11y {
@ -76,5 +79,43 @@ DocAccessibleChild::RecvDescription(const uint64_t& aID, nsString* aDesc)
acc->Description(*aDesc);
return true;
}
bool
DocAccessibleChild::RecvAttributes(const uint64_t& aID, nsTArray<Attribute>* aAttributes)
{
Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
if (!acc)
return true;
nsCOMPtr<nsIPersistentProperties> props = acc->Attributes();
if (!props)
return true;
nsCOMPtr<nsISimpleEnumerator> propEnum;
nsresult rv = props->Enumerate(getter_AddRefs(propEnum));
NS_ENSURE_SUCCESS(rv, false);
bool hasMore;
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> sup;
rv = propEnum->GetNext(getter_AddRefs(sup));
NS_ENSURE_SUCCESS(rv, false);
nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup));
NS_ENSURE_TRUE(propElem, false);
nsAutoCString name;
rv = propElem->GetKey(name);
NS_ENSURE_SUCCESS(rv, false);
nsAutoString value;
rv = propElem->GetValue(value);
NS_ENSURE_SUCCESS(rv, false);
aAttributes->AppendElement(Attribute(name, value));
}
return true;
}
}
}

View File

@ -48,6 +48,8 @@ public:
*/
virtual bool RecvDescription(const uint64_t& aID, nsString* aDesc) MOZ_OVERRIDE;
virtual bool RecvAttributes(const uint64_t& aID, nsTArray<Attribute> *aAttributes) MOZ_OVERRIDE;
private:
DocAccessible* mDoc;
};

View File

@ -23,6 +23,12 @@ struct ShowEventData
AccessibleData[] NewTree;
};
struct Attribute
{
nsCString Name;
nsString Value;
};
prio(normal upto high) sync protocol PDocAccessible
{
manager PContent;
@ -42,6 +48,7 @@ child:
prio(high) sync State(uint64_t aID) returns(uint64_t states);
prio(high) sync Name(uint64_t aID) returns(nsString name);
prio(high) sync Description(uint64_t aID) returns(nsString desc);
prio(high) sync Attributes(uint64_t aID) returns(Attribute[] attributes);
};
}

View File

@ -59,5 +59,11 @@ ProxyAccessible::Description(nsString& aDesc) const
{
unused << mDoc->SendDescription(mID, &aDesc);
}
void
ProxyAccessible::Attributes(nsTArray<Attribute> *aAttrs) const
{
unused << mDoc->SendAttributes(mID, aAttrs);
}
}
}

View File

@ -14,6 +14,7 @@
namespace mozilla {
namespace a11y {
class Attribute;
class DocAccessibleParent;
class ProxyAccessible
@ -68,6 +69,11 @@ public:
*/
void Description(nsString& aDesc) const;
/**
* Get the set of attributes on the proxied accessible.
*/
void Attributes(nsTArray<Attribute> *aAttrs) const;
/**
* Allow the platform to store a pointers worth of data on us.
*/