Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
Loirooriol committed Jan 17, 2025
1 parent 46e1e52 commit 21ffb37
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 51 deletions.
69 changes: 40 additions & 29 deletions components/layout_2020/display_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ use crate::fragment_tree::{
BackgroundMode, BoxFragment, Fragment, FragmentFlags, FragmentTree, SpecificLayoutInfo, Tag,
TextFragment,
};
use crate::geom::{LengthPercentageOrAuto, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize};
use crate::geom::{
LengthPercentageOrAuto, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize,
};
use crate::replaced::NaturalSizes;
use crate::style_ext::{BorderStyleColor, ComputedValuesExt};
use crate::table::SpecificTableGridInfo;

mod background;
mod clip_path;
Expand Down Expand Up @@ -651,9 +652,16 @@ impl<'a> BuilderForBoxFragment<'a> {
return;
}

if section == StackingContextSection::Outline {
self.build_outline(builder);
return;
match section {
StackingContextSection::CollapsedTableBorders => {
self.build_collapsed_table_borders(builder);
return;
},
StackingContextSection::Outline => {
self.build_outline(builder);
return;
},
_ => {},
}

self.build_hit_test(builder, self.border_rect);
Expand Down Expand Up @@ -894,15 +902,23 @@ impl<'a> BuilderForBoxFragment<'a> {
}
}

