TableFormattingContext.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. CSSPixels m_automatic_content_height { 0 };
  24. Optional<AvailableSpace> m_available_space;
  25. enum class ColumnType {
  26. Percent,
  27. Pixel,
  28. Auto
  29. };
  30. struct Column {
  31. ColumnType type { ColumnType::Auto };
  32. CSSPixels left_offset { 0 };
  33. CSSPixels min_width { 0 };
  34. CSSPixels max_width { 0 };
  35. CSSPixels used_width { 0 };
  36. float percentage_width { 0 };
  37. };
  38. struct Row {
  39. Box& box;
  40. CSSPixels used_width { 0 };
  41. CSSPixels baseline { 0 };
  42. };
  43. struct Cell {
  44. Box& box;
  45. size_t column_index;
  46. size_t row_index;
  47. size_t column_span;
  48. size_t row_span;
  49. CSSPixels baseline { 0 };
  50. CSSPixels min_width { 0 };
  51. CSSPixels max_width { 0 };
  52. };
  53. Vector<Cell> m_cells;
  54. Vector<Column> m_columns;
  55. Vector<Row> m_rows;
  56. };
  57. }