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

Unified Diff: third_party/WebKit/Source/core/paint/TableCellPainter.cpp

Issue 1676933004: Table cell background painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: colgroup paint bug125336 fix Created 4 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 side-by-side diff with in-line comments
Download patch
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 6c14e2660979408fa04745cdcf64e4c062fea5bc..ef0978c01c46d4f64fe98f27b8dda5126ee3ba87 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"
@@ -141,7 +142,8 @@ void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const L
}
}
-void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutObject* backgroundObject, DisplayItem::Type type)
+
Xianzhu 2016/02/23 22:58:27 Nit: unnecessary change.
atotic1 2016/03/15 16:50:47 I need this because paintBounds now takes a Layout
+void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const LayoutBox* backgroundObject, DisplayItem::Type type)
{
if (!backgroundObject)
return;
@@ -153,32 +155,46 @@ void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co
if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == HIDE && !m_layoutTableCell.firstChild())
return;
- LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layoutTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent);
+ LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layoutTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent, backgroundObject, type);
+
+ // Background objects have to enclose the entire cell
Xianzhu 2016/02/23 22:58:27 Nit: '.' as the end of the comment.
atotic1 2016/03/15 16:50:47 Done.
+ if (backgroundObject != &m_layoutTableCell) {
Xianzhu 2016/02/23 22:58:27 Nit: extra space after != Can you combine this bl
atotic1 2016/03/15 16:50:47 Done.
+ LayoutRect cellRect = m_layoutTableCell.frameRect();
+ cellRect.moveBy(paintOffset);
+ paintRect.unite(cellRect);
+ }
// Record drawing only if the cell is painting background from containers.
Optional<LayoutObjectDrawingRecorder> recorder;
if (backgroundObject != &m_layoutTableCell) {
LayoutPoint adjustedPaintOffset = paintRect.location();
- if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_layoutTableCell, type, adjustedPaintOffset))
+ if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_layoutTableCell, type, adjustedPaintOffset)) {
return;
+ }
Xianzhu 2016/02/23 22:58:27 Nit: Unnecessary change.
atotic1 2016/03/15 16:50:47 Done.
recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect, adjustedPaintOffset);
- } else {
- ASSERT(paintRect.location() == paintOffset);
Xianzhu 2016/02/23 22:58:27 Why is this removed?
}
Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor);
const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers();
+ FillLayer bgAdjustedLayer(bgLayer);
if (bgLayer.hasImage() || c.alpha()) {
- // We have to clip here because the background would paint
- // on top of the borders otherwise. This only matters for cells and rows.
- bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == &m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt->collapseBorders();
- GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClip);
- if (shouldClip) {
+ bool shouldClipCell = backgroundObject->hasLayer() && (backgroundObject == &m_layoutTableCell) && tableElt->collapseBorders();
+ bool shouldClipBackground = backgroundObject != &m_layoutTableCell;
+
+ GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClipCell || shouldClipBackground);
+ if (shouldClipCell) {
+ // We have to clip here because the background would paint
+ // on top of the borders otherwise. This only matters for cells and rows.
LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size());
clipRect.expand(m_layoutTableCell.borderInsets());
paintInfo.context.clip(pixelSnappedIntRect(clipRect));
+ } else if (shouldClipBackground) {
+ LayoutRect clipRect(m_layoutTableCell.location(), m_layoutTableCell.size());
+ clipRect.moveBy(paintOffset);
+ paintInfo.context.clip(pixelSnappedIntRect(clipRect));
+ paintRect.unite(clipRect);
}
- BoxPainter(m_layoutTableCell).paintFillLayers(paintInfo, c, bgLayer, paintRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject);
+ BoxPainter(*backgroundObject).paintFillLayers(paintInfo, c, bgLayer, paintRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject);
}
}
@@ -232,11 +248,44 @@ void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint&
BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect);
}
-LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBoundOffsetBehavior paintBoundOffsetBehavior)
+// Computed bounds for cell, or background objects
+LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBoundOffsetBehavior paintBoundOffsetBehavior, const LayoutBox* backgroundObject, DisplayItem::Type type)
{
+
LayoutPoint adjustedPaintOffset = paintOffset;
if (paintBoundOffsetBehavior == AddOffsetFromParent)
adjustedPaintOffset.moveBy(m_layoutTableCell.location());
+
+ if (backgroundObject) {
+ LayoutRect position;
+ switch (type) {
+ case DisplayItem::TableCellBackgroundFromColumnGroup:
+ case DisplayItem::TableCellBackgroundFromColumn:
+ {
+ position = static_cast<const LayoutTableCol*>(backgroundObject)->positionByCellSpan();
+ // position is relative to table, must correct for section location
+ LayoutPoint sectionLocation = m_layoutTableCell.section()->location();
+ position.moveBy(-sectionLocation);
+ position.moveBy(paintOffset);
+ }
+ break;
+ case DisplayItem::TableCellBackgroundFromSection:
+ 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;
+ case DisplayItem::BoxDecorationBackground:
+ position = LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSnappedSize()));
+ break;
+ default:
+ ASSERT(false);
+ break;
+ }
+ return position;
+ }
return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSnappedSize()));
}

Powered by Google App Engine
This is Rietveld 408576698