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 "config.h" | 5 #include "config.h" |
6 #include "core/paint/TableCellPainter.h" | 6 #include "core/paint/TableCellPainter.h" |
7 | 7 |
8 #include "core/layout/LayoutTableCell.h" | 8 #include "core/layout/LayoutTableCell.h" |
9 #include "core/paint/BlockPainter.h" | 9 #include "core/paint/BlockPainter.h" |
10 #include "core/paint/BoxPainter.h" | 10 #include "core/paint/BoxPainter.h" |
(...skipping 87 matching lines...) Loading... |
98 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); | 98 LayoutRect paintRect = paintBounds(paintOffset, AddOffsetFromParent); |
99 LayoutPoint adjustedPaintOffset = paintRect.location(); | 99 LayoutPoint adjustedPaintOffset = paintRect.location(); |
100 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, | 100 IntRect borderRect = pixelSnappedIntRect(paintRect.x() - leftWidth / 2, |
101 paintRect.y() - topWidth / 2, | 101 paintRect.y() - topWidth / 2, |
102 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, | 102 paintRect.width() + leftWidth / 2 + (rightWidth + 1) / 2, |
103 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); | 103 paintRect.height() + topWidth / 2 + (bottomWidth + 1) / 2); |
104 | 104 |
105 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) | 105 if (!paintInfo.cullRect().intersectsCullRect(borderRect)) |
106 return; | 106 return; |
107 | 107 |
108 GraphicsContext* graphicsContext = paintInfo.context; | 108 GraphicsContext& graphicsContext = paintInfo.context; |
109 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*graphicsContext
, m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType), adjustedPa
intOffset)) | 109 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(graphicsContext,
m_layoutTableCell, static_cast<DisplayItem::Type>(displayItemType), adjustedPai
ntOffset)) |
110 return; | 110 return; |
111 | 111 |
112 LayoutObjectDrawingRecorder recorder(*graphicsContext, m_layoutTableCell, st
atic_cast<DisplayItem::Type>(displayItemType), borderRect, adjustedPaintOffset); | 112 LayoutObjectDrawingRecorder recorder(graphicsContext, m_layoutTableCell, sta
tic_cast<DisplayItem::Type>(displayItemType), borderRect, adjustedPaintOffset); |
113 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); | 113 Color cellColor = m_layoutTableCell.resolveColor(CSSPropertyColor); |
114 | 114 |
115 // We never paint diagonals at the joins. We simply let the border with the
highest | 115 // We never paint diagonals at the joins. We simply let the border with the
highest |
116 // precedence paint on top of borders with lower precedence. | 116 // precedence paint on top of borders with lower precedence. |
117 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { | 117 if (displayItemType & DisplayItem::TableCollapsedBorderTop) { |
118 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.y(), borderRect.maxX(), borderRect.y() + topWidth, BSTop, | 118 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.y(), borderRect.maxX(), borderRect.y() + topWidth, BSTop, |
119 topBorderValue.color().resolve(cellColor), collapsedBorderStyle(topB
orderValue.style()), 0, 0, true); | 119 topBorderValue.color().resolve(cellColor), collapsedBorderStyle(topB
orderValue.style()), 0, 0, true); |
120 } | 120 } |
121 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { | 121 if (displayItemType & DisplayItem::TableCollapsedBorderBottom) { |
122 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), BSBottom, | 122 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde
rRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), BSBottom, |
(...skipping 23 matching lines...) Loading... |
146 LayoutTable* tableElt = m_layoutTableCell.table(); | 146 LayoutTable* tableElt = m_layoutTableCell.table(); |
147 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) | 147 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) |
148 return; | 148 return; |
149 | 149 |
150 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou
tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent); | 150 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou
tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent); |
151 | 151 |
152 // Record drawing only if the cell is painting background from containers. | 152 // Record drawing only if the cell is painting background from containers. |
153 Optional<LayoutObjectDrawingRecorder> recorder; | 153 Optional<LayoutObjectDrawingRecorder> recorder; |
154 if (backgroundObject != &m_layoutTableCell) { | 154 if (backgroundObject != &m_layoutTableCell) { |
155 LayoutPoint adjustedPaintOffset = paintRect.location(); | 155 LayoutPoint adjustedPaintOffset = paintRect.location(); |
156 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.c
ontext, m_layoutTableCell, type, adjustedPaintOffset)) | 156 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.co
ntext, m_layoutTableCell, type, adjustedPaintOffset)) |
157 return; | 157 return; |
158 recorder.emplace(*paintInfo.context, m_layoutTableCell, type, paintRect,
adjustedPaintOffset); | 158 recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect,
adjustedPaintOffset); |
159 } else { | 159 } else { |
160 ASSERT(paintRect.location() == paintOffset); | 160 ASSERT(paintRect.location() == paintOffset); |
161 } | 161 } |
162 | 162 |
163 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); | 163 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); |
164 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); | 164 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); |
165 if (bgLayer.hasImage() || c.alpha()) { | 165 if (bgLayer.hasImage() || c.alpha()) { |
166 // We have to clip here because the background would paint | 166 // We have to clip here because the background would paint |
167 // on top of the borders otherwise. This only matters for cells and row
s. | 167 // on top of the borders otherwise. This only matters for cells and row
s. |
168 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == &
m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt
->collapseBorders(); | 168 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == &
m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt
->collapseBorders(); |
169 GraphicsContextStateSaver stateSaver(*paintInfo.context, shouldClip); | 169 GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClip); |
170 if (shouldClip) { | 170 if (shouldClip) { |
171 LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size()); | 171 LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size()); |
172 clipRect.expand(m_layoutTableCell.borderInsets()); | 172 clipRect.expand(m_layoutTableCell.borderInsets()); |
173 paintInfo.context->clip(pixelSnappedIntRect(clipRect)); | 173 paintInfo.context.clip(pixelSnappedIntRect(clipRect)); |
174 } | 174 } |
175 BoxPainter(m_layoutTableCell).paintFillLayers(paintInfo, c, bgLayer, pai
ntRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject); | 175 BoxPainter(m_layoutTableCell).paintFillLayers(paintInfo, c, bgLayer, pai
ntRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo,
const LayoutPoint& paintOffset) | 179 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo,
const LayoutPoint& paintOffset) |
180 { | 180 { |
181 if (!paintInfo.shouldPaintWithinRoot(&m_layoutTableCell)) | 181 if (!paintInfo.shouldPaintWithinRoot(&m_layoutTableCell)) |
182 return; | 182 return; |
183 | 183 |
184 LayoutTable* table = m_layoutTableCell.table(); | 184 LayoutTable* table = m_layoutTableCell.table(); |
185 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() ==
HIDE && !m_layoutTableCell.firstChild()) | 185 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() ==
HIDE && !m_layoutTableCell.firstChild()) |
186 return; | 186 return; |
187 | 187 |
188 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration()
&& !table->collapseBorders(); | 188 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration()
&& !table->collapseBorders(); |
189 if (!m_layoutTableCell.hasBackground() && !m_layoutTableCell.styleRef().boxS
hadow() && !needsToPaintBorder) | 189 if (!m_layoutTableCell.hasBackground() && !m_layoutTableCell.styleRef().boxS
hadow() && !needsToPaintBorder) |
190 return; | 190 return; |
191 | 191 |
192 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.conte
xt, m_layoutTableCell, DisplayItem::BoxDecorationBackground, paintOffset)) | 192 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutTableCell, DisplayItem::BoxDecorationBackground, paintOffset)) |
193 return; | 193 return; |
194 | 194 |
195 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); | 195 LayoutRect visualOverflowRect = m_layoutTableCell.visualOverflowRect(); |
196 visualOverflowRect.moveBy(paintOffset); | 196 visualOverflowRect.moveBy(paintOffset); |
197 // TODO(chrishtr): the pixel-snapping here is likely incorrect. | 197 // TODO(chrishtr): the pixel-snapping here is likely incorrect. |
198 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutTableCell,
DisplayItem::BoxDecorationBackground, pixelSnappedIntRect(visualOverflowRect), p
aintOffset); | 198 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, D
isplayItem::BoxDecorationBackground, pixelSnappedIntRect(visualOverflowRect), pa
intOffset); |
199 | 199 |
200 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 200 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); |
201 | 201 |
202 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Normal); | 202 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Normal); |
203 | 203 |
204 // Paint our cell background. | 204 // Paint our cell background. |
205 paintBackgroundsBehindCell(paintInfo, paintOffset, &m_layoutTableCell, Displ
ayItem::BoxDecorationBackground); | 205 paintBackgroundsBehindCell(paintInfo, paintOffset, &m_layoutTableCell, Displ
ayItem::BoxDecorationBackground); |
206 | 206 |
207 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Inset); | 207 BoxPainter::paintBoxShadow(paintInfo, paintRect, m_layoutTableCell.styleRef(
), Inset); |
208 | 208 |
209 if (!needsToPaintBorder) | 209 if (!needsToPaintBorder) |
210 return; | 210 return; |
211 | 211 |
212 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, m_layoutTab
leCell.styleRef()); | 212 BoxPainter::paintBorder(m_layoutTableCell, paintInfo, paintRect, m_layoutTab
leCell.styleRef()); |
213 } | 213 } |
214 | 214 |
215 void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 215 void TableCellPainter::paintMask(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
216 { | 216 { |
217 if (m_layoutTableCell.style()->visibility() != VISIBLE || paintInfo.phase !=
PaintPhaseMask) | 217 if (m_layoutTableCell.style()->visibility() != VISIBLE || paintInfo.phase !=
PaintPhaseMask) |
218 return; | 218 return; |
219 | 219 |
220 LayoutTable* tableElt = m_layoutTableCell.table(); | 220 LayoutTable* tableElt = m_layoutTableCell.table(); |
221 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) | 221 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells()
== HIDE && !m_layoutTableCell.firstChild()) |
222 return; | 222 return; |
223 | 223 |
224 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintInfo.conte
xt, m_layoutTableCell, paintInfo.phase, paintOffset)) | 224 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutTableCell, paintInfo.phase, paintOffset)) |
225 return; | 225 return; |
226 | 226 |
227 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 227 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); |
228 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutTableCell,
paintInfo.phase, paintRect, paintOffset); | 228 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p
aintInfo.phase, paintRect, paintOffset); |
229 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 229 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
230 } | 230 } |
231 | 231 |
232 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo
undOffsetBehavior paintBoundOffsetBehavior) | 232 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo
undOffsetBehavior paintBoundOffsetBehavior) |
233 { | 233 { |
234 LayoutPoint adjustedPaintOffset = paintOffset; | 234 LayoutPoint adjustedPaintOffset = paintOffset; |
235 if (paintBoundOffsetBehavior == AddOffsetFromParent) | 235 if (paintBoundOffsetBehavior == AddOffsetFromParent) |
236 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); | 236 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); |
237 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna
ppedSize())); | 237 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna
ppedSize())); |
238 } | 238 } |
239 | 239 |
240 } // namespace blink | 240 } // namespace blink |
241 | 241 |
OLD | NEW |