summaryrefslogtreecommitdiff
path: root/layout/tables/nsTableFrame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'layout/tables/nsTableFrame.cpp')
-rw-r--r--layout/tables/nsTableFrame.cpp322
1 files changed, 132 insertions, 190 deletions
diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp
index 272a77406..890d050fd 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"
@@ -1131,67 +1130,40 @@ nsDisplayTableItem::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
}
-class nsDisplayTableBorderBackground : public nsDisplayTableItem {
+// A display item that draws all collapsed borders for a table.
+class nsDisplayTableBorderCollapse : public nsDisplayTableItem {
public:
- nsDisplayTableBorderBackground(nsDisplayListBuilder* aBuilder,
- nsTableFrame* aFrame,
- bool aDrawsBackground) :
- nsDisplayTableItem(aBuilder, aFrame, aDrawsBackground) {
- MOZ_COUNT_CTOR(nsDisplayTableBorderBackground);
- }
+ nsDisplayTableBorderCollapse(nsDisplayListBuilder* aBuilder,
+ nsTableFrame* aFrame)
+ : nsDisplayTableItem(aBuilder, aFrame) {
+ MOZ_COUNT_CTOR(nsDisplayTableBorderCollapse);
+ }
#ifdef NS_BUILD_REFCNT_LOGGING
- virtual ~nsDisplayTableBorderBackground() {
- MOZ_COUNT_DTOR(nsDisplayTableBorderBackground);
+ virtual ~nsDisplayTableBorderCollapse() {
+ MOZ_COUNT_DTOR(nsDisplayTableBorderCollapse);
}
#endif
virtual void Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx) override;
- NS_DISPLAY_DECL_NAME("TableBorderBackground", TYPE_TABLE_BORDER_BACKGROUND)
+ NS_DISPLAY_DECL_NAME("TableBorderCollapse", TYPE_TABLE_BORDER_COLLAPSE)
};
-#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)
+nsDisplayTableBorderCollapse::Paint(nsDisplayListBuilder* aBuilder,
+ nsRenderingContext* aCtx)
{
- DrawResult result = static_cast<nsTableFrame*>(mFrame)->
- PaintTableBorderBackground(aBuilder, *aCtx, mVisibleRect,
- ToReferenceFrame());
+ nsPoint pt = ToReferenceFrame();
+ DrawTarget* drawTarget = aCtx->GetDrawTarget();
- nsDisplayTableItemGeometry::UpdateDrawResult(this, result);
-}
+ gfxPoint devPixelOffset =
+ nsLayoutUtils::PointToGfxPoint(pt, mFrame->PresContext()->AppUnitsPerDevPixel());
-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;
-}
+ AutoRestoreTransform autoRestoreTransform(drawTarget);
+ drawTarget->SetTransform(
+ drawTarget->GetTransform().PreTranslate(ToPoint(devPixelOffset)));
-static bool CompareByTablePartRank(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
- void* aClosure)
-{
- return GetTablePartRank(aItem1) <= GetTablePartRank(aItem2);
+ static_cast<nsTableFrame*>(mFrame)->PaintBCBorders(*drawTarget, mVisibleRect - pt);
}
/* static */ void
@@ -1206,31 +1178,75 @@ 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 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(),
+ cell);
+ }
+}
+
+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<int32_t>& 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(),
+ cell);
+ }
+ }
+ }
+}
+
/* 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 +1258,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<nsTableRowGroupFrame*>(aFrame);
+ PaintRowGroupBackground(rowGroup, aFrame, aBuilder, aLists);
+ } else if (aFrame->GetType() == nsGkAtoms::tableRowFrame) {
+ nsTableRowFrame* row = static_cast<nsTableRowFrame*>(aFrame);
+ PaintRowBackground(row, aFrame, aBuilder, aLists);
+ } else if (aFrame->GetType() == nsGkAtoms::tableColGroupFrame) {
+ // Compute background rect by iterating all cell frame.
+ nsTableColGroupFrame* colGroup = static_cast<nsTableColGroupFrame*>(aFrame);
+ // Collecting column index.
+ AutoTArray<int32_t, 1> 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<nsTableColFrame*>(aFrame);
+ AutoTArray<int32_t, 1> 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<nsTableFrame*>(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<nsTableColGroupFrame*>(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 +1340,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
@@ -1359,59 +1354,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
{