Diff
Modified: trunk/Source/WebCore/ChangeLog (94775 => 94776)
--- trunk/Source/WebCore/ChangeLog 2011-09-08 18:46:01 UTC (rev 94775)
+++ trunk/Source/WebCore/ChangeLog 2011-09-08 18:53:02 UTC (rev 94776)
@@ -1,3 +1,47 @@
+2011-09-08 Julien Chaffraix <jchaffr...@webkit.org>
+
+ Factor out the code to get the first non-null RenderTableSection in RenderTable
+ https://bugs.webkit.org/show_bug.cgi?id=66972
+
+ Reviewed by Darin Adler.
+
+ Refactoring only, covered by existing tests.
+
+ * accessibility/AccessibilityTable.cpp:
+ (WebCore::AccessibilityTable::addChildren):
+ (WebCore::AccessibilityTable::cellForColumnAndRow):
+ * accessibility/AccessibilityTableCell.cpp:
+ (WebCore::AccessibilityTableCell::rowIndexRange):
+ Updated those for the signature change in sectionBelow. Also added
+ a FIXME where topSection should be used instead of iterating
+ over the section (and likely missing some corner cases).
+
+ * rendering/FixedTableLayout.cpp:
+ (WebCore::FixedTableLayout::calcWidthArray):
+ * rendering/RenderTable.cpp:
+ (WebCore::RenderTable::calcBorderStart):
+ (WebCore::RenderTable::calcBorderEnd):
+ (WebCore::RenderTable::outerBorderBefore):
+ (WebCore::RenderTable::sectionAbove):
+ (WebCore::RenderTable::sectionBelow):
+ (WebCore::RenderTable::firstLineBoxBaseline):
+ Updated all those functions to use the newly added functions. Also changed
+ the variable names to match the functions.
+
+ (WebCore::RenderTable::layout):
+ (WebCore::RenderTable::topNonEmptySection): Newly added function
+ that returns the top non null section of the table that has at least a
+ row.
+
+ (WebCore::RenderTable::cellAbove):
+ (WebCore::RenderTable::cellBelow):
+ Update the signature of those 2 functions to take an enum as it makes the
+ rest of the code more readable.
+
+ * rendering/RenderTable.h:
+ (WebCore::RenderTable::topSection): Newly added function to return
+ the top non null section in the table.
+
2011-04-19 Eric Seidel <e...@webkit.org>
Reviewed by Ryosuke Niwa.
Modified: trunk/Source/WebCore/accessibility/AccessibilityTable.cpp (94775 => 94776)
--- trunk/Source/WebCore/accessibility/AccessibilityTable.cpp 2011-09-08 18:46:01 UTC (rev 94775)
+++ trunk/Source/WebCore/accessibility/AccessibilityTable.cpp 2011-09-08 18:53:02 UTC (rev 94776)
@@ -299,6 +299,7 @@
// go through all the available sections to pull out the rows
// and add them as children
+ // FIXME: This will skip a table with just a tfoot. Should fix by using RenderTable::topSection.
RenderTableSection* tableSection = table->header();
if (!tableSection)
tableSection = table->firstBody();
@@ -343,7 +344,7 @@
}
}
- tableSection = table->sectionBelow(tableSection, true);
+ tableSection = table->sectionBelow(tableSection, SkipEmptySections);
}
// make the columns based on the number of columns in the first body
@@ -466,6 +467,7 @@
updateChildrenIfNecessary();
RenderTable* table = toRenderTable(m_renderer);
+ // FIXME: This will skip a table with just a tfoot. Should fix by using RenderTable::topSection.
RenderTableSection* tableSection = table->header();
if (!tableSection)
tableSection = table->firstBody();
@@ -517,7 +519,7 @@
// we didn't find anything between the rows we should have
if (row < rowCount)
break;
- tableSection = table->sectionBelow(tableSection, true);
+ tableSection = table->sectionBelow(tableSection, SkipEmptySections);
}
if (!cell)
Modified: trunk/Source/WebCore/accessibility/AccessibilityTableCell.cpp (94775 => 94776)
--- trunk/Source/WebCore/accessibility/AccessibilityTableCell.cpp 2011-09-08 18:46:01 UTC (rev 94775)
+++ trunk/Source/WebCore/accessibility/AccessibilityTableCell.cpp 2011-09-08 18:53:02 UTC (rev 94776)
@@ -112,7 +112,8 @@
RenderTable* table = renderCell->table();
if (!table || !section)
return;
-
+
+ // FIXME: This will skip a table with just a tfoot. Should fix by using RenderTable::topSection.
RenderTableSection* tableSection = table->header();
if (!tableSection)
tableSection = table->firstBody();
@@ -122,7 +123,7 @@
if (tableSection == section)
break;
rowOffset += tableSection->numRows();
- tableSection = table->sectionBelow(tableSection, true);
+ tableSection = table->sectionBelow(tableSection, SkipEmptySections);
}
rowRange.first += rowOffset;
Modified: trunk/Source/WebCore/rendering/FixedTableLayout.cpp (94775 => 94776)
--- trunk/Source/WebCore/rendering/FixedTableLayout.cpp 2011-09-08 18:46:01 UTC (rev 94775)
+++ trunk/Source/WebCore/rendering/FixedTableLayout.cpp 2011-09-08 18:53:02 UTC (rev 94776)
@@ -139,13 +139,7 @@
}
// Iterate over the first row in case some are unspecified.
- RenderTableSection* section = m_table->header();
- if (!section)
- section = m_table->firstBody();
- if (!section)
- section = m_table->footer();
- if (section && !section->numRows())
- section = m_table->sectionBelow(section, true);
+ RenderTableSection* section = m_table->topNonEmptySection();
if (section) {
int cCol = 0;
RenderObject* firstRow = section->firstChild();
Modified: trunk/Source/WebCore/rendering/RenderTable.cpp (94775 => 94776)
--- trunk/Source/WebCore/rendering/RenderTable.cpp 2011-09-08 18:46:01 UTC (rev 94775)
+++ trunk/Source/WebCore/rendering/RenderTable.cpp 2011-09-08 18:53:02 UTC (rev 94776)
@@ -370,7 +370,7 @@
sectionLogicalLeft += style()->isLeftToRightDirection() ? paddingStart() : paddingEnd();
// position the table sections
- RenderTableSection* section = m_head ? m_head : (m_firstBody ? m_firstBody : m_foot);
+ RenderTableSection* section = topSection();
while (section) {
if (!sectionMoved && section->logicalTop() != logicalHeight()) {
sectionMoved = true;
@@ -593,6 +593,14 @@
setPreferredLogicalWidthsDirty(false);
}
+RenderTableSection* RenderTable::topNonEmptySection() const
+{
+ RenderTableSection* section = topSection();
+ if (section && !section->numRows())
+ section = sectionBelow(section, SkipEmptySections);
+ return section;
+}
+
void RenderTable::splitColumn(int pos, int firstSpan)
{
// we need to add a new columnStruct
@@ -800,19 +808,15 @@
borderWidth = max<LayoutUnit>(borderWidth, gb.width());
}
- RenderTableSection* firstNonEmptySection = m_head ? m_head : (m_firstBody ? m_firstBody : m_foot);
- if (firstNonEmptySection && !firstNonEmptySection->numRows())
- firstNonEmptySection = sectionBelow(firstNonEmptySection, true);
-
- if (firstNonEmptySection) {
- const BorderValue& sb = firstNonEmptySection->style()->borderStart();
+ if (const RenderTableSection* topNonEmptySection = this->topNonEmptySection()) {
+ const BorderValue& sb = topNonEmptySection->style()->borderStart();
if (sb.style() == BHIDDEN)
return 0;
if (sb.style() > BHIDDEN)
borderWidth = max<LayoutUnit>(borderWidth, sb.width());
- const RenderTableSection::CellStruct& cs = firstNonEmptySection->cellAt(0, 0);
+ const RenderTableSection::CellStruct& cs = topNonEmptySection->cellAt(0, 0);
if (cs.hasCells()) {
const BorderValue& cb = cs.primaryCell()->style()->borderStart(); // FIXME: Make this work with perpendicualr and flipped cells.
@@ -857,20 +861,16 @@
if (gb.style() > BHIDDEN)
borderWidth = max<LayoutUnit>(borderWidth, gb.width());
}
-
- RenderTableSection* firstNonEmptySection = m_head ? m_head : (m_firstBody ? m_firstBody : m_foot);
- if (firstNonEmptySection && !firstNonEmptySection->numRows())
- firstNonEmptySection = sectionBelow(firstNonEmptySection, true);
-
- if (firstNonEmptySection) {
- const BorderValue& sb = firstNonEmptySection->style()->borderEnd();
+
+ if (const RenderTableSection* topNonEmptySection = this->topNonEmptySection()) {
+ const BorderValue& sb = topNonEmptySection->style()->borderEnd();
if (sb.style() == BHIDDEN)
return 0;
if (sb.style() > BHIDDEN)
borderWidth = max<LayoutUnit>(borderWidth, sb.width());
- const RenderTableSection::CellStruct& cs = firstNonEmptySection->cellAt(0, endColumn);
+ const RenderTableSection::CellStruct& cs = topNonEmptySection->cellAt(0, endColumn);
if (cs.hasCells()) {
const BorderValue& cb = cs.primaryCell()->style()->borderEnd(); // FIXME: Make this work with perpendicular and flipped cells.
@@ -917,16 +917,7 @@
if (!collapseBorders())
return 0;
LayoutUnit borderWidth = 0;
- RenderTableSection* topSection;
- if (m_head)
- topSection = m_head;
- else if (m_firstBody)
- topSection = m_firstBody;
- else if (m_foot)
- topSection = m_foot;
- else
- topSection = 0;
- if (topSection) {
+ if (RenderTableSection* topSection = this->topSection()) {
borderWidth = topSection->outerBorderBefore();
if (borderWidth < 0)
return 0; // Overridden by hidden
@@ -1023,7 +1014,7 @@
return borderWidth;
}
-RenderTableSection* RenderTable::sectionAbove(const RenderTableSection* section, bool skipEmptySections) const
+RenderTableSection* RenderTable::sectionAbove(const RenderTableSection* section, SkipEmptySectionsValue skipEmptySections) const
{
recalcSectionsIfNeeded();
@@ -1032,16 +1023,16 @@
RenderObject* prevSection = section == m_foot ? lastChild() : section->previousSibling();
while (prevSection) {
- if (prevSection->isTableSection() && prevSection != m_head && prevSection != m_foot && (!skipEmptySections || toRenderTableSection(prevSection)->numRows()))
+ if (prevSection->isTableSection() && prevSection != m_head && prevSection != m_foot && (skipEmptySections == DoNotSkipEmptySections || toRenderTableSection(prevSection)->numRows()))
break;
prevSection = prevSection->previousSibling();
}
- if (!prevSection && m_head && (!skipEmptySections || m_head->numRows()))
+ if (!prevSection && m_head && (skipEmptySections == DoNotSkipEmptySections || m_head->numRows()))
prevSection = m_head;
return toRenderTableSection(prevSection);
}
-RenderTableSection* RenderTable::sectionBelow(const RenderTableSection* section, bool skipEmptySections) const
+RenderTableSection* RenderTable::sectionBelow(const RenderTableSection* section, SkipEmptySectionsValue skipEmptySections) const
{
recalcSectionsIfNeeded();
@@ -1050,11 +1041,11 @@
RenderObject* nextSection = section == m_head ? firstChild() : section->nextSibling();
while (nextSection) {
- if (nextSection->isTableSection() && nextSection != m_head && nextSection != m_foot && (!skipEmptySections || toRenderTableSection(nextSection)->numRows()))
+ if (nextSection->isTableSection() && nextSection != m_head && nextSection != m_foot && (skipEmptySections == DoNotSkipEmptySections || toRenderTableSection(nextSection)->numRows()))
break;
nextSection = nextSection->nextSibling();
}
- if (!nextSection && m_foot && (!skipEmptySections || m_foot->numRows()))
+ if (!nextSection && m_foot && (skipEmptySections == DoNotSkipEmptySections || m_foot->numRows()))
nextSection = m_foot;
return toRenderTableSection(nextSection);
}
@@ -1072,7 +1063,7 @@
section = cell->section();
rAbove = r - 1;
} else {
- section = sectionAbove(cell->section(), true);
+ section = sectionAbove(cell->section(), SkipEmptySections);
if (section)
rAbove = section->numRows() - 1;
}
@@ -1099,7 +1090,7 @@
section = cell->section();
rBelow = r + 1;
} else {
- section = sectionBelow(cell->section(), true);
+ section = sectionBelow(cell->section(), SkipEmptySections);
if (section)
rBelow = 0;
}
@@ -1153,14 +1144,11 @@
recalcSectionsIfNeeded();
- RenderTableSection* firstNonEmptySection = m_head ? m_head : (m_firstBody ? m_firstBody : m_foot);
- if (firstNonEmptySection && !firstNonEmptySection->numRows())
- firstNonEmptySection = sectionBelow(firstNonEmptySection, true);
-
- if (!firstNonEmptySection)
+ const RenderTableSection* topNonEmptySection = this->topNonEmptySection();
+ if (!topNonEmptySection)
return -1;
- return firstNonEmptySection->logicalTop() + firstNonEmptySection->firstLineBoxBaseline();
+ return topNonEmptySection->logicalTop() + topNonEmptySection->firstLineBoxBaseline();
}
LayoutRect RenderTable::overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy relevancy)
Modified: trunk/Source/WebCore/rendering/RenderTable.h (94775 => 94776)
--- trunk/Source/WebCore/rendering/RenderTable.h 2011-09-08 18:46:01 UTC (rev 94775)
+++ trunk/Source/WebCore/rendering/RenderTable.h 2011-09-08 18:53:02 UTC (rev 94776)
@@ -37,6 +37,8 @@
class RenderTableSection;
class TableLayout;
+enum SkipEmptySectionsValue { DoNotSkipEmptySections, SkipEmptySections };
+
class RenderTable : public RenderBlock {
public:
explicit RenderTable(Node*);
@@ -144,6 +146,12 @@
RenderTableSection* footer() const { return m_foot; }
RenderTableSection* firstBody() const { return m_firstBody; }
+ // This function returns 0 if the table has no section.
+ RenderTableSection* topSection() const;
+
+ // This function returns 0 if the table has no non-empty sections.
+ RenderTableSection* topNonEmptySection() const;
+
void splitColumn(int pos, int firstSpan);
void appendColumn(int span);
int numEffCols() const { return m_columns.size(); }
@@ -184,8 +192,8 @@
setNeedsLayout(true);
}
- RenderTableSection* sectionAbove(const RenderTableSection*, bool skipEmptySections = false) const;
- RenderTableSection* sectionBelow(const RenderTableSection*, bool skipEmptySections = false) const;
+ RenderTableSection* sectionAbove(const RenderTableSection*, SkipEmptySectionsValue = DoNotSkipEmptySections) const;
+ RenderTableSection* sectionBelow(const RenderTableSection*, SkipEmptySectionsValue = DoNotSkipEmptySections) const;
RenderTableCell* cellAbove(const RenderTableCell*) const;
RenderTableCell* cellBelow(const RenderTableCell*) const;
@@ -262,6 +270,15 @@
LayoutUnit m_borderEnd;
};
+inline RenderTableSection* RenderTable::topSection() const
+{
+ if (m_head)
+ return m_head;
+ if (m_firstBody)
+ return m_firstBody;
+ return m_foot;
+}
+
inline RenderTable* toRenderTable(RenderObject* object)
{
ASSERT(!object || object->isTable());