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" |
| 11 #include "core/paint/ObjectPainter.h" | 11 #include "core/paint/ObjectPainter.h" |
| 12 #include "core/paint/PaintInfo.h" | 12 #include "core/paint/PaintInfo.h" |
| 13 #include "platform/graphics/GraphicsContextStateSaver.h" | 13 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 14 #include "platform/graphics/paint/DisplayItemCacheSkipper.h" | |
| 15 #include "platform/graphics/paint/DrawingRecorder.h" | |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 | 18 |
| 17 static const CollapsedBorderValue& collapsedLeftBorder( | 19 static const CollapsedBorderValue& collapsedLeftBorder( |
| 18 const ComputedStyle& styleForCellFlow, | 20 const ComputedStyle& styleForCellFlow, |
| 19 const LayoutTableCell::CollapsedBorderValues& values) { | 21 const LayoutTableCell::CollapsedBorderValues& values) { |
| 20 if (styleForCellFlow.isHorizontalWritingMode()) | 22 if (styleForCellFlow.isHorizontalWritingMode()) { |
| 21 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder | 23 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder() |
| 22 : values.endBorder; | 24 : values.endBorder(); |
| 23 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder | 25 } |
| 24 : values.beforeBorder; | 26 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder() |
| 27 : values.beforeBorder(); | |
| 25 } | 28 } |
| 26 | 29 |
| 27 static const CollapsedBorderValue& collapsedRightBorder( | 30 static const CollapsedBorderValue& collapsedRightBorder( |
| 28 const ComputedStyle& styleForCellFlow, | 31 const ComputedStyle& styleForCellFlow, |
| 29 const LayoutTableCell::CollapsedBorderValues& values) { | 32 const LayoutTableCell::CollapsedBorderValues& values) { |
| 30 if (styleForCellFlow.isHorizontalWritingMode()) | 33 if (styleForCellFlow.isHorizontalWritingMode()) { |
| 31 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder | 34 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder() |
| 32 : values.startBorder; | 35 : values.startBorder(); |
| 33 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder | 36 } |
| 34 : values.afterBorder; | 37 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder() |
| 38 : values.afterBorder(); | |
| 35 } | 39 } |
| 36 | 40 |
| 37 static const CollapsedBorderValue& collapsedTopBorder( | 41 static const CollapsedBorderValue& collapsedTopBorder( |
| 38 const ComputedStyle& styleForCellFlow, | 42 const ComputedStyle& styleForCellFlow, |
| 39 const LayoutTableCell::CollapsedBorderValues& values) { | 43 const LayoutTableCell::CollapsedBorderValues& values) { |
| 40 if (styleForCellFlow.isHorizontalWritingMode()) | 44 if (styleForCellFlow.isHorizontalWritingMode()) |
| 41 return values.beforeBorder; | 45 return values.beforeBorder(); |
| 42 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder | 46 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder() |
| 43 : values.endBorder; | 47 : values.endBorder(); |
| 44 } | 48 } |
| 45 | 49 |
| 46 static const CollapsedBorderValue& collapsedBottomBorder( | 50 static const CollapsedBorderValue& collapsedBottomBorder( |
| 47 const ComputedStyle& styleForCellFlow, | 51 const ComputedStyle& styleForCellFlow, |
| 48 const LayoutTableCell::CollapsedBorderValues& values) { | 52 const LayoutTableCell::CollapsedBorderValues& values) { |
| 49 if (styleForCellFlow.isHorizontalWritingMode()) | 53 if (styleForCellFlow.isHorizontalWritingMode()) |
| 50 return values.afterBorder; | 54 return values.afterBorder(); |
| 51 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder | 55 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder() |
| 52 : values.startBorder; | 56 : values.startBorder(); |
| 53 } | 57 } |
| 54 | 58 |
| 55 void TableCellPainter::paint(const PaintInfo& paintInfo, | 59 void TableCellPainter::paint(const PaintInfo& paintInfo, |
| 56 const LayoutPoint& paintOffset) { | 60 const LayoutPoint& paintOffset) { |
| 57 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); | 61 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); |
| 58 } | 62 } |
| 59 | 63 |
| 60 static EBorderStyle collapsedBorderStyle(EBorderStyle style) { | 64 static EBorderStyle collapsedBorderStyle(EBorderStyle style) { |
| 61 if (style == BorderStyleOutset) | 65 if (style == BorderStyleOutset) |
| 62 return BorderStyleGroove; | 66 return BorderStyleGroove; |
| 63 if (style == BorderStyleInset) | 67 if (style == BorderStyleInset) |
| 64 return BorderStyleRidge; | 68 return BorderStyleRidge; |
| 65 return style; | 69 return style; |
| 66 } | 70 } |
| 67 | 71 |
| 72 const DisplayItemClient& TableCellPainter::displayItemClient() const { | |
|
chrishtr
2016/10/19 01:13:21
The collapsed border values should only be used as
wkorman
2016/10/19 23:07:39
Done.
| |
| 73 // TODO(wkorman): We may need to handle PaintInvalidationDelayedFull at all | |
| 74 // callsites in this file that make use of | |
| 75 // this client. http://crbug.com/657186 | |
| 76 return m_layoutTableCell.usesTableAsDisplayItemClient() | |
| 77 ? static_cast<const DisplayItemClient&>( | |
| 78 *m_layoutTableCell.collapsedBorderValues()) | |
| 79 : m_layoutTableCell; | |
| 80 } | |
| 81 | |
| 68 void TableCellPainter::paintCollapsedBorders( | 82 void TableCellPainter::paintCollapsedBorders( |
| 69 const PaintInfo& paintInfo, | 83 const PaintInfo& paintInfo, |
| 70 const LayoutPoint& paintOffset, | 84 const LayoutPoint& paintOffset, |
| 71 const CollapsedBorderValue& currentBorderValue) { | 85 const CollapsedBorderValue& currentBorderValue) { |
| 72 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) | 86 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) |
| 73 return; | 87 return; |
| 74 | 88 |
| 75 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); | 89 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); |
| 76 if (!BlockPainter(m_layoutTableCell) | 90 if (!BlockPainter(m_layoutTableCell) |
| 77 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) | 91 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 // Adjust our x/y/width/height so that we paint the collapsed borders at the | 126 // Adjust our x/y/width/height so that we paint the collapsed borders at the |
| 113 // correct location. | 127 // correct location. |
| 114 LayoutRect paintRect = | 128 LayoutRect paintRect = |
| 115 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); | 129 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); |
| 116 IntRect borderRect = pixelSnappedIntRect( | 130 IntRect borderRect = pixelSnappedIntRect( |
| 117 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, | 131 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, |
| 118 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 132 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
| 119 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 133 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
| 120 | 134 |
| 121 GraphicsContext& graphicsContext = paintInfo.context; | 135 GraphicsContext& graphicsContext = paintInfo.context; |
| 122 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 136 const DisplayItemClient& client = displayItemClient(); |
| 123 graphicsContext, m_layoutTableCell, | 137 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 138 graphicsContext, client, | |
| 124 static_cast<DisplayItem::Type>(displayItemType))) | 139 static_cast<DisplayItem::Type>(displayItemType))) |
| 125 return; | 140 return; |
| 126 | 141 |
| 127 LayoutObjectDrawingRecorder recorder( | 142 DrawingRecorder recorder(graphicsContext, client, |
| 128 graphicsContext, m_layoutTableCell, | 143 static_cast<DisplayItem::Type>(displayItemType), |
| 129 static_cast<DisplayItem::Type>(displayItemType), borderRect); | 144 borderRect); |
| 130 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); | 145 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); |
| 131 | 146 |
| 132 // We never paint diagonals at the joins. We simply let the border with the | 147 // We never paint diagonals at the joins. We simply let the border with the |
| 133 // highest precedence paint on top of borders with lower precedence. | 148 // highest precedence paint on top of borders with lower precedence. |
| 134 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { | 149 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { |
| 135 ObjectPainter::drawLineForBoxSide( | 150 ObjectPainter::drawLineForBoxSide( |
| 136 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), | 151 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), |
| 137 borderRect.y() + topWidth, BSTop, | 152 borderRect.y() + topWidth, BSTop, |
| 138 topBorderValue.color().resolve(cellColor), | 153 topBorderValue.color().resolve(cellColor), |
| 139 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); | 154 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 if (!BlockPainter(m_layoutTableCell) | 190 if (!BlockPainter(m_layoutTableCell) |
| 176 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) | 191 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) |
| 177 return; | 192 return; |
| 178 | 193 |
| 179 LayoutTable* table = m_layoutTableCell.table(); | 194 LayoutTable* table = m_layoutTableCell.table(); |
| 180 if (!table->collapseBorders() && | 195 if (!table->collapseBorders() && |
| 181 m_layoutTableCell.style()->emptyCells() == EEmptyCells::Hide && | 196 m_layoutTableCell.style()->emptyCells() == EEmptyCells::Hide && |
| 182 !m_layoutTableCell.firstChild()) | 197 !m_layoutTableCell.firstChild()) |
| 183 return; | 198 return; |
| 184 | 199 |
| 200 // TODO(wkorman): Investigate using displayItemClient() below. Currently | |
| 201 // attempting breaks caching for some reason. | |
|
wkorman
2016/10/19 00:52:43
Thoughts on why attempting to use displayItemClien
chrishtr
2016/10/19 01:13:21
I think you might be accidentally painting into th
| |
| 185 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 202 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( |
| 186 paintInfo.context, m_layoutTableCell, type)) | 203 paintInfo.context, m_layoutTableCell, type)) |
| 187 return; | 204 return; |
| 188 | 205 |
| 189 LayoutRect paintRect = | 206 LayoutRect paintRect = |
| 190 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); | 207 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); |
| 191 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, | 208 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, |
| 192 type, paintRect); | 209 type, paintRect); |
| 193 paintBackground(paintInfo, paintRect, backgroundObject); | 210 paintBackground(paintInfo, paintRect, backgroundObject); |
| 194 } | 211 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 !m_layoutTableCell.firstChild()) | 246 !m_layoutTableCell.firstChild()) |
| 230 return; | 247 return; |
| 231 | 248 |
| 232 bool needsToPaintBorder = | 249 bool needsToPaintBorder = |
| 233 m_layoutTableCell.styleRef().hasBorderDecoration() && | 250 m_layoutTableCell.styleRef().hasBorderDecoration() && |
| 234 !table->collapseBorders(); | 251 !table->collapseBorders(); |
| 235 if (!m_layoutTableCell.styleRef().hasBackground() && | 252 if (!m_layoutTableCell.styleRef().hasBackground() && |
| 236 !m_layoutTableCell.styleRef().boxShadow() && !needsToPaintBorder) | 253 !m_layoutTableCell.styleRef().boxShadow() && !needsToPaintBorder) |
| 237 return; | 254 return; |
| 238 | 255 |
| 239 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 256 const DisplayItemClient& client = displayItemClient(); |
| 240 paintInfo.context, m_layoutTableCell, | 257 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 241 DisplayItem::kBoxDecorationBackground)) | 258 paintInfo.context, client, DisplayItem::kBoxDecorationBackground)) |
| 242 return; | 259 return; |
| 243 | 260 |
| 244 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); | 261 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); |
| 245 visualOverflowRect.moveBy(paintOffset); | 262 visualOverflowRect.moveBy(paintOffset); |
| 246 // TODO(chrishtr): the pixel-snapping here is likely incorrect. | 263 // TODO(chrishtr): the pixel-snapping here is likely incorrect. |
| 247 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, | 264 DrawingRecorder recorder(paintInfo.context, client, |
| 248 DisplayItem::kBoxDecorationBackground, | 265 DisplayItem::kBoxDecorationBackground, |
| 249 pixelSnappedIntRect(visualOverflowRect)); | 266 pixelSnappedIntRect(visualOverflowRect)); |
| 250 | 267 |
| 251 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset); | 268 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset); |
| 252 | 269 |
| 253 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(), | 270 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(), |
| 254 Normal); | 271 Normal); |
| 255 paintBackground(paintInfo, paintRect, m_layoutTableCell); | 272 paintBackground(paintInfo, paintRect, m_layoutTableCell); |
| 256 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(), | 273 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(), |
| 257 Inset); | 274 Inset); |
| 258 | 275 |
| 259 if (!needsToPaintBorder) | 276 if (!needsToPaintBorder) |
| 260 return; | 277 return; |
| 261 | 278 |
| 262 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, | 279 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, |
| 263 m_layoutTableCell.styleRef()); | 280 m_layoutTableCell.styleRef()); |
| 264 } | 281 } |
| 265 | 282 |
| 266 void TableCellPainter::paintMask(const PaintInfo& paintInfo, | 283 void TableCellPainter::paintMask(const PaintInfo& paintInfo, |
| 267 const LayoutPoint& paintOffset) { | 284 const LayoutPoint& paintOffset) { |
| 268 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible || | 285 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible || |
| 269 paintInfo.phase != PaintPhaseMask) | 286 paintInfo.phase != PaintPhaseMask) |
| 270 return; | 287 return; |
| 271 | 288 |
| 272 LayoutTable* tableElt = m_layoutTableCell.table(); | 289 LayoutTable* tableElt = m_layoutTableCell.table(); |
| 273 if (!tableElt->collapseBorders() && | 290 if (!tableElt->collapseBorders() && |
| 274 m_layoutTableCell.style()->emptyCells() == EEmptyCells::Hide && | 291 m_layoutTableCell.style()->emptyCells() == EEmptyCells::Hide && |
| 275 !m_layoutTableCell.firstChild()) | 292 !m_layoutTableCell.firstChild()) |
| 276 return; | 293 return; |
| 277 | 294 |
| 278 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 295 const DisplayItemClient& client = displayItemClient(); |
| 279 paintInfo.context, m_layoutTableCell, paintInfo.phase)) | 296 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 297 paintInfo.context, client, | |
| 298 DisplayItem::paintPhaseToDrawingType(paintInfo.phase))) | |
| 280 return; | 299 return; |
| 281 | 300 |
| 282 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset); | 301 LayoutRect paintRect = paintRectNotIncludingVisualOverflow(paintOffset); |
| 283 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, | 302 DrawingRecorder recorder( |
| 284 paintInfo.phase, paintRect); | 303 paintInfo.context, client, |
| 304 DisplayItem::paintPhaseToDrawingType(paintInfo.phase), | |
| 305 FloatRect(paintRect)); | |
| 285 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 306 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
| 286 } | 307 } |
| 287 | 308 |
| 288 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( | 309 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( |
| 289 const LayoutPoint& paintOffset) { | 310 const LayoutPoint& paintOffset) { |
| 290 return LayoutRect(paintOffset, | 311 return LayoutRect(paintOffset, |
| 291 LayoutSize(m_layoutTableCell.pixelSnappedSize())); | 312 LayoutSize(m_layoutTableCell.pixelSnappedSize())); |
| 292 } | 313 } |
| 293 | 314 |
| 294 } // namespace blink | 315 } // namespace blink |
| OLD | NEW |