TableFormattingContext.h 2.1 KB

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