2001-09-25 00:48:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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/
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
2001-09-25 00:48:50 +00:00
|
|
|
* 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.
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 00:48:50 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
2001-09-25 00:48:50 +00:00
|
|
|
* Contributor(s):
|
2009-09-11 01:07:56 +00:00
|
|
|
* Aaron Leventhal <aaronl@netscape.com> (original author)
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com>
|
2001-09-25 00:48:50 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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"),
|
2001-09-25 00:48:50 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 00:48:50 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 00:48:50 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsHTMLTableAccessible.h"
|
2010-03-17 06:02:28 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
#include "Relation.h"
|
2011-04-09 23:38:06 +00:00
|
|
|
#include "States.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
2010-07-02 01:22:41 +00:00
|
|
|
#include "nsAccTreeWalker.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccUtils.h"
|
2010-03-17 06:02:28 +00:00
|
|
|
#include "nsDocAccessible.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsTextEquivUtils.h"
|
2010-03-17 06:02:28 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
#include "nsIAccessibleRelation.h"
|
2003-04-15 08:45:55 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2007-05-11 12:21:43 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2005-06-01 14:09:24 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
2006-06-27 15:42:09 +00:00
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDOMHTMLTableCellElement.h"
|
|
|
|
#include "nsIDOMHTMLTableElement.h"
|
|
|
|
#include "nsIDOMHTMLTableRowElement.h"
|
|
|
|
#include "nsIDOMHTMLTableSectionElem.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsITableLayout.h"
|
2007-04-20 06:11:14 +00:00
|
|
|
#include "nsITableCellLayout.h"
|
2009-09-10 03:06:54 +00:00
|
|
|
#include "nsFrameSelection.h"
|
2008-03-06 04:11:45 +00:00
|
|
|
#include "nsLayoutErrors.h"
|
2009-09-11 01:07:56 +00:00
|
|
|
#include "nsArrayUtils.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2011-07-27 12:43:01 +00:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-09-11 01:07:56 +00:00
|
|
|
// nsHTMLTableCellAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableCellAccessible::
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLTableCellAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
|
|
|
nsHyperTextAccessibleWrap(aContent, aShell)
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
|
|
|
}
|
2003-03-24 02:09:55 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableCellAccessible: nsISupports implementation
|
2003-03-24 02:09:55 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableCellAccessible,
|
|
|
|
nsHyperTextAccessible,
|
|
|
|
nsIAccessibleTableCell)
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableCellAccessible: nsAccessible implementation
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2010-09-05 02:14:01 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableCellAccessible::NativeRole()
|
2001-03-04 02:31:28 +00:00
|
|
|
{
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_CELL;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64
|
|
|
|
nsHTMLTableCellAccessible::NativeState()
|
2009-07-08 02:37:43 +00:00
|
|
|
{
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64 state = nsHyperTextAccessibleWrap::NativeState();
|
2009-07-08 02:37:43 +00:00
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2009-07-08 02:37:43 +00:00
|
|
|
NS_ASSERTION(frame, "No frame for valid cell accessible!");
|
|
|
|
|
|
|
|
if (frame) {
|
2011-04-09 23:38:06 +00:00
|
|
|
state |= states::SELECTABLE;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2009-07-08 02:37:43 +00:00
|
|
|
frame->GetSelected(&isSelected);
|
|
|
|
if (isSelected)
|
2011-04-09 23:38:06 +00:00
|
|
|
state |= states::SELECTED;
|
2009-07-08 02:37:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
return state;
|
2009-07-08 02:37:43 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableCellAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv = nsHyperTextAccessibleWrap::GetAttributesInternal(aAttributes);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-11-24 11:31:34 +00:00
|
|
|
// table-cell-index attribute
|
2009-05-14 05:31:09 +00:00
|
|
|
nsCOMPtr<nsIAccessibleTable> tableAcc(GetTableAccessible());
|
|
|
|
if (!tableAcc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 rowIdx = -1, colIdx = -1;
|
|
|
|
rv = GetCellIndexes(rowIdx, colIdx);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 idx = -1;
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = tableAcc->GetCellIndexAt(rowIdx, colIdx, &idx);
|
2009-05-14 05:31:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString stringIdx;
|
|
|
|
stringIdx.AppendInt(idx);
|
2011-06-03 21:35:17 +00:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tableCellIndex, stringIdx);
|
2011-11-24 11:31:34 +00:00
|
|
|
|
|
|
|
// abbr attribute
|
|
|
|
|
|
|
|
// Pick up object attribute from abbr DOM element (a child of the cell) or
|
|
|
|
// from abbr DOM attribute.
|
|
|
|
nsAutoString abbrText;
|
|
|
|
if (GetChildCount() == 1) {
|
|
|
|
nsAccessible* abbr = FirstChild();
|
|
|
|
if (abbr->IsAbbreviation()) {
|
|
|
|
nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromTextContent(abbr->GetContent()->GetFirstChild(),
|
|
|
|
&abbrText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (abbrText.IsEmpty())
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::abbr, abbrText);
|
|
|
|
|
|
|
|
if (!abbrText.IsEmpty())
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::abbr, abbrText);
|
|
|
|
|
2011-11-24 11:31:41 +00:00
|
|
|
// axis attribute
|
|
|
|
nsAutoString axisText;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText);
|
|
|
|
if (!axisText.IsEmpty())
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::axis, axisText);
|
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableCellAccessible: nsIAccessibleTableCell implementation
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableCellAccessible::GetTable(nsIAccessibleTable **aTable)
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aTable);
|
|
|
|
*aTable = nsnull;
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
2009-05-14 05:31:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
|
|
|
|
table.swap(*aTable);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetColumnIndex(PRInt32 *aColumnIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnIndex);
|
|
|
|
*aColumnIndex = -1;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
|
|
|
return cellLayout->GetColIndex(*aColumnIndex);
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetRowIndex(PRInt32 *aRowIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRowIndex);
|
|
|
|
*aRowIndex = -1;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
|
|
|
return cellLayout->GetRowIndex(*aRowIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetColumnExtent(PRInt32 *aExtentCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aExtentCount);
|
|
|
|
*aExtentCount = 1;
|
|
|
|
|
|
|
|
PRInt32 rowIdx = -1, colIdx = -1;
|
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
|
|
|
|
NS_ENSURE_STATE(table);
|
|
|
|
|
|
|
|
return table->GetColumnExtentAt(rowIdx, colIdx, aExtentCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetRowExtent(PRInt32 *aExtentCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aExtentCount);
|
|
|
|
*aExtentCount = 1;
|
|
|
|
|
|
|
|
PRInt32 rowIdx = -1, colIdx = -1;
|
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
|
|
|
|
NS_ENSURE_STATE(table);
|
|
|
|
|
|
|
|
return table->GetRowExtentAt(rowIdx, colIdx, aExtentCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetColumnHeaderCells(nsIArray **aHeaderCells)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeaderCells);
|
|
|
|
*aHeaderCells = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return GetHeaderCells(nsAccUtils::eColumnHeaderCells, aHeaderCells);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetRowHeaderCells(nsIArray **aHeaderCells)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeaderCells);
|
|
|
|
*aHeaderCells = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return GetHeaderCells(nsAccUtils::eRowHeaderCells, aHeaderCells);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHTMLTableCellAccessible::IsSelected(bool *aIsSelected)
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsSelected = false;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 rowIdx = -1, colIdx = -1;
|
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
|
|
|
|
NS_ENSURE_STATE(table);
|
|
|
|
|
|
|
|
return table->IsCellSelected(rowIdx, colIdx, aIsSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableCellAccessible: protected implementation
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
already_AddRefed<nsIAccessibleTable>
|
|
|
|
nsHTMLTableCellAccessible::GetTableAccessible()
|
|
|
|
{
|
2010-09-07 02:41:53 +00:00
|
|
|
nsAccessible* parent = this;
|
2011-07-23 08:38:33 +00:00
|
|
|
while ((parent = parent->Parent())) {
|
2010-09-07 02:41:53 +00:00
|
|
|
PRUint32 role = parent->Role();
|
2009-09-15 04:05:26 +00:00
|
|
|
if (role == nsIAccessibleRole::ROLE_TABLE ||
|
|
|
|
role == nsIAccessibleRole::ROLE_TREE_TABLE) {
|
2009-05-14 05:31:09 +00:00
|
|
|
nsIAccessibleTable* tableAcc = nsnull;
|
2010-09-07 02:41:53 +00:00
|
|
|
CallQueryInterface(parent, &tableAcc);
|
2009-05-14 05:31:09 +00:00
|
|
|
return tableAcc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableCellLayout*
|
|
|
|
nsHTMLTableCellAccessible::GetCellLayout()
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2008-04-23 18:01:04 +00:00
|
|
|
NS_ASSERTION(frame, "The frame cannot be obtaied for HTML table cell.");
|
2009-09-11 01:07:56 +00:00
|
|
|
if (!frame)
|
|
|
|
return nsnull;
|
2010-06-11 08:23:18 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
nsITableCellLayout *cellLayout = do_QueryFrame(frame);
|
2009-09-11 01:07:56 +00:00
|
|
|
return cellLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLTableCellAccessible::GetCellIndexes(PRInt32& aRowIndex,
|
|
|
|
PRInt32& aColIndex)
|
|
|
|
{
|
|
|
|
nsITableCellLayout *cellLayout = GetCellLayout();
|
2008-04-15 03:38:31 +00:00
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
return cellLayout->GetCellIndexes(aRowIndex, aColIndex);
|
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
nsresult
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableCellAccessible::GetHeaderCells(PRInt32 aRowOrColumnHeaderCell,
|
|
|
|
nsIArray **aHeaderCells)
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
// Get header cells from @header attribute.
|
2011-06-03 21:35:17 +00:00
|
|
|
IDRefsIterator iter(mContent, nsGkAtoms::headers);
|
2010-11-17 03:32:15 +00:00
|
|
|
nsIContent* headerCellElm = iter.NextElem();
|
|
|
|
if (headerCellElm) {
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIMutableArray> headerCells =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-06-13 23:18:57 +00:00
|
|
|
PRUint32 desiredRole = -1;
|
|
|
|
if (aRowOrColumnHeaderCell == nsAccUtils::eRowHeaderCells)
|
|
|
|
desiredRole = nsIAccessibleRole::ROLE_ROWHEADER;
|
|
|
|
else if (aRowOrColumnHeaderCell == nsAccUtils::eColumnHeaderCells)
|
|
|
|
desiredRole = nsIAccessibleRole::ROLE_COLUMNHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2010-11-17 03:32:15 +00:00
|
|
|
do {
|
|
|
|
nsAccessible* headerCell =
|
|
|
|
GetAccService()->GetAccessibleInWeakShell(headerCellElm, mWeakShell);
|
|
|
|
|
2011-06-13 23:18:57 +00:00
|
|
|
if (headerCell && headerCell->Role() == desiredRole)
|
2010-11-17 03:32:15 +00:00
|
|
|
headerCells->AppendElement(static_cast<nsIAccessible*>(headerCell),
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
2010-11-17 03:32:15 +00:00
|
|
|
} while ((headerCellElm = iter.NextElem()));
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_ADDREF(*aHeaderCells = headerCells);
|
|
|
|
return NS_OK;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
// Otherwise calculate header cells from hierarchy (see 11.4.3 "Algorithm to
|
|
|
|
// find heading information" of w3c HTML 4.01).
|
|
|
|
nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
|
|
|
|
if (table) {
|
|
|
|
return nsAccUtils::GetHeaderCellsFor(table, this, aRowOrColumnHeaderCell,
|
|
|
|
aHeaderCells);
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
return NS_OK;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableHeaderAccessible
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableHeaderCellAccessible::
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLTableHeaderCellAccessible(nsIContent *aContent,
|
|
|
|
nsIWeakReference *aShell) :
|
|
|
|
nsHTMLTableCellAccessible(aContent, aShell)
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableHeaderAccessible: nsAccessible implementation
|
|
|
|
|
2010-09-05 02:14:01 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableHeaderCellAccessible::NativeRole()
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
|
|
|
// Check value of @scope attribute.
|
|
|
|
static nsIContent::AttrValuesArray scopeValues[] =
|
2011-06-03 21:35:17 +00:00
|
|
|
{&nsGkAtoms::col, &nsGkAtoms::row, nsnull};
|
2009-05-14 05:31:09 +00:00
|
|
|
PRInt32 valueIdx =
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::scope,
|
2010-06-11 08:23:18 +00:00
|
|
|
scopeValues, eCaseMatters);
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
switch (valueIdx) {
|
|
|
|
case 0:
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_COLUMNHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
case 1:
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_ROWHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assume it's columnheader if there are headers in siblings, oterwise
|
|
|
|
// rowheader.
|
2010-06-11 08:23:18 +00:00
|
|
|
nsIContent *parent = mContent->GetParent();
|
2010-09-05 02:14:01 +00:00
|
|
|
if (!parent) {
|
|
|
|
NS_ERROR("Deattached content on alive accessible?");
|
|
|
|
return nsIAccessibleRole::ROLE_NOTHING;
|
|
|
|
}
|
2009-11-10 06:12:15 +00:00
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
PRInt32 indexInParent = parent->IndexOf(mContent);
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
for (PRInt32 idx = indexInParent - 1; idx >= 0; idx--) {
|
|
|
|
nsIContent* sibling = parent->GetChildAt(idx);
|
2010-04-30 13:12:06 +00:00
|
|
|
if (sibling && sibling->IsElement()) {
|
2009-05-14 05:31:09 +00:00
|
|
|
if (nsCoreUtils::IsHTMLTableHeader(sibling))
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_COLUMNHEADER;
|
|
|
|
return nsIAccessibleRole::ROLE_ROWHEADER;
|
2008-04-15 03:38:31 +00:00
|
|
|
}
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
PRInt32 childCount = parent->GetChildCount();
|
|
|
|
for (PRInt32 idx = indexInParent + 1; idx < childCount; idx++) {
|
|
|
|
nsIContent* sibling = parent->GetChildAt(idx);
|
2010-04-30 13:12:06 +00:00
|
|
|
if (sibling && sibling->IsElement()) {
|
2009-05-14 05:31:09 +00:00
|
|
|
if (nsCoreUtils::IsHTMLTableHeader(sibling))
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_COLUMNHEADER;
|
|
|
|
return nsIAccessibleRole::ROLE_ROWHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 19:38:19 +00:00
|
|
|
// No elements in siblings what means the table has one column only. Therefore
|
|
|
|
// it should be column header.
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_COLUMNHEADER;
|
2008-04-15 03:38:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLTableAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
|
|
|
nsAccessibleWrap(aContent, aShell)
|
|
|
|
{
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-09-11 01:07:56 +00:00
|
|
|
// nsHTMLTableAccessible: nsISupports implementation
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED2(nsHTMLTableAccessible, nsAccessible,
|
|
|
|
nsHTMLTableAccessible, nsIAccessibleTable)
|
2002-06-07 04:15:18 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsAccessible implementation
|
2007-03-27 08:43:00 +00:00
|
|
|
|
2009-12-10 19:12:19 +00:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::CacheChildren()
|
2007-03-27 08:43:00 +00:00
|
|
|
{
|
2010-07-02 01:22:41 +00:00
|
|
|
// Move caption accessible so that it's the first child. Check for the first
|
|
|
|
// caption only, because nsAccessibilityService ensures we don't create
|
|
|
|
// accessibles for the other captions, since only the first is actually
|
|
|
|
// visible.
|
|
|
|
nsAccTreeWalker walker(mWeakShell, mContent, GetAllowsAnonChildAccessibles());
|
|
|
|
|
2011-03-31 09:30:58 +00:00
|
|
|
nsAccessible* child = nsnull;
|
|
|
|
while ((child = walker.NextChild())) {
|
2010-09-07 02:41:53 +00:00
|
|
|
if (child->Role() == nsIAccessibleRole::ROLE_CAPTION) {
|
2010-07-02 01:22:41 +00:00
|
|
|
InsertChildAt(0, child);
|
2011-03-31 09:30:58 +00:00
|
|
|
while ((child = walker.NextChild()) && AppendChild(child));
|
2009-12-10 19:12:19 +00:00
|
|
|
break;
|
2007-03-27 08:43:00 +00:00
|
|
|
}
|
2010-07-02 01:22:41 +00:00
|
|
|
AppendChild(child);
|
2007-03-27 08:43:00 +00:00
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2010-09-05 02:14:01 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::NativeRole()
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_TABLE;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64
|
|
|
|
nsHTMLTableAccessible::NativeState()
|
2001-12-11 21:42:58 +00:00
|
|
|
{
|
2011-04-09 23:38:06 +00:00
|
|
|
return nsAccessible::NativeState() | states::READONLY;
|
2001-12-11 21:42:58 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 12:26:55 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetNameInternal(nsAString& aName)
|
2001-12-11 21:42:58 +00:00
|
|
|
{
|
2008-10-10 12:26:55 +00:00
|
|
|
nsAccessible::GetNameInternal(aName);
|
2011-06-24 04:01:45 +00:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
2005-06-01 14:03:38 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
// Use table caption as a name.
|
|
|
|
nsAccessible* caption = Caption();
|
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
// If no caption then use summary as a name.
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
|
2001-12-11 21:42:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-06-07 04:15:18 +00:00
|
|
|
|
2007-04-07 09:07:24 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
2006-09-12 19:37:36 +00:00
|
|
|
{
|
2007-04-07 09:07:24 +00:00
|
|
|
nsresult rv = nsAccessibleWrap::GetAttributesInternal(aAttributes);
|
2006-09-12 19:37:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-11 08:23:18 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isProbablyForLayout;
|
2006-09-12 19:37:36 +00:00
|
|
|
IsProbablyForLayout(&isProbablyForLayout);
|
|
|
|
if (isProbablyForLayout) {
|
|
|
|
nsAutoString oldValueUnused;
|
2007-04-07 09:07:24 +00:00
|
|
|
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
|
|
|
|
NS_LITERAL_STRING("true"), oldValueUnused);
|
2006-09-12 19:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsIAccessible implementation
|
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
Relation
|
|
|
|
nsHTMLTableAccessible::RelationByType(PRUint32 aType)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2011-08-10 01:44:00 +00:00
|
|
|
Relation rel = nsAccessibleWrap::RelationByType(aType);
|
|
|
|
if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
|
|
|
|
rel.AppendTarget(Caption());
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
return rel;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsIAccessibleTable implementation
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-05 15:39:29 +00:00
|
|
|
nsHTMLTableAccessible::GetCaption(nsIAccessible **aCaption)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2011-06-24 04:01:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aCaption);
|
2008-10-17 10:10:43 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
NS_IF_ADDREF(*aCaption = Caption());
|
2007-07-05 15:39:29 +00:00
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetSummary(nsAString &aSummary)
|
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mContent));
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return table->GetSummary(aSummary);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetColumnCount(PRInt32 *acolumnCount)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(acolumnCount);
|
|
|
|
*acolumnCount = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
PRInt32 rows;
|
2009-09-11 01:07:56 +00:00
|
|
|
return tableLayout->GetTableSize(rows, *acolumnCount);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetRowCount(PRInt32 *arowCount)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(arowCount);
|
|
|
|
*arowCount = 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
PRInt32 columns;
|
2009-09-11 01:07:56 +00:00
|
|
|
return tableLayout->GetTableSize(*arowCount, columns);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedCellCount(PRUint32* aCount)
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 columnCount = 0;
|
|
|
|
rv = GetColumnCount(&columnCount);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2009-07-02 16:06:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2009-07-02 16:06:23 +00:00
|
|
|
|
2007-07-11 16:08:34 +00:00
|
|
|
PRInt32 rowIndex;
|
2009-09-11 01:07:56 +00:00
|
|
|
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
2007-07-11 16:08:34 +00:00
|
|
|
PRInt32 columnIndex;
|
2009-09-11 01:07:56 +00:00
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
2009-07-02 16:06:23 +00:00
|
|
|
rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
|
|
|
|
*getter_AddRefs(domElement),
|
|
|
|
startRowIndex, startColIndex,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
|
|
|
|
startColIndex == columnIndex && isSelected) {
|
2007-07-11 16:08:34 +00:00
|
|
|
(*aCount)++;
|
2009-07-02 16:06:23 +00:00
|
|
|
}
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedColumnCount(PRUint32* aCount)
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
PRInt32 count = 0;
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = GetColumnCount(&count);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool state = false;
|
2007-07-11 16:08:34 +00:00
|
|
|
rv = IsColumnSelected(index, &state);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
(*aCount)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedRowCount(PRUint32* aCount)
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
PRInt32 count = 0;
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = GetRowCount(&count);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool state = false;
|
2007-07-11 16:08:34 +00:00
|
|
|
rv = IsRowSelected(index, &state);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
(*aCount)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedCells(nsIArray **aCells)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCells);
|
|
|
|
*aCells = nsnull;
|
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 columnCount = 0;
|
|
|
|
rv = GetColumnCount(&columnCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> selCells =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
PRInt32 rowIndex, index;
|
|
|
|
for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
|
|
|
|
PRInt32 columnIndex;
|
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
|
|
|
|
rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
|
|
|
|
*getter_AddRefs(cellElement),
|
|
|
|
startRowIndex, startColIndex,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
|
|
|
|
startColIndex == columnIndex && isSelected) {
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
2010-05-25 08:05:52 +00:00
|
|
|
nsAccessible *cell =
|
2010-06-11 08:23:18 +00:00
|
|
|
GetAccService()->GetAccessibleInWeakShell(cellContent, mWeakShell);
|
2011-10-17 14:59:28 +00:00
|
|
|
selCells->AppendElement(static_cast<nsIAccessible*>(cell), false);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aCells = selCells);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetSelectedCellIndices(PRUint32 *aNumCells,
|
|
|
|
PRInt32 **aCells)
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumCells);
|
|
|
|
*aNumCells = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aCells);
|
|
|
|
*aCells = nsnull;
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 columnCount = 0;
|
|
|
|
rv = GetColumnCount(&columnCount);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
|
|
|
|
2009-07-02 16:06:23 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
2009-09-11 01:07:56 +00:00
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2009-07-02 16:06:23 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 cellsCount = columnCount * rowCount;
|
2011-09-29 06:19:26 +00:00
|
|
|
nsAutoArrayPtr<bool> states(new bool[cellsCount]);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PRInt32 rowIndex, index;
|
2009-09-11 01:07:56 +00:00
|
|
|
for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
|
2007-07-11 16:08:34 +00:00
|
|
|
PRInt32 columnIndex;
|
2009-09-11 01:07:56 +00:00
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
|
2009-07-02 16:06:23 +00:00
|
|
|
rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
|
|
|
|
*getter_AddRefs(domElement),
|
|
|
|
startRowIndex, startColIndex,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
|
|
|
|
startColIndex == columnIndex && isSelected) {
|
2011-10-17 14:59:28 +00:00
|
|
|
states[index] = true;
|
2007-07-11 16:08:34 +00:00
|
|
|
(*aNumCells)++;
|
2009-07-02 16:06:23 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
states[index] = false;
|
2009-07-02 16:06:23 +00:00
|
|
|
}
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 *cellsArray =
|
2009-09-11 01:07:56 +00:00
|
|
|
static_cast<PRInt32*>(nsMemory::Alloc((*aNumCells) * sizeof(PRInt32)));
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_TRUE(cellsArray, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PRInt32 curr = 0;
|
2009-09-11 01:07:56 +00:00
|
|
|
for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
|
2007-07-11 16:08:34 +00:00
|
|
|
PRInt32 columnIndex;
|
2009-09-11 01:07:56 +00:00
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
|
2007-07-11 16:08:34 +00:00
|
|
|
if (states[index]) {
|
|
|
|
PRInt32 cellIndex = -1;
|
2009-09-11 01:07:56 +00:00
|
|
|
GetCellIndexAt(rowIndex, columnIndex, &cellIndex);
|
2007-07-11 16:08:34 +00:00
|
|
|
cellsArray[curr++] = cellIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aCells = cellsArray;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedColumnIndices(PRUint32 *aNumColumns,
|
|
|
|
PRInt32 **aColumns)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PRInt32 columnCount;
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = GetColumnCount(&columnCount);
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *states = new bool[columnCount];
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aNumColumns = 0;
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < columnCount; index++) {
|
|
|
|
rv = IsColumnSelected(index, &states[index]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (states[index]) {
|
|
|
|
(*aNumColumns)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumColumns) * sizeof(PRInt32));
|
|
|
|
if (!outArray) {
|
|
|
|
delete []states;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 curr = 0;
|
|
|
|
for (index = 0; index < columnCount; index++) {
|
|
|
|
if (states[index]) {
|
|
|
|
outArray[curr++] = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete []states;
|
|
|
|
*aColumns = outArray;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedRowIndices(PRUint32 *aNumRows,
|
|
|
|
PRInt32 **aRows)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PRInt32 rowCount;
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = GetRowCount(&rowCount);
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *states = new bool[rowCount];
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aNumRows = 0;
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < rowCount; index++) {
|
|
|
|
rv = IsRowSelected(index, &states[index]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (states[index]) {
|
|
|
|
(*aNumRows)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumRows) * sizeof(PRInt32));
|
|
|
|
if (!outArray) {
|
|
|
|
delete []states;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 curr = 0;
|
|
|
|
for (index = 0; index < rowCount; index++) {
|
|
|
|
if (states[index]) {
|
|
|
|
outArray[curr++] = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete []states;
|
|
|
|
*aRows = outArray;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetCellAt(PRInt32 aRow, PRInt32 aColumn,
|
2006-06-27 15:42:09 +00:00
|
|
|
nsIAccessible **aTableCellAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = GetCellAt(aRow, aColumn, *getter_AddRefs(cellElement));
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
2010-05-25 08:05:52 +00:00
|
|
|
nsAccessible *cell =
|
2010-06-11 08:23:18 +00:00
|
|
|
GetAccService()->GetAccessibleInWeakShell(cellContent, mWeakShell);
|
2010-08-12 15:59:44 +00:00
|
|
|
|
|
|
|
if (!cell) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell != this) {
|
2010-08-12 15:59:40 +00:00
|
|
|
// XXX bug 576838: crazy tables (like table6 in tables/test_table2.html) may
|
|
|
|
// return itself as a cell what makes Orca hang.
|
|
|
|
NS_ADDREF(*aTableCellAccessible = cell);
|
|
|
|
}
|
2010-04-24 00:40:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetCellIndexAt(PRInt32 aRow, PRInt32 aColumn,
|
|
|
|
PRInt32 *aIndex)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-04-20 06:11:14 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIndex);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = tableLayout->GetIndexByRowAndColumn(aRow, aColumn, aIndex);
|
2009-06-29 10:54:26 +00:00
|
|
|
if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32 *aColumn)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-04-20 06:11:14 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aColumn);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2008-02-07 07:03:26 +00:00
|
|
|
|
|
|
|
PRInt32 row;
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, &row, aColumn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return (row == -1 || *aColumn == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32 *aRow)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-04-20 06:11:14 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aRow);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2008-02-07 07:03:26 +00:00
|
|
|
|
|
|
|
PRInt32 column;
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, aRow, &column);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return (*aRow == -1 || column == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 03:16:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetRowAndColumnIndicesAt(PRInt32 aIndex,
|
|
|
|
PRInt32* aRowIdx,
|
|
|
|
PRInt32* aColumnIdx)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRowIdx);
|
|
|
|
*aRowIdx = -1;
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnIdx);
|
|
|
|
*aColumnIdx = -1;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
|
|
|
if (tableLayout)
|
|
|
|
tableLayout->GetRowAndColumnByIndex(aIndex, aRowIdx, aColumnIdx);
|
|
|
|
|
|
|
|
return (*aRowIdx == -1 || *aColumnIdx == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetColumnExtentAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColumnIndex,
|
|
|
|
PRInt32 *aExtentCount)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = tableLayout->
|
2009-09-11 01:07:56 +00:00
|
|
|
GetCellDataAt(aRowIndex, aColumnIndex, *getter_AddRefs(domElement),
|
|
|
|
startRowIndex, startColIndex, rowSpan, colSpan,
|
|
|
|
actualRowSpan, *aExtentCount, isSelected);
|
2009-10-18 02:38:27 +00:00
|
|
|
|
|
|
|
return (rv == NS_TABLELAYOUT_CELL_NOT_FOUND) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetRowExtentAt(PRInt32 aRowIndex, PRInt32 aColumnIndex,
|
|
|
|
PRInt32 *aExtentCount)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualColSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = tableLayout->
|
2009-09-11 01:07:56 +00:00
|
|
|
GetCellDataAt(aRowIndex, aColumnIndex, *getter_AddRefs(domElement),
|
|
|
|
startRowIndex, startColIndex, rowSpan, colSpan,
|
|
|
|
*aExtentCount, actualColSpan, isSelected);
|
2009-10-18 02:38:27 +00:00
|
|
|
|
|
|
|
return (rv == NS_TABLELAYOUT_CELL_NOT_FOUND) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetColumnDescription(PRInt32 aColumn, nsAString &_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetRowDescription(PRInt32 aRow, nsAString &_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHTMLTableAccessible::IsColumnSelected(PRInt32 aColumn, bool *aIsSelected)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-10-18 02:38:27 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsSelected = false;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
PRInt32 colCount = 0;
|
|
|
|
nsresult rv = GetColumnCount(&colCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-02 10:55:13 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
if (aColumn < 0 || aColumn >= colCount)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
rv = GetRowCount(&rowCount);
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
for (PRInt32 rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2009-10-18 02:38:27 +00:00
|
|
|
rv = IsCellSelected(rowIdx, aColumn, &isSelected);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aIsSelected = isSelected;
|
|
|
|
if (!isSelected)
|
|
|
|
break;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHTMLTableAccessible::IsRowSelected(PRInt32 aRow, bool *aIsSelected)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-10-18 02:38:27 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsSelected = false;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-02 10:55:13 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
if (aRow < 0 || aRow >= rowCount)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
PRInt32 colCount = 0;
|
|
|
|
rv = GetColumnCount(&colCount);
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
for (PRInt32 colIdx = 0; colIdx < colCount; colIdx++) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2009-10-18 02:38:27 +00:00
|
|
|
rv = IsCellSelected(aRow, colIdx, &isSelected);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aIsSelected = isSelected;
|
|
|
|
if (!isSelected)
|
|
|
|
break;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-18 02:38:27 +00:00
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::IsCellSelected(PRInt32 aRow, PRInt32 aColumn,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *aIsSelected)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2008-03-06 04:11:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsSelected = false;
|
2008-01-02 10:55:13 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = tableLayout->
|
|
|
|
GetCellDataAt(aRow, aColumn, *getter_AddRefs(domElement),
|
|
|
|
startRowIndex, startColIndex, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan, *aIsSelected);
|
2008-03-06 04:11:45 +00:00
|
|
|
|
|
|
|
if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
return rv;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2007-05-11 12:21:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::SelectRow(PRInt32 aRow)
|
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
RemoveRowsOrColumnsFromSelection(aRow,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2009-09-10 03:06:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return AddRowOrColumnToSelection(aRow,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::SelectColumn(PRInt32 aColumn)
|
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
RemoveRowsOrColumnsFromSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2009-09-10 03:06:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return AddRowOrColumnToSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::UnselectRow(PRInt32 aRow)
|
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return
|
|
|
|
RemoveRowsOrColumnsFromSelection(aRow,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::UnselectColumn(PRInt32 aColumn)
|
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return
|
|
|
|
RemoveRowsOrColumnsFromSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-09-10 03:06:54 +00:00
|
|
|
nsHTMLTableAccessible::AddRowOrColumnToSelection(PRInt32 aIndex,
|
|
|
|
PRUint32 aTarget)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> cellElm;
|
|
|
|
PRInt32 startRowIdx, startColIdx, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected = false;
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
PRInt32 count = 0;
|
2009-09-10 03:06:54 +00:00
|
|
|
if (doSelectRow)
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = GetColumnCount(&count);
|
2009-09-10 03:06:54 +00:00
|
|
|
else
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = GetRowCount(&count);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
|
|
|
|
|
|
|
for (PRInt32 idx = 0; idx < count; idx++) {
|
|
|
|
PRInt32 rowIdx = doSelectRow ? aIndex : idx;
|
|
|
|
PRInt32 colIdx = doSelectRow ? idx : aIndex;
|
|
|
|
rv = tableLayout->GetCellDataAt(rowIdx, colIdx,
|
|
|
|
*getter_AddRefs(cellElm),
|
|
|
|
startRowIdx, startColIdx,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !isSelected) {
|
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElm));
|
|
|
|
rv = tableSelection->SelectCellElement(cellContent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
2009-09-10 03:06:54 +00:00
|
|
|
|
2007-05-12 02:21:10 +00:00
|
|
|
return NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-09-10 03:06:54 +00:00
|
|
|
nsHTMLTableAccessible::RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
|
|
|
|
PRUint32 aTarget,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsOuter)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2009-09-10 03:06:54 +00:00
|
|
|
PRInt32 count = 0;
|
2011-06-13 23:28:35 +00:00
|
|
|
nsresult rv = doUnselectRow ? GetColumnCount(&count) : GetRowCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-10 03:06:54 +00:00
|
|
|
|
|
|
|
PRInt32 startRowIdx = doUnselectRow ? aIndex : 0;
|
|
|
|
PRInt32 endRowIdx = doUnselectRow ? aIndex : count - 1;
|
|
|
|
PRInt32 startColIdx = doUnselectRow ? 0 : aIndex;
|
|
|
|
PRInt32 endColIdx = doUnselectRow ? count - 1 : aIndex;
|
|
|
|
|
|
|
|
if (aIsOuter)
|
2010-06-11 08:23:18 +00:00
|
|
|
return tableSelection->RestrictCellsToSelection(mContent,
|
2009-09-10 03:06:54 +00:00
|
|
|
startRowIdx, startColIdx,
|
|
|
|
endRowIdx, endColIdx);
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
return tableSelection->RemoveCellsFromSelection(mContent,
|
2009-09-10 03:06:54 +00:00
|
|
|
startRowIdx, startColIdx,
|
|
|
|
endRowIdx, endColIdx);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout*
|
|
|
|
nsHTMLTableAccessible::GetTableLayout()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2009-01-12 19:20:59 +00:00
|
|
|
if (!frame)
|
2009-09-11 01:07:56 +00:00
|
|
|
return nsnull;
|
2009-01-12 19:20:59 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = do_QueryFrame(frame);
|
|
|
|
return tableLayout;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetCellAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
nsIDOMElement* &aCell)
|
|
|
|
{
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSelected;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = tableLayout->
|
|
|
|
GetCellDataAt(aRowIndex, aColIndex, aCell, startRowIndex, startColIndex,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan, isSelected);
|
2008-03-06 04:11:45 +00:00
|
|
|
|
|
|
|
if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
return rv;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-23 13:14:05 +00:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::Description(nsString& aDescription)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
|
|
|
// Helpful for debugging layout vs. data tables
|
|
|
|
aDescription.Truncate();
|
2011-04-23 13:14:05 +00:00
|
|
|
nsAccessible::Description(aDescription);
|
|
|
|
if (!aDescription.IsEmpty())
|
|
|
|
return;
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
// Use summary as description if it weren't used as a name.
|
|
|
|
// XXX: get rid code duplication with NameInternal().
|
|
|
|
nsAccessible* caption = Caption();
|
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsAutoString captionText;
|
2011-04-23 13:14:05 +00:00
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
|
2011-06-24 04:01:45 +00:00
|
|
|
&captionText);
|
|
|
|
|
|
|
|
if (!captionText.IsEmpty()) { // summary isn't used as a name.
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary,
|
2011-06-24 04:01:45 +00:00
|
|
|
aDescription);
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 15:39:29 +00:00
|
|
|
}
|
2011-06-24 04:01:45 +00:00
|
|
|
|
2007-07-05 15:39:29 +00:00
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
if (aDescription.IsEmpty()) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isProbablyForLayout;
|
2007-07-05 15:39:29 +00:00
|
|
|
IsProbablyForLayout(&isProbablyForLayout);
|
|
|
|
aDescription = mLayoutHeuristic;
|
|
|
|
}
|
2006-08-11 17:21:56 +00:00
|
|
|
#ifdef DEBUG_A11Y
|
2006-07-24 14:26:25 +00:00
|
|
|
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
|
|
|
|
#endif
|
2007-07-05 15:39:29 +00:00
|
|
|
#endif
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-07-08 02:39:04 +00:00
|
|
|
nsHTMLTableAccessible::HasDescendant(const nsAString& aTagName,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aAllowEmpty)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mContent));
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(tableElt, false);
|
2006-07-24 14:26:25 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
2009-07-08 02:39:04 +00:00
|
|
|
tableElt->GetElementsByTagName(aTagName, getter_AddRefs(nodeList));
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(nodeList, false);
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> foundItem;
|
|
|
|
nodeList->Item(0, getter_AddRefs(foundItem));
|
|
|
|
if (!foundItem)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
if (aAllowEmpty)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
// Make sure that the item we found has contents and either has multiple
|
|
|
|
// children or the found item is not a whitespace-only text node.
|
|
|
|
nsCOMPtr<nsIContent> foundItemContent = do_QueryInterface(foundItem);
|
|
|
|
if (foundItemContent->GetChildCount() > 1)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true; // Treat multiple child nodes as non-empty
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
nsIContent *innerItemContent = foundItemContent->GetChildAt(0);
|
|
|
|
if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
// If we found more than one node then return true not depending on
|
|
|
|
// aAllowEmpty flag.
|
|
|
|
// XXX it might be dummy but bug 501375 where we changed this addresses
|
|
|
|
// performance problems only. Note, currently 'aAllowEmpty' flag is used for
|
|
|
|
// caption element only. On another hand we create accessible object for
|
|
|
|
// the first entry of caption element (see
|
|
|
|
// nsHTMLTableAccessible::CacheChildren).
|
|
|
|
nodeList->Item(1, getter_AddRefs(foundItem));
|
|
|
|
return !!foundItem;
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 13:21:09 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHTMLTableAccessible::IsProbablyForLayout(bool *aIsProbablyForLayout)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
|
|
|
// Implement a heuristic to determine if table is most likely used for layout
|
|
|
|
// XXX do we want to look for rowspan or colspan, especialy that span all but a couple cells
|
|
|
|
// at the beginning or end of a row/col, and especially when they occur at the edge of a table?
|
|
|
|
// XXX expose this info via object attributes to AT-SPI
|
|
|
|
|
|
|
|
// XXX For now debugging descriptions are always on via SHOW_LAYOUT_HEURISTIC
|
|
|
|
// This will allow release trunk builds to be used by testers to refine the algorithm
|
|
|
|
// Change to |#define SHOW_LAYOUT_HEURISTIC DEBUG| before final release
|
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) \
|
|
|
|
{ *aIsProbablyForLayout = isLayout; \
|
|
|
|
mLayoutHeuristic = isLayout ? NS_LITERAL_STRING("layout table: ") : NS_LITERAL_STRING("data table: "); \
|
|
|
|
mLayoutHeuristic += NS_LITERAL_STRING(heuristic); return NS_OK; }
|
|
|
|
#else
|
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { *aIsProbablyForLayout = isLayout; return NS_OK; }
|
|
|
|
#endif
|
|
|
|
|
2011-10-01 01:09:31 +00:00
|
|
|
*aIsProbablyForLayout = false;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2010-03-17 06:02:28 +00:00
|
|
|
nsDocAccessible *docAccessible = GetDocAccessible();
|
2007-04-13 11:38:43 +00:00
|
|
|
if (docAccessible) {
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64 docState = docAccessible->State();
|
|
|
|
if (docState & states::EDITABLE) { // Need to see all elements while document is being edited
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "In editable document");
|
2007-04-13 11:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:21:09 +00:00
|
|
|
// Check to see if an ARIA role overrides the role from native markup,
|
|
|
|
// but for which we still expose table semantics (treegrid, for example).
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasNonTableRole = (Role() != nsIAccessibleRole::ROLE_TABLE);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (hasNonTableRole) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-03 21:35:17 +00:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::role)) {
|
2009-07-03 13:21:09 +00:00
|
|
|
// Role attribute is present, but overridden roles have already been dealt with.
|
|
|
|
// Only landmarks and other roles that don't override the role from native
|
|
|
|
// markup are left to deal with here.
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute, weak role, and role is table");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2011-10-01 01:09:31 +00:00
|
|
|
|
2011-11-07 09:05:51 +00:00
|
|
|
if (mContent->Tag() != nsGkAtoms::table)
|
|
|
|
RETURN_LAYOUT_ANSWER(true, "table built by CSS display:table style");
|
|
|
|
|
2011-10-19 01:36:35 +00:00
|
|
|
// Check if datatable attribute has "0" value.
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::datatable,
|
|
|
|
NS_LITERAL_STRING("0"), eCaseMatters)) {
|
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has datatable = 0 attribute, it's for layout");
|
|
|
|
}
|
|
|
|
|
2011-10-01 01:09:31 +00:00
|
|
|
// Check for legitimate data table attributes.
|
2007-04-10 13:29:31 +00:00
|
|
|
nsAutoString summary;
|
2011-10-01 01:09:31 +00:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, summary) &&
|
|
|
|
!summary.IsEmpty())
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has summary -- legitimate table structures");
|
|
|
|
|
|
|
|
// Check for legitimate data table elements.
|
|
|
|
nsAccessible* caption = FirstChild();
|
|
|
|
if (caption && caption->Role() == nsIAccessibleRole::ROLE_CAPTION &&
|
|
|
|
caption->HasChildren()) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Not empty caption -- legitimate table structures");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2011-10-01 01:09:31 +00:00
|
|
|
|
2011-10-01 03:53:57 +00:00
|
|
|
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
|
|
|
childElm = childElm->GetNextSibling()) {
|
2011-10-01 01:09:31 +00:00
|
|
|
if (!childElm->IsHTML())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (childElm->Tag() == nsGkAtoms::col ||
|
|
|
|
childElm->Tag() == nsGkAtoms::colgroup ||
|
|
|
|
childElm->Tag() == nsGkAtoms::tfoot ||
|
|
|
|
childElm->Tag() == nsGkAtoms::thead) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Has col, colgroup, tfoot or thead -- legitimate table structures");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childElm->Tag() == nsGkAtoms::tbody) {
|
2011-10-01 03:53:57 +00:00
|
|
|
for (nsIContent* rowElm = childElm->GetFirstChild(); rowElm;
|
|
|
|
rowElm = rowElm->GetNextSibling()) {
|
2011-10-01 01:09:31 +00:00
|
|
|
if (rowElm->IsHTML() && rowElm->Tag() == nsGkAtoms::tr) {
|
2011-10-01 03:53:57 +00:00
|
|
|
for (nsIContent* cellElm = rowElm->GetFirstChild(); cellElm;
|
|
|
|
cellElm = cellElm->GetNextSibling()) {
|
2011-10-01 01:09:31 +00:00
|
|
|
if (cellElm->IsHTML() && cellElm->Tag() == nsGkAtoms::th) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Has th -- legitimate table structures");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("table"))) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has a nested table within it");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If only 1 column or only 1 row, it's for layout
|
|
|
|
PRInt32 columns, rows;
|
2009-09-11 01:07:56 +00:00
|
|
|
GetColumnCount(&columns);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (columns <=1) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 column");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2009-09-11 01:07:56 +00:00
|
|
|
GetRowCount(&rows);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (rows <=1) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 row");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many columns
|
|
|
|
if (columns >= 5) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">=5 columns");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we know there are 2-4 columns and 2 or more rows
|
|
|
|
// Check to see if there are visible borders on the cells
|
|
|
|
// XXX currently, we just check the first cell -- do we really need to do more?
|
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
2008-03-06 04:11:45 +00:00
|
|
|
nsresult rv = GetCellAt(0, 0, *getter_AddRefs(cellElement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
|
|
|
NS_ENSURE_TRUE(cellContent, NS_ERROR_FAILURE);
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame *cellFrame = cellContent->GetPrimaryFrame();
|
2007-05-17 08:21:49 +00:00
|
|
|
if (!cellFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
nsMargin border;
|
|
|
|
cellFrame->GetBorder(border);
|
|
|
|
if (border.top && border.bottom && border.left && border.right) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check for styled background color across the row
|
|
|
|
// Alternating background color is a common way
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mContent));
|
2006-07-24 14:26:25 +00:00
|
|
|
tableElt->GetElementsByTagName(NS_LITERAL_STRING("tr"), getter_AddRefs(nodeList));
|
|
|
|
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
|
|
|
|
PRUint32 length;
|
|
|
|
nodeList->GetLength(&length);
|
|
|
|
nsAutoString color, lastRowColor;
|
2009-06-24 23:18:46 +00:00
|
|
|
for (PRUint32 rowCount = 0; rowCount < length; rowCount ++) {
|
2006-07-24 14:26:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> rowNode;
|
|
|
|
nodeList->Item(rowCount, getter_AddRefs(rowNode));
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIContent> rowContent(do_QueryInterface(rowNode));
|
2008-09-17 13:09:34 +00:00
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl =
|
|
|
|
nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), rowContent);
|
2006-07-24 14:26:25 +00:00
|
|
|
NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
|
2008-09-17 13:09:34 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
lastRowColor = color;
|
|
|
|
styleDecl->GetPropertyValue(NS_LITERAL_STRING("background-color"), color);
|
2011-10-17 14:59:28 +00:00
|
|
|
if (rowCount > 0 && false == lastRowColor.Equals(color)) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many rows
|
|
|
|
const PRInt32 kMaxLayoutRows = 20;
|
|
|
|
if (rows > kMaxLayoutRows) { // A ton of rows, this is probably for data
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">= kMaxLayoutRows (20) and non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for very wide table
|
|
|
|
nsAutoString styledWidth;
|
|
|
|
GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("width"), styledWidth);
|
|
|
|
if (styledWidth.EqualsLiteral("100%")) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "<=4 columns and 100% width");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
if (styledWidth.Find(NS_LITERAL_STRING("px"))) { // Hardcoded in pixels
|
|
|
|
nsIFrame *tableFrame = GetFrame();
|
|
|
|
NS_ENSURE_TRUE(tableFrame , NS_ERROR_FAILURE);
|
|
|
|
nsSize tableSize = tableFrame->GetSize();
|
2008-11-01 03:58:07 +00:00
|
|
|
|
2010-06-12 04:04:50 +00:00
|
|
|
nsDocAccessible *docAccessible = GetDocAccessible();
|
2008-11-01 03:58:07 +00:00
|
|
|
NS_ENSURE_TRUE(docAccessible, NS_ERROR_FAILURE);
|
2010-06-12 04:04:50 +00:00
|
|
|
nsIFrame *docFrame = docAccessible->GetFrame();
|
2006-07-24 14:26:25 +00:00
|
|
|
NS_ENSURE_TRUE(docFrame , NS_ERROR_FAILURE);
|
2008-11-01 03:58:07 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsSize docSize = docFrame->GetSize();
|
2008-06-11 08:32:56 +00:00
|
|
|
if (docSize.width > 0) {
|
|
|
|
PRInt32 percentageOfDocWidth = (100 * tableSize.width) / docSize.width;
|
|
|
|
if (percentageOfDocWidth > 95) {
|
|
|
|
// 3-4 columns, no borders, not a lot of rows, and 95% of the doc's width
|
|
|
|
// Probably for layout
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "<=4 columns, width hardcoded in pixels and 95% of document width");
|
2008-06-11 08:32:56 +00:00
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two column rules
|
|
|
|
if (rows * columns <= 10) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "2-4 columns, 10 cells or less, non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("embed")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("object")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("applet")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("iframe"))) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "no layout factor strong enough, so will guess data");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLCaptionAccessible
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-03-07 15:38:58 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
Relation
|
|
|
|
nsHTMLCaptionAccessible::RelationByType(PRUint32 aType)
|
2007-07-05 15:39:29 +00:00
|
|
|
{
|
2011-08-10 01:44:00 +00:00
|
|
|
Relation rel = nsHyperTextAccessible::RelationByType(aType);
|
|
|
|
if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR)
|
|
|
|
rel.AppendTarget(Parent());
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
return rel;
|
2007-07-05 15:39:29 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 02:14:01 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLCaptionAccessible::NativeRole()
|
2009-03-07 15:38:58 +00:00
|
|
|
{
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_CAPTION;
|
2009-03-07 15:38:58 +00:00
|
|
|
}
|