| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (rightBorderValue) { | 98 if (rightBorderValue) { |
| 99 if (rightBorderValue->shouldPaint(currentBorderValue)) | 99 if (rightBorderValue->shouldPaint(currentBorderValue)) |
| 100 displayItemType |= DisplayItem::TableCollapsedBorderRight; | 100 displayItemType |= DisplayItem::TableCollapsedBorderRight; |
| 101 rightWidth = rightBorderValue->width(); | 101 rightWidth = rightBorderValue->width(); |
| 102 } | 102 } |
| 103 if (displayItemType == DisplayItem::TableCollapsedBorderBase) | 103 if (displayItemType == DisplayItem::TableCollapsedBorderBase) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 // Adjust our x/y/width/height so that we paint the collapsed borders at the
correct location. | 106 // Adjust our x/y/width/height so that we paint the collapsed borders at the
correct location. |
| 107 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); | 107 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); |
| 108 LayoutPoint adjustedPaintOffset = paintRect.location(); | |
| 109 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, | 108 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, |
| 110 paintRect.y() - topWidth / 2, | 109 paintRect.y() - topWidth / 2, |
| 111 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 110 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
| 112 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 111 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
| 113 | 112 |
| 114 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) | 113 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) |
| 115 return; | 114 return; |
| 116 | 115 |
| 117 GraphicsContext& graphicsContext = paintInfo.context; | 116 GraphicsContext& graphicsContext = paintInfo.context; |
| 118 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext,
m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType), adjustedPai
ntOffset)) | 117 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext,
m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType))) |
| 119 return; | 118 return; |
| 120 | 119 |
| 121 LayoutObjectDrawingRecorder recorder(graphicsContext, m_layoutTableCell, sta
tic_cast<DisplayItem::Type>(displayItemType), borderRect, adjustedPaintOffset); | 120 LayoutObjectDrawingRecorder recorder(graphicsContext, m_layoutTableCell, sta
tic_cast<DisplayItem::Type>(displayItemType), borderRect); |
| 122 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); | 121 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); |
| 123 | 122 |
| 124 // We never paint diagonals at the joins. We simply let the border with the
highest | 123 // We never paint diagonals at the joins. We simply let the border with the
highest |
| 125 // precedence paint on top of borders with lower precedence. | 124 // precedence paint on top of borders with lower precedence. |
| 126 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { | 125 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { |
| 127 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.y(), borderRect.maxX(), borderRect.y() + topWidth, BSTop, | 126 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.y(), borderRect.maxX(), borderRect.y() + topWidth, BSTop, |
| 128 topBorderValue->color().resolve(cellColor), collapsedBorderStyle(top
BorderValue->style()), 0, 0, true); | 127 topBorderValue->color().resolve(cellColor), collapsedBorderStyle(top
BorderValue->style()), 0, 0, true); |
| 129 } | 128 } |
| 130 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { | 129 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { |
| 131 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), BSBottom, | 130 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), BSBottom, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 151 | 150 |
| 152 LayoutTable* tableElt = m_layoutTableCell.table(); | 151 LayoutTable* tableElt = m_layoutTableCell.table(); |
| 153 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) | 152 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) |
| 154 return; | 153 return; |
| 155 | 154 |
| 156 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou
tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent); | 155 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou
tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent); |
| 157 | 156 |
| 158 // Record drawing only if the cell is painting background from containers. | 157 // Record drawing only if the cell is painting background from containers. |
| 159 Optional<LayoutObjectDrawingRecorder> recorder; | 158 Optional<LayoutObjectDrawingRecorder> recorder; |
| 160 if (backgroundObject != &m_layoutTableCell) { | 159 if (backgroundObject != &m_layoutTableCell) { |
| 161 LayoutPoint adjustedPaintOffset = paintRect.location(); | 160 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.co
ntext, m_layoutTableCell, type)) |
| 162 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.co
ntext, m_layoutTableCell, type, adjustedPaintOffset)) | |
| 163 return; | 161 return; |
| 164 recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect,
adjustedPaintOffset); | 162 recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect); |
| 165 } else { | 163 } else { |
| 166 ASSERT(paintRect.location() == paintOffset); | 164 ASSERT(paintRect.location() == paintOffset); |
| 167 } | 165 } |
| 168 | 166 |
| 169 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); | 167 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); |
| 170 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); | 168 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); |
| 171 if (bgLayer.hasImage() || c.alpha()) { | 169 if (bgLayer.hasImage() || c.alpha()) { |
| 172 // We have to clip here because the background would paint | 170 // We have to clip here because the background would paint |
| 173 // on top of the borders otherwise. This only matters for cells and row
s. | 171 // on top of the borders otherwise. This only matters for cells and row
s. |
| 174 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == &
m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt
->collapseBorders(); | 172 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == &
m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt
->collapseBorders(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 185 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo,
const LayoutPoint& paintOffset) | 183 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo,
const LayoutPoint& paintOffset) |
| 186 { | 184 { |
| 187 LayoutTable* table = m_layoutTableCell.table(); | 185 LayoutTable* table = m_layoutTableCell.table(); |
| 188 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() ==
HIDE && !m_layoutTableCell.firstChild()) | 186 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() ==
HIDE && !m_layoutTableCell.firstChild()) |
| 189 return; | 187 return; |
| 190 | 188 |
| 191 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration()
&& !table->collapseBorders(); | 189 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration()
&& !table->collapseBorders(); |
| 192 if (!m_layoutTableCell.hasBackground() && !m_layoutTableCell.styleRef().boxS
hadow() && !needsToPaintBorder) | 190 if (!m_layoutTableCell.hasBackground() && !m_layoutTableCell.styleRef().boxS
hadow() && !needsToPaintBorder) |
| 193 return; | 191 return; |
| 194 | 192 |
| 195 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutTableCell, DisplayItem::BoxDecorationBackground, paintOffset)) | 193 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutTableCell, DisplayItem::BoxDecorationBackground)) |
| 196 return; | 194 return; |
| 197 | 195 |
| 198 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); | 196 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); |
| 199 visualOverflowRect.moveBy(paintOffset); | 197 visualOverflowRect.moveBy(paintOffset); |
| 200 // TODO(chrishtr): the pixel-snapping here is likely incorrect. | 198 // TODO(chrishtr): the pixel-snapping here is likely incorrect. |
| 201 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, D
isplayItem::BoxDecorationBackground, pixelSnappedIntRect(visualOverflowRect), pa
intOffset); | 199 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, D
isplayItem::BoxDecorationBackground, pixelSnappedIntRect(visualOverflowRect)); |
| 202 | 200 |
| 203 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 201 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); |
| 204 | 202 |
| 205 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Normal); | 203 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Normal); |
| 206 | 204 |
| 207 // Paint our cell background. | 205 // Paint our cell background. |
| 208 paintBackgroundsBehindCell(paintInfo, paintOffset, &m_layoutTableCell, Displ
ayItem::BoxDecorationBackground); | 206 paintBackgroundsBehindCell(paintInfo, paintOffset, &m_layoutTableCell, Displ
ayItem::BoxDecorationBackground); |
| 209 | 207 |
| 210 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Inset); | 208 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Inset); |
| 211 | 209 |
| 212 if (!needsToPaintBorder) | 210 if (!needsToPaintBorder) |
| 213 return; | 211 return; |
| 214 | 212 |
| 215 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, m_layoutTab
leCell.styleRef()); | 213 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, m_layoutTab
leCell.styleRef()); |
| 216 } | 214 } |
| 217 | 215 |
| 218 void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 216 void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
| 219 { | 217 { |
| 220 if (m_layoutTableCell.style()->visibility() != VISIBLE || paintInfo.phase !=
PaintPhaseMask) | 218 if (m_layoutTableCell.style()->visibility() != VISIBLE || paintInfo.phase !=
PaintPhaseMask) |
| 221 return; | 219 return; |
| 222 | 220 |
| 223 LayoutTable* tableElt = m_layoutTableCell.table(); | 221 LayoutTable* tableElt = m_layoutTableCell.table(); |
| 224 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) | 222 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) |
| 225 return; | 223 return; |
| 226 | 224 |
| 227 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutTableCell, paintInfo.phase, paintOffset)) | 225 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutTableCell, paintInfo.phase)) |
| 228 return; | 226 return; |
| 229 | 227 |
| 230 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 228 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); |
| 231 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p
aintInfo.phase, paintRect, paintOffset); | 229 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p
aintInfo.phase, paintRect); |
| 232 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 230 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
| 233 } | 231 } |
| 234 | 232 |
| 235 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo
undOffsetBehavior paintBoundOffsetBehavior) | 233 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo
undOffsetBehavior paintBoundOffsetBehavior) |
| 236 { | 234 { |
| 237 LayoutPoint adjustedPaintOffset = paintOffset; | 235 LayoutPoint adjustedPaintOffset = paintOffset; |
| 238 if (paintBoundOffsetBehavior == AddOffsetFromParent) | 236 if (paintBoundOffsetBehavior == AddOffsetFromParent) |
| 239 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); | 237 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); |
| 240 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna
ppedSize())); | 238 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna
ppedSize())); |
| 241 } | 239 } |
| 242 | 240 |
| 243 } // namespace blink | 241 } // namespace blink |
| 244 | 242 |
| OLD | NEW |