Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: Source/modules/accessibility/AXTableColumn.cpp

Issue 942183003: Remove some redundant code from accessibility table headers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 return; 89 return;
90 } 90 }
91 91
92 if (!renderer->isTable()) 92 if (!renderer->isTable())
93 return; 93 return;
94 94
95 LayoutTable* table = toLayoutTable(renderer); 95 LayoutTable* table = toLayoutTable(renderer);
96 LayoutTableSection* tableSection = table->topSection(); 96 LayoutTableSection* tableSection = table->topSection();
97 for (; tableSection; tableSection = table->sectionBelow(tableSection, SkipEm ptySections)) { 97 for (; tableSection; tableSection = table->sectionBelow(tableSection, SkipEm ptySections)) {
98 unsigned numCols = tableSection->numColumns();
99 if (m_columnIndex >= numCols)
100 continue;
98 unsigned numRows = tableSection->numRows(); 101 unsigned numRows = tableSection->numRows();
99 for (unsigned r = 0; r < numRows; r++) { 102 for (unsigned r = 0; r < numRows; r++) {
100 LayoutTableCell* layoutCell = tableSection->primaryCellAt(r, m_colum nIndex); 103 LayoutTableCell* layoutCell = tableSection->primaryCellAt(r, m_colum nIndex);
101 if (!layoutCell) 104 if (!layoutCell)
102 continue; 105 continue;
103 106
104 // Whenever cell's effective col is less then current column index, we've found the cell with colspan.
105 // We do not need to add this cell, it's already been added.
106 if (layoutCell->table()->colToEffCol(layoutCell->col()) < m_columnIn dex)
107 continue;
108
109 AXObject* cell = axObjectCache()->getOrCreate(layoutCell->node()); 107 AXObject* cell = axObjectCache()->getOrCreate(layoutCell->node());
110 if (!cell || !cell->isTableCell()) 108 if (!cell || !cell->isTableCell() || headers.contains(cell))
111 continue; 109 continue;
112 110
113 if (toAXTableCell(cell)->scanToDecideHeaderRole() == ColumnHeaderRol e) 111 if (toAXTableCell(cell)->scanToDecideHeaderRole() == ColumnHeaderRol e)
114 headers.append(cell); 112 headers.append(cell);
115 } 113 }
116 } 114 }
117 } 115 }
118 116
119 AXObject* AXTableColumn::headerObject() 117 AXObject* AXTableColumn::headerObject()
120 { 118 {
121 if (!m_parent) 119 AccessibilityChildrenVector headers;
120 headerObjectsForColumn(headers);
121 if (!headers.size())
122 return 0; 122 return 0;
123 123
124 LayoutObject* renderer = m_parent->renderer(); 124 return headers[0].get();
125 if (!renderer)
126 return 0;
127
128 if (!m_parent->isAXTable())
129 return 0;
130
131 AXTable* parentTable = toAXTable(m_parent);
132 if (parentTable->isAriaTable()) {
133 AccessibilityChildrenVector rowChildren = children();
134 unsigned childrenCount = rowChildren.size();
135 for (unsigned i = 0; i < childrenCount; ++i) {
136 AXObject* cell = rowChildren[i].get();
137 if (cell->ariaRoleAttribute() == ColumnHeaderRole)
138 return cell;
139 }
140
141 return 0;
142 }
143
144 if (!renderer->isTable())
145 return 0;
146
147 LayoutTable* table = toLayoutTable(renderer);
148
149 AXObject* headerObject = 0;
150
151 // try the <thead> section first. this doesn't require th tags
152 headerObject = headerObjectForSection(table->header(), false);
153
154 if (headerObject)
155 return headerObject;
156
157 // now try for <th> tags in the first body
158 headerObject = headerObjectForSection(table->firstBody(), true);
159
160 return headerObject;
161 }
162
163 AXObject* AXTableColumn::headerObjectForSection(LayoutTableSection* section, boo l thTagRequired)
164 {
165 if (!section)
166 return 0;
167
168 unsigned numCols = section->numColumns();
169 if (m_columnIndex >= numCols)
170 return 0;
171
172 if (!section->numRows())
173 return 0;
174
175 LayoutTableCell* cell = 0;
176 // also account for cells that have a span
177 for (int testCol = m_columnIndex; testCol >= 0; --testCol) {
178 LayoutTableCell* testCell = section->primaryCellAt(0, testCol);
179 if (!testCell)
180 continue;
181
182 // we've reached a cell that doesn't even overlap our column
183 // it can't be our header
184 if (testCell->table()->colToEffCol(testCell->col() + (testCell->colSpan( )-1)) < m_columnIndex)
185 break;
186
187 Node* node = testCell->node();
188 if (!node)
189 continue;
190
191 if (thTagRequired && !node->hasTagName(thTag))
192 continue;
193
194 cell = testCell;
195 }
196
197 if (!cell)
198 return 0;
199
200 return axObjectCache()->getOrCreate(cell);
201 } 125 }
202 126
203 bool AXTableColumn::computeAccessibilityIsIgnored() const 127 bool AXTableColumn::computeAccessibilityIsIgnored() const
204 { 128 {
205 if (!m_parent) 129 if (!m_parent)
206 return true; 130 return true;
207 131
208 return m_parent->accessibilityIsIgnored(); 132 return m_parent->accessibilityIsIgnored();
209 } 133 }
210 134
(...skipping 16 matching lines...) Expand all
227 // make sure the last one isn't the same as this one (rowspan cells) 151 // make sure the last one isn't the same as this one (rowspan cells)
228 if (m_children.size() > 0 && m_children.last() == cell) 152 if (m_children.size() > 0 && m_children.last() == cell)
229 continue; 153 continue;
230 154
231 m_children.append(cell); 155 m_children.append(cell);
232 m_columnRect.unite(cell->elementRect()); 156 m_columnRect.unite(cell->elementRect());
233 } 157 }
234 } 158 }
235 159
236 } // namespace blink 160 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/accessibility/AXTableColumn.h ('k') | Source/modules/accessibility/AXTableRow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698