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 #include "platform/graphics/paint/DrawingRecorder.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 static const CollapsedBorderValue& collapsedLeftBorder( | 18 static const CollapsedBorderValue& collapsedLeftBorder( |
19 const ComputedStyle& styleForCellFlow, | 19 const ComputedStyle& styleForCellFlow, |
20 const LayoutTableCell::CollapsedBorderValues& values) { | 20 const LayoutTableCell::CollapsedBorderValues& values) { |
21 if (styleForCellFlow.isHorizontalWritingMode()) { | 21 if (styleForCellFlow.isHorizontalWritingMode()) { |
22 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder | 22 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder() |
23 : values.endBorder; | 23 : values.endBorder(); |
24 } | 24 } |
25 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder | 25 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder() |
26 : values.beforeBorder; | 26 : values.beforeBorder(); |
27 } | 27 } |
28 | 28 |
29 static const CollapsedBorderValue& collapsedRightBorder( | 29 static const CollapsedBorderValue& collapsedRightBorder( |
30 const ComputedStyle& styleForCellFlow, | 30 const ComputedStyle& styleForCellFlow, |
31 const LayoutTableCell::CollapsedBorderValues& values) { | 31 const LayoutTableCell::CollapsedBorderValues& values) { |
32 if (styleForCellFlow.isHorizontalWritingMode()) { | 32 if (styleForCellFlow.isHorizontalWritingMode()) { |
33 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder | 33 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder() |
34 : values.startBorder; | 34 : values.startBorder(); |
35 } | 35 } |
36 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder | 36 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder() |
37 : values.afterBorder; | 37 : values.afterBorder(); |
38 } | 38 } |
39 | 39 |
40 static const CollapsedBorderValue& collapsedTopBorder( | 40 static const CollapsedBorderValue& collapsedTopBorder( |
41 const ComputedStyle& styleForCellFlow, | 41 const ComputedStyle& styleForCellFlow, |
42 const LayoutTableCell::CollapsedBorderValues& values) { | 42 const LayoutTableCell::CollapsedBorderValues& values) { |
43 if (styleForCellFlow.isHorizontalWritingMode()) | 43 if (styleForCellFlow.isHorizontalWritingMode()) |
44 return values.beforeBorder; | 44 return values.beforeBorder(); |
45 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder | 45 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder() |
46 : values.endBorder; | 46 : values.endBorder(); |
47 } | 47 } |
48 | 48 |
49 static const CollapsedBorderValue& collapsedBottomBorder( | 49 static const CollapsedBorderValue& collapsedBottomBorder( |
50 const ComputedStyle& styleForCellFlow, | 50 const ComputedStyle& styleForCellFlow, |
51 const LayoutTableCell::CollapsedBorderValues& values) { | 51 const LayoutTableCell::CollapsedBorderValues& values) { |
52 if (styleForCellFlow.isHorizontalWritingMode()) | 52 if (styleForCellFlow.isHorizontalWritingMode()) |
53 return values.afterBorder; | 53 return values.afterBorder(); |
54 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder | 54 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder() |
55 : values.startBorder; | 55 : values.startBorder(); |
56 } | 56 } |
57 | 57 |
58 void TableCellPainter::paint(const PaintInfo& paintInfo, | 58 void TableCellPainter::paint(const PaintInfo& paintInfo, |
59 const LayoutPoint& paintOffset) { | 59 const LayoutPoint& paintOffset) { |
60 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); | 60 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); |
61 } | 61 } |
62 | 62 |
63 static EBorderStyle collapsedBorderStyle(EBorderStyle style) { | 63 static EBorderStyle collapsedBorderStyle(EBorderStyle style) { |
64 if (style == BorderStyleOutset) | 64 if (style == BorderStyleOutset) |
65 return BorderStyleGroove; | 65 return BorderStyleGroove; |
66 if (style == BorderStyleInset) | 66 if (style == BorderStyleInset) |
67 return BorderStyleRidge; | 67 return BorderStyleRidge; |
68 return style; | 68 return style; |
69 } | 69 } |
70 | 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.usesCompositedCellDisplayItemClients() |
| 75 ? static_cast<const DisplayItemClient&>( |
| 76 *m_layoutTableCell.collapsedBorderValues()) |
| 77 : m_layoutTableCell; |
| 78 } |
| 79 |
71 void TableCellPainter::paintCollapsedBorders( | 80 void TableCellPainter::paintCollapsedBorders( |
72 const PaintInfo& paintInfo, | 81 const PaintInfo& paintInfo, |
73 const LayoutPoint& paintOffset, | 82 const LayoutPoint& paintOffset, |
74 const CollapsedBorderValue& currentBorderValue) { | 83 const CollapsedBorderValue& currentBorderValue) { |
75 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) | 84 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) |
76 return; | 85 return; |
77 | 86 |
78 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); | 87 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); |
79 if (!BlockPainter(m_layoutTableCell) | 88 if (!BlockPainter(m_layoutTableCell) |
80 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) | 89 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) |
81 return; | 90 return; |
82 | 91 |
83 const LayoutTableCell::CollapsedBorderValues* values = | 92 const LayoutTableCell::CollapsedBorderValues* values = |
84 m_layoutTableCell.collapsedBorderValues(); | 93 m_layoutTableCell.collapsedBorderValues(); |
85 if (!values) | 94 if (!values) |
86 return; | 95 return; |
87 | 96 |
88 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow(); | 97 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow(); |
89 const CollapsedBorderValue& leftBorderValue = | 98 const CollapsedBorderValue& leftBorderValue = |
90 collapsedLeftBorder(styleForCellFlow, *values); | 99 collapsedLeftBorder(styleForCellFlow, *values); |
91 const CollapsedBorderValue& rightBorderValue = | 100 const CollapsedBorderValue& rightBorderValue = |
92 collapsedRightBorder(styleForCellFlow, *values); | 101 collapsedRightBorder(styleForCellFlow, *values); |
93 const CollapsedBorderValue& topBorderValue = | 102 const CollapsedBorderValue& topBorderValue = |
94 collapsedTopBorder(styleForCellFlow, *values); | 103 collapsedTopBorder(styleForCellFlow, *values); |
95 const CollapsedBorderValue& bottomBorderValue = | 104 const CollapsedBorderValue& bottomBorderValue = |
96 collapsedBottomBorder(styleForCellFlow, *values); | 105 collapsedBottomBorder(styleForCellFlow, *values); |
97 | 106 |
| 107 int displayItemType = DisplayItem::kTableCollapsedBorderBase; |
| 108 if (topBorderValue.shouldPaint(currentBorderValue)) |
| 109 displayItemType |= DisplayItem::TableCollapsedBorderTop; |
| 110 if (bottomBorderValue.shouldPaint(currentBorderValue)) |
| 111 displayItemType |= DisplayItem::TableCollapsedBorderBottom; |
| 112 if (leftBorderValue.shouldPaint(currentBorderValue)) |
| 113 displayItemType |= DisplayItem::TableCollapsedBorderLeft; |
| 114 if (rightBorderValue.shouldPaint(currentBorderValue)) |
| 115 displayItemType |= DisplayItem::TableCollapsedBorderRight; |
| 116 if (displayItemType == DisplayItem::kTableCollapsedBorderBase) |
| 117 return; |
| 118 |
98 int topWidth = topBorderValue.width(); | 119 int topWidth = topBorderValue.width(); |
99 int bottomWidth = bottomBorderValue.width(); | 120 int bottomWidth = bottomBorderValue.width(); |
100 int leftWidth = leftBorderValue.width(); | 121 int leftWidth = leftBorderValue.width(); |
101 int rightWidth = rightBorderValue.width(); | 122 int rightWidth = rightBorderValue.width(); |
102 | 123 |
103 // 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 |
104 // correct location. | 125 // correct location. |
105 LayoutRect paintRect = | 126 LayoutRect paintRect = |
106 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); | 127 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); |
107 IntRect borderRect = pixelSnappedIntRect( | 128 IntRect borderRect = pixelSnappedIntRect( |
108 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, | 129 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, |
109 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 130 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
110 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 131 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
111 | 132 |
112 GraphicsContext& graphicsContext = paintInfo.context; | 133 GraphicsContext& graphicsContext = paintInfo.context; |
| 134 const DisplayItemClient& client = displayItemClientForBorders(); |
| 135 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 136 graphicsContext, client, |
| 137 static_cast<DisplayItem::Type>(displayItemType))) |
| 138 return; |
| 139 |
| 140 DrawingRecorder recorder(graphicsContext, client, |
| 141 static_cast<DisplayItem::Type>(displayItemType), |
| 142 borderRect); |
113 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); | 143 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); |
114 | 144 |
115 // 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 |
116 // highest precedence paint on top of borders with lower precedence. | 146 // highest precedence paint on top of borders with lower precedence. |
117 if (topBorderValue.shouldPaint(currentBorderValue)) { | 147 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { |
118 ObjectPainter::drawLineForBoxSide( | 148 ObjectPainter::drawLineForBoxSide( |
119 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), | 149 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), |
120 borderRect.y() + topWidth, BSTop, | 150 borderRect.y() + topWidth, BSTop, |
121 topBorderValue.color().resolve(cellColor), | 151 topBorderValue.color().resolve(cellColor), |
122 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); | 152 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); |
123 } | 153 } |
124 if (bottomBorderValue.shouldPaint(currentBorderValue)) { | 154 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { |
125 ObjectPainter::drawLineForBoxSide( | 155 ObjectPainter::drawLineForBoxSide( |
126 graphicsContext, borderRect.x(), borderRect.maxY() - bottomWidth, | 156 graphicsContext, borderRect.x(), borderRect.maxY() - bottomWidth, |
127 borderRect.maxX(), borderRect.maxY(), BSBottom, | 157 borderRect.maxX(), borderRect.maxY(), BSBottom, |
128 bottomBorderValue.color().resolve(cellColor), | 158 bottomBorderValue.color().resolve(cellColor), |
129 collapsedBorderStyle(bottomBorderValue.style()), 0, 0, true); | 159 collapsedBorderStyle(bottomBorderValue.style()), 0, 0, true); |
130 } | 160 } |
131 if (leftBorderValue.shouldPaint(currentBorderValue)) { | 161 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { |
132 ObjectPainter::drawLineForBoxSide( | 162 ObjectPainter::drawLineForBoxSide( |
133 graphicsContext, borderRect.x(), borderRect.y(), | 163 graphicsContext, borderRect.x(), borderRect.y(), |
134 borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, | 164 borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, |
135 leftBorderValue.color().resolve(cellColor), | 165 leftBorderValue.color().resolve(cellColor), |
136 collapsedBorderStyle(leftBorderValue.style()), 0, 0, true); | 166 collapsedBorderStyle(leftBorderValue.style()), 0, 0, true); |
137 } | 167 } |
138 if (rightBorderValue.shouldPaint(currentBorderValue)) { | 168 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { |
139 ObjectPainter::drawLineForBoxSide( | 169 ObjectPainter::drawLineForBoxSide( |
140 graphicsContext, borderRect.maxX() - rightWidth, borderRect.y(), | 170 graphicsContext, borderRect.maxX() - rightWidth, borderRect.y(), |
141 borderRect.maxX(), borderRect.maxY(), BSRight, | 171 borderRect.maxX(), borderRect.maxY(), BSRight, |
142 rightBorderValue.color().resolve(cellColor), | 172 rightBorderValue.color().resolve(cellColor), |
143 collapsedBorderStyle(rightBorderValue.style()), 0, 0, true); | 173 collapsedBorderStyle(rightBorderValue.style()), 0, 0, true); |
144 } | 174 } |
145 } | 175 } |
146 | 176 |
147 void TableCellPainter::paintContainerBackgroundBehindCell( | 177 void TableCellPainter::paintContainerBackgroundBehindCell( |
148 const PaintInfo& paintInfo, | 178 const PaintInfo& paintInfo, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 300 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
271 } | 301 } |
272 | 302 |
273 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( | 303 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( |
274 const LayoutPoint& paintOffset) { | 304 const LayoutPoint& paintOffset) { |
275 return LayoutRect(paintOffset, | 305 return LayoutRect(paintOffset, |
276 LayoutSize(m_layoutTableCell.pixelSnappedSize())); | 306 LayoutSize(m_layoutTableCell.pixelSnappedSize())); |
277 } | 307 } |
278 | 308 |
279 } // namespace blink | 309 } // namespace blink |
OLD | NEW |