TableFormattingContext.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 compute_table_height(LayoutMode layout_mode);
  31. void distribute_height_to_rows();
  32. void position_row_boxes(CSSPixels&);
  33. void position_cell_boxes();
  34. CSSPixels m_table_height { 0 };
  35. CSSPixels m_automatic_content_height { 0 };
  36. Optional<AvailableSpace> m_available_space;
  37. enum class ColumnType {
  38. Percent,
  39. Pixel,
  40. Auto
  41. };
  42. struct Column {
  43. ColumnType type { ColumnType::Auto };
  44. CSSPixels left_offset { 0 };
  45. CSSPixels min_width { 0 };
  46. CSSPixels max_width { 0 };
  47. CSSPixels used_width { 0 };
  48. float percentage_width { 0 };
  49. };
  50. struct Row {
  51. JS::NonnullGCPtr<Box> box;
  52. CSSPixels base_height { 0 };
  53. CSSPixels reference_height { 0 };
  54. CSSPixels final_height { 0 };
  55. CSSPixels baseline { 0 };
  56. };
  57. struct Cell {
  58. JS::NonnullGCPtr<Box> box;
  59. size_t column_index;
  60. size_t row_index;
  61. size_t column_span;
  62. size_t row_span;
  63. CSSPixels baseline { 0 };
  64. CSSPixels min_width { 0 };
  65. CSSPixels max_width { 0 };
  66. };
  67. Vector<Cell> m_cells;
  68. Vector<Column> m_columns;
  69. Vector<Row> m_rows;
  70. };
  71. }