2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "AccessibilityTableCell.h"
32 #include "AXObjectCache.h"
33 #include "HTMLNames.h"
34 #include "RenderObject.h"
35 #include "RenderTableCell.h"
41 using namespace HTMLNames;
43 AccessibilityTableCell::AccessibilityTableCell(RenderObject* renderer)
44 : AccessibilityRenderObject(renderer)
48 AccessibilityTableCell::~AccessibilityTableCell()
52 PassRefPtr<AccessibilityTableCell> AccessibilityTableCell::create(RenderObject* renderer)
54 AccessibilityTableCell* obj = new AccessibilityTableCell(renderer);
59 bool AccessibilityTableCell::accessibilityIsIgnored() const
61 AccessibilityObjectInclusion decision = accessibilityIsIgnoredBase();
62 if (decision == IncludeObject)
64 if (decision == IgnoreObject)
68 return AccessibilityRenderObject::accessibilityIsIgnored();
73 AccessibilityObject* AccessibilityTableCell::parentTable() const
75 if (!m_renderer || !m_renderer->isTableCell())
78 // Do not use getOrCreate. parentTable() can be called while the render tree is being modified
79 // by javascript, and creating a table element may try to access the render tree while in a bad state.
80 // By using only get() implies that the AXTable must be created before AXTableCells. This should
81 // always be the case when AT clients access a table.
82 // https://bugs.webkit.org/show_bug.cgi?id=42652
83 return axObjectCache()->get(toRenderTableCell(m_renderer)->table());
86 bool AccessibilityTableCell::isTableCell() const
88 AccessibilityObject* table = parentTable();
89 if (!table || !table->isAccessibilityTable())
95 AccessibilityRole AccessibilityTableCell::roleValue() const
98 return AccessibilityRenderObject::roleValue();
103 void AccessibilityTableCell::rowIndexRange(pair<int, int>& rowRange)
105 if (!m_renderer || !m_renderer->isTableCell())
108 RenderTableCell* renderCell = toRenderTableCell(m_renderer);
109 rowRange.first = renderCell->rowIndex();
110 rowRange.second = renderCell->rowSpan();
112 // since our table might have multiple sections, we have to offset our row appropriately
113 RenderTableSection* section = renderCell->section();
114 RenderTable* table = renderCell->table();
115 if (!table || !section)
118 // FIXME: This will skip a table with just a tfoot. Should fix by using RenderTable::topSection.
119 RenderTableSection* tableSection = table->header();
121 tableSection = table->firstBody();
123 unsigned rowOffset = 0;
124 while (tableSection) {
125 if (tableSection == section)
127 rowOffset += tableSection->numRows();
128 tableSection = table->sectionBelow(tableSection, SkipEmptySections);
131 rowRange.first += rowOffset;
134 void AccessibilityTableCell::columnIndexRange(pair<int, int>& columnRange)
136 if (!m_renderer || !m_renderer->isTableCell())
139 RenderTableCell* renderCell = toRenderTableCell(m_renderer);
140 columnRange.first = renderCell->col();
141 columnRange.second = renderCell->colSpan();
144 AccessibilityObject* AccessibilityTableCell::titleUIElement() const
146 // Try to find if the first cell in this row is a <th>. If it is,
147 // then it can act as the title ui element. (This is only in the
148 // case when the table is not appearing as an AXTable.)
149 if (isTableCell() || !m_renderer || !m_renderer->isTableCell())
152 // Table cells that are th cannot have title ui elements, since by definition
153 // they are title ui elements
154 Node* node = m_renderer->node();
155 if (node && node->hasTagName(thTag))
158 RenderTableCell* renderCell = toRenderTableCell(m_renderer);
160 // If this cell is in the first column, there is no need to continue.
161 int col = renderCell->col();
165 int row = renderCell->rowIndex();
167 RenderTableSection* section = renderCell->section();
171 RenderTableCell* headerCell = section->primaryCellAt(row, 0);
172 if (!headerCell || headerCell == renderCell)
175 Node* cellElement = headerCell->node();
176 if (!cellElement || !cellElement->hasTagName(thTag))
179 return axObjectCache()->getOrCreate(headerCell);
182 } // namespace WebCore