AccessibilityARIAGrid.cpp [plain text]
#include "config.h"
#include "AccessibilityARIAGrid.h"
#include "AXObjectCache.h"
#include "AccessibilityARIAGridRow.h"
#include "AccessibilityTableCell.h"
#include "AccessibilityTableColumn.h"
#include "AccessibilityTableHeaderContainer.h"
#include "AccessibilityTableRow.h"
#include "RenderObject.h"
#include "RenderTableSection.h"
namespace WebCore {
AccessibilityARIAGrid::AccessibilityARIAGrid(RenderObject* renderer)
: AccessibilityTable(renderer)
{
}
AccessibilityARIAGrid::~AccessibilityARIAGrid() = default;
Ref<AccessibilityARIAGrid> AccessibilityARIAGrid::create(RenderObject* renderer)
{
return adoptRef(*new AccessibilityARIAGrid(renderer));
}
bool AccessibilityARIAGrid::addTableCellChild(AccessibilityObject* child, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount)
{
if (!child || (!is<AccessibilityTableRow>(*child) && !is<AccessibilityARIAGridRow>(*child)))
return false;
auto& row = downcast<AccessibilityTableRow>(*child);
if (appendedRows.contains(&row))
return false;
unsigned rowCellCount = row.children().size();
if (rowCellCount > columnCount)
columnCount = rowCellCount;
row.setRowIndex((int)m_rows.size());
m_rows.append(&row);
if (!row.accessibilityIsIgnored())
m_children.append(&row);
else
m_children.appendVector(row.children());
appendedRows.add(&row);
return true;
}
bool AccessibilityARIAGrid::isMultiSelectable() const
{
auto multiSelectable = boolValueForProperty(AXPropertyName::Multiselectable);
if (multiSelectable && !multiSelectable.value())
return false;
return true;
}
void AccessibilityARIAGrid::addRowDescendant(AccessibilityObject* rowChild, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount)
{
if (!rowChild)
return;
if (!rowChild->isTableRow() || !rowChild->node()) {
for (const auto& child : rowChild->children())
addRowDescendant(child.get(), appendedRows, columnCount);
} else
addTableCellChild(rowChild, appendedRows, columnCount);
}
void AccessibilityARIAGrid::addChildren()
{
ASSERT(!m_haveChildren);
if (!isExposableThroughAccessibility()) {
AccessibilityRenderObject::addChildren();
return;
}
m_haveChildren = true;
if (!m_renderer)
return;
AXObjectCache* axCache = m_renderer->document().axObjectCache();
HashSet<AccessibilityObject*> appendedRows;
unsigned columnCount = 0;
AccessibilityChildrenVector footerSections;
for (RefPtr<AccessibilityObject> child = firstChild(); child; child = child->nextSibling()) {
bool footerSection = false;
if (RenderObject* childRenderer = child->renderer()) {
if (is<RenderTableSection>(*childRenderer)) {
RenderTableSection& childSection = downcast<RenderTableSection>(*childRenderer);
if (&childSection == childSection.table()->footer()) {
footerSections.append(child);
footerSection = true;
}
}
}
if (!footerSection)
addRowDescendant(child.get(), appendedRows, columnCount);
}
for (const auto& footerSection : footerSections)
addRowDescendant(footerSection.get(), appendedRows, columnCount);
for (unsigned i = 0; i < columnCount; ++i) {
auto& column = downcast<AccessibilityTableColumn>(*axCache->getOrCreate(AccessibilityRole::Column));
column.setColumnIndex(static_cast<int>(i));
column.setParent(this);
m_columns.append(&column);
if (!column.accessibilityIsIgnored())
m_children.append(&column);
}
AccessibilityObject* headerContainerObject = headerContainer();
if (headerContainerObject && !headerContainerObject->accessibilityIsIgnored())
m_children.append(headerContainerObject);
}
}