Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/TableCellPainter.h" | 5 #include "core/paint/TableCellPainter.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutTableCell.h" | 7 #include "core/layout/LayoutTableCell.h" |
| 8 #include "core/paint/BlockPainter.h" | 8 #include "core/paint/BlockPainter.h" |
| 9 #include "core/paint/BoxPainter.h" | 9 #include "core/paint/BoxPainter.h" |
| 10 #include "core/paint/LayoutObjectDrawingRecorder.h" | 10 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 displayItemType |= DisplayItem::TableCollapsedBorderRight; | 81 displayItemType |= DisplayItem::TableCollapsedBorderRight; |
| 82 if (displayItemType == DisplayItem::TableCollapsedBorderBase) | 82 if (displayItemType == DisplayItem::TableCollapsedBorderBase) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 int topWidth = topBorderValue.width(); | 85 int topWidth = topBorderValue.width(); |
| 86 int bottomWidth = bottomBorderValue.width(); | 86 int bottomWidth = bottomBorderValue.width(); |
| 87 int leftWidth = leftBorderValue.width(); | 87 int leftWidth = leftBorderValue.width(); |
| 88 int rightWidth = rightBorderValue.width(); | 88 int rightWidth = rightBorderValue.width(); |
| 89 | 89 |
| 90 // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. | 90 // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location. |
| 91 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); | 91 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset + m_l ayoutTableCell.location()); |
| 92 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, | 92 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, |
| 93 paintRect.y() - topWidth / 2, | 93 paintRect.y() - topWidth / 2, |
| 94 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 94 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
| 95 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 95 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
| 96 | 96 |
| 97 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) | 97 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 GraphicsContext& graphicsContext = paintInfo.context; | 100 GraphicsContext& graphicsContext = paintInfo.context; |
| 101 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext, m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType))) | 101 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext, m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType))) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 117 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { | 117 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { |
| 118 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, | 118 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, |
| 119 leftBorderValue.color().resolve(cellColor), collapsedBorderStyle(lef tBorderValue.style()), 0, 0, true); | 119 leftBorderValue.color().resolve(cellColor), collapsedBorderStyle(lef tBorderValue.style()), 0, 0, true); |
| 120 } | 120 } |
| 121 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { | 121 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { |
| 122 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.maxX() - r ightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), BSRight, | 122 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.maxX() - r ightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), BSRight, |
| 123 rightBorderValue.color().resolve(cellColor), collapsedBorderStyle(ri ghtBorderValue.style()), 0, 0, true); | 123 rightBorderValue.color().resolve(cellColor), collapsedBorderStyle(ri ghtBorderValue.style()), 0, 0, true); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co nst LayoutPoint& paintOffset, const LayoutObject* backgroundObject, DisplayItem: :Type type) | 127 void TableCellPainter::paintContainerBackgroundBehindCell(const PaintInfo& paint Info, const LayoutPoint& paintOffset, const LayoutObject& backgroundObject, Disp layItem::Type type) |
| 128 { | 128 { |
| 129 if (!backgroundObject) | 129 DCHECK(backgroundObject != m_layoutTableCell); |
| 130 return; | |
| 131 | 130 |
| 132 if (m_layoutTableCell.style()->visibility() != VISIBLE) | 131 if (m_layoutTableCell.style()->visibility() != VISIBLE) |
| 133 return; | 132 return; |
| 134 | 133 |
| 135 LayoutTable* tableElt = m_layoutTableCell.table(); | 134 LayoutTable* table = m_layoutTableCell.table(); |
| 136 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) | 135 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) |
| 137 return; | 136 return; |
| 138 | 137 |
| 139 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent); | 138 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, type)) |
| 139 return; | |
| 140 | 140 |
| 141 // Record drawing only if the cell is painting background from containers. | 141 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset + m_l ayoutTableCell.location()); |
| 142 Optional<LayoutObjectDrawingRecorder> recorder; | 142 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, t ype, paintRect); |
| 143 if (backgroundObject != &m_layoutTableCell) { | 143 paintBackground(paintInfo, paintRect, backgroundObject); |
|
Xianzhu
2016/05/16 21:47:53
Previously paintBackgroundsBehindCell was like:
{
| |
| 144 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.co ntext, m_layoutTableCell, type)) | 144 } |
| 145 return; | |
| 146 recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect); | |
| 147 } else { | |
| 148 ASSERT(paintRect.location() == paintOffset); | |
| 149 } | |
| 150 | 145 |
| 151 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); | 146 void TableCellPainter::paintBackground(const PaintInfo& paintInfo, const LayoutR ect& paintRect, const LayoutObject& backgroundObject) |
| 152 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); | 147 { |
| 148 Color c = backgroundObject.resolveColor(CSSPropertyBackgroundColor); | |
| 149 const FillLayer& bgLayer = backgroundObject.styleRef().backgroundLayers(); | |
| 153 if (bgLayer.hasImage() || c.alpha()) { | 150 if (bgLayer.hasImage() || c.alpha()) { |
| 154 // We have to clip here because the background would paint | 151 // We have to clip here because the background would paint |
| 155 // on top of the borders otherwise. This only matters for cells and row s. | 152 // on top of the borders otherwise. This only matters for cells and row s. |
| 156 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == & m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt ->collapseBorders(); | 153 bool shouldClip = backgroundObject.hasLayer() && (backgroundObject == m_ layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && m_layoutTa bleCell.table()->collapseBorders(); |
| 157 GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClip); | 154 GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClip); |
| 158 if (shouldClip) { | 155 if (shouldClip) { |
| 159 LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size()); | 156 LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size()); |
| 160 clipRect.expand(m_layoutTableCell.borderInsets()); | 157 clipRect.expand(m_layoutTableCell.borderInsets()); |
| 161 paintInfo.context.clip(pixelSnappedIntRect(clipRect)); | 158 paintInfo.context.clip(pixelSnappedIntRect(clipRect)); |
| 162 } | 159 } |
| 163 BoxPainter(m_layoutTableCell).paintFillLayers(paintInfo, c, bgLayer, pai ntRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject); | 160 BoxPainter(m_layoutTableCell).paintFillLayers(paintInfo, c, bgLayer, pai ntRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, &backgroundObject); |
| 164 } | 161 } |
| 165 } | 162 } |
| 166 | 163 |
| 167 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) | 164 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 168 { | 165 { |
| 169 LayoutTable* table = m_layoutTableCell.table(); | 166 LayoutTable* table = m_layoutTableCell.table(); |
| 170 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) | 167 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) |
| 171 return; | 168 return; |
| 172 | 169 |
| 173 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration() && !table->collapseBorders(); | 170 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration() && !table->collapseBorders(); |
| 174 if (!m_layoutTableCell.hasBackground() && !m_layoutTableCell.styleRef().boxS hadow() && !needsToPaintBorder) | 171 if (!m_layoutTableCell.hasBackground() && !m_layoutTableCell.styleRef().boxS hadow() && !needsToPaintBorder) |
| 175 return; | 172 return; |
| 176 | 173 |
| 177 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, DisplayItem::BoxDecorationBackground)) | 174 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, DisplayItem::BoxDecorationBackground)) |
| 178 return; | 175 return; |
| 179 | 176 |
| 180 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); | 177 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); |
| 181 visualOverflowRect.moveBy(paintOffset); | 178 visualOverflowRect.moveBy(paintOffset); |
| 182 // TODO(chrishtr): the pixel-snapping here is likely incorrect. | 179 // TODO(chrishtr): the pixel-snapping here is likely incorrect. |
| 183 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, D isplayItem::BoxDecorationBackground, pixelSnappedIntRect(visualOverflowRect)); | 180 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, D isplayItem::BoxDecorationBackground, pixelSnappedIntRect(visualOverflowRect)); |
| 184 | 181 |
| 185 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 182 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset); |
| 186 | 183 |
| 187 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef( ), Normal); | 184 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef( ), Normal); |
| 188 | 185 paintBackground(paintInfo, paintRect, m_layoutTableCell); |
| 189 // Paint our cell background. | |
| 190 paintBackgroundsBehindCell(paintInfo, paintOffset, &m_layoutTableCell, Displ ayItem::BoxDecorationBackground); | |
| 191 | |
| 192 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef( ), Inset); | 186 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef( ), Inset); |
| 193 | 187 |
| 194 if (!needsToPaintBorder) | 188 if (!needsToPaintBorder) |
| 195 return; | 189 return; |
| 196 | 190 |
| 197 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, m_layoutTab leCell.styleRef()); | 191 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, m_layoutTab leCell.styleRef()); |
| 198 } | 192 } |
| 199 | 193 |
| 200 void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) | 194 void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 201 { | 195 { |
| 202 if (m_layoutTableCell.style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask) | 196 if (m_layoutTableCell.style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask) |
| 203 return; | 197 return; |
| 204 | 198 |
| 205 LayoutTable* tableElt = m_layoutTableCell.table(); | 199 LayoutTable* tableElt = m_layoutTableCell.table(); |
| 206 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) | 200 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == EmptyCellsHide && !m_layoutTableCell.firstChild()) |
| 207 return; | 201 return; |
| 208 | 202 |
| 209 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, paintInfo.phase)) | 203 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, paintInfo.phase)) |
| 210 return; | 204 return; |
| 211 | 205 |
| 212 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 206 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset); |
| 213 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p aintInfo.phase, paintRect); | 207 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p aintInfo.phase, paintRect); |
| 214 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 208 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
| 215 } | 209 } |
| 216 | 210 |
| 217 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior) | 211 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow(const LayoutPoi nt& paintOffset) |
| 218 { | 212 { |
| 219 LayoutPoint adjustedPaintOffset = paintOffset; | 213 return LayoutRect(paintOffset, LayoutSize(m_layoutTableCell.pixelSnappedSize ())); |
| 220 if (paintBoundOffsetBehavior == AddOffsetFromParent) | |
| 221 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); | |
| 222 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize())); | |
| 223 } | 214 } |
| 224 | 215 |
| 225 } // namespace blink | 216 } // namespace blink |
| 226 | 217 |
| OLD | NEW |