TableFormattingContext.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <LibWeb/Layout/TableWrapper.h>
  10. namespace Web::Layout {
  11. class TableFormattingContext final : public FormattingContext {
  12. public:
  13. explicit TableFormattingContext(LayoutState&, TableBox const&, FormattingContext* parent);
  14. ~TableFormattingContext();
  15. virtual void run(Box const&, LayoutMode, AvailableSpace const&) override;
  16. virtual CSSPixels automatic_content_height() const override;
  17. TableBox const& table_box() const { return static_cast<TableBox const&>(context_box()); }
  18. TableWrapper const& table_wrapper() const
  19. {
  20. return verify_cast<TableWrapper>(*table_box().containing_block());
  21. }
  22. private:
  23. void calculate_row_column_grid(Box const&);
  24. void compute_table_measures();
  25. void compute_table_width();
  26. void distribute_width_to_columns();
  27. void determine_intrisic_size_of_table_container(AvailableSpace const& available_space);
  28. void calculate_row_heights(LayoutMode layout_mode);
  29. void position_row_boxes();
  30. void position_cell_boxes();
  31. CSSPixels m_automatic_content_height { 0 };
  32. Optional<AvailableSpace> m_available_space;
  33. enum class ColumnType {
  34. Percent,
  35. Pixel,
  36. Auto
  37. };
  38. struct Column {
  39. ColumnType type { ColumnType::Auto };
  40. CSSPixels left_offset { 0 };
  41. CSSPixels min_width { 0 };
  42. CSSPixels max_width { 0 };
  43. CSSPixels used_width { 0 };
  44. float percentage_width { 0 };
  45. };
  46. struct Row {
  47. Box& box;
  48. CSSPixels used_height { 0 };
  49. CSSPixels baseline { 0 };
  50. };
  51. struct Cell {
  52. Box& box;
  53. size_t column_index;
  54. size_t row_index;
  55. size_t column_span;
  56. size_t row_span;
  57. CSSPixels baseline { 0 };
  58. CSSPixels min_width { 0 };
  59. CSSPixels max_width { 0 };
  60. };
  61. Vector<Cell> m_cells;
  62. Vector<Column> m_columns;
  63. Vector<Row> m_rows;
  64. };
  65. }