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

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

Issue 1549693002: Optimize collapsed border painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Field instead of global HashMap Created 4 years, 12 months 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
OLDNEW
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/PaintInfo.h" 11 #include "core/paint/PaintInfo.h"
12 #include "platform/graphics/GraphicsContextStateSaver.h" 12 #include "platform/graphics/GraphicsContextStateSaver.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 inline const CollapsedBorderValue& TableCellPainter::cachedCollapsedLeftBorder(c onst ComputedStyle& styleForCellFlow) const 16 static const CollapsedBorderValue& collapsedLeftBorder(const ComputedStyle& styl eForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
17 { 17 {
18 if (styleForCellFlow.isHorizontalWritingMode()) { 18 if (styleForCellFlow.isHorizontalWritingMode())
19 return styleForCellFlow.isLeftToRightDirection() ? m_layoutTableCell.se ction()->cachedCollapsedBorder(&m_layoutTableCell, CBSStart) 19 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder : values.endBorder;
20 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSEnd); 20 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorder : values.beforeBorder;
21 }
22 return styleForCellFlow.isFlippedBlocksWritingMode() ? m_layoutTableCell.se ction()->cachedCollapsedBorder(&m_layoutTableCell, CBSAfter)
23 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSBefore);
24 } 21 }
25 22
26 inline const CollapsedBorderValue& TableCellPainter::cachedCollapsedRightBorder( const ComputedStyle& styleForCellFlow) const 23 static const CollapsedBorderValue& collapsedRightBorder(const ComputedStyle& sty leForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
27 { 24 {
28 if (styleForCellFlow.isHorizontalWritingMode()) { 25 if (styleForCellFlow.isHorizontalWritingMode())
29 return styleForCellFlow.isLeftToRightDirection() ? m_layoutTableCell.se ction()->cachedCollapsedBorder(&m_layoutTableCell, CBSEnd) 26 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder : va lues.startBorder;
30 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSStart); 27 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBorder : values.afterBorder;
31 }
32 return styleForCellFlow.isFlippedBlocksWritingMode() ? m_layoutTableCell.se ction()->cachedCollapsedBorder(&m_layoutTableCell, CBSBefore)
33 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSAfter);
34 } 28 }
35 29
36 inline const CollapsedBorderValue& TableCellPainter::cachedCollapsedTopBorder(co nst ComputedStyle& styleForCellFlow) const 30 static const CollapsedBorderValue& collapsedTopBorder(const ComputedStyle& style ForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
37 { 31 {
38 if (styleForCellFlow.isHorizontalWritingMode()) 32 if (styleForCellFlow.isHorizontalWritingMode())
39 return styleForCellFlow.isFlippedBlocksWritingMode() ? m_layoutTableCel l.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSAfter) : m_layoutTable Cell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSBefore); 33 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.afterBorde r : values.beforeBorder;
40 return styleForCellFlow.isLeftToRightDirection() ? m_layoutTableCell.sectio n()->cachedCollapsedBorder(&m_layoutTableCell, CBSStart) : m_layoutTableCell.sec tion()->cachedCollapsedBorder(&m_layoutTableCell, CBSEnd); 34 return styleForCellFlow.isLeftToRightDirection() ? values.startBorder : valu es.endBorder;
41 } 35 }
42 36
43 inline const CollapsedBorderValue& TableCellPainter::cachedCollapsedBottomBorder (const ComputedStyle& styleForCellFlow) const 37 static const CollapsedBorderValue& collapsedBottomBorder(const ComputedStyle& st yleForCellFlow, const LayoutTableCell::CollapsedBorderValues& values)
44 { 38 {
45 if (styleForCellFlow.isHorizontalWritingMode()) { 39 if (styleForCellFlow.isHorizontalWritingMode())
46 return styleForCellFlow.isFlippedBlocksWritingMode() ? m_layoutTableCel l.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSBefore) 40 return styleForCellFlow.isFlippedBlocksWritingMode() ? values.beforeBord er : values.afterBorder;
47 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableC ell, CBSAfter); 41 return styleForCellFlow.isLeftToRightDirection() ? values.endBorder : values .startBorder;
48 }
49 return styleForCellFlow.isLeftToRightDirection() ? m_layoutTableCell.sectio n()->cachedCollapsedBorder(&m_layoutTableCell, CBSEnd)
50 : m_layoutTableCell.section()->cachedCollapsedBorder(&m_layoutTableCell, CBSStart);
51 } 42 }
52 43
53 void TableCellPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pain tOffset) 44 void TableCellPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pain tOffset)
54 { 45 {
55 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset); 46 BlockPainter(m_layoutTableCell).paint(paintInfo, paintOffset);
56 } 47 }
57 48
58 static EBorderStyle collapsedBorderStyle(EBorderStyle style) 49 static EBorderStyle collapsedBorderStyle(EBorderStyle style)
59 { 50 {
60 if (style == OUTSET) 51 if (style == OUTSET)
61 return GROOVE; 52 return GROOVE;
62 if (style == INSET) 53 if (style == INSET)
63 return RIDGE; 54 return RIDGE;
64 return style; 55 return style;
65 } 56 }
66 57
67 void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const L ayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue) 58 void TableCellPainter::paintCollapsedBorders(const PaintInfo& paintInfo, const L ayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue)
68 { 59 {
69 if (!paintInfo.shouldPaintWithinRoot(&m_layoutTableCell) || m_layoutTableCel l.style()->visibility() != VISIBLE) 60 if (!paintInfo.shouldPaintWithinRoot(&m_layoutTableCell) || m_layoutTableCel l.style()->visibility() != VISIBLE)
70 return; 61 return;
71 62
63 const LayoutTableCell::CollapsedBorderValues* values = m_layoutTableCell.col lapsedBorderValues();
64 if (!values)
65 return;
66
72 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow() ; 67 const ComputedStyle& styleForCellFlow = m_layoutTableCell.styleForCellFlow() ;
73 const CollapsedBorderValue& leftBorderValue = cachedCollapsedLeftBorder(styl eForCellFlow); 68 const CollapsedBorderValue& leftBorderValue = collapsedLeftBorder(styleForCe llFlow, *values);
74 const CollapsedBorderValue& rightBorderValue = cachedCollapsedRightBorder(st yleForCellFlow); 69 const CollapsedBorderValue& rightBorderValue = collapsedRightBorder(styleFor CellFlow, *values);
75 const CollapsedBorderValue& topBorderValue = cachedCollapsedTopBorder(styleF orCellFlow); 70 const CollapsedBorderValue& topBorderValue = collapsedTopBorder(styleForCell Flow, *values);
76 const CollapsedBorderValue& bottomBorderValue = cachedCollapsedBottomBorder( styleForCellFlow); 71 const CollapsedBorderValue& bottomBorderValue = collapsedBottomBorder(styleF orCellFlow, *values);
77 72
78 int displayItemType = DisplayItem::TableCollapsedBorderBase; 73 int displayItemType = DisplayItem::TableCollapsedBorderBase;
79 if (topBorderValue.shouldPaint(currentBorderValue)) 74 if (topBorderValue.shouldPaint(currentBorderValue))
80 displayItemType |= DisplayItem::TableCollapsedBorderTop; 75 displayItemType |= DisplayItem::TableCollapsedBorderTop;
81 if (bottomBorderValue.shouldPaint(currentBorderValue)) 76 if (bottomBorderValue.shouldPaint(currentBorderValue))
82 displayItemType |= DisplayItem::TableCollapsedBorderBottom; 77 displayItemType |= DisplayItem::TableCollapsedBorderBottom;
83 if (leftBorderValue.shouldPaint(currentBorderValue)) 78 if (leftBorderValue.shouldPaint(currentBorderValue))
84 displayItemType |= DisplayItem::TableCollapsedBorderLeft; 79 displayItemType |= DisplayItem::TableCollapsedBorderLeft;
85 if (rightBorderValue.shouldPaint(currentBorderValue)) 80 if (rightBorderValue.shouldPaint(currentBorderValue))
86 displayItemType |= DisplayItem::TableCollapsedBorderRight; 81 displayItemType |= DisplayItem::TableCollapsedBorderRight;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior) 226 LayoutRect TableCellPainter::paintBounds(const LayoutPoint& paintOffset, PaintBo undOffsetBehavior paintBoundOffsetBehavior)
232 { 227 {
233 LayoutPoint adjustedPaintOffset = paintOffset; 228 LayoutPoint adjustedPaintOffset = paintOffset;
234 if (paintBoundOffsetBehavior == AddOffsetFromParent) 229 if (paintBoundOffsetBehavior == AddOffsetFromParent)
235 adjustedPaintOffset.moveBy(m_layoutTableCell.location()); 230 adjustedPaintOffset.moveBy(m_layoutTableCell.location());
236 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize())); 231 return LayoutRect(adjustedPaintOffset, LayoutSize(m_layoutTableCell.pixelSna ppedSize()));
237 } 232 }
238 233
239 } // namespace blink 234 } // namespace blink
240 235
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698