TableFormattingContext.h 2.2 KB

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