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