TableFormattingContext.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibWeb/Layout/FormattingContext.h>
  9. namespace Web::Layout {
  10. class TableFormattingContext final : public FormattingContext {
  11. public:
  12. explicit TableFormattingContext(LayoutState&, TableBox const&, FormattingContext* parent);
  13. ~TableFormattingContext();
  14. virtual void run(Box const&, LayoutMode, AvailableSpace const&) override;
  15. virtual CSSPixels automatic_content_height() const override;
  16. private:
  17. void calculate_row_column_grid(Box const&);
  18. void compute_table_measures();
  19. void compute_table_width();
  20. void distribute_width_to_columns();
  21. void determine_intrisic_size_of_table_container(AvailableSpace const& available_space);
  22. void calculate_row_heights();
  23. void position_row_boxes();
  24. void position_cell_boxes();
  25. CSSPixels m_automatic_content_height { 0 };
  26. Optional<AvailableSpace> m_available_space;
  27. enum class ColumnType {
  28. Percent,
  29. Pixel,
  30. Auto
  31. };
  32. struct Column {
  33. ColumnType type { ColumnType::Auto };
  34. CSSPixels left_offset { 0 };
  35. CSSPixels min_width { 0 };
  36. CSSPixels max_width { 0 };
  37. CSSPixels used_width { 0 };
  38. float percentage_width { 0 };
  39. };
  40. struct Row {
  41. Box& box;
  42. CSSPixels used_width { 0 };
  43. CSSPixels baseline { 0 };
  44. };
  45. struct Cell {
  46. Box& box;
  47. size_t column_index;
  48. size_t row_index;
  49. size_t column_span;
  50. size_t row_span;
  51. CSSPixels baseline { 0 };
  52. CSSPixels min_width { 0 };
  53. CSSPixels max_width { 0 };
  54. };
  55. Vector<Cell> m_cells;
  56. Vector<Column> m_columns;
  57. Vector<Row> m_rows;
  58. };
  59. }