| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/TablePaintInvalidator.h" | 5 #include "core/paint/TablePaintInvalidator.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutTable.h" | 7 #include "core/layout/LayoutTable.h" |
| 8 #include "core/layout/LayoutTableCell.h" | 8 #include "core/layout/LayoutTableCell.h" |
| 9 #include "core/layout/LayoutTableCol.h" | 9 #include "core/layout/LayoutTableCol.h" |
| 10 #include "core/layout/LayoutTableRow.h" | 10 #include "core/layout/LayoutTableRow.h" |
| 11 #include "core/layout/LayoutTableSection.h" | 11 #include "core/layout/LayoutTableSection.h" |
| 12 #include "core/paint/BoxPaintInvalidator.h" | 12 #include "core/paint/BoxPaintInvalidator.h" |
| 13 #include "core/paint/PaintInvalidator.h" | 13 #include "core/paint/PaintInvalidator.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 PaintInvalidationReason TablePaintInvalidator::invalidatePaintIfNeeded() { | 17 PaintInvalidationReason TablePaintInvalidator::invalidatePaintIfNeeded() { |
| 18 PaintInvalidationReason reason = | 18 PaintInvalidationReason reason = |
| 19 BoxPaintInvalidator(m_table, m_context).invalidatePaintIfNeeded(); | 19 BoxPaintInvalidator(m_table, m_context).invalidatePaintIfNeeded(); |
| 20 | 20 |
| 21 // Table cells paint background from the containing column group, column, | 21 // If any col changed background, we need to invalidate all sections because |
| 22 // section and row. If background of any of them changed, we need to | 22 // col background paints into section's background display item. |
| 23 // invalidate all affected cells. Here use shouldDoFullPaintInvalidation() as | |
| 24 // a broader condition of background change. | |
| 25 | |
| 26 // If any col changed background, we'll check all cells for background | |
| 27 // changes. | |
| 28 bool hasColChangedBackground = false; | 23 bool hasColChangedBackground = false; |
| 29 bool visualRectChanged = m_context.oldVisualRect != m_table.visualRect(); | 24 if (m_table.hasColElements()) { |
| 30 for (LayoutTableCol* col = m_table.firstColumn(); col; | 25 bool visualRectChanged = m_context.oldVisualRect != m_table.visualRect(); |
| 31 col = col->nextColumn()) { | 26 for (LayoutTableCol* col = m_table.firstColumn(); col; |
| 32 // LayoutTableCol uses the table's localVisualRect(). Should check column | 27 col = col->nextColumn()) { |
| 33 // for paint invalidation when table's visual rect changed. | 28 // LayoutTableCol uses the table's localVisualRect(). Should check column |
| 34 if (visualRectChanged) | 29 // for paint invalidation when table's visual rect changed. |
| 35 col->setMayNeedPaintInvalidation(); | 30 if (visualRectChanged) |
| 36 // This ensures that the backgroundChangedSinceLastPaintInvalidation flag | 31 col->setMayNeedPaintInvalidation(); |
| 37 // is up-to-date. | 32 // This ensures that the backgroundChangedSinceLastPaintInvalidation flag |
| 38 col->ensureIsReadyForPaintInvalidation(); | 33 // is up-to-date. |
| 39 if (col->backgroundChangedSinceLastPaintInvalidation()) { | 34 col->ensureIsReadyForPaintInvalidation(); |
| 40 hasColChangedBackground = true; | 35 if (col->backgroundChangedSinceLastPaintInvalidation()) { |
| 41 break; | 36 hasColChangedBackground = true; |
| 42 } | 37 break; |
| 43 } | |
| 44 for (LayoutObject* child = m_table.firstChild(); child; | |
| 45 child = child->nextSibling()) { | |
| 46 if (!child->isTableSection()) | |
| 47 continue; | |
| 48 LayoutTableSection* section = toLayoutTableSection(child); | |
| 49 section->ensureIsReadyForPaintInvalidation(); | |
| 50 ObjectPaintInvalidator sectionInvalidator(*section); | |
| 51 if (!hasColChangedBackground && !section->shouldCheckForPaintInvalidation()) | |
| 52 continue; | |
| 53 for (LayoutTableRow* row = section->firstRow(); row; row = row->nextRow()) { | |
| 54 row->ensureIsReadyForPaintInvalidation(); | |
| 55 if (!hasColChangedBackground && | |
| 56 !section->backgroundChangedSinceLastPaintInvalidation() && | |
| 57 !row->backgroundChangedSinceLastPaintInvalidation()) | |
| 58 continue; | |
| 59 for (LayoutTableCell* cell = row->firstCell(); cell; | |
| 60 cell = cell->nextCell()) { | |
| 61 cell->ensureIsReadyForPaintInvalidation(); | |
| 62 bool invalidated = false; | |
| 63 // Table cells paint container's background on the container's backing | |
| 64 // instead of its own (if any), so we must invalidate it by the | |
| 65 // containers. | |
| 66 if (section->backgroundChangedSinceLastPaintInvalidation()) { | |
| 67 sectionInvalidator | |
| 68 .slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient( | |
| 69 cell->backgroundDisplayItemClient(), | |
| 70 PaintInvalidationStyleChange); | |
| 71 invalidated = true; | |
| 72 } else if (hasColChangedBackground) { | |
| 73 LayoutTable::ColAndColGroup colAndColGroup = | |
| 74 m_table.colElementAtAbsoluteColumn(cell->absoluteColumnIndex()); | |
| 75 LayoutTableCol* column = colAndColGroup.col; | |
| 76 LayoutTableCol* columnGroup = colAndColGroup.colgroup; | |
| 77 if ((columnGroup && | |
| 78 columnGroup->backgroundChangedSinceLastPaintInvalidation()) || | |
| 79 (column && | |
| 80 column->backgroundChangedSinceLastPaintInvalidation())) { | |
| 81 sectionInvalidator | |
| 82 .slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient( | |
| 83 cell->backgroundDisplayItemClient(), | |
| 84 PaintInvalidationStyleChange); | |
| 85 invalidated = true; | |
| 86 } | |
| 87 } | |
| 88 if ((!invalidated || row->hasSelfPaintingLayer()) && | |
| 89 row->backgroundChangedSinceLastPaintInvalidation()) { | |
| 90 ObjectPaintInvalidator(*row) | |
| 91 .slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient( | |
| 92 cell->backgroundDisplayItemClient(), | |
| 93 PaintInvalidationStyleChange); | |
| 94 } | |
| 95 } | 38 } |
| 96 } | 39 } |
| 97 } | 40 } |
| 98 | 41 |
| 42 if (hasColChangedBackground) { |
| 43 for (LayoutObject* child = m_table.firstChild(); child; |
| 44 child = child->nextSibling()) { |
| 45 if (!child->isTableSection()) |
| 46 continue; |
| 47 LayoutTableSection* section = toLayoutTableSection(child); |
| 48 section->ensureIsReadyForPaintInvalidation(); |
| 49 ObjectPaintInvalidator(*section) |
| 50 .slowSetPaintingLayerNeedsRepaintAndInvalidateDisplayItemClient( |
| 51 *section, PaintInvalidationStyleChange); |
| 52 } |
| 53 } |
| 54 |
| 99 return reason; | 55 return reason; |
| 100 } | 56 } |
| 101 | 57 |
| 102 } // namespace blink | 58 } // namespace blink |
| OLD | NEW |