Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) | 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) |
| 3 * (C) 1997 Torben Weis (weis@kde.org) | 3 * (C) 1997 Torben Weis (weis@kde.org) |
| 4 * (C) 1998 Waldo Bastian (bastian@kde.org) | 4 * (C) 1998 Waldo Bastian (bastian@kde.org) |
| 5 * (C) 1999 Lars Knoll (knoll@kde.org) | 5 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 6 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 6 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 7 * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2013 Apple Inc. All rights | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2013 Apple Inc. All rights |
| 8 * reserved. | 8 * reserved. |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef LayoutTableSection_h | 26 #ifndef LayoutTableSection_h |
| 27 #define LayoutTableSection_h | 27 #define LayoutTableSection_h |
| 28 | 28 |
| 29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
| 30 #include "core/layout/LayoutTable.h" | 30 #include "core/layout/LayoutTable.h" |
| 31 #include "core/layout/LayoutTableBoxComponent.h" | 31 #include "core/layout/LayoutTableBoxComponent.h" |
| 32 #include "core/layout/TableGridCell.h" | |
| 32 #include "platform/wtf/Vector.h" | 33 #include "platform/wtf/Vector.h" |
| 33 | 34 |
| 34 namespace blink { | 35 namespace blink { |
| 35 | 36 |
| 36 // Helper class for paintObject. | 37 // Helper class for paintObject. |
| 37 class CellSpan { | 38 class CellSpan { |
| 38 STACK_ALLOCATED(); | 39 STACK_ALLOCATED(); |
| 39 | 40 |
| 40 public: | 41 public: |
| 41 CellSpan(unsigned start, unsigned end) : start_(start), end_(end) {} | 42 CellSpan(unsigned start, unsigned end) : start_(start), end_(end) {} |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 void LayoutRows(); | 120 void LayoutRows(); |
| 120 void ComputeOverflowFromDescendants(); | 121 void ComputeOverflowFromDescendants(); |
| 121 bool RecalcChildOverflowAfterStyleChange(); | 122 bool RecalcChildOverflowAfterStyleChange(); |
| 122 | 123 |
| 123 void MarkAllCellsWidthsDirtyAndOrNeedsLayout(LayoutTable::WhatToMarkAllCells); | 124 void MarkAllCellsWidthsDirtyAndOrNeedsLayout(LayoutTable::WhatToMarkAllCells); |
| 124 | 125 |
| 125 LayoutTable* Table() const { return ToLayoutTable(Parent()); } | 126 LayoutTable* Table() const { return ToLayoutTable(Parent()); } |
| 126 | 127 |
| 127 typedef Vector<LayoutTableCell*, 2> SpanningLayoutTableCells; | 128 typedef Vector<LayoutTableCell*, 2> SpanningLayoutTableCells; |
| 128 | 129 |
| 129 // CellStruct represents the cells that occupy an (N, M) position in the | |
| 130 // table grid. | |
| 131 struct CellStruct { | |
| 132 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
| 133 | |
| 134 public: | |
| 135 // All the cells that fills this grid "slot". | |
| 136 // Due to colspan / rowpsan, it is possible to have overlapping cells | |
| 137 // (see class comment about an example). | |
| 138 // This Vector is sorted in DOM order. | |
| 139 Vector<LayoutTableCell*, 1> cells; | |
| 140 bool in_col_span; // true for columns after the first in a colspan | |
| 141 | |
| 142 CellStruct(); | |
| 143 ~CellStruct(); | |
| 144 | |
| 145 // This is the cell in the grid "slot" that is on top of the others | |
| 146 // (aka the last cell in DOM order for this slot). | |
| 147 // | |
| 148 // Multiple grid slots can have the same primary cell if the cell spans | |
| 149 // into the grid slots. The slot having the smallest row index and | |
| 150 // smallest effective column index is the originating slot of the cell. | |
| 151 // | |
| 152 // The concept of a primary cell is dubious at most as it doesn't | |
| 153 // correspond to a DOM or rendering concept. Also callers should be | |
| 154 // careful about assumptions about it. For example, even though the | |
| 155 // primary cell is visibly the top most, it is not guaranteed to be | |
| 156 // the only one visible for this slot due to different visual | |
| 157 // overflow rectangles. | |
| 158 LayoutTableCell* PrimaryCell() { | |
| 159 return HasCells() ? cells[cells.size() - 1] : 0; | |
| 160 } | |
| 161 | |
| 162 const LayoutTableCell* PrimaryCell() const { | |
| 163 return HasCells() ? cells[cells.size() - 1] : 0; | |
| 164 } | |
| 165 | |
| 166 bool HasCells() const { return cells.size() > 0; } | |
| 167 }; | |
| 168 | |
| 169 // The index is effective column index. | |
| 170 typedef Vector<CellStruct> Row; | |
| 171 | |
| 172 struct RowStruct { | |
| 173 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
| 174 | |
| 175 public: | |
| 176 RowStruct() : row_layout_object(nullptr), baseline(-1) {} | |
| 177 | |
| 178 Row row; | |
| 179 LayoutTableRow* row_layout_object; | |
| 180 int baseline; | |
| 181 Length logical_height; | |
| 182 }; | |
| 183 | |
| 184 struct SpanningRowsHeight { | 130 struct SpanningRowsHeight { |
| 185 STACK_ALLOCATED(); | 131 STACK_ALLOCATED(); |
| 186 WTF_MAKE_NONCOPYABLE(SpanningRowsHeight); | 132 WTF_MAKE_NONCOPYABLE(SpanningRowsHeight); |
| 187 | 133 |
| 188 public: | 134 public: |
| 189 SpanningRowsHeight() | 135 SpanningRowsHeight() |
| 190 : total_rows_height(0), | 136 : total_rows_height(0), |
| 191 spanning_cell_height_ignoring_border_spacing(0), | 137 spanning_cell_height_ignoring_border_spacing(0), |
| 192 is_any_row_with_only_spanning_cells(false) {} | 138 is_any_row_with_only_spanning_cells(false) {} |
| 193 | 139 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 210 | 156 |
| 211 return Style()->BorderStart(); | 157 return Style()->BorderStart(); |
| 212 } | 158 } |
| 213 | 159 |
| 214 BorderValue BorderAdjoiningStartCell(const LayoutTableCell*) const; | 160 BorderValue BorderAdjoiningStartCell(const LayoutTableCell*) const; |
| 215 BorderValue BorderAdjoiningEndCell(const LayoutTableCell*) const; | 161 BorderValue BorderAdjoiningEndCell(const LayoutTableCell*) const; |
| 216 | 162 |
| 217 const LayoutTableCell* FirstRowCellAdjoiningTableStart() const; | 163 const LayoutTableCell* FirstRowCellAdjoiningTableStart() const; |
| 218 const LayoutTableCell* FirstRowCellAdjoiningTableEnd() const; | 164 const LayoutTableCell* FirstRowCellAdjoiningTableEnd() const; |
| 219 | 165 |
| 220 CellStruct& CellAt(unsigned row, unsigned effective_column) { | 166 TableGridCell& GridCellAt(unsigned row, unsigned effective_column) { |
| 221 return grid_[row].row[effective_column]; | 167 return grid_[row].grid_cells[effective_column]; |
| 222 } | 168 } |
| 223 const CellStruct& CellAt(unsigned row, unsigned effective_column) const { | 169 const TableGridCell& GridCellAt(unsigned row, |
| 224 return grid_[row].row[effective_column]; | 170 unsigned effective_column) const { |
| 171 return grid_[row].grid_cells[effective_column]; | |
| 225 } | 172 } |
| 226 LayoutTableCell* PrimaryCellAt(unsigned row, unsigned effective_column) { | 173 LayoutTableCell* PrimaryCellAt(unsigned row, unsigned effective_column) { |
| 227 Row& row_vector = grid_[row].row; | 174 auto& grid_cells = grid_[row].grid_cells; |
| 228 if (effective_column >= row_vector.size()) | 175 if (effective_column >= grid_cells.size()) |
| 229 return nullptr; | 176 return nullptr; |
| 230 return row_vector[effective_column].PrimaryCell(); | 177 return grid_cells[effective_column].PrimaryCell(); |
| 231 } | 178 } |
| 232 const LayoutTableCell* PrimaryCellAt(unsigned row, | 179 const LayoutTableCell* PrimaryCellAt(unsigned row, |
| 233 unsigned effective_column) const { | 180 unsigned effective_column) const { |
| 234 return const_cast<LayoutTableSection*>(this)->PrimaryCellAt( | 181 return const_cast<LayoutTableSection*>(this)->PrimaryCellAt( |
| 235 row, effective_column); | 182 row, effective_column); |
| 236 } | 183 } |
| 237 | 184 |
| 238 // Returns the primary cell at (row, effectiveColumn) if the cell exists and | 185 // Returns the primary cell at (row, effectiveColumn) if the cell exists and |
| 239 // originates from (instead of spanning into) the grid slot, or nullptr. | 186 // originates from (instead of spanning into) the grid slot, or nullptr. |
| 240 LayoutTableCell* OriginatingCellAt(unsigned row, unsigned effective_column); | 187 LayoutTableCell* OriginatingCellAt(unsigned row, unsigned effective_column); |
| 241 const LayoutTableCell* OriginatingCellAt(unsigned row, | 188 const LayoutTableCell* OriginatingCellAt(unsigned row, |
| 242 unsigned effective_column) const { | 189 unsigned effective_column) const { |
| 243 return const_cast<LayoutTableSection*>(this)->OriginatingCellAt( | 190 return const_cast<LayoutTableSection*>(this)->OriginatingCellAt( |
| 244 row, effective_column); | 191 row, effective_column); |
| 245 } | 192 } |
| 246 | 193 |
| 247 unsigned NumCols(unsigned row) const { return grid_[row].row.size(); } | 194 unsigned NumCols(unsigned row) const { return grid_[row].grid_cells.size(); } |
| 248 | 195 |
| 249 // Returns null for cells with a rowspan that exceed the last row. Possibly | 196 // Returns null for cells with a rowspan that exceed the last row. Possibly |
| 250 // others. | 197 // others. |
| 251 LayoutTableRow* RowLayoutObjectAt(unsigned row) { | 198 LayoutTableRow* RowLayoutObjectAt(unsigned row) { return grid_[row].row; } |
| 252 return grid_[row].row_layout_object; | |
| 253 } | |
| 254 const LayoutTableRow* RowLayoutObjectAt(unsigned row) const { | 199 const LayoutTableRow* RowLayoutObjectAt(unsigned row) const { |
| 255 return grid_[row].row_layout_object; | 200 return grid_[row].row; |
| 256 } | 201 } |
| 257 | 202 |
| 258 void AppendEffectiveColumn(unsigned pos); | 203 void AppendEffectiveColumn(unsigned pos); |
| 259 void SplitEffectiveColumn(unsigned pos, unsigned first); | 204 void SplitEffectiveColumn(unsigned pos, unsigned first); |
| 260 | 205 |
| 261 enum BlockBorderSide { kBorderBefore, kBorderAfter }; | 206 enum BlockBorderSide { kBorderBefore, kBorderAfter }; |
| 262 int CalcBlockDirectionOuterBorder(BlockBorderSide) const; | 207 int CalcBlockDirectionOuterBorder(BlockBorderSide) const; |
| 263 enum InlineBorderSide { kBorderStart, kBorderEnd }; | 208 enum InlineBorderSide { kBorderStart, kBorderEnd }; |
| 264 int CalcInlineDirectionOuterBorder(InlineBorderSide) const; | 209 int CalcInlineDirectionOuterBorder(InlineBorderSide) const; |
| 265 void RecalcOuterBorder(); | 210 void RecalcOuterBorder(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 HitTestAction) override; | 310 HitTestAction) override; |
| 366 | 311 |
| 367 private: | 312 private: |
| 368 bool IsOfType(LayoutObjectType type) const override { | 313 bool IsOfType(LayoutObjectType type) const override { |
| 369 return type == kLayoutObjectTableSection || LayoutBox::IsOfType(type); | 314 return type == kLayoutObjectTableSection || LayoutBox::IsOfType(type); |
| 370 } | 315 } |
| 371 | 316 |
| 372 void WillBeRemovedFromTree() override; | 317 void WillBeRemovedFromTree() override; |
| 373 | 318 |
| 374 int BorderSpacingForRow(unsigned row) const { | 319 int BorderSpacingForRow(unsigned row) const { |
| 375 return grid_[row].row_layout_object ? Table()->VBorderSpacing() : 0; | 320 return grid_[row].row ? Table()->VBorderSpacing() : 0; |
| 376 } | 321 } |
| 377 | 322 |
| 378 void EnsureRows(unsigned num_rows) { | 323 void EnsureRows(unsigned num_rows) { |
| 379 if (num_rows > grid_.size()) | 324 if (num_rows > grid_.size()) |
| 380 grid_.Grow(num_rows); | 325 grid_.Grow(num_rows); |
| 381 } | 326 } |
| 382 | 327 |
| 383 void EnsureCols(unsigned row_index, unsigned num_cols) { | 328 void EnsureCols(unsigned row_index, unsigned num_cols) { |
| 384 if (num_cols > this->NumCols(row_index)) | 329 if (num_cols > this->NumCols(row_index)) |
| 385 grid_[row_index].row.Grow(num_cols); | 330 grid_[row_index].grid_cells.Grow(num_cols); |
| 386 } | 331 } |
| 387 | 332 |
| 388 bool RowHasOnlySpanningCells(unsigned); | 333 bool RowHasOnlySpanningCells(unsigned); |
| 389 unsigned CalcRowHeightHavingOnlySpanningCells(unsigned, | 334 unsigned CalcRowHeightHavingOnlySpanningCells(unsigned, |
| 390 int&, | 335 int&, |
| 391 unsigned, | 336 unsigned, |
| 392 unsigned&, | 337 unsigned&, |
| 393 Vector<int>&); | 338 Vector<int>&); |
| 394 void UpdateRowsHeightHavingOnlySpanningCells(LayoutTableCell*, | 339 void UpdateRowsHeightHavingOnlySpanningCells(LayoutTableCell*, |
| 395 struct SpanningRowsHeight&, | 340 struct SpanningRowsHeight&, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 void RelayoutCellIfFlexed(LayoutTableCell&, int row_index, int row_height); | 384 void RelayoutCellIfFlexed(LayoutTableCell&, int row_index, int row_height); |
| 440 | 385 |
| 441 int LogicalHeightForRow(const LayoutTableRow&) const; | 386 int LogicalHeightForRow(const LayoutTableRow&) const; |
| 442 | 387 |
| 443 // Honor breaking restrictions inside the table row, and adjust position and | 388 // Honor breaking restrictions inside the table row, and adjust position and |
| 444 // size accordingly. | 389 // size accordingly. |
| 445 void AdjustRowForPagination(LayoutTableRow&, SubtreeLayoutScope&); | 390 void AdjustRowForPagination(LayoutTableRow&, SubtreeLayoutScope&); |
| 446 | 391 |
| 447 bool PaintedOutputOfObjectHasNoEffectRegardlessOfSize() const override; | 392 bool PaintedOutputOfObjectHasNoEffectRegardlessOfSize() const override; |
| 448 | 393 |
| 449 // The representation of the rows and their cells (CellStruct). | 394 struct GridRow { |
|
dgrogan
2017/05/15 19:53:38
TableGridRow for consistency with the new class?
Xianzhu
2017/05/15 20:28:38
Done.
| |
| 450 Vector<RowStruct> grid_; | 395 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 396 | |
| 397 public: | |
| 398 inline void SetRowLogicalHeightToRowStyleLogicalHeight(); | |
| 399 inline void UpdateLogicalHeightForCell(const LayoutTableCell*); | |
| 400 | |
| 401 // The index is effective column index. | |
| 402 Vector<TableGridCell> grid_cells; | |
|
dgrogan
2017/05/15 19:53:38
This is so much clearer than the old "typedef Vect
| |
| 403 LayoutTableRow* row = nullptr; | |
|
dgrogan
2017/05/15 19:53:38
I know it's longer, but wdyt about s/row/layout_ta
Xianzhu
2017/05/15 20:28:38
I prefer the shorter name :)
| |
| 404 int baseline = -1; | |
| 405 Length logical_height; | |
| 406 }; | |
| 407 | |
| 408 // The representation of the rows and their grid cells. | |
| 409 Vector<GridRow> grid_; | |
| 451 | 410 |
| 452 // The logical offset of each row from the top of the section. | 411 // The logical offset of each row from the top of the section. |
| 453 // | 412 // |
| 454 // Note that this Vector has one more entry than the number of rows so that | 413 // Note that this Vector has one more entry than the number of rows so that |
| 455 // we can keep track of the final size of the section. That is, | 414 // we can keep track of the final size of the section. That is, |
| 456 // m_rowPos[m_grid.size()] is a valid entry. | 415 // m_rowPos[m_grid.size()] is a valid entry. |
| 457 // | 416 // |
| 458 // To know a row's height at |rowIndex|, use the formula: | 417 // To know a row's height at |rowIndex|, use the formula: |
| 459 // m_rowPos[rowIndex + 1] - m_rowPos[rowIndex] | 418 // m_rowPos[rowIndex + 1] - m_rowPos[rowIndex] |
| 460 Vector<int> row_pos_; | 419 Vector<int> row_pos_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 | 453 |
| 495 // Whether any cell spans multiple rows or cols. | 454 // Whether any cell spans multiple rows or cols. |
| 496 bool has_spanning_cells_; | 455 bool has_spanning_cells_; |
| 497 }; | 456 }; |
| 498 | 457 |
| 499 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutTableSection, IsTableSection()); | 458 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutTableSection, IsTableSection()); |
| 500 | 459 |
| 501 } // namespace blink | 460 } // namespace blink |
| 502 | 461 |
| 503 #endif // LayoutTableSection_h | 462 #endif // LayoutTableSection_h |
| OLD | NEW |