AccessibilityTableRow.cpp [plain text]
#include "config.h"
#include "AccessibilityTableRow.h"
#include "AXObjectCache.h"
#include "AccessibilityTable.h"
#include "AccessibilityTableCell.h"
#include "HTMLNames.h"
#include "HTMLTableRowElement.h"
#include "RenderObject.h"
#include "RenderTableCell.h"
#include "RenderTableRow.h"
namespace WebCore {
using namespace HTMLNames;
AccessibilityTableRow::AccessibilityTableRow(RenderObject* renderer)
: AccessibilityRenderObject(renderer)
{
}
AccessibilityTableRow::~AccessibilityTableRow()
{
}
Ref<AccessibilityTableRow> AccessibilityTableRow::create(RenderObject* renderer)
{
return adoptRef(*new AccessibilityTableRow(renderer));
}
AccessibilityRole AccessibilityTableRow::determineAccessibilityRole()
{
if (!isTableRow())
return AccessibilityRenderObject::determineAccessibilityRole();
if ((m_ariaRole = determineAriaRoleAttribute()) != UnknownRole)
return m_ariaRole;
return RowRole;
}
bool AccessibilityTableRow::isTableRow() const
{
AccessibilityObject* table = parentTable();
return is<AccessibilityTable>(table) && downcast<AccessibilityTable>(*table).isExposableThroughAccessibility();
}
AccessibilityObject* AccessibilityTableRow::observableObject() const
{
return parentTable();
}
bool AccessibilityTableRow::computeAccessibilityIsIgnored() const
{
AccessibilityObjectInclusion decision = defaultObjectInclusion();
if (decision == IncludeObject)
return false;
if (decision == IgnoreObject)
return true;
if (!isTableRow())
return AccessibilityRenderObject::computeAccessibilityIsIgnored();
return false;
}
AccessibilityTable* AccessibilityTableRow::parentTable() const
{
for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (is<AccessibilityTable>(*parent)) {
auto& parentTable = downcast<AccessibilityTable>(*parent);
if (parentTable.isExposableThroughAccessibility())
return &parentTable;
if (parentTable.node())
break;
}
}
return nullptr;
}
AccessibilityObject* AccessibilityTableRow::headerObject()
{
if (!m_renderer || !m_renderer->isTableRow())
return nullptr;
const auto& rowChildren = children();
if (!rowChildren.size())
return nullptr;
AccessibilityObject* cell = rowChildren[0].get();
if (!is<AccessibilityTableCell>(*cell))
return nullptr;
RenderObject* cellRenderer = downcast<AccessibilityTableCell>(*cell).renderer();
if (!cellRenderer)
return nullptr;
Node* cellNode = cellRenderer->node();
if (!cellNode || !cellNode->hasTagName(thTag))
return nullptr;
return cell;
}
void AccessibilityTableRow::addChildren()
{
AccessibilityRenderObject::addChildren();
int colIndex = ariaColumnIndex();
if (colIndex == -1)
return;
unsigned index = 0;
for (const auto& cell : children()) {
if (is<AccessibilityTableCell>(*cell))
downcast<AccessibilityTableCell>(*cell).setARIAColIndexFromRow(colIndex + index);
index++;
}
}
int AccessibilityTableRow::ariaColumnIndex() const
{
const AtomicString& colIndexValue = getAttribute(aria_colindexAttr);
if (colIndexValue.toInt() >= 1)
return colIndexValue.toInt();
return -1;
}
int AccessibilityTableRow::ariaRowIndex() const
{
const AtomicString& rowIndexValue = getAttribute(aria_rowindexAttr);
if (rowIndexValue.toInt() >= 1)
return rowIndexValue.toInt();
return -1;
}
}