mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-06 14:44:26 +00:00
Bug 762897 - Implement UIA_AriaPropertiesPropertyId r=tbsaunde
This commit is contained in:
parent
e4dab07b80
commit
36a70a1f7d
@ -7,11 +7,12 @@
|
||||
|
||||
#include "nsARIAMap.h"
|
||||
|
||||
#include "nsAccUtils.h"
|
||||
#include "nsCoreUtils.h"
|
||||
#include "Role.h"
|
||||
#include "States.h"
|
||||
|
||||
#include "nsIContent.h"
|
||||
#include "nsAttrName.h"
|
||||
#include "nsWhitespaceTokenizer.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -684,3 +685,39 @@ aria::UniversalStatesFor(mozilla::dom::Element* aElement)
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// AttrIterator class
|
||||
|
||||
bool
|
||||
AttrIterator::Next(nsAString& aAttrName, nsAString& aAttrValue)
|
||||
{
|
||||
while (mAttrIdx < mAttrCount) {
|
||||
const nsAttrName* attr = mContent->GetAttrNameAt(mAttrIdx);
|
||||
mAttrIdx++;
|
||||
if (attr->NamespaceEquals(kNameSpaceID_None)) {
|
||||
nsIAtom* attrAtom = attr->Atom();
|
||||
nsDependentAtomString attrStr(attrAtom);
|
||||
if (!StringBeginsWith(attrStr, NS_LITERAL_STRING("aria-")))
|
||||
continue; // Not ARIA
|
||||
|
||||
PRUint8 attrFlags = nsAccUtils::GetAttributeCharacteristics(attrAtom);
|
||||
if (attrFlags & ATTR_BYPASSOBJ)
|
||||
continue; // No need to handle exposing as obj attribute here
|
||||
|
||||
if ((attrFlags & ATTR_VALTOKEN) &&
|
||||
!nsAccUtils::HasDefinedARIAToken(mContent, attrAtom))
|
||||
continue; // only expose token based attributes if they are defined
|
||||
|
||||
nsAutoString value;
|
||||
if (mContent->GetAttr(kNameSpaceID_None, attrAtom, value)) {
|
||||
aAttrName.Assign(Substring(attrStr, 5));
|
||||
aAttrValue.Assign(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include "mozilla/a11y/Role.h"
|
||||
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIContent.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsINode;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -226,6 +226,31 @@ nsRoleMapEntry* GetRoleMap(nsINode* aNode);
|
||||
*/
|
||||
PRUint64 UniversalStatesFor(mozilla::dom::Element* aElement);
|
||||
|
||||
/**
|
||||
* Represents a simple enumerator for iterating through ARIA attributes
|
||||
* exposed as object attributes on a given accessible.
|
||||
*/
|
||||
class AttrIterator
|
||||
{
|
||||
public:
|
||||
AttrIterator(nsIContent* aContent) :
|
||||
mContent(aContent), mAttrIdx(0)
|
||||
{
|
||||
mAttrCount = mContent->GetAttrCount();
|
||||
}
|
||||
|
||||
bool Next(nsAString& aAttrName, nsAString& aAttrValue);
|
||||
|
||||
private:
|
||||
AttrIterator() MOZ_DELETE;
|
||||
AttrIterator(const AttrIterator&) MOZ_DELETE;
|
||||
AttrIterator& operator= (const AttrIterator&) MOZ_DELETE;
|
||||
|
||||
nsIContent* mContent;
|
||||
PRUint32 mAttrIdx;
|
||||
PRUint32 mAttrCount;
|
||||
};
|
||||
|
||||
} // namespace aria
|
||||
} // namespace a11y
|
||||
} // namespace mozilla
|
||||
|
@ -1225,25 +1225,11 @@ Accessible::GetAttributes(nsIPersistentProperties **aAttributes)
|
||||
groupPos.setSize, groupPos.posInSet);
|
||||
|
||||
// Expose object attributes from ARIA attributes.
|
||||
PRUint32 numAttrs = mContent->GetAttrCount();
|
||||
for (PRUint32 count = 0; count < numAttrs; count ++) {
|
||||
const nsAttrName *attr = mContent->GetAttrNameAt(count);
|
||||
if (attr && attr->NamespaceEquals(kNameSpaceID_None)) {
|
||||
nsIAtom *attrAtom = attr->Atom();
|
||||
nsDependentAtomString attrStr(attrAtom);
|
||||
if (!StringBeginsWith(attrStr, NS_LITERAL_STRING("aria-")))
|
||||
continue; // Not ARIA
|
||||
PRUint8 attrFlags = nsAccUtils::GetAttributeCharacteristics(attrAtom);
|
||||
if (attrFlags & ATTR_BYPASSOBJ)
|
||||
continue; // No need to handle exposing as obj attribute here
|
||||
if ((attrFlags & ATTR_VALTOKEN) &&
|
||||
!nsAccUtils::HasDefinedARIAToken(mContent, attrAtom))
|
||||
continue; // only expose token based attributes if they are defined
|
||||
nsAutoString value;
|
||||
if (mContent->GetAttr(kNameSpaceID_None, attrAtom, value)) {
|
||||
attributes->SetStringProperty(NS_ConvertUTF16toUTF8(Substring(attrStr, 5)), value, oldValueUnused);
|
||||
}
|
||||
}
|
||||
aria::AttrIterator attribIter(mContent);
|
||||
nsAutoString name, value;
|
||||
while(attribIter.Next(name, value)) {
|
||||
attributes->SetStringProperty(NS_ConvertUTF16toUTF8(name), value,
|
||||
oldValueUnused);
|
||||
}
|
||||
|
||||
// If there is no aria-live attribute then expose default value of 'live'
|
||||
@ -3258,3 +3244,4 @@ KeyBinding::ToAtkFormat(nsAString& aValue) const
|
||||
|
||||
aValue.Append(mKey);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "AccessibleWrap.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsARIAMap.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::a11y;
|
||||
@ -199,6 +200,30 @@ uiaRawElmProvider::GetPropertyValue(PROPERTYID aPropertyId,
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//ARIA Properties
|
||||
case UIA_AriaPropertiesPropertyId: {
|
||||
nsAutoString ariaProperties;
|
||||
|
||||
aria::AttrIterator attribIter(mAcc->GetContent());
|
||||
nsAutoString attribName, attribValue;
|
||||
while (attribIter.Next(attribName, attribValue)) {
|
||||
ariaProperties.Append(attribName);
|
||||
ariaProperties.Append('=');
|
||||
ariaProperties.Append(attribValue);
|
||||
ariaProperties.Append(';');
|
||||
}
|
||||
|
||||
if (!ariaProperties.IsEmpty()) {
|
||||
//remove last delimiter:
|
||||
ariaProperties.Truncate(ariaProperties.Length()-1);
|
||||
aPropertyValue->vt = VT_BSTR;
|
||||
aPropertyValue->bstrVal = ::SysAllocString(ariaProperties.get());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user