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 | |
80 void TableCellPainter::paintCollapsedBorders( | 71 void TableCellPainter::paintCollapsedBorders( |
81 const PaintInfo& paintInfo, | 72 const PaintInfo& paintInfo, |
82 const LayoutPoint& paintOffset, | 73 const LayoutPoint& paintOffset, |
83 const CollapsedBorderValue& currentBorderValue) { | 74 const CollapsedBorderValue& currentBorderValue) { |
84 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) | 75 if (m_layoutTableCell.style()->visibility() != EVisibility::Visible) |
85 return; | 76 return; |
86 | 77 |
87 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); | 78 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableCell.location(); |
88 if (!BlockPainter(m_layoutTableCell) | 79 if (!BlockPainter(m_layoutTableCell) |
89 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) | 80 .intersectsPaintRect(paintInfo, adjustedPaintOffset)) |
90 return; | 81 return; |
91 | 82 |
92 const LayoutTableCell::CollapsedBorderValues* values = | 83 const LayoutTableCell::CollapsedBorderValues* values = |
93 m_layoutTableCell.collapsedBorderValues(); | 84 m_layoutTableCell.collapsedBorderValues(); |
94 if (!values) | 85 if (!values) |
95 return; | 86 return; |
96 | 87 |
97 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow(); | 88 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow(); |
98 const CollapsedBorderValue& leftBorderValue = | 89 const CollapsedBorderValue& leftBorderValue = |
99 collapsedLeftBorder(styleForCellFlow, *values); | 90 collapsedLeftBorder(styleForCellFlow, *values); |
100 const CollapsedBorderValue& rightBorderValue = | 91 const CollapsedBorderValue& rightBorderValue = |
101 collapsedRightBorder(styleForCellFlow, *values); | 92 collapsedRightBorder(styleForCellFlow, *values); |
102 const CollapsedBorderValue& topBorderValue = | 93 const CollapsedBorderValue& topBorderValue = |
103 collapsedTopBorder(styleForCellFlow, *values); | 94 collapsedTopBorder(styleForCellFlow, *values); |
104 const CollapsedBorderValue& bottomBorderValue = | 95 const CollapsedBorderValue& bottomBorderValue = |
105 collapsedBottomBorder(styleForCellFlow, *values); | 96 collapsedBottomBorder(styleForCellFlow, *values); |
106 | 97 |
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 | |
119 int topWidth = topBorderValue.width(); | 98 int topWidth = topBorderValue.width(); |
120 int bottomWidth = bottomBorderValue.width(); | 99 int bottomWidth = bottomBorderValue.width(); |
121 int leftWidth = leftBorderValue.width(); | 100 int leftWidth = leftBorderValue.width(); |
122 int rightWidth = rightBorderValue.width(); | 101 int rightWidth = rightBorderValue.width(); |
123 | 102 |
124 // Adjust our x/y/width/height so that we paint the collapsed borders at the | 103 // Adjust our x/y/width/height so that we paint the collapsed borders at the |
125 // correct location. | 104 // correct location. |
126 LayoutRect paintRect = | 105 LayoutRect paintRect = |
127 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); | 106 paintRectNotIncludingVisualOverflow(adjustedPaintOffset); |
128 IntRect borderRect = pixelSnappedIntRect( | 107 IntRect borderRect = pixelSnappedIntRect( |
129 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, | 108 paintRect.x() - leftWidth / 2, paintRect.y() - topWidth / 2, |
130 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 109 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
131 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 110 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
132 | 111 |
133 GraphicsContext& graphicsContext = paintInfo.context; | 112 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); | |
143 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); | 113 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); |
144 | 114 |
145 // We never paint diagonals at the joins. We simply let the border with the | 115 // We never paint diagonals at the joins. We simply let the border with the |
146 // highest precedence paint on top of borders with lower precedence. | 116 // highest precedence paint on top of borders with lower precedence. |
147 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { | 117 if (topBorderValue.shouldPaint(currentBorderValue)) { |
148 ObjectPainter::drawLineForBoxSide( | 118 ObjectPainter::drawLineForBoxSide( |
149 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), | 119 graphicsContext, borderRect.x(), borderRect.y(), borderRect.maxX(), |
150 borderRect.y() + topWidth, BSTop, | 120 borderRect.y() + topWidth, BSTop, |
151 topBorderValue.color().resolve(cellColor), | 121 topBorderValue.color().resolve(cellColor), |
152 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); | 122 collapsedBorderStyle(topBorderValue.style()), 0, 0, true); |
153 } | 123 } |
154 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { | 124 if (bottomBorderValue.shouldPaint(currentBorderValue)) { |
155 ObjectPainter::drawLineForBoxSide( | 125 ObjectPainter::drawLineForBoxSide( |
156 graphicsContext, borderRect.x(), borderRect.maxY() - bottomWidth, | 126 graphicsContext, borderRect.x(), borderRect.maxY() - bottomWidth, |
157 borderRect.maxX(), borderRect.maxY(), BSBottom, | 127 borderRect.maxX(), borderRect.maxY(), BSBottom, |
158 bottomBorderValue.color().resolve(cellColor), | 128 bottomBorderValue.color().resolve(cellColor), |
159 collapsedBorderStyle(bottomBorderValue.style()), 0, 0, true); | 129 collapsedBorderStyle(bottomBorderValue.style()), 0, 0, true); |
160 } | 130 } |
161 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { | 131 if (leftBorderValue.shouldPaint(currentBorderValue)) { |
162 ObjectPainter::drawLineForBoxSide( | 132 ObjectPainter::drawLineForBoxSide( |
163 graphicsContext, borderRect.x(), borderRect.y(), | 133 graphicsContext, borderRect.x(), borderRect.y(), |
164 borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, | 134 borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, |
165 leftBorderValue.color().resolve(cellColor), | 135 leftBorderValue.color().resolve(cellColor), |
166 collapsedBorderStyle(leftBorderValue.style()), 0, 0, true); | 136 collapsedBorderStyle(leftBorderValue.style()), 0, 0, true); |
167 } | 137 } |
168 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { | 138 if (rightBorderValue.shouldPaint(currentBorderValue)) { |
169 ObjectPainter::drawLineForBoxSide( | 139 ObjectPainter::drawLineForBoxSide( |
170 graphicsContext, borderRect.maxX() - rightWidth, borderRect.y(), | 140 graphicsContext, borderRect.maxX() - rightWidth, borderRect.y(), |
171 borderRect.maxX(), borderRect.maxY(), BSRight, | 141 borderRect.maxX(), borderRect.maxY(), BSRight, |
172 rightBorderValue.color().resolve(cellColor), | 142 rightBorderValue.color().resolve(cellColor), |
173 collapsedBorderStyle(rightBorderValue.style()), 0, 0, true); | 143 collapsedBorderStyle(rightBorderValue.style()), 0, 0, true); |
174 } | 144 } |
175 } | 145 } |
176 | 146 |
177 void TableCellPainter::paintContainerBackgroundBehindCell( | 147 void TableCellPainter::paintContainerBackgroundBehindCell( |
178 const PaintInfo& paintInfo, | 148 const PaintInfo& paintInfo, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 270 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
301 } | 271 } |
302 | 272 |
303 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( | 273 LayoutRect TableCellPainter::paintRectNotIncludingVisualOverflow( |
304 const LayoutPoint& paintOffset) { | 274 const LayoutPoint& paintOffset) { |
305 return LayoutRect(paintOffset, | 275 return LayoutRect(paintOffset, |
306 LayoutSize(m_layoutTableCell.pixelSnappedSize())); | 276 LayoutSize(m_layoutTableCell.pixelSnappedSize())); |
307 } | 277 } |
308 | 278 |
309 } // namespace blink | 279 } // namespace blink |
OLD | NEW |