From 655223904d87cc6fd6d7b76b4f431d34a1d68382 Mon Sep 17 00:00:00 2001 From: "pete.zha%sun.com" Date: Mon, 15 Jul 2002 02:23:23 +0000 Subject: [PATCH] Implementation of nsIAccessibleValue bug=150606 r=kyle.yuan@sun.com sr=jag patch=gilbert.fang@sun.com --- .../src/xul/nsXULFormControlAccessible.cpp | 50 +++++++++++++++++++ .../src/xul/nsXULFormControlAccessible.h | 7 ++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index c66bc532b3d..7360ffe6c41 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -434,6 +434,7 @@ NS_IMETHODIMP nsXULGroupboxAccessible::GetAccName(nsAString& _retval) /** * progressmeter */ +NS_IMPL_ISUPPORTS_INHERITED1(nsXULProgressMeterAccessible, nsFormControlAccessible, nsIAccessibleValue) nsXULProgressMeterAccessible::nsXULProgressMeterAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsFormControlAccessible(aNode, aShell) @@ -465,6 +466,55 @@ NS_IMETHODIMP nsXULProgressMeterAccessible::GetAccValue(nsAString& _retval) return NS_OK; } +/* readonly attribute double maximumValue; */ +NS_IMETHODIMP nsXULProgressMeterAccessible::GetMaximumValue(double *aMaximumValue) +{ + *aMaximumValue = 1; // 100% = 1; + return NS_OK; +} + +/* readonly attribute double minimumValue; */ +NS_IMETHODIMP nsXULProgressMeterAccessible::GetMinimumValue(double *aMinimumValue) +{ + *aMinimumValue = 0; + return NS_OK; +} + +/* readonly attribute double currentValue; */ +NS_IMETHODIMP nsXULProgressMeterAccessible::GetCurrentValue(double *aCurrentValue) +{ + nsAutoString currentValue; + GetAccValue(currentValue); + PRInt32 error; + *aCurrentValue = currentValue.ToFloat(&error) / 100; + return NS_OK; +} + +/* boolean setCurrentValue (in double value); */ +NS_IMETHODIMP nsXULProgressMeterAccessible::SetCurrentValue(double aValue, PRBool *_retval) +{ + //Here I do not suppose the min/max are 0/1.00 because I want + // these part of code to be more extensible. + *_retval = PR_FALSE; + double min, max; + GetMinimumValue(&min); + GetMaximumValue(&max); + if (aValue > max || aValue < min) + return NS_ERROR_INVALID_ARG; + + nsCOMPtr element(do_QueryInterface(mDOMNode)); + NS_ASSERTION(element, "No element for DOM node!"); + PRUint32 value = PRUint32(aValue * 100.0 + 0.5); + nsAutoString valueString; + valueString.AppendInt(value); + valueString.Append(NS_LITERAL_STRING("%")); + if (NS_SUCCEEDED(element->SetAttribute(NS_LITERAL_STRING("value"), valueString))) { + *_retval = PR_TRUE; + return NS_OK; + } + return NS_ERROR_INVALID_ARG; +} + /** * XUL Radio Button */ diff --git a/accessible/src/xul/nsXULFormControlAccessible.h b/accessible/src/xul/nsXULFormControlAccessible.h index bc38dfa598a..467b6d9e19b 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.h +++ b/accessible/src/xul/nsXULFormControlAccessible.h @@ -44,6 +44,7 @@ #include "nsBaseWidgetAccessible.h" #include "nsFormControlAccessible.h" #include "nsHTMLFormControlAccessible.h" +#include "nsIAccessibleValue.h" class nsXULButtonAccessible : public nsAccessible // Don't inherit from nsFormControlAccessible - it doesn't allow children and a button can have a dropmarker child @@ -95,8 +96,12 @@ public: NS_IMETHOD GetAccName(nsAString& _retval); }; -class nsXULProgressMeterAccessible : public nsFormControlAccessible +class nsXULProgressMeterAccessible : public nsFormControlAccessible, + public nsIAccessibleValue { + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_NSIACCESSIBLEVALUE + public: nsXULProgressMeterAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); NS_IMETHOD GetAccRole(PRUint32 *_retval);