diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index a4f1bcd87b4..b124efc466c 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -3223,7 +3223,7 @@ nsAccessible::GetAttrValue(nsIAtom *aProperty, double *aValue) NS_ENSURE_ARG_POINTER(aValue); *aValue = 0; - if (!mDOMNode) + if (IsDefunct()) return NS_ERROR_FAILURE; // Node already shut down if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue) @@ -3232,12 +3232,19 @@ nsAccessible::GetAttrValue(nsIAtom *aProperty, double *aValue) nsCOMPtr content(do_QueryInterface(mDOMNode)); NS_ENSURE_STATE(content); - PRInt32 result = NS_OK; - nsAutoString value; - if (content->GetAttr(kNameSpaceID_None, aProperty, value)) - *aValue = value.ToFloat(&result); + nsAutoString attrValue; + content->GetAttr(kNameSpaceID_None, aProperty, attrValue); - return result; + // Return zero value if there is no attribute or its value is empty. + if (attrValue.IsEmpty()) + return NS_OK; + + PRInt32 error = NS_OK; + double value = attrValue.ToFloat(&error); + if (NS_SUCCEEDED(error)) + *aValue = value; + + return NS_OK; } PRUint32 diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index 8564ab76a20..e15a8d3d535 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -579,16 +579,25 @@ nsXULProgressMeterAccessible::GetCurrentValue(double *aCurrentValue) nsCOMPtr content(do_QueryInterface(mDOMNode)); - nsAutoString currentValue; - content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, currentValue); + nsAutoString attrValue; + content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, attrValue); - PRInt32 result = NS_OK; - if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::max)) - *aCurrentValue = currentValue.ToFloat(&result); - else - *aCurrentValue = currentValue.ToFloat(&result) / 100; + // Return zero value if there is no attribute or its value is empty. + if (attrValue.IsEmpty()) + return NS_OK; - return result; + PRInt32 error = NS_OK; + double value = attrValue.ToFloat(&error); + if (NS_FAILED(error)) + return NS_OK; // Zero value because of wrong markup. + + // If no max value then value is between 0 and 1 (refer to GetMaximumValue() + // method where max value is assumed to be equal to 1 in this case). + if (!content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::max)) + value /= 100; + + *aCurrentValue = value; + return NS_OK; } NS_IMETHODIMP diff --git a/accessible/src/xul/nsXULSliderAccessible.cpp b/accessible/src/xul/nsXULSliderAccessible.cpp index 75c0ea277e3..5e037aa7a64 100644 --- a/accessible/src/xul/nsXULSliderAccessible.cpp +++ b/accessible/src/xul/nsXULSliderAccessible.cpp @@ -49,6 +49,12 @@ nsXULSliderAccessible::nsXULSliderAccessible(nsIDOMNode* aNode, { } +// nsISupports + +NS_IMPL_ISUPPORTS_INHERITED1(nsXULSliderAccessible, + nsAccessibleWrap, + nsIAccessibleValue) + // nsIAccessible nsresult @@ -175,7 +181,7 @@ nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, nsAString& aValue) { aValue.Truncate(); - if (!mDOMNode) + if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr sliderNode(GetSliderNode()); @@ -188,7 +194,7 @@ nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, nsAString& aValue) nsresult nsXULSliderAccessible::SetSliderAttr(nsIAtom *aName, const nsAString& aValue) { - if (!mDOMNode) + if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr sliderNode(GetSliderNode()); @@ -204,13 +210,20 @@ nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, double *aValue) NS_ENSURE_ARG_POINTER(aValue); *aValue = 0; - nsAutoString value; - nsresult rv = GetSliderAttr(aName, value); + nsAutoString attrValue; + nsresult rv = GetSliderAttr(aName, attrValue); NS_ENSURE_SUCCESS(rv, rv); + // Return zero value if there is no attribute or its value is empty. + if (attrValue.IsEmpty()) + return NS_OK; + PRInt32 error = NS_OK; - *aValue = value.ToFloat(&error); - return error; + double value = attrValue.ToFloat(&error); + if (NS_SUCCEEDED(error)) + *aValue = value; + + return NS_OK; } nsresult diff --git a/accessible/src/xul/nsXULSliderAccessible.h b/accessible/src/xul/nsXULSliderAccessible.h index e46aa1c74d4..514b49266ae 100644 --- a/accessible/src/xul/nsXULSliderAccessible.h +++ b/accessible/src/xul/nsXULSliderAccessible.h @@ -48,15 +48,14 @@ class nsXULSliderAccessible : public nsAccessibleWrap public: nsXULSliderAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + // nsIAccessible NS_IMETHOD GetValue(nsAString& aValue); // nsIAccessibleValue - NS_IMETHOD GetMaximumValue(double *aMaximumValue); - NS_IMETHOD GetMinimumValue(double *aMinimumValue); - NS_IMETHOD GetMinimumIncrement(double *aMinIncrement); - NS_IMETHOD GetCurrentValue(double *aValue); - NS_IMETHOD SetCurrentValue(double aValue); + NS_DECL_NSIACCESSIBLEVALUE // nsPIAccessible NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren); diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index 505a24e682c..9e09e893910 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -64,6 +64,7 @@ _TEST_FILES =\ nsIAccessibleEditableText.js \ relations.js \ role.js \ + value.js \ test_accessnode_invalidation.html \ test_actions_aria.html \ $(warning test_actions_inputs.html temporarily disabled) \ @@ -78,7 +79,6 @@ _TEST_FILES =\ test_descr.html \ test_elm_filectrl.html \ test_elm_media.html \ - test_elm_prgrsmtr.xul \ test_elm_txtcntnr.html \ test_events_caretmove.html \ test_events_mutation.html \ @@ -121,6 +121,7 @@ _TEST_FILES =\ test_textattrs.html \ test_textboxes.html \ test_textboxes.xul \ + test_value.xul \ testTextboxes.js \ treeview.js \ z_states_frame.html \ diff --git a/accessible/tests/mochitest/common.js b/accessible/tests/mochitest/common.js index e1066f5ba16..58f7e94fae8 100644 --- a/accessible/tests/mochitest/common.js +++ b/accessible/tests/mochitest/common.js @@ -215,7 +215,7 @@ function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj, aDoNotFailIf) acc.QueryInterface(aInterfaces[index]); } catch (e) { if (!(aDoNotFailIf & DONOTFAIL_IF_NO_INTERFACE)) - ok(false, "Can't query " + aInterfaces[index] + " for " + aID); + ok(false, "Can't query " + aInterfaces[index] + " for " + aAccOrElmOrID); return null; } @@ -226,7 +226,7 @@ function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj, aDoNotFailIf) try { acc.QueryInterface(aInterfaces); } catch (e) { - ok(false, "Can't query " + aInterfaces + " for " + aID); + ok(false, "Can't query " + aInterfaces + " for " + aAccOrElmOrID); return null; } diff --git a/accessible/tests/mochitest/test_elm_prgrsmtr.xul b/accessible/tests/mochitest/test_value.xul similarity index 65% rename from accessible/tests/mochitest/test_elm_prgrsmtr.xul rename to accessible/tests/mochitest/test_value.xul index d5526318d71..fb1c1ffe1ed 100644 --- a/accessible/tests/mochitest/test_elm_prgrsmtr.xul +++ b/accessible/tests/mochitest/test_value.xul @@ -13,35 +13,25 @@