2001-09-25 00:48:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
2001-09-25 00:48:50 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 00:48:50 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-03-04 02:31:28 +00:00
|
|
|
*
|
2001-09-25 00:48:50 +00:00
|
|
|
* Contributor(s):
|
2009-09-11 01:07:56 +00:00
|
|
|
* Aaron Leventhal <aaronl@netscape.com> (original author)
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com>
|
2001-09-25 00:48:50 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 00:48:50 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 00:48:50 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 00:48:50 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsHTMLTableAccessible.h"
|
2010-03-17 06:02:28 +00:00
|
|
|
|
|
|
|
#include "nsDocAccessible.h"
|
|
|
|
|
2003-04-15 08:45:55 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2007-05-11 12:21:43 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentRange.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsISelection2.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2005-06-01 14:09:24 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2006-06-27 15:42:09 +00:00
|
|
|
#include "nsIAccessibilityService.h"
|
2006-07-24 14:26:25 +00:00
|
|
|
#include "nsIDOMCSSStyleDeclaration.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 "nsIServiceManager.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"
|
2006-06-27 15:42:09 +00:00
|
|
|
|
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::
|
|
|
|
nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell) :
|
|
|
|
nsHyperTextAccessibleWrap(aDomNode, aShell)
|
|
|
|
{
|
|
|
|
}
|
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
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableCellAccessible::GetRoleInternal(PRUint32 *aResult)
|
2001-03-04 02:31:28 +00:00
|
|
|
{
|
2007-03-15 02:26:13 +00:00
|
|
|
*aResult = nsIAccessibleRole::ROLE_CELL;
|
2001-05-11 21:11:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2009-07-08 02:37:43 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableCellAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
|
|
|
{
|
|
|
|
nsresult rv= nsHyperTextAccessibleWrap::GetStateInternal(aState, aExtraState);
|
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mWeakShell);
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame *frame = content->GetPrimaryFrame();
|
2009-07-08 02:37:43 +00:00
|
|
|
NS_ASSERTION(frame, "No frame for valid cell accessible!");
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTABLE;
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
frame->GetSelected(&isSelected);
|
|
|
|
if (isSelected)
|
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::tableCellIndex,
|
|
|
|
stringIdx);
|
|
|
|
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
|
|
|
|
nsHTMLTableCellAccessible::IsSelected(PRBool *aIsSelected)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
|
|
|
*aIsSelected = PR_FALSE;
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2009-09-15 04:05:26 +00:00
|
|
|
nsCOMPtr<nsIAccessible> childAcc(this), parentAcc;
|
|
|
|
childAcc->GetParent(getter_AddRefs(parentAcc));
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
while (parentAcc) {
|
2009-09-15 04:05:26 +00:00
|
|
|
PRUint32 role = nsAccUtils::Role(parentAcc);
|
|
|
|
if (role == nsIAccessibleRole::ROLE_TABLE ||
|
|
|
|
role == nsIAccessibleRole::ROLE_TREE_TABLE) {
|
2009-05-14 05:31:09 +00:00
|
|
|
nsIAccessibleTable* tableAcc = nsnull;
|
|
|
|
CallQueryInterface(parentAcc, &tableAcc);
|
|
|
|
return tableAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
parentAcc.swap(childAcc);
|
2009-09-15 04:05:26 +00:00
|
|
|
childAcc->GetParent(getter_AddRefs(parentAcc));
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableCellLayout*
|
|
|
|
nsHTMLTableCellAccessible::GetCellLayout()
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
2008-04-15 03:38:31 +00:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame *frame = content->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;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
// Get header cells from @header attribute.
|
|
|
|
nsCOMPtr<nsIArray> headerCellElms;
|
|
|
|
nsCoreUtils::GetElementsByIDRefsAttr(content, nsAccessibilityAtoms::headers,
|
|
|
|
getter_AddRefs(headerCellElms));
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (headerCellElms) {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIMutableArray> headerCells =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRUint32 count = 0;
|
|
|
|
rv = headerCellElms->GetLength(&count);
|
|
|
|
if (NS_SUCCEEDED(rv) && count > 0) {
|
|
|
|
nsCOMPtr<nsIDOMNode> headerCellNode;
|
|
|
|
for (PRUint32 idx = 0; idx < count; idx++) {
|
|
|
|
headerCellNode = do_QueryElementAt(headerCellElms, idx, &rv);
|
2010-04-24 00:40:51 +00:00
|
|
|
nsRefPtr<nsAccessible> headerCell =
|
|
|
|
GetAccService()->GetAccessibleInWeakShell(headerCellNode, mWeakShell);
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
if (headerCell &&
|
|
|
|
(aRowOrColumnHeaderCell == nsAccUtils::eRowHeaderCells &&
|
|
|
|
nsAccUtils::Role(headerCell) == nsIAccessibleRole::ROLE_ROWHEADER ||
|
|
|
|
aRowOrColumnHeaderCell == nsAccUtils::eColumnHeaderCells &&
|
|
|
|
nsAccUtils::Role(headerCell) == nsIAccessibleRole::ROLE_COLUMNHEADER))
|
2010-04-24 00:40:51 +00:00
|
|
|
headerCells->AppendElement(static_cast<nsIAccessible*>(headerCell.get()),
|
|
|
|
PR_FALSE);
|
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::
|
|
|
|
nsHTMLTableHeaderCellAccessible(nsIDOMNode* aDomNode,
|
|
|
|
nsIWeakReference* aShell) :
|
2009-05-14 05:31:09 +00:00
|
|
|
nsHTMLTableCellAccessible(aDomNode, aShell)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableHeaderAccessible: nsAccessible implementation
|
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
nsresult
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableHeaderCellAccessible::GetRoleInternal(PRUint32 *aRole)
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
|
|
|
|
// Check value of @scope attribute.
|
|
|
|
static nsIContent::AttrValuesArray scopeValues[] =
|
|
|
|
{&nsAccessibilityAtoms::col, &nsAccessibilityAtoms::row, nsnull};
|
|
|
|
PRInt32 valueIdx =
|
|
|
|
content->FindAttrValueIn(kNameSpaceID_None, nsAccessibilityAtoms::scope,
|
|
|
|
scopeValues, eCaseMatters);
|
|
|
|
|
|
|
|
switch (valueIdx) {
|
|
|
|
case 0:
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_COLUMNHEADER;
|
|
|
|
return NS_OK;
|
|
|
|
case 1:
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_ROWHEADER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assume it's columnheader if there are headers in siblings, oterwise
|
|
|
|
// rowheader.
|
|
|
|
nsIContent* parent = content->GetParent();
|
2009-11-10 06:12:15 +00:00
|
|
|
NS_ENSURE_STATE(parent);
|
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
PRInt32 indexInParent = parent->IndexOf(content);
|
|
|
|
|
|
|
|
for (PRInt32 idx = indexInParent - 1; idx >= 0; idx--) {
|
|
|
|
nsIContent* sibling = parent->GetChildAt(idx);
|
|
|
|
if (sibling && sibling->IsNodeOfType(nsINode::eELEMENT)) {
|
|
|
|
if (nsCoreUtils::IsHTMLTableHeader(sibling))
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_COLUMNHEADER;
|
|
|
|
else
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_ROWHEADER;
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
PRInt32 childCount = parent->GetChildCount();
|
|
|
|
for (PRInt32 idx = indexInParent + 1; idx < childCount; idx++) {
|
|
|
|
nsIContent* sibling = parent->GetChildAt(idx);
|
|
|
|
if (sibling && sibling->IsNodeOfType(nsINode::eELEMENT)) {
|
|
|
|
if (nsCoreUtils::IsHTMLTableHeader(sibling))
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_COLUMNHEADER;
|
|
|
|
else
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_ROWHEADER;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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.
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_COLUMNHEADER;
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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::
|
|
|
|
nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell) :
|
|
|
|
nsAccessibleWrap(aDomNode, aShell)
|
|
|
|
{
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-09-11 01:07:56 +00:00
|
|
|
// nsHTMLTableAccessible: nsISupports implementation
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED2(nsHTMLTableAccessible, nsAccessible,
|
|
|
|
nsHTMLTableAccessible, nsIAccessibleTable)
|
2002-06-07 04:15:18 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsAccessible implementation
|
2007-03-27 08:43:00 +00:00
|
|
|
|
2009-12-10 19:12:19 +00:00
|
|
|
void
|
|
|
|
nsHTMLTableAccessible::CacheChildren()
|
2007-03-27 08:43:00 +00:00
|
|
|
{
|
2009-12-10 19:12:19 +00:00
|
|
|
nsAccessible::CacheChildren();
|
|
|
|
|
|
|
|
// Move caption accessible so that it's the first child.
|
2010-01-11 14:14:06 +00:00
|
|
|
PRInt32 length = mChildren.Length();
|
2009-12-10 19:12:19 +00:00
|
|
|
for (PRInt32 idx = 0; idx < length; idx++) {
|
|
|
|
// Check for the first caption, because nsAccessibilityService ensures we
|
|
|
|
// don't create accessibles for the other captions, since only the first is
|
|
|
|
// actually visible.
|
|
|
|
|
2010-01-11 14:14:06 +00:00
|
|
|
nsAccessible* child = mChildren.ElementAt(idx);
|
2009-12-10 19:12:19 +00:00
|
|
|
if (nsAccUtils::Role(child) == nsIAccessibleRole::ROLE_CAPTION) {
|
|
|
|
if (idx == 0)
|
2007-07-05 15:39:29 +00:00
|
|
|
break;
|
2009-12-10 19:12:19 +00:00
|
|
|
|
2010-01-11 14:14:06 +00:00
|
|
|
nsRefPtr<nsAccessible> tmp = mChildren[0];
|
|
|
|
mChildren[0] = child;
|
|
|
|
mChildren[idx] = tmp;
|
2009-12-10 19:12:19 +00:00
|
|
|
break;
|
2007-03-27 08:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetRoleInternal(PRUint32 *aResult)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2007-03-15 02:26:13 +00:00
|
|
|
*aResult = nsIAccessibleRole::ROLE_TABLE;
|
2001-05-11 21:11:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2008-11-04 03:37:46 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLTableAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
|
2001-12-11 21:42:58 +00:00
|
|
|
{
|
2008-11-04 03:37:46 +00:00
|
|
|
nsresult rv= nsAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-27 04:04:05 +00:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2008-11-04 03:37:46 +00:00
|
|
|
|
2007-04-02 15:56:24 +00:00
|
|
|
*aState |= nsIAccessibleStates::STATE_READONLY;
|
2001-12-11 21:42:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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);
|
2005-06-01 14:03:38 +00:00
|
|
|
|
2007-07-05 15:39:29 +00:00
|
|
|
if (aName.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (content) {
|
2005-06-01 14:09:24 +00:00
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::summary, aName);
|
|
|
|
}
|
2001-12-11 21:42:58 +00:00
|
|
|
}
|
2007-07-05 15:39:29 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!mDOMNode) {
|
|
|
|
return NS_ERROR_FAILURE; // Node already shut down
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
PRBool isProbablyForLayout;
|
|
|
|
IsProbablyForLayout(&isProbablyForLayout);
|
|
|
|
if (isProbablyForLayout) {
|
|
|
|
nsAutoString oldValueUnused;
|
2007-04-07 09:07:24 +00:00
|
|
|
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
|
|
|
|
NS_LITERAL_STRING("true"), oldValueUnused);
|
2006-09-12 19:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsIAccessible implementation
|
|
|
|
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_IMETHODIMP
|
2009-02-10 10:03:30 +00:00
|
|
|
nsHTMLTableAccessible::GetRelationByType(PRUint32 aRelationType,
|
|
|
|
nsIAccessibleRelation **aRelation)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-02-10 10:03:30 +00:00
|
|
|
nsresult rv = nsAccessibleWrap::GetRelationByType(aRelationType,
|
|
|
|
aRelation);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2007-07-05 15:39:29 +00:00
|
|
|
if (aRelationType == nsIAccessibleRelation::RELATION_DESCRIBED_BY) {
|
2009-02-10 10:03:30 +00:00
|
|
|
nsCOMPtr<nsIAccessible> accCaption;
|
|
|
|
GetCaption(getter_AddRefs(accCaption));
|
|
|
|
return nsRelUtils::AddTarget(aRelationType, aRelation, accCaption);
|
2007-05-17 08:21:49 +00:00
|
|
|
}
|
2007-07-05 15:39:29 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLTableAccessible: nsIAccessibleTable implementation
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-05 15:39:29 +00:00
|
|
|
nsHTMLTableAccessible::GetCaption(nsIAccessible **aCaption)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-07-05 15:39:29 +00:00
|
|
|
nsCOMPtr<nsIAccessible> firstChild;
|
|
|
|
GetFirstChild(getter_AddRefs(firstChild));
|
2008-10-17 10:10:43 +00:00
|
|
|
if (nsAccUtils::Role(firstChild) == nsIAccessibleRole::ROLE_CAPTION)
|
2007-07-05 15:39:29 +00:00
|
|
|
NS_ADDREF(*aCaption = firstChild);
|
2008-10-17 10:10:43 +00:00
|
|
|
|
2007-07-05 15:39:29 +00:00
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::GetSummary(nsAString &aSummary)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return table->GetSummary(aSummary);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetColumnCount(PRInt32 *acolumnCount)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(acolumnCount);
|
|
|
|
*acolumnCount = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
PRInt32 rows;
|
2009-09-11 01:07:56 +00:00
|
|
|
return tableLayout->GetTableSize(rows, *acolumnCount);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetRowCount(PRInt32 *arowCount)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(arowCount);
|
|
|
|
*arowCount = 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
|
|
|
PRInt32 columns;
|
2009-09-11 01:07:56 +00:00
|
|
|
return tableLayout->GetTableSize(*arowCount, columns);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetSelectedCellCount(PRUint32* aCount)
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = GetRowCount(&rowCount);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 columnCount = 0;
|
|
|
|
rv = GetColumnCount(&columnCount);
|
2007-07-11 16:08:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2009-07-02 16:06:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement;
|
|
|
|
PRInt32 startRowIndex = 0, startColIndex = 0,
|
|
|
|
rowSpan, colSpan, actualRowSpan, actualColSpan;
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
|
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++) {
|
|
|
|
PRBool state = PR_FALSE;
|
|
|
|
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++) {
|
|
|
|
PRBool state = PR_FALSE;
|
|
|
|
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;
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
|
|
|
|
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-04-24 00:40:51 +00:00
|
|
|
nsRefPtr<nsAccessible> cell =
|
|
|
|
GetAccService()->GetAccessibleInWeakShell(cellElement, mWeakShell);
|
|
|
|
selCells->AppendElement(static_cast<nsIAccessible*>(cell.get()), PR_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;
|
2009-07-02 16:06:23 +00:00
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
PRInt32 cellsCount = columnCount * rowCount;
|
2007-07-11 16:08:34 +00:00
|
|
|
nsAutoArrayPtr<PRBool> states(new PRBool[cellsCount]);
|
|
|
|
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) {
|
|
|
|
states[index] = PR_TRUE;
|
2007-07-11 16:08:34 +00:00
|
|
|
(*aNumCells)++;
|
2009-07-02 16:06:23 +00:00
|
|
|
} else {
|
|
|
|
states[index] = PR_FALSE;
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
PRBool *states = new PRBool[columnCount];
|
|
|
|
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);
|
|
|
|
|
|
|
|
PRBool *states = new PRBool[rowCount];
|
|
|
|
NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aNumRows = 0;
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < rowCount; index++) {
|
|
|
|
rv = IsRowSelected(index, &states[index]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (states[index]) {
|
|
|
|
(*aNumRows)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumRows) * sizeof(PRInt32));
|
|
|
|
if (!outArray) {
|
|
|
|
delete []states;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 curr = 0;
|
|
|
|
for (index = 0; index < rowCount; index++) {
|
|
|
|
if (states[index]) {
|
|
|
|
outArray[curr++] = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete []states;
|
|
|
|
*aRows = outArray;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetCellAt(PRInt32 aRow, PRInt32 aColumn,
|
2006-06-27 15:42:09 +00:00
|
|
|
nsIAccessible **aTableCellAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = GetCellAt(aRow, aColumn, *getter_AddRefs(cellElement));
|
2006-06-27 15:42:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-24 00:40:51 +00:00
|
|
|
nsRefPtr<nsAccessible> cellAcc =
|
|
|
|
GetAccService()->GetAccessibleInWeakShell(cellElement, mWeakShell);
|
|
|
|
if (cellAcc)
|
|
|
|
CallQueryInterface(cellAcc, aTableCellAccessible);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetCellIndexAt(PRInt32 aRow, PRInt32 aColumn,
|
|
|
|
PRInt32 *aIndex)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-04-20 06:11:14 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIndex);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = tableLayout->GetIndexByRowAndColumn(aRow, aColumn, aIndex);
|
2009-06-29 10:54:26 +00:00
|
|
|
if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32 *aColumn)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-04-20 06:11:14 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aColumn);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2008-02-07 07:03:26 +00:00
|
|
|
|
|
|
|
PRInt32 row;
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, &row, aColumn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return (row == -1 || *aColumn == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-11 01:07:56 +00:00
|
|
|
nsHTMLTableAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32 *aRow)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2007-04-20 06:11:14 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aRow);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2008-02-07 07:03:26 +00:00
|
|
|
|
|
|
|
PRInt32 column;
|
2009-10-18 02:38:27 +00:00
|
|
|
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, aRow, &column);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return (*aRow == -1 || column == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
PRBool 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;
|
|
|
|
PRBool 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
|
2009-10-18 02:38:27 +00:00
|
|
|
nsHTMLTableAccessible::IsColumnSelected(PRInt32 aColumn, PRBool *aIsSelected)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-10-18 02:38:27 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
|
|
|
*aIsSelected = PR_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++) {
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
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
|
2009-10-18 02:38:27 +00:00
|
|
|
nsHTMLTableAccessible::IsRowSelected(PRInt32 aRow, PRBool *aIsSelected)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2009-10-18 02:38:27 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
|
|
|
*aIsSelected = PR_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++) {
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
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,
|
2008-03-06 04:11:45 +00:00
|
|
|
PRBool *aIsSelected)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2008-03-06 04:11:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
|
|
|
*aIsSelected = PR_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,
|
|
|
|
PR_TRUE);
|
|
|
|
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,
|
|
|
|
PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return AddRowOrColumnToSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::UnselectRow(PRInt32 aRow)
|
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return
|
|
|
|
RemoveRowsOrColumnsFromSelection(aRow,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
PR_FALSE);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::UnselectColumn(PRInt32 aColumn)
|
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return
|
|
|
|
RemoveRowsOrColumnsFromSelection(aColumn,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
PR_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
|
|
|
{
|
|
|
|
PRBool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
|
|
|
|
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;
|
|
|
|
PRBool isSelected = PR_FALSE;
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
PRInt32 count = 0;
|
2009-09-10 03:06:54 +00:00
|
|
|
if (doSelectRow)
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = GetColumnCount(&count);
|
2009-09-10 03:06:54 +00:00
|
|
|
else
|
2009-09-11 01:07:56 +00:00
|
|
|
rv = GetRowCount(&count);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
|
|
|
|
|
|
|
for (PRInt32 idx = 0; idx < count; idx++) {
|
|
|
|
PRInt32 rowIdx = doSelectRow ? aIndex : idx;
|
|
|
|
PRInt32 colIdx = doSelectRow ? idx : aIndex;
|
|
|
|
rv = tableLayout->GetCellDataAt(rowIdx, colIdx,
|
|
|
|
*getter_AddRefs(cellElm),
|
|
|
|
startRowIdx, startColIdx,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !isSelected) {
|
|
|
|
nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElm));
|
|
|
|
rv = tableSelection->SelectCellElement(cellContent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
2009-09-10 03:06:54 +00:00
|
|
|
|
2007-05-12 02:21:10 +00:00
|
|
|
return NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-09-10 03:06:54 +00:00
|
|
|
nsHTMLTableAccessible::RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
|
|
|
|
PRUint32 aTarget,
|
|
|
|
PRBool aIsOuter)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2009-09-10 03:06:54 +00:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableLayout *tableLayout = GetTableLayout();
|
|
|
|
NS_ENSURE_STATE(tableLayout);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2009-09-10 03:06:54 +00:00
|
|
|
PRBool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsresult rv = NS_OK;
|
2009-09-10 03:06:54 +00:00
|
|
|
PRInt32 count = 0;
|
|
|
|
if (doUnselectRow)
|
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);
|
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)
|
|
|
|
return tableSelection->RestrictCellsToSelection(content,
|
|
|
|
startRowIdx, startColIdx,
|
|
|
|
endRowIdx, endColIdx);
|
|
|
|
|
|
|
|
return tableSelection->RemoveCellsFromSelection(content,
|
|
|
|
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
|
|
|
{
|
2009-09-11 01:07:56 +00:00
|
|
|
nsCOMPtr<nsIContent> tableContent(do_QueryInterface(mDOMNode));
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame *frame = tableContent->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;
|
|
|
|
PRBool isSelected;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
NS_IMETHODIMP nsHTMLTableAccessible::GetDescription(nsAString& aDescription)
|
|
|
|
{
|
|
|
|
// Helpful for debugging layout vs. data tables
|
|
|
|
aDescription.Truncate();
|
2007-07-05 15:39:29 +00:00
|
|
|
nsAccessible::GetDescription(aDescription);
|
|
|
|
if (!aDescription.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> captionAccessible;
|
|
|
|
GetCaption(getter_AddRefs(captionAccessible));
|
|
|
|
nsCOMPtr<nsIAccessNode> captionAccessNode = do_QueryInterface(captionAccessible);
|
|
|
|
if (captionAccessNode) {
|
|
|
|
nsCOMPtr<nsIDOMNode> captionNode;
|
|
|
|
captionAccessNode->GetDOMNode(getter_AddRefs(captionNode));
|
|
|
|
nsCOMPtr<nsIContent> captionContent = do_QueryInterface(captionNode);
|
|
|
|
if (captionContent) {
|
2009-02-19 07:06:14 +00:00
|
|
|
nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromContent(this, captionContent, &aDescription);
|
2007-07-05 15:39:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
if (aDescription.IsEmpty()) {
|
|
|
|
PRBool isProbablyForLayout;
|
|
|
|
IsProbablyForLayout(&isProbablyForLayout);
|
|
|
|
aDescription = mLayoutHeuristic;
|
|
|
|
}
|
2006-08-11 17:21:56 +00:00
|
|
|
#ifdef DEBUG_A11Y
|
2006-07-24 14:26:25 +00:00
|
|
|
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
|
|
|
|
#endif
|
2007-07-05 15:39:29 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLTableAccessible::HasDescendant(const nsAString& aTagName,
|
|
|
|
PRBool aAllowEmpty)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_TRUE(tableElt, PR_FALSE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
2009-07-08 02:39:04 +00:00
|
|
|
tableElt->GetElementsByTagName(aTagName, getter_AddRefs(nodeList));
|
2008-02-20 07:50:45 +00:00
|
|
|
NS_ENSURE_TRUE(nodeList, PR_FALSE);
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> foundItem;
|
|
|
|
nodeList->Item(0, getter_AddRefs(foundItem));
|
|
|
|
if (!foundItem)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aAllowEmpty)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
return PR_TRUE; // Treat multiple child nodes as non-empty
|
|
|
|
|
|
|
|
nsIContent *innerItemContent = foundItemContent->GetChildAt(0);
|
|
|
|
if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
|
2007-04-10 13:29:31 +00:00
|
|
|
return PR_TRUE;
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
// If we found more than one node then return true not depending on
|
|
|
|
// aAllowEmpty flag.
|
|
|
|
// XXX it might be dummy but bug 501375 where we changed this addresses
|
|
|
|
// performance problems only. Note, currently 'aAllowEmpty' flag is used for
|
|
|
|
// caption element only. On another hand we create accessible object for
|
|
|
|
// the first entry of caption element (see
|
|
|
|
// nsHTMLTableAccessible::CacheChildren).
|
|
|
|
nodeList->Item(1, getter_AddRefs(foundItem));
|
|
|
|
return !!foundItem;
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 13:21:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLTableAccessible::IsProbablyForLayout(PRBool *aIsProbablyForLayout)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
|
|
|
// Implement a heuristic to determine if table is most likely used for layout
|
|
|
|
// XXX do we want to look for rowspan or colspan, especialy that span all but a couple cells
|
|
|
|
// at the beginning or end of a row/col, and especially when they occur at the edge of a table?
|
|
|
|
// XXX expose this info via object attributes to AT-SPI
|
|
|
|
|
|
|
|
// XXX For now debugging descriptions are always on via SHOW_LAYOUT_HEURISTIC
|
|
|
|
// This will allow release trunk builds to be used by testers to refine the algorithm
|
|
|
|
// Change to |#define SHOW_LAYOUT_HEURISTIC DEBUG| before final release
|
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) \
|
|
|
|
{ *aIsProbablyForLayout = isLayout; \
|
|
|
|
mLayoutHeuristic = isLayout ? NS_LITERAL_STRING("layout table: ") : NS_LITERAL_STRING("data table: "); \
|
|
|
|
mLayoutHeuristic += NS_LITERAL_STRING(heuristic); return NS_OK; }
|
|
|
|
#else
|
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { *aIsProbablyForLayout = isLayout; return NS_OK; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*aIsProbablyForLayout = PR_FALSE;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2010-03-17 06:02:28 +00:00
|
|
|
nsDocAccessible *docAccessible = GetDocAccessible();
|
2007-04-13 11:38:43 +00:00
|
|
|
if (docAccessible) {
|
|
|
|
PRUint32 state, extState;
|
2008-11-04 03:37:46 +00:00
|
|
|
docAccessible->GetState(&state, &extState);
|
2007-04-13 11:38:43 +00:00
|
|
|
if (extState & nsIAccessibleStates::EXT_STATE_EDITABLE) { // Need to see all elements while document is being edited
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "In editable document");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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).
|
2008-10-17 10:10:43 +00:00
|
|
|
PRBool hasNonTableRole =
|
|
|
|
(nsAccUtils::Role(this) != nsIAccessibleRole::ROLE_TABLE);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (hasNonTableRole) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "Has role attribute");
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2007-12-12 02:10:26 +00:00
|
|
|
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::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.
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "Has role attribute, weak role, and role is table");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for legitimate data table elements or attributes
|
2007-04-10 13:29:31 +00:00
|
|
|
nsAutoString summary;
|
|
|
|
if ((content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::summary, summary) && !summary.IsEmpty()) ||
|
2009-07-08 02:39:04 +00:00
|
|
|
HasDescendant(NS_LITERAL_STRING("caption"), PR_FALSE) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("th")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("thead")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("tfoot")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("colgroup"))) {
|
2006-07-24 14:26:25 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "Has caption, summary, th, thead, tfoot or colgroup -- legitimate table structures");
|
|
|
|
}
|
2009-07-08 02:39:04 +00:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("table"))) {
|
2006-07-24 14:26:25 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "Has a nested table within it");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "Has only 1 column");
|
|
|
|
}
|
2009-09-11 01:07:56 +00:00
|
|
|
GetRowCount(&rows);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (rows <=1) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "Has only 1 row");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many columns
|
|
|
|
if (columns >= 5) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, ">=5 columns");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "Has nonzero border-width on table cell");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check for styled background color across the row
|
|
|
|
// Alternating background color is a common way
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mDOMNode));
|
|
|
|
tableElt->GetElementsByTagName(NS_LITERAL_STRING("tr"), getter_AddRefs(nodeList));
|
|
|
|
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
|
|
|
|
PRUint32 length;
|
|
|
|
nodeList->GetLength(&length);
|
|
|
|
nsAutoString color, lastRowColor;
|
2009-06-24 23:18:46 +00:00
|
|
|
for (PRUint32 rowCount = 0; rowCount < length; rowCount ++) {
|
2006-07-24 14:26:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> rowNode;
|
|
|
|
nodeList->Item(rowCount, getter_AddRefs(rowNode));
|
2008-09-17 13:09:34 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
|
2008-10-17 10:10:43 +00:00
|
|
|
nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), rowNode,
|
|
|
|
getter_AddRefs(styleDecl));
|
2006-07-24 14:26:25 +00:00
|
|
|
NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
|
2008-09-17 13:09:34 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
lastRowColor = color;
|
|
|
|
styleDecl->GetPropertyValue(NS_LITERAL_STRING("background-color"), color);
|
|
|
|
if (rowCount > 0 && PR_FALSE == lastRowColor.Equals(color)) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "2 styles of row background color, non-bordered");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many rows
|
|
|
|
const PRInt32 kMaxLayoutRows = 20;
|
|
|
|
if (rows > kMaxLayoutRows) { // A ton of rows, this is probably for data
|
2006-11-15 16:14:45 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, ">= kMaxLayoutRows (20) and non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for very wide table
|
|
|
|
nsAutoString styledWidth;
|
|
|
|
GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("width"), styledWidth);
|
|
|
|
if (styledWidth.EqualsLiteral("100%")) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "<=4 columns and 100% width");
|
|
|
|
}
|
|
|
|
if (styledWidth.Find(NS_LITERAL_STRING("px"))) { // Hardcoded in pixels
|
|
|
|
nsIFrame *tableFrame = GetFrame();
|
|
|
|
NS_ENSURE_TRUE(tableFrame , NS_ERROR_FAILURE);
|
|
|
|
nsSize tableSize = tableFrame->GetSize();
|
2008-11-01 03:58:07 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsCOMPtr<nsIAccessibleDocument> docAccessible = GetDocAccessible();
|
2008-11-01 03:58:07 +00:00
|
|
|
NS_ENSURE_TRUE(docAccessible, NS_ERROR_FAILURE);
|
|
|
|
|
2010-04-27 03:16:41 +00:00
|
|
|
nsRefPtr<nsAccessNode> docAccessNode = do_QueryObject(docAccessible);
|
2008-11-01 03:58:07 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsIFrame *docFrame = docAccessNode->GetFrame();
|
|
|
|
NS_ENSURE_TRUE(docFrame , NS_ERROR_FAILURE);
|
2008-11-01 03:58:07 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsSize docSize = docFrame->GetSize();
|
2008-06-11 08:32:56 +00:00
|
|
|
if (docSize.width > 0) {
|
|
|
|
PRInt32 percentageOfDocWidth = (100 * tableSize.width) / docSize.width;
|
|
|
|
if (percentageOfDocWidth > 95) {
|
|
|
|
// 3-4 columns, no borders, not a lot of rows, and 95% of the doc's width
|
|
|
|
// Probably for layout
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "<=4 columns, width hardcoded in pixels and 95% of document width");
|
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two column rules
|
|
|
|
if (rows * columns <= 10) {
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "2-4 columns, 10 cells or less, non-bordered");
|
|
|
|
}
|
|
|
|
|
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"))) {
|
2006-07-24 14:26:25 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(PR_TRUE, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
|
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LAYOUT_ANSWER(PR_FALSE, "no layout factor strong enough, so will guess data");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-07-05 15:39:29 +00:00
|
|
|
NS_IMETHODIMP
|
2009-02-10 10:03:30 +00:00
|
|
|
nsHTMLCaptionAccessible::GetRelationByType(PRUint32 aRelationType,
|
|
|
|
nsIAccessibleRelation **aRelation)
|
2007-07-05 15:39:29 +00:00
|
|
|
{
|
2009-02-10 10:03:30 +00:00
|
|
|
nsresult rv = nsHyperTextAccessible::GetRelationByType(aRelationType,
|
|
|
|
aRelation);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-05 15:39:29 +00:00
|
|
|
|
|
|
|
if (aRelationType == nsIAccessibleRelation::RELATION_DESCRIPTION_FOR) {
|
2009-02-10 10:03:30 +00:00
|
|
|
nsCOMPtr<nsIAccessible> accParent;
|
|
|
|
GetParent(getter_AddRefs(accParent));
|
|
|
|
return nsRelUtils::AddTarget(aRelationType, aRelation, accParent);
|
2007-07-05 15:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLCaptionAccessible::GetRoleInternal(PRUint32 *aRole)
|
|
|
|
{
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_CAPTION;
|
|
|
|
return NS_OK;
|
|
|
|
}
|