From 8bd3a1f1d99e5baada68ef62986344497cbdd84a Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 2 Nov 2019 22:39:03 +0100 Subject: [PATCH 01/10] Issue #146 - Part 1: Draw each table's background on their own display list items. This patch does the following things: 1. Creates nsDisplayTableBorderCollapse that draws all collapse border of tables. 2. Stops the use of nsDisplayTableBorderBackground. 3. Lets column and column group frames generate display items. 4. When traversing the table, also traverses the column and column group frames. 5. For each type of table frame (col group, col, row group, row and cell), draws their own background. --- layout/base/nsDisplayItemTypesList.h | 1 + layout/base/nsDisplayList.cpp | 9 +- layout/base/nsDisplayList.h | 3 +- layout/tables/nsTableCellFrame.cpp | 103 ++++------ layout/tables/nsTableColFrame.cpp | 8 + layout/tables/nsTableColFrame.h | 5 +- layout/tables/nsTableColGroupFrame.cpp | 8 + layout/tables/nsTableColGroupFrame.h | 5 +- layout/tables/nsTableFrame.cpp | 268 ++++++++++++++----------- layout/tables/nsTableFrame.h | 1 - layout/tables/nsTableRowFrame.cpp | 16 +- layout/tables/nsTableRowGroupFrame.cpp | 13 +- layout/tables/nsTableWrapperFrame.cpp | 6 +- 13 files changed, 223 insertions(+), 223 deletions(-) diff --git a/layout/base/nsDisplayItemTypesList.h b/layout/base/nsDisplayItemTypesList.h index 9865395a79..d24f6f38fb 100644 --- a/layout/base/nsDisplayItemTypesList.h +++ b/layout/base/nsDisplayItemTypesList.h @@ -59,6 +59,7 @@ DECLARE_DISPLAY_ITEM_TYPE(TABLE_CELL_SELECTION) DECLARE_DISPLAY_ITEM_TYPE(TABLE_ROW_BACKGROUND) DECLARE_DISPLAY_ITEM_TYPE(TABLE_ROW_GROUP_BACKGROUND) DECLARE_DISPLAY_ITEM_TYPE(TABLE_BORDER_BACKGROUND) +DECLARE_DISPLAY_ITEM_TYPE(TABLE_BORDER_COLLAPSE) DECLARE_DISPLAY_ITEM_TYPE(TEXT) DECLARE_DISPLAY_ITEM_TYPE(TEXT_OVERFLOW) DECLARE_DISPLAY_ITEM_TYPE_FLAGS(TRANSFORM,TYPE_RENDERS_NO_IMAGES) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index e22230b410..744153831d 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -2631,11 +2631,16 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil const nsRect& aBackgroundRect, nsDisplayList* aList, bool aAllowWillPaintBorderOptimization, - nsStyleContext* aStyleContext) + nsStyleContext* aStyleContext, + const nsRect& aBackgroundOriginRect) { nsStyleContext* bgSC = aStyleContext; const nsStyleBackground* bg = nullptr; nsRect bgRect = aBackgroundRect + aBuilder->ToReferenceFrame(aFrame); + nsRect bgOriginRect = bgRect; + if (!aBackgroundOriginRect.IsEmpty()) { + bgOriginRect = aBackgroundOriginRect + aBuilder->ToReferenceFrame(aFrame); + } nsPresContext* presContext = aFrame->PresContext(); bool isThemed = aFrame->IsThemed(); if (!isThemed) { @@ -2744,7 +2749,7 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil nsDisplayList thisItemList; nsDisplayBackgroundImage* bgItem = - new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bgRect, bg); + new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bgOriginRect, bg); if (bgItem->ShouldFixToViewport(aBuilder)) { thisItemList.AppendNewToTop( diff --git a/layout/base/nsDisplayList.h b/layout/base/nsDisplayList.h index c81d34fac2..9431e2cc06 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -2737,7 +2737,8 @@ public: const nsRect& aBackgroundRect, nsDisplayList* aList, bool aAllowWillPaintBorderOptimization = true, - nsStyleContext* aStyleContext = nullptr); + nsStyleContext* aStyleContext = nullptr, + const nsRect& aBackgroundOriginRect = nsRect()); virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, LayerManager* aManager, diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp index dea82ea591..bac8d387ff 100644 --- a/layout/tables/nsTableCellFrame.cpp +++ b/layout/tables/nsTableCellFrame.cpp @@ -484,70 +484,51 @@ nsTableCellFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) { DO_GLOBAL_REFLOW_COUNT_DSP("nsTableCellFrame"); - if (IsVisibleInSelection(aBuilder)) { - nsTableFrame* tableFrame = GetTableFrame(); - int32_t emptyCellStyle = GetContentEmpty() && !tableFrame->IsBorderCollapse() ? - StyleTableBorder()->mEmptyCells - : NS_STYLE_TABLE_EMPTY_CELLS_SHOW; - // take account of 'empty-cells' - if (StyleVisibility()->IsVisible() && - (NS_STYLE_TABLE_EMPTY_CELLS_HIDE != emptyCellStyle)) { - // display outset box-shadows if we need to. - bool hasBoxShadow = !!StyleEffects()->mBoxShadow; - if (hasBoxShadow) { - aLists.BorderBackground()->AppendNewToTop( - new (aBuilder) nsDisplayBoxShadowOuter(aBuilder, this)); - } - - // display background if we need to. - if (aBuilder->IsForEventDelivery() || - !StyleBackground()->IsTransparent() || StyleDisplay()->mAppearance) { - if (!tableFrame->IsBorderCollapse()) { - nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, - this, - GetRectRelativeToSelf(), - aLists.BorderBackground()); - } else if (aBuilder->IsAtRootOfPseudoStackingContext() || - aBuilder->IsForEventDelivery()) { - // The cell background was not painted by the nsTablePainter, - // so we need to do it. We have special background processing here - // so we need to duplicate some code from nsFrame::DisplayBorderBackgroundOutline - nsDisplayTableItem* item = - new (aBuilder) nsDisplayTableCellBackground(aBuilder, this); - aLists.BorderBackground()->AppendNewToTop(item); - item->UpdateForFrameBackground(this); - } else { - // The nsTablePainter will paint our background. Make sure it - // knows if we're background-attachment:fixed. - nsDisplayTableItem* currentItem = aBuilder->GetCurrentTableItem(); - if (currentItem) { - currentItem->UpdateForFrameBackground(this); - } - } - } - - // display inset box-shadows if we need to. - if (hasBoxShadow) { - aLists.BorderBackground()->AppendNewToTop( - new (aBuilder) nsDisplayBoxShadowInner(aBuilder, this)); - } - - // display borders if we need to - ProcessBorders(tableFrame, aBuilder, aLists); - - // and display the selection border if we need to - if (IsSelected()) { - aLists.BorderBackground()->AppendNewToTop(new (aBuilder) - nsDisplayGeneric(aBuilder, this, ::PaintTableCellSelection, - "TableCellSelection", - nsDisplayItem::TYPE_TABLE_CELL_SELECTION)); - } + nsTableFrame* tableFrame = GetTableFrame(); + int32_t emptyCellStyle = GetContentEmpty() && !tableFrame->IsBorderCollapse() ? + StyleTableBorder()->mEmptyCells + : NS_STYLE_TABLE_EMPTY_CELLS_SHOW; + // take account of 'empty-cells' + if (StyleVisibility()->IsVisible() && + (NS_STYLE_TABLE_EMPTY_CELLS_HIDE != emptyCellStyle)) { + // display outset box-shadows if we need to. + bool hasBoxShadow = !!StyleEffects()->mBoxShadow; + if (hasBoxShadow) { + aLists.BorderBackground()->AppendNewToTop( + new (aBuilder) nsDisplayBoxShadowOuter(aBuilder, this)); + } + + // display background if we need to. + if (aBuilder->IsForEventDelivery() || + !StyleBackground()->IsTransparent() || + StyleDisplay()->mAppearance) { + nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, + this, + GetRectRelativeToSelf(), + aLists.BorderBackground()); + } + + // display inset box-shadows if we need to. + if (hasBoxShadow) { + aLists.BorderBackground()->AppendNewToTop( + new (aBuilder) nsDisplayBoxShadowInner(aBuilder, this)); + } + + // display borders if we need to + ProcessBorders(tableFrame, aBuilder, aLists); + + // and display the selection border if we need to + if (IsSelected()) { + aLists.BorderBackground()->AppendNewToTop(new (aBuilder) + nsDisplayGeneric(aBuilder, this, ::PaintTableCellSelection, + "TableCellSelection", + nsDisplayItem::TYPE_TABLE_CELL_SELECTION)); } - - // the 'empty-cells' property has no effect on 'outline' - DisplayOutline(aBuilder, aLists); } + // the 'empty-cells' property has no effect on 'outline' + DisplayOutline(aBuilder, aLists); + // Push a null 'current table item' so that descendant tables can't // accidentally mess with our table nsAutoPushCurrentTableItem pushTableItem; diff --git a/layout/tables/nsTableColFrame.cpp b/layout/tables/nsTableColFrame.cpp index 8f449c3d9c..54b03522b0 100644 --- a/layout/tables/nsTableColFrame.cpp +++ b/layout/tables/nsTableColFrame.cpp @@ -108,6 +108,14 @@ nsTableColFrame::Reflow(nsPresContext* aPresContext, NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize); } +void +nsTableColFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, + const nsRect& aDirtyRect, + const nsDisplayListSet& aLists) +{ + nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists); +} + int32_t nsTableColFrame::GetSpan() { return StyleTable()->mSpan; diff --git a/layout/tables/nsTableColFrame.h b/layout/tables/nsTableColFrame.h index e95fe76b1d..fb989061f7 100644 --- a/layout/tables/nsTableColFrame.h +++ b/layout/tables/nsTableColFrame.h @@ -59,12 +59,9 @@ public: const ReflowInput& aReflowInput, nsReflowStatus& aStatus) override; - /** - * Table columns never paint anything, nor receive events. - */ virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, - const nsDisplayListSet& aLists) override {} + const nsDisplayListSet& aLists) override; /** * Get the "type" of the frame diff --git a/layout/tables/nsTableColGroupFrame.cpp b/layout/tables/nsTableColGroupFrame.cpp index ff8879a0b0..6ee7f0b242 100644 --- a/layout/tables/nsTableColGroupFrame.cpp +++ b/layout/tables/nsTableColGroupFrame.cpp @@ -383,6 +383,14 @@ nsTableColGroupFrame::Reflow(nsPresContext* aPresContext, NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize); } +void +nsTableColGroupFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, + const nsRect& aDirtyRect, + const nsDisplayListSet& aLists) +{ + nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists); +} + nsTableColFrame * nsTableColGroupFrame::GetFirstColumn() { return GetNextColumn(nullptr); diff --git a/layout/tables/nsTableColGroupFrame.h b/layout/tables/nsTableColGroupFrame.h index 2a25fdc444..b3dfb94e77 100644 --- a/layout/tables/nsTableColGroupFrame.h +++ b/layout/tables/nsTableColGroupFrame.h @@ -43,12 +43,9 @@ public: return static_cast(parent); } - /** - * ColGroups never paint anything, nor receive events. - */ virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, - const nsDisplayListSet& aLists) override {} + const nsDisplayListSet& aLists) override; /** A colgroup can be caused by three things: * 1) An element with table-column-group display diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index 272a77406a..b5cd3b4874 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -1131,6 +1131,42 @@ nsDisplayTableItem::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion); } +// A display item that draws all collapsed borders for a table. +class nsDisplayTableBorderCollapse : public nsDisplayTableItem { +public: + nsDisplayTableBorderCollapse(nsDisplayListBuilder* aBuilder, + nsTableFrame* aFrame) + : nsDisplayTableItem(aBuilder, aFrame) { + MOZ_COUNT_CTOR(nsDisplayTableBorderCollapse); + } +#ifdef NS_BUILD_REFCNT_LOGGING + virtual ~nsDisplayTableBorderCollapse() { + MOZ_COUNT_DTOR(nsDisplayTableBorderCollapse); + } +#endif + + virtual void Paint(nsDisplayListBuilder* aBuilder, + nsRenderingContext* aCtx) override; + NS_DISPLAY_DECL_NAME("TableBorderCollapse", TYPE_TABLE_BORDER_COLLAPSE) +}; + +void +nsDisplayTableBorderCollapse::Paint(nsDisplayListBuilder* aBuilder, + nsRenderingContext* aCtx) +{ + nsPoint pt = ToReferenceFrame(); + DrawTarget* drawTarget = aCtx->GetDrawTarget(); + + gfxPoint devPixelOffset = + nsLayoutUtils::PointToGfxPoint(pt, mFrame->PresContext()->AppUnitsPerDevPixel()); + + AutoRestoreTransform autoRestoreTransform(drawTarget); + drawTarget->SetTransform( + drawTarget->GetTransform().PreTranslate(ToPoint(devPixelOffset))); + + static_cast(mFrame)->PaintBCBorders(*drawTarget, mVisibleRect - pt); +} + class nsDisplayTableBorderBackground : public nsDisplayTableItem { public: nsDisplayTableBorderBackground(nsDisplayListBuilder* aBuilder, @@ -1150,20 +1186,6 @@ public: NS_DISPLAY_DECL_NAME("TableBorderBackground", TYPE_TABLE_BORDER_BACKGROUND) }; -#ifdef DEBUG -static bool -IsFrameAllowedInTable(nsIAtom* aType) -{ - return IS_TABLE_CELL(aType) || - nsGkAtoms::tableRowFrame == aType || - nsGkAtoms::tableRowGroupFrame == aType || - nsGkAtoms::scrollFrame == aType || - nsGkAtoms::tableFrame == aType || - nsGkAtoms::tableColFrame == aType || - nsGkAtoms::tableColGroupFrame == aType; -} -#endif - void nsDisplayTableBorderBackground::Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) @@ -1175,25 +1197,6 @@ nsDisplayTableBorderBackground::Paint(nsDisplayListBuilder* aBuilder, nsDisplayTableItemGeometry::UpdateDrawResult(this, result); } -static int32_t -GetTablePartRank(nsDisplayItem* aItem) -{ - nsIAtom* type = aItem->Frame()->GetType(); - if (type == nsGkAtoms::tableFrame) - return 0; - if (type == nsGkAtoms::tableRowGroupFrame) - return 1; - if (type == nsGkAtoms::tableRowFrame) - return 2; - return 3; -} - -static bool CompareByTablePartRank(nsDisplayItem* aItem1, nsDisplayItem* aItem2, - void* aClosure) -{ - return GetTablePartRank(aItem1) <= GetTablePartRank(aItem2); -} - /* static */ void nsTableFrame::GenericTraversal(nsDisplayListBuilder* aBuilder, nsFrame* aFrame, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) @@ -1206,31 +1209,73 @@ nsTableFrame::GenericTraversal(nsDisplayListBuilder* aBuilder, nsFrame* aFrame, // 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, aDirtyRect, aLists); + } + for (nsIFrame* kid : aFrame->PrincipalChildList()) { aFrame->BuildDisplayListForChild(aBuilder, kid, aDirtyRect, aLists); } } +static void +PaintRowBackground(nsTableRowFrame* aRow, + nsIFrame* aFrame, + nsDisplayListBuilder* aBuilder, + const nsDisplayListSet& aLists, + const nsPoint& aOffset = nsPoint()) +{ + // Compute background rect by iterating all cell frame. + for (nsTableCellFrame* cell = aRow->GetFirstCell(); cell; cell = cell->GetNextCell()) { + auto cellRect = cell->GetRectRelativeToSelf() + cell->GetNormalPosition() + aOffset; + nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, cellRect, + aLists.BorderBackground(), + true, nullptr, + aFrame->GetRectRelativeToSelf()); + } +} + +static void +PaintRowGroupBackground(nsTableRowGroupFrame* aRowGroup, + nsIFrame* aFrame, + nsDisplayListBuilder* aBuilder, + const nsDisplayListSet& aLists) +{ + for (nsTableRowFrame* row = aRowGroup->GetFirstRow(); row; row = row->GetNextRow()) { + PaintRowBackground(row, aFrame, aBuilder, aLists, row->GetNormalPosition()); + } +} + +static void +PaintRowGroupBackgroundByColIdx(nsTableRowGroupFrame* aRowGroup, + nsIFrame* aFrame, + nsDisplayListBuilder* aBuilder, + const nsDisplayListSet& aLists, + const nsTArray& aColIdx, + const nsPoint& aOffset) +{ + for (nsTableRowFrame* row = aRowGroup->GetFirstRow(); row; row = row->GetNextRow()) { + for (nsTableCellFrame* cell = row->GetFirstCell(); cell; cell = cell->GetNextCell()) { + int32_t curColIdx; + cell->GetColIndex(curColIdx); + if (aColIdx.Contains(curColIdx)) { + auto cellRect = cell->GetRectRelativeToSelf() + cell->GetNormalPosition() + row->GetNormalPosition() + aOffset; + nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, cellRect, + aLists.BorderBackground(), + true, nullptr, + aFrame->GetRectRelativeToSelf()); + } + } + } +} + /* static */ void nsTableFrame::DisplayGenericTablePart(nsDisplayListBuilder* aBuilder, nsFrame* aFrame, const nsRect& aDirtyRect, const nsDisplayListSet& aLists, - nsDisplayTableItem* aDisplayItem, DisplayGenericTablePartTraversal aTraversal) { - nsDisplayList eventsBorderBackground; - // If we need to sort the event backgrounds, then we'll put descendants' - // display items into their own set of lists. - bool sortEventBackgrounds = aDisplayItem && aBuilder->IsForEventDelivery(); - nsDisplayListCollection separatedCollection; - const nsDisplayListSet* lists = sortEventBackgrounds ? &separatedCollection : &aLists; - - nsAutoPushCurrentTableItem pushTableItem; - if (aDisplayItem) { - pushTableItem.Push(aBuilder, aDisplayItem); - } - if (aFrame->IsVisibleForPainting(aBuilder)) { nsDisplayTableItem* currentItem = aBuilder->GetCurrentTableItem(); // currentItem may be null, when none of the table parts have a @@ -1242,72 +1287,79 @@ nsTableFrame::DisplayGenericTablePart(nsDisplayListBuilder* aBuilder, // Paint the outset box-shadows for the table frames bool hasBoxShadow = aFrame->StyleEffects()->mBoxShadow != nullptr; if (hasBoxShadow) { - lists->BorderBackground()->AppendNewToTop( + aLists.BorderBackground()->AppendNewToTop( new (aBuilder) nsDisplayBoxShadowOuter(aBuilder, aFrame)); } - // Create dedicated background display items per-frame when we're - // handling events. - // XXX how to handle collapsed borders? - if (aBuilder->IsForEventDelivery()) { + if (aFrame->GetType() == nsGkAtoms::tableRowGroupFrame) { + nsTableRowGroupFrame* rowGroup = static_cast(aFrame); + PaintRowGroupBackground(rowGroup, aFrame, aBuilder, aLists); + } else if (aFrame->GetType() == nsGkAtoms::tableRowFrame) { + nsTableRowFrame* row = static_cast(aFrame); + PaintRowBackground(row, aFrame, aBuilder, aLists); + } else if (aFrame->GetType() == nsGkAtoms::tableColGroupFrame) { + // Compute background rect by iterating all cell frame. + nsTableColGroupFrame* colGroup = static_cast(aFrame); + // Collecting column index. + AutoTArray colIdx; + for (nsTableColFrame* col = colGroup->GetFirstColumn(); col; col = col->GetNextCol()) { + colIdx.AppendElement(col->GetColIndex()); + } + + nsTableFrame* table = colGroup->GetTableFrame(); + RowGroupArray rowGroups; + table->OrderRowGroups(rowGroups); + for (nsTableRowGroupFrame* rowGroup : rowGroups) { + auto offset = rowGroup->GetNormalPosition() - colGroup->GetNormalPosition(); + 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(aFrame); + AutoTArray colIdx; + colIdx.AppendElement(col->GetColIndex()); + + nsTableFrame* table = col->GetTableFrame(); + RowGroupArray rowGroups; + table->OrderRowGroups(rowGroups); + for (nsTableRowGroupFrame* rowGroup : rowGroups) { + auto offset = rowGroup->GetNormalPosition() - + col->GetNormalPosition() - + col->GetTableColGroupFrame()->GetNormalPosition(); + PaintRowGroupBackgroundByColIdx(rowGroup, aFrame, aBuilder, aLists, colIdx, offset); + } + } else { nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, aFrame->GetRectRelativeToSelf(), - lists->BorderBackground()); + aLists.BorderBackground()); } // Paint the inset box-shadows for the table frames if (hasBoxShadow) { - lists->BorderBackground()->AppendNewToTop( + aLists.BorderBackground()->AppendNewToTop( new (aBuilder) nsDisplayBoxShadowInner(aBuilder, aFrame)); } } - aTraversal(aBuilder, aFrame, aDirtyRect, *lists); + aTraversal(aBuilder, aFrame, aDirtyRect, aLists); - if (sortEventBackgrounds) { - // Ensure that the table frame event background goes before the - // table rowgroups event backgrounds, before the table row event backgrounds, - // before everything else (cells and their blocks) - separatedCollection.BorderBackground()->Sort(CompareByTablePartRank, nullptr); - separatedCollection.MoveTo(aLists); + if (aFrame->IsVisibleForPainting(aBuilder)) { + if (aFrame->GetType() == nsGkAtoms::tableFrame) { + nsTableFrame* table = static_cast(aFrame); + // In the collapsed border model, overlay all collapsed borders. + if (table->IsBorderCollapse()) { + aLists.BorderBackground()->AppendNewToTop( + new (aBuilder) nsDisplayTableBorderCollapse(aBuilder, table)); + } else { + aLists.BorderBackground()->AppendNewToTop( + new (aBuilder) nsDisplayBorder(aBuilder, table)); + } + } } aFrame->DisplayOutline(aBuilder, aLists); } -static bool -AnyTablePartHasBorderOrBackground(nsIFrame* aStart, nsIFrame* aEnd) -{ - for (nsIFrame* f = aStart; f != aEnd; f = f->GetNextSibling()) { - NS_ASSERTION(IsFrameAllowedInTable(f->GetType()), "unexpected frame type"); - - if (FrameHasBorderOrBackground(f)) - return true; - - nsTableCellFrame *cellFrame = do_QueryFrame(f); - if (cellFrame) - continue; - - if (AnyTablePartHasBorderOrBackground(f->PrincipalChildList().FirstChild(), nullptr)) - return true; - } - - return false; -} - -static void -UpdateItemForColGroupBackgrounds(nsDisplayTableItem* item, - const nsFrameList& aFrames) { - for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) { - nsTableColGroupFrame* cg = static_cast(e.get()); - item->UpdateForFrameBackground(cg); - for (nsTableColFrame* colFrame = cg->GetFirstColumn(); colFrame; - colFrame = colFrame->GetNextCol()) { - item->UpdateForFrameBackground(colFrame); - } - } -} - // table paint code is concerned primarily with borders and bg color // SEC: TODO: adjust the rect for captions void @@ -1317,35 +1369,7 @@ nsTableFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, { DO_GLOBAL_REFLOW_COUNT_DSP_COLOR("nsTableFrame", NS_RGB(255,128,255)); - nsDisplayTableItem* item = nullptr; - if (IsVisibleInSelection(aBuilder)) { - nsMargin deflate = GetDeflationForBackground(PresContext()); - if (StyleVisibility()->IsVisible()) { - // If 'deflate' is (0,0,0,0) then we can paint the table background - // in its own display item, so do that to take advantage of - // opacity and visibility optimizations - if (deflate == nsMargin(0, 0, 0, 0)) { - DisplayBackgroundUnconditional(aBuilder, aLists, false); - } - } - - // This background is created if any of the table parts are visible, - // or if we're doing event handling (since DisplayGenericTablePart - // needs the item for the |sortEventBackgrounds|-dependent code). - // Specific visibility decisions are delegated to the table background - // painter, which handles borders and backgrounds for the table. - if (aBuilder->IsForEventDelivery() || - AnyTablePartHasBorderOrBackground(this, GetNextSibling()) || - AnyTablePartHasBorderOrBackground(mColGroups.FirstChild(), nullptr)) { - item = new (aBuilder) nsDisplayTableBorderBackground(aBuilder, this, - deflate != nsMargin(0, 0, 0, 0)); - aLists.BorderBackground()->AppendNewToTop(item); - } - } - DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists, item); - if (item) { - UpdateItemForColGroupBackgrounds(item, mColGroups); - } + DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists); } nsMargin diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h index c7b92d387e..d4b6d88a7e 100644 --- a/layout/tables/nsTableFrame.h +++ b/layout/tables/nsTableFrame.h @@ -250,7 +250,6 @@ public: nsFrame* aFrame, const nsRect& aDirtyRect, const nsDisplayListSet& aLists, - nsDisplayTableItem* aDisplayItem, DisplayGenericTablePartTraversal aTraversal = GenericTraversal); // Return the closest sibling of aPriorChildFrame (including aPriroChildFrame) diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 1b6051ef2a..dc053c991f 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -605,21 +605,7 @@ nsTableRowFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { - nsDisplayTableItem* item = nullptr; - if (IsVisibleInSelection(aBuilder)) { - bool isRoot = aBuilder->IsAtRootOfPseudoStackingContext(); - if (isRoot) { - // This background is created regardless of whether this frame is - // visible or not. Visibility decisions are delegated to the - // table background painter. - // We would use nsDisplayGeneric for this rare case except that we - // need the background to be larger than the row frame in some - // cases. - item = new (aBuilder) nsDisplayTableRowBackground(aBuilder, this); - aLists.BorderBackground()->AppendNewToTop(item); - } - } - nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists, item); + nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, aLists); } nsIFrame::LogicalSides diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp index 8f014b2049..943bdf50b8 100644 --- a/layout/tables/nsTableRowGroupFrame.cpp +++ b/layout/tables/nsTableRowGroupFrame.cpp @@ -249,19 +249,8 @@ nsTableRowGroupFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { - nsDisplayTableItem* item = nullptr; - if (IsVisibleInSelection(aBuilder)) { - bool isRoot = aBuilder->IsAtRootOfPseudoStackingContext(); - if (isRoot) { - // This background is created regardless of whether this frame is - // visible or not. Visibility decisions are delegated to the - // table background painter. - item = new (aBuilder) nsDisplayTableRowGroupBackground(aBuilder, this); - aLists.BorderBackground()->AppendNewToTop(item); - } - } nsTableFrame::DisplayGenericTablePart(aBuilder, this, aDirtyRect, - aLists, item, DisplayRows); + aLists, DisplayRows); } nsIFrame::LogicalSides diff --git a/layout/tables/nsTableWrapperFrame.cpp b/layout/tables/nsTableWrapperFrame.cpp index f0b6d1512d..da71375d5d 100644 --- a/layout/tables/nsTableWrapperFrame.cpp +++ b/layout/tables/nsTableWrapperFrame.cpp @@ -190,7 +190,11 @@ nsTableWrapperFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, // Now we have to sort everything by content order, since the caption // may be somewhere inside the table - set.SortAllByContentOrder(GetContent()); + set.BlockBorderBackgrounds()->SortByContentOrder(GetContent()); + set.Floats()->SortByContentOrder(GetContent()); + set.Content()->SortByContentOrder(GetContent()); + set.PositionedDescendants()->SortByContentOrder(GetContent()); + set.Outlines()->SortByContentOrder(GetContent()); set.MoveTo(aLists); } From 04db41da36979e0ae7522c8836021c1132ea17b0 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 2 Nov 2019 23:07:40 +0100 Subject: [PATCH 02/10] Issue #146 - Part 2: Remove custom table painting component. Since we're now putting table borders and backgrounds properly in the display lists, we no longer need this custom component to do this work for us. --- layout/base/nsDisplayItemTypesList.h | 3 - layout/tables/moz.build | 1 - layout/tables/nsTableCellFrame.cpp | 14 - layout/tables/nsTableCellFrame.h | 5 - layout/tables/nsTableFrame.cpp | 84 --- layout/tables/nsTableFrame.h | 10 - layout/tables/nsTablePainter.cpp | 696 ------------------------- layout/tables/nsTablePainter.h | 268 ---------- layout/tables/nsTableRowFrame.cpp | 39 -- layout/tables/nsTableRowFrame.h | 1 - layout/tables/nsTableRowGroupFrame.cpp | 40 -- layout/tables/nsTableRowGroupFrame.h | 1 - 12 files changed, 1162 deletions(-) delete mode 100644 layout/tables/nsTablePainter.cpp delete mode 100644 layout/tables/nsTablePainter.h diff --git a/layout/base/nsDisplayItemTypesList.h b/layout/base/nsDisplayItemTypesList.h index d24f6f38fb..cf809817ff 100644 --- a/layout/base/nsDisplayItemTypesList.h +++ b/layout/base/nsDisplayItemTypesList.h @@ -56,9 +56,6 @@ DECLARE_DISPLAY_ITEM_TYPE(SVG_PATH_GEOMETRY) DECLARE_DISPLAY_ITEM_TYPE(SVG_TEXT) DECLARE_DISPLAY_ITEM_TYPE(TABLE_CELL_BACKGROUND) DECLARE_DISPLAY_ITEM_TYPE(TABLE_CELL_SELECTION) -DECLARE_DISPLAY_ITEM_TYPE(TABLE_ROW_BACKGROUND) -DECLARE_DISPLAY_ITEM_TYPE(TABLE_ROW_GROUP_BACKGROUND) -DECLARE_DISPLAY_ITEM_TYPE(TABLE_BORDER_BACKGROUND) DECLARE_DISPLAY_ITEM_TYPE(TABLE_BORDER_COLLAPSE) DECLARE_DISPLAY_ITEM_TYPE(TEXT) DECLARE_DISPLAY_ITEM_TYPE(TEXT_OVERFLOW) diff --git a/layout/tables/moz.build b/layout/tables/moz.build index b777763202..e28e21ee0a 100644 --- a/layout/tables/moz.build +++ b/layout/tables/moz.build @@ -21,7 +21,6 @@ UNIFIED_SOURCES += [ 'nsTableColFrame.cpp', 'nsTableColGroupFrame.cpp', 'nsTableFrame.cpp', - 'nsTablePainter.cpp', 'nsTableRowFrame.cpp', 'nsTableRowGroupFrame.cpp', 'nsTableWrapperFrame.cpp', diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp index bac8d387ff..ec9458f76f 100644 --- a/layout/tables/nsTableCellFrame.cpp +++ b/layout/tables/nsTableCellFrame.cpp @@ -12,7 +12,6 @@ #include "nsTableColFrame.h" #include "nsTableRowFrame.h" #include "nsTableRowGroupFrame.h" -#include "nsTablePainter.h" #include "nsStyleContext.h" #include "nsStyleConsts.h" #include "nsPresContext.h" @@ -380,19 +379,6 @@ nsTableCellFrame::PaintBackground(nsRenderingContext& aRenderingContext, return nsCSSRendering::PaintBackground(params); } -// Called by nsTablePainter -DrawResult -nsTableCellFrame::PaintCellBackground(nsRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, nsPoint aPt, - uint32_t aFlags) -{ - if (!StyleVisibility()->IsVisible()) { - return DrawResult::SUCCESS; - } - - return PaintBackground(aRenderingContext, aDirtyRect, aPt, aFlags); -} - nsresult nsTableCellFrame::ProcessBorders(nsTableFrame* aFrame, nsDisplayListBuilder* aBuilder, diff --git a/layout/tables/nsTableCellFrame.h b/layout/tables/nsTableCellFrame.h index 2408098507..5f87c5f6d0 100644 --- a/layout/tables/nsTableCellFrame.h +++ b/layout/tables/nsTableCellFrame.h @@ -107,11 +107,6 @@ public: const nsRect& aDirtyRect, const nsDisplayListSet& aLists) override; - DrawResult PaintCellBackground(nsRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, nsPoint aPt, - uint32_t aFlags); - - virtual nsresult ProcessBorders(nsTableFrame* aFrame, nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists); diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index b5cd3b4874..06a05292fd 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -23,7 +23,6 @@ #include "nsTableRowFrame.h" #include "nsTableRowGroupFrame.h" #include "nsTableWrapperFrame.h" -#include "nsTablePainter.h" #include "BasicTableLayoutStrategy.h" #include "FixedTableLayoutStrategy.h" @@ -1167,36 +1166,6 @@ nsDisplayTableBorderCollapse::Paint(nsDisplayListBuilder* aBuilder, static_cast(mFrame)->PaintBCBorders(*drawTarget, mVisibleRect - pt); } -class nsDisplayTableBorderBackground : public nsDisplayTableItem { -public: - nsDisplayTableBorderBackground(nsDisplayListBuilder* aBuilder, - nsTableFrame* aFrame, - bool aDrawsBackground) : - nsDisplayTableItem(aBuilder, aFrame, aDrawsBackground) { - MOZ_COUNT_CTOR(nsDisplayTableBorderBackground); - } -#ifdef NS_BUILD_REFCNT_LOGGING - virtual ~nsDisplayTableBorderBackground() { - MOZ_COUNT_DTOR(nsDisplayTableBorderBackground); - } -#endif - - virtual void Paint(nsDisplayListBuilder* aBuilder, - nsRenderingContext* aCtx) override; - NS_DISPLAY_DECL_NAME("TableBorderBackground", TYPE_TABLE_BORDER_BACKGROUND) -}; - -void -nsDisplayTableBorderBackground::Paint(nsDisplayListBuilder* aBuilder, - nsRenderingContext* aCtx) -{ - DrawResult result = static_cast(mFrame)-> - PaintTableBorderBackground(aBuilder, *aCtx, mVisibleRect, - ToReferenceFrame()); - - nsDisplayTableItemGeometry::UpdateDrawResult(this, result); -} - /* static */ void nsTableFrame::GenericTraversal(nsDisplayListBuilder* aBuilder, nsFrame* aFrame, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) @@ -1383,59 +1352,6 @@ nsTableFrame::GetDeflationForBackground(nsPresContext* aPresContext) const return GetOuterBCBorder(wm).GetPhysicalMargin(wm); } -// XXX We don't put the borders and backgrounds in tree order like we should. -// That requires some major surgery which we aren't going to do right now. -DrawResult -nsTableFrame::PaintTableBorderBackground(nsDisplayListBuilder* aBuilder, - nsRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsPoint aPt) -{ - nsPresContext* presContext = PresContext(); - - uint32_t bgFlags = aBuilder->GetBackgroundPaintFlags(); - PaintBorderFlags borderFlags = aBuilder->ShouldSyncDecodeImages() - ? PaintBorderFlags::SYNC_DECODE_IMAGES - : PaintBorderFlags(); - - TableBackgroundPainter painter(this, TableBackgroundPainter::eOrigin_Table, - presContext, aRenderingContext, - aDirtyRect, aPt, bgFlags); - nsMargin deflate = GetDeflationForBackground(presContext); - // If 'deflate' is (0,0,0,0) then we'll paint the table background - // in a separate display item, so don't do it here. - DrawResult result = - painter.PaintTable(this, deflate, deflate != nsMargin(0, 0, 0, 0)); - - if (StyleVisibility()->IsVisible()) { - if (!IsBorderCollapse()) { - Sides skipSides = GetSkipSides(); - nsRect rect(aPt, mRect.Size()); - - result &= - nsCSSRendering::PaintBorder(presContext, aRenderingContext, this, - aDirtyRect, rect, mStyleContext, - borderFlags, skipSides); - } else { - DrawTarget* drawTarget = aRenderingContext.GetDrawTarget(); - - gfxPoint devPixelOffset = - nsLayoutUtils::PointToGfxPoint(aPt, - PresContext()->AppUnitsPerDevPixel()); - - // XXX we should probably get rid of this translation at some stage - // But that would mean modifying PaintBCBorders, ugh - AutoRestoreTransform autoRestoreTransform(drawTarget); - drawTarget->SetTransform( - drawTarget->GetTransform().PreTranslate(ToPoint(devPixelOffset))); - - PaintBCBorders(*drawTarget, aDirtyRect - aPt); - } - } - - return result; -} - nsIFrame::LogicalSides nsTableFrame::GetLogicalSkipSides(const ReflowInput* aReflowInput) const { diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h index d4b6d88a7e..a6b786402d 100644 --- a/layout/tables/nsTableFrame.h +++ b/layout/tables/nsTableFrame.h @@ -271,16 +271,6 @@ public: const nsRect& aDirtyRect, const nsDisplayListSet& aLists) override; - /** - * Paint the background of the table and its parts (column groups, - * columns, row groups, rows, and cells), and the table border, and all - * internal borders if border-collapse is on. - */ - DrawResult PaintTableBorderBackground(nsDisplayListBuilder* aBuilder, - nsRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsPoint aPt); - /** Get the outer half (i.e., the part outside the height and width of * the table) of the largest segment (?) of border-collapsed border on * the table on each side, or 0 for non border-collapsed tables. diff --git a/layout/tables/nsTablePainter.cpp b/layout/tables/nsTablePainter.cpp deleted file mode 100644 index bfe2a7d429..0000000000 --- a/layout/tables/nsTablePainter.cpp +++ /dev/null @@ -1,696 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsTableFrame.h" -#include "nsTableRowGroupFrame.h" -#include "nsTableRowFrame.h" -#include "nsTableColGroupFrame.h" -#include "nsTableColFrame.h" -#include "nsTableCellFrame.h" -#include "nsTablePainter.h" -#include "nsCSSRendering.h" -#include "nsDisplayList.h" -#include "mozilla/WritingModes.h" - -/* ~*~ Table Background Painting ~*~ - - Mozilla's Table Background painting follows CSS2.1:17.5.1 - That section does not, however, describe the effect of - borders on background image positioning. What we do is: - - - in separate borders, the borders are passed in so that - their width figures in image positioning, even for rows/cols, which - don't have visible borders. This is done to allow authors - to position row backgrounds by, for example, aligning the - top left corner with the top left padding corner of the - top left table cell in the row in cases where all cells - have consistent border widths. If we didn't honor these - invisible borders, there would be no way to align - backgrounds with the padding edges, and designs would be - lost underneath the border. - - - in collapsing borders, because the borders collapse, we - use the -continuous border- width to synthesize a border - style and pass that in instead of using the element's - assigned style directly. - - The continuous border on a given edge of an element is - the collapse of all borders guaranteed to be continuous - along that edge. Cell borders are ignored (because, for - example, setting a thick border on the leftmost cell - should not shift the row background over; this way a - striped background set on will line up across rows - even if the cells are assigned arbitrary border widths. - - For example, the continuous border on the top edge of a - row group is the collapse of any row group, row, and - table borders involved. (The first row group's top would - be [table-top + row group top + first row top]. It's bottom - would be [row group bottom + last row bottom + next row - top + next row group top].) - The top edge of a column group likewise includes the - table top, row group top, and first row top borders. However, - it *also* includes its own top border, since that is guaranteed - to be continuous. It does not include column borders because - those are not guaranteed to be continuous: there may be two - columns with different borders in a single column group. - - An alternative would be to define the continuous border as - [table? + row group + row] for horizontal - [table? + col group + col] for vertical - This makes it easier to line up backgrounds across elements - despite varying border widths, but it does not give much - flexibility in aligning /to/ those border widths. -*/ - - -/* ~*~ TableBackgroundPainter ~*~ - - The TableBackgroundPainter is created and destroyed in one painting call. - Its principal function is PaintTable, which paints all table element - backgrounds. The initial code in that method sets up an array of column - data that caches the background styles and the border sizes for the - columns and colgroups in TableBackgroundData structs in mCols. Data for - BC borders are calculated and stashed in a synthesized border style struct - in the data struct since collapsed borders aren't the same width as style- - assigned borders. The data struct optimizes by only doing this if there's - an image background; otherwise we don't care. //XXX should also check background-origin - The class then loops through the row groups, rows, and cells. At the cell - level, it paints the backgrounds, one over the other, inside the cell rect. - - The exception to this pattern is when a table element creates a (pseudo) - stacking context. Elements with stacking contexts (e.g., 'opacity' applied) - are passed through, which means their data (and their - descendants' data) are not cached. The full loop is still executed, however, - so that underlying layers can get painted at the cell level. - - The TableBackgroundPainter is then destroyed. - - Elements with stacking contexts set up their own painter to finish the - painting process, since they were skipped. They call the appropriate - sub-part of the loop (e.g. PaintRow) which will paint the frame and - descendants. - - XXX views are going - */ - -using namespace mozilla; -using namespace mozilla::image; - -TableBackgroundPainter::TableBackgroundData::TableBackgroundData() - : mFrame(nullptr) - , mVisible(false) - , mUsesSynthBorder(false) -{ -} - -TableBackgroundPainter::TableBackgroundData::TableBackgroundData(nsIFrame* aFrame) - : mFrame(aFrame) - , mRect(aFrame->GetRect()) - , mVisible(mFrame->IsVisibleForPainting()) - , mUsesSynthBorder(false) -{ -} - -inline bool -TableBackgroundPainter::TableBackgroundData::ShouldSetBCBorder() const -{ - /* we only need accurate border data when positioning background images*/ - if (!mVisible) { - return false; - } - - const nsStyleImageLayers& layers = mFrame->StyleBackground()->mImage; - NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, layers) { - if (!layers.mLayers[i].mImage.IsEmpty()) - return true; - } - return false; -} - -void -TableBackgroundPainter::TableBackgroundData::SetBCBorder(const nsMargin& aBorder) -{ - mUsesSynthBorder = true; - mSynthBorderWidths = aBorder; -} - -nsStyleBorder -TableBackgroundPainter::TableBackgroundData::StyleBorder(const nsStyleBorder& aZeroBorder) const -{ - MOZ_ASSERT(mVisible, "Don't call StyleBorder on an invisible TableBackgroundData"); - - if (mUsesSynthBorder) { - nsStyleBorder result = aZeroBorder; - NS_FOR_CSS_SIDES(side) { - result.SetBorderWidth(side, mSynthBorderWidths.Side(side)); - } - return result; - } - - MOZ_ASSERT(mFrame); - - return *mFrame->StyleBorder(); -} - -TableBackgroundPainter::TableBackgroundPainter(nsTableFrame* aTableFrame, - Origin aOrigin, - nsPresContext* aPresContext, - nsRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - const nsPoint& aRenderPt, - uint32_t aBGPaintFlags) - : mPresContext(aPresContext), - mRenderingContext(aRenderingContext), - mRenderPt(aRenderPt), - mDirtyRect(aDirtyRect), - mOrigin(aOrigin), - mZeroBorder(aPresContext), - mBGPaintFlags(aBGPaintFlags) -{ - MOZ_COUNT_CTOR(TableBackgroundPainter); - - NS_FOR_CSS_SIDES(side) { - mZeroBorder.SetBorderStyle(side, NS_STYLE_BORDER_STYLE_SOLID); - mZeroBorder.SetBorderWidth(side, 0); - } - - mIsBorderCollapse = aTableFrame->IsBorderCollapse(); -#ifdef DEBUG - mCompatMode = mPresContext->CompatibilityMode(); -#endif - mNumCols = aTableFrame->GetColCount(); -} - -TableBackgroundPainter::~TableBackgroundPainter() -{ - MOZ_COUNT_DTOR(TableBackgroundPainter); -} - -DrawResult -TableBackgroundPainter::PaintTableFrame(nsTableFrame* aTableFrame, - nsTableRowGroupFrame* aFirstRowGroup, - nsTableRowGroupFrame* aLastRowGroup, - const nsMargin& aDeflate) -{ - MOZ_ASSERT(aTableFrame, "null frame"); - TableBackgroundData tableData(aTableFrame); - tableData.mRect.MoveTo(0,0); //using table's coords - tableData.mRect.Deflate(aDeflate); - WritingMode wm = aTableFrame->GetWritingMode(); - if (mIsBorderCollapse && tableData.ShouldSetBCBorder()) { - if (aFirstRowGroup && aLastRowGroup && mNumCols > 0) { - //only handle non-degenerate tables; we need a more robust BC model - //to make degenerate tables' borders reasonable to deal with - LogicalMargin border(wm); - LogicalMargin tempBorder(wm); - nsTableColFrame* colFrame = aTableFrame->GetColFrame(mNumCols - 1); - if (colFrame) { - colFrame->GetContinuousBCBorderWidth(wm, tempBorder); - } - border.IEnd(wm) = tempBorder.IEnd(wm); - - aLastRowGroup->GetContinuousBCBorderWidth(wm, tempBorder); - border.BEnd(wm) = tempBorder.BEnd(wm); - - nsTableRowFrame* rowFrame = aFirstRowGroup->GetFirstRow(); - if (rowFrame) { - rowFrame->GetContinuousBCBorderWidth(wm, tempBorder); - border.BStart(wm) = tempBorder.BStart(wm); - } - - border.IStart(wm) = aTableFrame->GetContinuousIStartBCBorderWidth(); - - tableData.SetBCBorder(border.GetPhysicalMargin(wm)); - } - } - - DrawResult result = DrawResult::SUCCESS; - - if (tableData.IsVisible()) { - nsCSSRendering::PaintBGParams params = - nsCSSRendering::PaintBGParams::ForAllLayers(*mPresContext, - mRenderingContext, - mDirtyRect, - tableData.mRect + mRenderPt, - tableData.mFrame, - mBGPaintFlags); - - result &= - nsCSSRendering::PaintBackgroundWithSC(params, - tableData.mFrame->StyleContext(), - tableData.StyleBorder(mZeroBorder)); - } - - return result; -} - -void -TableBackgroundPainter::TranslateContext(nscoord aDX, - nscoord aDY) -{ - mRenderPt += nsPoint(aDX, aDY); - for (auto& col : mCols) { - col.mCol.mRect.MoveBy(-aDX, -aDY); - } - for (auto& colGroup : mColGroups) { - colGroup.mRect.MoveBy(-aDX, -aDY); - } -} - -TableBackgroundPainter::ColData::ColData(nsIFrame* aFrame, TableBackgroundData& aColGroupBGData) - : mCol(aFrame) - , mColGroup(aColGroupBGData) -{ -} - -DrawResult -TableBackgroundPainter::PaintTable(nsTableFrame* aTableFrame, - const nsMargin& aDeflate, - bool aPaintTableBackground) -{ - NS_PRECONDITION(aTableFrame, "null table frame"); - - nsTableFrame::RowGroupArray rowGroups; - aTableFrame->OrderRowGroups(rowGroups); - WritingMode wm = aTableFrame->GetWritingMode(); - - DrawResult result = DrawResult::SUCCESS; - - if (rowGroups.Length() < 1) { //degenerate case - if (aPaintTableBackground) { - result &= PaintTableFrame(aTableFrame, nullptr, nullptr, nsMargin(0,0,0,0)); - } - /* No cells; nothing else to paint */ - return result; - } - - if (aPaintTableBackground) { - result &= - PaintTableFrame(aTableFrame, rowGroups[0], rowGroups[rowGroups.Length() - 1], - aDeflate); - } - - /*Set up column background/border data*/ - if (mNumCols > 0) { - nsFrameList& colGroupList = aTableFrame->GetColGroups(); - NS_ASSERTION(colGroupList.FirstChild(), "table should have at least one colgroup"); - - // Collect all col group frames first so that we know how many there are. - nsTArray colGroupFrames; - for (nsTableColGroupFrame* cgFrame = static_cast(colGroupList.FirstChild()); - cgFrame; cgFrame = static_cast(cgFrame->GetNextSibling())) { - - if (cgFrame->GetColCount() < 1) { - //No columns, no cells, so no need for data - continue; - } - colGroupFrames.AppendElement(cgFrame); - } - - // Ensure that mColGroups won't reallocate during the loop below, because - // we grab references to its contents and need those to stay valid until - // mColGroups is destroyed as part of TablePainter destruction. - mColGroups.SetCapacity(colGroupFrames.Length()); - - LogicalMargin border(wm); - /* BC iStart borders aren't stored on cols, but the previous column's - iEnd border is the next one's iStart border.*/ - //Start with table's iStart border. - nscoord lastIStartBorder = aTableFrame->GetContinuousIStartBCBorderWidth(); - - for (nsTableColGroupFrame* cgFrame : colGroupFrames) { - /*Create data struct for column group*/ - TableBackgroundData& cgData = *mColGroups.AppendElement(TableBackgroundData(cgFrame)); - if (mIsBorderCollapse && cgData.ShouldSetBCBorder()) { - border.IStart(wm) = lastIStartBorder; - cgFrame->GetContinuousBCBorderWidth(wm, border); - cgData.SetBCBorder(border.GetPhysicalMargin(wm)); - } - - /*Loop over columns in this colgroup*/ - for (nsTableColFrame* col = cgFrame->GetFirstColumn(); col; - col = static_cast(col->GetNextSibling())) { - MOZ_ASSERT(size_t(col->GetColIndex()) == mCols.Length()); - // Store a reference to the colGroup in the ColData element. - ColData& colData = *mCols.AppendElement(ColData(col, cgData)); - //Bring column mRect into table's coord system - colData.mCol.mRect.MoveBy(cgData.mRect.x, cgData.mRect.y); - if (mIsBorderCollapse) { - border.IStart(wm) = lastIStartBorder; - lastIStartBorder = col->GetContinuousBCBorderWidth(wm, border); - if (colData.mCol.ShouldSetBCBorder()) { - colData.mCol.SetBCBorder(border.GetPhysicalMargin(wm)); - } - } - } - } - } - - for (uint32_t i = 0; i < rowGroups.Length(); i++) { - nsTableRowGroupFrame* rg = rowGroups[i]; - TableBackgroundData rowGroupBGData(rg); - // Need to compute the right rect via GetOffsetTo, since the row - // group may not be a child of the table. - rowGroupBGData.mRect.MoveTo(rg->GetOffsetTo(aTableFrame)); - - // We have to draw backgrounds not only within the overflow region of this - // row group, but also possibly (in the case of column / column group - // backgrounds) at its pre-relative-positioning location. - nsRect rgVisualOverflow = rg->GetVisualOverflowRectRelativeToSelf(); - nsRect rgOverflowRect = rgVisualOverflow + rg->GetPosition(); - nsRect rgNormalRect = rgVisualOverflow + rg->GetNormalPosition(); - - if (rgOverflowRect.Union(rgNormalRect).Intersects(mDirtyRect - mRenderPt)) { - result &= - PaintRowGroup(rg, rowGroupBGData, rg->IsPseudoStackingContextFromStyle()); - } - } - - return result; -} - -DrawResult -TableBackgroundPainter::PaintRowGroup(nsTableRowGroupFrame* aFrame) -{ - return PaintRowGroup(aFrame, TableBackgroundData(aFrame), false); -} - -DrawResult -TableBackgroundPainter::PaintRowGroup(nsTableRowGroupFrame* aFrame, - TableBackgroundData aRowGroupBGData, - bool aPassThrough) -{ - MOZ_ASSERT(aFrame, "null frame"); - - nsTableRowFrame* firstRow = aFrame->GetFirstRow(); - WritingMode wm = aFrame->GetWritingMode(); - - /* Load row group data */ - if (aPassThrough) { - aRowGroupBGData.MakeInvisible(); - } else { - if (mIsBorderCollapse && aRowGroupBGData.ShouldSetBCBorder()) { - LogicalMargin border(wm); - if (firstRow) { - //pick up first row's bstart border (= rg bstart border) - firstRow->GetContinuousBCBorderWidth(wm, border); - /* (row group doesn't store its bstart border) */ - } - //overwrite sides+bottom borders with rg's own - aFrame->GetContinuousBCBorderWidth(wm, border); - aRowGroupBGData.SetBCBorder(border.GetPhysicalMargin(wm)); - } - aPassThrough = !aRowGroupBGData.IsVisible(); - } - - /* translate everything into row group coord system*/ - if (eOrigin_TableRowGroup != mOrigin) { - TranslateContext(aRowGroupBGData.mRect.x, aRowGroupBGData.mRect.y); - } - nsRect rgRect = aRowGroupBGData.mRect; - aRowGroupBGData.mRect.MoveTo(0, 0); - - /* Find the right row to start with */ - - // Note that mDirtyRect - mRenderPt is guaranteed to be in the row - // group's coordinate system here, so passing its .y to - // GetFirstRowContaining is ok. - nscoord overflowAbove; - nsIFrame* cursor = aFrame->GetFirstRowContaining(mDirtyRect.y - mRenderPt.y, &overflowAbove); - - // Sadly, it seems like there may be non-row frames in there... or something? - // There are certainly null-checks in GetFirstRow() and GetNextRow(). :( - while (cursor && cursor->GetType() != nsGkAtoms::tableRowFrame) { - cursor = cursor->GetNextSibling(); - } - - // It's OK if cursor is null here. - nsTableRowFrame* row = static_cast(cursor); - if (!row) { - // No useful cursor; just start at the top. Don't bother to set up a - // cursor; if we've gotten this far then we've already built the display - // list for the rowgroup, so not having a cursor means that there's some - // good reason we don't have a cursor and we shouldn't create one here. - row = firstRow; - } - - DrawResult result = DrawResult::SUCCESS; - - /* Finally paint */ - for (; row; row = row->GetNextRow()) { - TableBackgroundData rowBackgroundData(row); - - // Be sure to consider our positions both pre- and post-relative - // positioning, since we potentially need to paint at both places. - nscoord rowY = std::min(rowBackgroundData.mRect.y, row->GetNormalPosition().y); - - // Intersect wouldn't handle rowspans. - if (cursor && - (mDirtyRect.YMost() - mRenderPt.y) <= (rowY - overflowAbove)) { - // All done; cells originating in later rows can't intersect mDirtyRect. - break; - } - - result &= - PaintRow(row, aRowGroupBGData, rowBackgroundData, - aPassThrough || row->IsPseudoStackingContextFromStyle()); - } - - /* translate back into table coord system */ - if (eOrigin_TableRowGroup != mOrigin) { - TranslateContext(-rgRect.x, -rgRect.y); - } - - return result; -} - -DrawResult -TableBackgroundPainter::PaintRow(nsTableRowFrame* aFrame) -{ - return PaintRow(aFrame, TableBackgroundData(), TableBackgroundData(aFrame), false); -} - -DrawResult -TableBackgroundPainter::PaintRow(nsTableRowFrame* aFrame, - const TableBackgroundData& aRowGroupBGData, - TableBackgroundData aRowBGData, - bool aPassThrough) -{ - MOZ_ASSERT(aFrame, "null frame"); - - /* Load row data */ - WritingMode wm = aFrame->GetWritingMode(); - if (aPassThrough) { - aRowBGData.MakeInvisible(); - } else { - if (mIsBorderCollapse && aRowBGData.ShouldSetBCBorder()) { - LogicalMargin border(wm); - nsTableRowFrame* nextRow = aFrame->GetNextRow(); - if (nextRow) { //outer bStart after us is inner bEnd for us - border.BEnd(wm) = nextRow->GetOuterBStartContBCBorderWidth(); - } - else { //acquire rg's bEnd border - nsTableRowGroupFrame* rowGroup = static_cast(aFrame->GetParent()); - rowGroup->GetContinuousBCBorderWidth(wm, border); - } - //get the rest of the borders; will overwrite all but bEnd - aFrame->GetContinuousBCBorderWidth(wm, border); - - aRowBGData.SetBCBorder(border.GetPhysicalMargin(wm)); - } - aPassThrough = !aRowBGData.IsVisible(); - } - - /* Translate */ - if (eOrigin_TableRow == mOrigin) { - /* If we originate from the row, then make the row the origin. */ - aRowBGData.mRect.MoveTo(0, 0); - } - //else: Use row group's coord system -> no translation necessary - - DrawResult result = DrawResult::SUCCESS; - - for (nsTableCellFrame* cell = aFrame->GetFirstCell(); cell; cell = cell->GetNextCell()) { - nsRect cellBGRect, rowBGRect, rowGroupBGRect, colBGRect; - ComputeCellBackgrounds(cell, aRowGroupBGData, aRowBGData, - cellBGRect, rowBGRect, - rowGroupBGRect, colBGRect); - - // Find the union of all the cell background layers. - nsRect combinedRect(cellBGRect); - combinedRect.UnionRect(combinedRect, rowBGRect); - combinedRect.UnionRect(combinedRect, rowGroupBGRect); - combinedRect.UnionRect(combinedRect, colBGRect); - - if (combinedRect.Intersects(mDirtyRect)) { - bool passCell = aPassThrough || cell->IsPseudoStackingContextFromStyle(); - result &= - PaintCell(cell, aRowGroupBGData, aRowBGData, cellBGRect, rowBGRect, - rowGroupBGRect, colBGRect, passCell); - } - } - - return result; -} - -DrawResult -TableBackgroundPainter::PaintCell(nsTableCellFrame* aCell, - const TableBackgroundData& aRowGroupBGData, - const TableBackgroundData& aRowBGData, - nsRect& aCellBGRect, - nsRect& aRowBGRect, - nsRect& aRowGroupBGRect, - nsRect& aColBGRect, - bool aPassSelf) -{ - MOZ_ASSERT(aCell, "null frame"); - - const nsStyleTableBorder* cellTableStyle; - cellTableStyle = aCell->StyleTableBorder(); - if (NS_STYLE_TABLE_EMPTY_CELLS_SHOW != cellTableStyle->mEmptyCells && - aCell->GetContentEmpty() && !mIsBorderCollapse) { - return DrawResult::SUCCESS; - } - - int32_t colIndex; - aCell->GetColIndex(colIndex); - // We're checking mNumCols instead of mCols.Length() here because mCols can - // be empty even if mNumCols > 0. - NS_ASSERTION(size_t(colIndex) < mNumCols, "out-of-bounds column index"); - if (size_t(colIndex) >= mNumCols) { - return DrawResult::SUCCESS; - } - - // If callers call PaintRowGroup or PaintRow directly, we haven't processed - // our columns. Ignore column / col group backgrounds in that case. - bool haveColumns = !mCols.IsEmpty(); - - DrawResult result = DrawResult::SUCCESS; - - //Paint column group background - if (haveColumns && mCols[colIndex].mColGroup.IsVisible()) { - nsCSSRendering::PaintBGParams params = - nsCSSRendering::PaintBGParams::ForAllLayers(*mPresContext, mRenderingContext, - mDirtyRect, - mCols[colIndex].mColGroup.mRect + mRenderPt, - mCols[colIndex].mColGroup.mFrame, - mBGPaintFlags); - params.bgClipRect = &aColBGRect; - result &= - nsCSSRendering::PaintBackgroundWithSC(params, - mCols[colIndex].mColGroup.mFrame->StyleContext(), - mCols[colIndex].mColGroup.StyleBorder(mZeroBorder)); - } - - //Paint column background - if (haveColumns && mCols[colIndex].mCol.IsVisible()) { - nsCSSRendering::PaintBGParams params = - nsCSSRendering::PaintBGParams::ForAllLayers(*mPresContext, mRenderingContext, - mDirtyRect, - mCols[colIndex].mCol.mRect + mRenderPt, - mCols[colIndex].mCol.mFrame, - mBGPaintFlags); - params.bgClipRect = &aColBGRect; - result &= - nsCSSRendering::PaintBackgroundWithSC(params, - mCols[colIndex].mCol.mFrame->StyleContext(), - mCols[colIndex].mCol.StyleBorder(mZeroBorder)); - } - - //Paint row group background - if (aRowGroupBGData.IsVisible()) { - nsCSSRendering::PaintBGParams params = - nsCSSRendering::PaintBGParams::ForAllLayers(*mPresContext, mRenderingContext, - mDirtyRect, - aRowGroupBGData.mRect + mRenderPt, - aRowGroupBGData.mFrame, mBGPaintFlags); - params.bgClipRect = &aRowGroupBGRect; - result &= - nsCSSRendering::PaintBackgroundWithSC(params, - aRowGroupBGData.mFrame->StyleContext(), - aRowGroupBGData.StyleBorder(mZeroBorder)); - } - - //Paint row background - if (aRowBGData.IsVisible()) { - nsCSSRendering::PaintBGParams params = - nsCSSRendering::PaintBGParams::ForAllLayers(*mPresContext, mRenderingContext, - mDirtyRect, - aRowBGData.mRect + mRenderPt, - aRowBGData.mFrame, mBGPaintFlags); - params.bgClipRect = &aRowBGRect; - result &= - nsCSSRendering::PaintBackgroundWithSC(params, - aRowBGData.mFrame->StyleContext(), - aRowBGData.StyleBorder(mZeroBorder)); - } - - //Paint cell background in border-collapse unless we're just passing - if (mIsBorderCollapse && !aPassSelf) { - result &= - aCell->PaintCellBackground(mRenderingContext, mDirtyRect, - aCellBGRect.TopLeft(), mBGPaintFlags); - } - - return result; -} - -void -TableBackgroundPainter::ComputeCellBackgrounds(nsTableCellFrame* aCell, - const TableBackgroundData& aRowGroupBGData, - const TableBackgroundData& aRowBGData, - nsRect& aCellBGRect, - nsRect& aRowBGRect, - nsRect& aRowGroupBGRect, - nsRect& aColBGRect) -{ - // We need to compute table background layer rects for this cell space, - // adjusted for possible relative positioning. This behavior is not specified - // at the time of this writing, but the approach below should be web - // compatible. - // - // Our goal is that relative positioning of a table part should leave - // backgrounds *under* that part unchanged. ("Under" being defined by CSS 2.1 - // Section 17.5.1.) If a cell is positioned, we do not expect the row - // background to move. On the other hand, the backgrounds of layers *above* - // the positioned part are taken along for the ride -- for example, - // positioning a row group will also cause the row background to be drawn in - // the new location, unless it has further positioning applied. - // - // Each table part layer has its position stored in the coordinate space of - // the layer below (which is to say, its geometric parent), and the stored - // position is the post-relative-positioning one. The position of each - // background layer rect is thus determined by peeling off successive table - // part layers, removing the contribution of each layer's positioning one by - // one. Every rect we generate will be the same size, the size of the cell - // space. - - // We cannot rely on the row group background data to be available, since some - // callers enter through PaintRow. - nsIFrame* rowGroupFrame = - aRowGroupBGData.mFrame ? aRowGroupBGData.mFrame : aRowBGData.mFrame->GetParent(); - - // The cell background goes at the cell's position, translated to use the same - // coordinate system as aRowBGData. - aCellBGRect = aCell->GetRect() + aRowBGData.mRect.TopLeft() + mRenderPt; - - // The row background goes at the normal position of the cell, which is to say - // the position without relative positioning applied. - aRowBGRect = aCellBGRect + (aCell->GetNormalPosition() - aCell->GetPosition()); - - // The row group background goes at the position we'd find the cell if neither - // the cell's relative positioning nor the row's were applied. - aRowGroupBGRect = aRowBGRect + - (aRowBGData.mFrame->GetNormalPosition() - aRowBGData.mFrame->GetPosition()); - - // The column and column group backgrounds (they're always at the same - // location, since relative positioning doesn't apply to columns or column - // groups) are drawn at the position we'd find the cell if none of the cell's, - // row's, or row group's relative positioning were applied. - aColBGRect = aRowGroupBGRect + - (rowGroupFrame->GetNormalPosition() - rowGroupFrame->GetPosition()); - -} diff --git a/layout/tables/nsTablePainter.h b/layout/tables/nsTablePainter.h deleted file mode 100644 index dfba421565..0000000000 --- a/layout/tables/nsTablePainter.h +++ /dev/null @@ -1,268 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef nsTablePainter_h__ -#define nsTablePainter_h__ - -#include "imgIContainer.h" - -#include "celldata.h" - -// flags for Paint, PaintChild, PaintChildren are currently only used by tables. -//Table-based paint call; not a direct call as with views -#define NS_PAINT_FLAG_TABLE_BG_PAINT 0x00000001 -//Cells should paint their backgrounds only, no children -#define NS_PAINT_FLAG_TABLE_CELL_BG_PASS 0x00000002 - -class nsIFrame; -class nsTableFrame; -class nsTableRowGroupFrame; -class nsTableRowFrame; -class nsTableCellFrame; - -class TableBackgroundPainter -{ - /* - * Helper class for painting table backgrounds - * - */ - - typedef mozilla::image::DrawResult DrawResult; - - public: - - enum Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow }; - - /** Public constructor - * @param aTableFrame - the table's table frame - * @param aOrigin - what type of table frame is creating this instance - * @param aPresContext - the presentation context - * @param aRenderingContext - the rendering context - * @param aDirtyRect - the area that needs to be painted, - * relative to aRenderingContext - * @param aPt - offset of the table frame relative to - * aRenderingContext - * @param aBGPaintFlags - Flags of the nsCSSRendering::PAINTBG_* variety - */ - TableBackgroundPainter(nsTableFrame* aTableFrame, - Origin aOrigin, - nsPresContext* aPresContext, - nsRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - const nsPoint& aPt, - uint32_t aBGPaintFlags); - - /** Destructor */ - ~TableBackgroundPainter(); - - /* ~*~ The Border Collapse Painting Issue ~*~ - - In border-collapse, the *table* paints the cells' borders, - so we need to make sure the backgrounds get painted first - (underneath) by doing a cell-background-only painting pass. - */ - - /* ~*~ Using nsTablePainter Background Painting ~*~ - - A call to PaintTable will normally paint all of the table's - elements (except for the table background, if aPaintTableBackground - is false). - Elements with views however, will be skipped and must create their - own painter to call the appropriate paint function in their ::Paint - method (e.g. painter.PaintRow in nsTableRow::Paint) - */ - - /** Paint background for the table frame (if requested) and its children - * down through cells. - * (Cells themselves will only be painted in border collapse) - * Table must do a flagged TABLE_BG_PAINT ::Paint call on its - * children afterwards - * @param aTableFrame - the table frame - * @param aDeflate - deflation needed to bring table's mRect - * to the outer grid lines in border-collapse - * @param aPaintTableBackground - if true, the table background - * is included, otherwise it isn't - * @returns DrawResult::SUCCESS if all painting was successful. If some - * painting failed or an improved result could be achieved by sync - * decoding images, returns another value. - */ - DrawResult PaintTable(nsTableFrame* aTableFrame, const nsMargin& aDeflate, - bool aPaintTableBackground); - - /** Paint background for the row group and its children down through cells - * (Cells themselves will only be painted in border collapse) - * Standards mode only - * Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its - * children afterwards - * @param aFrame - the table row group frame - * @returns DrawResult::SUCCESS if all painting was successful. If some - * painting failed or an improved result could be achieved by sync - * decoding images, returns another value. - */ - DrawResult PaintRowGroup(nsTableRowGroupFrame* aFrame); - - /** Paint background for the row and its children down through cells - * (Cells themselves will only be painted in border collapse) - * Standards mode only - * Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its - * children afterwards - * @param aFrame - the table row frame - * @returns DrawResult::SUCCESS if all painting was successful. If some - * painting failed or an improved result could be achieved by sync - * decoding images, returns another value. - */ - DrawResult PaintRow(nsTableRowFrame* aFrame); - - private: - struct TableBackgroundData; - - /** Paint table frame's background - * @param aTableFrame - the table frame - * @param aFirstRowGroup - the first (in layout order) row group - * may be null - * @param aLastRowGroup - the last (in layout order) row group - * may be null - * @param aDeflate - adjustment to frame's rect (used for quirks BC) - * may be null - */ - DrawResult PaintTableFrame(nsTableFrame* aTableFrame, - nsTableRowGroupFrame* aFirstRowGroup, - nsTableRowGroupFrame* aLastRowGroup, - const nsMargin& aDeflate); - - /* aPassThrough params indicate whether to paint the element or to just - * pass through and paint underlying layers only. - * aRowGroupBGData is not a const reference because the function modifies - * its copy. Same for aRowBGData in PaintRow. - * See Public versions for function descriptions - */ - DrawResult PaintRowGroup(nsTableRowGroupFrame* aFrame, - TableBackgroundData aRowGroupBGData, - bool aPassThrough); - - DrawResult PaintRow(nsTableRowFrame* aFrame, - const TableBackgroundData& aRowGroupBGData, - TableBackgroundData aRowBGData, - bool aPassThrough); - - /** Paint table background layers for this cell space - * Also paints cell's own background in border-collapse mode - * @param aCell - the cell - * @param aRowGroupBGData - background drawing info for the row group - * @param aRowBGData - background drawing info for the row - * @param aCellBGRect - background rect for the cell - * @param aRowBGRect - background rect for the row - * @param aRowGroupBGRect - background rect for the row group - * @param aColBGRect - background rect for the column and column group - * @param aPassSelf - pass this cell; i.e. paint only underlying layers - */ - DrawResult PaintCell(nsTableCellFrame* aCell, - const TableBackgroundData& aRowGroupBGData, - const TableBackgroundData& aRowBGData, - nsRect& aCellBGRect, - nsRect& aRowBGRect, - nsRect& aRowGroupBGRect, - nsRect& aColBGRect, - bool aPassSelf); - - /** Compute table background layer positions for this cell space - * @param aCell - the cell - * @param aRowGroupBGData - background drawing info for the row group - * @param aRowBGData - background drawing info for the row - * @param aCellBGRectOut - outparam: background rect for the cell - * @param aRowBGRectOut - outparam: background rect for the row - * @param aRowGroupBGRectOut - outparam: background rect for the row group - * @param aColBGRectOut - outparam: background rect for the column - and column group - */ - void ComputeCellBackgrounds(nsTableCellFrame* aCell, - const TableBackgroundData& aRowGroupBGData, - const TableBackgroundData& aRowBGData, - nsRect& aCellBGRect, - nsRect& aRowBGRect, - nsRect& aRowGroupBGRect, - nsRect& aColBGRect); - - /** Translate mRenderingContext, mDirtyRect, and mCols' column and - * colgroup coords - * @param aDX - origin's x-coord change - * @param aDY - origin's y-coord change - */ - void TranslateContext(nscoord aDX, - nscoord aDY); - - struct TableBackgroundData { - public: - /** - * Construct an empty TableBackgroundData instance, which is invisible. - */ - TableBackgroundData(); - - /** - * Construct a TableBackgroundData instance for a frame. Visibility will - * be derived from the frame and can be overridden using MakeInvisible(). - */ - explicit TableBackgroundData(nsIFrame* aFrame); - - /** Destructor */ - ~TableBackgroundData() {} - - /** Data is valid & frame is visible */ - bool IsVisible() const { return mVisible; } - - /** Override visibility of the frame, force it to be invisible */ - void MakeInvisible() { mVisible = false; } - - /** True if need to set border-collapse border; must call SetFull beforehand */ - bool ShouldSetBCBorder() const; - - /** Set border-collapse border with aBorderWidth as widths */ - void SetBCBorder(const nsMargin& aBorderWidth); - - /** - * @param aZeroBorder An nsStyleBorder instance that has been initialized - * for the right nsPresContext, with all border widths - * set to zero and border styles set to solid. - * @return The nsStyleBorder that should be used for rendering - * this background. - */ - nsStyleBorder StyleBorder(const nsStyleBorder& aZeroBorder) const; - - nsIFrame* const mFrame; - - /** mRect is the rect of mFrame in the current coordinate system */ - nsRect mRect; - - private: - nsMargin mSynthBorderWidths; - bool mVisible; - bool mUsesSynthBorder; - }; - - struct ColData { - ColData(nsIFrame* aFrame, TableBackgroundData& aColGroupBGData); - TableBackgroundData mCol; - TableBackgroundData& mColGroup; // reference to col's parent colgroup's data, owned by TablePainter in mColGroups - }; - - nsPresContext* mPresContext; - nsRenderingContext& mRenderingContext; - nsPoint mRenderPt; - nsRect mDirtyRect; -#ifdef DEBUG - nsCompatibility mCompatMode; -#endif - bool mIsBorderCollapse; - Origin mOrigin; //user's table frame type - - nsTArray mColGroups; - nsTArray mCols; - size_t mNumCols; - - nsStyleBorder mZeroBorder; //cached zero-width border - uint32_t mBGPaintFlags; -}; - -#endif diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index dc053c991f..05b9deee9c 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -561,45 +561,6 @@ nsTableRowFrame::CalcBSize(const ReflowInput& aReflowInput) return GetInitialBSize(); } -/** - * We need a custom display item for table row backgrounds. This is only used - * when the table row is the root of a stacking context (e.g., has 'opacity'). - * Table row backgrounds can extend beyond the row frame bounds, when - * the row contains row-spanning cells. - */ -class nsDisplayTableRowBackground : public nsDisplayTableItem { -public: - nsDisplayTableRowBackground(nsDisplayListBuilder* aBuilder, - nsTableRowFrame* aFrame) : - nsDisplayTableItem(aBuilder, aFrame) { - MOZ_COUNT_CTOR(nsDisplayTableRowBackground); - } -#ifdef NS_BUILD_REFCNT_LOGGING - virtual ~nsDisplayTableRowBackground() { - MOZ_COUNT_DTOR(nsDisplayTableRowBackground); - } -#endif - - virtual void Paint(nsDisplayListBuilder* aBuilder, - nsRenderingContext* aCtx) override; - NS_DISPLAY_DECL_NAME("TableRowBackground", TYPE_TABLE_ROW_BACKGROUND) -}; - -void -nsDisplayTableRowBackground::Paint(nsDisplayListBuilder* aBuilder, - nsRenderingContext* aCtx) -{ - auto rowFrame = static_cast(mFrame); - TableBackgroundPainter painter(rowFrame->GetTableFrame(), - TableBackgroundPainter::eOrigin_TableRow, - mFrame->PresContext(), *aCtx, - mVisibleRect, ToReferenceFrame(), - aBuilder->GetBackgroundPaintFlags()); - - DrawResult result = painter.PaintRow(rowFrame); - nsDisplayTableItemGeometry::UpdateDrawResult(this, result); -} - void nsTableRowFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, diff --git a/layout/tables/nsTableRowFrame.h b/layout/tables/nsTableRowFrame.h index a6aba81e7d..9e15d851fc 100644 --- a/layout/tables/nsTableRowFrame.h +++ b/layout/tables/nsTableRowFrame.h @@ -8,7 +8,6 @@ #include "mozilla/Attributes.h" #include "nscore.h" #include "nsContainerFrame.h" -#include "nsTablePainter.h" #include "nsTableRowGroupFrame.h" #include "mozilla/WritingModes.h" diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp index 943bdf50b8..3e4f60f624 100644 --- a/layout/tables/nsTableRowGroupFrame.cpp +++ b/layout/tables/nsTableRowGroupFrame.cpp @@ -154,46 +154,6 @@ nsTableRowGroupFrame::InitRepeatedFrame(nsTableRowGroupFrame* aHeaderFooterFrame return NS_OK; } -/** - * We need a custom display item for table row backgrounds. This is only used - * when the table row is the root of a stacking context (e.g., has 'opacity'). - * Table row backgrounds can extend beyond the row frame bounds, when - * the row contains row-spanning cells. - */ -class nsDisplayTableRowGroupBackground : public nsDisplayTableItem { -public: - nsDisplayTableRowGroupBackground(nsDisplayListBuilder* aBuilder, - nsTableRowGroupFrame* aFrame) : - nsDisplayTableItem(aBuilder, aFrame) { - MOZ_COUNT_CTOR(nsDisplayTableRowGroupBackground); - } -#ifdef NS_BUILD_REFCNT_LOGGING - virtual ~nsDisplayTableRowGroupBackground() { - MOZ_COUNT_DTOR(nsDisplayTableRowGroupBackground); - } -#endif - - virtual void Paint(nsDisplayListBuilder* aBuilder, - nsRenderingContext* aCtx) override; - - NS_DISPLAY_DECL_NAME("TableRowGroupBackground", TYPE_TABLE_ROW_GROUP_BACKGROUND) -}; - -void -nsDisplayTableRowGroupBackground::Paint(nsDisplayListBuilder* aBuilder, - nsRenderingContext* aCtx) -{ - auto rgFrame = static_cast(mFrame); - TableBackgroundPainter painter(rgFrame->GetTableFrame(), - TableBackgroundPainter::eOrigin_TableRowGroup, - mFrame->PresContext(), *aCtx, - mVisibleRect, ToReferenceFrame(), - aBuilder->GetBackgroundPaintFlags()); - - DrawResult result = painter.PaintRowGroup(rgFrame); - nsDisplayTableItemGeometry::UpdateDrawResult(this, result); -} - // Handle the child-traversal part of DisplayGenericTablePart static void DisplayRows(nsDisplayListBuilder* aBuilder, nsFrame* aFrame, diff --git a/layout/tables/nsTableRowGroupFrame.h b/layout/tables/nsTableRowGroupFrame.h index 7abdd4b74b..721d910465 100644 --- a/layout/tables/nsTableRowGroupFrame.h +++ b/layout/tables/nsTableRowGroupFrame.h @@ -10,7 +10,6 @@ #include "nsContainerFrame.h" #include "nsIAtom.h" #include "nsILineIterator.h" -#include "nsTablePainter.h" #include "nsTArray.h" #include "nsTableFrame.h" #include "mozilla/WritingModes.h" From c8aaad04285ba52c86f8c36a38d63883ccf8a391 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 15:12:34 +0100 Subject: [PATCH 03/10] Issue #146 - Part 3: Create nsDisplayTableFixedPosition to avoid display list collisions when processing the background image of a table. --- layout/base/nsDisplayList.cpp | 63 ++++++++++++++++++++++++++++++++-- layout/base/nsDisplayList.h | 45 ++++++++++++++++++++++-- layout/tables/nsTableFrame.cpp | 8 +++-- 3 files changed, 108 insertions(+), 8 deletions(-) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 744153831d..6b792a779c 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -80,6 +80,8 @@ #include "nsPluginFrame.h" #include "DisplayItemScrollClip.h" #include "nsSVGMaskFrame.h" +#include "nsTableCellFrame.h" +#include "nsTableColFrame.h" // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to // GetTickCount(). @@ -2632,7 +2634,8 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil nsDisplayList* aList, bool aAllowWillPaintBorderOptimization, nsStyleContext* aStyleContext, - const nsRect& aBackgroundOriginRect) + const nsRect& aBackgroundOriginRect, + nsIFrame* aSecondaryReferenceFrame) { nsStyleContext* bgSC = aStyleContext; const nsStyleBackground* bg = nullptr; @@ -2752,8 +2755,17 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bgOriginRect, bg); if (bgItem->ShouldFixToViewport(aBuilder)) { - thisItemList.AppendNewToTop( - nsDisplayFixedPosition::CreateForFixedBackground(aBuilder, aFrame, bgItem, i)); + if (aSecondaryReferenceFrame) { + thisItemList.AppendNewToTop( + nsDisplayTableFixedPosition::CreateForFixedBackground(aBuilder, + aSecondaryReferenceFrame, + bgItem, + i, + aFrame)); + } else { + thisItemList.AppendNewToTop( + nsDisplayFixedPosition::CreateForFixedBackground(aBuilder, aFrame, bgItem, i)); + } } else { thisItemList.AppendNewToTop(bgItem); } @@ -5277,6 +5289,51 @@ bool nsDisplayFixedPosition::TryMerge(nsDisplayItem* aItem) { return true; } +TableType +GetTableTypeFromFrame(nsIFrame* aFrame) +{ + nsIAtom* type = aFrame->GetType(); + if (type == nsGkAtoms::tableFrame) { + return TableType::TABLE; + } else if (type == nsGkAtoms::tableColFrame) { + return TableType::TABLE_COL; + } else if (type == nsGkAtoms::tableColGroupFrame) { + return TableType::TABLE_COL_GROUP; + } else if (type == nsGkAtoms::tableRowFrame) { + return TableType::TABLE_ROW; + } else if (type == nsGkAtoms::tableRowGroupFrame) { + return TableType::TABLE_ROW_GROUP; + } else if (type == nsGkAtoms::tableCellFrame) { + return TableType::TABLE_CELL; + } else { + MOZ_ASSERT_UNREACHABLE("Invalid frame."); + return TableType::TABLE; + } +} + +nsDisplayTableFixedPosition::nsDisplayTableFixedPosition(nsDisplayListBuilder* aBuilder, + nsIFrame* aFrame, + nsDisplayList* aList, + uint32_t aIndex, + nsIFrame* aAncestorFrame) + : nsDisplayFixedPosition(aBuilder, aFrame, aList, aIndex) + , mTableType(GetTableTypeFromFrame(aAncestorFrame)) +{ +} + +/* static */ nsDisplayTableFixedPosition* +nsDisplayTableFixedPosition::CreateForFixedBackground(nsDisplayListBuilder* aBuilder, + nsIFrame* aFrame, + nsDisplayBackgroundImage* aImage, + uint32_t aIndex, + nsIFrame* aAncestorFrame) +{ + nsDisplayList temp; + temp.AppendToTop(aImage); + + return new (aBuilder) nsDisplayTableFixedPosition(aBuilder, aFrame, &temp, aIndex + 1, aAncestorFrame); +} + nsDisplayStickyPosition::nsDisplayStickyPosition(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, nsDisplayList* aList) diff --git a/layout/base/nsDisplayList.h b/layout/base/nsDisplayList.h index 9431e2cc06..69d13ded99 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -2738,7 +2738,8 @@ public: nsDisplayList* aList, bool aAllowWillPaintBorderOptimization = true, nsStyleContext* aStyleContext = nullptr, - const nsRect& aBackgroundOriginRect = nsRect()); + const nsRect& aBackgroundOriginRect = nsRect(), + nsIFrame* aSecondaryReferenceFrame = nullptr); virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, LayerManager* aManager, @@ -2838,6 +2839,25 @@ protected: bool mShouldTreatAsFixed; }; +enum class TableType : uint8_t { + TABLE, + TABLE_COL, + TABLE_COL_GROUP, + TABLE_ROW, + TABLE_ROW_GROUP, + TABLE_CELL, + + TABLE_TYPE_MAX +}; + +enum class TableTypeBits : uint8_t { + COUNT = 3 +}; + +static_assert( + static_cast(TableType::TABLE_TYPE_MAX) < (1 << (static_cast(TableTypeBits::COUNT) + 1)), + "TableType cannot fit with TableTypeBits::COUNT"); +TableType GetTableTypeFromFrame(nsIFrame* aFrame); /** * A display item to paint the native theme background for a frame. @@ -3736,7 +3756,7 @@ public: return mAnimatedGeometryRootForScrollMetadata; } -private: +protected: // For background-attachment:fixed nsDisplayFixedPosition(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, nsDisplayList* aList, uint32_t aIndex); @@ -3747,6 +3767,27 @@ private: bool mIsFixedBackground; }; +class nsDisplayTableFixedPosition : public nsDisplayFixedPosition +{ +public: + static nsDisplayTableFixedPosition* CreateForFixedBackground(nsDisplayListBuilder* aBuilder, + nsIFrame* aFrame, + nsDisplayBackgroundImage* aImage, + uint32_t aIndex, + nsIFrame* aAncestorFrame); + + virtual uint32_t GetPerFrameKey() override { + return (mIndex << (nsDisplayItem::TYPE_BITS + static_cast(TableTypeBits::COUNT))) | + (static_cast(mTableType) << nsDisplayItem::TYPE_BITS) | + nsDisplayItem::GetPerFrameKey(); + } +protected: + nsDisplayTableFixedPosition(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, + nsDisplayList* aList, uint32_t aIndex, nsIFrame* aAncestorFrame); + + TableType mTableType; +}; + /** * This creates an empty scrollable layer. It has no child layers. * It is used to record the existence of a scrollable frame in the layer diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index 06a05292fd..890d050fdf 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -1194,13 +1194,14 @@ PaintRowBackground(nsTableRowFrame* aRow, const nsDisplayListSet& aLists, const nsPoint& aOffset = nsPoint()) { - // Compute background rect by iterating all cell frame. + // Compute background rect by iterating over all cell frames. for (nsTableCellFrame* cell = aRow->GetFirstCell(); cell; cell = cell->GetNextCell()) { auto cellRect = cell->GetRectRelativeToSelf() + cell->GetNormalPosition() + aOffset; nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, cellRect, aLists.BorderBackground(), true, nullptr, - aFrame->GetRectRelativeToSelf()); + aFrame->GetRectRelativeToSelf(), + cell); } } @@ -1232,7 +1233,8 @@ PaintRowGroupBackgroundByColIdx(nsTableRowGroupFrame* aRowGroup, nsDisplayBackgroundImage::AppendBackgroundItemsToTop(aBuilder, aFrame, cellRect, aLists.BorderBackground(), true, nullptr, - aFrame->GetRectRelativeToSelf()); + aFrame->GetRectRelativeToSelf(), + cell); } } } From a96ec7b886b0776229967a52d6996efa65ed9811 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 17:25:37 +0100 Subject: [PATCH 04/10] Issue #146 - Part 3: Create nsDisplayTableBackgroundImage to avoid display list collisions when processing the background image of a table. --- layout/base/nsDisplayList.cpp | 45 +++++++++++++++++++++++++++++------ layout/base/nsDisplayList.h | 37 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 6b792a779c..1579e69703 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -2751,9 +2751,19 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil } nsDisplayList thisItemList; - nsDisplayBackgroundImage* bgItem = - new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bgOriginRect, bg); - + nsDisplayBackgroundImage* bgItem; + if (aSecondaryReferenceFrame) { + bgItem = + new (aBuilder) nsDisplayTableBackgroundImage(aBuilder, + aFrame, + i, + bgOriginRect, + bg, + aSecondaryReferenceFrame); + } else { + bgItem = + new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bgOriginRect, bg); + } if (bgItem->ShouldFixToViewport(aBuilder)) { if (aSecondaryReferenceFrame) { thisItemList.AppendNewToTop( @@ -2906,7 +2916,7 @@ nsDisplayBackgroundImage::ImageLayerization nsDisplayBackgroundImage::ShouldCreateOwnLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager) { - nsIFrame* backgroundStyleFrame = nsCSSRendering::FindBackgroundStyleFrame(mFrame); + nsIFrame* backgroundStyleFrame = nsCSSRendering::FindBackgroundStyleFrame(StyleFrame()); if (ActiveLayerTracker::IsBackgroundPositionAnimated(aBuilder, backgroundStyleFrame)) { return WHENEVER_POSSIBLE; @@ -3161,16 +3171,16 @@ nsDisplayBackgroundImage::PaintInternal(nsDisplayListBuilder* aBuilder, StyleGeometryBox clip = mBackgroundStyle->mImage.mLayers[mLayer].mClip; if (clip == StyleGeometryBox::Text) { - if (!GenerateAndPushTextMask(mFrame, aCtx, mBackgroundRect, aBuilder)) { + if (!GenerateAndPushTextMask(StyleFrame(), aCtx, mBackgroundRect, aBuilder)) { return; } } nsCSSRendering::PaintBGParams params = - nsCSSRendering::PaintBGParams::ForSingleLayer(*mFrame->PresContext(), + nsCSSRendering::PaintBGParams::ForSingleLayer(*StyleFrame()->PresContext(), *aCtx, aBounds, mBackgroundRect, - mFrame, flags, mLayer, + StyleFrame(), flags, mLayer, CompositionOp::OP_OVER); params.bgClipRect = aClipRect; image::DrawResult result = @@ -3272,6 +3282,27 @@ nsDisplayBackgroundImage::GetPerFrameKey() nsDisplayItem::GetPerFrameKey(); } +nsDisplayTableBackgroundImage::nsDisplayTableBackgroundImage(nsDisplayListBuilder* aBuilder, + nsIFrame* aFrame, + uint32_t aLayer, + const nsRect& aBackgroundRect, + const nsStyleBackground* aBackgroundStyle, + nsIFrame* aCellFrame) + : nsDisplayBackgroundImage(aBuilder, aFrame, aLayer, aBackgroundRect, aBackgroundStyle) + , mStyleFrame(aFrame) + , mTableType(GetTableTypeFromFrame(mStyleFrame)) +{ + mFrame = aCellFrame; +} + +bool +nsDisplayTableBackgroundImage::IsInvalid(nsRect& aRect) +{ + bool result = mStyleFrame ? mStyleFrame->IsInvalid(aRect) : false; + aRect += ToReferenceFrame(); + return result; +} + nsDisplayThemedBackground::nsDisplayThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, const nsRect& aBackgroundRect) diff --git a/layout/base/nsDisplayList.h b/layout/base/nsDisplayList.h index 69d13ded99..e9047b1135 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -2814,6 +2814,8 @@ protected: void PaintInternal(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx, const nsRect& aBounds, nsRect* aClipRect); + virtual nsIFrame* StyleFrame() { return mFrame; } + // Determine whether we want to be separated into our own layer, independent // of whether this item can actually be layerized. enum ImageLayerization { @@ -2859,6 +2861,41 @@ static_assert( "TableType cannot fit with TableTypeBits::COUNT"); TableType GetTableTypeFromFrame(nsIFrame* aFrame); +/** + * A display item to paint background image for table. For table parts, such + * as row, row group, col, col group, when drawing its background, we'll + * create separate background image display item for its containning cell. + * Those background image display items will reference to same DisplayItemData + * if we keep the mFrame point to cell's ancestor frame. We don't want to this + * happened bacause share same DisplatItemData will cause many bugs. So that + * we let mFrame point to cell frame and store the table type of the ancestor + * frame. And use mFrame and table type as key to generate DisplayItemData to + * avoid sharing DisplayItemData. + * + * Also store ancestor frame as mStyleFrame for all rendering informations. + */ +class nsDisplayTableBackgroundImage : public nsDisplayBackgroundImage { +public: + nsDisplayTableBackgroundImage(nsDisplayListBuilder* aBuilder, + nsIFrame* aFrame, + uint32_t aLayer, + const nsRect& aBackgroundRect, + const nsStyleBackground* aBackgroundStyle, + nsIFrame* aCellFrame); + + virtual uint32_t GetPerFrameKey() override { + return (static_cast(mTableType) << nsDisplayItem::TYPE_BITS) | + nsDisplayItem::GetPerFrameKey(); + } + + virtual bool IsInvalid(nsRect& aRect) override; +protected: + virtual nsIFrame* StyleFrame() override { return mStyleFrame; } + + nsIFrame* mStyleFrame; + TableType mTableType; +}; + /** * A display item to paint the native theme background for a frame. */ From babd256e10fbfad7e608d89053f021baf1e3ff26 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 18:49:57 +0100 Subject: [PATCH 05/10] Issue #146 - Part 4: Adjust tests for fixes. This also adds a reftest for border radius on collapsed borders (should be ignored according to the CSS3 standard). We didn't do this before, except on internal elements. --- layout/reftests/table-background/reftest.list | 6 +++--- .../bc_borderradius-ref.html | 17 +++++++++++++++++ .../table-bordercollapse/bc_borderradius.html | 18 ++++++++++++++++++ .../reftests/table-bordercollapse/reftest.list | 4 +++- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 layout/reftests/table-bordercollapse/bc_borderradius-ref.html create mode 100644 layout/reftests/table-bordercollapse/bc_borderradius.html diff --git a/layout/reftests/table-background/reftest.list b/layout/reftests/table-background/reftest.list index eb2817ca09..68dc43e956 100644 --- a/layout/reftests/table-background/reftest.list +++ b/layout/reftests/table-background/reftest.list @@ -44,11 +44,11 @@ fuzzy-if(d2d,1,1083) fuzzy-if(skiaContent,1,2200) == border-collapse-opacity-tab fails == border-collapse-opacity-table-column-group.html border-collapse-opacity-table-column-group-ref.html # bug 424274 fails == border-collapse-opacity-table-column.html border-collapse-opacity-table-column-ref.html # bug 424274 fuzzy-if(d2d,1,16359) fuzzy-if(skiaContent,1,17000) == border-collapse-opacity-table-row-group.html border-collapse-opacity-table-row-group-ref.html -fuzzy-if(d2d,1,5453) fuzzy-if(skiaContent,1,11000) == border-collapse-opacity-table-row.html border-collapse-opacity-table-row-ref.html +fuzzy-if(d2d,1,11000) fuzzy-if(skiaContent,1,11000) == border-collapse-opacity-table-row.html border-collapse-opacity-table-row-ref.html fuzzy-if(d2d||skiaContent,1,60000) == border-collapse-opacity-table.html border-collapse-opacity-table-ref.html fuzzy-if(d2d,1,2478) fuzzy-if(skiaContent,1,2500) == border-separate-opacity-table-cell.html border-separate-opacity-table-cell-ref.html -fails == border-separate-opacity-table-column-group.html border-separate-opacity-table-column-group-ref.html # bug 424274 -fails == border-separate-opacity-table-column.html border-separate-opacity-table-column-ref.html # bug 424274 +fuzzy-if(d2d,1,38000) == border-separate-opacity-table-column-group.html border-separate-opacity-table-column-group-ref.html # bug 424274 +fuzzy-if(d2d,1,13000) == border-separate-opacity-table-column.html border-separate-opacity-table-column-ref.html # bug 424274 fuzzy-if(d2d,1,37170) fuzzy-if(skiaContent,1,38000) == border-separate-opacity-table-row-group.html border-separate-opacity-table-row-group-ref.html fuzzy-if(d2d,1,12390) fuzzy-if(skiaContent,1,13000) == border-separate-opacity-table-row.html border-separate-opacity-table-row-ref.html fuzzy-if(d2d||skiaContent,1,95000) == border-separate-opacity-table.html border-separate-opacity-table-ref.html diff --git a/layout/reftests/table-bordercollapse/bc_borderradius-ref.html b/layout/reftests/table-bordercollapse/bc_borderradius-ref.html new file mode 100644 index 0000000000..c7b041f79c --- /dev/null +++ b/layout/reftests/table-bordercollapse/bc_borderradius-ref.html @@ -0,0 +1,17 @@ + + + + + + +
diff --git a/layout/reftests/table-bordercollapse/bc_borderradius.html b/layout/reftests/table-bordercollapse/bc_borderradius.html new file mode 100644 index 0000000000..3ae2a89d8c --- /dev/null +++ b/layout/reftests/table-bordercollapse/bc_borderradius.html @@ -0,0 +1,18 @@ + + + + + + +
diff --git a/layout/reftests/table-bordercollapse/reftest.list b/layout/reftests/table-bordercollapse/reftest.list index 8356dc54b3..5ca6f305ab 100644 --- a/layout/reftests/table-bordercollapse/reftest.list +++ b/layout/reftests/table-bordercollapse/reftest.list @@ -20,6 +20,7 @@ == bc_dyn_table3.html bc_dyn_table3_ref.html == bc_borderoffset1.html bc_borderoffset1_ref.html == bc_borderoffset2.html bc_borderoffset2_ref.html +== bc_borderradius.html bc_borderradius-ref.html == frame_above_rules_all.html frame_above_rules_all_ref.html == frame_above_rules_cols.html frame_above_rules_cols_ref.html == frame_above_rules_groups.html frame_above_rules_groups_ref.html @@ -104,4 +105,5 @@ fuzzy(255,40) == border-style-outset-becomes-groove.html border-style-outset-bec # So get 40 pixels of fuzz, 20 at each beveled corner (because the border width # is 20px). fuzzy(255,40) == border-style-inset-becomes-ridge.html border-style-inset-becomes-ridge-ref.html -fuzzy(2,8301) == 1324524.html 1324524-ref.html +fuzzy(2,11000) == 1324524.html 1324524-ref.html + From af75c920b0ffb2a90c0ac768df32789e3cf32811 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 19:09:47 +0100 Subject: [PATCH 06/10] Issue #146 - Part 5: Treat table row groups as containing blocks. This aligns our behavior with Gecko/Blink. --- layout/generic/StickyScrollContainer.cpp | 8 ++++++++ layout/generic/nsFrame.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/layout/generic/StickyScrollContainer.cpp b/layout/generic/StickyScrollContainer.cpp index ca68992c36..ff8ebcfef3 100644 --- a/layout/generic/StickyScrollContainer.cpp +++ b/layout/generic/StickyScrollContainer.cpp @@ -176,6 +176,14 @@ StickyScrollContainer::ComputeStickyLimits(nsIFrame* aFrame, nsRect* aStick, nsRect rect = nsLayoutUtils::GetAllInFlowRectsUnion(aFrame, aFrame->GetParent()); + // Note: Table row groups aren't supposed to be containing blocks, but we treat + // them as such anyway. + // Not having this basically disables position:sticky on table cells, which + // would be really unfortunate, and doesn't match what other browsers do. + if (cbFrame != scrolledFrame && cbFrame->GetType() == nsGkAtoms::tableRowGroupFrame) { + cbFrame = cbFrame->GetContainingBlock(); + } + // Containing block limits for the position of aFrame relative to its parent. // The margin box of the sticky element stays within the content box of the // contaning-block element. diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index a531dea07f..d4bcf22edd 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -6629,6 +6629,9 @@ GetNearestBlockContainer(nsIFrame* frame) // Since the parent of such a block is either a normal block or // another such pseudo, this shouldn't cause anything bad to happen. // Also the anonymous blocks inside table cells are not containing blocks. + // + // If we ever start skipping table row groups from being containing blocks, + // we need to remove the containing block assignment in StickyScrollContainer . while (frame->IsFrameOfType(nsIFrame::eLineParticipant) || frame->IsBlockWrapper() || // Table rows are not containing blocks either From d26e13657b42119e456066d0de57c7b0a41155bc Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 19:43:51 +0100 Subject: [PATCH 07/10] Issue #146 - Part 6: Allow `position: sticky` on table elements. --- layout/base/RestyleManagerBase.cpp | 9 --------- layout/generic/StickyScrollContainer.cpp | 2 +- layout/generic/nsFrame.cpp | 5 +---- layout/tables/nsTableRowFrame.cpp | 11 +++++------ 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/layout/base/RestyleManagerBase.cpp b/layout/base/RestyleManagerBase.cpp index 6770f94642..6ef048a19e 100644 --- a/layout/base/RestyleManagerBase.cpp +++ b/layout/base/RestyleManagerBase.cpp @@ -474,15 +474,6 @@ RecomputePosition(nsIFrame* aFrame) if (display->IsRelativelyPositionedStyle()) { // Move the frame if (display->mPosition == NS_STYLE_POSITION_STICKY) { - if (display->IsInnerTableStyle()) { - // We don't currently support sticky positioning of inner table - // elements (bug 975644). Bail. - // - // When this is fixed, remove the null-check for the computed - // offsets in nsTableRowFrame::ReflowChildren. - return true; - } - // Update sticky positioning for an entire element at once, starting with // the first continuation or ib-split sibling. // It's rare that the frame we already have isn't already the first diff --git a/layout/generic/StickyScrollContainer.cpp b/layout/generic/StickyScrollContainer.cpp index ff8ebcfef3..c5ed44e927 100644 --- a/layout/generic/StickyScrollContainer.cpp +++ b/layout/generic/StickyScrollContainer.cpp @@ -45,7 +45,7 @@ StickyScrollContainer::GetStickyScrollContainerForFrame(nsIFrame* aFrame) // return nullptr; } - auto frame = static_cast(do_QueryFrame(scrollFrame)); + nsIFrame* frame = do_QueryFrame(scrollFrame); StickyScrollContainer* s = frame->GetProperty(StickyScrollContainerProperty()); if (!s) { diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index d4bcf22edd..bbbb5c3320 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -562,15 +562,12 @@ nsFrame::Init(nsIContent* aContent, } if (disp->mPosition == NS_STYLE_POSITION_STICKY && !aPrevInFlow && - !(mState & NS_FRAME_IS_NONDISPLAY) && - !disp->IsInnerTableStyle()) { + !(mState & NS_FRAME_IS_NONDISPLAY)) { // Note that we only add first continuations, but we really only // want to add first continuation-or-ib-split-siblings. But since we // don't yet know if we're a later part of a block-in-inline split, // we'll just add later members of a block-in-inline split here, and // then StickyScrollContainer will remove them later. - // We don't currently support relative positioning of inner table - // elements (bug 35168), so exclude them from sticky positioning too. StickyScrollContainer* ssc = StickyScrollContainer::GetStickyScrollContainerForFrame(this); if (ssc) { diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index 05b9deee9c..ea2477b730 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -926,12 +926,11 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, // be merged into the else below if we can.) nsMargin* computedOffsetProp = kidFrame->GetProperty(nsIFrame::ComputedOffsetProperty()); - // Bug 975644: a position:sticky kid can end up with a null - // property value here. - LogicalMargin computedOffsets(wm, computedOffsetProp ? - *computedOffsetProp : nsMargin()); - ReflowInput::ApplyRelativePositioning(kidFrame, wm, computedOffsets, - &kidPosition, containerSize); + + // On our fist reflow sticky children may not have the property yet (we + // need to reflow the children first to size the scroll frame). + LogicalMargin computedOffsets(wm, computedOffsetProp ? *computedOffsetProp : nsMargin()); + ReflowInput::ApplyRelativePositioning(kidFrame, wm, computedOffsets, &kidPosition, containerSize); } // In vertical-rl mode, we are likely to have containerSize.width = 0 From cfb46e368dfb67c329a86fd724e21d9e5498ee41 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 19:45:49 +0100 Subject: [PATCH 08/10] Issue #146 - Part 7: Remove no longer relevant reftest. --- .../position-sticky/inner-table-1-ref.html | 26 -------------- .../position-sticky/inner-table-1.html | 35 ------------------- layout/reftests/position-sticky/reftest.list | 1 - 3 files changed, 62 deletions(-) delete mode 100644 layout/reftests/position-sticky/inner-table-1-ref.html delete mode 100644 layout/reftests/position-sticky/inner-table-1.html diff --git a/layout/reftests/position-sticky/inner-table-1-ref.html b/layout/reftests/position-sticky/inner-table-1-ref.html deleted file mode 100644 index 379841fae7..0000000000 --- a/layout/reftests/position-sticky/inner-table-1-ref.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - -
a
b
c
d
- - diff --git a/layout/reftests/position-sticky/inner-table-1.html b/layout/reftests/position-sticky/inner-table-1.html deleted file mode 100644 index 212e658fd5..0000000000 --- a/layout/reftests/position-sticky/inner-table-1.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - CSS Test: Sticky Positioning - inner table elements - - - - - - - - - - - - - - - - - - - - - -
a
b
c
d
- - diff --git a/layout/reftests/position-sticky/reftest.list b/layout/reftests/position-sticky/reftest.list index 2705d08fd2..01e7b16389 100644 --- a/layout/reftests/position-sticky/reftest.list +++ b/layout/reftests/position-sticky/reftest.list @@ -48,4 +48,3 @@ fails == column-contain-1a.html column-contain-1-ref.html fuzzy-if(skiaContent,1,22) fuzzy-if(winWidget&&!layersGPUAccelerated,116,1320) fuzzy-if(Android,8,1533) == block-in-inline-2.html block-in-inline-2-ref.html fuzzy-if(Android,8,630) fuzzy-if(OSX>=1008,1,11) fuzzy-if(skiaContent,1,220) fuzzy-if(winWidget&&!layersGPUAccelerated,116,1320) == block-in-inline-3.html block-in-inline-3-ref.html == block-in-inline-continuations.html block-in-inline-continuations-ref.html -fuzzy-if(winWidget&&!layersGPUAccelerated,140,140) == inner-table-1.html inner-table-1-ref.html From 7e9d02223c74b509e638786c56b9cf4399179447 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 3 Nov 2019 22:36:56 +0100 Subject: [PATCH 09/10] Bump Goanna version. --- config/milestone.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/milestone.txt b/config/milestone.txt index 67b4fdd4e1..210727cac2 100644 --- a/config/milestone.txt +++ b/config/milestone.txt @@ -10,4 +10,4 @@ # hardcoded milestones in the tree from these two files. #-------------------------------------------------------- -4.4.1 \ No newline at end of file +4.4.2 \ No newline at end of file From c7212a0d1a2b810491f5ff7cac4723eeab78e549 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 4 Nov 2019 11:40:18 +0000 Subject: [PATCH 10/10] Issue #1252 - Remove fragile fast path. This resolves #1252. --- application/basilisk/base/content/tabbrowser.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/application/basilisk/base/content/tabbrowser.xml b/application/basilisk/base/content/tabbrowser.xml index b0958370be..02bccc477c 100644 --- a/application/basilisk/base/content/tabbrowser.xml +++ b/application/basilisk/base/content/tabbrowser.xml @@ -383,17 +383,6 @@