| 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/DrawingRecorder.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 static const CollapsedBorderValue& collapsedLeftBorder( | 18 static const CollapsedBorderValue& collapsedLeftBorder( |
| 18 const ComputedStyle& styleForCellFlow, | 19 const ComputedStyle& styleForCellFlow, |
| 19 const LayoutTableCell::CollapsedBorderValues& values) { | 20 const LayoutTableCell::CollapsedBorderValues& values) { |
| 20 if (styleForCellFlow.isHorizontalWritingMode()) | 21 if (styleForCellFlow.isHorizontalWritingMode()) { |
| 21 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder | 22 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder() |
| 22 : values.endBorder; | 23 : values.endBorder(); |
| 23 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder | 24 } |
| 24 : values.beforeBorder; | 25 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder() |
| 26 : values.beforeBorder(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 static const CollapsedBorderValue& collapsedRightBorder( | 29 static const CollapsedBorderValue& collapsedRightBorder( |
| 28 const ComputedStyle& styleForCellFlow, | 30 const ComputedStyle& styleForCellFlow, |
| 29 const LayoutTableCell::CollapsedBorderValues& values) { | 31 const LayoutTableCell::CollapsedBorderValues& values) { |
| 30 if (styleForCellFlow.isHorizontalWritingMode()) | 32 if (styleForCellFlow.isHorizontalWritingMode()) { |
| 31 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder | 33 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder() |
| 32 : values.startBorder; | 34 : values.startBorder(); |
| 33 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder | 35 } |
| 34 : values.afterBorder; | 36 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder() |
| 37 : values.afterBorder(); |
| 35 } | 38 } |
| 36 | 39 |
| 37 static const CollapsedBorderValue& collapsedTopBorder( | 40 static const CollapsedBorderValue& collapsedTopBorder( |
| 38 const ComputedStyle& styleForCellFlow, | 41 const ComputedStyle& styleForCellFlow, |
| 39 const LayoutTableCell::CollapsedBorderValues& values) { | 42 const LayoutTableCell::CollapsedBorderValues& values) { |
| 40 if (styleForCellFlow.isHorizontalWritingMode()) | 43 if (styleForCellFlow.isHorizontalWritingMode()) |
| 41 return values.beforeBorder; | 44 return values.beforeBorder(); |
| 42 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder | 45 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder() |
| 43 : values.endBorder; | 46 : values.endBorder(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 static const CollapsedBorderValue& collapsedBottomBorder( | 49 static const CollapsedBorderValue& collapsedBottomBorder( |
| 47 const ComputedStyle& styleForCellFlow, | 50 const ComputedStyle& styleForCellFlow, |
| 48 const LayoutTableCell::CollapsedBorderValues& values) { | 51 const LayoutTableCell::CollapsedBorderValues& values) { |
| 49 if (styleForCellFlow.isHorizontalWritingMode()) | 52 if (styleForCellFlow.isHorizontalWritingMode()) |
| 50 return values.afterBorder; | 53 return values.afterBorder(); |
| 51 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder | 54 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder() |
| 52 : values.startBorder; | 55 : values.startBorder(); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void TableCellPainter::paint(const PaintInfo& paintInfo, | 58 void TableCellPainter::paint(const PaintInfo& paintInfo, |
| 56 const LayoutPoint& paintOffset) { | 59 const LayoutPoint& paintOffset) { |
| 57 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); | 60 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); |
| 58 } | 61 } |
| 59 | 62 |
| 60 static EBorderStyle collapsedBorderStyle(EBorderStyle style) { | 63 static EBorderStyle collapsedBorderStyle(EBorderStyle style) { |
| 61 if (style == BorderStyleOutset) | 64 if (style == BorderStyleOutset) |
| 62 return BorderStyleGroove; | 65 return BorderStyleGroove; |
| 63 if (style == BorderStyleInset) | 66 if (style == BorderStyleInset) |
| 64 return BorderStyleRidge; | 67 return BorderStyleRidge; |
| 65 return style; | 68 return style; |
| 66 } | 69 } |
| 67 | 70 |
| 71 const DisplayItemClient& TableCellPainter::displayItemClientForBorders() const { |
| 72 // TODO(wkorman): We may need to handle PaintInvalidationDelayedFull. |
| 73 // http://crbug.com/657186 |
| 74 return m_layoutTableCell.usesTableAsAdditionalDisplayItemClient() |
| 75 ? static_cast<const DisplayItemClient&>( |
| 76 *m_layoutTableCell.collapsedBorderValues()) |
| 77 : m_layoutTableCell; |
| 78 } |
| 79 |
| 68 void TableCellPainter::paintCollapsedBorders( | 80 void TableCellPainter::paintCollapsedBorders( |
| 69 const PaintInfo& paintInfo, | 81 const PaintInfo& paintInfo, |
| 70 const LayoutPoint& paintOffset, | 82 const LayoutPoint& paintOffset, |
| 71 const CollapsedBorderValue& currentBorderValue) { | 83 const CollapsedBorderValue& currentBorderValue) { |
| 72 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) | 84 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) |
| 73 return; | 85 return; |
| 74 | 86 |
| 75 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); | 87 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); |
| 76 if (!BlockPainter(m_layoutTableCell) | 88 if (!BlockPainter(m_layoutTableCell) |
| 77 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) | 89 .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 | 124 // Adjust our x/y/width/height so that we paint the collapsed borders at the |
| 113 // correct location. | 125 // correct location. |
| 114 LayoutRect paintRect = | 126 LayoutRect paintRect = |
| 115 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); | 127 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); |
| 116 IntRect borderRect = pixelSnappedIntRect( | 128 IntRect borderRect = pixelSnappedIntRect( |
| 117 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, | 129 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, |
| 118 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 130 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
| 119 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 131 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
| 120 | 132 |
| 121 GraphicsContext& graphicsContext = paintInfo.context; | 133 GraphicsContext& graphicsContext = paintInfo.context; |
| 122 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 134 const DisplayItemClient& client = displayItemClientForBorders(); |
| 123 graphicsContext, m_layoutTableCell, | 135 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 136 graphicsContext, client, |
| 124 static_cast<DisplayItem::Type>(displayItemType))) | 137 static_cast<DisplayItem::Type>(displayItemType))) |
| 125 return; | 138 return; |
| 126 | 139 |
| 127 LayoutObjectDrawingRecorder recorder( | 140 DrawingRecorder recorder(graphicsContext, client, |
| 128 graphicsContext, m_layoutTableCell, | 141 static_cast<DisplayItem::Type>(displayItemType), |
| 129 static_cast<DisplayItem::Type>(displayItemType), borderRect); | 142 borderRect); |
| 130 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); | 143 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); |
| 131 | 144 |
| 132 // We never paint diagonals at the joins. We simply let the border with the | 145 // 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. | 146 // highest precedence paint on top of borders with lower precedence. |
| 134 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { | 147 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { |
| 135 ObjectPainter::drawLineForBoxSide( | 148 ObjectPainter::drawLineForBoxSide( |
| 136 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), | 149 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), |
| 137 borderRect.y() + topWidth, BSTop, | 150 borderRect.y() + topWidth, BSTop, |
| 138 topBorderValue.color().resolve(cellColor), | 151 topBorderValue.color().resolve(cellColor), |
| 139 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); | 152 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 298 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
| 286 } | 299 } |
| 287 | 300 |
| 288 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( | 301 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( |
| 289 const LayoutPoint& paintOffset) { | 302 const LayoutPoint& paintOffset) { |
| 290 return LayoutRect(paintOffset, | 303 return LayoutRect(paintOffset, |
| 291 LayoutSize(m_layoutTableCell.pixelSnappedSize())); | 304 LayoutSize(m_layoutTableCell.pixelSnappedSize())); |
| 292 } | 305 } |
| 293 | 306 |
| 294 } // namespace blink | 307 } // namespace blink |
| OLD | NEW |