Bug 799909 - decomify Accessible::GetNameInternal, r=tbsaunde

This commit is contained in:
Alexander Surkov 2012-10-14 13:18:39 +09:00
parent 221b02948b
commit 50bae428b0
34 changed files with 280 additions and 271 deletions

View File

@ -273,7 +273,7 @@ Accessible::Name(nsString& aName)
return eNameOK;
}
nsresult rv = GetNameInternal(aName);
ENameValueFlag nameFlag = NativeName(aName);
if (!aName.IsEmpty())
return eNameOK;
@ -292,7 +292,7 @@ Accessible::Name(nsString& aName)
return eNameOK;
}
if (rv != NS_OK_EMPTY_NAME)
if (nameFlag != eNoNameOnPurpose)
aName.SetIsVoid(true);
return eNameOK;
@ -1055,26 +1055,19 @@ Accessible::TakeFocus()
return NS_OK;
}
nsresult
Accessible::GetHTMLName(nsAString& aLabel)
void
Accessible::GetHTMLName(nsString& aLabel)
{
nsAutoString label;
Accessible* labelAcc = nullptr;
HTMLLabelIterator iter(Document(), this);
while ((labelAcc = iter.Next())) {
nsresult rv = nsTextEquivUtils::
AppendTextEquivFromContent(this, labelAcc->GetContent(), &label);
NS_ENSURE_SUCCESS(rv, rv);
label.CompressWhitespace();
nsTextEquivUtils::AppendTextEquivFromContent(this, labelAcc->GetContent(),
&aLabel);
aLabel.CompressWhitespace();
}
if (label.IsEmpty())
return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
aLabel = label;
return NS_OK;
if (aLabel.IsEmpty())
nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
}
/**
@ -1089,60 +1082,53 @@ Accessible::GetHTMLName(nsAString& aLabel)
* the control that uses the control="controlID" syntax will use
* the child label for its Name.
*/
nsresult
Accessible::GetXULName(nsAString& aLabel)
void
Accessible::GetXULName(nsString& aName)
{
// CASE #1 (via label attribute) -- great majority of the cases
nsresult rv = NS_OK;
nsAutoString label;
nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl(do_QueryInterface(mContent));
nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl =
do_QueryInterface(mContent);
if (labeledEl) {
rv = labeledEl->GetLabel(label);
}
else {
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl(do_QueryInterface(mContent));
labeledEl->GetLabel(aName);
} else {
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl =
do_QueryInterface(mContent);
if (itemEl) {
rv = itemEl->GetLabel(label);
}
else {
nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mContent));
itemEl->GetLabel(aName);
} else {
nsCOMPtr<nsIDOMXULSelectControlElement> select =
do_QueryInterface(mContent);
// Use label if this is not a select control element which
// uses label attribute to indicate which option is selected
if (!select) {
nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(mContent));
if (xulEl) {
rv = xulEl->GetAttribute(NS_LITERAL_STRING("label"), label);
}
if (xulEl)
xulEl->GetAttribute(NS_LITERAL_STRING("label"), aName);
}
}
}
// CASES #2 and #3 ------ label as a child or <label control="id" ... > </label>
if (NS_FAILED(rv) || label.IsEmpty()) {
label.Truncate();
if (aName.IsEmpty()) {
Accessible* labelAcc = nullptr;
XULLabelIterator iter(Document(), mContent);
while ((labelAcc = iter.Next())) {
nsCOMPtr<nsIDOMXULLabelElement> xulLabel =
do_QueryInterface(labelAcc->GetContent());
// Check if label's value attribute is used
if (xulLabel && NS_SUCCEEDED(xulLabel->GetValue(label)) && label.IsEmpty()) {
if (xulLabel && NS_SUCCEEDED(xulLabel->GetValue(aName)) && aName.IsEmpty()) {
// If no value attribute, a non-empty label must contain
// children that define its text -- possibly using HTML
nsTextEquivUtils::
AppendTextEquivFromContent(this, labelAcc->GetContent(), &label);
AppendTextEquivFromContent(this, labelAcc->GetContent(), &aName);
}
}
}
// XXX If CompressWhiteSpace worked on nsAString we could avoid a copy
label.CompressWhitespace();
if (!label.IsEmpty()) {
aLabel = label;
return NS_OK;
}
aName.CompressWhitespace();
if (!aName.IsEmpty())
return;
// Can get text from title of <toolbaritem> if we're a child of a <toolbaritem>
nsIContent *bindingParent = mContent->GetBindingParent();
@ -1150,15 +1136,14 @@ Accessible::GetXULName(nsAString& aLabel)
mContent->GetParent();
while (parent) {
if (parent->Tag() == nsGkAtoms::toolbaritem &&
parent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, label)) {
label.CompressWhitespace();
aLabel = label;
return NS_OK;
parent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, aName)) {
aName.CompressWhitespace();
return;
}
parent = parent->GetParent();
}
return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
nsTextEquivUtils::GetNameFromSubtree(this, aName);
}
nsresult
@ -2433,9 +2418,6 @@ Accessible::Shutdown()
nsAccessNodeWrap::Shutdown();
}
////////////////////////////////////////////////////////////////////////////////
// Accessible public methods
// Accessible protected
void
Accessible::ARIAName(nsAString& aName)
@ -2458,16 +2440,16 @@ Accessible::ARIAName(nsAString& aName)
}
}
nsresult
Accessible::GetNameInternal(nsAString& aName)
// Accessible protected
ENameValueFlag
Accessible::NativeName(nsString& aName)
{
if (mContent->IsHTML())
return GetHTMLName(aName);
GetHTMLName(aName);
else if (mContent->IsXUL())
GetXULName(aName);
if (mContent->IsXUL())
return GetXULName(aName);
return NS_OK;
return eNameOK;
}
// Accessible protected
@ -2490,6 +2472,7 @@ Accessible::BindToParent(Accessible* aParent, uint32_t aIndexInParent)
mIndexInParent = aIndexInParent;
}
// Accessible protected
void
Accessible::UnbindFromParent()
{
@ -2499,6 +2482,9 @@ Accessible::UnbindFromParent()
mGroupInfo = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
// Accessible public methods
void
Accessible::InvalidateChildren()
{

View File

@ -49,10 +49,19 @@ enum ENameValueFlag {
* Name either
* a) present (not empty): !name.IsEmpty()
* b) no name (was missed): name.IsVoid()
* c) was left empty by the author on demand: name.IsEmpty() && !name.IsVoid()
*/
eNameOK,
eNameFromTooltip // Tooltip was used as a name
/**
* Name was left empty by the author on purpose:
* name.IsEmpty() && !name.IsVoid().
*/
eNoNameOnPurpose,
/**
* Tooltip was used as a name.
*/
eNameFromTooltip
};
/**
@ -132,6 +141,9 @@ public:
/**
* Get the name of this accessible.
*
* Note: aName.IsVoid() when name was left empty by the author on purpose.
* aName.IsEmpty() when the author missed name, AT can try to repair a name.
*/
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
@ -155,18 +167,6 @@ public:
*/
virtual void ApplyARIAState(uint64_t* aState) const;
/**
* Returns the accessible name provided by native markup. It doesn't take
* into account ARIA markup used to specify the name.
*
* @param aName [out] the accessible name
*
* @return NS_OK_EMPTY_NAME points empty name was specified by native markup
* explicitly (see nsIAccessible::name attribute for
* details)
*/
virtual nsresult GetNameInternal(nsAString& aName);
/**
* Return enumerated accessible role (see constants in Role.h).
*/
@ -793,20 +793,22 @@ protected:
//////////////////////////////////////////////////////////////////////////////
// Name helpers
/**
* Return the accessible name provided by native markup. It doesn't take
* into account ARIA markup used to specify the name.
*/
virtual mozilla::a11y::ENameValueFlag NativeName(nsString& aName);
/**
* Returns the accessible name specified by ARIA.
*/
void ARIAName(nsAString& aName);
/**
* Compute the name of HTML node.
* Compute the name of HTML/XUL node.
*/
nsresult GetHTMLName(nsAString& aName);
/**
* Compute the name for XUL node.
*/
nsresult GetXULName(nsAString& aName);
void GetHTMLName(nsString& aName);
void GetXULName(nsString& aName);
// helper method to verify frames
static nsresult GetFullKeyName(const nsAString& aModifierName, const nsAString& aKeyName, nsAString& aStringOut);

