Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1424)

Side by Side Diff: Source/core/paint/TableCellPainter.cpp

Issue 724483002: Move painting code from RenderTableCell to TableCellPainter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/paint/TableCellPainter.h ('k') | Source/core/paint/TableRowPainter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/paint/TableCellPainter.h"
7
8 #include "core/paint/BlockPainter.h"
9 #include "core/paint/BoxPainter.h"
10 #include "core/paint/DrawingRecorder.h"
11 #include "core/rendering/PaintInfo.h"
12 #include "core/rendering/RenderTableCell.h"
13
14 namespace blink {
15
16 inline CollapsedBorderValue TableCellPainter::cachedCollapsedLeftBorder(const Re nderStyle* styleForCellFlow) const
17 {
18 if (styleForCellFlow->isHorizontalWritingMode()) {
19 return styleForCellFlow->isLeftToRightDirection() ? m_renderTableCell.se ction()->cachedCollapsedBorder(&m_renderTableCell, CBSStart)
20 : m_renderTableCell.section()->cachedCollapsedBorder(&m_renderTableC ell, CBSEnd);
21 }
22 return styleForCellFlow->slowIsFlippedBlocksWritingMode() ? m_renderTableCel l.section()->cachedCollapsedBorder(&m_renderTableCell, CBSAfter)
23 : m_renderTableCell.section()->cachedCollapsedBorder(&m_renderTableCell, CBSBefore);
24 }
25
26 inline CollapsedBorderValue TableCellPainter::cachedCollapsedRightBorder(const R enderStyle* styleForCellFlow) const
27 {
28 if (styleForCellFlow->isHorizontalWritingMode()) {
29 return styleForCellFlow->isLeftToRightDirection() ? m_renderTableCell.se ction()->cachedCollapsedBorder(&m_renderTableCell, CBSEnd)
30 : m_renderTableCell.section()->cachedCollapsedBorder(&m_renderTableC ell, CBSStart);
31 }
32 return styleForCellFlow->slowIsFlippedBlocksWritingMode() ? m_renderTableCel l.section()->cachedCollapsedBorder(&m_renderTableCell, CBSBefore)
33 : m_renderTableCell.section()->cachedCollapsedBorder(&m_renderTableCell, CBSAfter);
34 }
35
36 inline CollapsedBorderValue TableCellPainter::cachedCollapsedTopBorder(const Ren derStyle* styleForCellFlow) const
37 {
38 if (styleForCellFlow->isHorizontalWritingMode())
39 return styleForCellFlow->slowIsFlippedBlocksWritingMode() ? m_renderTabl eCell.section()->cachedCollapsedBorder(&m_renderTableCell, CBSAfter) : m_renderT ableCell.section()->cachedCollapsedBorder(&m_renderTableCell, CBSBefore);
40 return styleForCellFlow->isLeftToRightDirection() ? m_renderTableCell.sectio n()->cachedCollapsedBorder(&m_renderTableCell, CBSStart) : m_renderTableCell.sec tion()->cachedCollapsedBorder(&m_renderTableCell, CBSEnd);
41 }
42
43 inline CollapsedBorderValue TableCellPainter::cachedCollapsedBottomBorder(const RenderStyle* styleForCellFlow) const
44 {
45 if (styleForCellFlow->isHorizontalWritingMode()) {
46 return styleForCellFlow->slowIsFlippedBlocksWritingMode() ? m_renderTabl eCell.section()->cachedCollapsedBorder(&m_renderTableCell, CBSBefore)
47 : m_renderTableCell.section()->cachedCollapsedBorder(&m_renderTableC ell, CBSAfter);
48 }
49 return styleForCellFlow->isLeftToRightDirection() ? m_renderTableCell.sectio n()->cachedCollapsedBorder(&m_renderTableCell, CBSEnd)
50 : m_renderTableCell.section()->cachedCollapsedBorder(&m_renderTableCell, CBSStart);
51 }
52
53 void TableCellPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse t)
54 {
55 ASSERT(paintInfo.phase != PaintPhaseCollapsedTableBorders);
56 BlockPainter(m_renderTableCell).paint(paintInfo, paintOffset);
57 }
58
59 struct CollapsedBorder {
60 CollapsedBorderValue borderValue;
61 BoxSide side;
62 bool shouldPaint;
63 int x1;
64 int y1;
65 int x2;
66 int y2;
67 EBorderStyle style;
68 };
69
70 class CollapsedBorders {
71 public:
72 CollapsedBorders()
73 : m_count(0)
74 {
75 }
76
77 void addBorder(const CollapsedBorderValue& borderValue, BoxSide borderSide, bool shouldPaint, int x1, int y1, int x2, int y2, EBorderStyle borderStyle)
78 {
79 if (borderValue.exists() && shouldPaint) {
80 m_borders[m_count].borderValue = borderValue;
81 m_borders[m_count].side = borderSide;
82 m_borders[m_count].shouldPaint = shouldPaint;
83 m_borders[m_count].x1 = x1;
84 m_borders[m_count].x2 = x2;
85 m_borders[m_count].y1 = y1;
86 m_borders[m_count].y2 = y2;
87 m_borders[m_count].style = borderStyle;
88 m_count++;
89 }
90 }
91
92 CollapsedBorder* nextBorder()
93 {
94 for (unsigned i = 0; i < m_count; i++) {
95 if (m_borders[i].borderValue.exists() && m_borders[i].shouldPaint) {
96 m_borders[i].shouldPaint = false;
97 return &m_borders[i];
98 }
99 }
100
101 return 0;
102 }
103
104 CollapsedBorder m_borders[4];
105 unsigned m_count;
106 };
107
108 static EBorderStyle collapsedBorderStyle(EBorderStyle style)
109 {
110 if (style == OUTSET)
111 return GROOVE;
112 if (style == INSET)
113 return RIDGE;
114 return style;
115 }
116
117 void TableCellPainter::paintCollapsedBorders(PaintInfo& paintInfo, const LayoutP oint& paintOffset)
118 {
119 ASSERT(paintInfo.phase == PaintPhaseCollapsedTableBorders);
120
121 if (!paintInfo.shouldPaintWithinRoot(&m_renderTableCell) || m_renderTableCel l.style()->visibility() != VISIBLE)
122 return;
123
124 LayoutRect paintRect = LayoutRect(paintOffset + m_renderTableCell.location() , m_renderTableCell.pixelSnappedSize());
125 if (paintRect.y() - m_renderTableCell.table()->outerBorderTop() >= paintInfo .rect.maxY())
126 return;
127
128 if (paintRect.maxY() + m_renderTableCell.table()->outerBorderBottom() <= pai ntInfo.rect.y())
129 return;
130
131 if (!m_renderTableCell.table()->currentBorderValue())
132 return;
133
134 const RenderStyle* styleForCellFlow = m_renderTableCell.styleForCellFlow();
135 CollapsedBorderValue leftVal = cachedCollapsedLeftBorder(styleForCellFlow);
136 CollapsedBorderValue rightVal = cachedCollapsedRightBorder(styleForCellFlow) ;
137 CollapsedBorderValue topVal = cachedCollapsedTopBorder(styleForCellFlow);
138 CollapsedBorderValue bottomVal = cachedCollapsedBottomBorder(styleForCellFlo w);
139
140 // Adjust our x/y/width/height so that we paint the collapsed borders at the correct location.
141 int topWidth = topVal.width();
142 int bottomWidth = bottomVal.width();
143 int leftWidth = leftVal.width();
144 int rightWidth = rightVal.width();
145
146 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2,
147 paintRect.y() - topWidth / 2,
148 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2,
149 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2);
150
151 EBorderStyle topStyle = collapsedBorderStyle(topVal.style());
152 EBorderStyle bottomStyle = collapsedBorderStyle(bottomVal.style());
153 EBorderStyle leftStyle = collapsedBorderStyle(leftVal.style());
154 EBorderStyle rightStyle = collapsedBorderStyle(rightVal.style());
155
156 bool renderTop = topStyle > BHIDDEN && !topVal.isTransparent();
157 bool renderBottom = bottomStyle > BHIDDEN && !bottomVal.isTransparent();
158 bool renderLeft = leftStyle > BHIDDEN && !leftVal.isTransparent();
159 bool renderRight = rightStyle > BHIDDEN && !rightVal.isTransparent();
160
161 // We never paint diagonals at the joins. We simply let the border with the highest
162 // precedence paint on top of borders with lower precedence.
163 CollapsedBorders borders;
164 borders.addBorder(topVal, BSTop, renderTop, borderRect.x(), borderRect.y(), borderRect.maxX(), borderRect.y() + topWidth, topStyle);
165 borders.addBorder(bottomVal, BSBottom, renderBottom, borderRect.x(), borderR ect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), bottomStyle);
166 borders.addBorder(leftVal, BSLeft, renderLeft, borderRect.x(), borderRect.y( ), borderRect.x() + leftWidth, borderRect.maxY(), leftStyle);
167 borders.addBorder(rightVal, BSRight, renderRight, borderRect.maxX() - rightW idth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), rightStyle);
168
169 GraphicsContext* graphicsContext = paintInfo.context;
170 bool antialias = BoxPainter::shouldAntialiasLines(graphicsContext);
171
172 for (CollapsedBorder* border = borders.nextBorder(); border; border = border s.nextBorder()) {
173 if (border->borderValue.isSameIgnoringColor(*m_renderTableCell.table()-> currentBorderValue())) {
174 ObjectPainter::drawLineForBoxSide(graphicsContext, border->x1, borde r->y1, border->x2, border->y2, border->side,
175 border->borderValue.color().resolve(m_renderTableCell.style()->v isitedDependentColor(CSSPropertyColor)), border->style, 0, 0, antialias);
176 }
177 }
178 }
179
180 void TableCellPainter::paintBackgroundsBehindCell(PaintInfo& paintInfo, const La youtPoint& paintOffset, RenderObject* backgroundObject)
181 {
182 if (!paintInfo.shouldPaintWithinRoot(&m_renderTableCell))
183 return;
184
185 if (!backgroundObject)
186 return;
187
188 if (m_renderTableCell.style()->visibility() != VISIBLE)
189 return;
190
191 RenderTable* tableElt = m_renderTableCell.table();
192 if (!tableElt->collapseBorders() && m_renderTableCell.style()->emptyCells() == HIDE && !m_renderTableCell.firstChild())
193 return;
194
195 LayoutPoint adjustedPaintOffset = paintOffset;
196 if (backgroundObject != &m_renderTableCell)
197 adjustedPaintOffset.moveBy(m_renderTableCell.location());
198
199 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor);
200 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers();
201
202 if (bgLayer.hasImage() || c.alpha()) {
203 // We have to clip here because the background would paint
204 // on top of the borders otherwise. This only matters for cells and row s.
205 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == & m_renderTableCell || backgroundObject == m_renderTableCell.parent()) && tableElt ->collapseBorders();
206 GraphicsContextStateSaver stateSaver(*paintInfo.context, shouldClip);
207 if (shouldClip) {
208 LayoutRect clipRect(adjustedPaintOffset.x() + m_renderTableCell.bord erLeft(), adjustedPaintOffset.y() + m_renderTableCell.borderTop(),
209 m_renderTableCell.width() - m_renderTableCell.borderLeft() - m_r enderTableCell.borderRight(),
210 m_renderTableCell.height() - m_renderTableCell.borderTop() - m_r enderTableCell.borderBottom());
211 paintInfo.context->clip(clipRect);
212 }
213 BoxPainter(m_renderTableCell).paintFillLayers(paintInfo, c, bgLayer, Lay outRect(adjustedPaintOffset, m_renderTableCell.pixelSnappedSize()), BackgroundBl eedNone, CompositeSourceOver, backgroundObject);
214 }
215 }
216
217 void TableCellPainter::paintBoxDecorationBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
218 {
219 if (!paintInfo.shouldPaintWithinRoot(&m_renderTableCell))
220 return;
221
222 RenderTable* tableElt = m_renderTableCell.table();
223 if (!tableElt->collapseBorders() && m_renderTableCell.style()->emptyCells() == HIDE && !m_renderTableCell.firstChild())
224 return;
225
226 LayoutRect paintRect = LayoutRect(paintOffset, m_renderTableCell.pixelSnappe dSize());
227 DrawingRecorder recorder(paintInfo.context, &m_renderTableCell, paintInfo.ph ase, pixelSnappedIntRect(paintRect));
228 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_renderTableCell.style(), Normal);
229
230 // Paint our cell background.
231 paintBackgroundsBehindCell(paintInfo, paintOffset, &m_renderTableCell);
232
233 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_renderTableCell.style(), Inset);
234
235 if (!m_renderTableCell.style()->hasBorder() || tableElt->collapseBorders())
236 return;
237
238 BoxPainter::paintBorder(m_renderTableCell, paintInfo, paintRect, m_renderTab leCell.style());
239 }
240
241 void TableCellPainter::paintMask(PaintInfo& paintInfo, const LayoutPoint& paintO ffset)
242 {
243 if (m_renderTableCell.style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask)
244 return;
245
246 RenderTable* tableElt = m_renderTableCell.table();
247 if (!tableElt->collapseBorders() && m_renderTableCell.style()->emptyCells() == HIDE && !m_renderTableCell.firstChild())
248 return;
249
250 BoxPainter(m_renderTableCell).paintMaskImages(paintInfo, LayoutRect(paintOff set, m_renderTableCell.pixelSnappedSize()));
251 }
252
253 } // namespace blink
254
OLDNEW
« no previous file with comments | « Source/core/paint/TableCellPainter.h ('k') | Source/core/paint/TableRowPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698