summaryrefslogtreecommitdiffstats
path: root/layout/tables/nsTableFrame.cpp
diff options
context:
space:
mode:
authorwin7-7 <win7-7@users.noreply.github.com>2020-05-08 01:21:41 +0300
committerMoonchild <moonchild@palemoon.org>2020-05-20 13:49:25 +0000
commitd3d3aad6e52397334844ed80f8db650174937854 (patch)
treeda624662628e938611db00fc64037fd27fb05a37 /layout/tables/nsTableFrame.cpp
parentd8d0538162defbb3e44be475c4781bb71f55c2ba (diff)
downloadUXP-d3d3aad6e52397334844ed80f8db650174937854.tar
UXP-d3d3aad6e52397334844ed80f8db650174937854.tar.gz
UXP-d3d3aad6e52397334844ed80f8db650174937854.tar.lz
UXP-d3d3aad6e52397334844ed80f8db650174937854.tar.xz
UXP-d3d3aad6e52397334844ed80f8db650174937854.zip
Issue #1355 - Better way to create display items for column backgrounds
Part 1: Remove current table item, as it's never set. Part 2: Get rid of generic table painting code, and handle each class separately. Part 4: Hoist outline skipping into col(group) frame code. Part 5: Skip box-shadow for table column and column groups. Part 6: Store column and column group backgrounds separately, and then append them before the rest of the table contents. Part 7: Pass rects in display list coordinates to AppendBackgroundItemsToTop. Part 8: Create column and column group background display items as part of the cell's BuildDisplayList. Part 9: Used cached values instead of calling nsDisplayListBuilder::ToReferenceFrame when possible, since it can be expensive when the requested frame isn't the builder's current frame. Part 10: Make sure we build display items for table parts where only the normal position is visible, since we may need to create background items for ancestors at that position. Part 11: Create an AutoBuildingDisplayList when we create background items for table columns and column groups, so that we initialize the invalidation state correctly.
Diffstat (limited to 'layout/tables/nsTableFrame.cpp')
-rw-r--r--layout/tables/nsTableFrame.cpp286
1 files changed, 51 insertions, 235 deletions
diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp
index 57b249fb3..59a6d0f1a 100644
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -1166,113 +1166,7 @@ nsDisplayTableBorderCollapse::Paint(nsDisplayListBuilder* aBuilder,
static_cast<nsTableFrame*>(mFrame)->PaintBCBorders(*drawTarget, mVisibleRect - pt);
}
-/* static */ void
-nsTableFrame::GenericTraversal(nsDisplayListBuilder* aBuilder, nsFrame* aFrame,
- const nsDisplayListSet& aLists)
-{
- // This is similar to what nsContainerFrame::BuildDisplayListForNonBlockChildren
- // does, except that we allow the children's background and borders to go
- // in our BorderBackground list. This doesn't really affect background
- // painting --- the children won't actually draw their own backgrounds
- // because the nsTableFrame already drew them, unless a child has its own
- // stacking context, in which case the child won't use its passed-in
- // BorderBackground list anyway. It does affect cell borders though; this
- // lets us get cell borders into the nsTableFrame's BorderBackground list.
- for (nsIFrame* kid : aFrame->GetChildList(kColGroupList)) {
- aFrame->BuildDisplayListForChild(aBuilder, kid, aLists);
- }
-
- for (nsIFrame* kid : aFrame->PrincipalChildList()) {
- aFrame->BuildDisplayListForChild(aBuilder, kid, aLists);
- }
-}
-
-static void
-PaintRowBackground(nsTableRowFrame* aRow,
- nsIFrame* aFrame,
- nsDisplayListBuilder* aBuilder,
- const nsDisplayListSet& aLists,
- const nsPoint& aOffset = nsPoint())
-{
- // Compute background rect by iterating over all cell frames.
- for (nsTableCellFrame* cell = aRow->GetFirstCell(); cell; cell = cell->GetNextCell()) {
- if (!cell->ShouldPaintBackground(aBuilder)) {
- continue;
- }
-
- auto cellRect = cell->GetRectRelativeToSelf() + cell->GetNormalPosition() + aOffset;
- if (!aBuilder->GetDirtyRect().Intersects(cellRect)) {
- continue;
- }
- nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, cellRect,
- aLists.BorderBackground(),
- true, nullptr,
- aFrame->GetRectRelativeToSelf(),
- cell);
- }
-}
-
-static void
-PaintRowGroupBackground(nsTableRowGroupFrame* aRowGroup,
- nsIFrame* aFrame,
- nsDisplayListBuilder* aBuilder,
- const nsDisplayListSet& aLists)
-{
- for (nsTableRowFrame* row = aRowGroup->GetFirstRow(); row; row = row->GetNextRow()) {
- if (!aBuilder->GetDirtyRect().Intersects(nsRect(row->GetNormalPosition(),
- row->GetSize()))) {
- continue;
- }
- PaintRowBackground(row, aFrame, aBuilder, aLists, row->GetNormalPosition());
- }
-}
-
-static void
-PaintRowGroupBackgroundByColIdx(nsTableRowGroupFrame* aRowGroup,
- nsIFrame* aFrame,
- nsDisplayListBuilder* aBuilder,
- const nsDisplayListSet& aLists,
- const nsTArray<uint32_t>& aColIdx,
- const nsPoint& aOffset)
-{
- MOZ_DIAGNOSTIC_ASSERT(!aColIdx.IsEmpty(),
- "Must be painting backgrounds for something");
- for (nsTableRowFrame* row = aRowGroup->GetFirstRow(); row; row = row->GetNextRow()) {
- auto rowPos = row->GetNormalPosition() + aOffset;
- if (!aBuilder->GetDirtyRect().Intersects(nsRect(rowPos, row->GetSize()))) {
- continue;
- }
- for (nsTableCellFrame* cell = row->GetFirstCell(); cell; cell = cell->GetNextCell()) {
-
- uint32_t curColIdx = cell->ColIndex();
- if (!aColIdx.Contains(curColIdx)) {
- if (curColIdx > aColIdx.LastElement()) {
- // We can just stop looking at this row.
- break;
- }
- continue;
- }
-
- if (!cell->ShouldPaintBackground(aBuilder)) {
- continue;
- }
-
- auto cellPos = cell->GetNormalPosition() + rowPos;
- auto cellRect = nsRect(cellPos, cell->GetSize());
- if (!aBuilder->GetDirtyRect().Intersects(cellRect)) {
- continue;
- }
- nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, cellRect,
- aLists.BorderBackground(),
- true, nullptr,
- aFrame->GetRectRelativeToSelf(),
- cell);
- }
- }
-}
-
-static inline bool FrameHasBorder(nsIFrame* f)
-{
+static inline bool FrameHasBorder(nsIFrame* f) {
if (!f->StyleVisibility()->IsVisible()) {
return false;
}
@@ -1284,8 +1178,7 @@ static inline bool FrameHasBorder(nsIFrame* f)
return false;
}
-void nsTableFrame::CalcHasBCBorders()
-{
+void nsTableFrame::CalcHasBCBorders() {
if (!IsBorderCollapse()) {
SetHasBCBorders(false);
return;
@@ -1303,8 +1196,9 @@ void nsTableFrame::CalcHasBCBorders()
return;
}
- nsTableColGroupFrame *colGroup = static_cast<nsTableColGroupFrame*>(f);
- for (nsTableColFrame* col = colGroup->GetFirstColumn(); col; col = col->GetNextCol()) {
+ nsTableColGroupFrame* colGroup = static_cast<nsTableColGroupFrame*>(f);
+ for (nsTableColFrame* col = colGroup->GetFirstColumn(); col;
+ col = col->GetNextCol()) {
if (FrameHasBorder(col)) {
SetHasBCBorders(true);
return;
@@ -1321,13 +1215,15 @@ void nsTableFrame::CalcHasBCBorders()
return;
}
- for (nsTableRowFrame* row = rowGroup->GetFirstRow(); row; row = row->GetNextRow()) {
+ for (nsTableRowFrame* row = rowGroup->GetFirstRow(); row;
+ row = row->GetNextRow()) {
if (FrameHasBorder(row)) {
SetHasBCBorders(true);
return;
}
- for (nsTableCellFrame* cell = row->GetFirstCell(); cell; cell = cell->GetNextCell()) {
+ for (nsTableCellFrame* cell = row->GetFirstCell(); cell;
+ cell = cell->GetNextCell()) {
if (FrameHasBorder(cell)) {
SetHasBCBorders(true);
return;
@@ -1339,138 +1235,58 @@ void nsTableFrame::CalcHasBCBorders()
SetHasBCBorders(false);
}
-/* static */ void
-nsTableFrame::DisplayGenericTablePart(nsDisplayListBuilder* aBuilder,
- nsFrame* aFrame,
- const nsDisplayListSet& aLists,
- DisplayGenericTablePartTraversal aTraversal)
-{
- bool isVisible = aFrame->IsVisibleForPainting(aBuilder);
- bool isTable = (aFrame->GetType() == nsGkAtoms::tableFrame);
-
- if (isVisible || !isTable) {
- nsDisplayTableItem* currentItem = aBuilder->GetCurrentTableItem();
- // currentItem may be null, when none of the table parts have a
- // background or border
- if (currentItem) {
- currentItem->UpdateForFrameBackground(aFrame);
- }
- }
-
- if (isVisible) {
- // XXX: should box-shadow for rows/rowgroups/columns/colgroups get painted
- // just because we're visible? Or should it depend on the cell visibility
- // when we're not the whole table?
-
- // Paint the outset box-shadows for the table frames
- if (aFrame->StyleEffects()->mBoxShadow) {
- aLists.BorderBackground()->AppendNewToTop(
- new (aBuilder) nsDisplayBoxShadowOuter(aBuilder, aFrame));
- }
- }
-
- // Background visibility for rows, rowgroups, columns, colgroups depends on
- // the visibility of the _cell_, not of the row/col(group).
- // See spec at https://drafts.csswg.org/css-tables-3/#drawing-cell-backgrounds
- if (aFrame->GetType() == nsGkAtoms::tableRowGroupFrame) {
- nsTableRowGroupFrame* rowGroup = static_cast<nsTableRowGroupFrame*>(aFrame);
- PaintRowGroupBackground(rowGroup, aFrame, aBuilder, aLists);
- } else if (aFrame->GetType() == nsGkAtoms::tableRowFrame) {
- nsTableRowFrame* row = static_cast<nsTableRowFrame*>(aFrame);
- PaintRowBackground(row, aFrame, aBuilder, aLists);
- } else if (aFrame->GetType() == nsGkAtoms::tableColGroupFrame) {
- // Compute background rect by iterating all cell frame.
- nsTableColGroupFrame* colGroup = static_cast<nsTableColGroupFrame*>(aFrame);
- // Collecting column index.
- AutoTArray<uint32_t, 1> colIdx;
- for (nsTableColFrame* col = colGroup->GetFirstColumn(); col; col = col->GetNextCol()) {
- MOZ_ASSERT(colIdx.IsEmpty() ||
- static_cast<uint32_t>(col->GetColIndex()) > colIdx.LastElement());
- colIdx.AppendElement(col->GetColIndex());
- }
-
- if (!colIdx.IsEmpty()) {
- // We have some actual cells that live inside this rowgroup.
- nsTableFrame* table = colGroup->GetTableFrame();
- RowGroupArray rowGroups;
- table->OrderRowGroups(rowGroups);
- for (nsTableRowGroupFrame* rowGroup : rowGroups) {
- auto offset = rowGroup->GetNormalPosition() - colGroup->GetNormalPosition();
- if (!aBuilder->GetDirtyRect().Intersects(nsRect(offset, rowGroup->GetSize()))) {
- continue;
- }
- PaintRowGroupBackgroundByColIdx(rowGroup, aFrame, aBuilder, aLists, colIdx, offset);
- }
- }
- } else if (aFrame->GetType() == nsGkAtoms::tableColFrame) {
- // Compute background rect by iterating all cell frame.
- nsTableColFrame* col = static_cast<nsTableColFrame*>(aFrame);
- AutoTArray<uint32_t, 1> colIdx;
- colIdx.AppendElement(col->GetColIndex());
+// table paint code is concerned primarily with borders and bg color
+// SEC: TODO: adjust the rect for captions
+void
+nsTableFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
+ const nsDisplayListSet& aLists)
+{
+ DO_GLOBAL_REFLOW_COUNT_DSP_COLOR("nsTableFrame", NS_RGB(255,128,255));
- nsTableFrame* table = col->GetTableFrame();
- RowGroupArray rowGroups;
- table->OrderRowGroups(rowGroups);
- for (nsTableRowGroupFrame* rowGroup : rowGroups) {
- auto offset = rowGroup->GetNormalPosition() -
- col->GetNormalPosition() -
- col->GetTableColGroupFrame()->GetNormalPosition();
- if (!aBuilder->GetDirtyRect().Intersects(nsRect(offset, rowGroup->GetSize()))) {
- continue;
- }
- PaintRowGroupBackgroundByColIdx(rowGroup, aFrame, aBuilder, aLists, colIdx, offset);
- }
- } else if (isVisible) {
- nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame,
- aFrame->GetRectRelativeToSelf(),
- aLists.BorderBackground());
- }
+ DisplayBorderBackgroundOutline(aBuilder, aLists);
- if (isVisible) {
- // XXX: should box-shadow for rows/rowgroups/columns/colgroups get painted
- // just because we're visible? Or should it depend on the cell visibility
- // when we're not the whole table?
+ nsDisplayTableBackgroundSet tableBGs(aBuilder, this);
+ nsDisplayListCollection lists(aBuilder);
- // Paint the inset box-shadows for the table frames
- if (aFrame->StyleEffects()->mBoxShadow) {
- aLists.BorderBackground()->AppendNewToTop(
- new (aBuilder) nsDisplayBoxShadowInner(aBuilder, aFrame));
+// This is similar to what
+ // nsContainerFrame::BuildDisplayListForNonBlockChildren does, except that we
+ // allow the children's background and borders to go in our BorderBackground
+ // list. This doesn't really affect background painting --- the children won't
+ // actually draw their own backgrounds because the nsTableFrame already drew
+ // them, unless a child has its own stacking context, in which case the child
+ // won't use its passed-in BorderBackground list anyway. It does affect cell
+ // borders though; this lets us get cell borders into the nsTableFrame's
+ // BorderBackground list.
+ for (nsIFrame* colGroup : FirstContinuation()->GetChildList(kColGroupList)) {
+ for (nsIFrame* col : colGroup->PrincipalChildList()) {
+ tableBGs.AddColumn((nsTableColFrame*)col);
}
}
- aTraversal(aBuilder, aFrame, aLists);
+ for (nsIFrame* kid : PrincipalChildList()) {
+ BuildDisplayListForChild(aBuilder, kid, lists);
+ }
- if (isVisible) {
- if (isTable) {
- nsTableFrame* table = static_cast<nsTableFrame*>(aFrame);
- // In the collapsed border model, overlay all collapsed borders.
- if (table->IsBorderCollapse()) {
- if (table->HasBCBorders()) {
- aLists.BorderBackground()->AppendNewToTop(
- new (aBuilder) nsDisplayTableBorderCollapse(aBuilder, table));
- }
- } else {
- const nsStyleBorder* borderStyle = aFrame->StyleBorder();
- if (borderStyle->HasBorder()) {
- aLists.BorderBackground()->AppendNewToTop(
- new (aBuilder) nsDisplayBorder(aBuilder, table));
- }
+ tableBGs.MoveTo(aLists);
+ lists.MoveTo(aLists);
+
+ if (IsVisibleForPainting(aBuilder)) {
+ // In the collapsed border model, overlay all collapsed borders.
+ if (IsBorderCollapse()) {
+ if (HasBCBorders()) {
+ aLists.BorderBackground()->AppendNewToTop(
+ new (aBuilder) nsDisplayTableBorderCollapse
+ (aBuilder, this));
+ }
+ } else {
+ const nsStyleBorder* borderStyle = StyleBorder();
+ if (borderStyle->HasBorder()) {
+ aLists.BorderBackground()->AppendNewToTop(
+ new (aBuilder) nsDisplayBorder
+ (aBuilder, this));
}
}
}
-
- aFrame->DisplayOutline(aBuilder, aLists);
-}
-
-// table paint code is concerned primarily with borders and bg color
-// SEC: TODO: adjust the rect for captions
-void
-nsTableFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
- const nsDisplayListSet& aLists)
-{
- DO_GLOBAL_REFLOW_COUNT_DSP_COLOR("nsTableFrame", NS_RGB(255,128,255));
-
- DisplayGenericTablePart(aBuilder, this, aLists);
}
nsMargin