View File

@ -1949,23 +1949,20 @@ HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartIndex,
////////////////////////////////////////////////////////////////////////////////
// Accessible public
nsresult
HyperTextAccessible::GetNameInternal(nsAString& aName)
// Accessible protected
ENameValueFlag
HyperTextAccessible::NativeName(nsString& aName)
{
nsresult rv = AccessibleWrap::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
AccessibleWrap::NativeName(aName);
// Get name from title attribute for HTML abbr and acronym elements making it
// a valid name from markup. Otherwise their name isn't picked up by recursive
// name computation algorithm. See NS_OK_NAME_FROM_TOOLTIP.
if (aName.IsEmpty() && IsAbbreviation()) {
nsAutoString name;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, name)) {
name.CompressWhitespace();
aName = name;
}
}
return NS_OK;
if (aName.IsEmpty() && IsAbbreviation() &&
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, aName))
aName.CompressWhitespace();
return eNameOK;
}
void

View File

@ -52,7 +52,6 @@ public:
// Accessible
virtual int32_t GetLevelInternal();
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
virtual uint64_t NativeState();
@ -243,6 +242,9 @@ public:
virtual already_AddRefed<nsIEditor> GetEditor() const;
protected:
// Accessible
virtual mozilla::a11y::ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
// HyperTextAccessible
/**

View File

@ -69,26 +69,24 @@ ImageAccessible::NativeState()
return state;
}
nsresult
ImageAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
ImageAccessible::NativeName(nsString& aName)
{
bool hasAltAttrib =
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName);
if (!aName.IsEmpty())
return NS_OK;
nsresult rv = Accessible::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
return eNameOK;
Accessible::NativeName(aName);
if (aName.IsEmpty() && hasAltAttrib) {
// No accessible name but empty 'alt' attribute is present. If further name
// computation algorithm doesn't provide non empty name then it means
// an empty 'alt' attribute was used to indicate a decorative image (see
// nsIAccessible::name attribute for details).
return NS_OK_EMPTY_NAME;
return eNoNameOnPurpose;
}
return NS_OK;
return eNameOK;
}
role

View File

@ -36,7 +36,6 @@ public:
NS_DECL_NSIACCESSIBLEIMAGE
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
@ -44,6 +43,10 @@ public:
// ActionAccessible
virtual uint8_t ActionCount();
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
private:
/**
* Return whether the element has a longdesc URI.

View File

@ -41,11 +41,11 @@ HTMLBRAccessible::NativeState()
return states::READONLY;
}
nsresult
HTMLBRAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLBRAccessible::NativeName(nsString& aName)
{
aName = static_cast<PRUnichar>('\n'); // Newline char
return NS_OK;
return eNameOK;
}
////////////////////////////////////////////////////////////////////////////////
@ -54,10 +54,11 @@ HTMLBRAccessible::GetNameInternal(nsAString& aName)
NS_IMPL_ISUPPORTS_INHERITED0(HTMLLabelAccessible, HyperTextAccessible)
nsresult
HTMLLabelAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLLabelAccessible::NativeName(nsString& aName)
{
return nsTextEquivUtils::GetNameFromSubtree(this, aName);
nsTextEquivUtils::GetNameFromSubtree(this, aName);
return eNameOK;
}
role

View File

@ -32,14 +32,16 @@ public:
class HTMLBRAccessible : public LeafAccessible
{
public:
HTMLBRAccessible(nsIContent* aContent, DocAccessible* aDoc) :
LeafAccessible(aContent, aDoc) {};
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**
@ -55,8 +57,10 @@ public:
NS_DECL_ISUPPORTS_INHERITED
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
protected:
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**

View File

@ -256,37 +256,32 @@ HTMLButtonAccessible::NativeRole()
return roles::PUSHBUTTON;
}
nsresult
HTMLButtonAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLButtonAccessible::NativeName(nsString& aName)
{
Accessible::GetNameInternal(aName);
Accessible::NativeName(aName);
if (!aName.IsEmpty() || mContent->Tag() != nsGkAtoms::input)
return NS_OK;
return eNameOK;
// No name from HTML or ARIA
nsAutoString name;
if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value,
name) &&
!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt,
name)) {
if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName) &&
!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName)) {
// Use the button's (default) label if nothing else works
nsIFrame* frame = GetFrame();
if (frame) {
nsIFormControlFrame* fcFrame = do_QueryFrame(frame);
if (fcFrame)
fcFrame->GetFormProperty(nsGkAtoms::defaultLabel, name);
fcFrame->GetFormProperty(nsGkAtoms::defaultLabel, aName);
}
}
if (name.IsEmpty() &&
!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, name)) {
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, name);
if (aName.IsEmpty() &&
!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, aName)) {
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, aName);
}
name.CompressWhitespace();
aName = name;
return NS_OK;
aName.CompressWhitespace();
return eNameOK;
}
////////////////////////////////////////////////////////////////////////////////
@ -325,17 +320,14 @@ HTMLTextFieldAccessible::NativeRole()
return roles::ENTRY;
}
nsresult
HTMLTextFieldAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLTextFieldAccessible::NativeName(nsString& aName)
{
nsresult rv = Accessible::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
Accessible::NativeName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
if (mContent->GetBindingParent())
{
if (mContent->GetBindingParent()) {
// XXX: bug 459640
// There's a binding parent.
// This means we're part of another control, so use parent accessible for name.
@ -347,12 +339,11 @@ HTMLTextFieldAccessible::GetNameInternal(nsAString& aName)
}
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
// text inputs and textareas might have useful placeholder text
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, aName);
return NS_OK;
return eNameOK;
}
void
@ -619,22 +610,18 @@ HTMLGroupboxAccessible::GetLegend()
return nullptr;
}
nsresult
HTMLGroupboxAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLGroupboxAccessible::NativeName(nsString& aName)
{
nsresult rv = Accessible::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
Accessible::NativeName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
nsIContent *legendContent = GetLegend();
if (legendContent) {
return nsTextEquivUtils::
AppendTextEquivFromContent(this, legendContent, &aName);
}
nsIContent* legendContent = GetLegend();
if (legendContent)
nsTextEquivUtils::AppendTextEquivFromContent(this, legendContent, &aName);
return NS_OK;
return eNameOK;
}
Relation
@ -706,22 +693,18 @@ HTMLFigureAccessible::NativeRole()
return roles::FIGURE;
}
nsresult
HTMLFigureAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLFigureAccessible::NativeName(nsString& aName)
{
nsresult rv = HyperTextAccessibleWrap::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
HyperTextAccessibleWrap::NativeName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
nsIContent* captionContent = Caption();
if (captionContent) {
return nsTextEquivUtils::
AppendTextEquivFromContent(this, captionContent, &aName);
}
if (captionContent)
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
return NS_OK;
return eNameOK;
}
Relation

View File

@ -77,7 +77,6 @@ public:
NS_IMETHOD DoAction(uint8_t index);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
virtual uint64_t State();
virtual uint64_t NativeState();
@ -87,6 +86,10 @@ public:
// Widgets
virtual bool IsWidget() const;
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
@ -113,7 +116,6 @@ public:
// Accessible
virtual void Value(nsString& aValue);
virtual void ApplyARIAState(uint64_t* aState) const;
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
virtual uint64_t State();
virtual uint64_t NativeState();
@ -124,6 +126,10 @@ public:
// Widgets
virtual bool IsWidget() const;
virtual Accessible* ContainerWidget() const;
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
@ -149,11 +155,14 @@ public:
HTMLGroupboxAccessible(nsIContent* aContent, DocAccessible* aDoc);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
virtual Relation RelationByType(uint32_t aType);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
// HTMLGroupboxAccessible
nsIContent* GetLegend();
};
@ -181,11 +190,14 @@ public:
// Accessible
virtual nsresult GetAttributesInternal(nsIPersistentProperties* aAttributes);
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
virtual Relation RelationByType(uint32_t aType);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
// HTMLLegendAccessible
nsIContent* Caption() const;
};

View File

@ -160,19 +160,17 @@ HTMLAreaAccessible::
////////////////////////////////////////////////////////////////////////////////
// HTMLAreaAccessible: nsIAccessible
nsresult
HTMLAreaAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLAreaAccessible::NativeName(nsString& aName)
{
nsresult rv = Accessible::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
Accessible::NativeName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName))
return GetValue(aName);
GetValue(aName);
return NS_OK;
return eNameOK;
}
void

View File

@ -55,7 +55,6 @@ public:
// Accessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
EWhichChildAtPoint aWhichChild);
virtual void GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame);
@ -65,8 +64,8 @@ public:
virtual uint32_t EndOffset();
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
virtual void CacheChildren();
};

View File

@ -185,34 +185,24 @@ HTMLSelectOptionAccessible::NativeRole()
return roles::OPTION;
}
nsresult
HTMLSelectOptionAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLSelectOptionAccessible::NativeName(nsString& aName)
{
// CASE #1 -- great majority of the cases
// find the label attribute - this is what the W3C says we should use
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
// CASE #2 -- no label parameter, get the first child,
// use it if it is a text node
nsIContent* text = mContent->GetFirstChild();
if (!text)
return NS_OK;
if (text->IsNodeOfType(nsINode::eTEXT)) {
nsAutoString txtValue;
nsresult rv = nsTextEquivUtils::
AppendTextEquivFromTextContent(text, &txtValue);
NS_ENSURE_SUCCESS(rv, rv);
// Temp var (txtValue) needed until CompressWhitespace built for nsAString
txtValue.CompressWhitespace();
aName.Assign(txtValue);
return NS_OK;
if (text && text->IsNodeOfType(nsINode::eTEXT)) {
nsTextEquivUtils::AppendTextEquivFromTextContent(text, &aName);
aName.CompressWhitespace();
}
return NS_OK;
return eNameOK;
}
uint64_t

View File

@ -84,7 +84,6 @@ public:
NS_IMETHOD SetSelected(bool aSelect);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
virtual uint64_t NativeInteractiveState() const;
@ -98,6 +97,10 @@ public:
// Widgets
virtual Accessible* ContainerWidget() const;
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
private:
/**

View File

@ -385,12 +385,12 @@ HTMLTableAccessible::NativeState()
return Accessible::NativeState() | states::READONLY;
}
nsresult
HTMLTableAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
HTMLTableAccessible::NativeName(nsString& aName)
{
Accessible::GetNameInternal(aName);
Accessible::NativeName(aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
// Use table caption as a name.
Accessible* caption = Caption();
@ -399,13 +399,13 @@ HTMLTableAccessible::GetNameInternal(nsAString& aName)
if (captionContent) {
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
if (!aName.IsEmpty())
return NS_OK;
return eNameOK;
}
}
// If no caption then use summary as a name.
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
return NS_OK;
return eNameOK;
}
nsresult

View File

@ -143,7 +143,6 @@ public:
// Accessible
virtual TableAccessible* AsTable() { return this; }
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
@ -163,8 +162,8 @@ public:
nsITableLayout* GetTableLayout();
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
virtual void CacheChildren();
// HTMLTableAccessible

View File

@ -264,7 +264,7 @@ __try {
// The name was not provided, e.g. no alt attribute for an image. A screen
// reader may choose to invent its own accessible name, e.g. from an image src
// attribute. Refer to NS_OK_EMPTY_NAME return value.
// attribute. Refer to eNoNameOnPurpose return value.
if (name.IsVoid())
return S_FALSE;

View File

@ -158,11 +158,12 @@ nsXFormsAccessible::NativelyUnavailable() const
return !isRelevant;
}
nsresult
nsXFormsAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
nsXFormsAccessible::NativeName(nsString& aName)
{
// search the xforms:label element
return GetBoundChildElementValue(NS_LITERAL_STRING("label"), aName);
GetBoundChildElementValue(NS_LITERAL_STRING("label"), aName);
return eNameOK;
}
void

View File

@ -46,9 +46,6 @@ public:
// Returns value of instance node that xforms element is bound to.
virtual void Value(nsString& aValue);
// Returns value of child xforms 'label' element.
virtual nsresult GetNameInternal(nsAString& aName);
// Returns state of xforms element taking into account state of instance node
// that it is bound to.
virtual uint64_t NativeState();
@ -58,7 +55,12 @@ public:
// always returning false value.
virtual bool CanHaveAnonChildren();
protected:
// Accessible
// Returns value of child xforms 'label' element.
virtual mozilla::a11y::ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
// Returns value of first child xforms element by tagname that is bound to
// instance node.
nsresult GetBoundChildElementValue(const nsAString& aTagName,

View File

@ -27,11 +27,11 @@ nsXFormsLabelAccessible::NativeRole()
return roles::LABEL;
}
nsresult
nsXFormsLabelAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
nsXFormsLabelAccessible::NativeName(nsString& aName)
{
// XXX Correct name calculation for this, see bug 453594.
return NS_OK;
return eNameOK;
}
void

View File

@ -19,8 +19,11 @@ public:
// Accessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
protected:
// Accessible
virtual mozilla::a11y::ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**

View File

@ -133,12 +133,12 @@ nsXFormsComboboxPopupWidgetAccessible::NativeInteractiveState() const
return NativelyUnavailable() ? states::UNAVAILABLE : states::FOCUSABLE;
}
nsresult
nsXFormsComboboxPopupWidgetAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
nsXFormsComboboxPopupWidgetAccessible::NativeName(nsString& aName)
{
// Override nsXFormsAccessible::GetName() to prevent name calculation by
// XForms rules.
return NS_OK;
return eNameOK;
}
void

View File

@ -61,13 +61,13 @@ public:
// Accessible
virtual void Description(nsString& aDescription);
virtual void Value(nsString& aValue);
virtual nsresult GetNameInternal(nsAString& aName);
virtual mozilla::a11y::role NativeRole();
virtual uint64_t NativeState();
virtual uint64_t NativeInteractiveState() const;
protected:
// Accessible
virtual mozilla::a11y::ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
virtual void CacheChildren();
};

View File

@ -32,13 +32,13 @@ XULLabelAccessible::
{
}
nsresult
XULLabelAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULLabelAccessible::NativeName(nsString& aName)
{
// if the value attr doesn't exist, the screen reader must get the accessible text
// from the accessible text interface or from the children
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
return NS_OK;
return eNameOK;
}
role
@ -121,14 +121,14 @@ XULLinkAccessible::Value(nsString& aValue)
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, aValue);
}
nsresult
XULLinkAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULLinkAccessible::NativeName(nsString& aName)
{
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
if (!aName.IsEmpty())
return NS_OK;
if (aName.IsEmpty())
nsTextEquivUtils::GetNameFromSubtree(this, aName);
return nsTextEquivUtils::GetNameFromSubtree(this, aName);
return eNameOK;
}
role

View File

@ -21,10 +21,13 @@ public:
XULLabelAccessible(nsIContent* aContent, DocAccessible* aDoc);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
virtual Relation RelationByType(uint32_t aRelationType);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**
@ -55,7 +58,6 @@ public:
// Accessible
virtual void Value(nsString& aValue);
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeLinkState() const;
@ -69,6 +71,9 @@ public:
virtual already_AddRefed<nsIURI> AnchorURIAt(uint32_t aAnchorIndex);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
enum { eAction_Jump = 0 };
};

View File

@ -413,16 +413,16 @@ XULGroupboxAccessible::NativeRole()
return roles::GROUPING;
}
nsresult
XULGroupboxAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULGroupboxAccessible::NativeName(nsString& aName)
{
// XXX: we use the first related accessible only.
Accessible* label =
RelationByType(nsIAccessibleRelation::RELATION_LABELLED_BY).Next();
if (label)
return label->GetName(aName);
return label->Name(aName);
return NS_OK;
return eNameOK;
}
Relation
@ -639,16 +639,13 @@ XULToolbarAccessible::NativeRole()
return roles::TOOLBAR;
}
nsresult
XULToolbarAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULToolbarAccessible::NativeName(nsString& aName)
{
nsAutoString name;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::toolbarname, name)) {
name.CompressWhitespace();
aName = name;
}
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::toolbarname, aName))
aName.CompressWhitespace();
return NS_OK;
return eNameOK;
}

View File

@ -117,8 +117,11 @@ public:
// Accessible
virtual mozilla::a11y::role NativeRole();
virtual nsresult GetNameInternal(nsAString& aName);
virtual Relation RelationByType(uint32_t aRelationType);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**
@ -194,7 +197,10 @@ public:
// Accessible
virtual mozilla::a11y::role NativeRole();
virtual nsresult GetNameInternal(nsAString& aName);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**

View File

@ -622,18 +622,20 @@ XULListitemAccessible::Description(nsString& aDesc)
* If there is a Listcell as a child ( not anonymous ) use it, otherwise
* default to getting the name from GetXULName
*/
nsresult
XULListitemAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULListitemAccessible::NativeName(nsString& aName)
{
nsIContent* childContent = mContent->GetFirstChild();
if (childContent) {
if (childContent->NodeInfo()->Equals(nsGkAtoms::listcell,
kNameSpaceID_XUL)) {
childContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
return NS_OK;
return eNameOK;
}
}
return GetXULName(aName);
GetXULName(aName);
return eNameOK;
}
role

