diff options
Diffstat (limited to 'layout/base')
-rw-r--r-- | layout/base/RestyleManagerBase.cpp | 9 | ||||
-rw-r--r-- | layout/base/nsDisplayItemTypesList.h | 4 | ||||
-rw-r--r-- | layout/base/nsDisplayList.cpp | 113 | ||||
-rw-r--r-- | layout/base/nsDisplayList.h | 83 |
4 files changed, 185 insertions, 24 deletions
diff --git a/layout/base/RestyleManagerBase.cpp b/layout/base/RestyleManagerBase.cpp index 6770f9464..6ef048a19 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/base/nsDisplayItemTypesList.h b/layout/base/nsDisplayItemTypesList.h index 9865395a7..cf809817f 100644 --- a/layout/base/nsDisplayItemTypesList.h +++ b/layout/base/nsDisplayItemTypesList.h @@ -56,9 +56,7 @@ 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) DECLARE_DISPLAY_ITEM_TYPE_FLAGS(TRANSFORM,TYPE_RENDERS_NO_IMAGES) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index e22230b41..1579e6970 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(). @@ -2631,11 +2633,17 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil const nsRect& aBackgroundRect, nsDisplayList* aList, bool aAllowWillPaintBorderOptimization, - nsStyleContext* aStyleContext) + nsStyleContext* aStyleContext, + const nsRect& aBackgroundOriginRect, + nsIFrame* aSecondaryReferenceFrame) { 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) { @@ -2743,12 +2751,31 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil } nsDisplayList thisItemList; - nsDisplayBackgroundImage* bgItem = - new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bgRect, 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)) { - 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); } @@ -2889,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; @@ -3144,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 = @@ -3255,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) @@ -5272,6 +5320,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 c81d34fac..e9047b113 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -2737,7 +2737,9 @@ public: const nsRect& aBackgroundRect, nsDisplayList* aList, bool aAllowWillPaintBorderOptimization = true, - nsStyleContext* aStyleContext = nullptr); + nsStyleContext* aStyleContext = nullptr, + const nsRect& aBackgroundOriginRect = nsRect(), + nsIFrame* aSecondaryReferenceFrame = nullptr); virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder, LayerManager* aManager, @@ -2812,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 { @@ -2837,6 +2841,60 @@ 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<uint8_t>(TableType::TABLE_TYPE_MAX) < (1 << (static_cast<uint8_t>(TableTypeBits::COUNT) + 1)), + "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<uint8_t>(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. @@ -3735,7 +3793,7 @@ public: return mAnimatedGeometryRootForScrollMetadata; } -private: +protected: // For background-attachment:fixed nsDisplayFixedPosition(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, nsDisplayList* aList, uint32_t aIndex); @@ -3746,6 +3804,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<uint8_t>(TableTypeBits::COUNT))) | + (static_cast<uint8_t>(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 |