cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 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. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 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. |
| 27 | */ |
| 28 | |
| 29 | #include "config.h" |
| 30 | #include "AccessibilityTable.h" |
| 31 | |
cfleizach@apple.com | f534eb2 | 2009-11-03 07:01:20 +0000 | [diff] [blame] | 32 | #include "AXObjectCache.h" |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 33 | #include "AccessibilityTableCell.h" |
| 34 | #include "AccessibilityTableColumn.h" |
| 35 | #include "AccessibilityTableHeaderContainer.h" |
| 36 | #include "AccessibilityTableRow.h" |
antti@apple.com | 0494cf8 | 2013-08-31 14:12:00 +0000 | [diff] [blame] | 37 | #include "ElementIterator.h" |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 38 | #include "HTMLNames.h" |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 39 | #include "HTMLTableCaptionElement.h" |
| 40 | #include "HTMLTableCellElement.h" |
cfleizach@apple.com | f534eb2 | 2009-11-03 07:01:20 +0000 | [diff] [blame] | 41 | #include "HTMLTableElement.h" |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 42 | #include "RenderObject.h" |
| 43 | #include "RenderTable.h" |
| 44 | #include "RenderTableCell.h" |
| 45 | #include "RenderTableSection.h" |
| 46 | |
commit-queue@webkit.org | ac97cff | 2015-08-10 01:53:10 +0000 | [diff] [blame] | 47 | #include <wtf/Deque.h> |
| 48 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 49 | namespace WebCore { |
| 50 | |
| 51 | using namespace HTMLNames; |
| 52 | |
| 53 | AccessibilityTable::AccessibilityTable(RenderObject* renderer) |
cfleizach@apple.com | a59d8e4 | 2013-02-14 19:22:10 +0000 | [diff] [blame] | 54 | : AccessibilityRenderObject(renderer) |
mmaxfield@apple.com | 890554f | 2014-07-23 14:57:15 +0000 | [diff] [blame] | 55 | , m_headerContainer(nullptr) |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 56 | , m_isExposableThroughAccessibility(true) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 57 | { |
dmazzoni@google.com | c35bf3d | 2012-07-24 06:26:32 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | AccessibilityTable::~AccessibilityTable() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | void AccessibilityTable::init() |
| 65 | { |
| 66 | AccessibilityRenderObject::init(); |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 67 | m_isExposableThroughAccessibility = computeIsTableExposableThroughAccessibility(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 68 | } |
| 69 | |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 70 | Ref<AccessibilityTable> AccessibilityTable::create(RenderObject* renderer) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 71 | { |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 72 | return adoptRef(*new AccessibilityTable(renderer)); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 73 | } |
| 74 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 75 | bool AccessibilityTable::hasARIARole() const |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 76 | { |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 77 | if (!m_renderer) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 78 | return false; |
| 79 | |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 80 | AccessibilityRole ariaRole = ariaRoleAttribute(); |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 81 | if (ariaRole != UnknownRole) |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 82 | return true; |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 87 | bool AccessibilityTable::isExposableThroughAccessibility() const |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 88 | { |
| 89 | if (!m_renderer) |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 90 | return false; |
| 91 | |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 92 | return m_isExposableThroughAccessibility; |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 93 | } |
| 94 | |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 95 | HTMLTableElement* AccessibilityTable::tableElement() const |
| 96 | { |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 97 | if (!is<RenderTable>(*m_renderer)) |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 98 | return nullptr; |
| 99 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 100 | RenderTable& table = downcast<RenderTable>(*m_renderer); |
| 101 | if (is<HTMLTableElement>(table.element())) |
| 102 | return downcast<HTMLTableElement>(table.element()); |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 103 | |
| 104 | // If the table has a display:table-row-group, then the RenderTable does not have a pointer to it's HTMLTableElement. |
| 105 | // We can instead find it by asking the firstSection for its parent. |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 106 | RenderTableSection* firstBody = table.firstBody(); |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 107 | if (!firstBody || !firstBody->element()) |
| 108 | return nullptr; |
| 109 | |
| 110 | Element* actualTable = firstBody->element()->parentElement(); |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 111 | if (!is<HTMLTableElement>(actualTable)) |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 112 | return nullptr; |
| 113 | |
cdumez@apple.com | 72754ba | 2014-09-23 22:03:15 +0000 | [diff] [blame] | 114 | return downcast<HTMLTableElement>(actualTable); |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 115 | } |
| 116 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 117 | bool AccessibilityTable::isDataTable() const |
| 118 | { |
| 119 | if (!m_renderer) |
| 120 | return false; |
| 121 | |
| 122 | // Do not consider it a data table is it has an ARIA role. |
| 123 | if (hasARIARole()) |
| 124 | return false; |
| 125 | |
aboxhall@chromium.org | 8abadf1 | 2012-05-23 07:45:29 +0000 | [diff] [blame] | 126 | // When a section of the document is contentEditable, all tables should be |
| 127 | // treated as data tables, otherwise users may not be able to work with rich |
| 128 | // text editors that allow creating and editing tables. |
antti@apple.com | f02be1e | 2013-12-21 18:51:04 +0000 | [diff] [blame] | 129 | if (node() && node()->hasEditableStyle()) |
aboxhall@chromium.org | 8abadf1 | 2012-05-23 07:45:29 +0000 | [diff] [blame] | 130 | return true; |
| 131 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 132 | if (!is<RenderTable>(*m_renderer)) |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 133 | return false; |
| 134 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 135 | // This employs a heuristic to determine if this table should appear. |
| 136 | // Only "data" tables should be exposed as tables. |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 137 | // Unfortunately, there is no good way to determine the difference |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 138 | // between a "layout" table and a "data" table. |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 139 | if (HTMLTableElement* tableElement = this->tableElement()) { |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 140 | // If there is a caption element, summary, THEAD, or TFOOT section, it's most certainly a data table. |
| 141 | if (!tableElement->summary().isEmpty() || tableElement->tHead() || tableElement->tFoot() || tableElement->caption()) |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 142 | return true; |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 143 | |
| 144 | // If someone used "rules" attribute than the table should appear. |
| 145 | if (!tableElement->rules().isEmpty()) |
| 146 | return true; |
| 147 | |
| 148 | // If there's a colgroup or col element, it's probably a data table. |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 149 | for (const auto& child : childrenOfType<HTMLElement>(*tableElement)) { |
cfleizach@apple.com | 7d83f56 | 2014-03-13 16:28:24 +0000 | [diff] [blame] | 150 | if (child.hasTagName(colTag) || child.hasTagName(colgroupTag)) |
| 151 | return true; |
| 152 | } |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 153 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 154 | |
cfleizach@apple.com | 9813191 | 2015-05-10 14:52:50 +0000 | [diff] [blame] | 155 | // The following checks should only apply if this is a real <table> element. |
| 156 | if (!hasTagName(tableTag)) |
| 157 | return false; |
| 158 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 159 | RenderTable& table = downcast<RenderTable>(*m_renderer); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 160 | // go through the cell's and check for tell-tale signs of "data" table status |
| 161 | // cells have borders, or use attributes like headers, abbr, scope or axis |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 162 | table.recalcSectionsIfNeeded(); |
| 163 | RenderTableSection* firstBody = table.firstBody(); |
cfleizach@apple.com | 33a556b | 2008-08-26 22:29:14 +0000 | [diff] [blame] | 164 | if (!firstBody) |
| 165 | return false; |
| 166 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 167 | int numCols = firstBody->numColumns(); |
| 168 | int numRows = firstBody->numRows(); |
| 169 | |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 170 | // If there's only one cell, it's not a good AXTable candidate. |
cfleizach@apple.com | debb872 | 2008-09-22 18:47:16 +0000 | [diff] [blame] | 171 | if (numRows == 1 && numCols == 1) |
| 172 | return false; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 173 | |
| 174 | // If there are at least 20 rows, we'll call it a data table. |
| 175 | if (numRows >= 20) |
| 176 | return true; |
cfleizach@apple.com | debb872 | 2008-09-22 18:47:16 +0000 | [diff] [blame] | 177 | |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 178 | // Store the background color of the table to check against cell's background colors. |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 179 | const RenderStyle& tableStyle = table.style(); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 180 | Color tableBGColor = tableStyle.visitedDependentColor(CSSPropertyBackgroundColor); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 181 | |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 182 | // check enough of the cells to find if the table matches our criteria |
| 183 | // Criteria: |
| 184 | // 1) must have at least one valid cell (and) |
| 185 | // 2) at least half of cells have borders (or) |
| 186 | // 3) at least half of cells have different bg colors than the table, and there is cell spacing |
| 187 | unsigned validCellCount = 0; |
| 188 | unsigned borderedCellCount = 0; |
| 189 | unsigned backgroundDifferenceCellCount = 0; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 190 | unsigned cellsWithTopBorder = 0; |
| 191 | unsigned cellsWithBottomBorder = 0; |
| 192 | unsigned cellsWithLeftBorder = 0; |
| 193 | unsigned cellsWithRightBorder = 0; |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 194 | |
cfleizach@apple.com | 58c0133 | 2010-07-14 21:10:50 +0000 | [diff] [blame] | 195 | Color alternatingRowColors[5]; |
| 196 | int alternatingRowColorCount = 0; |
| 197 | |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 198 | int headersInFirstColumnCount = 0; |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 199 | for (int row = 0; row < numRows; ++row) { |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 200 | |
| 201 | int headersInFirstRowCount = 0; |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 202 | for (int col = 0; col < numCols; ++col) { |
jamesr@google.com | 36623a3 | 2010-07-23 20:22:29 +0000 | [diff] [blame] | 203 | RenderTableCell* cell = firstBody->primaryCellAt(row, col); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 204 | if (!cell) |
| 205 | continue; |
cfleizach@apple.com | 0cc2526 | 2014-02-17 22:26:54 +0000 | [diff] [blame] | 206 | |
| 207 | Element* cellElement = cell->element(); |
| 208 | if (!cellElement) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 209 | continue; |
| 210 | |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 211 | if (cell->width() < 1 || cell->height() < 1) |
| 212 | continue; |
| 213 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 214 | ++validCellCount; |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 215 | |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 216 | bool isTHCell = cellElement->hasTagName(thTag); |
| 217 | // If the first row is comprised of all <th> tags, assume it is a data table. |
| 218 | if (!row && isTHCell) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 219 | ++headersInFirstRowCount; |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 220 | |
cfleizach@apple.com | 8f21375 | 2012-02-13 19:23:52 +0000 | [diff] [blame] | 221 | // If the first column is comprised of all <th> tags, assume it is a data table. |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 222 | if (!col && isTHCell) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 223 | ++headersInFirstColumnCount; |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 224 | |
cfleizach@apple.com | 0cc2526 | 2014-02-17 22:26:54 +0000 | [diff] [blame] | 225 | // In this case, the developer explicitly assigned a "data" table attribute. |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 226 | if (is<HTMLTableCellElement>(*cellElement)) { |
cdumez@apple.com | cd13153 | 2014-09-27 01:32:34 +0000 | [diff] [blame] | 227 | HTMLTableCellElement& tableCellElement = downcast<HTMLTableCellElement>(*cellElement); |
| 228 | if (!tableCellElement.headers().isEmpty() || !tableCellElement.abbr().isEmpty() |
| 229 | || !tableCellElement.axis().isEmpty() || !tableCellElement.scope().isEmpty()) |
cfleizach@apple.com | 0cc2526 | 2014-02-17 22:26:54 +0000 | [diff] [blame] | 230 | return true; |
| 231 | } |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 232 | const RenderStyle& renderStyle = cell->style(); |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 233 | |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 234 | // If the empty-cells style is set, we'll call it a data table. |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 235 | if (renderStyle.emptyCells() == HIDE) |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 236 | return true; |
| 237 | |
| 238 | // If a cell has matching bordered sides, call it a (fully) bordered cell. |
cfleizach@apple.com | f534eb2 | 2009-11-03 07:01:20 +0000 | [diff] [blame] | 239 | if ((cell->borderTop() > 0 && cell->borderBottom() > 0) |
| 240 | || (cell->borderLeft() > 0 && cell->borderRight() > 0)) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 241 | ++borderedCellCount; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 242 | |
| 243 | // Also keep track of each individual border, so we can catch tables where most |
| 244 | // cells have a bottom border, for example. |
| 245 | if (cell->borderTop() > 0) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 246 | ++cellsWithTopBorder; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 247 | if (cell->borderBottom() > 0) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 248 | ++cellsWithBottomBorder; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 249 | if (cell->borderLeft() > 0) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 250 | ++cellsWithLeftBorder; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 251 | if (cell->borderRight() > 0) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 252 | ++cellsWithRightBorder; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 253 | |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 254 | // If the cell has a different color from the table and there is cell spacing, |
| 255 | // then it is probably a data table cell (spacing and colors take the place of borders). |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 256 | Color cellColor = renderStyle.visitedDependentColor(CSSPropertyBackgroundColor); |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 257 | if (table.hBorderSpacing() > 0 && table.vBorderSpacing() > 0 |
cfleizach@apple.com | f534eb2 | 2009-11-03 07:01:20 +0000 | [diff] [blame] | 258 | && tableBGColor != cellColor && cellColor.alpha() != 1) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 259 | ++backgroundDifferenceCellCount; |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 260 | |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 261 | // If we've found 10 "good" cells, we don't need to keep searching. |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 262 | if (borderedCellCount >= 10 || backgroundDifferenceCellCount >= 10) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 263 | return true; |
cfleizach@apple.com | 58c0133 | 2010-07-14 21:10:50 +0000 | [diff] [blame] | 264 | |
| 265 | // For the first 5 rows, cache the background color so we can check if this table has zebra-striped rows. |
| 266 | if (row < 5 && row == alternatingRowColorCount) { |
cdumez@apple.com | dd2b64a | 2014-10-10 15:49:24 +0000 | [diff] [blame] | 267 | RenderElement* renderRow = cell->parent(); |
| 268 | if (!is<RenderTableRow>(renderRow)) |
cfleizach@apple.com | 58c0133 | 2010-07-14 21:10:50 +0000 | [diff] [blame] | 269 | continue; |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 270 | const RenderStyle& rowRenderStyle = renderRow->style(); |
| 271 | Color rowColor = rowRenderStyle.visitedDependentColor(CSSPropertyBackgroundColor); |
cfleizach@apple.com | 58c0133 | 2010-07-14 21:10:50 +0000 | [diff] [blame] | 272 | alternatingRowColors[alternatingRowColorCount] = rowColor; |
cdumez@apple.com | dd2b64a | 2014-10-10 15:49:24 +0000 | [diff] [blame] | 273 | ++alternatingRowColorCount; |
cfleizach@apple.com | 58c0133 | 2010-07-14 21:10:50 +0000 | [diff] [blame] | 274 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 275 | } |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 276 | |
| 277 | if (!row && headersInFirstRowCount == numCols && numCols > 1) |
| 278 | return true; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 279 | } |
| 280 | |
cfleizach@apple.com | 881da5c | 2010-07-07 22:36:34 +0000 | [diff] [blame] | 281 | if (headersInFirstColumnCount == numRows && numRows > 1) |
| 282 | return true; |
| 283 | |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 284 | // if there is less than two valid cells, it's not a data table |
| 285 | if (validCellCount <= 1) |
| 286 | return false; |
| 287 | |
| 288 | // half of the cells had borders, it's a data table |
| 289 | unsigned neededCellCount = validCellCount / 2; |
dmazzoni@google.com | cdb4f67 | 2013-01-18 18:48:30 +0000 | [diff] [blame] | 290 | if (borderedCellCount >= neededCellCount |
| 291 | || cellsWithTopBorder >= neededCellCount |
| 292 | || cellsWithBottomBorder >= neededCellCount |
| 293 | || cellsWithLeftBorder >= neededCellCount |
| 294 | || cellsWithRightBorder >= neededCellCount) |
cfleizach@apple.com | d6bc1e7 | 2008-10-02 23:59:49 +0000 | [diff] [blame] | 295 | return true; |
| 296 | |
| 297 | // half had different background colors, it's a data table |
| 298 | if (backgroundDifferenceCellCount >= neededCellCount) |
| 299 | return true; |
| 300 | |
cfleizach@apple.com | 58c0133 | 2010-07-14 21:10:50 +0000 | [diff] [blame] | 301 | // Check if there is an alternating row background color indicating a zebra striped style pattern. |
| 302 | if (alternatingRowColorCount > 2) { |
| 303 | Color firstColor = alternatingRowColors[0]; |
| 304 | for (int k = 1; k < alternatingRowColorCount; k++) { |
| 305 | // If an odd row was the same color as the first row, its not alternating. |
| 306 | if (k % 2 == 1 && alternatingRowColors[k] == firstColor) |
| 307 | return false; |
| 308 | // If an even row is not the same as the first row, its not alternating. |
| 309 | if (!(k % 2) && alternatingRowColors[k] != firstColor) |
| 310 | return false; |
| 311 | } |
| 312 | return true; |
| 313 | } |
| 314 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 315 | return false; |
| 316 | } |
| 317 | |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 318 | bool AccessibilityTable::computeIsTableExposableThroughAccessibility() const |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 319 | { |
| 320 | // The following is a heuristic used to determine if a |
| 321 | // <table> should be exposed as an AXTable. The goal |
| 322 | // is to only show "data" tables. |
| 323 | |
| 324 | if (!m_renderer) |
| 325 | return false; |
| 326 | |
| 327 | // If the developer assigned an aria role to this, then we |
| 328 | // shouldn't expose it as a table, unless, of course, the aria |
| 329 | // role is a table. |
| 330 | if (hasARIARole()) |
| 331 | return false; |
| 332 | |
jdiggs@igalia.com | a9bb1f0 | 2015-05-05 07:39:23 +0000 | [diff] [blame] | 333 | if (isDataTable()) |
| 334 | return true; |
| 335 | |
jdiggs@igalia.com | 0bdce53f | 2015-05-12 12:01:50 +0000 | [diff] [blame] | 336 | // Gtk+ ATs used to expect all tables to be exposed as tables. |
| 337 | // N.B. Efl may wish to follow suit and also defer to WebCore. In the meantime, the following |
jdiggs@igalia.com | a9bb1f0 | 2015-05-05 07:39:23 +0000 | [diff] [blame] | 338 | // check fails for data tables with display:table-row-group. By checking for data tables first, |
| 339 | // we can handle that edge case without introducing regressions prior to switching to WebCore's |
| 340 | // default behavior for table exposure. |
jdiggs@igalia.com | 0bdce53f | 2015-05-12 12:01:50 +0000 | [diff] [blame] | 341 | #if PLATFORM(EFL) |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 342 | Element* tableNode = downcast<RenderTable>(*m_renderer).element(); |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 343 | return is<HTMLTableElement>(tableNode); |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 344 | #endif |
| 345 | |
jdiggs@igalia.com | a9bb1f0 | 2015-05-05 07:39:23 +0000 | [diff] [blame] | 346 | return false; |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 347 | } |
| 348 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 349 | void AccessibilityTable::clearChildren() |
| 350 | { |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 351 | AccessibilityRenderObject::clearChildren(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 352 | m_rows.clear(); |
| 353 | m_columns.clear(); |
cfleizach@apple.com | 04c1617 | 2011-12-12 23:54:37 +0000 | [diff] [blame] | 354 | |
| 355 | if (m_headerContainer) { |
| 356 | m_headerContainer->detachFromParent(); |
mmaxfield@apple.com | 890554f | 2014-07-23 14:57:15 +0000 | [diff] [blame] | 357 | m_headerContainer = nullptr; |
cfleizach@apple.com | 04c1617 | 2011-12-12 23:54:37 +0000 | [diff] [blame] | 358 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void AccessibilityTable::addChildren() |
| 362 | { |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 363 | if (!isExposableThroughAccessibility()) { |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 364 | AccessibilityRenderObject::addChildren(); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | ASSERT(!m_haveChildren); |
| 369 | |
| 370 | m_haveChildren = true; |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 371 | if (!is<RenderTable>(m_renderer)) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 372 | return; |
| 373 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 374 | RenderTable& table = downcast<RenderTable>(*m_renderer); |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 375 | // Go through all the available sections to pull out the rows and add them as children. |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 376 | table.recalcSectionsIfNeeded(); |
cfleizach@apple.com | 2826b44 | 2008-10-20 17:57:12 +0000 | [diff] [blame] | 377 | |
jdiggs@igalia.com | e8a090d | 2014-12-03 02:02:36 +0000 | [diff] [blame] | 378 | if (HTMLTableElement* tableElement = this->tableElement()) { |
| 379 | if (HTMLTableCaptionElement* caption = tableElement->caption()) { |
rgabor@webkit.org | e42695d | 2014-12-21 23:56:55 +0000 | [diff] [blame] | 380 | AccessibilityObject* axCaption = axObjectCache()->getOrCreate(caption); |
| 381 | if (axCaption && !axCaption->accessibilityIsIgnored()) |
| 382 | m_children.append(axCaption); |
jdiggs@igalia.com | e8a090d | 2014-12-03 02:02:36 +0000 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
cfleizach@apple.com | 36282cb | 2013-07-22 22:04:23 +0000 | [diff] [blame] | 386 | unsigned maxColumnCount = 0; |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 387 | RenderTableSection* footer = table.footer(); |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 388 | |
cdumez@apple.com | 8faf772 | 2014-10-13 18:21:11 +0000 | [diff] [blame] | 389 | for (RenderTableSection* tableSection = table.topSection(); tableSection; tableSection = table.sectionBelow(tableSection, SkipEmptySections)) { |
cfleizach@apple.com | 7c95c0c | 2014-04-29 16:15:14 +0000 | [diff] [blame] | 390 | if (tableSection == footer) |
| 391 | continue; |
| 392 | addChildrenFromSection(tableSection, maxColumnCount); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 393 | } |
| 394 | |
cfleizach@apple.com | 7c95c0c | 2014-04-29 16:15:14 +0000 | [diff] [blame] | 395 | // Process the footer last, in case it was ordered earlier in the DOM. |
| 396 | if (footer) |
| 397 | addChildrenFromSection(footer, maxColumnCount); |
| 398 | |
| 399 | AXObjectCache* axCache = m_renderer->document().axObjectCache(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 400 | // make the columns based on the number of columns in the first body |
cfleizach@apple.com | 36282cb | 2013-07-22 22:04:23 +0000 | [diff] [blame] | 401 | unsigned length = maxColumnCount; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 402 | for (unsigned i = 0; i < length; ++i) { |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 403 | auto& column = downcast<AccessibilityTableColumn>(*axCache->getOrCreate(ColumnRole)); |
| 404 | column.setColumnIndex((int)i); |
| 405 | column.setParent(this); |
| 406 | m_columns.append(&column); |
| 407 | if (!column.accessibilityIsIgnored()) |
| 408 | m_children.append(&column); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | AccessibilityObject* headerContainerObject = headerContainer(); |
eric@webkit.org | fad8d12 | 2010-03-08 21:06:08 +0000 | [diff] [blame] | 412 | if (headerContainerObject && !headerContainerObject->accessibilityIsIgnored()) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 413 | m_children.append(headerContainerObject); |
commit-queue@webkit.org | 9e9e3f0 | 2015-07-17 23:32:30 +0000 | [diff] [blame] | 414 | |
| 415 | // Sometimes the cell gets the wrong role initially because it is created before the parent |
| 416 | // determines whether it is an accessibility table. Iterate all the cells and allow them to |
| 417 | // update their roles now that the table knows its status. |
| 418 | // see bug: https://bugs.webkit.org/show_bug.cgi?id=147001 |
| 419 | for (const auto& row : m_rows) { |
| 420 | for (const auto& cell : row->children()) |
| 421 | cell->updateAccessibilityRole(); |
| 422 | } |
| 423 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 424 | } |
cfleizach@apple.com | 7c95c0c | 2014-04-29 16:15:14 +0000 | [diff] [blame] | 425 | |
commit-queue@webkit.org | ac97cff | 2015-08-10 01:53:10 +0000 | [diff] [blame] | 426 | void AccessibilityTable::addTableCellChild(AccessibilityObject* rowObject, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount) |
| 427 | { |
| 428 | if (!rowObject || !is<AccessibilityTableRow>(*rowObject)) |
| 429 | return; |
| 430 | |
| 431 | auto& row = downcast<AccessibilityTableRow>(*rowObject); |
| 432 | // We need to check every cell for a new row, because cell spans |
| 433 | // can cause us to miss rows if we just check the first column. |
| 434 | if (appendedRows.contains(&row)) |
| 435 | return; |
| 436 | |
| 437 | row.setRowIndex(static_cast<int>(m_rows.size())); |
| 438 | m_rows.append(&row); |
| 439 | if (!row.accessibilityIsIgnored()) |
| 440 | m_children.append(&row); |
| 441 | appendedRows.add(&row); |
| 442 | |
| 443 | // store the maximum number of columns |
| 444 | unsigned rowCellCount = row.children().size(); |
| 445 | if (rowCellCount > columnCount) |
| 446 | columnCount = rowCellCount; |
| 447 | } |
| 448 | |
cfleizach@apple.com | 7c95c0c | 2014-04-29 16:15:14 +0000 | [diff] [blame] | 449 | void AccessibilityTable::addChildrenFromSection(RenderTableSection* tableSection, unsigned& maxColumnCount) |
| 450 | { |
| 451 | ASSERT(tableSection); |
| 452 | if (!tableSection) |
| 453 | return; |
| 454 | |
| 455 | AXObjectCache* axCache = m_renderer->document().axObjectCache(); |
| 456 | HashSet<AccessibilityObject*> appendedRows; |
| 457 | unsigned numRows = tableSection->numRows(); |
| 458 | for (unsigned rowIndex = 0; rowIndex < numRows; ++rowIndex) { |
| 459 | |
| 460 | RenderTableRow* renderRow = tableSection->rowRendererAt(rowIndex); |
| 461 | if (!renderRow) |
| 462 | continue; |
| 463 | |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 464 | AccessibilityObject& rowObject = *axCache->getOrCreate(renderRow); |
cfleizach@apple.com | 7c95c0c | 2014-04-29 16:15:14 +0000 | [diff] [blame] | 465 | |
commit-queue@webkit.org | ac97cff | 2015-08-10 01:53:10 +0000 | [diff] [blame] | 466 | // If the row is anonymous, we should dive deeper into the descendants to try to find a valid row. |
| 467 | if (renderRow->isAnonymous()) { |
| 468 | Deque<AccessibilityObject*> queue; |
| 469 | queue.append(&rowObject); |
| 470 | |
| 471 | while (!queue.isEmpty()) { |
| 472 | AccessibilityObject* obj = queue.takeFirst(); |
| 473 | if (obj->node() && is<AccessibilityTableRow>(*obj)) { |
| 474 | addTableCellChild(obj, appendedRows, maxColumnCount); |
| 475 | continue; |
| 476 | } |
| 477 | for (auto child = obj->firstChild(); child; child = child->nextSibling()) |
| 478 | queue.append(child); |
| 479 | } |
| 480 | } else |
| 481 | addTableCellChild(&rowObject, appendedRows, maxColumnCount); |
cfleizach@apple.com | 7c95c0c | 2014-04-29 16:15:14 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | maxColumnCount = std::max(tableSection->numColumns(), maxColumnCount); |
| 485 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 486 | |
| 487 | AccessibilityObject* AccessibilityTable::headerContainer() |
| 488 | { |
| 489 | if (m_headerContainer) |
cfleizach@apple.com | 04c1617 | 2011-12-12 23:54:37 +0000 | [diff] [blame] | 490 | return m_headerContainer.get(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 491 | |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 492 | auto& tableHeader = downcast<AccessibilityMockObject>(*axObjectCache()->getOrCreate(TableHeaderContainerRole)); |
| 493 | tableHeader.setParent(this); |
cfleizach@apple.com | 04c1617 | 2011-12-12 23:54:37 +0000 | [diff] [blame] | 494 | |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 495 | m_headerContainer = &tableHeader; |
cfleizach@apple.com | 04c1617 | 2011-12-12 23:54:37 +0000 | [diff] [blame] | 496 | return m_headerContainer.get(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 497 | } |
| 498 | |
cfleizach@apple.com | e1cbd81 | 2014-01-29 01:05:07 +0000 | [diff] [blame] | 499 | const AccessibilityObject::AccessibilityChildrenVector& AccessibilityTable::columns() |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 500 | { |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 501 | updateChildrenIfNecessary(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 502 | |
| 503 | return m_columns; |
| 504 | } |
| 505 | |
cfleizach@apple.com | e1cbd81 | 2014-01-29 01:05:07 +0000 | [diff] [blame] | 506 | const AccessibilityObject::AccessibilityChildrenVector& AccessibilityTable::rows() |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 507 | { |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 508 | updateChildrenIfNecessary(); |
| 509 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 510 | return m_rows; |
| 511 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 512 | |
| 513 | void AccessibilityTable::columnHeaders(AccessibilityChildrenVector& headers) |
| 514 | { |
| 515 | if (!m_renderer) |
| 516 | return; |
| 517 | |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 518 | updateChildrenIfNecessary(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 519 | |
cfleizach@apple.com | 421baa1 | 2014-01-14 18:09:51 +0000 | [diff] [blame] | 520 | for (const auto& column : m_columns) { |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 521 | if (AccessibilityObject* header = downcast<AccessibilityTableColumn>(*column).headerObject()) |
samuel_white@apple.com | e722c50 | 2013-11-19 00:32:44 +0000 | [diff] [blame] | 522 | headers.append(header); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 523 | } |
| 524 | } |
samuel_white@apple.com | e722c50 | 2013-11-19 00:32:44 +0000 | [diff] [blame] | 525 | |
| 526 | void AccessibilityTable::rowHeaders(AccessibilityChildrenVector& headers) |
| 527 | { |
| 528 | if (!m_renderer) |
| 529 | return; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 530 | |
samuel_white@apple.com | e722c50 | 2013-11-19 00:32:44 +0000 | [diff] [blame] | 531 | updateChildrenIfNecessary(); |
| 532 | |
cfleizach@apple.com | 421baa1 | 2014-01-14 18:09:51 +0000 | [diff] [blame] | 533 | for (const auto& row : m_rows) { |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 534 | if (AccessibilityObject* header = downcast<AccessibilityTableRow>(*row).headerObject()) |
samuel_white@apple.com | e722c50 | 2013-11-19 00:32:44 +0000 | [diff] [blame] | 535 | headers.append(header); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | void AccessibilityTable::visibleRows(AccessibilityChildrenVector& rows) |
| 540 | { |
| 541 | if (!m_renderer) |
| 542 | return; |
| 543 | |
| 544 | updateChildrenIfNecessary(); |
| 545 | |
cfleizach@apple.com | 421baa1 | 2014-01-14 18:09:51 +0000 | [diff] [blame] | 546 | for (const auto& row : m_rows) { |
samuel_white@apple.com | e722c50 | 2013-11-19 00:32:44 +0000 | [diff] [blame] | 547 | if (row && !row->isOffScreen()) |
| 548 | rows.append(row); |
| 549 | } |
| 550 | } |
| 551 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 552 | void AccessibilityTable::cells(AccessibilityObject::AccessibilityChildrenVector& cells) |
| 553 | { |
| 554 | if (!m_renderer) |
| 555 | return; |
| 556 | |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 557 | updateChildrenIfNecessary(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 558 | |
cfleizach@apple.com | 421baa1 | 2014-01-14 18:09:51 +0000 | [diff] [blame] | 559 | for (const auto& row : m_rows) |
| 560 | cells.appendVector(row->children()); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 561 | } |
| 562 | |
darin@apple.com | 0558f4c | 2009-05-17 16:50:21 +0000 | [diff] [blame] | 563 | unsigned AccessibilityTable::columnCount() |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 564 | { |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 565 | updateChildrenIfNecessary(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 566 | |
| 567 | return m_columns.size(); |
| 568 | } |
| 569 | |
darin@apple.com | 0558f4c | 2009-05-17 16:50:21 +0000 | [diff] [blame] | 570 | unsigned AccessibilityTable::rowCount() |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 571 | { |
cfleizach@apple.com | e4893cb | 2010-03-02 01:19:25 +0000 | [diff] [blame] | 572 | updateChildrenIfNecessary(); |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 573 | |
| 574 | return m_rows.size(); |
| 575 | } |
commit-queue@webkit.org | 35c6d9e | 2011-07-29 17:37:31 +0000 | [diff] [blame] | 576 | |
| 577 | int AccessibilityTable::tableLevel() const |
| 578 | { |
| 579 | int level = 0; |
commit-queue@webkit.org | e262e74 | 2011-08-17 18:28:02 +0000 | [diff] [blame] | 580 | for (AccessibilityObject* obj = static_cast<AccessibilityObject*>(const_cast<AccessibilityTable*>(this)); obj; obj = obj->parentObject()) { |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 581 | if (is<AccessibilityTable>(*obj) && downcast<AccessibilityTable>(*obj).isExposableThroughAccessibility()) |
commit-queue@webkit.org | 35c6d9e | 2011-07-29 17:37:31 +0000 | [diff] [blame] | 582 | ++level; |
| 583 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 584 | |
commit-queue@webkit.org | 35c6d9e | 2011-07-29 17:37:31 +0000 | [diff] [blame] | 585 | return level; |
| 586 | } |
| 587 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 588 | AccessibilityTableCell* AccessibilityTable::cellForColumnAndRow(unsigned column, unsigned row) |
| 589 | { |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 590 | updateChildrenIfNecessary(); |
| 591 | if (column >= columnCount() || row >= rowCount()) |
mmaxfield@apple.com | 890554f | 2014-07-23 14:57:15 +0000 | [diff] [blame] | 592 | return nullptr; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 593 | |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 594 | // Iterate backwards through the rows in case the desired cell has a rowspan and exists in a previous row. |
| 595 | for (unsigned rowIndexCounter = row + 1; rowIndexCounter > 0; --rowIndexCounter) { |
| 596 | unsigned rowIndex = rowIndexCounter - 1; |
cfleizach@apple.com | 421baa1 | 2014-01-14 18:09:51 +0000 | [diff] [blame] | 597 | const auto& children = m_rows[rowIndex]->children(); |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 598 | // Since some cells may have colspans, we have to check the actual range of each |
| 599 | // cell to determine which is the right one. |
| 600 | for (unsigned colIndexCounter = std::min(static_cast<unsigned>(children.size()), column + 1); colIndexCounter > 0; --colIndexCounter) { |
| 601 | unsigned colIndex = colIndexCounter - 1; |
| 602 | AccessibilityObject* child = children[colIndex].get(); |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 603 | ASSERT(is<AccessibilityTableCell>(*child)); |
| 604 | if (!is<AccessibilityTableCell>(*child)) |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 605 | continue; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 606 | |
zandobersek@gmail.com | 83a3119 | 2014-01-04 17:26:52 +0000 | [diff] [blame] | 607 | std::pair<unsigned, unsigned> columnRange; |
| 608 | std::pair<unsigned, unsigned> rowRange; |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 609 | auto& tableCellChild = downcast<AccessibilityTableCell>(*child); |
| 610 | tableCellChild.columnIndexRange(columnRange); |
| 611 | tableCellChild.rowIndexRange(rowRange); |
cfleizach@apple.com | 55378e4 | 2013-03-05 07:13:46 +0000 | [diff] [blame] | 612 | |
| 613 | if ((column >= columnRange.first && column < (columnRange.first + columnRange.second)) |
| 614 | && (row >= rowRange.first && row < (rowRange.first + rowRange.second))) |
cdumez@apple.com | 234cbdc | 2014-10-20 19:08:40 +0000 | [diff] [blame] | 615 | return &tableCellChild; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 616 | } |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 617 | } |
| 618 | |
mmaxfield@apple.com | 890554f | 2014-07-23 14:57:15 +0000 | [diff] [blame] | 619 | return nullptr; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | AccessibilityRole AccessibilityTable::roleValue() const |
| 623 | { |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 624 | if (!isExposableThroughAccessibility()) |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 625 | return AccessibilityRenderObject::roleValue(); |
commit-queue@webkit.org | 893f27c | 2015-07-10 22:04:50 +0000 | [diff] [blame] | 626 | |
| 627 | AccessibilityRole ariaRole = ariaRoleAttribute(); |
| 628 | if (ariaRole == GridRole || ariaRole == TreeGridRole) |
| 629 | return GridRole; |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 630 | |
| 631 | return TableRole; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 632 | } |
| 633 | |
dmazzoni@google.com | 3b5179d | 2013-02-09 23:06:00 +0000 | [diff] [blame] | 634 | bool AccessibilityTable::computeAccessibilityIsIgnored() const |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 635 | { |
cfleizach@apple.com | a9eba45 | 2013-03-16 08:51:52 +0000 | [diff] [blame] | 636 | AccessibilityObjectInclusion decision = defaultObjectInclusion(); |
cfleizach@apple.com | 14f57ce | 2010-03-11 22:24:33 +0000 | [diff] [blame] | 637 | if (decision == IncludeObject) |
| 638 | return false; |
| 639 | if (decision == IgnoreObject) |
cfleizach@apple.com | 6f3a569 | 2010-03-11 00:36:02 +0000 | [diff] [blame] | 640 | return true; |
cfleizach@apple.com | 14f57ce | 2010-03-11 22:24:33 +0000 | [diff] [blame] | 641 | |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 642 | if (!isExposableThroughAccessibility()) |
dmazzoni@google.com | 3b5179d | 2013-02-09 23:06:00 +0000 | [diff] [blame] | 643 | return AccessibilityRenderObject::computeAccessibilityIsIgnored(); |
cfleizach@apple.com | 6f3a569 | 2010-03-11 00:36:02 +0000 | [diff] [blame] | 644 | |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 645 | return false; |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 646 | } |
commit-queue@webkit.org | 0572ed1 | 2013-10-03 23:29:25 +0000 | [diff] [blame] | 647 | |
| 648 | void AccessibilityTable::titleElementText(Vector<AccessibilityText>& textOrder) const |
| 649 | { |
| 650 | String title = this->title(); |
| 651 | if (!title.isEmpty()) |
| 652 | textOrder.append(AccessibilityText(title, LabelByElementText)); |
| 653 | } |
| 654 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 655 | String AccessibilityTable::title() const |
| 656 | { |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 657 | if (!isExposableThroughAccessibility()) |
cfleizach@apple.com | 2a72d8f | 2008-09-18 22:54:37 +0000 | [diff] [blame] | 658 | return AccessibilityRenderObject::title(); |
| 659 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 660 | String title; |
| 661 | if (!m_renderer) |
| 662 | return title; |
| 663 | |
| 664 | // see if there is a caption |
hyatt@apple.com | 7e03253 | 2009-02-11 22:06:32 +0000 | [diff] [blame] | 665 | Node* tableElement = m_renderer->node(); |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 666 | if (is<HTMLTableElement>(tableElement)) { |
cdumez@apple.com | 72754ba | 2014-09-23 22:03:15 +0000 | [diff] [blame] | 667 | if (HTMLTableCaptionElement* caption = downcast<HTMLTableElement>(*tableElement).caption()) |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 668 | title = caption->innerText(); |
| 669 | } |
| 670 | |
| 671 | // try the standard |
| 672 | if (title.isEmpty()) |
| 673 | title = AccessibilityRenderObject::title(); |
| 674 | |
| 675 | return title; |
| 676 | } |
| 677 | |
cfleizach@apple.com | 7c7b5f3 | 2008-08-19 22:05:37 +0000 | [diff] [blame] | 678 | } // namespace WebCore |