2007-08-03 22:27:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsXULSliderAccessible.h"
|
|
|
|
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentXBL.h"
|
|
|
|
|
|
|
|
// nsXULSliderAccessible
|
|
|
|
|
|
|
|
nsXULSliderAccessible::nsXULSliderAccessible(nsIDOMNode* aNode,
|
|
|
|
nsIWeakReference* aShell) :
|
|
|
|
nsAccessibleWrap(aNode, aShell)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
// nsISupports
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsXULSliderAccessible,
|
|
|
|
nsAccessibleWrap,
|
|
|
|
nsIAccessibleValue)
|
|
|
|
|
2009-05-22 09:09:51 -07:00
|
|
|
// nsAccessible
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsXULSliderAccessible::GetRoleInternal(PRUint32 *aRole)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_SLIDER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-22 09:09:51 -07:00
|
|
|
nsresult
|
|
|
|
nsXULSliderAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::GetStateInternal(aState, aExtraState);
|
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> sliderContent(GetSliderNode());
|
|
|
|
NS_ENSURE_STATE(sliderContent);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
|
|
|
|
NS_ENSURE_STATE(shell);
|
|
|
|
|
|
|
|
nsIFrame *frame = shell->GetPrimaryFrameFor(sliderContent);
|
|
|
|
if (frame && frame->IsFocusable())
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSABLE;
|
|
|
|
|
|
|
|
if (gLastFocusedNode == mDOMNode)
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSED;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAccessible
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetValue(nsAString& aValue)
|
|
|
|
{
|
|
|
|
return GetSliderAttr(nsAccessibilityAtoms::curpos, aValue);
|
|
|
|
}
|
|
|
|
|
2009-05-22 09:09:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetNumActions(PRUint8 *aCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
|
|
|
|
*aCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
NS_ENSURE_ARG(aIndex == 0);
|
|
|
|
|
|
|
|
aName.AssignLiteral("activate");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::DoAction(PRUint8 aIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aIndex == 0);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> sliderContent(GetSliderNode());
|
|
|
|
NS_ENSURE_STATE(sliderContent);
|
|
|
|
|
|
|
|
return DoCommand(sliderContent);
|
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
// nsIAccessibleValue
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetMaximumValue(double *aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::GetMaximumValue(aValue);
|
|
|
|
|
|
|
|
// ARIA redefined maximum value.
|
|
|
|
if (rv != NS_OK_NO_ARIA_VALUE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return GetSliderAttr(nsAccessibilityAtoms::maxpos, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetMinimumValue(double *aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::GetMinimumValue(aValue);
|
|
|
|
|
|
|
|
// ARIA redefined minmum value.
|
|
|
|
if (rv != NS_OK_NO_ARIA_VALUE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return GetSliderAttr(nsAccessibilityAtoms::minpos, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetMinimumIncrement(double *aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::GetMinimumIncrement(aValue);
|
|
|
|
|
|
|
|
// ARIA redefined minimum increment value.
|
|
|
|
if (rv != NS_OK_NO_ARIA_VALUE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return GetSliderAttr(nsAccessibilityAtoms::increment, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::GetCurrentValue(double *aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::GetCurrentValue(aValue);
|
|
|
|
|
|
|
|
// ARIA redefined current value.
|
|
|
|
if (rv != NS_OK_NO_ARIA_VALUE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return GetSliderAttr(nsAccessibilityAtoms::curpos, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULSliderAccessible::SetCurrentValue(double aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::SetCurrentValue(aValue);
|
|
|
|
|
|
|
|
// ARIA redefined current value.
|
|
|
|
if (rv != NS_OK_NO_ARIA_VALUE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return SetSliderAttr(nsAccessibilityAtoms::curpos, aValue);
|
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
PRBool
|
|
|
|
nsXULSliderAccessible::GetAllowsAnonChildAccessibles()
|
2009-05-22 09:09:51 -07:00
|
|
|
{
|
|
|
|
// Do not allow anonymous xul:slider be accessible.
|
2009-06-18 00:37:38 -07:00
|
|
|
return PR_FALSE;
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
// Utils
|
|
|
|
|
2009-05-11 08:20:03 -07:00
|
|
|
already_AddRefed<nsIContent>
|
|
|
|
nsXULSliderAccessible::GetSliderNode()
|
|
|
|
{
|
|
|
|
if (!mDOMNode)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if (!mSliderNode) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> document;
|
|
|
|
mDOMNode->GetOwnerDocument(getter_AddRefs(document));
|
|
|
|
if (!document)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocumentXBL> xblDoc(do_QueryInterface(document));
|
|
|
|
if (!xblDoc)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// XXX: we depend on anonymous content.
|
|
|
|
nsCOMPtr<nsIDOMElement> domElm(do_QueryInterface(mDOMNode));
|
|
|
|
if (!domElm)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
xblDoc->GetAnonymousElementByAttribute(domElm, NS_LITERAL_STRING("anonid"),
|
|
|
|
NS_LITERAL_STRING("slider"),
|
|
|
|
getter_AddRefs(mSliderNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *sliderNode = nsnull;
|
|
|
|
nsresult rv = CallQueryInterface(mSliderNode, &sliderNode);
|
|
|
|
return NS_FAILED(rv) ? nsnull : sliderNode;
|
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
nsresult
|
|
|
|
nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
if (IsDefunct())
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-05-11 08:20:03 -07:00
|
|
|
nsCOMPtr<nsIContent> sliderNode(GetSliderNode());
|
|
|
|
NS_ENSURE_STATE(sliderNode);
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
sliderNode->GetAttr(kNameSpaceID_None, aName, aValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULSliderAccessible::SetSliderAttr(nsIAtom *aName, const nsAString& aValue)
|
|
|
|
{
|
2009-05-05 20:16:36 -07:00
|
|
|
if (IsDefunct())
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-05-11 08:20:03 -07:00
|
|
|
nsCOMPtr<nsIContent> sliderNode(GetSliderNode());
|
|
|
|
NS_ENSURE_STATE(sliderNode);
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
sliderNode->SetAttr(kNameSpaceID_None, aName, aValue, PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULSliderAccessible::GetSliderAttr(nsIAtom *aName, double *aValue)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aValue);
|
|
|
|
*aValue = 0;
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
nsAutoString attrValue;
|
|
|
|
nsresult rv = GetSliderAttr(aName, attrValue);
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
// Return zero value if there is no attribute or its value is empty.
|
|
|
|
if (attrValue.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
PRInt32 error = NS_OK;
|
2009-05-05 20:16:36 -07:00
|
|
|
double value = attrValue.ToFloat(&error);
|
|
|
|
if (NS_SUCCEEDED(error))
|
|
|
|
*aValue = value;
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULSliderAccessible::SetSliderAttr(nsIAtom *aName, double aValue)
|
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
value.AppendFloat(aValue);
|
|
|
|
|
|
|
|
return SetSliderAttr(aName, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsXULThumbAccessible
|
|
|
|
|
|
|
|
nsXULThumbAccessible::nsXULThumbAccessible(nsIDOMNode* aNode,
|
|
|
|
nsIWeakReference* aShell) :
|
|
|
|
nsAccessibleWrap(aNode, aShell) {}
|
|
|
|
|
2009-05-11 08:20:03 -07:00
|
|
|
// nsIAccessible
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsXULThumbAccessible::GetRoleInternal(PRUint32 *aRole)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_INDICATOR;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|