2020-11-22 13:38:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-22 13:38:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
2022-12-04 21:57:21 +03:00
|
|
|
#include <LibWeb/Layout/FormattingContext.h>
|
2023-01-14 15:05:08 +01:00
|
|
|
#include <LibWeb/Layout/TableWrapper.h>
|
2020-11-22 13:38:18 +01:00
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
2022-12-04 21:57:21 +03:00
|
|
|
class TableFormattingContext final : public FormattingContext {
|
2020-11-22 13:38:18 +01:00
|
|
|
public:
|
2023-05-29 14:11:19 +03:00
|
|
|
explicit TableFormattingContext(LayoutState&, Box const&, FormattingContext* parent);
|
2020-11-22 13:38:18 +01:00
|
|
|
~TableFormattingContext();
|
|
|
|
|
2022-09-27 15:29:17 +02:00
|
|
|
virtual void run(Box const&, LayoutMode, AvailableSpace const&) override;
|
2023-03-19 09:57:31 +01:00
|
|
|
virtual CSSPixels automatic_content_width() const override;
|
2022-11-23 17:46:10 +00:00
|
|
|
virtual CSSPixels automatic_content_height() const override;
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2023-05-29 14:11:19 +03:00
|
|
|
Box const& table_box() const { return context_box(); }
|
2023-01-14 15:05:08 +01:00
|
|
|
TableWrapper const& table_wrapper() const
|
|
|
|
{
|
|
|
|
return verify_cast<TableWrapper>(*table_box().containing_block());
|
|
|
|
}
|
2023-01-08 01:54:25 +03:00
|
|
|
|
2020-11-22 13:38:18 +01:00
|
|
|
private:
|
2022-12-04 22:39:38 +03:00
|
|
|
void calculate_row_column_grid(Box const&);
|
|
|
|
void compute_table_measures();
|
2023-01-05 18:56:34 +03:00
|
|
|
void compute_table_width();
|
|
|
|
void distribute_width_to_columns();
|
2022-12-04 22:39:38 +03:00
|
|
|
void determine_intrisic_size_of_table_container(AvailableSpace const& available_space);
|
2023-04-29 00:43:05 +03:00
|
|
|
void compute_table_height(LayoutMode layout_mode);
|
|
|
|
void distribute_height_to_rows();
|
2023-01-20 00:59:43 +01:00
|
|
|
void position_row_boxes(CSSPixels&);
|
2023-01-08 00:57:57 +03:00
|
|
|
void position_cell_boxes();
|
2022-09-24 13:39:43 +02:00
|
|
|
|
2023-04-29 00:43:05 +03:00
|
|
|
CSSPixels m_table_height { 0 };
|
2022-12-15 12:57:36 +00:00
|
|
|
CSSPixels m_automatic_content_height { 0 };
|
2022-12-04 22:39:38 +03:00
|
|
|
|
2023-01-05 18:44:04 +03:00
|
|
|
Optional<AvailableSpace> m_available_space;
|
|
|
|
|
2023-01-05 18:56:34 +03:00
|
|
|
enum class ColumnType {
|
|
|
|
Percent,
|
|
|
|
Pixel,
|
|
|
|
Auto
|
|
|
|
};
|
|
|
|
|
2022-12-04 22:39:38 +03:00
|
|
|
struct Column {
|
2023-01-05 18:56:34 +03:00
|
|
|
ColumnType type { ColumnType::Auto };
|
2022-12-15 12:57:36 +00:00
|
|
|
CSSPixels left_offset { 0 };
|
|
|
|
CSSPixels min_width { 0 };
|
|
|
|
CSSPixels max_width { 0 };
|
|
|
|
CSSPixels used_width { 0 };
|
2023-05-24 10:50:57 +02:00
|
|
|
double percentage_width { 0 };
|
2022-12-04 22:39:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Row {
|
2023-02-26 16:09:02 -07:00
|
|
|
JS::NonnullGCPtr<Box> box;
|
2023-04-29 00:43:05 +03:00
|
|
|
CSSPixels base_height { 0 };
|
|
|
|
CSSPixels reference_height { 0 };
|
|
|
|
CSSPixels final_height { 0 };
|
2022-12-15 12:57:36 +00:00
|
|
|
CSSPixels baseline { 0 };
|
2022-12-04 22:39:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Cell {
|
2023-02-26 16:09:02 -07:00
|
|
|
JS::NonnullGCPtr<Box> box;
|
2022-12-04 22:39:38 +03:00
|
|
|
size_t column_index;
|
|
|
|
size_t row_index;
|
|
|
|
size_t column_span;
|
2022-12-09 13:36:56 +03:00
|
|
|
size_t row_span;
|
2022-12-15 12:57:36 +00:00
|
|
|
CSSPixels baseline { 0 };
|
2023-01-07 01:19:52 +03:00
|
|
|
CSSPixels min_width { 0 };
|
|
|
|
CSSPixels max_width { 0 };
|
2022-12-04 22:39:38 +03:00
|
|
|
};
|
|
|
|
|
2023-05-18 03:55:39 +00:00
|
|
|
CSSPixels compute_row_content_height(Cell const& cell) const;
|
|
|
|
|
2022-12-04 22:39:38 +03:00
|
|
|
Vector<Cell> m_cells;
|
|
|
|
Vector<Column> m_columns;
|
|
|
|
Vector<Row> m_rows;
|
2020-11-22 13:38:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|