OLD | NEW |
(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 #ifndef TableCollapsedBorderPainter_h |
| 5 #define TableCollapsedBorderPainter_h |
| 6 #include "core/layout/LayoutTableSection.h" // for LayoutTableSection::CellStru
ct |
| 7 #include "core/style/BorderValue.h" |
| 8 #include "core/style/CollapsedBorderValue.h" |
| 9 #include "platform/graphics/paint/DisplayItem.h" |
| 10 #include "platform/wtf/Allocator.h" |
| 11 namespace blink { |
| 12 struct PaintInfo; |
| 13 class CellSpan; |
| 14 class BorderValue; |
| 15 class LayoutPoint; |
| 16 class LayoutTable; |
| 17 class LayoutTableCell; |
| 18 class LayoutTableCol; |
| 19 class LayoutTableRow; |
| 20 class LayoutTableSection; |
| 21 /* |
| 22 * * Paints all the borders inside a single section |
| 23 * */ |
| 24 class TableCollapsedBorderPainter { |
| 25 STACK_ALLOCATED(); |
| 26 |
| 27 public: |
| 28 TableCollapsedBorderPainter(const LayoutTableSection* layoutTableSection) |
| 29 : layout_table_section_(layoutTableSection) { |
| 30 hidden_border_.SetStyle(kBorderStyleNone); |
| 31 } |
| 32 TableCollapsedBorderPainter() : layout_table_section_(nullptr) { |
| 33 hidden_border_.SetStyle(kBorderStyleNone); |
| 34 } |
| 35 void PaintBorders(const PaintInfo&, |
| 36 const LayoutPoint&, |
| 37 const CellSpan&, |
| 38 const CellSpan&, |
| 39 const TableCollapsedBorderPainter& previous_painter); |
| 40 struct EdgeRecord { |
| 41 EdgeRecord() : precedence_(kBorderPrecedenceOff){}; |
| 42 EdgeRecord(const BorderValue& border, |
| 43 EBorderPrecedence precedence, |
| 44 Color resolved_color) |
| 45 : precedence_(precedence), |
| 46 border_(border), |
| 47 resolved_color_(resolved_color){}; |
| 48 EBorderPrecedence precedence_; |
| 49 BorderValue border_; |
| 50 Color resolved_color_; |
| 51 }; |
| 52 // Ordered by winning order, do not modify |
| 53 enum EdgeDirection { North, West, East, South, None }; |
| 54 |
| 55 private: |
| 56 // Represents a visible edge in a table |
| 57 struct VisibleEdgeRecord { |
| 58 VisibleEdgeRecord(unsigned row, |
| 59 unsigned column, |
| 60 EdgeDirection direction, |
| 61 const BorderValue& border, |
| 62 EBorderPrecedence precedence, |
| 63 Color resolved_color, |
| 64 bool force_removal = false) |
| 65 : m_row(row), |
| 66 m_column(column), |
| 67 direction_(direction), |
| 68 precedence_(precedence), |
| 69 border_(border), |
| 70 resolved_color_(resolved_color), |
| 71 force_removal_(force_removal){}; |
| 72 unsigned m_row; |
| 73 unsigned m_column; |
| 74 EdgeDirection direction_; |
| 75 EBorderPrecedence precedence_; |
| 76 BorderValue border_; |
| 77 Color resolved_color_; |
| 78 bool force_removal_; |
| 79 }; |
| 80 typedef Vector<VisibleEdgeRecord> VisibleEdgeContainer; |
| 81 typedef Vector<EdgeRecord> EdgeRecordContainer; |
| 82 // Represents edge intersection |
| 83 struct Intersection { |
| 84 Intersection() : width_(0), height_(0), direction_(None){}; |
| 85 Intersection(LayoutUnit width, LayoutUnit height, EdgeDirection direction) |
| 86 : width_(width), height_(height), direction_(direction){}; |
| 87 LayoutUnit width_; // width of widest north-south edge |
| 88 LayoutUnit height_; // width of widest east-west edge |
| 89 EdgeDirection direction_; // direction of the winning edge |
| 90 }; |
| 91 typedef Vector<Intersection> IntersectionContainer; |
| 92 void InitEdges(const CellSpan&, |
| 93 const CellSpan&, |
| 94 const TableCollapsedBorderPainter& previous_painter); |
| 95 void PopulateEdges(const CellSpan&, |
| 96 const CellSpan&, |
| 97 const TableCollapsedBorderPainter& previous_painter); |
| 98 // Visible edges traversal |
| 99 void GetVisibleEdgesTable(VisibleEdgeContainer& edges, const LayoutTable*); |
| 100 void GetVisibleEdgesSection(VisibleEdgeContainer& edges); |
| 101 void GetVisibleEdgesColgroup(VisibleEdgeContainer& edges, |
| 102 const LayoutTableCol*); |
| 103 void GetVisibleEdgesCol(VisibleEdgeContainer& edges, const LayoutTableCol*); |
| 104 void GetVisibleEdgesRow(VisibleEdgeContainer& edges, const LayoutTableRow*); |
| 105 void GetVisibleEdgesCell(VisibleEdgeContainer& edges, |
| 106 const LayoutTableCell*, |
| 107 TextDirection); |
| 108 void GetVisibleEdgesSiblingSection( |
| 109 VisibleEdgeContainer& edges, |
| 110 const TableCollapsedBorderPainter& previous_painter); |
| 111 // Visible edges utils |
| 112 void RotateBorders(TextDirection, |
| 113 WritingMode, |
| 114 const BorderValue** top_border, |
| 115 const BorderValue** right_border, |
| 116 const BorderValue** bottom_border, |
| 117 const BorderValue** left_border) const; |
| 118 void FillVisibleRect(VisibleEdgeContainer& edges, |
| 119 unsigned startRow, |
| 120 unsigned start_column, |
| 121 unsigned end_row, |
| 122 unsigned end_column, |
| 123 const ComputedStyle* border_style, |
| 124 TextDirection, |
| 125 WritingMode, |
| 126 Color resolved_color, |
| 127 EBorderPrecedence); |
| 128 void FillHorizontalEdges(VisibleEdgeContainer& edges, |
| 129 unsigned row, |
| 130 unsigned start_column, |
| 131 unsigned end_column, |
| 132 const BorderValue&, |
| 133 EBorderPrecedence, |
| 134 Color resolved_color); |
| 135 void FillVerticalEdges(VisibleEdgeContainer& edges, |
| 136 unsigned column, |
| 137 unsigned startRow, |
| 138 unsigned end_row, |
| 139 const BorderValue&, |
| 140 EBorderPrecedence, |
| 141 Color resolved_color); |
| 142 void MergeVisibleEdges(VisibleEdgeContainer& edges); |
| 143 void InitIntersections(); |
| 144 void InitIntersection(unsigned row, unsigned col); |
| 145 LayoutRect GetCellPhysicalPosition(unsigned row, unsigned effective_column) { |
| 146 DCHECK(row != npos && effective_column != npos); |
| 147 return layout_table_section_->GetCellPhysicalPosition(row, |
| 148 effective_column); |
| 149 }; |
| 150 // Painting |
| 151 LayoutRect CellRectAsBorder(const LayoutRect& cell_rect, |
| 152 BoxSide, |
| 153 unsigned border_width, |
| 154 WritingMode, |
| 155 TextDirection); |
| 156 LayoutRect EdgePaintPosition(unsigned row, |
| 157 unsigned col, |
| 158 unsigned border_width, |
| 159 EdgeDirection, |
| 160 WritingMode, |
| 161 TextDirection); |
| 162 void PaintEdges(const PaintInfo&, |
| 163 const LayoutPoint&, |
| 164 const CellSpan& rows, |
| 165 const CellSpan& cols); |
| 166 void PaintOneEdge(const PaintInfo&, |
| 167 const LayoutPoint&, |
| 168 unsigned row, |
| 169 unsigned col, |
| 170 EdgeDirection, |
| 171 WritingMode, |
| 172 TextDirection); |
| 173 void AdjustForIntersections(LayoutRect& position, |
| 174 unsigned row, |
| 175 unsigned col, |
| 176 EdgeDirection, |
| 177 WritingMode, |
| 178 TextDirection); |
| 179 void AdjustForIntersectionsHorizontal(LayoutRect& position, |
| 180 EdgeDirection, |
| 181 bool isLTR, |
| 182 const Intersection* start_intersection, |
| 183 bool winner_start, |
| 184 const Intersection* end_intersection, |
| 185 bool winner_end); |
| 186 void AdjustForIntersectionsFlippedBlocks( |
| 187 LayoutRect& position, |
| 188 EdgeDirection, |
| 189 bool isLTR, |
| 190 const Intersection* start_intersection, |
| 191 bool winner_start, |
| 192 const Intersection* end_intersection, |
| 193 bool winner_end); |
| 194 void AdjustForIntersectionsFlippedLines( |
| 195 LayoutRect& position, |
| 196 EdgeDirection, |
| 197 bool isLTR, |
| 198 const Intersection* start_intersection, |
| 199 bool winner_start, |
| 200 const Intersection* end_intersection, |
| 201 bool winner_end); |
| 202 void ShowEdge(unsigned row, |
| 203 unsigned col, |
| 204 EdgeDirection, |
| 205 EBorderPrecedence, |
| 206 const BorderValue&, |
| 207 Color) const; |
| 208 void ShowEdges(bool showHidden = false) const; |
| 209 void ShowVisibleEdges(const VisibleEdgeContainer& edges) const; |
| 210 void ShowIntersections() const; |
| 211 void ShowIntersection(unsigned row, unsigned col) const; |
| 212 |
| 213 // Edges: |
| 214 // Mental model for edges is that they originate at intersections (where cells |
| 215 // meet) We store two edges for each intersection: East and South. We only |
| 216 // store visible edges, not all edges in a section. |
| 217 EdgeRecordContainer edges_; |
| 218 // Limits for rows/cols stored in edges_. effective |
| 219 unsigned start_visible_row_; |
| 220 unsigned start_visible_column_; |
| 221 unsigned end_visible_row_; // inclusive, +1 is out of bounds |
| 222 unsigned end_visible_column_; // inclusive, +1 is out of bounds |
| 223 // not-a-position edge index |
| 224 static const unsigned npos = 0xFFFFFFFF; |
| 225 // returns edge index for position, npos for none |
| 226 unsigned EdgeToIndex(unsigned row, unsigned column, EdgeDirection) const; |
| 227 // Intersections: |
| 228 // Each intersection has width, height, and winning border |
| 229 IntersectionContainer intersections_; |
| 230 unsigned max_intersection_width_; |
| 231 unsigned max_intersection_height_; |
| 232 unsigned IntersectionToIndex(unsigned row, unsigned column) const; |
| 233 const LayoutTableSection* layout_table_section_; |
| 234 // number of rows/cols in the section |
| 235 unsigned num_rows_; |
| 236 unsigned num_effective_columns_; |
| 237 BorderValue hidden_border_; |
| 238 }; |
| 239 } // namespace blink |
| 240 #endif // TableCollapsedBorderPainter_h |
OLD | NEW |