View File

@ -131,7 +131,6 @@ public:
// Accessible
virtual void Description(nsString& aDesc);
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
virtual uint64_t NativeInteractiveState() const;
@ -141,6 +140,11 @@ public:
virtual Accessible* ContainerWidget() const;
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
// XULListitemAccessible
/**
* Return listbox accessible for the listitem.
*/

View File

@ -134,11 +134,11 @@ XULMenuitemAccessible::NativeInteractiveState() const
return states::FOCUSABLE | states::SELECTABLE;
}
nsresult
XULMenuitemAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULMenuitemAccessible::NativeName(nsString& aName)
{
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
return NS_OK;
return eNameOK;
}
void
@ -396,10 +396,10 @@ XULMenuSeparatorAccessible::NativeState()
(states::OFFSCREEN | states::INVISIBLE);
}
nsresult
XULMenuSeparatorAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULMenuSeparatorAccessible::NativeName(nsString& aName)
{
return NS_OK;
return eNameOK;
}
role
@ -469,16 +469,16 @@ XULMenupopupAccessible::NativeState()
return state;
}
nsresult
XULMenupopupAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULMenupopupAccessible::NativeName(nsString& aName)
{
nsIContent *content = mContent;
nsIContent* content = mContent;
while (content && aName.IsEmpty()) {
content->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
content = content->GetParent();
}
return NS_OK;
return eNameOK;
}
role
@ -572,11 +572,11 @@ XULMenubarAccessible::
{
}
nsresult
XULMenubarAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULMenubarAccessible::NativeName(nsString& aName)
{
aName.AssignLiteral("Application");
return NS_OK;
return eNameOK;
}
role

