mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:37:36 +00:00
LibWeb: Adjust border widths for tables using collapsing borders
When using the collapsing border model, cells on either side of the edge get half the specified width of the border for their box model.
This commit is contained in:
parent
8b6450842e
commit
4c81d39483
5 changed files with 67 additions and 53 deletions
|
@ -98,18 +98,18 @@ struct LayoutState {
|
|||
|
||||
Vector<LineBox> line_boxes;
|
||||
|
||||
CSSPixels margin_box_left() const { return margin_left + border_left + padding_left; }
|
||||
CSSPixels margin_box_right() const { return margin_right + border_right + padding_right; }
|
||||
CSSPixels margin_box_top() const { return margin_top + border_top + padding_top; }
|
||||
CSSPixels margin_box_bottom() const { return margin_bottom + border_bottom + padding_bottom; }
|
||||
CSSPixels margin_box_left() const { return margin_left + border_left_collapsed() + padding_left; }
|
||||
CSSPixels margin_box_right() const { return margin_right + border_right_collapsed() + padding_right; }
|
||||
CSSPixels margin_box_top() const { return margin_top + border_top_collapsed() + padding_top; }
|
||||
CSSPixels margin_box_bottom() const { return margin_bottom + border_bottom_collapsed() + padding_bottom; }
|
||||
|
||||
CSSPixels margin_box_width() const { return margin_box_left() + content_width() + margin_box_right(); }
|
||||
CSSPixels margin_box_height() const { return margin_box_top() + content_height() + margin_box_bottom(); }
|
||||
|
||||
CSSPixels border_box_left() const { return border_left + padding_left; }
|
||||
CSSPixels border_box_right() const { return border_right + padding_right; }
|
||||
CSSPixels border_box_top() const { return border_top + padding_top; }
|
||||
CSSPixels border_box_bottom() const { return border_bottom + padding_bottom; }
|
||||
CSSPixels border_box_left() const { return border_left_collapsed() + padding_left; }
|
||||
CSSPixels border_box_right() const { return border_right_collapsed() + padding_right; }
|
||||
CSSPixels border_box_top() const { return border_top_collapsed() + padding_top; }
|
||||
CSSPixels border_box_bottom() const { return border_bottom_collapsed() + padding_bottom; }
|
||||
|
||||
CSSPixels border_box_width() const { return border_box_left() + content_width() + border_box_right(); }
|
||||
CSSPixels border_box_height() const { return border_box_top() + content_height() + border_box_bottom(); }
|
||||
|
@ -129,6 +129,13 @@ struct LayoutState {
|
|||
AvailableSize available_width_inside() const;
|
||||
AvailableSize available_height_inside() const;
|
||||
|
||||
bool use_collapsing_borders_model() const { return m_override_borders_data.has_value(); }
|
||||
// Implement the collapsing border model https://www.w3.org/TR/CSS22/tables.html#collapsing-borders.
|
||||
CSSPixels border_left_collapsed() const { return use_collapsing_borders_model() ? round(border_left / 2) : border_left; }
|
||||
CSSPixels border_right_collapsed() const { return use_collapsing_borders_model() ? round(border_right / 2) : border_right; }
|
||||
CSSPixels border_top_collapsed() const { return use_collapsing_borders_model() ? round(border_top / 2) : border_top; }
|
||||
CSSPixels border_bottom_collapsed() const { return use_collapsing_borders_model() ? round(border_bottom / 2) : border_bottom; }
|
||||
|
||||
JS::GCPtr<Layout::NodeWithStyleAndBoxModelMetrics> m_node { nullptr };
|
||||
|
||||
CSSPixels m_content_width { 0 };
|
||||
|
|
|
@ -174,11 +174,12 @@ void TableFormattingContext::compute_cell_measures(AvailableSpace const& availab
|
|||
CSSPixels padding_right = computed_values.padding().right().to_px(cell.box, containing_block.content_width());
|
||||
|
||||
auto const& cell_state = m_state.get(cell.box);
|
||||
auto is_collapse = cell.box->computed_values().border_collapse() == CSS::BorderCollapse::Collapse;
|
||||
CSSPixels border_top = is_collapse ? cell_state.border_top : computed_values.border_top().width;
|
||||
CSSPixels border_bottom = is_collapse ? cell_state.border_bottom : computed_values.border_bottom().width;
|
||||
CSSPixels border_left = is_collapse ? cell_state.border_left : computed_values.border_left().width;
|
||||
CSSPixels border_right = is_collapse ? cell_state.border_right : computed_values.border_right().width;
|
||||
auto use_collapsing_borders_model = cell_state.override_borders_data().has_value();
|
||||
// Implement the collapsing border model https://www.w3.org/TR/CSS22/tables.html#collapsing-borders.
|
||||
CSSPixels border_top = use_collapsing_borders_model ? round(cell_state.border_top / 2) : computed_values.border_top().width;
|
||||
CSSPixels border_bottom = use_collapsing_borders_model ? round(cell_state.border_bottom / 2) : computed_values.border_bottom().width;
|
||||
CSSPixels border_left = use_collapsing_borders_model ? round(cell_state.border_left / 2) : computed_values.border_left().width;
|
||||
CSSPixels border_right = use_collapsing_borders_model ? round(cell_state.border_right / 2) : computed_values.border_right().width;
|
||||
|
||||
auto height = computed_values.height().to_px(cell.box, containing_block.content_height());
|
||||
auto width = (computed_values.width().is_length() || !table_width_is_auto) ? computed_values.width().to_px(cell.box, containing_block.content_width()) : 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue