2001-09-25 04:48:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 05:31:28 +03:00
|
|
|
|
2012-06-07 16:47:49 +04:00
|
|
|
#include "HTMLTableAccessible.h"
|
2010-03-17 09:02:28 +03:00
|
|
|
|
2013-02-14 19:33:16 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsTextEquivUtils.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Relation.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2012-11-19 13:20:09 +04:00
|
|
|
#include "TreeWalker.h"
|
2010-03-17 09:02:28 +03:00
|
|
|
|
2013-02-14 19:33:16 +04:00
|
|
|
#include "mozilla/dom/HTMLTableElement.h"
|
2003-04-15 12:45:55 +04:00
|
|
|
#include "nsIDOMElement.h"
|
2007-05-11 16:21:43 +04:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsIDOMNodeList.h"
|
2006-06-27 19:42:09 +04:00
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDocument.h"
|
2012-11-19 13:20:09 +04:00
|
|
|
#include "nsIMutableArray.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2006-06-27 19:42:09 +04:00
|
|
|
#include "nsIPresShell.h"
|
2007-04-20 10:11:14 +04:00
|
|
|
#include "nsITableCellLayout.h"
|
2009-09-10 07:06:54 +04:00
|
|
|
#include "nsFrameSelection.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2009-09-11 05:07:56 +04:00
|
|
|
#include "nsArrayUtils.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2012-08-08 17:05:17 +04:00
|
|
|
#include "nsTableCellFrame.h"
|
2016-06-16 15:14:08 +03:00
|
|
|
#include "nsTableWrapperFrame.h"
|
2006-06-27 19:42:09 +04:00
|
|
|
|
2012-07-22 14:35:49 +04:00
|
|
|
using namespace mozilla;
|
2014-06-17 02:50:15 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-04-15 07:38:31 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLTableCellAccessible
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableCellAccessible::
|
|
|
|
HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2014-10-22 04:49:28 +04:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2015-02-14 04:09:51 +03:00
|
|
|
mType = eHTMLTableCellType;
|
2013-07-18 19:09:45 +04:00
|
|
|
mGenericTypes |= eTableCell;
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
2003-03-24 05:09:55 +03:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableCellAccessible, HyperTextAccessible)
|
2001-03-04 05:31:28 +03:00
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLTableCellAccessible: Accessible implementation
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableCellAccessible::NativeRole()
|
2001-03-04 05:31:28 +03:00
|
|
|
{
|
2015-03-19 19:45:59 +03:00
|
|
|
if (mContent->IsMathMLElement(nsGkAtoms::mtd_)) {
|
|
|
|
return roles::MATHML_CELL;
|
|
|
|
}
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::CELL;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
2001-03-04 05:31:28 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableCellAccessible::NativeState()
|
2009-07-08 06:37:43 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::NativeState();
|
2009-07-08 06:37:43 +04:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
nsIFrame *frame = mContent->GetPrimaryFrame();
|
2009-07-08 06:37:43 +04:00
|
|
|
NS_ASSERTION(frame, "No frame for valid cell accessible!");
|
|
|
|
|
2012-06-04 09:41:06 +04:00
|
|
|
if (frame && frame->IsSelected())
|
|
|
|
state |= states::SELECTED;
|
2009-07-08 06:37:43 +04:00
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
return state;
|
2009-07-08 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableCellAccessible::NativeInteractiveState() const
|
2012-06-04 09:41:06 +04:00
|
|
|
{
|
|
|
|
return HyperTextAccessibleWrap::NativeInteractiveState() | states::SELECTABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HTMLTableCellAccessible::NativeAttributes()
|
2008-04-15 07:38:31 +04:00
|
|
|
{
|
2012-10-19 11:15:23 +04:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
HyperTextAccessibleWrap::NativeAttributes();
|
2008-04-15 07:38:31 +04:00
|
|
|
|
2011-11-24 15:31:34 +04:00
|
|
|
// table-cell-index attribute
|
2012-08-09 10:24:31 +04:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
if (!table)
|
2012-10-19 11:15:23 +04:00
|
|
|
return attributes.forget();
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2012-10-19 11:15:23 +04:00
|
|
|
nsresult rv = GetCellIndexes(rowIdx, colIdx);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return attributes.forget();
|
2009-05-14 09:31:09 +04:00
|
|
|
|
|
|
|
nsAutoString stringIdx;
|
2012-08-09 10:24:31 +04:00
|
|
|
stringIdx.AppendInt(table->CellIndexAt(rowIdx, colIdx));
|
2012-10-19 11:15:23 +04:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::tableCellIndex, stringIdx);
|
2011-11-24 15:31:34 +04: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 14:53:45 +04:00
|
|
|
if (ChildCount() == 1) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* abbr = FirstChild();
|
2011-11-24 15:31:34 +04:00
|
|
|
if (abbr->IsAbbreviation()) {
|
2012-12-07 21:27:17 +04:00
|
|
|
nsIContent* firstChildNode = abbr->GetContent()->GetFirstChild();
|
|
|
|
if (firstChildNode) {
|
|
|
|
nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromTextContent(firstChildNode, &abbrText);
|
|
|
|
}
|
2011-11-24 15:31:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (abbrText.IsEmpty())
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::abbr, abbrText);
|
|
|
|
|
|
|
|
if (!abbrText.IsEmpty())
|
2012-10-19 11:15:23 +04:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::abbr, abbrText);
|
2011-11-24 15:31:34 +04:00
|
|
|
|
2011-11-24 15:31:41 +04:00
|
|
|
// axis attribute
|
|
|
|
nsAutoString axisText;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText);
|
|
|
|
if (!axisText.IsEmpty())
|
2012-10-19 11:15:23 +04:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::axis, axisText);
|
2011-11-24 15:31:41 +04:00
|
|
|
|
2015-02-14 04:09:51 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsAutoString unused;
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("cppclass"),
|
|
|
|
NS_LITERAL_STRING("HTMLTableCellAccessible"),
|
|
|
|
unused);
|
|
|
|
#endif
|
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
return attributes.forget();
|
2009-05-14 09:31:09 +04:00
|
|
|
}
|
|
|
|
|
2015-06-27 00:41:22 +03:00
|
|
|
GroupPos
|
|
|
|
HTMLTableCellAccessible::GroupPosition()
|
|
|
|
{
|
|
|
|
int32_t count = 0, index = 0;
|
2015-08-28 17:52:21 +03:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
if (table && nsCoreUtils::GetUIntAttr(table->AsAccessible()->GetContent(),
|
2015-08-19 03:38:24 +03:00
|
|
|
nsGkAtoms::aria_colcount, &count) &&
|
2015-06-27 00:41:22 +03:00
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_colindex, &index)) {
|
|
|
|
return GroupPos(0, index, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return HyperTextAccessibleWrap::GroupPosition();
|
|
|
|
}
|
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-22 04:49:28 +04:00
|
|
|
// HTMLTableCellAccessible: TableCellAccessible implementation
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
TableAccessible*
|
|
|
|
HTMLTableCellAccessible::Table() const
|
2009-05-14 09:31:09 +04:00
|
|
|
{
|
2012-08-09 10:24:31 +04:00
|
|
|
Accessible* parent = const_cast<HTMLTableCellAccessible*>(this);
|
|
|
|
while ((parent = parent->Parent())) {
|
2015-03-19 19:45:59 +03:00
|
|
|
if (parent->IsTable())
|
2012-08-09 10:24:31 +04:00
|
|
|
return parent->AsTable();
|
|
|
|
}
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
return nullptr;
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::ColIdx() const
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
2012-08-09 10:24:31 +04:00
|
|
|
NS_ENSURE_TRUE(cellLayout, 0);
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
int32_t colIdx = 0;
|
|
|
|
cellLayout->GetColIndex(colIdx);
|
|
|
|
return colIdx > 0 ? static_cast<uint32_t>(colIdx) : 0;
|
2009-05-14 09:31:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::RowIdx() const
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
|
|
|
nsITableCellLayout* cellLayout = GetCellLayout();
|
2012-08-09 10:24:31 +04:00
|
|
|
NS_ENSURE_TRUE(cellLayout, 0);
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
int32_t rowIdx = 0;
|
|
|
|
cellLayout->GetRowIndex(rowIdx);
|
|
|
|
return rowIdx > 0 ? static_cast<uint32_t>(rowIdx) : 0;
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::ColExtent() const
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2009-09-11 05:07:56 +04:00
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
NS_ASSERTION(table, "cell not in a table!");
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
return table->ColExtentAt(rowIdx, colIdx);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLTableCellAccessible::RowExtent() const
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2009-09-11 05:07:56 +04:00
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
NS_ASSERTION(table, "cell not in atable!");
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
return table->RowExtentAt(rowIdx, colIdx);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
void
|
|
|
|
HTMLTableCellAccessible::ColHeaderCells(nsTArray<Accessible*>* aCells)
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2012-08-09 10:24:31 +04:00
|
|
|
IDRefsIterator itr(mDoc, mContent, nsGkAtoms::headers);
|
2013-06-04 09:48:44 +04:00
|
|
|
while (Accessible* cell = itr.Next()) {
|
|
|
|
a11y::role cellRole = cell->Role();
|
|
|
|
if (cellRole == roles::COLUMNHEADER) {
|
2012-08-09 10:24:31 +04:00
|
|
|
aCells->AppendElement(cell);
|
2013-06-04 09:48:44 +04: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 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
if (aCells->IsEmpty())
|
|
|
|
TableCellAccessible::ColHeaderCells(aCells);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
void
|
|
|
|
HTMLTableCellAccessible::RowHeaderCells(nsTArray<Accessible*>* aCells)
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2012-08-09 10:24:31 +04:00
|
|
|
IDRefsIterator itr(mDoc, mContent, nsGkAtoms::headers);
|
2013-06-04 09:48:44 +04:00
|
|
|
while (Accessible* cell = itr.Next()) {
|
|
|
|
a11y::role cellRole = cell->Role();
|
|
|
|
if (cellRole == roles::ROWHEADER) {
|
2012-08-09 10:24:31 +04:00
|
|
|
aCells->AppendElement(cell);
|
2013-06-04 09:48:44 +04: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 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
if (aCells->IsEmpty())
|
|
|
|
TableCellAccessible::RowHeaderCells(aCells);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
bool
|
|
|
|
HTMLTableCellAccessible::Selected()
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2009-09-11 05:07:56 +04:00
|
|
|
GetCellIndexes(rowIdx, colIdx);
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
NS_ENSURE_TRUE(table, false);
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
return table->IsCellSelected(rowIdx, colIdx);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLTableCellAccessible: protected implementation
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
nsITableCellLayout*
|
2012-08-09 10:24:31 +04:00
|
|
|
HTMLTableCellAccessible::GetCellLayout() const
|
2009-05-14 09:31:09 +04:00
|
|
|
{
|
2012-08-09 10:24:31 +04:00
|
|
|
return do_QueryFrame(mContent->GetPrimaryFrame());
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-09 10:24:31 +04:00
|
|
|
HTMLTableCellAccessible::GetCellIndexes(int32_t& aRowIdx, int32_t& aColIdx) const
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
|
|
|
nsITableCellLayout *cellLayout = GetCellLayout();
|
2008-04-15 07:38:31 +04:00
|
|
|
NS_ENSURE_STATE(cellLayout);
|
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
return cellLayout->GetCellIndexes(aRowIdx, aColIdx);
|
2009-05-14 09:31:09 +04:00
|
|
|
}
|
2008-04-15 07:38:31 +04:00
|
|
|
|
2009-05-14 09:31:09 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLTableHeaderCellAccessible
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableHeaderCellAccessible::
|
|
|
|
HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
|
|
|
HTMLTableCellAccessible(aContent, aDoc)
|
2009-05-14 09:31:09 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLTableHeaderCellAccessible: Accessible implementation
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableHeaderCellAccessible::NativeRole()
|
2009-05-14 09:31:09 +04:00
|
|
|
{
|
|
|
|
// Check value of @scope attribute.
|
|
|
|
static nsIContent::AttrValuesArray scopeValues[] =
|
2015-03-23 18:51:33 +03:00
|
|
|
{ &nsGkAtoms::col, &nsGkAtoms::colgroup,
|
|
|
|
&nsGkAtoms::row, &nsGkAtoms::rowgroup, nullptr };
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t valueIdx =
|
2011-06-04 01:35:17 +04:00
|
|
|
mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::scope,
|
2010-06-11 12:23:18 +04:00
|
|
|
scopeValues, eCaseMatters);
|
2009-05-14 09:31:09 +04:00
|
|
|
|
|
|
|
switch (valueIdx) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2015-03-23 18:51:33 +03:00
|
|
|
return roles::COLUMNHEADER;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::ROWHEADER;
|
2009-05-14 09:31:09 +04:00
|
|
|
}
|
|
|
|
|
2015-03-26 15:05:06 +03:00
|
|
|
TableAccessible* table = Table();
|
|
|
|
if (!table)
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::NOTHING;
|
2008-04-15 07:38:31 +04:00
|
|
|
|
2015-03-26 15:05:06 +03:00
|
|
|
// If the cell next to this one is not a header cell then assume this cell is
|
|
|
|
// a row header for it.
|
|
|
|
uint32_t rowIdx = RowIdx(), colIdx = ColIdx();
|
|
|
|
Accessible* cell = table->CellAt(rowIdx, colIdx + ColExtent());
|
|
|
|
if (cell && !nsCoreUtils::IsHTMLTableHeader(cell->GetContent()))
|
|
|
|
return roles::ROWHEADER;
|
|
|
|
|
|
|
|
// If the cell below this one is not a header cell then assume this cell is
|
|
|
|
// a column header for it.
|
|
|
|
uint32_t rowExtent = RowExtent();
|
|
|
|
cell = table->CellAt(rowIdx + rowExtent, colIdx);
|
|
|
|
if (cell && !nsCoreUtils::IsHTMLTableHeader(cell->GetContent()))
|
|
|
|
return roles::COLUMNHEADER;
|
|
|
|
|
|
|
|
// Otherwise if this cell is surrounded by header cells only then make a guess
|
|
|
|
// based on its cell spanning. In other words if it is row spanned then assume
|
|
|
|
// it's a row header, otherwise it's a column header.
|
|
|
|
return rowExtent > 1 ? roles::ROWHEADER : roles::COLUMNHEADER;
|
2008-04-15 07:38:31 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 11:33:01 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLTableRowAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableRowAccessible, Accessible)
|
|
|
|
|
|
|
|
role
|
|
|
|
HTMLTableRowAccessible::NativeRole()
|
|
|
|
{
|
2015-03-19 19:45:59 +03:00
|
|
|
if (mContent->IsMathMLElement(nsGkAtoms::mtr_)) {
|
|
|
|
return roles::MATHML_TABLE_ROW;
|
|
|
|
} else if (mContent->IsMathMLElement(nsGkAtoms::mlabeledtr_)) {
|
|
|
|
return roles::MATHML_LABELED_ROW;
|
|
|
|
}
|
2012-11-30 11:33:01 +04:00
|
|
|
return roles::ROW;
|
|
|
|
}
|
|
|
|
|
2015-06-27 00:41:22 +03:00
|
|
|
GroupPos
|
|
|
|
HTMLTableRowAccessible::GroupPosition()
|
|
|
|
{
|
|
|
|
int32_t count = 0, index = 0;
|
2015-07-14 10:27:26 +03:00
|
|
|
Accessible* table = nsAccUtils::TableFor(this);
|
|
|
|
if (table && nsCoreUtils::GetUIntAttr(table->GetContent(),
|
|
|
|
nsGkAtoms::aria_rowcount, &count) &&
|
2015-06-27 00:41:22 +03:00
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_rowindex, &index)) {
|
|
|
|
return GroupPos(0, index, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return AccessibleWrap::GroupPosition();
|
|
|
|
}
|
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLTableAccessible
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableAccessible, Accessible)
|
2002-06-07 08:15:18 +04:00
|
|
|
|
2012-03-28 04:53:58 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-10-29 07:30:55 +04:00
|
|
|
// HTMLTableAccessible: Accessible
|
2012-03-28 04:53:58 +04:00
|
|
|
|
2016-03-01 18:54:49 +03:00
|
|
|
bool
|
|
|
|
HTMLTableAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild)
|
2007-03-27 12:43:00 +04:00
|
|
|
{
|
2010-07-02 05:22:41 +04: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.
|
2016-03-01 18:54:49 +03:00
|
|
|
return Accessible::InsertChildAt(aChild->IsHTMLCaption() ? 0 : aIndex, aChild);
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
2001-03-04 05:31:28 +03:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::NativeRole()
|
2001-05-12 01:11:38 +04:00
|
|
|
{
|
2015-03-19 19:45:59 +03:00
|
|
|
if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) {
|
|
|
|
return roles::MATHML_TABLE;
|
|
|
|
}
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::TABLE;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
2001-03-04 05:31:28 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::NativeState()
|
2001-12-12 00:42:58 +03:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
return Accessible::NativeState() | states::READONLY;
|
2001-12-12 00:42:58 +03:00
|
|
|
}
|
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
ENameValueFlag
|
|
|
|
HTMLTableAccessible::NativeName(nsString& aName)
|
2001-12-12 00:42:58 +03:00
|
|
|
{
|
2012-10-17 10:38:16 +04:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
2011-06-24 08:01:45 +04:00
|
|
|
if (!aName.IsEmpty())
|
2012-10-17 10:38:16 +04:00
|
|
|
return nameFlag;
|
2005-06-01 18:03:38 +04:00
|
|
|
|
2011-06-24 08:01:45 +04:00
|
|
|
// Use table caption as a name.
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* caption = Caption();
|
2011-06-24 08:01:45 +04:00
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
|
|
|
|
if (!aName.IsEmpty())
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2011-06-24 08:01:45 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 19:39:29 +04:00
|
|
|
|
2011-06-24 08:01:45 +04:00
|
|
|
// If no caption then use summary as a name.
|
2011-06-04 01:35:17 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2001-12-12 00:42:58 +03:00
|
|
|
}
|
2002-06-07 08:15:18 +04:00
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HTMLTableAccessible::NativeAttributes()
|
2006-09-12 23:37:36 +04:00
|
|
|
{
|
2012-10-19 11:15:23 +04:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
AccessibleWrap::NativeAttributes();
|
2015-03-19 19:45:59 +03:00
|
|
|
|
|
|
|
if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) {
|
|
|
|
GetAccService()->MarkupAttributes(mContent, attributes);
|
|
|
|
}
|
|
|
|
|
2012-03-28 04:53:58 +04:00
|
|
|
if (IsProbablyLayoutTable()) {
|
2012-10-19 11:15:23 +04:00
|
|
|
nsAutoString unused;
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
|
|
|
|
NS_LITERAL_STRING("true"), unused);
|
2006-09-12 23:37:36 +04:00
|
|
|
}
|
2012-05-30 04:51:08 +04:00
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
return attributes.forget();
|
2006-09-12 23:37:36 +04:00
|
|
|
}
|
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-22 04:49:28 +04:00
|
|
|
// HTMLTableAccessible: Accessible
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
Relation
|
2013-10-19 22:19:50 +04:00
|
|
|
HTMLTableAccessible::RelationByType(RelationType aType)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
Relation rel = AccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABELLED_BY)
|
2011-08-10 05:44:00 +04:00
|
|
|
rel.AppendTarget(Caption());
|
2007-07-05 19:39:29 +04:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
return rel;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-22 04:49:28 +04:00
|
|
|
// HTMLTableAccessible: Table
|
2007-07-05 19:39:29 +04:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2014-09-16 21:30:23 +04:00
|
|
|
HTMLTableAccessible::Caption() const
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* child = mChildren.SafeElementAt(0, nullptr);
|
|
|
|
return child && child->Role() == roles::CAPTION ? child : nullptr;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-04-16 06:41:58 +04:00
|
|
|
void
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::Summary(nsString& aSummary)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2013-02-14 19:33:16 +04:00
|
|
|
dom::HTMLTableElement* table = dom::HTMLTableElement::FromContent(mContent);
|
2012-05-30 04:51:08 +04:00
|
|
|
|
2012-04-16 06:41:58 +04:00
|
|
|
if (table)
|
|
|
|
table->GetSummary(aSummary);
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::ColCount()
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
return tableFrame ? tableFrame->GetColCount() : 0;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::RowCount()
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
return tableFrame ? tableFrame->GetRowCount() : 0;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-20 22:05:31 +04:00
|
|
|
HTMLTableAccessible::SelectedCellCount()
|
2007-07-11 20:08:34 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-06-20 22:05:31 +04:00
|
|
|
return 0;
|
|
|
|
|
2012-08-22 19:56:38 +04: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 17:05:17 +04: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-18 00:54:44 +04:00
|
|
|
if (startRow >= 0 && (uint32_t)startRow == rowIdx &&
|
|
|
|
startCol >= 0 && (uint32_t)startCol == colIdx)
|
2012-06-20 22:05:31 +04:00
|
|
|
count++;
|
2007-07-11 20:08:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 22:05:31 +04:00
|
|
|
return count;
|
2007-07-11 20:08:34 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-20 22:05:31 +04:00
|
|
|
HTMLTableAccessible::SelectedColCount()
|
2007-07-11 20:08:34 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0, colCount = ColCount();
|
2007-07-11 20:08:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++)
|
2012-06-20 22:05:31 +04:00
|
|
|
if (IsColSelected(colIdx))
|
|
|
|
count++;
|
2007-07-11 20:08:34 +04:00
|
|
|
|
2012-06-20 22:05:31 +04:00
|
|
|
return count;
|
2007-07-11 20:08:34 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-20 22:05:31 +04:00
|
|
|
HTMLTableAccessible::SelectedRowCount()
|
2007-07-11 20:08:34 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0, rowCount = RowCount();
|
2007-07-11 20:08:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++)
|
2012-06-20 22:05:31 +04:00
|
|
|
if (IsRowSelected(rowIdx))
|
|
|
|
count++;
|
2007-07-11 20:08:34 +04:00
|
|
|
|
2012-06-20 22:05:31 +04:00
|
|
|
return count;
|
2007-07-11 20:08:34 +04:00
|
|
|
}
|
|
|
|
|
2012-06-29 12:14:22 +04:00
|
|
|
void
|
|
|
|
HTMLTableAccessible::SelectedCells(nsTArray<Accessible*>* aCells)
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-06-29 12:14:22 +04:00
|
|
|
return;
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
uint32_t rowCount = RowCount(), colCount = ColCount();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) {
|
2012-08-08 17:05:17 +04: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-18 00:54:44 +04:00
|
|
|
if ((startRow >= 0 && (uint32_t)startRow != rowIdx) ||
|
|
|
|
(startCol >= 0 && (uint32_t)startCol != colIdx))
|
2012-08-08 17:05:17 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Accessible* cell = mDoc->GetAccessible(cellFrame->GetContent());
|
2012-06-29 12:14:22 +04:00
|
|
|
aCells->AppendElement(cell);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-24 02:34:44 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::SelectedCellIndices(nsTArray<uint32_t>* aCells)
|
2007-07-11 20:08:34 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-06-24 02:34:44 +04:00
|
|
|
return;
|
|
|
|
|
2012-08-22 19:56:38 +04: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 17:05:17 +04: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-18 00:54:44 +04:00
|
|
|
if (startRow >= 0 && (uint32_t)startRow == rowIdx &&
|
|
|
|
startCol >= 0 && (uint32_t)startCol == colIdx)
|
2012-06-24 02:34:44 +04:00
|
|
|
aCells->AppendElement(CellIndexAt(rowIdx, colIdx));
|
2007-07-11 20:08:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-24 02:34:44 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::SelectedColIndices(nsTArray<uint32_t>* aCols)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t colCount = ColCount();
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++)
|
2012-06-24 02:34:44 +04:00
|
|
|
if (IsColSelected(colIdx))
|
|
|
|
aCols->AppendElement(colIdx);
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-24 02:34:44 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::SelectedRowIndices(nsTArray<uint32_t>* aRows)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rowCount = RowCount();
|
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++)
|
2012-06-24 02:34:44 +04:00
|
|
|
if (IsRowSelected(rowIdx))
|
|
|
|
aRows->AppendElement(rowIdx);
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2012-08-08 17:05:17 +04:00
|
|
|
HTMLTableAccessible::CellAt(uint32_t aRowIdx, uint32_t aColIdx)
|
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-12 19:59:44 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
nsIContent* cellContent = tableFrame->GetCellAt(aRowIdx, aColIdx);
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellContent);
|
2010-04-24 04:40:51 +04:00
|
|
|
|
2012-05-22 20:41:01 +04: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 18:20:58 +04:00
|
|
|
return cell == this ? nullptr : cell;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
HTMLTableAccessible::CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
|
|
|
return -1;
|
2009-06-29 14:54:26 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
return tableFrame->GetIndexByRowAndColumn(aRowIdx, aColIdx);
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
HTMLTableAccessible::ColIndexAt(uint32_t aCellIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-06-24 02:34:48 +04:00
|
|
|
return -1;
|
2009-10-18 06:38:27 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2012-08-08 17:05:17 +04:00
|
|
|
tableFrame->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx);
|
2012-06-24 02:34:48 +04:00
|
|
|
return colIdx;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
HTMLTableAccessible::RowIndexAt(uint32_t aCellIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-06-24 02:34:48 +04:00
|
|
|
return -1;
|
2009-10-18 06:38:27 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = -1, colIdx = -1;
|
2012-08-08 17:05:17 +04:00
|
|
|
tableFrame->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx);
|
2012-06-24 02:34:48 +04:00
|
|
|
return rowIdx;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-24 02:34:48 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
|
|
|
|
int32_t* aColIdx)
|
2010-07-03 07:16:52 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (tableFrame)
|
|
|
|
tableFrame->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
|
2010-07-03 07:16:52 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLTableAccessible::ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-05-30 04:51:08 +04:00
|
|
|
return 0;
|
2006-06-27 19:42:09 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
return tableFrame->GetEffectiveColSpanAt(aRowIdx, aColIdx);
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
|
|
|
HTMLTableAccessible::RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-05-30 04:51:08 +04:00
|
|
|
return 0;
|
2006-06-27 19:42:09 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
return tableFrame->GetEffectiveRowSpanAt(aRowIdx, aColIdx);
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 12:03:51 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::IsColSelected(uint32_t aColIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2012-06-15 12:03:51 +04:00
|
|
|
bool isSelected = false;
|
2006-06-27 19:42:09 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rowCount = RowCount();
|
|
|
|
for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) {
|
2012-06-15 12:03:51 +04:00
|
|
|
isSelected = IsCellSelected(rowIdx, aColIdx);
|
|
|
|
if (!isSelected)
|
|
|
|
return false;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 12:03:51 +04:00
|
|
|
return isSelected;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 12:03:51 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::IsRowSelected(uint32_t aRowIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2012-06-15 12:03:51 +04:00
|
|
|
bool isSelected = false;
|
2006-06-27 19:42:09 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t colCount = ColCount();
|
|
|
|
for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) {
|
2012-06-15 12:03:51 +04:00
|
|
|
isSelected = IsCellSelected(aRowIdx, colIdx);
|
|
|
|
if (!isSelected)
|
|
|
|
return false;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 12:03:51 +04:00
|
|
|
return isSelected;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 12:03:51 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx)
|
2006-06-27 19:42:09 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
2012-06-15 12:03:51 +04:00
|
|
|
return false;
|
2006-06-27 19:42:09 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(aRowIdx, aColIdx);
|
|
|
|
return cellFrame ? cellFrame->IsSelected() : false;
|
2006-06-27 19:42:09 +04:00
|
|
|
}
|
|
|
|
|
2012-06-11 09:25:07 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::SelectRow(uint32_t aRowIdx)
|
2007-05-11 16:21:43 +04:00
|
|
|
{
|
2013-03-13 00:08:29 +04:00
|
|
|
DebugOnly<nsresult> rv =
|
2012-06-15 12:03:51 +04:00
|
|
|
RemoveRowsOrColumnsFromSelection(aRowIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
true);
|
2012-06-11 09:25:07 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveRowsOrColumnsFromSelection() Shouldn't fail!");
|
2009-09-10 07:06:54 +04:00
|
|
|
|
2012-06-11 09:25:07 +04:00
|
|
|
AddRowOrColumnToSelection(aRowIdx, nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
|
|
|
|
2012-06-11 09:25:07 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::SelectCol(uint32_t aColIdx)
|
2007-05-11 16:21:43 +04:00
|
|
|
{
|
2013-03-13 00:08:29 +04:00
|
|
|
DebugOnly<nsresult> rv =
|
2012-06-15 12:03:51 +04:00
|
|
|
RemoveRowsOrColumnsFromSelection(aColIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
true);
|
2012-06-11 09:25:07 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"RemoveRowsOrColumnsFromSelection() Shouldn't fail!");
|
2009-09-10 07:06:54 +04:00
|
|
|
|
2012-06-11 09:25:07 +04:00
|
|
|
AddRowOrColumnToSelection(aColIdx, nsISelectionPrivate::TABLESELECTION_COLUMN);
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
|
|
|
|
2012-04-26 15:19:59 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::UnselectRow(uint32_t aRowIdx)
|
2007-05-11 16:21:43 +04:00
|
|
|
{
|
2012-04-26 15:19:59 +04:00
|
|
|
RemoveRowsOrColumnsFromSelection(aRowIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_ROW,
|
|
|
|
false);
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
|
|
|
|
2012-04-26 15:19:59 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::UnselectCol(uint32_t aColIdx)
|
2007-05-11 16:21:43 +04:00
|
|
|
{
|
2012-04-26 15:19:59 +04:00
|
|
|
RemoveRowsOrColumnsFromSelection(aColIdx,
|
|
|
|
nsISelectionPrivate::TABLESELECTION_COLUMN,
|
|
|
|
false);
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget)
|
2007-05-11 16:21:43 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2007-05-11 16:21:43 +04:00
|
|
|
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
|
|
|
return NS_OK;
|
2007-05-11 16:21:43 +04:00
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
uint32_t count = 0;
|
2009-09-10 07:06:54 +04:00
|
|
|
if (doSelectRow)
|
2012-08-08 17:05:17 +04:00
|
|
|
count = ColCount();
|
2009-09-10 07:06:54 +04:00
|
|
|
else
|
2012-08-08 17:05:17 +04:00
|
|
|
count = RowCount();
|
2007-05-11 16:21:43 +04:00
|
|
|
|
2012-02-08 02:38:54 +04:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> tableSelection =
|
2009-09-10 07:06:54 +04:00
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
|
|
|
|
2012-08-08 17:05:17 +04:00
|
|
|
for (uint32_t idx = 0; idx < count; idx++) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowIdx = doSelectRow ? aIndex : idx;
|
|
|
|
int32_t colIdx = doSelectRow ? idx : aIndex;
|
2012-08-08 17:05:17 +04:00
|
|
|
nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx);
|
|
|
|
if (cellFrame && !cellFrame->IsSelected()) {
|
|
|
|
nsresult rv = tableSelection->SelectCellElement(cellFrame->GetContent());
|
2009-09-10 07:06:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
2009-09-10 07:06:54 +04:00
|
|
|
|
2007-05-12 06:21:10 +04:00
|
|
|
return NS_OK;
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLTableAccessible::RemoveRowsOrColumnsFromSelection(int32_t aIndex,
|
|
|
|
uint32_t aTarget,
|
2012-06-07 16:47:49 +04:00
|
|
|
bool aIsOuter)
|
2007-05-11 16:21:43 +04:00
|
|
|
{
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
if (!tableFrame)
|
|
|
|
return NS_OK;
|
2007-05-11 16:21:43 +04:00
|
|
|
|
2012-02-08 02:38:54 +04:00
|
|
|
nsIPresShell* presShell(mDoc->PresShell());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> tableSelection =
|
2009-09-10 07:06:54 +04:00
|
|
|
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
|
2007-05-11 16:21:43 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
|
2012-08-08 17:05:17 +04:00
|
|
|
uint32_t count = doUnselectRow ? ColCount() : RowCount();
|
2009-09-10 07:06:54 +04:00
|
|
|
|
2012-08-22 19:56:38 +04: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 07:06:54 +04:00
|
|
|
|
|
|
|
if (aIsOuter)
|
2010-06-11 12:23:18 +04:00
|
|
|
return tableSelection->RestrictCellsToSelection(mContent,
|
2012-05-30 04:51:08 +04:00
|
|
|
startRowIdx, startColIdx,
|
2009-09-10 07:06:54 +04:00
|
|
|
endRowIdx, endColIdx);
|
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
return tableSelection->RemoveCellsFromSelection(mContent,
|
2012-05-30 04:51:08 +04:00
|
|
|
startRowIdx, startColIdx,
|
2009-09-10 07:06:54 +04:00
|
|
|
endRowIdx, endColIdx);
|
2007-05-11 16:21:43 +04:00
|
|
|
}
|
|
|
|
|
2011-04-23 17:14:05 +04:00
|
|
|
void
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::Description(nsString& aDescription)
|
2006-07-24 18:26:25 +04:00
|
|
|
{
|
|
|
|
// Helpful for debugging layout vs. data tables
|
|
|
|
aDescription.Truncate();
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible::Description(aDescription);
|
2011-04-23 17:14:05 +04:00
|
|
|
if (!aDescription.IsEmpty())
|
|
|
|
return;
|
2007-07-05 19:39:29 +04:00
|
|
|
|
2011-06-24 08:01:45 +04:00
|
|
|
// Use summary as description if it weren't used as a name.
|
|
|
|
// XXX: get rid code duplication with NameInternal().
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* caption = Caption();
|
2011-06-24 08:01:45 +04:00
|
|
|
if (caption) {
|
|
|
|
nsIContent* captionContent = caption->GetContent();
|
|
|
|
if (captionContent) {
|
|
|
|
nsAutoString captionText;
|
2011-04-23 17:14:05 +04:00
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
|
2011-06-24 08:01:45 +04:00
|
|
|
&captionText);
|
|
|
|
|
|
|
|
if (!captionText.IsEmpty()) { // summary isn't used as a name.
|
2011-06-04 01:35:17 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary,
|
2011-06-24 08:01:45 +04:00
|
|
|
aDescription);
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 19:39:29 +04:00
|
|
|
}
|
2011-06-24 08:01:45 +04:00
|
|
|
|
2007-07-05 19:39:29 +04:00
|
|
|
#ifdef SHOW_LAYOUT_HEURISTIC
|
|
|
|
if (aDescription.IsEmpty()) {
|
2012-03-28 04:53:58 +04:00
|
|
|
bool isProbablyForLayout = IsProbablyLayoutTable();
|
2007-07-05 19:39:29 +04:00
|
|
|
aDescription = mLayoutHeuristic;
|
|
|
|
}
|
2006-07-24 18:26:25 +04:00
|
|
|
printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::HasDescendant(const nsAString& aTagName, bool aAllowEmpty)
|
2006-07-24 18:26:25 +04:00
|
|
|
{
|
2014-06-17 02:50:15 +04:00
|
|
|
nsCOMPtr<nsIHTMLCollection> elements =
|
|
|
|
mContent->AsElement()->GetElementsByTagName(aTagName);
|
2006-07-24 18:26:25 +04:00
|
|
|
|
2014-06-17 02:50:15 +04:00
|
|
|
Element* foundItem = elements->Item(0);
|
2009-07-08 06:39:04 +04:00
|
|
|
if (!foundItem)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-07-08 06:39:04 +04:00
|
|
|
|
|
|
|
if (aAllowEmpty)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-07-08 06:39:04 +04: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.
|
2014-06-17 02:50:15 +04:00
|
|
|
if (foundItem->GetChildCount() > 1)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // Treat multiple child nodes as non-empty
|
2009-07-08 06:39:04 +04:00
|
|
|
|
2014-06-17 02:50:15 +04:00
|
|
|
nsIContent *innerItemContent = foundItem->GetFirstChild();
|
2009-07-08 06:39:04 +04:00
|
|
|
if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-07-24 18:26:25 +04:00
|
|
|
|
2009-07-08 06:39:04 +04: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
|
2016-03-30 13:53:00 +03:00
|
|
|
// HTMLTableAccessible::InsertChildAt).
|
2014-06-17 02:50:15 +04:00
|
|
|
return !!elements->Item(1);
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
2012-03-28 04:53:58 +04:00
|
|
|
bool
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLTableAccessible::IsProbablyLayoutTable()
|
2006-07-24 18:26:25 +04: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 04:53:58 +04:00
|
|
|
{ \
|
|
|
|
mLayoutHeuristic = isLayout ? \
|
|
|
|
NS_LITERAL_STRING("layout table: " heuristic) : \
|
|
|
|
NS_LITERAL_STRING("data table: " heuristic); \
|
|
|
|
return isLayout; \
|
|
|
|
}
|
2006-07-24 18:26:25 +04:00
|
|
|
#else
|
2012-03-28 04:53:58 +04:00
|
|
|
#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { return isLayout; }
|
2006-07-24 18:26:25 +04:00
|
|
|
#endif
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* docAccessible = Document();
|
2007-04-13 15:38:43 +04:00
|
|
|
if (docAccessible) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t docState = docAccessible->State();
|
2011-04-10 03:38:06 +04:00
|
|
|
if (docState & states::EDITABLE) { // Need to see all elements while document is being edited
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "In editable document");
|
2007-04-13 15:38:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 17:21:09 +04: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 04:51:08 +04:00
|
|
|
if (Role() != roles::TABLE)
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute");
|
2006-07-24 18:26:25 +04:00
|
|
|
|
2011-06-04 01:35:17 +04:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::role)) {
|
2009-07-03 17:21:09 +04: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 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has role attribute, weak role, and role is table");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
2011-10-01 05:09:31 +04:00
|
|
|
|
2015-10-19 15:46:54 +03:00
|
|
|
NS_ASSERTION(mContent->IsHTMLElement(nsGkAtoms::table),
|
|
|
|
"table should not be built by CSS display:table style");
|
2011-11-07 13:05:51 +04:00
|
|
|
|
2011-10-19 05:36:35 +04: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 05:09:31 +04:00
|
|
|
// Check for legitimate data table attributes.
|
2007-04-10 17:29:31 +04:00
|
|
|
nsAutoString summary;
|
2011-10-01 05:09:31 +04: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 05:18:45 +04:00
|
|
|
Accessible* caption = FirstChild();
|
2012-01-12 07:07:35 +04:00
|
|
|
if (caption && caption->Role() == roles::CAPTION && caption->HasChildren())
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "Not empty caption -- legitimate table structures");
|
2011-10-01 05:09:31 +04:00
|
|
|
|
2011-10-01 07:53:57 +04:00
|
|
|
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
|
|
|
childElm = childElm->GetNextSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!childElm->IsHTMLElement())
|
2011-10-01 05:09:31 +04:00
|
|
|
continue;
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (childElm->IsAnyOfHTMLElements(nsGkAtoms::col,
|
|
|
|
nsGkAtoms::colgroup,
|
|
|
|
nsGkAtoms::tfoot,
|
|
|
|
nsGkAtoms::thead)) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"Has col, colgroup, tfoot or thead -- legitimate table structures");
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (childElm->IsHTMLElement(nsGkAtoms::tbody)) {
|
2011-10-01 07:53:57 +04:00
|
|
|
for (nsIContent* rowElm = childElm->GetFirstChild(); rowElm;
|
|
|
|
rowElm = rowElm->GetNextSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (rowElm->IsHTMLElement(nsGkAtoms::tr)) {
|
2011-10-01 07:53:57 +04:00
|
|
|
for (nsIContent* cellElm = rowElm->GetFirstChild(); cellElm;
|
|
|
|
cellElm = cellElm->GetNextSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (cellElm->IsHTMLElement()) {
|
2012-05-30 04:51:08 +04:00
|
|
|
|
2012-03-12 21:54:21 +04: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 05:18:45 +04:00
|
|
|
Accessible* cell = mDoc->GetAccessible(cellElm);
|
2012-05-25 14:53:45 +04:00
|
|
|
if (cell && cell->ChildCount() == 1 &&
|
2012-03-12 21:54:21 +04:00
|
|
|
cell->FirstChild()->IsAbbreviation()) {
|
|
|
|
RETURN_LAYOUT_ANSWER(false,
|
|
|
|
"has abbr -- legitimate table structures");
|
|
|
|
}
|
2011-10-01 05:09:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 06:39:04 +04:00
|
|
|
if (HasDescendant(NS_LITERAL_STRING("table"))) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has a nested table within it");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
2012-01-12 07:07:35 +04:00
|
|
|
|
2006-07-24 18:26:25 +04:00
|
|
|
// If only 1 column or only 1 row, it's for layout
|
2014-10-22 04:49:28 +04:00
|
|
|
uint32_t colCount = ColCount();
|
|
|
|
if (colCount <=1) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 column");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
2014-10-22 04:49:28 +04:00
|
|
|
uint32_t rowCount = RowCount();
|
|
|
|
if (rowCount <=1) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has only 1 row");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many columns
|
2014-10-22 04:49:28 +04:00
|
|
|
if (colCount >= 5) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">=5 columns");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
2012-01-12 07:07:35 +04:00
|
|
|
|
2006-07-24 18:26:25 +04: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?
|
2016-06-16 15:14:08 +03:00
|
|
|
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-08-08 17:05:17 +04:00
|
|
|
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 18:26:25 +04:00
|
|
|
nsMargin border;
|
2016-04-21 07:28:33 +03:00
|
|
|
cellFrame->GetXULBorder(border);
|
2006-07-24 18:26:25 +04:00
|
|
|
if (border.top && border.bottom && border.left && border.right) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
|
|
|
|
*/
|
|
|
|
|
2012-02-17 11:21:26 +04:00
|
|
|
// Check for styled background color across rows (alternating background
|
|
|
|
// color is a common feature for data tables).
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = ChildCount();
|
2012-06-19 00:14:01 +04:00
|
|
|
nscolor rowColor = 0;
|
|
|
|
nscolor prevRowColor;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
2012-02-17 11:21:26 +04:00
|
|
|
if (child->Role() == roles::ROW) {
|
2012-03-04 06:29:25 +04:00
|
|
|
prevRowColor = rowColor;
|
|
|
|
nsIFrame* rowFrame = child->GetFrame();
|
2013-02-17 01:51:02 +04:00
|
|
|
rowColor = rowFrame->StyleBackground()->mBackgroundColor;
|
2012-03-04 06:29:25 +04:00
|
|
|
|
|
|
|
if (childIdx > 0 && prevRowColor != rowColor)
|
|
|
|
RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for many rows
|
2014-10-22 04:49:28 +04:00
|
|
|
const uint32_t kMaxLayoutRows = 20;
|
|
|
|
if (rowCount > kMaxLayoutRows) { // A ton of rows, this is probably for data
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, ">= kMaxLayoutRows (20) and non-bordered");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:18:48 +04: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 19:56:38 +04:00
|
|
|
int32_t percentageOfDocWidth = (100 * tableSize.width) / documentSize.width;
|
2012-02-18 13:18:48 +04: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 18:26:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two column rules
|
2014-10-22 04:49:28 +04:00
|
|
|
if (rowCount * colCount <= 10) {
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "2-4 columns, 10 cells or less, non-bordered");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
2009-07-08 06:39:04 +04: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 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(true, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
2011-10-01 05:09:31 +04:00
|
|
|
RETURN_LAYOUT_ANSWER(false, "no layout factor strong enough, so will guess data");
|
2006-07-24 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-07 18:38:58 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-07 16:47:49 +04:00
|
|
|
// HTMLCaptionAccessible
|
2009-09-11 05:07:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-03-07 18:38:58 +03:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
Relation
|
2013-10-19 22:19:50 +04:00
|
|
|
HTMLCaptionAccessible::RelationByType(RelationType aType)
|
2007-07-05 19:39:29 +04:00
|
|
|
{
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessible::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABEL_FOR)
|
2011-08-10 05:44:00 +04:00
|
|
|
rel.AppendTarget(Parent());
|
2007-07-05 19:39:29 +04:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
return rel;
|
2007-07-05 19:39:29 +04:00
|
|
|
}
|
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2012-06-07 16:47:49 +04:00
|
|
|
HTMLCaptionAccessible::NativeRole()
|
2009-03-07 18:38:58 +03:00
|
|
|
{
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::CAPTION;
|
2009-03-07 18:38:58 +03:00
|
|
|
}
|