зеркало из https://github.com/mozilla/pjs.git
Bug 686433 - move out nsXULSelectableAccessible class from nsXULMenuAccessible.h file. r=tbsaunde
This commit is contained in:
Родитель
5b2851fa4e
Коммит
229022546b
|
@ -50,6 +50,7 @@ LIBXUL_LIBRARY = 1
|
|||
|
||||
|
||||
CPPSRCS = \
|
||||
XULSelectControlAccessible.cpp \
|
||||
nsXULAlertAccessible.cpp \
|
||||
nsXULColorPickerAccessible.cpp \
|
||||
nsXULComboboxAccessible.cpp \
|
||||
|
|
|
@ -0,0 +1,309 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* ***** 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) 2012
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jignesh Kakadiya (jigneshhk1992@gmail.com)
|
||||
*
|
||||
* 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 "XULSelectControlAccessible.h"
|
||||
|
||||
#include "nsAccessibilityService.h"
|
||||
#include "nsDocAccessible.h"
|
||||
|
||||
#include "nsIDOMXULContainerElement.h"
|
||||
#include "nsIDOMXULSelectCntrlItemEl.h"
|
||||
#include "nsIDOMXULMultSelectCntrlEl.h"
|
||||
#include "nsIDOMKeyEvent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIMutableArray.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::a11y;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XULSelectControlAccessible
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
XULSelectControlAccessible::
|
||||
XULSelectControlAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
||||
nsAccessibleWrap(aContent, aShell)
|
||||
{
|
||||
mSelectControl = do_QueryInterface(aContent);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XULSelectControlAccessible: nsAccessNode
|
||||
|
||||
void
|
||||
XULSelectControlAccessible::Shutdown()
|
||||
{
|
||||
mSelectControl = nsnull;
|
||||
nsAccessibleWrap::Shutdown();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XULSelectControlAccessible: SelectAccessible
|
||||
|
||||
bool
|
||||
XULSelectControlAccessible::IsSelect()
|
||||
{
|
||||
return !!mSelectControl;
|
||||
}
|
||||
|
||||
// Interface methods
|
||||
already_AddRefed<nsIArray>
|
||||
XULSelectControlAccessible::SelectedItems()
|
||||
{
|
||||
nsCOMPtr<nsIMutableArray> selectedItems =
|
||||
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
||||
if (!selectedItems)
|
||||
return nsnull;
|
||||
|
||||
// For XUL multi-select control
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (xulMultiSelect) {
|
||||
PRInt32 length = 0;
|
||||
xulMultiSelect->GetSelectedCount(&length);
|
||||
for (PRInt32 index = 0; index < length; index++) {
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
|
||||
xulMultiSelect->GetSelectedItem(index, getter_AddRefs(itemElm));
|
||||
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
|
||||
nsAccessible* item =
|
||||
GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell);
|
||||
if (item)
|
||||
selectedItems->AppendElement(static_cast<nsIAccessible*>(item),
|
||||
false);
|
||||
}
|
||||
} else { // Single select?
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
|
||||
mSelectControl->GetSelectedItem(getter_AddRefs(itemElm));
|
||||
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
|
||||
if(itemNode) {
|
||||
nsAccessible* item =
|
||||
GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell);
|
||||
if (item)
|
||||
selectedItems->AppendElement(static_cast<nsIAccessible*>(item),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
nsIMutableArray* items = nsnull;
|
||||
selectedItems.forget(&items);
|
||||
return items;
|
||||
}
|
||||
|
||||
nsAccessible*
|
||||
XULSelectControlAccessible::GetSelectedItem(PRUint32 aIndex)
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->GetSelectedItem(aIndex, getter_AddRefs(itemElm));
|
||||
else if (aIndex == 0)
|
||||
mSelectControl->GetSelectedItem(getter_AddRefs(itemElm));
|
||||
|
||||
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
|
||||
return itemNode ?
|
||||
GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell) : nsnull;
|
||||
}
|
||||
|
||||
PRUint32
|
||||
XULSelectControlAccessible::SelectedItemCount()
|
||||
{
|
||||
// For XUL multi-select control
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl) {
|
||||
PRInt32 count = 0;
|
||||
multiSelectControl->GetSelectedCount(&count);
|
||||
return count;
|
||||
}
|
||||
|
||||
// For XUL single-select control/menulist
|
||||
PRInt32 index;
|
||||
mSelectControl->GetSelectedIndex(&index);
|
||||
return (index >= 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
bool
|
||||
XULSelectControlAccessible::AddItemToSelection(PRUint32 aIndex)
|
||||
{
|
||||
nsAccessible* item = GetChildAt(aIndex);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(item->GetContent());
|
||||
if (!itemElm)
|
||||
return false;
|
||||
|
||||
bool isItemSelected = false;
|
||||
itemElm->GetSelected(&isItemSelected);
|
||||
if (isItemSelected)
|
||||
return true;
|
||||
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->AddItemToSelection(itemElm);
|
||||
else
|
||||
mSelectControl->SetSelectedItem(itemElm);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
XULSelectControlAccessible::RemoveItemFromSelection(PRUint32 aIndex)
|
||||
{
|
||||
nsAccessible* item = GetChildAt(aIndex);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(item->GetContent());
|
||||
if (!itemElm)
|
||||
return false;
|
||||
|
||||
bool isItemSelected = false;
|
||||
itemElm->GetSelected(&isItemSelected);
|
||||
if (!isItemSelected)
|
||||
return true;
|
||||
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->RemoveItemFromSelection(itemElm);
|
||||
else
|
||||
mSelectControl->SetSelectedItem(nsnull);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
XULSelectControlAccessible::IsItemSelected(PRUint32 aIndex)
|
||||
{
|
||||
nsAccessible* item = GetChildAt(aIndex);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(item->GetContent());
|
||||
if (!itemElm)
|
||||
return false;
|
||||
|
||||
bool isItemSelected = false;
|
||||
itemElm->GetSelected(&isItemSelected);
|
||||
return isItemSelected;
|
||||
}
|
||||
|
||||
bool
|
||||
XULSelectControlAccessible::UnselectAll()
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
multiSelectControl ?
|
||||
multiSelectControl->ClearSelection() : mSelectControl->SetSelectedIndex(-1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
XULSelectControlAccessible::SelectAll()
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl) {
|
||||
multiSelectControl->SelectAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
// otherwise, don't support this method
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// XULSelectControlAccessible: Widgets
|
||||
|
||||
nsAccessible*
|
||||
XULSelectControlAccessible::CurrentItem()
|
||||
{
|
||||
if (!mSelectControl)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> currentItemElm;
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->GetCurrentItem(getter_AddRefs(currentItemElm));
|
||||
else
|
||||
mSelectControl->GetSelectedItem(getter_AddRefs(currentItemElm));
|
||||
|
||||
nsCOMPtr<nsINode> DOMNode;
|
||||
if (currentItemElm)
|
||||
DOMNode = do_QueryInterface(currentItemElm);
|
||||
|
||||
if (DOMNode) {
|
||||
nsDocAccessible* document = GetDocAccessible();
|
||||
if (document)
|
||||
return document->GetAccessible(DOMNode);
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void
|
||||
XULSelectControlAccessible::SetCurrentItem(nsAccessible* aItem)
|
||||
{
|
||||
if (!mSelectControl)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(aItem->GetContent());
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->SetCurrentItem(itemElm);
|
||||
else
|
||||
mSelectControl->SetSelectedItem(itemElm);
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* ***** 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) 2012
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jignesh Kakadiya (jigneshhk1992@gmail.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef _XULSelectControlAccessible_H_
|
||||
#define _XULSelectControlAccessible_H_
|
||||
|
||||
#include "nsAccessibleWrap.h"
|
||||
#include "nsIDOMXULSelectCntrlEl.h"
|
||||
|
||||
/**
|
||||
* The basic implementation of accessible selection for XUL select controls.
|
||||
*/
|
||||
class XULSelectControlAccessible : public nsAccessibleWrap
|
||||
{
|
||||
public:
|
||||
XULSelectControlAccessible(nsIContent *aContent, nsIWeakReference *aShell);
|
||||
virtual ~XULSelectControlAccessible() {}
|
||||
|
||||
// nsAccessNode
|
||||
virtual void Shutdown();
|
||||
|
||||
// SelectAccessible
|
||||
virtual bool IsSelect();
|
||||
virtual already_AddRefed<nsIArray> SelectedItems();
|
||||
virtual PRUint32 SelectedItemCount();
|
||||
virtual nsAccessible* GetSelectedItem(PRUint32 aIndex);
|
||||
virtual bool IsItemSelected(PRUint32 aIndex);
|
||||
virtual bool AddItemToSelection(PRUint32 aIndex);
|
||||
virtual bool RemoveItemFromSelection(PRUint32 aIndex);
|
||||
virtual bool SelectAll();
|
||||
virtual bool UnselectAll();
|
||||
|
||||
// Widgets
|
||||
virtual nsAccessible* CurrentItem();
|
||||
virtual void SetCurrentItem(nsAccessible* aItem);
|
||||
|
||||
protected:
|
||||
// nsIDOMXULMultiSelectControlElement inherits from this, so we'll always have
|
||||
// one of these if the widget is valid and not defunct
|
||||
nsCOMPtr<nsIDOMXULSelectControlElement> mSelectControl;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -559,7 +559,7 @@ nsXULRadioButtonAccessible::ContainerWidget() const
|
|||
|
||||
nsXULRadioGroupAccessible::
|
||||
nsXULRadioGroupAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
||||
nsXULSelectableAccessible(aContent, aShell)
|
||||
XULSelectControlAccessible(aContent, aShell)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
// NOTE: alphabetically ordered
|
||||
#include "nsAccessibleWrap.h"
|
||||
#include "nsFormControlAccessible.h"
|
||||
#include "nsXULMenuAccessible.h"
|
||||
#include "nsHyperTextAccessibleWrap.h"
|
||||
#include "XULSelectControlAccessible.h"
|
||||
|
||||
/**
|
||||
* Used for XUL progressmeter element.
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
/**
|
||||
* Used for XUL radiogroup element.
|
||||
*/
|
||||
class nsXULRadioGroupAccessible : public nsXULSelectableAccessible
|
||||
class nsXULRadioGroupAccessible : public XULSelectControlAccessible
|
||||
{
|
||||
public:
|
||||
nsXULRadioGroupAccessible(nsIContent *aContent, nsIWeakReference *aShell);
|
||||
|
@ -284,5 +284,5 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ nsXULColumnItemAccessible::DoAction(PRUint8 aIndex)
|
|||
|
||||
nsXULListboxAccessible::
|
||||
nsXULListboxAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
||||
nsXULSelectableAccessible(aContent, aShell)
|
||||
XULSelectControlAccessible(aContent, aShell)
|
||||
{
|
||||
nsIContent* parentContent = mContent->GetParent();
|
||||
if (parentContent) {
|
||||
|
@ -144,13 +144,13 @@ nsXULListboxAccessible::
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsXULListboxAccessible, nsXULSelectableAccessible)
|
||||
NS_IMPL_RELEASE_INHERITED(nsXULListboxAccessible, nsXULSelectableAccessible)
|
||||
NS_IMPL_ADDREF_INHERITED(nsXULListboxAccessible, XULSelectControlAccessible)
|
||||
NS_IMPL_RELEASE_INHERITED(nsXULListboxAccessible, XULSelectControlAccessible)
|
||||
|
||||
nsresult
|
||||
nsXULListboxAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult rv = nsXULSelectableAccessible::QueryInterface(aIID, aInstancePtr);
|
||||
nsresult rv = XULSelectControlAccessible::QueryInterface(aIID, aInstancePtr);
|
||||
if (*aInstancePtr)
|
||||
return rv;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsXULMenuAccessible.h"
|
||||
#include "nsBaseWidgetAccessible.h"
|
||||
#include "XULSelectControlAccessible.h"
|
||||
|
||||
class nsIWeakReference;
|
||||
|
||||
|
@ -88,7 +89,7 @@ public:
|
|||
/*
|
||||
* A class the represents the XUL Listbox widget.
|
||||
*/
|
||||
class nsXULListboxAccessible : public nsXULSelectableAccessible,
|
||||
class nsXULListboxAccessible : public XULSelectControlAccessible,
|
||||
public nsIAccessibleTable
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -66,259 +66,6 @@
|
|||
using namespace mozilla;
|
||||
using namespace mozilla::a11y;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsXULSelectableAccessible
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsXULSelectableAccessible::
|
||||
nsXULSelectableAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
||||
nsAccessibleWrap(aContent, aShell)
|
||||
{
|
||||
mSelectControl = do_QueryInterface(aContent);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsXULSelectableAccessible: nsAccessNode
|
||||
|
||||
void
|
||||
nsXULSelectableAccessible::Shutdown()
|
||||
{
|
||||
mSelectControl = nsnull;
|
||||
nsAccessibleWrap::Shutdown();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsXULSelectableAccessible: SelectAccessible
|
||||
|
||||
bool
|
||||
nsXULSelectableAccessible::IsSelect()
|
||||
{
|
||||
return !!mSelectControl;
|
||||
}
|
||||
|
||||
// Interface methods
|
||||
already_AddRefed<nsIArray>
|
||||
nsXULSelectableAccessible::SelectedItems()
|
||||
{
|
||||
nsCOMPtr<nsIMutableArray> selectedItems =
|
||||
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
||||
if (!selectedItems)
|
||||
return nsnull;
|
||||
|
||||
// For XUL multi-select control
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (xulMultiSelect) {
|
||||
PRInt32 length = 0;
|
||||
xulMultiSelect->GetSelectedCount(&length);
|
||||
for (PRInt32 index = 0; index < length; index++) {
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
|
||||
xulMultiSelect->GetSelectedItem(index, getter_AddRefs(itemElm));
|
||||
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
|
||||
nsAccessible* item =
|
||||
GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell);
|
||||
if (item)
|
||||
selectedItems->AppendElement(static_cast<nsIAccessible*>(item),
|
||||
false);
|
||||
}
|
||||
}
|
||||
else { // Single select?
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
|
||||
mSelectControl->GetSelectedItem(getter_AddRefs(itemElm));
|
||||
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
|
||||
if(itemNode) {
|
||||
nsAccessible* item =
|
||||
GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell);
|
||||
if (item)
|
||||
selectedItems->AppendElement(static_cast<nsIAccessible*>(item),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
nsIMutableArray* items = nsnull;
|
||||
selectedItems.forget(&items);
|
||||
return items;
|
||||
}
|
||||
|
||||
nsAccessible*
|
||||
nsXULSelectableAccessible::GetSelectedItem(PRUint32 aIndex)
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->GetSelectedItem(aIndex, getter_AddRefs(itemElm));
|
||||
else if (aIndex == 0)
|
||||
mSelectControl->GetSelectedItem(getter_AddRefs(itemElm));
|
||||
|
||||
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
|
||||
return itemNode ?
|
||||
GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell) : nsnull;
|
||||
}
|
||||
|
||||
PRUint32
|
||||
nsXULSelectableAccessible::SelectedItemCount()
|
||||
{
|
||||
// For XUL multi-select control
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl) {
|
||||
PRInt32 count = 0;
|
||||
multiSelectControl->GetSelectedCount(&count);
|
||||
return count;
|
||||
}
|
||||
|
||||
// For XUL single-select control/menulist
|
||||
PRInt32 index;
|
||||
mSelectControl->GetSelectedIndex(&index);
|
||||
return (index >= 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
bool
|
||||
nsXULSelectableAccessible::AddItemToSelection(PRUint32 aIndex)
|
||||
{
|
||||
nsAccessible* item = GetChildAt(aIndex);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(item->GetContent());
|
||||
if (!itemElm)
|
||||
return false;
|
||||
|
||||
bool isItemSelected = false;
|
||||
itemElm->GetSelected(&isItemSelected);
|
||||
if (isItemSelected)
|
||||
return true;
|
||||
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->AddItemToSelection(itemElm);
|
||||
else
|
||||
mSelectControl->SetSelectedItem(itemElm);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nsXULSelectableAccessible::RemoveItemFromSelection(PRUint32 aIndex)
|
||||
{
|
||||
nsAccessible* item = GetChildAt(aIndex);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(item->GetContent());
|
||||
if (!itemElm)
|
||||
return false;
|
||||
|
||||
bool isItemSelected = false;
|
||||
itemElm->GetSelected(&isItemSelected);
|
||||
if (!isItemSelected)
|
||||
return true;
|
||||
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->RemoveItemFromSelection(itemElm);
|
||||
else
|
||||
mSelectControl->SetSelectedItem(nsnull);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nsXULSelectableAccessible::IsItemSelected(PRUint32 aIndex)
|
||||
{
|
||||
nsAccessible* item = GetChildAt(aIndex);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(item->GetContent());
|
||||
if (!itemElm)
|
||||
return false;
|
||||
|
||||
bool isItemSelected = false;
|
||||
itemElm->GetSelected(&isItemSelected);
|
||||
return isItemSelected;
|
||||
}
|
||||
|
||||
bool
|
||||
nsXULSelectableAccessible::UnselectAll()
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
multiSelectControl ?
|
||||
multiSelectControl->ClearSelection() : mSelectControl->SetSelectedIndex(-1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nsXULSelectableAccessible::SelectAll()
|
||||
{
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl) {
|
||||
multiSelectControl->SelectAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
// otherwise, don't support this method
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsXULSelectableAccessible: Widgets
|
||||
|
||||
nsAccessible*
|
||||
nsXULSelectableAccessible::CurrentItem()
|
||||
{
|
||||
if (!mSelectControl)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> currentItemElm;
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->GetCurrentItem(getter_AddRefs(currentItemElm));
|
||||
else
|
||||
mSelectControl->GetSelectedItem(getter_AddRefs(currentItemElm));
|
||||
|
||||
nsCOMPtr<nsINode> DOMNode;
|
||||
if (currentItemElm)
|
||||
DOMNode = do_QueryInterface(currentItemElm);
|
||||
|
||||
if (DOMNode) {
|
||||
nsDocAccessible* document = GetDocAccessible();
|
||||
if (document)
|
||||
return document->GetAccessible(DOMNode);
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void
|
||||
nsXULSelectableAccessible::SetCurrentItem(nsAccessible* aItem)
|
||||
{
|
||||
if (!mSelectControl)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
|
||||
do_QueryInterface(aItem->GetContent());
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
|
||||
do_QueryInterface(mSelectControl);
|
||||
if (multiSelectControl)
|
||||
multiSelectControl->SetCurrentItem(itemElm);
|
||||
else
|
||||
mSelectControl->SetSelectedItem(itemElm);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsXULMenuitemAccessible
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -708,7 +455,7 @@ nsXULMenuSeparatorAccessible::ActionCount()
|
|||
|
||||
nsXULMenupopupAccessible::
|
||||
nsXULMenupopupAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
||||
nsXULSelectableAccessible(aContent, aShell)
|
||||
XULSelectControlAccessible(aContent, aShell)
|
||||
{
|
||||
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetFrame());
|
||||
if (menuPopupFrame && menuPopupFrame->IsMenu())
|
||||
|
|
|
@ -41,39 +41,7 @@
|
|||
|
||||
#include "nsAccessibleWrap.h"
|
||||
#include "nsIDOMXULSelectCntrlEl.h"
|
||||
|
||||
/**
|
||||
* The basic implementation of SelectAccessible for XUL select controls.
|
||||
*/
|
||||
class nsXULSelectableAccessible : public nsAccessibleWrap
|
||||
{
|
||||
public:
|
||||
nsXULSelectableAccessible(nsIContent *aContent, nsIWeakReference *aShell);
|
||||
virtual ~nsXULSelectableAccessible() {}
|
||||
|
||||
// nsAccessNode
|
||||
virtual void Shutdown();
|
||||
|
||||
// SelectAccessible
|
||||
virtual bool IsSelect();
|
||||
virtual already_AddRefed<nsIArray> SelectedItems();
|
||||
virtual PRUint32 SelectedItemCount();
|
||||
virtual nsAccessible* GetSelectedItem(PRUint32 aIndex);
|
||||
virtual bool IsItemSelected(PRUint32 aIndex);
|
||||
virtual bool AddItemToSelection(PRUint32 aIndex);
|
||||
virtual bool RemoveItemFromSelection(PRUint32 aIndex);
|
||||
virtual bool SelectAll();
|
||||
virtual bool UnselectAll();
|
||||
|
||||
// Widgets
|
||||
virtual nsAccessible* CurrentItem();
|
||||
virtual void SetCurrentItem(nsAccessible* aItem);
|
||||
|
||||
protected:
|
||||
// nsIDOMXULMultiSelectControlElement inherits from this, so we'll always have
|
||||
// one of these if the widget is valid and not defunct
|
||||
nsCOMPtr<nsIDOMXULSelectControlElement> mSelectControl;
|
||||
};
|
||||
#include "XULSelectControlAccessible.h"
|
||||
|
||||
/**
|
||||
* Used for XUL menu, menuitem elements.
|
||||
|
@ -136,7 +104,7 @@ public:
|
|||
/**
|
||||
* Used for XUL menupopup and panel.
|
||||
*/
|
||||
class nsXULMenupopupAccessible : public nsXULSelectableAccessible
|
||||
class nsXULMenupopupAccessible : public XULSelectControlAccessible
|
||||
{
|
||||
public:
|
||||
nsXULMenupopupAccessible(nsIContent *aContent, nsIWeakReference *aShell);
|
||||
|
@ -174,4 +142,4 @@ public:
|
|||
virtual void SetCurrentItem(nsAccessible* aItem);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -179,7 +179,7 @@ nsXULTabAccessible::GetPositionAndSizeInternal(PRInt32 *aPosInSet,
|
|||
|
||||
nsXULTabsAccessible::
|
||||
nsXULTabsAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
||||
nsXULSelectableAccessible(aContent, aShell)
|
||||
XULSelectControlAccessible(aContent, aShell)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
// NOTE: alphabetically ordered
|
||||
#include "nsBaseWidgetAccessible.h"
|
||||
#include "nsXULMenuAccessible.h"
|
||||
#include "XULSelectControlAccessible.h"
|
||||
|
||||
/**
|
||||
* An individual tab, xul:tab element.
|
||||
|
@ -72,7 +73,7 @@ public:
|
|||
/**
|
||||
* A container of tab objects, xul:tabs element.
|
||||
*/
|
||||
class nsXULTabsAccessible : public nsXULSelectableAccessible
|
||||
class nsXULTabsAccessible : public XULSelectControlAccessible
|
||||
{
|
||||
public:
|
||||
nsXULTabsAccessible(nsIContent *aContent, nsIWeakReference *aShell);
|
||||
|
|
Загрузка…
Ссылка в новой задаче