2001-09-25 00:48:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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
|
|
|
|
2012-04-13 14:17:03 +00:00
|
|
|
#include "Accessible-inl.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"
|
2012-01-12 03:07:35 +00:00
|
|
|
#include "Relation.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.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::
|
2012-02-07 22:38:54 +00:00
|
|
|
nsHTMLTableCellAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
|
|
|
|
nsHyperTextAccessibleWrap(aContent, aDoc)
|
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
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2010-09-05 02:14:01 +00:00
|
|
|
nsHTMLTableCellAccessible::NativeRole()
|
2001-03-04 02:31:28 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::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-12-20 09:15:41 +00:00
|
|
|
if (frame->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;
|
2012-05-25 10:53:45 +00:00
|
|
|
if (ChildCount() == 1) {
|
2011-11-24 11:31:34 +00:00
|
|
|
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())) {
|
2012-01-12 03:07:35 +00:00
|
|
|
roles::Role role = parent->Role();
|
|
|
|
if (role == roles::TABLE || role == roles::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.
|
2012-03-23 05:26:52 +00:00
|
|
|
IDRefsIterator iter(mDoc, 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);
|
2012-01-12 03:07:35 +00:00
|
|
|
roles::Role desiredRole = static_cast<roles::Role>(-1) ;
|
2011-06-13 23:18:57 +00:00
|
|
|
if (aRowOrColumnHeaderCell == nsAccUtils::eRowHeaderCells)
|
2012-01-12 03:07:35 +00:00
|
|
|
desiredRole = roles::ROWHEADER;
|
2011-06-13 23:18:57 +00:00
|
|
|
else if (aRowOrColumnHeaderCell == nsAccUtils::eColumnHeaderCells)
|
2012-01-12 03:07:35 +00:00
|
|
|
desiredRole = roles::COLUMNHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2010-11-17 03:32:15 +00:00
|
|
|
do {
|
2012-02-07 22:38:54 +00:00
|
|
|
nsAccessible* headerCell = mDoc->GetAccessible(headerCellElm);
|
2010-11-17 03:32:15 +00:00
|
|
|
|
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::
|
2012-02-07 22:38:54 +00:00
|
|
|
nsHTMLTableHeaderCellAccessible(nsIContent* aContent,
|
|
|
|
nsDocAccessible* aDoc) :
|
|
|
|
nsHTMLTableCellAccessible(aContent, aDoc)
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableHeaderAccessible: nsAccessible implementation
|
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2010-09-05 02:14:01 +00:00
|
|
|
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:
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::COLUMNHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
case 1:
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::ROWHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assume it's columnheader if there are headers in siblings, oterwise
|
|
|
|
// rowheader.
|
2011-12-07 07:20:17 +00:00
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
if (!parentContent) {
|
2010-09-05 02:14:01 +00:00
|
|
|
NS_ERROR("Deattached content on alive accessible?");
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::NOTHING;
|
2010-09-05 02:14:01 +00:00
|
|
|
}
|
2009-11-10 06:12:15 +00:00
|
|
|
|
2011-12-07 07:20:17 +00:00
|
|
|
for (nsIContent* siblingContent = mContent->GetPreviousSibling(); siblingContent;
|
|
|
|
siblingContent = siblingContent->GetPreviousSibling()) {
|
|
|
|
if (siblingContent->IsElement()) {
|
2012-01-12 03:07:35 +00:00
|
|
|
return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
|
|
|
|
roles::COLUMNHEADER : roles::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
|
|
|
|
2011-12-07 07:20:17 +00:00
|
|
|
for (nsIContent* siblingContent = mContent->GetNextSibling(); siblingContent;
|
|
|
|
siblingContent = siblingContent->GetNextSibling()) {
|
|
|
|
if (siblingContent->IsElement()) {
|
2012-01-12 03:07:35 +00:00
|
|
|
return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
|
|
|
|
roles::COLUMNHEADER : roles::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.
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::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::
|
2012-02-07 22:38:54 +00:00
|
|
|
nsHTMLTableAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
|
2012-03-28 00:53:58 +00:00
|
|
|
nsAccessibleWrap(aContent, aDoc), xpcAccessibleTable(this)
|
2010-06-11 08:23:18 +00:00
|
|
|
{
|
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
|
|
|
|
2012-04-10 10:52:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableAccessible, nsAccessible,
|
|
|
|
nsIAccessibleTable)
|
2002-06-07 04:15:18 +00:00
|
|
|
|
2012-03-28 00:53:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//nsAccessNode
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
mTable = nsnull;
|
|
|
|
nsAccessibleWrap::Shutdown();
|
|
|
|
}
|
|
|
|
|
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.
|
2012-02-09 16:49:17 +00:00
|
|
|
nsAccTreeWalker walker(mDoc, mContent, CanHaveAnonChildren());
|
2010-07-02 01:22:41 +00:00
|
|
|
|
2011-03-31 09:30:58 +00:00
|
|
|
nsAccessible* child = nsnull;
|
|
|
|
while ((child = walker.NextChild())) {
|
2012-01-12 03:07:35 +00:00
|
|
|
if (child->Role() == roles::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
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2010-09-05 02:14:01 +00:00
|
|
|
nsHTMLTableAccessible::NativeRole()
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::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
|
|
|
|
2012-03-28 00:53:58 +00:00
|
|
|
if (IsProbablyLayoutTable()) {
|
2006-09-12 19:37:36 +00:00
|
|
|
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
|
|
|
|
2012-03-28 00:53:58 +00:00
|
|
|
nsAccessible*
|
|
|
|
nsHTMLTableAccessible::Caption()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-03-28 00:53:58 +00:00
|
|
|
nsAccessible* child = mChildren.SafeElementAt(0, nsnull);
|
|
|
|
return child && child->Role() == roles::CAPTION ? child : nsnull;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 02:41:58 +00:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::Summary(nsString& aSummary)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mContent));
|
2012-04-16 02:41:58 +00:00
|
|
|
|
|
|
|
if (table)
|
|
|
|
table->GetSummary(aSummary);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 21:32:11 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::ColCount()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-04-19 21:32:11 +00:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
2012-05-22 17:23:20 +00:00
|
|
|
if (!tableLayout)
|
|
|
|
return 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-04-19 21:32:11 +00:00
|
|
|
PRInt32 rowCount = 0, colCount = 0;
|
|
|
|
tableLayout->GetTableSize(rowCount, colCount);
|
|
|
|
return colCount;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 21:32:11 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::RowCount()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-04-19 21:32:11 +00:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
2012-05-22 17:23:20 +00:00
|
|
|
if (!tableLayout)
|
|
|
|
return 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-04-19 21:32:11 +00:00
|
|
|
PRInt32 rowCount = 0, colCount = 0;
|
|
|
|
tableLayout->GetTableSize(rowCount, colCount);
|
|
|
|
return rowCount;
|
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));
|
2012-02-07 22:38:54 +00:00
|
|
|
nsAccessible *cell = mDoc->GetAccessible(cellContent);
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:41:01 +00:00
|
|
|
nsAccessible*
|
|
|
|
nsHTMLTableAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
|
|
|
|
{
|
2006-06-27 15:42:09 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
2012-05-22 16:41:01 +00:00
|
|
|
GetCellAt(aRowIndex, aColumnIndex, *getter_AddRefs(cellElement));
|
|
|
|
if (!cellElement)
|
|
|
|
return nsnull;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
2012-05-22 16:41:01 +00:00
|
|
|
if (!cellContent)
|
|
|
|
return nsnull;
|
2010-08-12 15:59:44 +00:00
|
|
|
|
2012-05-22 16:41:01 +00:00
|
|
|
nsAccessible* cell = mDoc->GetAccessible(cellContent);
|
2010-04-24 00:40:51 +00:00
|
|
|
|
2012-05-22 16:41:01 +00:00
|
|
|
// XXX bug 576838: crazy tables (like table6 in tables/test_table2.html) may
|
|
|
|
// return itself as a cell what makes Orca hang.
|
|
|
|
return cell == this ? nsnull : cell;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 20:50:46 +00:00
|
|
|
PRInt32
|
|
|
|
nsHTMLTableAccessible::CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-05-08 20:50:46 +00:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
2009-06-29 10:54:26 +00:00
|
|
|
|
2012-05-08 20:50:46 +00:00
|
|
|
PRInt32 index = -1;
|
|
|
|
tableLayout->GetIndexByRowAndColumn(aRowIdx, aColIdx, &index);
|
|
|
|
return index;
|
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
|
|
|
}
|
|
|
|
|
2012-04-26 11:19:59 +00:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::UnselectRow(PRUint32 aRowIdx)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2012-04-26 11:19:59 +00:00
|
|
|
RemoveRowsOrColumnsFromSelection(aRowIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
false);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 11:19:59 +00:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::UnselectCol(PRUint32 aColIdx)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2012-04-26 11:19:59 +00:00
|
|
|
RemoveRowsOrColumnsFromSelection(aColIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
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
|
|
|
|
2012-02-07 22:38:54 +00:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2009-09-10 03:06:54 +00:00
|
|
|
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
|
|
|
|
2012-02-07 22:38:54 +00:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2009-09-10 03:06:54 +00:00
|
|
|
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()) {
|
2012-03-28 00:53:58 +00:00
|
|
|
bool isProbablyForLayout = IsProbablyLayoutTable();
|
2007-07-05 15:39:29 +00:00
|
|
|
aDescription = mLayoutHeuristic;
|
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-01-25 07:50:07 +00:00
|
|
|
nsIContent *innerItemContent = foundItemContent->GetFirstChild();
|
2009-07-08 02:39:04 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-03-28 00:53:58 +00:00
|
|
|
bool
|
|
|
|
nsHTMLTableAccessible::IsProbablyLayoutTable()
|
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) \
|
2012-03-28 00:53:58 +00:00
|
|
|
{ \
|
|
|
|
mLayoutHeuristic = isLayout ? \
|
|
|
|
NS_LITERAL_STRING("layout table: " heuristic) : \
|
|
|
|
NS_LITERAL_STRING("data table: " heuristic); \
|
|
|
|
return isLayout; \
|
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
#else
|
2012-03-28 00:53:58 +00:00
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { return isLayout; }
|
2006-07-24 14:26:25 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-09 22:52:00 +00:00
|
|
|
nsDocAccessible* docAccessible = Document();
|
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).
|
2012-01-12 03:07:35 +00:00
|
|
|
if (Role() != roles::TABLE)
|
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();
|
2012-01-12 03:07:35 +00:00
|
|
|
if (caption && caption->Role() == roles::CAPTION && caption->HasChildren())
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "Not empty caption -- legitimate table structures");
|
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()) {
|
2012-03-12 17:54:21 +00:00
|
|
|
if (cellElm->IsHTML()) {
|
|
|
|
|
|
|
|
if (cellElm->NodeInfo()->Equals(nsGkAtoms::th)) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Has th -- legitimate table structures");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::headers) ||
|
|
|
|
cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::scope) ||
|
|
|
|
cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::abbr)) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Has headers, scope, or abbr attribute -- legitimate table structures");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAccessible* cell = mDoc->GetAccessible(cellElm);
|
2012-05-25 10:53:45 +00:00
|
|
|
if (cell && cell->ChildCount() == 1 &&
|
2012-03-12 17:54:21 +00:00
|
|
|
cell->FirstChild()->IsAbbreviation()) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"has abbr -- legitimate table structures");
|
|
|
|
}
|
2011-10-01 01:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2012-01-12 03:07:35 +00:00
|
|
|
|
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
|
|
|
}
|
2012-01-12 03:07:35 +00:00
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2012-02-17 07:21:26 +00:00
|
|
|
// Check for styled background color across rows (alternating background
|
|
|
|
// color is a common feature for data tables).
|
2012-05-25 10:53:45 +00:00
|
|
|
PRUint32 childCount = ChildCount();
|
2012-03-04 02:29:25 +00:00
|
|
|
nscolor rowColor, prevRowColor;
|
2012-02-17 07:21:26 +00:00
|
|
|
for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
|
|
|
|
nsAccessible* child = GetChildAt(childIdx);
|
|
|
|
if (child->Role() == roles::ROW) {
|
2012-03-04 02:29:25 +00:00
|
|
|
prevRowColor = rowColor;
|
|
|
|
nsIFrame* rowFrame = child->GetFrame();
|
|
|
|
rowColor = rowFrame->GetStyleBackground()->mBackgroundColor;
|
|
|
|
|
|
|
|
if (childIdx > 0 && prevRowColor != rowColor)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-18 09:18:48 +00:00
|
|
|
// Check for very wide table.
|
|
|
|
nsIFrame* documentFrame = Document()->GetFrame();
|
|
|
|
nsSize documentSize = documentFrame->GetSize();
|
|
|
|
if (documentSize.width > 0) {
|
|
|
|
nsSize tableSize = GetFrame()->GetSize();
|
|
|
|
PRInt32 percentageOfDocWidth = (100 * tableSize.width) / documentSize.width;
|
|
|
|
if (percentageOfDocWidth > 95) {
|
|
|
|
// 3-4 columns, no borders, not a lot of rows, and 95% of the doc's width
|
|
|
|
// Probably for layout
|
|
|
|
RETURN_LAYOUT_ANSWER(true,
|
|
|
|
"<= 4 columns, table width is 95% of document width");
|
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
|
|
|
}
|
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2010-09-05 02:14:01 +00:00
|
|
|
nsHTMLCaptionAccessible::NativeRole()
|
2009-03-07 15:38:58 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::CAPTION;
|
2009-03-07 15:38:58 +00:00
|
|
|
}
|