Chromium Code Reviews| 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/layout/LayoutTableCol.h" | |
| 8 #include "core/paint/BlockPainter.h" | 9 #include "core/paint/BlockPainter.h" |
| 9 #include "core/paint/BoxPainter.h" | 10 #include "core/paint/BoxPainter.h" |
| 10 #include "core/paint/LayoutObjectDrawingRecorder.h" | 11 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 11 #include "core/paint/PaintInfo.h" | 12 #include "core/paint/PaintInfo.h" |
| 12 #include "platform/graphics/GraphicsContextStateSaver.h" | 13 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 inline const CollapsedBorderValue* TableCellPainter::cachedCollapsedLeftBorder(c onst ComputedStyle& styleForCellFlow) const | 17 inline const CollapsedBorderValue* TableCellPainter::cachedCollapsedLeftBorder(c onst ComputedStyle& styleForCellFlow) const |
| 17 { | 18 { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { | 135 if (displayItemType & DisplayItem::TableCollapsedBorderLeft) { |
| 135 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, | 136 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.x(), borde rRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), BSLeft, |
| 136 leftBorderValue->color().resolve(cellColor), collapsedBorderStyle(le ftBorderValue->style()), 0, 0, true); | 137 leftBorderValue->color().resolve(cellColor), collapsedBorderStyle(le ftBorderValue->style()), 0, 0, true); |
| 137 } | 138 } |
| 138 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { | 139 if (displayItemType & DisplayItem::TableCollapsedBorderRight) { |
| 139 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.maxX() - r ightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), BSRight, | 140 ObjectPainter::drawLineForBoxSide(graphicsContext, borderRect.maxX() - r ightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), BSRight, |
| 140 rightBorderValue->color().resolve(cellColor), collapsedBorderStyle(r ightBorderValue->style()), 0, 0, true); | 141 rightBorderValue->color().resolve(cellColor), collapsedBorderStyle(r ightBorderValue->style()), 0, 0, true); |
| 141 } | 142 } |
| 142 } | 143 } |
| 143 | 144 |
| 144 void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co nst LayoutPoint& paintOffset, const LayoutObject* backgroundObject, DisplayItem: :Type type) | 145 |
|
Xianzhu
2016/02/23 22:58:27
Nit: unnecessary change.
atotic1
2016/03/15 16:50:47
I need this because paintBounds now takes a Layout
| |
| 146 void TableCellPainter::paintBackgroundsBehindCell(const PaintInfo& paintInfo, co nst LayoutPoint& paintOffset, const LayoutBox* backgroundObject, DisplayItem::Ty pe type) | |
| 145 { | 147 { |
| 146 if (!backgroundObject) | 148 if (!backgroundObject) |
| 147 return; | 149 return; |
| 148 | 150 |
| 149 if (m_layoutTableCell.style()->visibility() != VISIBLE) | 151 if (m_layoutTableCell.style()->visibility() != VISIBLE) |
| 150 return; | 152 return; |
| 151 | 153 |
| 152 LayoutTable* tableElt = m_layoutTableCell.table(); | 154 LayoutTable* tableElt = m_layoutTableCell.table(); |
| 153 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == HIDE && !m_layoutTableCell.firstChild()) | 155 if (!tableElt->collapseBorders() && m_layoutTableCell.style()->emptyCells() == HIDE && !m_layoutTableCell.firstChild()) |
| 154 return; | 156 return; |
| 155 | 157 |
| 156 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent); | 158 LayoutRect paintRect = paintBounds(paintOffset, backgroundObject != &m_layou tTableCell ? AddOffsetFromParent : DoNotAddOffsetFromParent, backgroundObject, t ype); |
| 159 | |
| 160 // Background objects have to enclose the entire cell | |
|
Xianzhu
2016/02/23 22:58:27
Nit: '.' as the end of the comment.
atotic1
2016/03/15 16:50:47
Done.
| |
| 161 if (backgroundObject != &m_layoutTableCell) { | |
|
Xianzhu
2016/02/23 22:58:27
Nit: extra space after !=
Can you combine this bl
atotic1
2016/03/15 16:50:47
Done.
| |
| 162 LayoutRect cellRect = m_layoutTableCell.frameRect(); | |
| 163 cellRect.moveBy(paintOffset); | |
| 164 paintRect.unite(cellRect); | |
| 165 } | |
| 157 | 166 |
| 158 // Record drawing only if the cell is painting background from containers. | 167 // Record drawing only if the cell is painting background from containers. |
| 159 Optional<LayoutObjectDrawingRecorder> recorder; | 168 Optional<LayoutObjectDrawingRecorder> recorder; |
| 160 if (backgroundObject != &m_layoutTableCell) { | 169 if (backgroundObject != &m_layoutTableCell) { |
| 161 LayoutPoint adjustedPaintOffset = paintRect.location(); | 170 LayoutPoint adjustedPaintOffset = paintRect.location(); |
| 162 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.co ntext, m_layoutTableCell, type, adjustedPaintOffset)) | 171 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.co ntext, m_layoutTableCell, type, adjustedPaintOffset)) { |
| 163 return; | 172 return; |
| 173 } | |
|
Xianzhu
2016/02/23 22:58:27
Nit: Unnecessary change.
atotic1
2016/03/15 16:50:47
Done.
| |
| 164 recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect, adjustedPaintOffset); | 174 recorder.emplace(paintInfo.context, m_layoutTableCell, type, paintRect, adjustedPaintOffset); |
| 165 } else { | |
| 166 ASSERT(paintRect.location() == paintOffset); | |
|
Xianzhu
2016/02/23 22:58:27
Why is this removed?
| |
| 167 } | 175 } |
| 168 | 176 |
| 169 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); | 177 Color c = backgroundObject->resolveColor(CSSPropertyBackgroundColor); |
| 170 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); | 178 const FillLayer& bgLayer = backgroundObject->style()->backgroundLayers(); |
| 179 FillLayer bgAdjustedLayer(bgLayer); | |
| 171 if (bgLayer.hasImage() || c.alpha()) { | 180 if (bgLayer.hasImage() || c.alpha()) { |
| 172 // We have to clip here because the background would paint | 181 bool shouldClipCell = backgroundObject->hasLayer() && (backgroundObject == &m_layoutTableCell) && tableElt->collapseBorders(); |
| 173 // on top of the borders otherwise. This only matters for cells and row s. | 182 bool shouldClipBackground = backgroundObject != &m_layoutTableCell; |
| 174 bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == & m_layoutTableCell || backgroundObject == m_layoutTableCell.parent()) && tableElt ->collapseBorders(); | 183 |
| 175 GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClip); | 184 GraphicsContextStateSaver stateSaver(paintInfo.context, shouldClipCell | | shouldClipBackground); |
| 176 if (shouldClip) { | 185 if (shouldClipCell) { |
| 186 // We have to clip here because the background would paint | |
| 187 // on top of the borders otherwise. This only matters for cells and rows. | |
| 177 LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size()); | 188 LayoutRect clipRect(paintRect.location(), m_layoutTableCell.size()); |
| 178 clipRect.expand(m_layoutTableCell.borderInsets()); | 189 clipRect.expand(m_layoutTableCell.borderInsets()); |
| 179 paintInfo.context.clip(pixelSnappedIntRect(clipRect)); | 190 paintInfo.context.clip(pixelSnappedIntRect(clipRect)); |
| 191 } else if (shouldClipBackground) { | |
| 192 LayoutRect clipRect(m_layoutTableCell.location(), m_layoutTableCell. size()); | |
| 193 clipRect.moveBy(paintOffset); | |
| 194 paintInfo.context.clip(pixelSnappedIntRect(clipRect)); | |
| 195 paintRect.unite(clipRect); | |
| 180 } | 196 } |
| 181 BoxPainter(m_layoutTableCell).paintFillLayers(paintInfo, c, bgLayer, pai ntRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject); | 197 BoxPainter(*backgroundObject).paintFillLayers(paintInfo, c, bgLayer, pai ntRect, BackgroundBleedNone, SkXfermode::kSrcOver_Mode, backgroundObject); |
| 182 } | 198 } |
| 183 } | 199 } |
| 184 | 200 |
| 185 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) | 201 void TableCellPainter::paintBoxDecorationBackground(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| 186 { | 202 { |
| 187 LayoutTable* table = m_layoutTableCell.table(); | 203 LayoutTable* table = m_layoutTableCell.table(); |
| 188 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() == HIDE && !m_layoutTableCell.firstChild()) | 204 if (!table->collapseBorders() && m_layoutTableCell.style()->emptyCells() == HIDE && !m_layoutTableCell.firstChild()) |
| 189 return; | 205 return; |
| 190 | 206 |
| 191 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration() && !table->collapseBorders(); | 207 bool needsToPaintBorder = m_layoutTableCell.styleRef().hasBorderDecoration() && !table->collapseBorders(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 return; | 241 return; |
| 226 | 242 |
| 227 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, paintInfo.phase, paintOffset)) | 243 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex t, m_layoutTableCell, paintInfo.phase, paintOffset)) |
| 228 return; | 244 return; |
| 229 | 245 |
| 230 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); | 246 LayoutRect paintRect = paintBounds(paintOffset, DoNotAddOffsetFromParent); |
| 231 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p aintInfo.phase, paintRect, paintOffset); | 247 LayoutObjectDrawingRecorder recorder(paintInfo.context, m_layoutTableCell, p aintInfo.phase, paintRect, paintOffset); |
| 232 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); | 248 BoxPainter(m_layoutTableCell).paintMaskImages(paintInfo, paintRect); |
| 233 } | 249 } |
| 234 | 250 |
| 235 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior) | 251 // Computed bounds for cell, or background objects |
| 252 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior, const LayoutBox* backgroundObject, D isplayItem::Type type) | |
| 236 { | 253 { |
| 254 | |
| 237 LayoutPoint adjustedPaintOffset = paintOffset; | 255 LayoutPoint adjustedPaintOffset = paintOffset; |
| 238 if (paintBoundOffsetBehavior == AddOffsetFromParent) | 256 if (paintBoundOffsetBehavior == AddOffsetFromParent) |
| 239 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); | 257 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); |
| 258 | |
| 259 if (backgroundObject) { | |
| 260 LayoutRect position; | |
| 261 switch (type) { | |
| 262 case DisplayItem::TableCellBackgroundFromColumnGroup: | |
| 263 case DisplayItem::TableCellBackgroundFromColumn: | |
| 264 { | |
| 265 position = static_cast<const LayoutTableCol*>(backgroundObject)->pos itionByCellSpan(); | |
| 266 // position is relative to table, must correct for section location | |
| 267 LayoutPoint sectionLocation = m_layoutTableCell.section()->location( ); | |
| 268 position.moveBy(-sectionLocation); | |
| 269 position.moveBy(paintOffset); | |
| 270 } | |
| 271 break; | |
| 272 case DisplayItem::TableCellBackgroundFromSection: | |
| 273 position = static_cast<const LayoutTableSection*>(backgroundObject)- >positionByCellSpan(); | |
| 274 position.moveBy(paintOffset); | |
| 275 break; | |
| 276 case DisplayItem::TableCellBackgroundFromRow: | |
| 277 position = static_cast<const LayoutTableRow*>(backgroundObject)->pos itionByCellSpan(); | |
| 278 position.moveBy(paintOffset); | |
| 279 break; | |
| 280 case DisplayItem::BoxDecorationBackground: | |
| 281 position = LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTable Cell.pixelSnappedSize())); | |
| 282 break; | |
| 283 default: | |
| 284 ASSERT(false); | |
| 285 break; | |
| 286 } | |
| 287 return position; | |
| 288 } | |
| 240 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize())); | 289 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize())); |
| 241 } | 290 } |
| 242 | 291 |
| 243 } // namespace blink | 292 } // namespace blink |
| 244 | 293 |
| OLD | NEW |