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

Side by Side Diff: third_party/WebKit/Source/core/paint/TableCollapsedBorderPainter.h

Issue 1781463002: Fix table background painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sample code for improved collapsed border painting Created 3 years, 11 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
(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 #ifndef TableCollapsedBorderPainter_h
6 #define TableCollapsedBorderPainter_h
7
8 #include "core/layout/LayoutTableSection.h" // for LayoutTableSection::CellStruc t
9 #include "core/style/BorderValue.h"
10 #include "core/style/CollapsedBorderValue.h"
11 #include "platform/graphics/paint/DisplayItem.h"
12 #include "wtf/Allocator.h"
13
14 namespace blink {
15
16 struct PaintInfo;
17 class CellSpan;
18 class BorderValue;
19 class LayoutObject;
20 class LayoutPoint;
21 class LayoutTable;
22 class LayoutTableCell;
23 class LayoutTableCol;
24 class LayoutTableRow;
25 class LayoutTableSection;
26 enum TextDirection;
27
28 /*
29 * Paints all the borders inside a single section
30 */
31 class TableCollapsedBorderPainter {
32 STACK_ALLOCATED();
33 public:
34 TableCollapsedBorderPainter(const LayoutTableSection* layoutTableSection) : m_layoutTableSection(layoutTableSection)
35 {
36 m_hiddenBorder.setStyle(BorderStyleNone);
37 }
38
39 void paintBorders(const PaintInfo&, const LayoutPoint&, const CellSpan&, con st CellSpan&, const TableCollapsedBorderPainter& previousPainter);
40
41 struct EdgeRecord {
42 EdgeRecord() : m_precedence(BorderPrecedenceOff) {};
43 EdgeRecord(const BorderValue& border, EBorderPrecedence precedence, Colo r resolvedColor) :
44 m_precedence(precedence),
45 m_border(border),
46 m_resolvedColor(resolvedColor) {};
47
48 EBorderPrecedence m_precedence;
49 BorderValue m_border;
50 Color m_resolvedColor;
51 };
52
53 // Ordered by winning order, do not modify
54 enum EdgeDirection { North, West, East, South, None};
55
56 private:
57
58 // Represents a visible edge in a table
59 struct VisibleEdgeRecord {
60 VisibleEdgeRecord(unsigned row, unsigned column, EdgeDirection direction , const BorderValue& border, EBorderPrecedence precedence, Color resolvedColor, bool forceRemoval = false) :
61 m_row(row),
62 m_column(column),
63 m_direction(direction),
64 m_precedence(precedence),
65 m_border(border),
66 m_resolvedColor(resolvedColor),
67 m_forceRemoval(forceRemoval)
68 {};
69
70 unsigned m_row;
71 unsigned m_column;
72 EdgeDirection m_direction;
73 EBorderPrecedence m_precedence;
74 BorderValue m_border;
75 Color m_resolvedColor;
76 bool m_forceRemoval;
77 };
78
79 typedef Vector<VisibleEdgeRecord> VisibleEdgeContainer;
80
81 typedef Vector<EdgeRecord> EdgeRecordContainer;
82
83 // Represents edge intersection
84 struct Intersection {
85 Intersection() : m_width(0), m_height(0), m_direction(None) {};
86 Intersection(LayoutUnit width, LayoutUnit height, EdgeDirection directio n) :
87 m_width(width),
88 m_height(height),
89 m_direction(direction) {};
90 LayoutUnit m_width; // width of widest north-south edge
91 LayoutUnit m_height; // width of widest east-west edge
92 EdgeDirection m_direction; // direction of the winning edge
93 };
94
95 typedef Vector<Intersection> IntersectionContainer;
96
97 void initEdges(const CellSpan&, const CellSpan&, const TableCollapsedBorderP ainter& previousPainter);
98 void populateEdges(const CellSpan&, const CellSpan&, const TableCollapsedBor derPainter& previousPainter);
99
100 // Visible edges traversal
101 void getVisibleEdgesTable(VisibleEdgeContainer& edges, const LayoutTable *);
102 void getVisibleEdgesSection(VisibleEdgeContainer& edges);
103 void getVisibleEdgesColgroup(VisibleEdgeContainer& edges, const LayoutTableC ol *);
104 void getVisibleEdgesCol(VisibleEdgeContainer& edges, const LayoutTableCol *) ;
105 void getVisibleEdgesRow(VisibleEdgeContainer& edges, const LayoutTableRow *) ;
106 void getVisibleEdgesCell(VisibleEdgeContainer& edges, const LayoutTableCell *, TextDirection);
107 void getVisibleEdgesSiblingSection(VisibleEdgeContainer& edges, const TableC ollapsedBorderPainter& previousPainter);
108
109 // Visible edges utils
110 void rotateBorders(TextDirection, WritingMode,
111 const BorderValue** topBorder,
112 const BorderValue** rightBorder,
113 const BorderValue** bottomBorder,
114 const BorderValue** leftBorder) const;
115
116 void fillVisibleRect(VisibleEdgeContainer& edges,
117 unsigned startRow, unsigned startColumn, unsigned endRow, unsigned endCo lumn,
118 const ComputedStyle* borderStyle, TextDirection, WritingMode,
119 Color resolvedColor, EBorderPrecedence);
120 void fillHorizontalEdges(VisibleEdgeContainer& edges, unsigned row, unsigned startColumn, unsigned endColumn, const BorderValue &, EBorderPrecedence, Color resolvedColor);
121 void fillVerticalEdges(VisibleEdgeContainer& edges, unsigned column, unsigne d startRow, unsigned endRow, const BorderValue &, EBorderPrecedence, Color resol vedColor);
122 void mergeVisibleEdges(VisibleEdgeContainer& edges);
123
124 void initIntersections();
125 void initIntersection(unsigned row, unsigned col);
126
127 LayoutRect getCellPhysicalPosition(unsigned row, unsigned effectiveColumn)
128 {
129 ASSERT(row != npos && effectiveColumn != npos);
130 return m_layoutTableSection->getCellPhysicalPosition(row, effectiveColum n);
131 };
132
133 // Painting
134 LayoutRect cellRectAsBorder(const LayoutRect& cellRect, BoxSide, unsigned bo rderWidth, WritingMode, TextDirection);
135 LayoutRect edgePaintPosition(unsigned row, unsigned col, unsigned borderWidt h, EdgeDirection, WritingMode, TextDirection);
136 void paintEdges(const PaintInfo&, const LayoutPoint&, const CellSpan& rows, const CellSpan& cols);
137 void paintOneEdge(const PaintInfo&, const LayoutPoint&, unsigned row, unsign ed col, EdgeDirection, WritingMode, TextDirection);
138 void adjustForIntersections(LayoutRect& position, unsigned row, unsigned col , EdgeDirection, WritingMode, TextDirection);
139 void adjustForIntersectionsHorizontal(LayoutRect& position, EdgeDirection, b ool isLTR,
140 const Intersection* startIntersection, bool winnerStart,
141 const Intersection* endIntersection, bool winnerEnd);
142 void adjustForIntersectionsFlippedBlocks(LayoutRect& position, EdgeDirection , bool isLTR,
143 const Intersection* startIntersection, bool winnerStart,
144 const Intersection* endIntersection, bool winnerEnd);
145 void adjustForIntersectionsFlippedLines(LayoutRect& position, EdgeDirection, bool isLTR,
146 const Intersection* startIntersection, bool winnerStart,
147 const Intersection* endIntersection, bool winnerEnd);
148
149
150 #ifndef NDEBUG
151
152 void showEdge(unsigned row, unsigned col, EdgeDirection, EBorderPrecedence, const BorderValue&, Color) const;
153 void showEdges(bool showHidden = false) const;
154 void showVisibleEdges(const VisibleEdgeContainer& edges) const;
155 void showIntersections() const;
156 void showIntersection(unsigned row, unsigned col) const;
157
158 #endif
159
160 // Edges:
161 // Mental model for edges is that they originate at intersections (where cel ls meet)
162 // We store two edges for each intersection: East and South.
163 // We only store visible edges, not all edges in a section.
164 EdgeRecordContainer m_edges;
165
166 // Limits for rows/cols stored in m_edges. effective
167 unsigned m_startVisibleRow;
168 unsigned m_startVisibleColumn;
169 unsigned m_endVisibleRow; // inclusive, +1 is out of bounds
170 unsigned m_endVisibleColumn; // inclusive, +1 is out of bounds
171
172 // not-a-position edge index
173 static const unsigned npos = 0xFFFFFFFF;
174 // returns edge index for position, npos for none
175 unsigned edgeToIndex(unsigned row, unsigned column, EdgeDirection) const;
176
177 // Intersections:
178 // Each intersection has width, height, and winning border
179 IntersectionContainer m_intersections;
180 unsigned m_maxIntersectionWidth;
181 unsigned m_maxIntersectionHeight;
182
183 unsigned intersectionToIndex(unsigned row, unsigned column) const;
184
185 const LayoutTableSection* m_layoutTableSection;
186
187 // number of rows/cols in the section
188 unsigned m_numRows;
189 unsigned m_numEffectiveColumns;
190
191 BorderValue m_hiddenBorder;
192 };
193
194 } // namespace blink
195
196 #endif // TableCollapsedBorderPainter_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698