View File

@ -29,7 +29,6 @@ public:
// Accessible
virtual void Description(nsString& aDescription);
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
virtual uint64_t NativeInteractiveState() const;
@ -46,6 +45,10 @@ public:
virtual bool IsActiveWidget() const;
virtual bool AreItemsOperable() const;
virtual Accessible* ContainerWidget() const;
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**
@ -61,12 +64,15 @@ public:
NS_IMETHOD GetActionName(uint8_t aIndex, nsAString& aName);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
// ActionAccessible
virtual uint8_t ActionCount();
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
@ -79,7 +85,6 @@ public:
XULMenupopupAccessible(nsIContent* aContent, DocAccessible* aDoc);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
@ -89,6 +94,10 @@ public:
virtual bool AreItemsOperable() const;
virtual Accessible* ContainerWidget() const;
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
/**
@ -100,7 +109,6 @@ public:
XULMenubarAccessible(nsIContent* aContent, DocAccessible* aDoc);
// Accessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
// Widget
@ -108,6 +116,10 @@ public:
virtual bool AreItemsOperable() const;
virtual Accessible* CurrentItem();
virtual void SetCurrentItem(Accessible* aItem);
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};
} // namespace a11y

View File

@ -154,11 +154,11 @@ XULTabsAccessible::Value(nsString& aValue)
aValue.Truncate();
}
nsresult
XULTabsAccessible::GetNameInternal(nsAString& aName)
ENameValueFlag
XULTabsAccessible::NativeName(nsString& aName)
{
// no name
return NS_OK;
return eNameOK;
}

View File

@ -48,11 +48,14 @@ public:
// Accessible
virtual void Value(nsString& aValue);
virtual nsresult GetNameInternal(nsAString& aName);
virtual a11y::role NativeRole();
// ActionAccessible
virtual uint8_t ActionCount();
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
};

View File

@ -905,9 +905,6 @@
/* see Accessible::GetAttrValue */
ERROR(NS_OK_NO_ARIA_VALUE, SUCCESS(33)),
ERROR(NS_OK_DEFUNCT_OBJECT, SUCCESS(34)),
/* see Accessible::GetNameInternal */
ERROR(NS_OK_EMPTY_NAME, SUCCESS(35)),
ERROR(NS_OK_NO_NAME_CLAUSE_HANDLED, SUCCESS(36)),
/* see Accessible::GetNameInternal */
ERROR(NS_OK_NAME_FROM_TOOLTIP, SUCCESS(37))
/* see nsTextEquivUtils */
ERROR(NS_OK_NO_NAME_CLAUSE_HANDLED, SUCCESS(35))
#undef MODULE