2001-09-25 00:48:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2012-06-07 12:47:49 +00:00
|
|
|
#include "HTMLTableAccessible.h"
|
2010-03-17 06:02:28 +00:00
|
|
|
|
2013-02-14 15:33:16 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-04-13 14:17:03 +00:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 09:01:40 +00:00
|
|
|
#include "DocAccessible.h"
|
2012-11-19 09:20:09 +00:00
|
|
|
#include "nsIAccessibleRelation.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsTextEquivUtils.h"
|
2012-01-12 03:07:35 +00:00
|
|
|
#include "Relation.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2012-11-19 09:20:09 +00:00
|
|
|
#include "TreeWalker.h"
|
2010-03-17 06:02:28 +00:00
|
|
|
|
2013-02-14 15:33:16 +00:00
|
|
|
#include "mozilla/dom/HTMLTableElement.h"
|
2003-04-15 08:45:55 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2007-05-11 12:21:43 +00:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
2006-06-27 15:42:09 +00:00
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDocument.h"
|
2012-11-19 09:20:09 +00:00
|
|
|
#include "nsIMutableArray.h"
|
2013-09-10 22:18:59 +00:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2006-06-27 15:42:09 +00:00
|
|
|
#include "nsIPresShell.h"
|
2007-04-20 06:11:14 +00:00
|
|
|
#include "nsITableCellLayout.h"
|
2009-09-10 03:06:54 +00:00
|
|
|
#include "nsFrameSelection.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2009-09-11 01:07:56 +00:00
|
|
|
#include "nsArrayUtils.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2012-08-08 13:05:17 +00:00
|
|
|
#include "nsTableCellFrame.h"
|
|
|
|
#include "nsTableOuterFrame.h"
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-07-22 10:35:49 +00:00
|
|
|
using namespace mozilla;
|
2011-07-27 12:43:01 +00:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-04-15 03:38:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableCellAccessible
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableCellAccessible::
|
|
|
|
HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-07-24 15:58:25 +00:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc), xpcAccessibleTableCell(this)
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2013-07-18 15:09:45 +00:00
|
|
|
mGenericTypes |= eTableCell;
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
2003-03-24 02:09:55 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableCellAccessible: nsISupports implementation
|
2003-03-24 02:09:55 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLTableCellAccessible,
|
|
|
|
HyperTextAccessible,
|
|
|
|
nsIAccessibleTableCell)
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableCellAccessible: Accessible implementation
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
void
|
|
|
|
HTMLTableCellAccessible::Shutdown()
|
2012-07-24 15:58:25 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mTableCell = nullptr;
|
2012-07-24 15:58:25 +00:00
|
|
|
HyperTextAccessibleWrap::Shutdown();
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableCellAccessible::NativeRole()
|
2001-03-04 02:31:28 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::CELL;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableCellAccessible::NativeState()
|
2009-07-08 02:37:43 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::NativeState();
|
2009-07-08 02:37:43 +00:00
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2009-07-08 02:37:43 +00:00
|
|
|
NS_ASSERTION(frame, "No frame for valid cell accessible!");
|
|
|
|
|
2012-06-04 05:41:06 +00:00
|
|
|
if (frame && frame->IsSelected())
|
|
|
|
state |= states::SELECTED;
|
2009-07-08 02:37:43 +00:00
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
return state;
|
2009-07-08 02:37:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableCellAccessible::NativeInteractiveState() const
|
2012-06-04 05:41:06 +00:00
|
|
|
{
|
|
|
|
return HyperTextAccessibleWrap::NativeInteractiveState() | states::SELECTABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-19 07:15:23 +00:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HTMLTableCellAccessible::NativeAttributes()
|
2008-04-15 03:38:31 +00:00
|
|
|
{
|
2012-10-19 07:15:23 +00:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
HyperTextAccessibleWrap::NativeAttributes();
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2011-11-24 11:31:34 +00:00
|
|
|
// table-cell-index attribute
|
2012-08-09 06:24:31 +00:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
if (!table)
|
2012-10-19 07:15:23 +00:00
|
|
|
return attributes.forget();
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2012-10-19 07:15:23 +00:00
|
|
|
nsresult rv = GetCellIndexes(rowIdx, colIdx);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return attributes.forget();
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
nsAutoString stringIdx;
|
2012-08-09 06:24:31 +00:00
|
|
|
stringIdx.AppendInt(table->CellIndexAt(rowIdx, colIdx));
|
2012-10-19 07:15:23 +00:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::tableCellIndex, stringIdx);
|
2011-11-24 11:31:34 +00:00
|
|
|
|
|
|
|
// abbr attribute
|
|
|
|
|
|
|
|
// Pick up object attribute from abbr DOM element (a child of the cell) or
|
|
|
|
// from abbr DOM attribute.
|
|
|
|
nsAutoString abbrText;
|
2012-05-25 10:53:45 +00:00
|
|
|
if (ChildCount() == 1) {
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* abbr = FirstChild();
|
2011-11-24 11:31:34 +00:00
|
|
|
if (abbr->IsAbbreviation()) {
|
2012-12-07 17:27:17 +00:00
|
|
|
nsIContent* firstChildNode = abbr->GetContent()->GetFirstChild();
|
|
|
|
if (firstChildNode) {
|
|
|
|
nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromTextContent(firstChildNode, &abbrText);
|
|
|
|
}
|
2011-11-24 11:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (abbrText.IsEmpty())
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::abbr, abbrText);
|
|
|
|
|
|
|
|
if (!abbrText.IsEmpty())
|
2012-10-19 07:15:23 +00:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::abbr, abbrText);
|
2011-11-24 11:31:34 +00:00
|
|
|
|
2011-11-24 11:31:41 +00:00
|
|
|
// axis attribute
|
|
|
|
nsAutoString axisText;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText);
|
|
|
|
if (!axisText.IsEmpty())
|
2012-10-19 07:15:23 +00:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::axis, axisText);
|
2011-11-24 11:31:41 +00:00
|
|
|
|
2012-10-19 07:15:23 +00:00
|
|
|
return attributes.forget();
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableCellAccessible: nsIAccessibleTableCell implementation
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
TableAccessible*
|
|
|
|
HTMLTableCellAccessible::Table() const
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
2012-08-09 06:24:31 +00:00
|
|
|
Accessible* parent = const_cast<HTMLTableCellAccessible*>(this);
|
|
|
|
while ((parent = parent->Parent())) {
|
|
|
|
roles::Role role = parent->Role();
|
|
|
|
if (role == roles::TABLE || role == roles::TREE_TABLE)
|
|
|
|
return parent->AsTable();
|
|
|
|
}
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
return nullptr;
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::ColIdx() const
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
2012-08-09 06:24:31 +00:00
|
|
|
NS_ENSURE_TRUE(cellLayout, 0);
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
int32_t colIdx = 0;
|
|
|
|
cellLayout->GetColIndex(colIdx);
|
|
|
|
return colIdx > 0 ? static_cast<uint32_t>(colIdx) : 0;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::RowIdx() const
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
2012-08-09 06:24:31 +00:00
|
|
|
NS_ENSURE_TRUE(cellLayout, 0);
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
int32_t rowIdx = 0;
|
|
|
|
cellLayout->GetRowIndex(rowIdx);
|
|
|
|
return rowIdx > 0 ? static_cast<uint32_t>(rowIdx) : 0;
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::ColExtent() const
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2009-09-11 01:07:56 +00:00
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
NS_ASSERTION(table, "cell not in a table!");
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
return table->ColExtentAt(rowIdx, colIdx);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::RowExtent() const
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2009-09-11 01:07:56 +00:00
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
NS_ASSERTION(table, "cell not in atable!");
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
return table->RowExtentAt(rowIdx, colIdx);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
void
|
|
|
|
HTMLTableCellAccessible::ColHeaderCells(nsTArray<Accessible*>* aCells)
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2012-08-09 06:24:31 +00:00
|
|
|
IDRefsIterator itr(mDoc, mContent, nsGkAtoms::headers);
|
2013-06-04 05:48:44 +00:00
|
|
|
while (Accessible* cell = itr.Next()) {
|
|
|
|
a11y::role cellRole = cell->Role();
|
|
|
|
if (cellRole == roles::COLUMNHEADER) {
|
2012-08-09 06:24:31 +00:00
|
|
|
aCells->AppendElement(cell);
|
2013-06-04 05:48:44 +00:00
|
|
|
} else if (cellRole != roles::ROWHEADER) {
|
|
|
|
// If referred table cell is at the same column then treat it as a column
|
|
|
|
// header.
|
|
|
|
TableCellAccessible* tableCell = cell->AsTableCell();
|
|
|
|
if (tableCell && tableCell->ColIdx() == ColIdx())
|
|
|
|
aCells->AppendElement(cell);
|
|
|
|
}
|
|
|
|
}
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
if (aCells->IsEmpty())
|
|
|
|
TableCellAccessible::ColHeaderCells(aCells);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
void
|
|
|
|
HTMLTableCellAccessible::RowHeaderCells(nsTArray<Accessible*>* aCells)
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2012-08-09 06:24:31 +00:00
|
|
|
IDRefsIterator itr(mDoc, mContent, nsGkAtoms::headers);
|
2013-06-04 05:48:44 +00:00
|
|
|
while (Accessible* cell = itr.Next()) {
|
|
|
|
a11y::role cellRole = cell->Role();
|
|
|
|
if (cellRole == roles::ROWHEADER) {
|
2012-08-09 06:24:31 +00:00
|
|
|
aCells->AppendElement(cell);
|
2013-06-04 05:48:44 +00:00
|
|
|
} else if (cellRole != roles::COLUMNHEADER) {
|
|
|
|
// If referred table cell is at the same row then treat it as a column
|
|
|
|
// header.
|
|
|
|
TableCellAccessible* tableCell = cell->AsTableCell();
|
|
|
|
if (tableCell && tableCell->RowIdx() == RowIdx())
|
|
|
|
aCells->AppendElement(cell);
|
|
|
|
}
|
|
|
|
}
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
if (aCells->IsEmpty())
|
|
|
|
TableCellAccessible::RowHeaderCells(aCells);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
bool
|
|
|
|
HTMLTableCellAccessible::Selected()
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2009-09-11 01:07:56 +00:00
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
NS_ENSURE_TRUE(table, false);
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
return table->IsCellSelected(rowIdx, colIdx);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableCellAccessible: protected implementation
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
nsITableCellLayout*
|
2012-08-09 06:24:31 +00:00
|
|
|
HTMLTableCellAccessible::GetCellLayout() const
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
2012-08-09 06:24:31 +00:00
|
|
|
return do_QueryFrame(mContent->GetPrimaryFrame());
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-09 06:24:31 +00:00
|
|
|
HTMLTableCellAccessible::GetCellIndexes(int32_t& aRowIdx, int32_t& aColIdx) const
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
|
|
|
nsITableCellLayout *cellLayout = GetCellLayout();
|
2008-04-15 03:38:31 +00:00
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
2012-08-09 06:24:31 +00:00
|
|
|
return cellLayout->GetCellIndexes(aRowIdx, aColIdx);
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableHeaderCellAccessible
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableHeaderCellAccessible::
|
|
|
|
HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
|
|
|
HTMLTableCellAccessible(aContent, aDoc)
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableHeaderCellAccessible: Accessible implementation
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableHeaderCellAccessible::NativeRole()
|
2009-05-14 05:31:09 +00:00
|
|
|
{
|
|
|
|
// Check value of @scope attribute.
|
|
|
|
static nsIContent::AttrValuesArray scopeValues[] =
|
2012-07-30 14:20:58 +00:00
|
|
|
{&nsGkAtoms::col, &nsGkAtoms::row, nullptr};
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t valueIdx =
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::scope,
|
2010-06-11 08:23:18 +00:00
|
|
|
scopeValues, eCaseMatters);
|
2009-05-14 05:31:09 +00:00
|
|
|
|
|
|
|
switch (valueIdx) {
|
|
|
|
case 0:
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::COLUMNHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
case 1:
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::ROWHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-04 05:48:44 +00:00
|
|
|
// Assume it's columnheader if there are headers in siblings, otherwise
|
2009-05-14 05:31:09 +00:00
|
|
|
// rowheader.
|
2013-05-01 22:50:08 +00:00
|
|
|
// This should iterate the flattened tree
|
2011-12-07 07:20:17 +00:00
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
if (!parentContent) {
|
2010-09-05 02:14:01 +00:00
|
|
|
NS_ERROR("Deattached content on alive accessible?");
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::NOTHING;
|
2010-09-05 02:14:01 +00:00
|
|
|
}
|
2009-11-10 06:12:15 +00:00
|
|
|
|
2011-12-07 07:20:17 +00:00
|
|
|
for (nsIContent* siblingContent = mContent->GetPreviousSibling(); siblingContent;
|
|
|
|
siblingContent = siblingContent->GetPreviousSibling()) {
|
|
|
|
if (siblingContent->IsElement()) {
|
2012-05-30 00:51:08 +00:00
|
|
|
return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
|
2013-06-04 05:48:44 +00:00
|
|
|
roles::COLUMNHEADER : roles::ROWHEADER;
|
2008-04-15 03:38:31 +00:00
|
|
|
}
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
|
2011-12-07 07:20:17 +00:00
|
|
|
for (nsIContent* siblingContent = mContent->GetNextSibling(); siblingContent;
|
|
|
|
siblingContent = siblingContent->GetNextSibling()) {
|
|
|
|
if (siblingContent->IsElement()) {
|
2012-05-30 00:51:08 +00:00
|
|
|
return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
|
2013-06-04 05:48:44 +00:00
|
|
|
roles::COLUMNHEADER : roles::ROWHEADER;
|
2009-05-14 05:31:09 +00:00
|
|
|
}
|
2008-04-15 03:38:31 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 19:38:19 +00:00
|
|
|
// No elements in siblings what means the table has one column only. Therefore
|
|
|
|
// it should be column header.
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::COLUMNHEADER;
|
2008-04-15 03:38:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 07:33:01 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLTableRowAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableRowAccessible, Accessible)
|
|
|
|
|
|
|
|
role
|
|
|
|
HTMLTableRowAccessible::NativeRole()
|
|
|
|
{
|
|
|
|
return roles::ROW;
|
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableAccessible
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 05:31:09 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLTableAccessible, Accessible,
|
|
|
|
nsIAccessibleTable)
|
2002-06-07 04:15:18 +00:00
|
|
|
|
2012-03-28 00:53:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-10-29 03:30:55 +00:00
|
|
|
// HTMLTableAccessible: Accessible
|
2012-03-28 00:53:58 +00:00
|
|
|
|
|
|
|
void
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::Shutdown()
|
2012-03-28 00:53:58 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mTable = nullptr;
|
2012-05-29 01:18:45 +00:00
|
|
|
AccessibleWrap::Shutdown();
|
2012-03-28 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
2009-12-10 19:12:19 +00:00
|
|
|
void
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::CacheChildren()
|
2007-03-27 08:43:00 +00:00
|
|
|
{
|
2010-07-02 01:22:41 +00:00
|
|
|
// Move caption accessible so that it's the first child. Check for the first
|
|
|
|
// caption only, because nsAccessibilityService ensures we don't create
|
|
|
|
// accessibles for the other captions, since only the first is actually
|
|
|
|
// visible.
|
2012-11-19 09:20:09 +00:00
|
|
|
TreeWalker walker(this, mContent);
|
2010-07-02 01:22:41 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
Accessible* child = nullptr;
|
2011-03-31 09:30:58 +00:00
|
|
|
while ((child = walker.NextChild())) {
|
2012-01-12 03:07:35 +00:00
|
|
|
if (child->Role() == roles::CAPTION) {
|
2010-07-02 01:22:41 +00:00
|
|
|
InsertChildAt(0, child);
|
2011-03-31 09:30:58 +00:00
|
|
|
while ((child = walker.NextChild()) && AppendChild(child));
|
2009-12-10 19:12:19 +00:00
|
|
|
break;
|
2007-03-27 08:43:00 +00:00
|
|
|
}
|
2010-07-02 01:22:41 +00:00
|
|
|
AppendChild(child);
|
2007-03-27 08:43:00 +00:00
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::NativeRole()
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::TABLE;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2001-03-04 02:31:28 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::NativeState()
|
2001-12-11 21:42:58 +00:00
|
|
|
{
|
2012-05-29 01:18:45 +00:00
|
|
|
return Accessible::NativeState() | states::READONLY;
|
2001-12-11 21:42:58 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 04:18:39 +00:00
|
|
|
ENameValueFlag
|
|
|
|
HTMLTableAccessible::NativeName(nsString& aName)
|
2001-12-11 21:42:58 +00:00
|
|
|
{
|
2012-10-17 06:38:16 +00:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
2011-06-24 04:01:45 +00:00
|
|
|
if (!aName.IsEmpty())
|
2012-10-17 06:38:16 +00:00
|
|
|
return nameFlag;
|
2005-06-01 14:03:38 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
// Use table caption as a name.
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* caption = Caption();
|
2011-06-24 04:01:45 +00:00
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
|
|
|
|
if (!aName.IsEmpty())
|
2012-10-14 04:18:39 +00:00
|
|
|
return eNameOK;
|
2011-06-24 04:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
// If no caption then use summary as a name.
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
|
2012-10-14 04:18:39 +00:00
|
|
|
return eNameOK;
|
2001-12-11 21:42:58 +00:00
|
|
|
}
|
2002-06-07 04:15:18 +00:00
|
|
|
|
2012-10-19 07:15:23 +00:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HTMLTableAccessible::NativeAttributes()
|
2006-09-12 19:37:36 +00:00
|
|
|
{
|
2012-10-19 07:15:23 +00:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
AccessibleWrap::NativeAttributes();
|
2012-03-28 00:53:58 +00:00
|
|
|
if (IsProbablyLayoutTable()) {
|
2012-10-19 07:15:23 +00:00
|
|
|
nsAutoString unused;
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
|
|
|
|
NS_LITERAL_STRING("true"), unused);
|
2006-09-12 19:37:36 +00:00
|
|
|
}
|
2012-05-30 00:51:08 +00:00
|
|
|
|
2012-10-19 07:15:23 +00:00
|
|
|
return attributes.forget();
|
2006-09-12 19:37:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableAccessible: nsIAccessible implementation
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
Relation
|
2013-10-19 18:19:50 +00:00
|
|
|
HTMLTableAccessible::RelationByType(RelationType aType)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-05-29 01:18:45 +00:00
|
|
|
Relation rel = AccessibleWrap::RelationByType(aType);
|
2013-10-19 18:19:50 +00:00
|
|
|
if (aType == RelationType::LABELLED_BY)
|
2011-08-10 01:44:00 +00:00
|
|
|
rel.AppendTarget(Caption());
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
return rel;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableAccessible: nsIAccessibleTable implementation
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible*
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::Caption()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
Accessible* child = mChildren.SafeElementAt(0, nullptr);
|
|
|
|
return child && child->Role() == roles::CAPTION ? child : nullptr;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 02:41:58 +00:00
|
|
|
void
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::Summary(nsString& aSummary)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2013-02-14 15:33:16 +00:00
|
|
|
dom::HTMLTableElement* table = dom::HTMLTableElement::FromContent(mContent);
|
2012-05-30 00:51:08 +00:00
|
|
|
|
2012-04-16 02:41:58 +00:00
|
|
|
if (table)
|
|
|
|
table->GetSummary(aSummary);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::ColCount()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
return tableFrame ? tableFrame->GetColCount() : 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::RowCount()
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
return tableFrame ? tableFrame->GetRowCount() : 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-20 18:05:31 +00:00
|
|
|
HTMLTableAccessible::SelectedCellCount()
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-06-20 18:05:31 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = 0, rowCount = RowCount(), colCount = ColCount();
|
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) {
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx);
|
|
|
|
if (!cellFrame || !cellFrame->IsSelected())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int32_t startRow = -1, startCol = -1;
|
|
|
|
cellFrame->GetRowIndex(startRow);
|
|
|
|
cellFrame->GetColIndex(startCol);
|
2012-12-17 20:54:44 +00:00
|
|
|
if (startRow >= 0 && (uint32_t)startRow == rowIdx &&
|
|
|
|
startCol >= 0 && (uint32_t)startCol == colIdx)
|
2012-06-20 18:05:31 +00:00
|
|
|
count++;
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 18:05:31 +00:00
|
|
|
return count;
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-20 18:05:31 +00:00
|
|
|
HTMLTableAccessible::SelectedColCount()
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = 0, colCount = ColCount();
|
2007-07-11 16:08:34 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++)
|
2012-06-20 18:05:31 +00:00
|
|
|
if (IsColSelected(colIdx))
|
|
|
|
count++;
|
2007-07-11 16:08:34 +00:00
|
|
|
|
2012-06-20 18:05:31 +00:00
|
|
|
return count;
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-20 18:05:31 +00:00
|
|
|
HTMLTableAccessible::SelectedRowCount()
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = 0, rowCount = RowCount();
|
2007-07-11 16:08:34 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++)
|
2012-06-20 18:05:31 +00:00
|
|
|
if (IsRowSelected(rowIdx))
|
|
|
|
count++;
|
2007-07-11 16:08:34 +00:00
|
|
|
|
2012-06-20 18:05:31 +00:00
|
|
|
return count;
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 08:14:22 +00:00
|
|
|
void
|
|
|
|
HTMLTableAccessible::SelectedCells(nsTArray<Accessible*>* aCells)
|
2009-09-11 01:07:56 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-06-29 08:14:22 +00:00
|
|
|
return;
|
2009-09-11 01:07:56 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
uint32_t rowCount = RowCount(), colCount = ColCount();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) {
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx);
|
|
|
|
if (!cellFrame || !cellFrame->IsSelected())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int32_t startCol = -1, startRow = -1;
|
|
|
|
cellFrame->GetRowIndex(startRow);
|
|
|
|
cellFrame->GetColIndex(startCol);
|
2012-12-17 20:54:44 +00:00
|
|
|
if ((startRow >= 0 && (uint32_t)startRow != rowIdx) ||
|
|
|
|
(startCol >= 0 && (uint32_t)startCol != colIdx))
|
2012-08-08 13:05:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Accessible* cell = mDoc->GetAccessible(cellFrame->GetContent());
|
2012-06-29 08:14:22 +00:00
|
|
|
aCells->AppendElement(cell);
|
2009-09-11 01:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-23 22:34:44 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::SelectedCellIndices(nsTArray<uint32_t>* aCells)
|
2007-07-11 16:08:34 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-06-23 22:34:44 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t rowCount = RowCount(), colCount = ColCount();
|
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) {
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx);
|
|
|
|
if (!cellFrame || !cellFrame->IsSelected())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int32_t startRow = -1, startCol = -1;
|
|
|
|
cellFrame->GetColIndex(startCol);
|
|
|
|
cellFrame->GetRowIndex(startRow);
|
2012-12-17 20:54:44 +00:00
|
|
|
if (startRow >= 0 && (uint32_t)startRow == rowIdx &&
|
|
|
|
startCol >= 0 && (uint32_t)startCol == colIdx)
|
2012-06-23 22:34:44 +00:00
|
|
|
aCells->AppendElement(CellIndexAt(rowIdx, colIdx));
|
2007-07-11 16:08:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-23 22:34:44 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::SelectedColIndices(nsTArray<uint32_t>* aCols)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t colCount = ColCount();
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++)
|
2012-06-23 22:34:44 +00:00
|
|
|
if (IsColSelected(colIdx))
|
|
|
|
aCols->AppendElement(colIdx);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 22:34:44 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::SelectedRowIndices(nsTArray<uint32_t>* aRows)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t rowCount = RowCount();
|
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++)
|
2012-06-23 22:34:44 +00:00
|
|
|
if (IsRowSelected(rowIdx))
|
|
|
|
aRows->AppendElement(rowIdx);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible*
|
2012-08-08 13:05:17 +00:00
|
|
|
HTMLTableAccessible::CellAt(uint32_t aRowIdx, uint32_t aColIdx)
|
|
|
|
{
|
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-08-12 15:59:44 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
nsIContent* cellContent = tableFrame->GetCellAt(aRowIdx, aColIdx);
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellContent);
|
2010-04-24 00:40:51 +00:00
|
|
|
|
2012-05-22 16:41:01 +00:00
|
|
|
// XXX bug 576838: crazy tables (like table6 in tables/test_table2.html) may
|
|
|
|
// return itself as a cell what makes Orca hang.
|
2012-07-30 14:20:58 +00:00
|
|
|
return cell == this ? nullptr : cell;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
|
|
|
HTMLTableAccessible::CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
|
|
|
return -1;
|
2009-06-29 10:54:26 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
return tableFrame->GetIndexByRowAndColumn(aRowIdx, aColIdx);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
|
|
|
HTMLTableAccessible::ColIndexAt(uint32_t aCellIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-06-23 22:34:48 +00:00
|
|
|
return -1;
|
2009-10-18 02:38:27 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2012-08-08 13:05:17 +00:00
|
|
|
tableFrame->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx);
|
2012-06-23 22:34:48 +00:00
|
|
|
return colIdx;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
|
|
|
HTMLTableAccessible::RowIndexAt(uint32_t aCellIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-06-23 22:34:48 +00:00
|
|
|
return -1;
|
2009-10-18 02:38:27 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2012-08-08 13:05:17 +00:00
|
|
|
tableFrame->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx);
|
2012-06-23 22:34:48 +00:00
|
|
|
return rowIdx;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 22:34:48 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
|
|
|
|
int32_t* aColIdx)
|
2010-07-03 03:16:52 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (tableFrame)
|
|
|
|
tableFrame->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
|
2010-07-03 03:16:52 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
|
|
|
HTMLTableAccessible::ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-05-30 00:51:08 +00:00
|
|
|
return 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
return tableFrame->GetEffectiveColSpanAt(aRowIdx, aColIdx);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
|
|
|
HTMLTableAccessible::RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-05-30 00:51:08 +00:00
|
|
|
return 0;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
return tableFrame->GetEffectiveRowSpanAt(aRowIdx, aColIdx);
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 08:03:51 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::IsColSelected(uint32_t aColIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-06-15 08:03:51 +00:00
|
|
|
bool isSelected = false;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t rowCount = RowCount();
|
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
2012-06-15 08:03:51 +00:00
|
|
|
isSelected = IsCellSelected(rowIdx, aColIdx);
|
|
|
|
if (!isSelected)
|
|
|
|
return false;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 08:03:51 +00:00
|
|
|
return isSelected;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 08:03:51 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::IsRowSelected(uint32_t aRowIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-06-15 08:03:51 +00:00
|
|
|
bool isSelected = false;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t colCount = ColCount();
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) {
|
2012-06-15 08:03:51 +00:00
|
|
|
isSelected = IsCellSelected(aRowIdx, colIdx);
|
|
|
|
if (!isSelected)
|
|
|
|
return false;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 08:03:51 +00:00
|
|
|
return isSelected;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 08:03:51 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 15:42:09 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
2012-06-15 08:03:51 +00:00
|
|
|
return false;
|
2006-06-27 15:42:09 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(aRowIdx, aColIdx);
|
|
|
|
return cellFrame ? cellFrame->IsSelected() : false;
|
2006-06-27 15:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 05:25:07 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::SelectRow(uint32_t aRowIdx)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2013-03-12 20:08:29 +00:00
|
|
|
DebugOnly<nsresult> rv =
|
2012-06-15 08:03:51 +00:00
|
|
|
RemoveRowsOrColumnsFromSelection(aRowIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
true);
|
2012-06-11 05:25:07 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveRowsOrColumnsFromSelection() Shouldn't fail!");
|
2009-09-10 03:06:54 +00:00
|
|
|
|
2012-06-11 05:25:07 +00:00
|
|
|
AddRowOrColumnToSelection(aRowIdx, nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 05:25:07 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::SelectCol(uint32_t aColIdx)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2013-03-12 20:08:29 +00:00
|
|
|
DebugOnly<nsresult> rv =
|
2012-06-15 08:03:51 +00:00
|
|
|
RemoveRowsOrColumnsFromSelection(aColIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
true);
|
2012-06-11 05:25:07 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveRowsOrColumnsFromSelection() Shouldn't fail!");
|
2009-09-10 03:06:54 +00:00
|
|
|
|
2012-06-11 05:25:07 +00:00
|
|
|
AddRowOrColumnToSelection(aColIdx, nsISelectionPrivate::TABLESELECTION_COLUMN);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 11:19:59 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::UnselectRow(uint32_t aRowIdx)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2012-04-26 11:19:59 +00:00
|
|
|
RemoveRowsOrColumnsFromSelection(aRowIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
false);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 11:19:59 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::UnselectCol(uint32_t aColIdx)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2012-04-26 11:19:59 +00:00
|
|
|
RemoveRowsOrColumnsFromSelection(aColIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
false);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
|
|
|
return NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
uint32_t count = 0;
|
2009-09-10 03:06:54 +00:00
|
|
|
if (doSelectRow)
|
2012-08-08 13:05:17 +00:00
|
|
|
count = ColCount();
|
2009-09-10 03:06:54 +00:00
|
|
|
else
|
2012-08-08 13:05:17 +00:00
|
|
|
count = RowCount();
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2012-02-07 22:38:54 +00:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2009-09-10 03:06:54 +00:00
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
|
|
|
|
2012-08-08 13:05:17 +00:00
|
|
|
for (uint32_t idx = 0; idx < count; idx++) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIdx = doSelectRow ? aIndex : idx;
|
|
|
|
int32_t colIdx = doSelectRow ? idx : aIndex;
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx);
|
|
|
|
if (cellFrame && !cellFrame->IsSelected()) {
|
|
|
|
nsresult rv = tableSelection->SelectCellElement(cellFrame->GetContent());
|
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
|
|
|
|
2007-05-12 02:21:10 +00:00
|
|
|
return NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLTableAccessible::RemoveRowsOrColumnsFromSelection(int32_t aIndex,
|
|
|
|
uint32_t aTarget,
|
2012-06-07 12:47:49 +00:00
|
|
|
bool aIsOuter)
|
2007-05-11 12:21:43 +00:00
|
|
|
{
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
|
|
|
return NS_OK;
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2012-02-07 22:38:54 +00:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2009-09-10 03:06:54 +00:00
|
|
|
nsRefPtr<nsFrameSelection> tableSelection =
|
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
2007-05-11 12:21:43 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2012-08-08 13:05:17 +00:00
|
|
|
uint32_t count = doUnselectRow ? ColCount() : RowCount();
|
2009-09-10 03:06:54 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t startRowIdx = doUnselectRow ? aIndex : 0;
|
|
|
|
int32_t endRowIdx = doUnselectRow ? aIndex : count - 1;
|
|
|
|
int32_t startColIdx = doUnselectRow ? 0 : aIndex;
|
|
|
|
int32_t endColIdx = doUnselectRow ? count - 1 : aIndex;
|
2009-09-10 03:06:54 +00:00
|
|
|
|
|
|
|
if (aIsOuter)
|
2010-06-11 08:23:18 +00:00
|
|
|
return tableSelection->RestrictCellsToSelection(mContent,
|
2012-05-30 00:51:08 +00:00
|
|
|
startRowIdx, startColIdx,
|
2009-09-10 03:06:54 +00:00
|
|
|
endRowIdx, endColIdx);
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
return tableSelection->RemoveCellsFromSelection(mContent,
|
2012-05-30 00:51:08 +00:00
|
|
|
startRowIdx, startColIdx,
|
2009-09-10 03:06:54 +00:00
|
|
|
endRowIdx, endColIdx);
|
2007-05-11 12:21:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-23 13:14:05 +00:00
|
|
|
void
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::Description(nsString& aDescription)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
|
|
|
// Helpful for debugging layout vs. data tables
|
|
|
|
aDescription.Truncate();
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible::Description(aDescription);
|
2011-04-23 13:14:05 +00:00
|
|
|
if (!aDescription.IsEmpty())
|
|
|
|
return;
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-06-24 04:01:45 +00:00
|
|
|
// Use summary as description if it weren't used as a name.
|
|
|
|
// XXX: get rid code duplication with NameInternal().
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* caption = Caption();
|
2011-06-24 04:01:45 +00:00
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsAutoString captionText;
|
2011-04-23 13:14:05 +00:00
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
|
2011-06-24 04:01:45 +00:00
|
|
|
&captionText);
|
|
|
|
|
|
|
|
if (!captionText.IsEmpty()) { // summary isn't used as a name.
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary,
|
2011-06-24 04:01:45 +00:00
|
|
|
aDescription);
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 15:39:29 +00:00
|
|
|
}
|
2011-06-24 04:01:45 +00:00
|
|
|
|
2007-07-05 15:39:29 +00:00
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
if (aDescription.IsEmpty()) {
|
2012-03-28 00:53:58 +00:00
|
|
|
bool isProbablyForLayout = IsProbablyLayoutTable();
|
2007-07-05 15:39:29 +00:00
|
|
|
aDescription = mLayoutHeuristic;
|
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::HasDescendant(const nsAString& aTagName, bool aAllowEmpty)
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mContent));
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(tableElt, false);
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2012-09-26 14:17:47 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> nodeList;
|
2009-07-08 02:39:04 +00:00
|
|
|
tableElt->GetElementsByTagName(aTagName, getter_AddRefs(nodeList));
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(nodeList, false);
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> foundItem;
|
|
|
|
nodeList->Item(0, getter_AddRefs(foundItem));
|
|
|
|
if (!foundItem)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
if (aAllowEmpty)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-07-08 02:39:04 +00:00
|
|
|
|
|
|
|
// Make sure that the item we found has contents and either has multiple
|
|
|
|
// children or the found item is not a whitespace-only text node.
|
|
|
|
nsCOMPtr<nsIContent> foundItemContent = do_QueryInterface(foundItem);
|
|
|
|
if (foundItemContent->GetChildCount() > 1)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true; // Treat multiple child nodes as non-empty
|
2009-07-08 02:39:04 +00:00
|
|
|
|
2012-01-25 07:50:07 +00:00
|
|
|
nsIContent *innerItemContent = foundItemContent->GetFirstChild();
|
2009-07-08 02:39:04 +00:00
|
|
|
if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
// If we found more than one node then return true not depending on
|
|
|
|
// aAllowEmpty flag.
|
|
|
|
// XXX it might be dummy but bug 501375 where we changed this addresses
|
|
|
|
// performance problems only. Note, currently 'aAllowEmpty' flag is used for
|
|
|
|
// caption element only. On another hand we create accessible object for
|
|
|
|
// the first entry of caption element (see
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLTableAccessible::CacheChildren).
|
2009-07-08 02:39:04 +00:00
|
|
|
nodeList->Item(1, getter_AddRefs(foundItem));
|
|
|
|
return !!foundItem;
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 00:53:58 +00:00
|
|
|
bool
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLTableAccessible::IsProbablyLayoutTable()
|
2006-07-24 14:26:25 +00:00
|
|
|
{
|
|
|
|
// Implement a heuristic to determine if table is most likely used for layout
|
|
|
|
// XXX do we want to look for rowspan or colspan, especialy that span all but a couple cells
|
|
|
|
// at the beginning or end of a row/col, and especially when they occur at the edge of a table?
|
|
|
|
// XXX expose this info via object attributes to AT-SPI
|
|
|
|
|
|
|
|
// XXX For now debugging descriptions are always on via SHOW_LAYOUT_HEURISTIC
|
|
|
|
// This will allow release trunk builds to be used by testers to refine the algorithm
|
|
|
|
// Change to |#define SHOW_LAYOUT_HEURISTIC DEBUG| before final release
|
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) \
|
2012-03-28 00:53:58 +00:00
|
|
|
{ \
|
|
|
|
mLayoutHeuristic = isLayout ? \
|
|
|
|
NS_LITERAL_STRING("layout table: " heuristic) : \
|
|
|
|
NS_LITERAL_STRING("data table: " heuristic); \
|
|
|
|
return isLayout; \
|
|
|
|
}
|
2006-07-24 14:26:25 +00:00
|
|
|
#else
|
2012-03-28 00:53:58 +00:00
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { return isLayout; }
|
2006-07-24 14:26:25 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-27 09:01:40 +00:00
|
|
|
DocAccessible* docAccessible = Document();
|
2007-04-13 11:38:43 +00:00
|
|
|
if (docAccessible) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t docState = docAccessible->State();
|
2011-04-09 23:38:06 +00:00
|
|
|
if (docState & states::EDITABLE) { // Need to see all elements while document is being edited
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "In editable document");
|
2007-04-13 11:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:21:09 +00:00
|
|
|
// Check to see if an ARIA role overrides the role from native markup,
|
|
|
|
// but for which we still expose table semantics (treegrid, for example).
|
2012-05-30 00:51:08 +00:00
|
|
|
if (Role() != roles::TABLE)
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute");
|
2006-07-24 14:26:25 +00:00
|
|
|
|
2011-06-03 21:35:17 +00:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::role)) {
|
2009-07-03 13:21:09 +00:00
|
|
|
// Role attribute is present, but overridden roles have already been dealt with.
|
|
|
|
// Only landmarks and other roles that don't override the role from native
|
|
|
|
// markup are left to deal with here.
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute, weak role, and role is table");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2011-10-01 01:09:31 +00:00
|
|
|
|
2011-11-07 09:05:51 +00:00
|
|
|
if (mContent->Tag() != nsGkAtoms::table)
|
|
|
|
RETURN_LAYOUT_ANSWER(true, "table built by CSS display:table style");
|
|
|
|
|
2011-10-19 01:36:35 +00:00
|
|
|
// Check if datatable attribute has "0" value.
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::datatable,
|
|
|
|
NS_LITERAL_STRING("0"), eCaseMatters)) {
|
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has datatable = 0 attribute, it's for layout");
|
|
|
|
}
|
|
|
|
|
2011-10-01 01:09:31 +00:00
|
|
|
// Check for legitimate data table attributes.
|
2007-04-10 13:29:31 +00:00
|
|
|
nsAutoString summary;
|
2011-10-01 01:09:31 +00:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, summary) &&
|
|
|
|
!summary.IsEmpty())
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has summary -- legitimate table structures");
|
|
|
|
|
|
|
|
// Check for legitimate data table elements.
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* caption = FirstChild();
|
2012-01-12 03:07:35 +00:00
|
|
|
if (caption && caption->Role() == roles::CAPTION && caption->HasChildren())
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "Not empty caption -- legitimate table structures");
|
2011-10-01 01:09:31 +00:00
|
|
|
|
2011-10-01 03:53:57 +00:00
|
|
|
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
|
|
|
childElm = childElm->GetNextSibling()) {
|
2011-10-01 01:09:31 +00:00
|
|
|
if (!childElm->IsHTML())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (childElm->Tag() == nsGkAtoms::col ||
|
|
|
|
childElm->Tag() == nsGkAtoms::colgroup ||
|
|
|
|
childElm->Tag() == nsGkAtoms::tfoot ||
|
|
|
|
childElm->Tag() == nsGkAtoms::thead) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Has col, colgroup, tfoot or thead -- legitimate table structures");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childElm->Tag() == nsGkAtoms::tbody) {
|
2011-10-01 03:53:57 +00:00
|
|
|
for (nsIContent* rowElm = childElm->GetFirstChild(); rowElm;
|
|
|
|
rowElm = rowElm->GetNextSibling()) {
|
2011-10-01 01:09:31 +00:00
|
|
|
if (rowElm->IsHTML() && rowElm->Tag() == nsGkAtoms::tr) {
|
2011-10-01 03:53:57 +00:00
|
|
|
for (nsIContent* cellElm = rowElm->GetFirstChild(); cellElm;
|
|
|
|
cellElm = cellElm->GetNextSibling()) {
|
2012-03-12 17:54:21 +00:00
|
|
|
if (cellElm->IsHTML()) {
|
2012-05-30 00:51:08 +00:00
|
|
|
|
2012-03-12 17:54:21 +00: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-29 01:18:45 +00:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellElm);
|
2012-05-25 10:53:45 +00:00
|
|
|
if (cell && cell->ChildCount() == 1 &&
|
2012-03-12 17:54:21 +00:00
|
|
|
cell->FirstChild()->IsAbbreviation()) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"has abbr -- legitimate table structures");
|
|
|
|
}
|
2011-10-01 01:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("table"))) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has a nested table within it");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2012-01-12 03:07:35 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
// If only 1 column or only 1 row, it's for layout
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t columns, rows;
|
2009-09-11 01:07:56 +00:00
|
|
|
GetColumnCount(&columns);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (columns <=1) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 column");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2009-09-11 01:07:56 +00:00
|
|
|
GetRowCount(&rows);
|
2006-07-24 14:26:25 +00:00
|
|
|
if (rows <=1) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 row");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many columns
|
|
|
|
if (columns >= 5) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">=5 columns");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
2012-01-12 03:07:35 +00:00
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
// Now we know there are 2-4 columns and 2 or more rows
|
|
|
|
// Check to see if there are visible borders on the cells
|
|
|
|
// XXX currently, we just check the first cell -- do we really need to do more?
|
2012-08-08 13:05:17 +00:00
|
|
|
nsTableOuterFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (!tableFrame)
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "table with no frame!");
|
|
|
|
|
|
|
|
nsIFrame* cellFrame = tableFrame->GetCellFrameAt(0, 0);
|
|
|
|
if (!cellFrame)
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "table's first cell has no frame!");
|
|
|
|
|
2006-07-24 14:26:25 +00:00
|
|
|
nsMargin border;
|
|
|
|
cellFrame->GetBorder(border);
|
|
|
|
if (border.top && border.bottom && border.left && border.right) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
|
|
|
|
*/
|
|
|
|
|
2012-02-17 07:21:26 +00:00
|
|
|
// Check for styled background color across rows (alternating background
|
|
|
|
// color is a common feature for data tables).
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t childCount = ChildCount();
|
2012-06-18 20:14:01 +00:00
|
|
|
nscolor rowColor = 0;
|
|
|
|
nscolor prevRowColor;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
2012-02-17 07:21:26 +00:00
|
|
|
if (child->Role() == roles::ROW) {
|
2012-03-04 02:29:25 +00:00
|
|
|
prevRowColor = rowColor;
|
|
|
|
nsIFrame* rowFrame = child->GetFrame();
|
2013-02-16 21:51:02 +00:00
|
|
|
rowColor = rowFrame->StyleBackground()->mBackgroundColor;
|
2012-03-04 02:29:25 +00:00
|
|
|
|
|
|
|
if (childIdx > 0 && prevRowColor != rowColor)
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many rows
|
2012-08-22 15:56:38 +00:00
|
|
|
const int32_t kMaxLayoutRows = 20;
|
2006-07-24 14:26:25 +00:00
|
|
|
if (rows > kMaxLayoutRows) { // A ton of rows, this is probably for data
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">= kMaxLayoutRows (20) and non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 09:18:48 +00:00
|
|
|
// Check for very wide table.
|
|
|
|
nsIFrame* documentFrame = Document()->GetFrame();
|
|
|
|
nsSize documentSize = documentFrame->GetSize();
|
|
|
|
if (documentSize.width > 0) {
|
|
|
|
nsSize tableSize = GetFrame()->GetSize();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t percentageOfDocWidth = (100 * tableSize.width) / documentSize.width;
|
2012-02-18 09:18:48 +00:00
|
|
|
if (percentageOfDocWidth > 95) {
|
|
|
|
// 3-4 columns, no borders, not a lot of rows, and 95% of the doc's width
|
|
|
|
// Probably for layout
|
|
|
|
RETURN_LAYOUT_ANSWER(true,
|
|
|
|
"<= 4 columns, table width is 95% of document width");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two column rules
|
|
|
|
if (rows * columns <= 10) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "2-4 columns, 10 cells or less, non-bordered");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 02:39:04 +00:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("embed")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("object")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("applet")) ||
|
|
|
|
HasDescendant(NS_LITERAL_STRING("iframe"))) {
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
2011-10-01 01:09:31 +00:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "no layout factor strong enough, so will guess data");
|
2006-07-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 12:47:49 +00:00
|
|
|
// HTMLCaptionAccessible
|
2009-09-11 01:07:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-03-07 15:38:58 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
Relation
|
2013-10-19 18:19:50 +00:00
|
|
|
HTMLCaptionAccessible::RelationByType(RelationType aType)
|
2007-07-05 15:39:29 +00:00
|
|
|
{
|
2012-05-31 08:04:41 +00:00
|
|
|
Relation rel = HyperTextAccessible::RelationByType(aType);
|
2013-10-19 18:19:50 +00:00
|
|
|
if (aType == RelationType::LABEL_FOR)
|
2011-08-10 01:44:00 +00:00
|
|
|
rel.AppendTarget(Parent());
|
2007-07-05 15:39:29 +00:00
|
|
|
|
2011-08-10 01:44:00 +00:00
|
|
|
return rel;
|
2007-07-05 15:39:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2012-06-07 12:47:49 +00:00
|
|
|
HTMLCaptionAccessible::NativeRole()
|
2009-03-07 15:38:58 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::CAPTION;
|
2009-03-07 15:38:58 +00:00
|
|
|
}
|