1 /*
2  * Copyright (C) 2002 Lars Knoll (knoll@kde.org)
3  *           (C) 2002 Dirk Mueller (mueller@kde.org)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_TABLE_LAYOUT_ALGORITHM_AUTO_H_
22 #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_TABLE_LAYOUT_ALGORITHM_AUTO_H_
23 
24 #include "third_party/blink/renderer/core/layout/table_layout_algorithm.h"
25 #include "third_party/blink/renderer/platform/geometry/layout_unit.h"
26 #include "third_party/blink/renderer/platform/geometry/length.h"
27 #include "third_party/blink/renderer/platform/wtf/vector.h"
28 
29 namespace blink {
30 
31 class LayoutTable;
32 class LayoutTableCell;
33 
34 enum CellsToProcess { kAllCells, kNonEmptyCells, kEmptyCells };
35 
36 enum DistributionMode { kExtraWidth, kInitialWidth, kLeftoverWidth };
37 
38 enum DistributionDirection { kStartToEnd, kEndToStart };
39 
40 class TableLayoutAlgorithmAuto final : public TableLayoutAlgorithm {
41  public:
42   TableLayoutAlgorithmAuto(LayoutTable*);
43   ~TableLayoutAlgorithmAuto() override;
44 
45   void ComputeIntrinsicLogicalWidths(LayoutUnit& min_width,
46                                      LayoutUnit& max_width) override;
ScaledWidthFromPercentColumns()47   LayoutUnit ScaledWidthFromPercentColumns() override {
48     return scaled_width_from_percent_columns_;
49   }
50   void ApplyPreferredLogicalWidthQuirks(LayoutUnit& min_width,
51                                         LayoutUnit& max_width) const override;
52   void UpdateLayout() override;
WillChangeTableLayout()53   void WillChangeTableLayout() override {}
54 
55  private:
56   void FullRecalc();
57   void RecalcColumn(unsigned eff_col);
58 
59   int CalcEffectiveLogicalWidth();
60   void ShrinkColumnWidth(const Length::Type&, int& available);
61   template <typename Total,
62             Length::Type,
63             CellsToProcess,
64             DistributionMode,
65             DistributionDirection>
66   void DistributeWidthToColumns(int& available, Total);
67 
68   void InsertSpanCell(LayoutTableCell*);
69 
70   struct Layout {
LayoutLayout71     Layout()
72         : min_logical_width(0),
73           max_logical_width(0),
74           effective_min_logical_width(0),
75           effective_max_logical_width(0),
76           computed_logical_width(0),
77           empty_cells_only(true),
78           column_has_no_cells(true) {}
79 
80     Length logical_width;
81     Length effective_logical_width;
82     int min_logical_width;
83     int max_logical_width;
84     int effective_min_logical_width;
85     int effective_max_logical_width;
86     int computed_logical_width;
87     bool empty_cells_only;
88     bool column_has_no_cells;
ClampedEffectiveMaxLogicalWidthLayout89     int ClampedEffectiveMaxLogicalWidth() {
90       return std::max<int>(1, effective_max_logical_width);
91     }
92   };
93 
94   Vector<Layout, 4> layout_struct_;
95   Vector<LayoutTableCell*, 4> span_cells_;
96   bool has_percent_ : 1;
97   mutable bool effective_logical_width_dirty_ : 1;
98   LayoutUnit scaled_width_from_percent_columns_;
99 };
100 
101 }  // namespace blink
102 
103 #endif  // TableLayoutAlgorithmAuto
104