2009-09-10 18:07:56 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#include "XULComboboxAccessible.h"
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2010-06-08 09:39:58 -07:00
|
|
|
#include "nsCoreUtils.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsIAutoCompleteInput.h"
|
2009-09-10 18:07:56 -07:00
|
|
|
#include "nsIDOMXULMenuListElement.h"
|
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULComboboxAccessible
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::
|
|
|
|
XULComboboxAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
2011-09-27 18:46:11 -07:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::autocomplete, eIgnoreCase))
|
2012-12-17 21:22:26 -08:00
|
|
|
mGenericTypes |= eAutoComplete;
|
2011-09-27 18:46:11 -07:00
|
|
|
else
|
2012-12-17 21:22:26 -08:00
|
|
|
mGenericTypes |= eCombobox;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::NativeRole()
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return IsAutoComplete() ? roles::AUTOCOMPLETE : roles::COMBOBOX;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::NativeState()
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
// As a nsComboboxAccessible we can have the following states:
|
|
|
|
// STATE_FOCUSED
|
|
|
|
// STATE_FOCUSABLE
|
|
|
|
// STATE_HASPOPUP
|
|
|
|
// STATE_EXPANDED
|
|
|
|
// STATE_COLLAPSED
|
|
|
|
|
|
|
|
// Get focus status from base class
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t state = Accessible::NativeState();
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
|
2009-09-10 18:07:56 -07:00
|
|
|
if (menuList) {
|
2012-06-03 22:41:06 -07:00
|
|
|
bool isOpen = false;
|
2009-09-10 18:07:56 -07:00
|
|
|
menuList->GetOpen(&isOpen);
|
2012-06-03 22:41:06 -07:00
|
|
|
if (isOpen)
|
|
|
|
state |= states::EXPANDED;
|
|
|
|
else
|
|
|
|
state |= states::COLLAPSED;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
return state | states::HASPOPUP;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2011-04-23 06:14:05 -07:00
|
|
|
void
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::Description(nsString& aDescription)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
aDescription.Truncate();
|
|
|
|
// Use description of currently focused option
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuListElm(do_QueryInterface(mContent));
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!menuListElm)
|
2011-04-23 06:14:05 -07:00
|
|
|
return;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> focusedOptionItem;
|
|
|
|
menuListElm->GetSelectedItem(getter_AddRefs(focusedOptionItem));
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIContent> focusedOptionContent =
|
|
|
|
do_QueryInterface(focusedOptionItem);
|
2012-02-07 14:38:54 -08:00
|
|
|
if (focusedOptionContent && mDoc) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* focusedOptionAcc = mDoc->GetAccessible(focusedOptionContent);
|
2011-04-23 06:14:05 -07:00
|
|
|
if (focusedOptionAcc)
|
|
|
|
focusedOptionAcc->Description(aDescription);
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
void
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::Value(nsString& aValue)
|
2012-04-09 02:48:41 -07:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
// The value is the option or text shown entered in the combobox.
|
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
|
|
|
|
if (menuList)
|
|
|
|
menuList->GetLabel(aValue);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::CanHaveAnonChildren()
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->NodeInfo()->Equals(nsGkAtoms::textbox, kNameSpaceID_XUL) ||
|
|
|
|
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
|
|
|
|
nsGkAtoms::_true, eIgnoreCase)) {
|
2009-09-10 18:07:56 -07:00
|
|
|
// Both the XUL <textbox type="autocomplete"> and <menulist editable="true"> widgets
|
2012-06-10 16:44:50 -07:00
|
|
|
// use XULComboboxAccessible. We need to walk the anonymous children for these
|
2009-09-10 18:07:56 -07:00
|
|
|
// so that the entry field is a child
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Argument of false indicates we don't walk anonymous children for
|
2009-09-10 18:07:56 -07:00
|
|
|
// menuitems
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::ActionCount()
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
// Just one action (click).
|
2011-06-05 12:35:43 -07:00
|
|
|
return 1;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
XULComboboxAccessible::DoAction(uint8_t aIndex)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
2014-09-16 10:30:23 -07:00
|
|
|
if (aIndex != XULComboboxAccessible::eAction_Click)
|
|
|
|
return false;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
|
|
|
// Programmaticaly toggle the combo box.
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
|
2014-09-16 10:30:23 -07:00
|
|
|
if (!menuList)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool isDroppedDown = false;
|
2009-09-10 18:07:56 -07:00
|
|
|
menuList->GetOpen(&isDroppedDown);
|
2014-09-16 10:30:23 -07:00
|
|
|
menuList->SetOpen(!isDroppedDown);
|
|
|
|
return true;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
void
|
|
|
|
XULComboboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
2014-09-16 10:30:23 -07:00
|
|
|
aName.Truncate();
|
|
|
|
if (aIndex != XULComboboxAccessible::eAction_Click)
|
|
|
|
return;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
|
2014-09-16 10:30:23 -07:00
|
|
|
if (!menuList)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool isDroppedDown = false;
|
2009-09-10 18:07:56 -07:00
|
|
|
menuList->GetOpen(&isDroppedDown);
|
|
|
|
if (isDroppedDown)
|
2014-09-16 10:30:23 -07:00
|
|
|
aName.AssignLiteral("close");
|
2009-09-10 18:07:56 -07:00
|
|
|
else
|
2014-09-16 10:30:23 -07:00
|
|
|
aName.AssignLiteral("open");
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Widgets
|
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::IsActiveWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
if (IsAutoComplete() ||
|
|
|
|
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
|
|
|
|
nsGkAtoms::_true, eIgnoreCase)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childCount = mChildren.Length();
|
|
|
|
for (int32_t idx = 0; idx < childCount; idx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = mChildren[idx];
|
2012-01-11 19:07:35 -08:00
|
|
|
if (child->Role() == roles::ENTRY)
|
2011-09-27 18:46:11 -07:00
|
|
|
return FocusMgr()->HasDOMFocus(child->GetContent());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FocusMgr()->HasDOMFocus(mContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULComboboxAccessible::AreItemsOperable() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
if (IsAutoComplete()) {
|
|
|
|
nsCOMPtr<nsIAutoCompleteInput> autoCompleteInputElm =
|
|
|
|
do_QueryInterface(mContent);
|
|
|
|
if (autoCompleteInputElm) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOpen = false;
|
2011-09-27 18:46:11 -07:00
|
|
|
autoCompleteInputElm->GetPopupOpen(&isOpen);
|
|
|
|
return isOpen;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuListElm = do_QueryInterface(mContent);
|
|
|
|
if (menuListElm) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOpen = false;
|
2011-09-27 18:46:11 -07:00
|
|
|
menuListElm->GetOpen(&isOpen);
|
|
|
|
return isOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|