fn build_table_collapsed_borders(&mut self, builder: &mut DisplayListBuilder, table_info: &SpecificTableGridInfo) {
fn build_collapsed_table_borders(&mut self, builder: &mut DisplayListBuilder) {
let table_info = match &self.fragment.detailed_layout_info {
Some(SpecificLayoutInfo::TableGrid(table_info)) => table_info,
_ => return,
};
let none = wr::BorderSide {
color: wr::ColorF::TRANSPARENT,
style: wr::BorderStyle::None,
};
let mut common = builder.common_properties(units::LayoutRect::default(), &self.fragment.style);
let mut common =
builder.common_properties(units::LayoutRect::default(), &self.fragment.style);
let mut column_sum = Au::zero();
println!("# table_info.track_sizes {:?}", table_info.track_sizes);
println!("# table_info.collapsed_borders {:?}", table_info.collapsed_borders);
println!(
"# table_info.collapsed_borders {:?}",
table_info.collapsed_borders
);
for (x, column_size) in table_info.track_sizes.x.iter().enumerate() {
let mut row_sum = Au::zero();
for (y, row_size) in table_info.track_sizes.y.iter().enumerate() {
Expand All @@ -912,11 +928,7 @@ impl<'a> BuilderForBoxFragment<'a> {
let top_border = &table_info.collapsed_borders.y[y].list[x];
let bottom_border = &table_info.collapsed_borders.y[y + 1].list[x];
let border_widths = PhysicalSides::new(
if y == 0 {
top_border.width
} else {
Au::zero()
},
if y == 0 { top_border.width } else { Au::zero() },
right_border.width,
bottom_border.width,
if x == 0 {
Expand Down Expand Up @@ -959,23 +971,26 @@ impl<'a> BuilderForBoxFragment<'a> {
if y + 1 < table_info.track_sizes.y.len() {
size.height += border_widths.bottom / 2;
}
let border_rect = PhysicalRect::new(
origin,
size,
);
let border_rect = PhysicalRect::new(origin, size);
println!(" border_rect {:?}", border_rect);
println!(" self.fragment.content_rect {:?}", self.fragment.content_rect);
println!(
" self.fragment.content_rect {:?}",
self.fragment.content_rect
);
println!(" self.containing_block {:?}", self.containing_block);
let border_rect = border_rect
.translate(self.fragment.content_rect.origin.to_vector())
.translate(self.containing_block.origin.to_vector());
println!(" final border_rect {:?}", border_rect);
println!("");
println!();
let border_rect = border_rect.to_webrender();
common.clip_rect = border_rect;
builder
.wr()
.push_border(&common, border_rect, border_widths.to_webrender(), details);
builder.wr().push_border(
&common,
border_rect,
border_widths.to_webrender(),
details,
);
row_sum += *row_size;
}
column_sum += *column_size;
Expand All @@ -984,20 +999,16 @@ impl<'a> BuilderForBoxFragment<'a> {

fn build_border(&mut self, builder: &mut DisplayListBuilder) {
match &self.fragment.detailed_layout_info {
Some(SpecificLayoutInfo::TableGrid(table_info)) => {
self.build_table_collapsed_borders(builder, table_info);
return;
},
Some(SpecificLayoutInfo::TableCell) => {
// Avoid painting borders for table cells in collapsed-borders mode,
Some(SpecificLayoutInfo::TableGrid(_) | SpecificLayoutInfo::TableCell) => {
// Avoid painting borders for table cells and table grid in collapsed-borders mode,
// since they are painted with the table grid.
return;
},
_ => {},
}

use style::values::specified::box_::DisplayInside;
use style::computed_values::border_collapse::T as BorderCollapse;
use style::values::specified::box_::DisplayInside;
if self.fragment.style.get_box().display.inside() == DisplayInside::Table &&
self.fragment.style.get_inherited_table().border_collapse == BorderCollapse::Collapse
{
Expand Down
44 changes: 29 additions & 15 deletions components/layout_2020/display_list/stacking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use super::DisplayList;
use crate::display_list::conversions::{FilterToWebRender, ToWebRender};
use crate::display_list::{BuilderForBoxFragment, DisplayListBuilder};
use crate::fragment_tree::{
BoxFragment, ContainingBlockManager, Fragment, FragmentFlags, FragmentTree, PositioningFragment,
BoxFragment, ContainingBlockManager, Fragment, FragmentFlags, FragmentTree,
PositioningFragment, SpecificLayoutInfo,
};
use crate::geom::{AuOrAuto, PhysicalRect, PhysicalSides};
use crate::style_ext::ComputedValuesExt;
Expand Down Expand Up @@ -87,6 +88,7 @@ pub(crate) type ContainingBlockInfo<'a> = ContainingBlockManager<'a, ContainingB
pub(crate) enum StackingContextSection {
OwnBackgroundsAndBorders,
DescendantBackgroundsAndBorders,
CollapsedTableBorders,
Foreground,
Outline,
}
Expand Down Expand Up @@ -726,6 +728,15 @@ impl StackingContext {
child.build_display_list(builder, &self.atomic_inline_stacking_containers);
}

// Collapsed table borders
while contents.peek().is_some_and(|(_, child)| {
child.section() == StackingContextSection::CollapsedTableBorders
}) {
let (i, child) = contents.next().unwrap();
self.debug_push_print_item(DebugPrintField::Contents, i);
child.build_display_list(builder, &self.atomic_inline_stacking_containers);
}

// Step 5: Float stacking containers
for (i, child) in self.float_stacking_containers.iter().enumerate() {
self.debug_push_print_item(DebugPrintField::FloatStackingContainers, i);
Expand Down Expand Up @@ -1181,30 +1192,34 @@ impl BoxFragment {
.for_absolute_and_fixed_descendants
.scroll_node_id
};
stacking_context
.contents
.push(StackingContextContent::Fragment {
scroll_node_id: new_scroll_node_id,
reference_frame_scroll_node_id: reference_frame_scroll_node_id_for_fragments,
clip_chain_id: new_clip_chain_id,
section: self.get_stacking_context_section(),
containing_block: containing_block.rect,
fragment: fragment.clone(),
is_hit_test_for_scrollable_overflow: false,
});

if !self.style.get_outline().outline_width.is_zero() {
let mut add_fragment = |section| {
stacking_context
.contents
.push(StackingContextContent::Fragment {
scroll_node_id: new_scroll_node_id,
reference_frame_scroll_node_id: reference_frame_scroll_node_id_for_fragments,
clip_chain_id: new_clip_chain_id,
section: StackingContextSection::Outline,
section,
containing_block: containing_block.rect,
fragment: fragment.clone(),
is_hit_test_for_scrollable_overflow: false,
});
};

add_fragment(self.get_stacking_context_section());

if let Fragment::Box(box_fragment) = &fragment {
if matches!(
box_fragment.borrow().detailed_layout_info,
Some(SpecificLayoutInfo::TableGrid(_))
) {
add_fragment(StackingContextSection::CollapsedTableBorders);
}
}

if !self.style.get_outline().outline_width.is_zero() {
add_fragment(StackingContextSection::Outline);
}

// We want to build the scroll frame after the background and border, because
Expand All @@ -1218,7 +1233,6 @@ impl BoxFragment {
new_scroll_node_id = scroll_frame_data.scroll_tree_node_id;
new_clip_chain_id = scroll_frame_data.clip_chain_id;
new_scroll_frame_size = Some(scroll_frame_data.scroll_frame_rect.size());

stacking_context
.contents
.push(StackingContextContent::Fragment {
Expand Down
11 changes: 6 additions & 5 deletions components/layout_2020/table/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ use style::values::generics::box_::{GenericVerticalAlign as VerticalAlign, Verti
use style::Zero;

use super::{
ArcRefCell, CollapsedBorder, CollapsedBorderLine, SpecificTableGridInfo,
Table, TableCaption, TableSlot, TableSlotCell, TableSlotCoordinates, TableTrack,
TableTrackGroup,
ArcRefCell, CollapsedBorder, CollapsedBorderLine, SpecificTableGridInfo, Table, TableCaption,
TableSlot, TableSlotCell, TableSlotCoordinates, TableTrack, TableTrackGroup,
};
use crate::context::LayoutContext;
use crate::formatting_contexts::{Baselines, IndependentLayout};
Expand All @@ -37,7 +36,7 @@ use crate::fragment_tree::{
};
use crate::geom::{
AuOrAuto, LogicalRect, LogicalSides, LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides,
Size, SizeConstraint, ToLogical, ToLogicalWithContainingBlock, PhysicalVec,
PhysicalVec, Size, SizeConstraint, ToLogical, ToLogicalWithContainingBlock,
};
use crate::positioned::{relative_adjustement, PositioningContext, PositioningContextLength};
use crate::sizing::{ComputeInlineContentSizes, ContentSizes, InlineContentSizesResult};
Expand Down Expand Up @@ -2889,7 +2888,9 @@ impl TableSlotCell {
);
positioning_context.append(layout.positioning_context);

let detailed_layout_info = (table_style.get_inherited_table().border_collapse == BorderCollapse::Collapse).then_some(SpecificLayoutInfo::TableCell);
let detailed_layout_info = (table_style.get_inherited_table().border_collapse ==
BorderCollapse::Collapse)
.then_some(SpecificLayoutInfo::TableCell);

BoxFragment::new(
base_fragment_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@

td#tested-cell
{
background: blue;
background-color: blue;
border-left: orange solid 60px;
border-right: orange solid 60px;
border-color: rgba(255, 255, 0, 0.5);
color: blue;
width: 80px;
}
Expand Down

0 comments on commit 21ffb37

Please sign in to comment.