2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsHTMLTableAccessible.h"
|
2010-03-16 23:02:28 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2010-07-01 18:22:41 -07:00
|
|
|
#include "nsAccTreeWalker.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsTextEquivUtils.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Relation.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2010-03-16 23:02:28 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "nsIAccessibleRelation.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
2007-05-11 05:21:43 -07:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsINameSpaceManager.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsIDOMNodeList.h"
|
2007-03-22 10:30:00 -07: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-19 23:11:14 -07:00
|
|
|
#include "nsITableCellLayout.h"
|
2009-09-09 20:06:54 -07:00
|
|
|
#include "nsFrameSelection.h"
|
2008-03-05 20:11:45 -08:00
|
|
|
#include "nsLayoutErrors.h"
|
2009-09-10 18:07:56 -07:00
|
|
|
#include "nsArrayUtils.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-04-14 20:38:31 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-09-10 18:07:56 -07:00
|
|
|
// nsHTMLTableCellAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableCellAccessible::
|
2012-05-27 02:01:40 -07:00
|
|
|
nsHTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-02-07 14:38:54 -08:00
|
|
|
nsHyperTextAccessibleWrap(aContent, aDoc)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableCellAccessible: nsISupports implementation
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableCellAccessible,
|
|
|
|
nsHyperTextAccessible,
|
|
|
|
nsIAccessibleTableCell)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// nsHTMLTableCellAccessible: Accessible implementation
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
nsHTMLTableCellAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::CELL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64
|
|
|
|
nsHTMLTableCellAccessible::NativeState()
|
2009-07-07 19:37:43 -07:00
|
|
|
{
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64 state = nsHyperTextAccessibleWrap::NativeState();
|
2009-07-07 19:37:43 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2009-07-07 19:37:43 -07:00
|
|
|
NS_ASSERTION(frame, "No frame for valid cell accessible!");
|
|
|
|
|
|
|
|
if (frame) {
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::SELECTABLE;
|
2011-12-20 01:15:41 -08:00
|
|
|
if (frame->IsSelected())
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::SELECTED;
|
2009-07-07 19:37:43 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2009-07-07 19:37:43 -07:00
|
|
|
}
|
|
|
|
|
2008-04-14 20:38:31 -07: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 03:31:34 -08:00
|
|
|
// table-cell-index attribute
|
2009-05-13 22:31:09 -07: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-10 18:07:56 -07:00
|
|
|
rv = tableAcc->GetCellIndexAt(rowIdx, colIdx, &idx);
|
2009-05-13 22:31:09 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString stringIdx;
|
|
|
|
stringIdx.AppendInt(idx);
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tableCellIndex, stringIdx);
|
2011-11-24 03:31:34 -08: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 03:53:45 -07:00
|
|
|
if (ChildCount() == 1) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* abbr = FirstChild();
|
2011-11-24 03:31:34 -08:00
|
|
|
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 03:31:41 -08:00
|
|
|
// axis attribute
|
|
|
|
nsAutoString axisText;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText);
|
|
|
|
if (!axisText.IsEmpty())
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::axis, axisText);
|
|
|
|
|
2009-05-13 22:31:09 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableCellAccessible: nsIAccessibleTableCell implementation
|
2009-05-13 22:31:09 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableCellAccessible::GetTable(nsIAccessibleTable **aTable)
|
2009-05-13 22:31:09 -07:00
|
|
|
{
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aTable);
|
|
|
|
*aTable = nsnull;
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
if (IsDefunct())
|
2009-05-13 22:31:09 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
|
|
|
|
table.swap(*aTable);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableCellAccessible::GetColumnIndex(PRInt32 *aColumnIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnIndex);
|
|
|
|
*aColumnIndex = -1;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
|
|
|
return cellLayout->GetColIndex(*aColumnIndex);
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07: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-28 23:19:26 -07:00
|
|
|
nsHTMLTableCellAccessible::IsSelected(bool *aIsSelected)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = false;
|
2009-09-10 18:07:56 -07: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-13 22:31:09 -07:00
|
|
|
|
|
|
|
already_AddRefed<nsIAccessibleTable>
|
|
|
|
nsHTMLTableCellAccessible::GetTableAccessible()
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = this;
|
2011-07-23 01:38:33 -07:00
|
|
|
while ((parent = parent->Parent())) {
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = parent->Role();
|
|
|
|
if (role == roles::TABLE || role == roles::TREE_TABLE) {
|
2009-05-13 22:31:09 -07:00
|
|
|
nsIAccessibleTable* tableAcc = nsnull;
|
2010-09-06 19:41:53 -07:00
|
|
|
CallQueryInterface(parent, &tableAcc);
|
2009-05-13 22:31:09 -07:00
|
|
|
return tableAcc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableCellLayout*
|
|
|
|
nsHTMLTableCellAccessible::GetCellLayout()
|
2009-05-13 22:31:09 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2008-04-23 11:01:04 -07:00
|
|
|
NS_ASSERTION(frame, "The frame cannot be obtaied for HTML table cell.");
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!frame)
|
|
|
|
return nsnull;
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsITableCellLayout *cellLayout = do_QueryFrame(frame);
|
2009-09-10 18:07:56 -07:00
|
|
|
return cellLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLTableCellAccessible::GetCellIndexes(PRInt32& aRowIndex,
|
|
|
|
PRInt32& aColIndex)
|
|
|
|
{
|
|
|
|
nsITableCellLayout *cellLayout = GetCellLayout();
|
2008-04-14 20:38:31 -07:00
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
2009-05-13 22:31:09 -07:00
|
|
|
return cellLayout->GetCellIndexes(aRowIndex, aColIndex);
|
|
|
|
}
|
2008-04-14 20:38:31 -07:00
|
|
|
|
2009-05-13 22:31:09 -07:00
|
|
|
nsresult
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableCellAccessible::GetHeaderCells(PRInt32 aRowOrColumnHeaderCell,
|
|
|
|
nsIArray **aHeaderCells)
|
2009-05-13 22:31:09 -07:00
|
|
|
{
|
2009-09-10 18:07:56 -07:00
|
|
|
// Get header cells from @header attribute.
|
2012-03-22 22:26:52 -07:00
|
|
|
IDRefsIterator iter(mDoc, mContent, nsGkAtoms::headers);
|
2010-11-16 19:32:15 -08:00
|
|
|
nsIContent* headerCellElm = iter.NextElem();
|
|
|
|
if (headerCellElm) {
|
2009-09-10 18:07:56 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIMutableArray> headerCells =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role desiredRole = static_cast<roles::Role>(-1) ;
|
2011-06-13 16:18:57 -07:00
|
|
|
if (aRowOrColumnHeaderCell == nsAccUtils::eRowHeaderCells)
|
2012-01-11 19:07:35 -08:00
|
|
|
desiredRole = roles::ROWHEADER;
|
2011-06-13 16:18:57 -07:00
|
|
|
else if (aRowOrColumnHeaderCell == nsAccUtils::eColumnHeaderCells)
|
2012-01-11 19:07:35 -08:00
|
|
|
desiredRole = roles::COLUMNHEADER;
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2010-11-16 19:32:15 -08:00
|
|
|
do {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* headerCell = mDoc->GetAccessible(headerCellElm);
|
2010-11-16 19:32:15 -08:00
|
|
|
|
2011-06-13 16:18:57 -07:00
|
|
|
if (headerCell && headerCell->Role() == desiredRole)
|
2010-11-16 19:32:15 -08:00
|
|
|
headerCells->AppendElement(static_cast<nsIAccessible*>(headerCell),
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2010-11-16 19:32:15 -08:00
|
|
|
} while ((headerCellElm = iter.NextElem()));
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ADDREF(*aHeaderCells = headerCells);
|
|
|
|
return NS_OK;
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07: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-13 22:31:09 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
return NS_OK;
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableHeaderAccessible
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableHeaderCellAccessible::
|
2012-02-07 14:38:54 -08:00
|
|
|
nsHTMLTableHeaderCellAccessible(nsIContent* aContent,
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* aDoc) :
|
2012-02-07 14:38:54 -08:00
|
|
|
nsHTMLTableCellAccessible(aContent, aDoc)
|
2009-05-13 22:31:09 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// nsHTMLTableHeaderAccessible: Accessible implementation
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
nsHTMLTableHeaderCellAccessible::NativeRole()
|
2009-05-13 22:31:09 -07:00
|
|
|
{
|
|
|
|
// Check value of @scope attribute.
|
|
|
|
static nsIContent::AttrValuesArray scopeValues[] =
|
2011-06-03 14:35:17 -07:00
|
|
|
{&nsGkAtoms::col, &nsGkAtoms::row, nsnull};
|
2012-05-29 17:51:08 -07:00
|
|
|
PRInt32 valueIdx =
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::scope,
|
2010-06-11 01:23:18 -07:00
|
|
|
scopeValues, eCaseMatters);
|
2009-05-13 22:31:09 -07:00
|
|
|
|
|
|
|
switch (valueIdx) {
|
|
|
|
case 0:
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::COLUMNHEADER;
|
2009-05-13 22:31:09 -07:00
|
|
|
case 1:
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::ROWHEADER;
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assume it's columnheader if there are headers in siblings, oterwise
|
|
|
|
// rowheader.
|
2011-12-06 23:20:17 -08:00
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
if (!parentContent) {
|
2010-09-04 19:14:01 -07:00
|
|
|
NS_ERROR("Deattached content on alive accessible?");
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::NOTHING;
|
2010-09-04 19:14:01 -07:00
|
|
|
}
|
2009-11-09 22:12:15 -08:00
|
|
|
|
2011-12-06 23:20:17 -08:00
|
|
|
for (nsIContent* siblingContent = mContent->GetPreviousSibling(); siblingContent;
|
|
|
|
siblingContent = siblingContent->GetPreviousSibling()) {
|
|
|
|
if (siblingContent->IsElement()) {
|
2012-05-29 17:51:08 -07:00
|
|
|
return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::COLUMNHEADER : roles::ROWHEADER;
|
2008-04-14 20:38:31 -07:00
|
|
|
}
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
2008-04-14 20:38:31 -07:00
|
|
|
|
2011-12-06 23:20:17 -08:00
|
|
|
for (nsIContent* siblingContent = mContent->GetNextSibling(); siblingContent;
|
|
|
|
siblingContent = siblingContent->GetNextSibling()) {
|
|
|
|
if (siblingContent->IsElement()) {
|
2012-05-29 17:51:08 -07:00
|
|
|
return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::COLUMNHEADER : roles::ROWHEADER;
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
2008-04-14 20:38:31 -07:00
|
|
|
}
|
|
|
|
|
2009-12-11 11:38:19 -08:00
|
|
|
// No elements in siblings what means the table has one column only. Therefore
|
|
|
|
// it should be column header.
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::COLUMNHEADER;
|
2008-04-14 20:38:31 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::
|
2012-05-27 02:01:40 -07:00
|
|
|
nsHTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc), xpcAccessibleTable(this)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
|
|
|
|
2008-04-14 20:38:31 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-09-10 18:07:56 -07:00
|
|
|
// nsHTMLTableAccessible: nsISupports implementation
|
2008-04-14 20:38:31 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableAccessible, Accessible,
|
2012-04-10 03:52:00 -07:00
|
|
|
nsIAccessibleTable)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-27 17:53:58 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//nsAccessNode
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
mTable = nsnull;
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::Shutdown();
|
2012-03-27 17:53:58 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// nsHTMLTableAccessible: Accessible implementation
|
2007-03-27 01:43:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::CacheChildren()
|
2007-03-27 01:43:00 -07:00
|
|
|
{
|
2010-07-01 18:22:41 -07: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 08:49:17 -08:00
|
|
|
nsAccTreeWalker walker(mDoc, mContent, CanHaveAnonChildren());
|
2010-07-01 18:22:41 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = nsnull;
|
2011-03-31 02:30:58 -07:00
|
|
|
while ((child = walker.NextChild())) {
|
2012-01-11 19:07:35 -08:00
|
|
|
if (child->Role() == roles::CAPTION) {
|
2010-07-01 18:22:41 -07:00
|
|
|
InsertChildAt(0, child);
|
2011-03-31 02:30:58 -07:00
|
|
|
while ((child = walker.NextChild()) && AppendChild(child));
|
2009-12-10 11:12:19 -08:00
|
|
|
break;
|
2007-03-27 01:43:00 -07:00
|
|
|
}
|
2010-07-01 18:22:41 -07:00
|
|
|
AppendChild(child);
|
2007-03-27 01:43:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
nsHTMLTableAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::TABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64
|
|
|
|
nsHTMLTableAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
return Accessible::NativeState() | states::READONLY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetNameInternal(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetNameInternal(aName);
|
2011-06-23 21:01:45 -07:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-23 21:01:45 -07:00
|
|
|
// Use table caption as a name.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* caption = Caption();
|
2011-06-23 21:01:45 -07:00
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 08:39:29 -07:00
|
|
|
|
2011-06-23 21:01:45 -07:00
|
|
|
// If no caption then use summary as a name.
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
nsresult rv = AccessibleWrap::GetAttributesInternal(aAttributes);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2012-03-27 17:53:58 -07:00
|
|
|
if (IsProbablyLayoutTable()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString oldValueUnused;
|
2007-04-07 02:07:24 -07:00
|
|
|
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
|
|
|
|
NS_LITERAL_STRING("true"), oldValueUnused);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-05-29 17:51:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsIAccessible implementation
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation
|
|
|
|
nsHTMLTableAccessible::RelationByType(PRUint32 aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Relation rel = AccessibleWrap::RelationByType(aType);
|
2011-08-09 18:44:00 -07:00
|
|
|
if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
|
|
|
|
rel.AppendTarget(Caption());
|
2007-07-05 08:39:29 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsIAccessibleTable implementation
|
2007-07-05 08:39:29 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-03-27 17:53:58 -07:00
|
|
|
nsHTMLTableAccessible::Caption()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = mChildren.SafeElementAt(0, nsnull);
|
2012-03-27 17:53:58 -07:00
|
|
|
return child && child->Role() == roles::CAPTION ? child : nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-15 19:41:58 -07:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::Summary(nsString& aSummary)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mContent));
|
2012-05-29 17:51:08 -07:00
|
|
|
|
2012-04-15 19:41:58 -07:00
|
|
|
if (table)
|
|
|
|
table->GetSummary(aSummary);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::ColCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-19 14:32:11 -07:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
2012-05-22 10:23:20 -07:00
|
|
|
if (!tableLayout)
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRInt32 rowCount = 0, colCount = 0;
|
|
|
|
tableLayout->GetTableSize(rowCount, colCount);
|
|
|
|
return colCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::RowCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-19 14:32:11 -07:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
2012-05-22 10:23:20 -07:00
|
|
|
if (!tableLayout)
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRInt32 rowCount = 0, colCount = 0;
|
|
|
|
tableLayout->GetTableSize(rowCount, colCount);
|
|
|
|
return rowCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetSelectedCellCount(PRUint32* aCount)
|
2007-07-11 09:08:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 columnCount = 0;
|
|
|
|
rv = GetColumnCount(&columnCount);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2009-07-02 09:06:23 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2009-07-02 09:06:23 -07:00
|
|
|
|
2007-07-11 09:08:34 -07:00
|
|
|
PRInt32 rowIndex;
|
2009-09-10 18:07:56 -07:00
|
|
|
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
2007-07-11 09:08:34 -07:00
|
|
|
PRInt32 columnIndex;
|
2009-09-10 18:07:56 -07:00
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
|
2009-07-02 09:06:23 -07: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 09:08:34 -07:00
|
|
|
(*aCount)++;
|
2009-07-02 09:06:23 -07:00
|
|
|
}
|
2007-07-11 09:08:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetSelectedColumnCount(PRUint32* aCount)
|
2007-07-11 09:08:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
PRInt32 count = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
nsresult rv = GetColumnCount(&count);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool state = false;
|
2007-07-11 09:08:34 -07:00
|
|
|
rv = IsColumnSelected(index, &state);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
(*aCount)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetSelectedRowCount(PRUint32* aCount)
|
2007-07-11 09:08:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
PRInt32 count = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
nsresult rv = GetRowCount(&count);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool state = false;
|
2007-07-11 09:08:34 -07:00
|
|
|
rv = IsRowSelected(index, &state);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
(*aCount)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07: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-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2009-09-10 18:07:56 -07: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 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellContent);
|
2011-10-17 07:59:28 -07:00
|
|
|
selCells->AppendElement(static_cast<nsIAccessible*>(cell), false);
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aCells = selCells);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetSelectedCellIndices(PRUint32 *aNumCells,
|
|
|
|
PRInt32 **aCells)
|
2007-07-11 09:08:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumCells);
|
|
|
|
*aNumCells = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aCells);
|
|
|
|
*aCells = nsnull;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 columnCount = 0;
|
|
|
|
rv = GetColumnCount(&columnCount);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
|
|
|
|
2009-07-02 09:06:23 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
2009-09-10 18:07:56 -07:00
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2009-07-02 09:06:23 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 cellsCount = columnCount * rowCount;
|
2011-09-28 23:19:26 -07:00
|
|
|
nsAutoArrayPtr<bool> states(new bool[cellsCount]);
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PRInt32 rowIndex, index;
|
2009-09-10 18:07:56 -07:00
|
|
|
for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
|
2007-07-11 09:08:34 -07:00
|
|
|
PRInt32 columnIndex;
|
2009-09-10 18:07:56 -07:00
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
|
2009-07-02 09:06:23 -07: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 07:59:28 -07:00
|
|
|
states[index] = true;
|
2007-07-11 09:08:34 -07:00
|
|
|
(*aNumCells)++;
|
2009-07-02 09:06:23 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
states[index] = false;
|
2009-07-02 09:06:23 -07:00
|
|
|
}
|
2007-07-11 09:08:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 *cellsArray =
|
2009-09-10 18:07:56 -07:00
|
|
|
static_cast<PRInt32*>(nsMemory::Alloc((*aNumCells) * sizeof(PRInt32)));
|
2007-07-11 09:08:34 -07:00
|
|
|
NS_ENSURE_TRUE(cellsArray, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PRInt32 curr = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
|
2007-07-11 09:08:34 -07:00
|
|
|
PRInt32 columnIndex;
|
2009-09-10 18:07:56 -07:00
|
|
|
for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
|
2007-07-11 09:08:34 -07:00
|
|
|
if (states[index]) {
|
|
|
|
PRInt32 cellIndex = -1;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetCellIndexAt(rowIndex, columnIndex, &cellIndex);
|
2007-07-11 09:08:34 -07:00
|
|
|
cellsArray[curr++] = cellIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aCells = cellsArray;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetSelectedColumnIndices(PRUint32 *aNumColumns,
|
|
|
|
PRInt32 **aColumns)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PRInt32 columnCount;
|
2009-09-10 18:07:56 -07:00
|
|
|
rv = GetColumnCount(&columnCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *states = new bool[columnCount];
|
2007-03-22 10:30:00 -07: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-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetSelectedRowIndices(PRUint32 *aNumRows,
|
|
|
|
PRInt32 **aRows)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PRInt32 rowCount;
|
2009-09-10 18:07:56 -07:00
|
|
|
rv = GetRowCount(&rowCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *states = new bool[rowCount];
|
2007-03-22 10:30:00 -07: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-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-05-22 09:41:01 -07:00
|
|
|
nsHTMLTableAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
2012-05-22 09:41:01 -07:00
|
|
|
GetCellAt(aRowIndex, aColumnIndex, *getter_AddRefs(cellElement));
|
|
|
|
if (!cellElement)
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
2012-05-22 09:41:01 -07:00
|
|
|
if (!cellContent)
|
|
|
|
return nsnull;
|
2010-08-12 08:59:44 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellContent);
|
2010-04-23 17:40:51 -07:00
|
|
|
|
2012-05-22 09:41:01 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-08 13:50:46 -07:00
|
|
|
PRInt32
|
|
|
|
nsHTMLTableAccessible::CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-08 13:50:46 -07:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
2009-06-29 03:54:26 -07:00
|
|
|
|
2012-05-08 13:50:46 -07:00
|
|
|
PRInt32 index = -1;
|
|
|
|
tableLayout->GetIndexByRowAndColumn(aRowIdx, aColIdx, &index);
|
|
|
|
return index;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32 *aColumn)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-19 23:11:14 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aColumn);
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2008-02-06 23:03:26 -08:00
|
|
|
|
|
|
|
PRInt32 row;
|
2009-10-17 19:38:27 -07:00
|
|
|
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, &row, aColumn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return (row == -1 || *aColumn == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-10 18:07:56 -07:00
|
|
|
nsHTMLTableAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32 *aRow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-19 23:11:14 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRow);
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2008-02-06 23:03:26 -08:00
|
|
|
|
|
|
|
PRInt32 column;
|
2009-10-17 19:38:27 -07:00
|
|
|
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, aRow, &column);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return (*aRow == -1 || column == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 20:16:52 -07: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;
|
|
|
|
}
|
|
|
|
|
2012-05-29 17:51:08 -07:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-29 17:51:08 -07:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
|
|
|
if (!tableLayout)
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected;
|
2012-05-29 17:51:08 -07:00
|
|
|
PRInt32 columnExtent = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
nsresult rv = tableLayout->
|
2012-05-29 17:51:08 -07:00
|
|
|
GetCellDataAt(aRowIdx, aColIdx, *getter_AddRefs(domElement),
|
2009-09-10 18:07:56 -07:00
|
|
|
startRowIndex, startColIndex, rowSpan, colSpan,
|
2012-05-29 17:51:08 -07:00
|
|
|
actualRowSpan, columnExtent, isSelected);
|
2009-10-17 19:38:27 -07:00
|
|
|
|
2012-05-29 17:51:08 -07:00
|
|
|
return columnExtent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-29 17:51:08 -07:00
|
|
|
PRUint32
|
|
|
|
nsHTMLTableAccessible::RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-29 17:51:08 -07:00
|
|
|
nsITableLayout* tableLayout = GetTableLayout();
|
|
|
|
if (!tableLayout)
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualColSpan;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected;
|
2012-05-29 17:51:08 -07:00
|
|
|
PRInt32 rowExtent = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
nsresult rv = tableLayout->
|
2012-05-29 17:51:08 -07:00
|
|
|
GetCellDataAt(aRowIdx, aColIdx, *getter_AddRefs(domElement),
|
2009-09-10 18:07:56 -07:00
|
|
|
startRowIndex, startColIndex, rowSpan, colSpan,
|
2012-05-29 17:51:08 -07:00
|
|
|
rowExtent, actualColSpan, isSelected);
|
2009-10-17 19:38:27 -07:00
|
|
|
|
2012-05-29 17:51:08 -07:00
|
|
|
return rowExtent;
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
nsHTMLTableAccessible::IsColumnSelected(PRInt32 aColumn, bool *aIsSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-17 19:38:27 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
PRInt32 colCount = 0;
|
|
|
|
nsresult rv = GetColumnCount(&colCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-02 02:55:13 -08:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
if (aColumn < 0 || aColumn >= colCount)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
rv = GetRowCount(&rowCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
for (PRInt32 rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2009-10-17 19:38:27 -07:00
|
|
|
rv = IsCellSelected(rowIdx, aColumn, &isSelected);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aIsSelected = isSelected;
|
|
|
|
if (!isSelected)
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLTableAccessible::IsRowSelected(PRInt32 aRow, bool *aIsSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-17 19:38:27 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-02 02:55:13 -08:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
if (aRow < 0 || aRow >= rowCount)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
PRInt32 colCount = 0;
|
|
|
|
rv = GetColumnCount(&colCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
for (PRInt32 colIdx = 0; colIdx < colCount; colIdx++) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2009-10-17 19:38:27 -07:00
|
|
|
rv = IsCellSelected(aRow, colIdx, &isSelected);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aIsSelected = isSelected;
|
|
|
|
if (!isSelected)
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-17 19:38:27 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::IsCellSelected(PRInt32 aRow, PRInt32 aColumn,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *aIsSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-05 20:11:45 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = false;
|
2008-01-02 02:55:13 -08:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsresult rv = tableLayout->
|
|
|
|
GetCellDataAt(aRow, aColumn, *getter_AddRefs(domElement),
|
|
|
|
startRowIndex, startColIndex, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan, *aIsSelected);
|
2008-03-05 20:11:45 -08:00
|
|
|
|
|
|
|
if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-11 05:21:43 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::SelectRow(PRInt32 aRow)
|
|
|
|
{
|
2009-09-09 20:06:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
RemoveRowsOrColumnsFromSelection(aRow,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2009-09-09 20:06:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return AddRowOrColumnToSelection(aRow,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::SelectColumn(PRInt32 aColumn)
|
|
|
|
{
|
2009-09-09 20:06:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
RemoveRowsOrColumnsFromSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2009-09-09 20:06:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return AddRowOrColumnToSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN);
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:19:59 -07:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::UnselectRow(PRUint32 aRowIdx)
|
2007-05-11 05:21:43 -07:00
|
|
|
{
|
2012-04-26 04:19:59 -07:00
|
|
|
RemoveRowsOrColumnsFromSelection(aRowIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
false);
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:19:59 -07:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::UnselectCol(PRUint32 aColIdx)
|
2007-05-11 05:21:43 -07:00
|
|
|
{
|
2012-04-26 04:19:59 -07:00
|
|
|
RemoveRowsOrColumnsFromSelection(aColIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
false);
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-09-09 20:06:54 -07:00
|
|
|
nsHTMLTableAccessible::AddRowOrColumnToSelection(PRInt32 aIndex,
|
|
|
|
PRUint32 aTarget)
|
2007-05-11 05:21:43 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2009-09-09 20:06:54 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> cellElm;
|
|
|
|
PRInt32 startRowIdx, startColIdx, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsresult rv = NS_OK;
|
2007-05-11 05:21:43 -07:00
|
|
|
PRInt32 count = 0;
|
2009-09-09 20:06:54 -07:00
|
|
|
if (doSelectRow)
|
2009-09-10 18:07:56 -07:00
|
|
|
rv = GetColumnCount(&count);
|
2009-09-09 20:06:54 -07:00
|
|
|
else
|
2009-09-10 18:07:56 -07:00
|
|
|
rv = GetRowCount(&count);
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2009-09-09 20:06:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2012-02-07 14:38:54 -08:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2009-09-09 20:06:54 -07: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,
|
2012-05-29 17:51:08 -07:00
|
|
|
isSelected);
|
2009-09-09 20:06:54 -07:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !isSelected) {
|
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElm));
|
|
|
|
rv = tableSelection->SelectCellElement(cellContent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
2009-09-09 20:06:54 -07:00
|
|
|
|
2007-05-11 19:21:10 -07:00
|
|
|
return NS_OK;
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-09-09 20:06:54 -07:00
|
|
|
nsHTMLTableAccessible::RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
|
|
|
|
PRUint32 aTarget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsOuter)
|
2007-05-11 05:21:43 -07:00
|
|
|
{
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2012-02-07 14:38:54 -08:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2009-09-09 20:06:54 -07:00
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
2007-05-11 05:21:43 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2009-09-09 20:06:54 -07:00
|
|
|
PRInt32 count = 0;
|
2011-06-13 16:28:35 -07:00
|
|
|
nsresult rv = doUnselectRow ? GetColumnCount(&count) : GetRowCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-09 20:06:54 -07: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 01:23:18 -07:00
|
|
|
return tableSelection->RestrictCellsToSelection(mContent,
|
2012-05-29 17:51:08 -07:00
|
|
|
startRowIdx, startColIdx,
|
2009-09-09 20:06:54 -07:00
|
|
|
endRowIdx, endColIdx);
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
return tableSelection->RemoveCellsFromSelection(mContent,
|
2012-05-29 17:51:08 -07:00
|
|
|
startRowIdx, startColIdx,
|
2009-09-09 20:06:54 -07:00
|
|
|
endRowIdx, endColIdx);
|
2007-05-11 05:21:43 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout*
|
|
|
|
nsHTMLTableAccessible::GetTableLayout()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2009-01-12 11:20:59 -08:00
|
|
|
if (!frame)
|
2009-09-10 18:07:56 -07:00
|
|
|
return nsnull;
|
2009-01-12 11:20:59 -08:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = do_QueryFrame(frame);
|
|
|
|
return tableLayout;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetCellAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex,
|
|
|
|
nsIDOMElement* &aCell)
|
|
|
|
{
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
nsresult rv = tableLayout->
|
|
|
|
GetCellDataAt(aRowIndex, aColIndex, aCell, startRowIndex, startColIndex,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan, isSelected);
|
2008-03-05 20:11:45 -08:00
|
|
|
|
|
|
|
if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-23 06:14:05 -07:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::Description(nsString& aDescription)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Helpful for debugging layout vs. data tables
|
|
|
|
aDescription.Truncate();
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Description(aDescription);
|
2011-04-23 06:14:05 -07:00
|
|
|
if (!aDescription.IsEmpty())
|
|
|
|
return;
|
2007-07-05 08:39:29 -07:00
|
|
|
|
2011-06-23 21:01:45 -07:00
|
|
|
// Use summary as description if it weren't used as a name.
|
|
|
|
// XXX: get rid code duplication with NameInternal().
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* caption = Caption();
|
2011-06-23 21:01:45 -07:00
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsAutoString captionText;
|
2011-04-23 06:14:05 -07:00
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
|
2011-06-23 21:01:45 -07:00
|
|
|
&captionText);
|
|
|
|
|
|
|
|
if (!captionText.IsEmpty()) { // summary isn't used as a name.
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary,
|
2011-06-23 21:01:45 -07:00
|
|
|
aDescription);
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 08:39:29 -07:00
|
|
|
}
|
2011-06-23 21:01:45 -07:00
|
|
|
|
2007-07-05 08:39:29 -07:00
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
if (aDescription.IsEmpty()) {
|
2012-03-27 17:53:58 -07:00
|
|
|
bool isProbablyForLayout = IsProbablyLayoutTable();
|
2007-07-05 08:39:29 -07:00
|
|
|
aDescription = mLayoutHeuristic;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-07-07 19:39:04 -07:00
|
|
|
nsHTMLTableAccessible::HasDescendant(const nsAString& aTagName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowEmpty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mContent));
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(tableElt, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
2009-07-07 19:39:04 -07:00
|
|
|
tableElt->GetElementsByTagName(aTagName, getter_AddRefs(nodeList));
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(nodeList, false);
|
2009-07-07 19:39:04 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> foundItem;
|
|
|
|
nodeList->Item(0, getter_AddRefs(foundItem));
|
|
|
|
if (!foundItem)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-07-07 19:39:04 -07:00
|
|
|
|
|
|
|
if (aAllowEmpty)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-07-07 19:39:04 -07: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 07:59:28 -07:00
|
|
|
return true; // Treat multiple child nodes as non-empty
|
2009-07-07 19:39:04 -07:00
|
|
|
|
2012-01-24 23:50:07 -08:00
|
|
|
nsIContent *innerItemContent = foundItemContent->GetFirstChild();
|
2009-07-07 19:39:04 -07:00
|
|
|
if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-07 19:39:04 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 17:53:58 -07:00
|
|
|
bool
|
|
|
|
nsHTMLTableAccessible::IsProbablyLayoutTable()
|
2007-03-22 10:30:00 -07: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-27 17:53:58 -07:00
|
|
|
{ \
|
|
|
|
mLayoutHeuristic = isLayout ? \
|
|
|
|
NS_LITERAL_STRING("layout table: " heuristic) : \
|
|
|
|
NS_LITERAL_STRING("data table: " heuristic); \
|
|
|
|
return isLayout; \
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2012-03-27 17:53:58 -07:00
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { return isLayout; }
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* docAccessible = Document();
|
2007-04-13 04:38:43 -07:00
|
|
|
if (docAccessible) {
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64 docState = docAccessible->State();
|
|
|
|
if (docState & states::EDITABLE) { // Need to see all elements while document is being edited
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "In editable document");
|
2007-04-13 04:38:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:21:09 -07: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-05-29 17:51:08 -07:00
|
|
|
if (Role() != roles::TABLE)
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::role)) {
|
2009-07-03 06:21:09 -07: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-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute, weak role, and role is table");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-09-30 18:09:31 -07:00
|
|
|
|
2011-11-07 01:05:51 -08:00
|
|
|
if (mContent->Tag() != nsGkAtoms::table)
|
|
|
|
RETURN_LAYOUT_ANSWER(true, "table built by CSS display:table style");
|
|
|
|
|
2011-10-18 18:36:35 -07: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-09-30 18:09:31 -07:00
|
|
|
// Check for legitimate data table attributes.
|
2007-04-10 06:29:31 -07:00
|
|
|
nsAutoString summary;
|
2011-09-30 18:09:31 -07: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.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* caption = FirstChild();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (caption && caption->Role() == roles::CAPTION && caption->HasChildren())
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "Not empty caption -- legitimate table structures");
|
2011-09-30 18:09:31 -07:00
|
|
|
|
2011-09-30 20:53:57 -07:00
|
|
|
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
|
|
|
childElm = childElm->GetNextSibling()) {
|
2011-09-30 18:09:31 -07: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-09-30 20:53:57 -07:00
|
|
|
for (nsIContent* rowElm = childElm->GetFirstChild(); rowElm;
|
|
|
|
rowElm = rowElm->GetNextSibling()) {
|
2011-09-30 18:09:31 -07:00
|
|
|
if (rowElm->IsHTML() && rowElm->Tag() == nsGkAtoms::tr) {
|
2011-09-30 20:53:57 -07:00
|
|
|
for (nsIContent* cellElm = rowElm->GetFirstChild(); cellElm;
|
|
|
|
cellElm = cellElm->GetNextSibling()) {
|
2012-03-12 10:54:21 -07:00
|
|
|
if (cellElm->IsHTML()) {
|
2012-05-29 17:51:08 -07:00
|
|
|
|
2012-03-12 10:54:21 -07:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellElm);
|
2012-05-25 03:53:45 -07:00
|
|
|
if (cell && cell->ChildCount() == 1 &&
|
2012-03-12 10:54:21 -07:00
|
|
|
cell->FirstChild()->IsAbbreviation()) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"has abbr -- legitimate table structures");
|
|
|
|
}
|
2011-09-30 18:09:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-07 19:39:04 -07:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("table"))) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has a nested table within it");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-01-11 19:07:35 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If only 1 column or only 1 row, it's for layout
|
|
|
|
PRInt32 columns, rows;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetColumnCount(&columns);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (columns <=1) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 column");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-09-10 18:07:56 -07:00
|
|
|
GetRowCount(&rows);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rows <=1) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 row");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many columns
|
|
|
|
if (columns >= 5) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">=5 columns");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-01-11 19:07:35 -08:00
|
|
|
|
2007-03-22 10:30:00 -07: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-05 20:11:45 -08:00
|
|
|
nsresult rv = GetCellAt(0, 0, *getter_AddRefs(cellElement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
|
|
|
|
NS_ENSURE_TRUE(cellContent, NS_ERROR_FAILURE);
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame *cellFrame = cellContent->GetPrimaryFrame();
|
2007-05-17 01:21:49 -07:00
|
|
|
if (!cellFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin border;
|
|
|
|
cellFrame->GetBorder(border);
|
|
|
|
if (border.top && border.bottom && border.left && border.right) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
|
|
|
|
*/
|
|
|
|
|
2012-02-16 23:21:26 -08:00
|
|
|
// Check for styled background color across rows (alternating background
|
|
|
|
// color is a common feature for data tables).
|
2012-05-25 03:53:45 -07:00
|
|
|
PRUint32 childCount = ChildCount();
|
2012-03-03 18:29:25 -08:00
|
|
|
nscolor rowColor, prevRowColor;
|
2012-02-16 23:21:26 -08:00
|
|
|
for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
2012-02-16 23:21:26 -08:00
|
|
|
if (child->Role() == roles::ROW) {
|
2012-03-03 18:29:25 -08: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");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many rows
|
|
|
|
const PRInt32 kMaxLayoutRows = 20;
|
|
|
|
if (rows > kMaxLayoutRows) { // A ton of rows, this is probably for data
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">= kMaxLayoutRows (20) and non-bordered");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-18 01:18:48 -08: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");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two column rules
|
|
|
|
if (rows * columns <= 10) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "2-4 columns, 10 cells or less, non-bordered");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-07 19:39:04 -07:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("embed")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("object")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("applet")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("iframe"))) {
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-30 18:09:31 -07:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "no layout factor strong enough, so will guess data");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLCaptionAccessible
|
2009-09-10 18:07:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-03-07 07:38:58 -08:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation
|
|
|
|
nsHTMLCaptionAccessible::RelationByType(PRUint32 aType)
|
2007-07-05 08:39:29 -07:00
|
|
|
{
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation rel = nsHyperTextAccessible::RelationByType(aType);
|
|
|
|
if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR)
|
|
|
|
rel.AppendTarget(Parent());
|
2007-07-05 08:39:29 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-07-05 08:39:29 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
nsHTMLCaptionAccessible::NativeRole()
|
2009-03-07 07:38:58 -08:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::CAPTION;
|
2009-03-07 07:38:58 -08:00
|
|
|
}
|