Chromium Code Reviews| Index: third_party/WebKit/Source/core/paint/TableCellPainter.cpp |
| diff --git a/third_party/WebKit/Source/core/paint/TableCellPainter.cpp b/third_party/WebKit/Source/core/paint/TableCellPainter.cpp |
| index d30a77340c74afe4822b12116fa57d3f56be879b..973527f990cc7a4b48ca121ab3e34827aa4eb35c 100644 |
| --- a/third_party/WebKit/Source/core/paint/TableCellPainter.cpp |
| +++ b/third_party/WebKit/Source/core/paint/TableCellPainter.cpp |
| @@ -5,6 +5,7 @@ |
| #include "core/paint/TableCellPainter.h" |
| #include "core/layout/LayoutTableCell.h" |
| +#include "core/layout/LayoutTableCol.h" |
| #include "core/paint/BlockPainter.h" |
| #include "core/paint/BoxPainter.h" |
| #include "core/paint/LayoutObjectDrawingRecorder.h" |
| @@ -140,8 +141,13 @@ void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const L |
| } |
| } |
| -void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutObject* backgroundObject, DisplayItem::Type type) |
| +void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutBox* backgroundObject, DisplayItem::Type type) |
| { |
| + if (RuntimeEnabledFeatures::newTableCellBackgroundPaintingEnabled() && backgroundObject != &m_layoutTableCell) { |
| + paintParentBackgroundsBehindCell(paintInfo, paintOffset, backgroundObject, type); |
| + return; |
| + } |
| + |
| if (!backgroundObject) |
| return; |
| @@ -180,6 +186,68 @@ void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co |
| } |
| } |
| +void TableCellPainter::paintParentBackgroundsBehindCell(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutBox* backgroundObject, DisplayItem::Type type) |
| +{ |
| + if (!backgroundObject) |
| + return; |
| + |
| + if (m_layoutTableCell.style()->visibility() != VISIBLE) |
| + return; |
| + |
| + LayoutTable* tableElt = m_layoutTableCell.table(); |
|
Xianzhu
2016/03/28 00:44:43
s/tableElt/table/
atotic1
2016/03/29 17:05:17
Done.
|
| + if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) |
| + return; |
| + |
| + LayoutRect backgroundRect = paintBoundsParent(paintOffset, backgroundObject, type); |
| + |
| + LayoutRect cellRect = m_layoutTableCell.frameRect(); |
| + cellRect.moveBy(paintOffset); |
| + |
| + cellRect.setLocation(LayoutPoint(cellRect.pixelSnappedLocation())); |
| + cellRect.setSize(LayoutSize(cellRect.pixelSnappedSize())); |
| + |
| + // We paint background LTR, top->bottom. |
| + // This makes code much simpler, but is not spec-conformant. |
| + // The spec-conformant code would have to handle all writing-mode |
| + // painting directions correctly. |
|
Xianzhu
2016/03/28 00:44:42
Convert the above to a TODO, and reference a bug.
atotic1
2016/03/29 17:05:17
Done.
|
| + |
| + if (backgroundRect.x() > cellRect.x()) |
| + backgroundRect.setX(cellRect.x()); |
| + if (backgroundRect.y() > cellRect.y()) |
| + backgroundRect.setY(cellRect.y()); |
|
Xianzhu
2016/03/28 00:44:43
Why does this happen?
atotic1
2016/03/29 17:05:17
This happens when table is vertical. I've reworked
|
| + |
| + Optional<LayoutObjectDrawingRecorder> recorder; |
|
Xianzhu
2016/03/28 00:44:42
This recorder doesn't need to be optional. You can
atotic1
2016/03/29 17:05:17
Done.
|
| + if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_layoutTableCell, type)) { |
| + return; |
| + } |
| + recorder.emplace(paintInfo.context, m_layoutTableCell, type, cellRect); |
| + |
| + Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); |
|
Xianzhu
2016/03/28 00:44:42
s/c/color/
atotic1
2016/03/29 17:05:17
Done.
|
| + const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); |
|
Xianzhu
2016/03/28 00:44:43
s/bgLayer/backgroundLayer/
atotic1
2016/03/29 17:05:17
Done.
|
| + FillLayer bgAdjustedLayer(bgLayer); |
|
Xianzhu
2016/03/28 00:44:42
Not used?
atotic1
2016/03/29 17:05:17
Done.
|
| + |
| + if (bgLayer.hasImage() || c.alpha()) { |
| + |
| + GraphicsContextStateSaver stateSaver(paintInfo.context, true); |
| + LayoutRect clipRect(m_layoutTableCell.location(), m_layoutTableCell.size()); |
| + clipRect.moveBy(paintOffset); |
| + paintInfo.context.clip(pixelSnappedIntRect(clipRect)); |
| + |
| + // If cell is larger than background, we might have to paint multiple times. |
| + LayoutUnit colExtraPixels = std::max(LayoutUnit(0), cellRect.maxX() - backgroundRect.maxX()); |
| + unsigned colRepeat = 1 + (colExtraPixels / backgroundRect.width()) + (colExtraPixels % backgroundRect.width() != 0); |
| + LayoutUnit rowExtraPixels = std::max(LayoutUnit(0), cellRect.maxY() - backgroundRect.maxY()); |
| + unsigned rowRepeat = 1 + (rowExtraPixels / backgroundRect.height()) + (rowExtraPixels % backgroundRect.height() != 0); |
| + for (unsigned row = 0; row < rowRepeat; row++) { |
| + for (unsigned col = 0; col < colRepeat; col++) { |
| + LayoutRect paintRect = backgroundRect; |
| + paintRect.move(col * paintRect.width(), row * paintRect.height()); |
| + BoxPainter(*backgroundObject).paintFillLayers(paintInfo, c, bgLayer, paintRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject); |
| + } |
| + } |
|
Xianzhu
2016/03/28 00:44:43
The following case is broken with the code:
<!DOC
atotic1
2016/03/28 20:45:33
You are correct in that we fail this test case. My
Xianzhu
2016/03/28 21:26:04
Because the background bug has been there for a lo
|
| + } |
| +} |
| + |
| void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| { |
| LayoutTable* table = m_layoutTableCell.table(); |
| @@ -238,5 +306,41 @@ LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo |
| return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSnappedSize())); |
| } |
| +LayoutRect TableCellPainter::paintBoundsParent(const LayoutPoint& paintOffset, const LayoutBox* backgroundObject, DisplayItem::Type type) |
| +{ |
| + LayoutRect position; |
| + switch (type) { |
| + case DisplayItem::TableCellBackgroundFromColumnGroup: |
| + case DisplayItem::TableCellBackgroundFromColumn: |
| + { |
|
Xianzhu
2016/03/28 00:44:43
Put '{' at the end of the previous line.
atotic1
2016/03/29 17:05:17
Done.
|
| + position = static_cast<const LayoutTableCol*>(backgroundObject)->positionByCellSpan( |
| + m_layoutTableCell.absoluteColumnIndex()); |
| + // position is relative to table, must correct for section location |
| + LayoutPoint sectionLocation = m_layoutTableCell.section()->location(); |
| + position.moveBy(-sectionLocation); |
| + position.moveBy(paintOffset); |
| + } |
|
Xianzhu
2016/03/28 00:44:43
Put break inside of '}' and align '}' with 'case'.
atotic1
2016/03/29 17:05:17
Done.
|
| + break; |
| + case DisplayItem::TableCellBackgroundFromSection: |
|
Xianzhu
2016/03/28 00:44:42
We know TableCellSection's paint bounds in TableCe
atotic1
2016/03/29 17:05:17
How do we know TableSection bounds inside TableCel
|
| + position = static_cast<const LayoutTableSection*>(backgroundObject)->positionByCellSpan(); |
| + position.moveBy(paintOffset); |
| + break; |
| + case DisplayItem::TableCellBackgroundFromRow: |
| + position = static_cast<const LayoutTableRow*>(backgroundObject)->positionByCellSpan(); |
| + position.moveBy(paintOffset); |
| + break; |
|
Xianzhu
2016/03/28 00:44:42
Ditto.
|
| + case DisplayItem::BoxDecorationBackground: { |
| + LayoutPoint adjustedPaintOffset = paintOffset; |
| + adjustedPaintOffset.moveBy(m_layoutTableCell.location()); |
| + position = LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSnappedSize())); |
| + } |
| + break; |
| + default: |
| + ASSERT(false); |
|
Xianzhu
2016/03/28 00:44:42
ASSERT_NOT_REACHED();
atotic1
2016/03/29 17:05:17
Done.
|
| + break; |
| + } |
| + return LayoutRect(position.pixelSnappedLocation(), position.pixelSnappedSize()); |
| +} |
| + |
| } // namespace blink |