Bug 686281 - Implement nsStyleImageLayers; r=dbaron

This commit is contained in:
CJKu
2016-01-28 06:24:00 +01:00
parent c92508f304
commit d5371994d3
17 changed files with 447 additions and 395 deletions

View File

@@ -1005,7 +1005,7 @@ nsCSSRendering::PaintFocus(nsPresContext* aPresContext,
* that function, except they're for a single coordinate / a single size
* dimension. (so, x/width vs. y/height)
*/
typedef nsStyleBackground::Position::PositionCoord PositionCoord;
typedef nsStyleImageLayers::Position::PositionCoord PositionCoord;
static void
ComputeObjectAnchorCoord(const PositionCoord& aCoord,
const nscoord aOriginBounds,
@@ -1029,7 +1029,7 @@ ComputeObjectAnchorCoord(const PositionCoord& aCoord,
void
nsImageRenderer::ComputeObjectAnchorPoint(
const nsStyleBackground::Position& aPos,
const nsStyleImageLayers::Position& aPos,
const nsSize& aOriginBounds,
const nsSize& aImageSize,
nsPoint* aTopLeft,
@@ -1749,7 +1749,7 @@ SetupDirtyRects(const nsRect& aBGClipArea, const nsRect& aCallerDirtyRect,
}
/* static */ void
nsCSSRendering::GetBackgroundClip(const nsStyleBackground::Layer& aLayer,
nsCSSRendering::GetBackgroundClip(const nsStyleImageLayers::Layer& aLayer,
nsIFrame* aForFrame, const nsStyleBorder& aBorder,
const nsRect& aBorderArea, const nsRect& aCallerDirtyRect,
bool aWillPaintBorder, nscoord aAppUnitsPerPixel,
@@ -2901,9 +2901,9 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
drawBackgroundImage,
drawBackgroundColor);
const nsStyleImageLayers& layers = aBackgroundSC->StyleBackground()->mLayers;
// If we're drawing a specific layer, we don't want to draw the
// background color.
const nsStyleBackground *bg = aBackgroundSC->StyleBackground();
if (drawBackgroundColor && aLayer >= 0) {
drawBackgroundColor = false;
}
@@ -2938,7 +2938,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
SetupDirtyRects(clipState.mBGClipArea, aDirtyRect, appUnitsPerPixel,
&clipState.mDirtyRect, &clipState.mDirtyRectGfx);
} else {
GetBackgroundClip(bg->BottomLayer(),
GetBackgroundClip(layers.BottomLayer(),
aForFrame, aBorder, aBorderArea,
aDirtyRect, (aFlags & PAINTBG_WILL_PAINT_BORDER), appUnitsPerPixel,
&clipState);
@@ -2962,7 +2962,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
return DrawResult::SUCCESS;
}
if (bg->mImageCount < 1) {
if (layers.mImageCount < 1) {
// Return if there are no background layers, all work from this point
// onwards happens iteratively on these.
return DrawResult::SUCCESS;
@@ -2972,16 +2972,16 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
int32_t startLayer = aLayer;
int32_t nLayers = 1;
if (startLayer < 0) {
startLayer = (int32_t)bg->mImageCount - 1;
nLayers = bg->mImageCount;
startLayer = (int32_t)layers.mImageCount - 1;
nLayers = layers.mImageCount;
}
// Ensure we get invalidated for loads of the image. We need to do
// this here because this might be the only code that knows about the
// association of the style data with the frame.
if (aBackgroundSC != aForFrame->StyleContext()) {
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, bg, startLayer, nLayers) {
aForFrame->AssociateImage(bg->mLayers[i].mImage, aPresContext);
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, layers, startLayer, nLayers) {
aForFrame->AssociateImage(layers.mLayers[i].mImage, aPresContext);
}
}
@@ -2994,10 +2994,10 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
if (drawBackgroundImage) {
bool clipSet = false;
uint8_t currentBackgroundClip = NS_STYLE_BG_CLIP_BORDER;
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, bg, bg->mImageCount - 1,
nLayers + (bg->mImageCount -
startLayer - 1)) {
const nsStyleBackground::Layer &layer = bg->mLayers[i];
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(i, layers, layers.mImageCount - 1,
nLayers + (layers.mImageCount -
startLayer - 1)) {
const nsStyleImageLayers::Layer& layer = layers.mLayers[i];
if (!aBGClipRect) {
if (currentBackgroundClip != layer.mClip || !clipSet) {
currentBackgroundClip = layer.mClip;
@@ -3069,7 +3069,7 @@ nsRect
nsCSSRendering::ComputeBackgroundPositioningArea(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsRect& aBorderArea,
const nsStyleBackground::Layer& aLayer,
const nsStyleImageLayers::Layer& aLayer,
nsIFrame** aAttachedToFrame)
{
// Compute background origin area relative to aBorderArea now as we may need
@@ -3174,13 +3174,13 @@ nsCSSRendering::ComputeBackgroundPositioningArea(nsPresContext* aPresContext,
static nsSize
ComputeDrawnSizeForBackground(const CSSSizeOrRatio& aIntrinsicSize,
const nsSize& aBgPositioningArea,
const nsStyleBackground::Size& aLayerSize)
const nsStyleImageLayers::Size& aLayerSize)
{
// Size is dictated by cover or contain rules.
if (aLayerSize.mWidthType == nsStyleBackground::Size::eContain ||
aLayerSize.mWidthType == nsStyleBackground::Size::eCover) {
if (aLayerSize.mWidthType == nsStyleImageLayers::Size::eContain ||
aLayerSize.mWidthType == nsStyleImageLayers::Size::eCover) {
nsImageRenderer::FitType fitType =
aLayerSize.mWidthType == nsStyleBackground::Size::eCover
aLayerSize.mWidthType == nsStyleImageLayers::Size::eCover
? nsImageRenderer::COVER
: nsImageRenderer::CONTAIN;
return nsImageRenderer::ComputeConstrainedSize(aBgPositioningArea,
@@ -3190,11 +3190,11 @@ ComputeDrawnSizeForBackground(const CSSSizeOrRatio& aIntrinsicSize,
// No cover/contain constraint, use default algorithm.
CSSSizeOrRatio specifiedSize;
if (aLayerSize.mWidthType == nsStyleBackground::Size::eLengthPercentage) {
if (aLayerSize.mWidthType == nsStyleImageLayers::Size::eLengthPercentage) {
specifiedSize.SetWidth(
aLayerSize.ResolveWidthLengthPercentage(aBgPositioningArea));
}
if (aLayerSize.mHeightType == nsStyleBackground::Size::eLengthPercentage) {
if (aLayerSize.mHeightType == nsStyleImageLayers::Size::eLengthPercentage) {
specifiedSize.SetHeight(
aLayerSize.ResolveHeightLengthPercentage(aBgPositioningArea));
}
@@ -3210,7 +3210,7 @@ nsCSSRendering::PrepareBackgroundLayer(nsPresContext* aPresContext,
uint32_t aFlags,
const nsRect& aBorderArea,
const nsRect& aBGClipRect,
const nsStyleBackground::Layer& aLayer)
const nsStyleImageLayers::Layer& aLayer)
{
/*
* The properties we need to keep in mind when drawing background
@@ -3374,7 +3374,7 @@ nsCSSRendering::GetBackgroundLayerRect(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsRect& aBorderArea,
const nsRect& aClipRect,
const nsStyleBackground::Layer& aLayer,
const nsStyleImageLayers::Layer& aLayer,
uint32_t aFlags)
{
Sides skipSides = aForFrame->GetSkipSides();
@@ -4862,7 +4862,7 @@ nsImageRenderer::ComputeIntrinsicSize()
// and that element's ratio, if it matches. If it doesn't match, it
// should have no width/height or ratio. See element() in CSS images:
// <http://dev.w3.org/csswg/css-images-4/#element-notation>.
// Make sure to change nsStyleBackground::Size::DependsOnFrameSize
// Make sure to change nsStyleImageLayers::Size::DependsOnFrameSize
// when fixing this!
if (mPaintServerFrame) {
// SVG images have no intrinsic size

View File

@@ -175,7 +175,7 @@ public:
*
* Points are returned relative to aOriginBounds.
*/
static void ComputeObjectAnchorPoint(const nsStyleBackground::Position& aPos,
static void ComputeObjectAnchorPoint(const nsStyleImageLayers::Position& aPos,
const nsSize& aOriginBounds,
const nsSize& aImageSize,
nsPoint* aTopLeft,
@@ -535,7 +535,7 @@ struct nsCSSRendering {
ComputeBackgroundPositioningArea(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsRect& aBorderArea,
const nsStyleBackground::Layer& aLayer,
const nsStyleImageLayers::Layer& aLayer,
nsIFrame** aAttachedToFrame);
static nsBackgroundLayerState
@@ -544,7 +544,7 @@ struct nsCSSRendering {
uint32_t aFlags,
const nsRect& aBorderArea,
const nsRect& aBGClipRect,
const nsStyleBackground::Layer& aLayer);
const nsStyleImageLayers::Layer& aLayer);
struct BackgroundClipState {
nsRect mBGClipArea; // Affected by mClippedRadii
@@ -563,7 +563,7 @@ struct nsCSSRendering {
};
static void
GetBackgroundClip(const nsStyleBackground::Layer& aLayer,
GetBackgroundClip(const nsStyleImageLayers::Layer& aLayer,
nsIFrame* aForFrame, const nsStyleBorder& aBorder, const nsRect& aBorderArea,
const nsRect& aCallerDirtyRect, bool aWillPaintBorder,
nscoord aAppUnitsPerPixel,
@@ -627,7 +627,7 @@ struct nsCSSRendering {
nsIFrame* aForFrame,
const nsRect& aBorderArea,
const nsRect& aClipRect,
const nsStyleBackground::Layer& aLayer,
const nsStyleImageLayers::Layer& aLayer,
uint32_t aFlags);
/**

View File

@@ -2270,7 +2270,7 @@ nsDisplayBackgroundImage::GetDestAreaInternal(nsDisplayListBuilder* aBuilder)
nsPresContext* presContext = mFrame->PresContext();
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer& layer = mBackgroundStyle->mLayers.mLayers[mLayer];
nsBackgroundLayerState state =
nsCSSRendering::PrepareBackgroundLayer(presContext, mFrame, flags,
@@ -2311,7 +2311,7 @@ static nsStyleContext* GetBackgroundStyleContext(nsIFrame* aFrame)
/* static */ void
SetBackgroundClipRegion(DisplayListClipState::AutoSaveRestore& aClipState,
nsIFrame* aFrame, const nsPoint& aToReferenceFrame,
const nsStyleBackground::Layer& aLayer,
const nsStyleImageLayers::Layer& aLayer,
bool aWillPaintBorder)
{
nsRect borderBox = nsRect(aToReferenceFrame, aFrame->GetSize());
@@ -2417,18 +2417,18 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil
// Passing bg == nullptr in this macro will result in one iteration with
// i = 0.
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
if (bg->mLayers[i].mImage.IsEmpty()) {
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, bg->mLayers) {
if (bg->mLayers.mLayers[i].mImage.IsEmpty()) {
continue;
}
if (bg->mLayers[i].mBlendMode != NS_STYLE_BLEND_NORMAL) {
if (bg->mLayers.mLayers[i].mBlendMode != NS_STYLE_BLEND_NORMAL) {
needBlendContainer = true;
}
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
if (!aBuilder->IsForEventDelivery()) {
const nsStyleBackground::Layer& layer = bg->mLayers[i];
const nsStyleImageLayers::Layer& layer = bg->mLayers.mLayers[i];
SetBackgroundClipRegion(clipState, aFrame, toRef,
layer, willPaintBorder);
}
@@ -2492,13 +2492,13 @@ nsDisplayBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuil
if (!mBackgroundStyle)
return false;
if (mBackgroundStyle->mLayers.Length() != 1)
if (mBackgroundStyle->mLayers.mLayers.Length() != 1)
return false;
nsPresContext* presContext = mFrame->PresContext();
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mLayers.mLayers[mLayer];
if (layer.mAttachment != NS_STYLE_BG_ATTACHMENT_FIXED)
return false;
@@ -2520,8 +2520,8 @@ nsDisplayBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuil
bool
nsDisplayBackgroundImage::IsNonEmptyFixedImage() const
{
return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
!mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
return mBackgroundStyle->mLayers.mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
!mBackgroundStyle->mLayers.mLayers[mLayer].mImage.IsEmpty();
}
bool
@@ -2550,7 +2550,7 @@ nsDisplayBackgroundImage::CanOptimizeToImageLayer(LayerManager* aManager,
nsPresContext* presContext = mFrame->PresContext();
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mLayers.mLayers[mLayer];
nsBackgroundLayerState state =
nsCSSRendering::PrepareBackgroundLayer(presContext, mFrame, flags,
@@ -2574,8 +2574,8 @@ nsDisplayBackgroundImage::CanOptimizeToImageLayer(LayerManager* aManager,
// For 'contain' and 'cover', we allow any pixel of the image to be sampled
// because there isn't going to be any spriting/atlasing going on.
bool allowPartialImages =
(layer.mSize.mWidthType == nsStyleBackground::Size::eContain ||
layer.mSize.mWidthType == nsStyleBackground::Size::eCover);
(layer.mSize.mWidthType == nsStyleImageLayers::Size::eContain ||
layer.mSize.mWidthType == nsStyleImageLayers::Size::eCover);
if (!allowPartialImages && !state.mFillArea.Contains(state.mDestArea)) {
return false;
}
@@ -2629,7 +2629,7 @@ nsDisplayBackgroundImage::ShouldCreateOwnLayer(nsDisplayListBuilder* aBuilder,
}
if (nsLayoutUtils::AnimatedImageLayersEnabled() && mBackgroundStyle) {
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mLayers.mLayers[mLayer];
const nsStyleImage* image = &layer.mImage;
if (image->GetType() == eStyleImageType_Image) {
imgIRequest* imgreq = image->GetImageData();
@@ -2825,7 +2825,7 @@ nsDisplayBackgroundImage::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
if (mFrame->StyleBorder()->mBoxDecorationBreak ==
NS_STYLE_BOX_DECORATION_BREAK_CLONE ||
(!mFrame->GetPrevContinuation() && !mFrame->GetNextContinuation())) {
const nsStyleBackground::Layer& layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer& layer = mBackgroundStyle->mLayers.mLayers[mLayer];
if (layer.mImage.IsOpaque() && layer.mBlendMode == NS_STYLE_BLEND_NORMAL) {
result = GetInsideClipRegion(this, layer.mClip, mBounds);
}
@@ -2853,7 +2853,7 @@ nsDisplayBackgroundImage::GetPositioningArea()
return nsCSSRendering::ComputeBackgroundPositioningArea(
mFrame->PresContext(), mFrame,
nsRect(ToReferenceFrame(), mFrame->GetSize()),
mBackgroundStyle->mLayers[mLayer],
mBackgroundStyle->mLayers.mLayers[mLayer],
&attachedToFrame) + ToReferenceFrame();
}
@@ -2870,7 +2870,7 @@ nsDisplayBackgroundImage::RenderingMightDependOnPositioningAreaSizeChange()
return true;
}
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mLayers.mLayers[mLayer];
if (layer.RenderingMightDependOnPositioningAreaSizeChange()) {
return true;
}
@@ -2946,7 +2946,7 @@ void nsDisplayBackgroundImage::ComputeInvalidationRegion(nsDisplayListBuilder* a
return;
}
if (aBuilder->ShouldSyncDecodeImages()) {
const nsStyleImage& image = mBackgroundStyle->mLayers[mLayer].mImage;
const nsStyleImage& image = mBackgroundStyle->mLayers.mLayers[mLayer].mImage;
if (image.GetType() == eStyleImageType_Image &&
geometry->ShouldInvalidateToSyncDecodeImages()) {
aInvalidRegion->Or(*aInvalidRegion, bounds);
@@ -2992,7 +2992,7 @@ nsDisplayBackgroundImage::GetBoundsInternal(nsDisplayListBuilder* aBuilder) {
clipRect = clipRect.Union(rootRect + aBuilder->ToReferenceFrame(mFrame));
}
}
const nsStyleBackground::Layer& layer = mBackgroundStyle->mLayers[mLayer];
const nsStyleImageLayers::Layer& layer = mBackgroundStyle->mLayers.mLayers[mLayer];
return nsCSSRendering::GetBackgroundLayerRect(presContext, mFrame,
borderBox, clipRect, layer,
aBuilder->GetBackgroundPaintFlags());
@@ -3240,7 +3240,7 @@ nsDisplayBackgroundColor::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
*aSnap = true;
const nsStyleBackground::Layer& bottomLayer = mBackgroundStyle->BottomLayer();
const nsStyleImageLayers::Layer& bottomLayer = mBackgroundStyle->BottomLayer();
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
return nsDisplayBackgroundImage::GetInsideClipRegion(this, bottomLayer.mClip,
borderBox);

View File

@@ -3953,7 +3953,7 @@ ComputeConcreteObjectSize(const nsSize& aConstraintSize,
// (Helper for HasInitialObjectFitAndPosition, to check
// each "object-position" coord.)
typedef nsStyleBackground::Position::PositionCoord PositionCoord;
typedef nsStyleImageLayers::Position::PositionCoord PositionCoord;
static bool
IsCoord50Pct(const PositionCoord& aCoord)
{
@@ -3967,7 +3967,7 @@ IsCoord50Pct(const PositionCoord& aCoord)
static bool
HasInitialObjectFitAndPosition(const nsStylePosition* aStylePos)
{
const nsStyleBackground::Position& objectPos = aStylePos->mObjectPosition;
const nsStyleImageLayers::Position& objectPos = aStylePos->mObjectPosition;
return aStylePos->mObjectFit == NS_STYLE_OBJECT_FIT_FILL &&
IsCoord50Pct(objectPos.mXPosition) &&

View File

@@ -410,11 +410,12 @@ nsCanvasFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
bool needBlendContainer = false;
// Create separate items for each background layer.
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
if (bg->mLayers[i].mImage.IsEmpty()) {
const nsStyleImageLayers& layers = bg->mLayers;
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, layers) {
if (layers.mLayers[i].mImage.IsEmpty()) {
continue;
}
if (bg->mLayers[i].mBlendMode != NS_STYLE_BLEND_NORMAL) {
if (layers.mLayers[i].mBlendMode != NS_STYLE_BLEND_NORMAL) {
needBlendContainer = true;
}
nsDisplayCanvasBackgroundImage* bgItem =

View File

@@ -220,8 +220,8 @@ public:
// compositing layer. Since we know their background painting area can't
// change (unless the viewport size itself changes), async scrolling
// will work well.
return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
!mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
return mBackgroundStyle->mLayers.mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
!mBackgroundStyle->mLayers.mLayers[mLayer].mImage.IsEmpty();
}
// We still need to paint a background color as well as an image for this item,

View File

@@ -770,12 +770,14 @@ nsFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
aOldStyleContext->StyleBackground() :
nullptr;
const nsStyleBackground *newBG = StyleBackground();
const nsStyleImageLayers& oldBGLayers = oldBG->mLayers;
const nsStyleImageLayers& newBGLayers = newBG->mLayers;
if (oldBG) {
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, oldBG) {
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, oldBGLayers) {
// If there is an image in oldBG that's not in newBG, drop it.
if (i >= newBG->mImageCount ||
!oldBG->mLayers[i].mImage.ImageDataEquals(newBG->mLayers[i].mImage)) {
const nsStyleImage& oldImage = oldBG->mLayers[i].mImage;
if (i >= newBGLayers.mImageCount ||
!oldBGLayers.mLayers[i].mImage.ImageDataEquals(newBGLayers.mLayers[i].mImage)) {
const nsStyleImage& oldImage = oldBGLayers.mLayers[i].mImage;
if (oldImage.GetType() != eStyleImageType_Image) {
continue;
}
@@ -786,11 +788,11 @@ nsFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
}
}
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, newBG) {
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, newBGLayers) {
// If there is an image in newBG that's not in oldBG, add it.
if (!oldBG || i >= oldBG->mImageCount ||
!newBG->mLayers[i].mImage.ImageDataEquals(oldBG->mLayers[i].mImage)) {
const nsStyleImage& newImage = newBG->mLayers[i].mImage;
if (!oldBG || i >= oldBGLayers.mImageCount ||
!newBGLayers.mLayers[i].mImage.ImageDataEquals(oldBGLayers.mLayers[i].mImage)) {
const nsStyleImage& newImage = newBGLayers.mLayers[i].mImage;
if (newImage.GetType() != eStyleImageType_Image) {
continue;
}

View File

@@ -5769,7 +5769,7 @@ ScrollSnapHelper(SnappingEdgeCallback& aCallback, nsIFrame* aFrame,
nsPoint offset = f->GetOffsetTo(aScrolledFrame);
nsRect edgesRect = nsRect(offset, frameRect.Size());
for (size_t coordNum = 0; coordNum < coordCount; coordNum++) {
const nsStyleBackground::Position &coordPosition =
const nsStyleImageLayers::Position &coordPosition =
f->StyleDisplay()->mScrollSnapCoordinate[coordNum];
nsPoint coordPoint = edgesRect.TopLeft() - aScrollSnapDestination;
coordPoint += nsPoint(coordPosition.mXPosition.mLength,

View File

@@ -2923,7 +2923,7 @@ StyleCoordToCSSValue(const nsStyleCoord& aCoord, nsCSSValue& aCSSValue)
}
static void
SetPositionValue(const nsStyleBackground::Position& aPos, nsCSSValue& aCSSValue)
SetPositionValue(const nsStyleImageLayers::Position& aPos, nsCSSValue& aCSSValue)
{
RefPtr<nsCSSValue::Array> posArray = nsCSSValue::Array::Create(4);
aCSSValue.SetArrayValue(posArray.get(), eCSSUnit_Array);
@@ -3292,12 +3292,12 @@ StyleAnimationValue::ExtractComputedValue(nsCSSProperty aProperty,
static_cast<const nsStyleBackground*>(styleStruct);
nsAutoPtr<nsCSSValueList> result;
nsCSSValueList **resultTail = getter_Transfers(result);
MOZ_ASSERT(bg->mPositionCount > 0, "unexpected count");
for (uint32_t i = 0, i_end = bg->mPositionCount; i != i_end; ++i) {
MOZ_ASSERT(bg->mLayers.mPositionCount > 0, "unexpected count");
for (uint32_t i = 0, i_end = bg->mLayers.mPositionCount; i != i_end; ++i) {
nsCSSValueList *item = new nsCSSValueList;
*resultTail = item;
resultTail = &item->mNext;
SetPositionValue(bg->mLayers[i].mPosition, item->mValue);
SetPositionValue(bg->mLayers.mLayers[i].mPosition, item->mValue);
}
aComputedValue.SetAndAdoptCSSValueListValue(result.forget(),
@@ -3310,23 +3310,23 @@ StyleAnimationValue::ExtractComputedValue(nsCSSProperty aProperty,
static_cast<const nsStyleBackground*>(styleStruct);
nsAutoPtr<nsCSSValuePairList> result;
nsCSSValuePairList **resultTail = getter_Transfers(result);
MOZ_ASSERT(bg->mSizeCount > 0, "unexpected count");
for (uint32_t i = 0, i_end = bg->mSizeCount; i != i_end; ++i) {
MOZ_ASSERT(bg->mLayers.mSizeCount > 0, "unexpected count");
for (uint32_t i = 0, i_end = bg->mLayers.mSizeCount; i != i_end; ++i) {
nsCSSValuePairList *item = new nsCSSValuePairList;
*resultTail = item;
resultTail = &item->mNext;
const nsStyleBackground::Size &size = bg->mLayers[i].mSize;
const nsStyleImageLayers::Size &size = bg->mLayers.mLayers[i].mSize;
switch (size.mWidthType) {
case nsStyleBackground::Size::eContain:
case nsStyleBackground::Size::eCover:
case nsStyleImageLayers::Size::eContain:
case nsStyleImageLayers::Size::eCover:
item->mXValue.SetIntValue(size.mWidthType,
eCSSUnit_Enumerated);
break;
case nsStyleBackground::Size::eAuto:
case nsStyleImageLayers::Size::eAuto:
item->mXValue.SetAutoValue();
break;
case nsStyleBackground::Size::eLengthPercentage:
case nsStyleImageLayers::Size::eLengthPercentage:
// XXXbz is there a good reason we can't just
// SetCalcValue(&size.mWidth, item->mXValue) here?
if (!size.mWidth.mHasPercent &&
@@ -3346,14 +3346,14 @@ StyleAnimationValue::ExtractComputedValue(nsCSSProperty aProperty,
}
switch (size.mHeightType) {
case nsStyleBackground::Size::eContain:
case nsStyleBackground::Size::eCover:
case nsStyleImageLayers::Size::eContain:
case nsStyleImageLayers::Size::eCover:
// leave it null
break;
case nsStyleBackground::Size::eAuto:
case nsStyleImageLayers::Size::eAuto:
item->mYValue.SetAutoValue();
break;
case nsStyleBackground::Size::eLengthPercentage:
case nsStyleImageLayers::Size::eLengthPercentage:
// XXXbz is there a good reason we can't just
// SetCalcValue(&size.mHeight, item->mYValue) here?
if (!size.mHeight.mHasPercent &&

View File

@@ -857,23 +857,27 @@ protected:
nsCSSValueList* mOrigin;
nsCSSValueList* mPosition;
nsCSSValuePairList* mSize;
nsCSSValueList* mComposite;
nsCSSValueList* mMode;
BackgroundParseState(
nsCSSValue& aColor, nsCSSValueList* aImage, nsCSSValuePairList* aRepeat,
nsCSSValueList* aAttachment, nsCSSValueList* aClip,
nsCSSValueList* aOrigin, nsCSSValueList* aPosition,
nsCSSValuePairList* aSize) :
nsCSSValuePairList* aSize, nsCSSValueList* aComposite,
nsCSSValueList* aMode) :
mColor(aColor), mImage(aImage), mRepeat(aRepeat),
mAttachment(aAttachment), mClip(aClip), mOrigin(aOrigin),
mPosition(aPosition), mSize(aSize) {};
mPosition(aPosition), mSize(aSize), mComposite(aComposite),
mMode(aMode) {};
};
bool IsFunctionTokenValidForBackgroundImage(const nsCSSToken& aToken) const;
bool ParseBackgroundItem(BackgroundParseState& aState);
bool ParseValueList(nsCSSProperty aPropID); // a single value prop-id
bool ParseBackgroundRepeat();
bool ParseBackgroundRepeat(nsCSSProperty aPropID);
bool ParseBackgroundRepeatValues(nsCSSValuePair& aValue);
bool ParseBackgroundPosition();
bool ParseBackgroundPosition(nsCSSProperty aPropID);
// ParseBoxPositionValues parses the CSS 2.1 background-position syntax,
// which is still used by some properties. See ParsePositionValue
@@ -885,7 +889,7 @@ protected:
// the 'background-position' property.
bool ParsePositionValue(nsCSSValue& aOut);
bool ParseBackgroundSize();
bool ParseBackgroundSize(nsCSSProperty aPropID);
bool ParseBackgroundSizeValues(nsCSSValuePair& aOut);
bool ParseBorderColor();
bool ParseBorderColors(nsCSSProperty aProperty);
@@ -11209,11 +11213,11 @@ CSSParserImpl::ParsePropertyByFunction(nsCSSProperty aPropID)
case eCSSProperty_background:
return ParseBackground();
case eCSSProperty_background_repeat:
return ParseBackgroundRepeat();
return ParseBackgroundRepeat(eCSSProperty_background_repeat);
case eCSSProperty_background_position:
return ParseBackgroundPosition();
return ParseBackgroundPosition(eCSSProperty_background_position);
case eCSSProperty_background_size:
return ParseBackgroundSize();
return ParseBackgroundSize(eCSSProperty_background_size);
case eCSSProperty_border:
return ParseBorderSide(kBorderTopIDs, true);
case eCSSProperty_border_color:
@@ -11662,12 +11666,13 @@ CSSParserImpl::ParseBackground()
return true;
}
nsCSSValue image, repeat, attachment, clip, origin, position, size;
BackgroundParseState state(color, image.SetListValue(),
repeat.SetPairListValue(),
attachment.SetListValue(), clip.SetListValue(),
origin.SetListValue(), position.SetListValue(),
size.SetPairListValue());
nsCSSValue image, repeat, attachment, clip, origin, position, size, composite, mode;
BackgroundParseState state(color, image.SetListValue(),
repeat.SetPairListValue(),
attachment.SetListValue(), clip.SetListValue(),
origin.SetListValue(), position.SetListValue(),
size.SetPairListValue(), composite.SetListValue(),
mode.SetListValue());
for (;;) {
if (!ParseBackgroundItem(state)) {
@@ -11968,7 +11973,7 @@ CSSParserImpl::ParseValueList(nsCSSProperty aPropID)
}
bool
CSSParserImpl::ParseBackgroundRepeat()
CSSParserImpl::ParseBackgroundRepeat(nsCSSProperty aPropID)
{
nsCSSValue value;
// 'initial', 'inherit' and 'unset' stand alone, no list permitted.
@@ -11992,7 +11997,7 @@ CSSParserImpl::ParseBackgroundRepeat()
}
}
AppendValue(eCSSProperty_background_repeat, value);
AppendValue(aPropID, value);
return true;
}
@@ -12021,7 +12026,7 @@ CSSParserImpl::ParseBackgroundRepeatValues(nsCSSValuePair& aValue)
// This function is very similar to ParseScrollSnapCoordinate,
// ParseBackgroundList, and ParseBackgroundSize.
bool
CSSParserImpl::ParseBackgroundPosition()
CSSParserImpl::ParseBackgroundPosition(nsCSSProperty aPropID)
{
nsCSSValue value;
// 'initial', 'inherit' and 'unset' stand alone, no list permitted.
@@ -12043,7 +12048,7 @@ CSSParserImpl::ParseBackgroundPosition()
item = item->mNext;
}
}
AppendValue(eCSSProperty_background_position, value);
AppendValue(aPropID, value);
return true;
}
@@ -12339,7 +12344,7 @@ CSSParserImpl::ParsePositionValue(nsCSSValue& aOut)
// This function is very similar to ParseScrollSnapCoordinate,
// ParseBackgroundList, and ParseBackgroundPosition.
bool
CSSParserImpl::ParseBackgroundSize()
CSSParserImpl::ParseBackgroundSize(nsCSSProperty aPropID)
{
nsCSSValue value;
// 'initial', 'inherit' and 'unset' stand alone, no list permitted.
@@ -12362,7 +12367,7 @@ CSSParserImpl::ParseBackgroundSize()
item = item->mNext;
}
}
AppendValue(eCSSProperty_background_size, value);
AppendValue(aPropID, value);
return true;
}

View File

@@ -1796,17 +1796,16 @@ nsComputedDOMStyle::DoGetFontVariantPosition()
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::GetBackgroundList(uint8_t nsStyleBackground::Layer::* aMember,
uint32_t nsStyleBackground::* aCount,
nsComputedDOMStyle::GetBackgroundList(uint8_t nsStyleImageLayers::Layer::* aMember,
uint32_t nsStyleImageLayers::* aCount,
const nsStyleImageLayers& aLayers,
const KTableEntry aTable[])
{
const nsStyleBackground* bg = StyleBackground();
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
for (uint32_t i = 0, i_end = bg->*aCount; i < i_end; ++i) {
for (uint32_t i = 0, i_end = aLayers.*aCount; i < i_end; ++i) {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
val->SetIdent(nsCSSProps::ValueToKeywordEnum(bg->mLayers[i].*aMember,
val->SetIdent(nsCSSProps::ValueToKeywordEnum(aLayers.mLayers[i].*aMember,
aTable));
valueList->AppendCSSValue(val.forget());
}
@@ -1817,16 +1816,18 @@ nsComputedDOMStyle::GetBackgroundList(uint8_t nsStyleBackground::Layer::* aMembe
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBackgroundAttachment()
{
return GetBackgroundList(&nsStyleBackground::Layer::mAttachment,
&nsStyleBackground::mAttachmentCount,
return GetBackgroundList(&nsStyleImageLayers::Layer::mAttachment,
&nsStyleImageLayers::mAttachmentCount,
StyleBackground()->mLayers,
nsCSSProps::kBackgroundAttachmentKTable);
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBackgroundClip()
{
return GetBackgroundList(&nsStyleBackground::Layer::mClip,
&nsStyleBackground::mClipCount,
return GetBackgroundList(&nsStyleImageLayers::Layer::mClip,
&nsStyleImageLayers::mClipCount,
StyleBackground()->mLayers,
nsCSSProps::kBackgroundOriginKTable);
}
@@ -2129,10 +2130,10 @@ nsComputedDOMStyle::DoGetBackgroundImage()
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
for (uint32_t i = 0, i_end = bg->mImageCount; i < i_end; ++i) {
for (uint32_t i = 0, i_end = bg->mLayers.mImageCount; i < i_end; ++i) {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
const nsStyleImage& image = bg->mLayers[i].mImage;
const nsStyleImage& image = bg->mLayers.mLayers[i].mImage;
SetValueToStyleImage(image, val);
valueList->AppendCSSValue(val.forget());
}
@@ -2143,22 +2144,24 @@ nsComputedDOMStyle::DoGetBackgroundImage()
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBackgroundBlendMode()
{
return GetBackgroundList(&nsStyleBackground::Layer::mBlendMode,
&nsStyleBackground::mBlendModeCount,
return GetBackgroundList(&nsStyleImageLayers::Layer::mBlendMode,
&nsStyleImageLayers::mBlendModeCount,
StyleBackground()->mLayers,
nsCSSProps::kBlendModeKTable);
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBackgroundOrigin()
{
return GetBackgroundList(&nsStyleBackground::Layer::mOrigin,
&nsStyleBackground::mOriginCount,
return GetBackgroundList(&nsStyleImageLayers::Layer::mOrigin,
&nsStyleImageLayers::mOriginCount,
StyleBackground()->mLayers,
nsCSSProps::kBackgroundOriginKTable);
}
void
nsComputedDOMStyle::SetValueToPositionCoord(
const nsStyleBackground::Position::PositionCoord& aCoord,
const nsStyleImageLayers::Position::PositionCoord& aCoord,
nsROCSSPrimitiveValue* aValue)
{
if (!aCoord.mHasPercent) {
@@ -2174,7 +2177,7 @@ nsComputedDOMStyle::SetValueToPositionCoord(
void
nsComputedDOMStyle::SetValueToPosition(
const nsStyleBackground::Position& aPosition,
const nsStyleImageLayers::Position& aPosition,
nsDOMCSSValueList* aValueList)
{
RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
@@ -2193,9 +2196,9 @@ nsComputedDOMStyle::DoGetBackgroundPosition()
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
for (uint32_t i = 0, i_end = bg->mPositionCount; i < i_end; ++i) {
for (uint32_t i = 0, i_end = bg->mLayers.mPositionCount; i < i_end; ++i) {
RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
SetValueToPosition(bg->mLayers[i].mPosition, itemList);
SetValueToPosition(bg->mLayers.mLayers[i].mPosition, itemList);
valueList->AppendCSSValue(itemList.forget());
}
@@ -2209,12 +2212,12 @@ nsComputedDOMStyle::DoGetBackgroundRepeat()
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
for (uint32_t i = 0, i_end = bg->mRepeatCount; i < i_end; ++i) {
for (uint32_t i = 0, i_end = bg->mLayers.mRepeatCount; i < i_end; ++i) {
RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
const uint8_t& xRepeat = bg->mLayers[i].mRepeat.mXRepeat;
const uint8_t& yRepeat = bg->mLayers[i].mRepeat.mYRepeat;
const uint8_t& xRepeat = bg->mLayers.mLayers[i].mRepeat.mXRepeat;
const uint8_t& yRepeat = bg->mLayers.mLayers[i].mRepeat.mYRepeat;
bool hasContraction = true;
unsigned contraction;
@@ -2259,15 +2262,15 @@ nsComputedDOMStyle::DoGetBackgroundSize()
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
for (uint32_t i = 0, i_end = bg->mSizeCount; i < i_end; ++i) {
const nsStyleBackground::Size &size = bg->mLayers[i].mSize;
for (uint32_t i = 0, i_end = bg->mLayers.mSizeCount; i < i_end; ++i) {
const nsStyleImageLayers::Size &size = bg->mLayers.mLayers[i].mSize;
switch (size.mWidthType) {
case nsStyleBackground::Size::eContain:
case nsStyleBackground::Size::eCover: {
case nsStyleImageLayers::Size::eContain:
case nsStyleImageLayers::Size::eCover: {
MOZ_ASSERT(size.mWidthType == size.mHeightType,
"unsynced types");
nsCSSKeyword keyword = size.mWidthType == nsStyleBackground::Size::eContain
nsCSSKeyword keyword = size.mWidthType == nsStyleImageLayers::Size::eContain
? eCSSKeyword_contain
: eCSSKeyword_cover;
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
@@ -2281,11 +2284,11 @@ nsComputedDOMStyle::DoGetBackgroundSize()
RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
if (size.mWidthType == nsStyleBackground::Size::eAuto) {
if (size.mWidthType == nsStyleImageLayers::Size::eAuto) {
valX->SetIdent(eCSSKeyword_auto);
} else {
MOZ_ASSERT(size.mWidthType ==
nsStyleBackground::Size::eLengthPercentage,
nsStyleImageLayers::Size::eLengthPercentage,
"bad mWidthType");
if (!size.mWidth.mHasPercent &&
// negative values must have come from calc()
@@ -2302,11 +2305,11 @@ nsComputedDOMStyle::DoGetBackgroundSize()
}
}
if (size.mHeightType == nsStyleBackground::Size::eAuto) {
if (size.mHeightType == nsStyleImageLayers::Size::eAuto) {
valY->SetIdent(eCSSKeyword_auto);
} else {
MOZ_ASSERT(size.mHeightType ==
nsStyleBackground::Size::eLengthPercentage,
nsStyleImageLayers::Size::eLengthPercentage,
"bad mHeightType");
if (!size.mHeight.mHasPercent &&
// negative values must have come from calc()

View File

@@ -22,6 +22,7 @@
#include "nsCoord.h"
#include "nsColor.h"
#include "nsIContent.h"
#include "nsStyleStruct.h"
namespace mozilla {
namespace dom {
@@ -36,7 +37,6 @@ class nsIPresShell;
class nsDOMCSSValueList;
struct nsMargin;
class nsROCSSPrimitiveValue;
struct nsStyleBackground;
class nsStyleCoord;
class nsStyleCorners;
struct nsStyleFilter;
@@ -203,8 +203,9 @@ private:
bool aIsBoxShadow);
already_AddRefed<CSSValue> GetBackgroundList(
uint8_t nsStyleBackground::Layer::* aMember,
uint32_t nsStyleBackground::* aCount,
uint8_t nsStyleImageLayers::Layer::* aMember,
uint32_t nsStyleImageLayers::* aCount,
const nsStyleImageLayers& aLayers,
const KTableEntry aTable[]);
void GetCSSGradientString(const nsStyleGradient* aGradient,
@@ -557,9 +558,9 @@ private:
void SetValueToStyleImage(const nsStyleImage& aStyleImage,
nsROCSSPrimitiveValue* aValue);
void SetValueToPositionCoord(
const nsStyleBackground::Position::PositionCoord& aCoord,
const nsStyleImageLayers::Position::PositionCoord& aCoord,
nsROCSSPrimitiveValue* aValue);
void SetValueToPosition(const nsStyleBackground::Position& aPosition,
void SetValueToPosition(const nsStyleImageLayers::Position& aPosition,
nsDOMCSSValueList* aValueList);
/**

View File

@@ -115,7 +115,7 @@ nsConditionalResetStyleData::GetConditionalStyleData(nsStyleStructID aSID,
static void
ComputePositionValue(nsStyleContext* aStyleContext,
const nsCSSValue& aValue,
nsStyleBackground::Position& aComputedValue,
nsStyleImageLayers::Position& aComputedValue,
RuleNodeCacheConditions& aConditions);
/*
@@ -5633,7 +5633,7 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
}
// scroll-snap-coordinate: none, inherit, initial
typedef nsStyleBackground::Position Position;
typedef nsStyleImageLayers::Position Position;
const nsCSSValue& snapCoordinate = *aRuleData->ValueForScrollSnapCoordinate();
switch (snapCoordinate.GetUnit()) {
@@ -6381,18 +6381,18 @@ struct BackgroundItemComputer<nsCSSValueList, uint8_t>
};
template <>
struct BackgroundItemComputer<nsCSSValuePairList, nsStyleBackground::Repeat>
struct BackgroundItemComputer<nsCSSValuePairList, nsStyleImageLayers::Repeat>
{
static void ComputeValue(nsStyleContext* aStyleContext,
const nsCSSValuePairList* aSpecifiedValue,
nsStyleBackground::Repeat& aComputedValue,
nsStyleImageLayers::Repeat& aComputedValue,
RuleNodeCacheConditions& aConditions)
{
NS_ASSERTION(aSpecifiedValue->mXValue.GetUnit() == eCSSUnit_Enumerated &&
(aSpecifiedValue->mYValue.GetUnit() == eCSSUnit_Enumerated ||
aSpecifiedValue->mYValue.GetUnit() == eCSSUnit_Null),
"Invalid unit");
bool hasContraction = true;
uint8_t value = aSpecifiedValue->mXValue.GetIntValue();
switch (value) {
@@ -6409,13 +6409,13 @@ struct BackgroundItemComputer<nsCSSValuePairList, nsStyleBackground::Repeat>
hasContraction = false;
break;
}
if (hasContraction) {
NS_ASSERTION(aSpecifiedValue->mYValue.GetUnit() == eCSSUnit_Null,
"Invalid unit.");
return;
}
switch (aSpecifiedValue->mYValue.GetUnit()) {
case eCSSUnit_Null:
aComputedValue.mYRepeat = aComputedValue.mXRepeat;
@@ -6450,7 +6450,7 @@ struct BackgroundItemComputer<nsCSSValueList, nsStyleImage>
* This function computes a single PositionCoord from two nsCSSValue objects,
* which represent an edge and an offset from that edge.
*/
typedef nsStyleBackground::Position::PositionCoord PositionCoord;
typedef nsStyleImageLayers::Position::PositionCoord PositionCoord;
static void
ComputePositionCoord(nsStyleContext* aStyleContext,
const nsCSSValue& aEdge,
@@ -6505,7 +6505,7 @@ ComputePositionCoord(nsStyleContext* aStyleContext,
static void
ComputePositionValue(nsStyleContext* aStyleContext,
const nsCSSValue& aValue,
nsStyleBackground::Position& aComputedValue,
nsStyleImageLayers::Position& aComputedValue,
RuleNodeCacheConditions& aConditions)
{
NS_ASSERTION(aValue.GetUnit() == eCSSUnit_Array,
@@ -6535,11 +6535,11 @@ ComputePositionValue(nsStyleContext* aStyleContext,
}
template <>
struct BackgroundItemComputer<nsCSSValueList, nsStyleBackground::Position>
struct BackgroundItemComputer<nsCSSValueList, nsStyleImageLayers::Position>
{
static void ComputeValue(nsStyleContext* aStyleContext,
const nsCSSValueList* aSpecifiedValue,
nsStyleBackground::Position& aComputedValue,
nsStyleImageLayers::Position& aComputedValue,
RuleNodeCacheConditions& aConditions)
{
ComputePositionValue(aStyleContext, aSpecifiedValue->mValue,
@@ -6550,39 +6550,39 @@ struct BackgroundItemComputer<nsCSSValueList, nsStyleBackground::Position>
struct BackgroundSizeAxis {
nsCSSValue nsCSSValuePairList::* specified;
nsStyleBackground::Size::Dimension nsStyleBackground::Size::* result;
uint8_t nsStyleBackground::Size::* type;
nsStyleImageLayers::Size::Dimension nsStyleImageLayers::Size::* result;
uint8_t nsStyleImageLayers::Size::* type;
};
static const BackgroundSizeAxis gBGSizeAxes[] = {
{ &nsCSSValuePairList::mXValue,
&nsStyleBackground::Size::mWidth,
&nsStyleBackground::Size::mWidthType },
&nsStyleImageLayers::Size::mWidth,
&nsStyleImageLayers::Size::mWidthType },
{ &nsCSSValuePairList::mYValue,
&nsStyleBackground::Size::mHeight,
&nsStyleBackground::Size::mHeightType }
&nsStyleImageLayers::Size::mHeight,
&nsStyleImageLayers::Size::mHeightType }
};
template <>
struct BackgroundItemComputer<nsCSSValuePairList, nsStyleBackground::Size>
struct BackgroundItemComputer<nsCSSValuePairList, nsStyleImageLayers::Size>
{
static void ComputeValue(nsStyleContext* aStyleContext,
const nsCSSValuePairList* aSpecifiedValue,
nsStyleBackground::Size& aComputedValue,
nsStyleImageLayers::Size& aComputedValue,
RuleNodeCacheConditions& aConditions)
{
nsStyleBackground::Size &size = aComputedValue;
nsStyleImageLayers::Size &size = aComputedValue;
for (const BackgroundSizeAxis *axis = gBGSizeAxes,
*axis_end = ArrayEnd(gBGSizeAxes);
axis < axis_end; ++axis) {
const nsCSSValue &specified = aSpecifiedValue->*(axis->specified);
if (eCSSUnit_Auto == specified.GetUnit()) {
size.*(axis->type) = nsStyleBackground::Size::eAuto;
size.*(axis->type) = nsStyleImageLayers::Size::eAuto;
}
else if (eCSSUnit_Enumerated == specified.GetUnit()) {
static_assert(nsStyleBackground::Size::eContain ==
static_assert(nsStyleImageLayers::Size::eContain ==
NS_STYLE_BG_SIZE_CONTAIN &&
nsStyleBackground::Size::eCover ==
nsStyleImageLayers::Size::eCover ==
NS_STYLE_BG_SIZE_COVER,
"background size constants out of sync");
MOZ_ASSERT(specified.GetIntValue() == NS_STYLE_BG_SIZE_CONTAIN ||
@@ -6614,7 +6614,7 @@ struct BackgroundItemComputer<nsCSSValuePairList, nsStyleBackground::Size>
(size.*(axis->result)).mLength = 0;
(size.*(axis->result)).mPercent = specified.GetPercentValue();
(size.*(axis->result)).mHasPercent = true;
size.*(axis->type) = nsStyleBackground::Size::eLengthPercentage;
size.*(axis->type) = nsStyleImageLayers::Size::eLengthPercentage;
}
else if (specified.IsLengthUnit()) {
(size.*(axis->result)).mLength =
@@ -6622,7 +6622,7 @@ struct BackgroundItemComputer<nsCSSValuePairList, nsStyleBackground::Size>
aConditions);
(size.*(axis->result)).mPercent = 0.0f;
(size.*(axis->result)).mHasPercent = false;
size.*(axis->type) = nsStyleBackground::Size::eLengthPercentage;
size.*(axis->type) = nsStyleImageLayers::Size::eLengthPercentage;
} else {
MOZ_ASSERT(specified.IsCalcUnit(), "unexpected unit");
LengthPercentPairCalcOps ops(aStyleContext,
@@ -6632,16 +6632,16 @@ struct BackgroundItemComputer<nsCSSValuePairList, nsStyleBackground::Size>
(size.*(axis->result)).mLength = vals.mLength;
(size.*(axis->result)).mPercent = vals.mPercent;
(size.*(axis->result)).mHasPercent = ops.mHasPercent;
size.*(axis->type) = nsStyleBackground::Size::eLengthPercentage;
size.*(axis->type) = nsStyleImageLayers::Size::eLengthPercentage;
}
}
MOZ_ASSERT(size.mWidthType < nsStyleBackground::Size::eDimensionType_COUNT,
MOZ_ASSERT(size.mWidthType < nsStyleImageLayers::Size::eDimensionType_COUNT,
"bad width type");
MOZ_ASSERT(size.mHeightType < nsStyleBackground::Size::eDimensionType_COUNT,
MOZ_ASSERT(size.mHeightType < nsStyleImageLayers::Size::eDimensionType_COUNT,
"bad height type");
MOZ_ASSERT((size.mWidthType != nsStyleBackground::Size::eContain &&
size.mWidthType != nsStyleBackground::Size::eCover) ||
MOZ_ASSERT((size.mWidthType != nsStyleImageLayers::Size::eContain &&
size.mWidthType != nsStyleImageLayers::Size::eCover) ||
size.mWidthType == size.mHeightType,
"contain/cover apply to both dimensions or to neither");
}
@@ -6651,9 +6651,9 @@ template <class ComputedValueItem>
static void
SetBackgroundList(nsStyleContext* aStyleContext,
const nsCSSValue& aValue,
nsAutoTArray< nsStyleBackground::Layer, 1> &aLayers,
const nsAutoTArray<nsStyleBackground::Layer, 1> &aParentLayers,
ComputedValueItem nsStyleBackground::Layer::* aResultLocation,
nsAutoTArray< nsStyleImageLayers::Layer, 1> &aLayers,
const nsAutoTArray<nsStyleImageLayers::Layer, 1> &aParentLayers,
ComputedValueItem nsStyleImageLayers::Layer::* aResultLocation,
ComputedValueItem aInitialValue,
uint32_t aParentItemCount,
uint32_t& aItemCount,
@@ -6716,10 +6716,10 @@ template <class ComputedValueItem>
static void
SetBackgroundPairList(nsStyleContext* aStyleContext,
const nsCSSValue& aValue,
nsAutoTArray< nsStyleBackground::Layer, 1> &aLayers,
const nsAutoTArray<nsStyleBackground::Layer, 1>
nsAutoTArray< nsStyleImageLayers::Layer, 1> &aLayers,
const nsAutoTArray<nsStyleImageLayers::Layer, 1>
&aParentLayers,
ComputedValueItem nsStyleBackground::Layer::*
ComputedValueItem nsStyleImageLayers::Layer::*
aResultLocation,
ComputedValueItem aInitialValue,
uint32_t aParentItemCount,
@@ -6783,8 +6783,8 @@ SetBackgroundPairList(nsStyleContext* aStyleContext,
template <class ComputedValueItem>
static void
FillBackgroundList(nsAutoTArray< nsStyleBackground::Layer, 1> &aLayers,
ComputedValueItem nsStyleBackground::Layer::* aResultLocation,
FillBackgroundList(nsAutoTArray< nsStyleImageLayers::Layer, 1> &aLayers,
ComputedValueItem nsStyleImageLayers::Layer::* aResultLocation,
uint32_t aItemCount, uint32_t aFillCount)
{
NS_PRECONDITION(aFillCount <= aLayers.Length(), "unexpected array length");
@@ -6824,100 +6824,99 @@ nsRuleNode::ComputeBackgroundData(void* aStartStruct,
// background-image: url (stored as image), none, inherit [list]
nsStyleImage initialImage;
SetBackgroundList(aContext, *aRuleData->ValueForBackgroundImage(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mImage,
initialImage, parentBG->mImageCount, bg->mImageCount,
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mImage,
initialImage, parentBG->mLayers.mImageCount, bg->mLayers.mImageCount,
maxItemCount, rebuild, conditions);
// background-repeat: enum, inherit, initial [pair list]
nsStyleBackground::Repeat initialRepeat;
nsStyleImageLayers::Repeat initialRepeat;
initialRepeat.SetInitialValues();
SetBackgroundPairList(aContext, *aRuleData->ValueForBackgroundRepeat(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mRepeat,
initialRepeat, parentBG->mRepeatCount,
bg->mRepeatCount, maxItemCount, rebuild,
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mRepeat,
initialRepeat, parentBG->mLayers.mRepeatCount,
bg->mLayers.mRepeatCount, maxItemCount, rebuild,
conditions);
// background-attachment: enum, inherit, initial [list]
SetBackgroundList(aContext, *aRuleData->ValueForBackgroundAttachment(),
bg->mLayers, parentBG->mLayers,
&nsStyleBackground::Layer::mAttachment,
bg->mLayers.mLayers, parentBG->mLayers.mLayers,
&nsStyleImageLayers::Layer::mAttachment,
uint8_t(NS_STYLE_BG_ATTACHMENT_SCROLL),
parentBG->mAttachmentCount,
bg->mAttachmentCount, maxItemCount, rebuild,
parentBG->mLayers.mAttachmentCount,
bg->mLayers.mAttachmentCount, maxItemCount, rebuild,
conditions);
// background-clip: enum, inherit, initial [list]
SetBackgroundList(aContext, *aRuleData->ValueForBackgroundClip(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mClip,
uint8_t(NS_STYLE_BG_CLIP_BORDER), parentBG->mClipCount,
bg->mClipCount, maxItemCount, rebuild, conditions);
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mClip,
uint8_t(NS_STYLE_BG_CLIP_BORDER), parentBG->mLayers.mClipCount,
bg->mLayers.mClipCount, maxItemCount, rebuild, conditions);
// background-blend-mode: enum, inherit, initial [list]
SetBackgroundList(aContext, *aRuleData->ValueForBackgroundBlendMode(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mBlendMode,
uint8_t(NS_STYLE_BLEND_NORMAL), parentBG->mBlendModeCount,
bg->mBlendModeCount, maxItemCount, rebuild,
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mBlendMode,
uint8_t(NS_STYLE_BLEND_NORMAL), parentBG->mLayers.mBlendModeCount,
bg->mLayers.mBlendModeCount, maxItemCount, rebuild,
conditions);
// background-origin: enum, inherit, initial [list]
SetBackgroundList(aContext, *aRuleData->ValueForBackgroundOrigin(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mOrigin,
uint8_t(NS_STYLE_BG_ORIGIN_PADDING), parentBG->mOriginCount,
bg->mOriginCount, maxItemCount, rebuild,
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mOrigin,
uint8_t(NS_STYLE_BG_ORIGIN_PADDING), parentBG->mLayers.mOriginCount,
bg->mLayers.mOriginCount, maxItemCount, rebuild,
conditions);
// background-position: enum, length, percent (flags), inherit [pair list]
nsStyleBackground::Position initialPosition;
nsStyleImageLayers::Position initialPosition;
initialPosition.SetInitialPercentValues(0.0f);
SetBackgroundList(aContext, *aRuleData->ValueForBackgroundPosition(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mPosition,
initialPosition, parentBG->mPositionCount,
bg->mPositionCount, maxItemCount, rebuild,
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mPosition,
initialPosition, parentBG->mLayers.mPositionCount,
bg->mLayers.mPositionCount, maxItemCount, rebuild,
conditions);
// background-size: enum, length, auto, inherit, initial [pair list]
nsStyleBackground::Size initialSize;
nsStyleImageLayers::Size initialSize;
initialSize.SetInitialValues();
SetBackgroundPairList(aContext, *aRuleData->ValueForBackgroundSize(),
bg->mLayers,
parentBG->mLayers, &nsStyleBackground::Layer::mSize,
initialSize, parentBG->mSizeCount,
bg->mSizeCount, maxItemCount, rebuild,
bg->mLayers.mLayers,
parentBG->mLayers.mLayers, &nsStyleImageLayers::Layer::mSize,
initialSize, parentBG->mLayers.mSizeCount,
bg->mLayers.mSizeCount, maxItemCount, rebuild,
conditions);
if (rebuild) {
// Delete any extra items. We need to keep layers in which any
// property was specified.
bg->mLayers.TruncateLength(maxItemCount);
bg->mLayers.mLayers.TruncateLength(maxItemCount);
uint32_t fillCount = bg->mImageCount;
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mImage,
bg->mImageCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mRepeat,
bg->mRepeatCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mAttachment,
bg->mAttachmentCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mClip,
bg->mClipCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mBlendMode,
bg->mBlendModeCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mOrigin,
bg->mOriginCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mPosition,
bg->mPositionCount, fillCount);
FillBackgroundList(bg->mLayers, &nsStyleBackground::Layer::mSize,
bg->mSizeCount, fillCount);
uint32_t fillCount = bg->mLayers.mImageCount;
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mImage,
bg->mLayers.mImageCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mRepeat,
bg->mLayers.mRepeatCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mAttachment,
bg->mLayers.mAttachmentCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mClip,
bg->mLayers.mClipCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mBlendMode,
bg->mLayers.mBlendModeCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mOrigin,
bg->mLayers.mOriginCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mPosition,
bg->mLayers.mPositionCount, fillCount);
FillBackgroundList(bg->mLayers.mLayers, &nsStyleImageLayers::Layer::mSize,
bg->mLayers.mSizeCount, fillCount);
}
// Now that the dust has settled, register the images with the document
for (uint32_t i = 0; i < bg->mImageCount; ++i)
bg->mLayers[i].TrackImages(aContext->PresContext());
bg->mLayers.TrackImages(aContext->PresContext());
COMPUTE_END_RESET(Background, bg)
}

View File

@@ -2201,10 +2201,10 @@ nsStyleImage::operator==(const nsStyleImage& aOther) const
}
// --------------------
// nsStyleBackground
// nsStyleImageLayers
//
nsStyleBackground::nsStyleBackground()
nsStyleImageLayers::nsStyleImageLayers()
: mAttachmentCount(1)
, mClipCount(1)
, mOriginCount(1)
@@ -2213,15 +2213,13 @@ nsStyleBackground::nsStyleBackground()
, mImageCount(1)
, mSizeCount(1)
, mBlendModeCount(1)
, mBackgroundColor(NS_RGBA(0, 0, 0, 0))
{
MOZ_COUNT_CTOR(nsStyleBackground);
Layer *onlyLayer = mLayers.AppendElement();
NS_ASSERTION(onlyLayer, "auto array must have room for 1 element");
onlyLayer->SetInitialValues();
MOZ_COUNT_CTOR(nsStyleImageLayers);
mLayers.AppendElement();
NS_ASSERTION(mLayers.Length() == 1, "auto array must have room for 1 element");
}
nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)
nsStyleImageLayers::nsStyleImageLayers(const nsStyleImageLayers &aSource)
: mAttachmentCount(aSource.mAttachmentCount)
, mClipCount(aSource.mClipCount)
, mOriginCount(aSource.mOriginCount)
@@ -2231,9 +2229,8 @@ nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)
, mSizeCount(aSource.mSizeCount)
, mBlendModeCount(aSource.mBlendModeCount)
, mLayers(aSource.mLayers) // deep copy
, mBackgroundColor(aSource.mBackgroundColor)
{
MOZ_COUNT_CTOR(nsStyleBackground);
MOZ_COUNT_CTOR(nsStyleImageLayers);
// If the deep copy of mLayers failed, truncate the counts.
uint32_t count = mLayers.Length();
if (count != aSource.mLayers.Length()) {
@@ -2245,94 +2242,12 @@ nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)
mPositionCount = std::max(mPositionCount, count);
mImageCount = std::max(mImageCount, count);
mSizeCount = std::max(mSizeCount, count);
mBlendModeCount = std::max(mSizeCount, count);
mBlendModeCount = std::max(mBlendModeCount, count);
}
}
nsStyleBackground::~nsStyleBackground()
{
MOZ_COUNT_DTOR(nsStyleBackground);
}
void
nsStyleBackground::Destroy(nsPresContext* aContext)
{
// Untrack all the images stored in our layers
for (uint32_t i = 0; i < mImageCount; ++i)
mLayers[i].UntrackImages(aContext);
this->~nsStyleBackground();
aContext->PresShell()->
FreeByObjectID(eArenaObjectID_nsStyleBackground, this);
}
nsChangeHint nsStyleBackground::CalcDifference(const nsStyleBackground& aOther) const
{
const nsStyleBackground* moreLayers =
mImageCount > aOther.mImageCount ? this : &aOther;
const nsStyleBackground* lessLayers =
mImageCount > aOther.mImageCount ? &aOther : this;
nsChangeHint hint = nsChangeHint(0);
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, moreLayers) {
if (i < lessLayers->mImageCount) {
nsChangeHint layerDifference = moreLayers->mLayers[i].CalcDifference(lessLayers->mLayers[i]);
hint |= layerDifference;
if (layerDifference &&
((moreLayers->mLayers[i].mImage.GetType() == eStyleImageType_Element) ||
(lessLayers->mLayers[i].mImage.GetType() == eStyleImageType_Element))) {
hint |= nsChangeHint_UpdateEffects | nsChangeHint_RepaintFrame;
}
} else {
hint |= nsChangeHint_RepaintFrame;
if (moreLayers->mLayers[i].mImage.GetType() == eStyleImageType_Element) {
hint |= nsChangeHint_UpdateEffects | nsChangeHint_RepaintFrame;
}
}
}
if (mBackgroundColor != aOther.mBackgroundColor) {
hint |= nsChangeHint_RepaintFrame;
}
if (hint) {
return hint;
}
if (mAttachmentCount != aOther.mAttachmentCount ||
mClipCount != aOther.mClipCount ||
mOriginCount != aOther.mOriginCount ||
mRepeatCount != aOther.mRepeatCount ||
mPositionCount != aOther.mPositionCount ||
mSizeCount != aOther.mSizeCount) {
return nsChangeHint_NeutralChange;
}
return NS_STYLE_HINT_NONE;
}
bool nsStyleBackground::HasFixedBackground() const
{
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, this) {
const Layer &layer = mLayers[i];
if (layer.mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
!layer.mImage.IsEmpty()) {
return true;
}
}
return false;
}
bool nsStyleBackground::IsTransparent() const
{
return BottomLayer().mImage.IsEmpty() &&
mImageCount == 1 &&
NS_GET_A(mBackgroundColor) == 0;
}
void
nsStyleBackground::Position::SetInitialPercentValues(float aPercentVal)
nsStyleImageLayers::Position::SetInitialPercentValues(float aPercentVal)
{
mXPosition.mPercent = aPercentVal;
mXPosition.mLength = 0;
@@ -2343,7 +2258,7 @@ nsStyleBackground::Position::SetInitialPercentValues(float aPercentVal)
}
void
nsStyleBackground::Position::SetInitialZeroValues()
nsStyleImageLayers::Position::SetInitialZeroValues()
{
mXPosition.mPercent = 0;
mXPosition.mLength = 0;
@@ -2354,7 +2269,7 @@ nsStyleBackground::Position::SetInitialZeroValues()
}
bool
nsStyleBackground::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImage) const
nsStyleImageLayers::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImage) const
{
MOZ_ASSERT(aImage.GetType() != eStyleImageType_Null,
"caller should have handled this");
@@ -2433,13 +2348,13 @@ nsStyleBackground::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImage
}
void
nsStyleBackground::Size::SetInitialValues()
nsStyleImageLayers::Size::SetInitialValues()
{
mWidthType = mHeightType = eAuto;
}
bool
nsStyleBackground::Size::operator==(const Size& aOther) const
nsStyleImageLayers::Size::operator==(const Size& aOther) const
{
MOZ_ASSERT(mWidthType < eDimensionType_COUNT,
"bad mWidthType for this");
@@ -2457,35 +2372,30 @@ nsStyleBackground::Size::operator==(const Size& aOther) const
}
void
nsStyleBackground::Repeat::SetInitialValues()
nsStyleImageLayers::Repeat::SetInitialValues()
{
mXRepeat = NS_STYLE_BG_REPEAT_REPEAT;
mYRepeat = NS_STYLE_BG_REPEAT_REPEAT;
}
nsStyleBackground::Layer::Layer()
nsStyleImageLayers::Layer::Layer()
: mClip(NS_STYLE_BG_CLIP_BORDER),
mOrigin(NS_STYLE_BG_ORIGIN_PADDING),
mAttachment(NS_STYLE_BG_ATTACHMENT_SCROLL),
mBlendMode(NS_STYLE_BLEND_NORMAL)
{
}
nsStyleBackground::Layer::~Layer()
{
}
void
nsStyleBackground::Layer::SetInitialValues()
{
mAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
mClip = NS_STYLE_BG_CLIP_BORDER;
mOrigin = NS_STYLE_BG_ORIGIN_PADDING;
mRepeat.SetInitialValues();
mBlendMode = NS_STYLE_BLEND_NORMAL;
mPosition.SetInitialPercentValues(0.0f); // Initial value is "0% 0%"
mSize.SetInitialValues();
mImage.SetNull();
mRepeat.SetInitialValues();
mSize.SetInitialValues();
}
nsStyleImageLayers::Layer::~Layer()
{
}
bool
nsStyleBackground::Layer::RenderingMightDependOnPositioningAreaSizeChange() const
nsStyleImageLayers::Layer::RenderingMightDependOnPositioningAreaSizeChange() const
{
// Do we even have an image?
if (mImage.IsEmpty()) {
@@ -2497,7 +2407,7 @@ nsStyleBackground::Layer::RenderingMightDependOnPositioningAreaSizeChange() cons
}
bool
nsStyleBackground::Layer::operator==(const Layer& aOther) const
nsStyleImageLayers::Layer::operator==(const Layer& aOther) const
{
return mAttachment == aOther.mAttachment &&
mClip == aOther.mClip &&
@@ -2510,7 +2420,7 @@ nsStyleBackground::Layer::operator==(const Layer& aOther) const
}
nsChangeHint
nsStyleBackground::Layer::CalcDifference(const Layer& aOther) const
nsStyleImageLayers::Layer::CalcDifference(const nsStyleImageLayers::Layer& aOther) const
{
nsChangeHint hint = nsChangeHint(0);
if (mAttachment != aOther.mAttachment ||
@@ -2528,6 +2438,109 @@ nsStyleBackground::Layer::CalcDifference(const Layer& aOther) const
return hint;
}
// --------------------
// nsStyleBackground
//
nsStyleBackground::nsStyleBackground()
: mBackgroundColor(NS_RGBA(0, 0, 0, 0))
{
MOZ_COUNT_CTOR(nsStyleBackground);
}
nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)
: mLayers(aSource.mLayers)
, mBackgroundColor(aSource.mBackgroundColor)
{
MOZ_COUNT_CTOR(nsStyleBackground);
}
nsStyleBackground::~nsStyleBackground()
{
MOZ_COUNT_DTOR(nsStyleBackground);
}
void
nsStyleBackground::Destroy(nsPresContext* aContext)
{
// Untrack all the images stored in our layers
mLayers.UntrackImages(aContext);
this->~nsStyleBackground();
aContext->PresShell()->
FreeByObjectID(eArenaObjectID_nsStyleBackground, this);
}
nsChangeHint nsStyleBackground::CalcDifference(const nsStyleBackground& aOther) const
{
const nsStyleImageLayers& moreLayers =
mLayers.mImageCount > aOther.mLayers.mImageCount ?
this->mLayers : aOther.mLayers;
const nsStyleImageLayers& lessLayers =
mLayers.mImageCount > aOther.mLayers.mImageCount ?
aOther.mLayers : this->mLayers;
nsChangeHint hint = nsChangeHint(0);
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, moreLayers) {
if (i < lessLayers.mImageCount) {
nsChangeHint layerDifference = moreLayers.mLayers[i].
CalcDifference(lessLayers.mLayers[i]);
hint |= layerDifference;
if (layerDifference &&
((moreLayers.mLayers[i].mImage.GetType() == eStyleImageType_Element) ||
(lessLayers.mLayers[i].mImage.GetType() == eStyleImageType_Element))) {
hint |= nsChangeHint_UpdateEffects | nsChangeHint_RepaintFrame;
}
} else {
hint |= nsChangeHint_RepaintFrame;
if (moreLayers.mLayers[i].mImage.GetType() == eStyleImageType_Element) {
hint |= nsChangeHint_UpdateEffects | nsChangeHint_RepaintFrame;
}
}
}
if (mBackgroundColor != aOther.mBackgroundColor) {
hint |= nsChangeHint_RepaintFrame;
}
if (hint) {
return hint;
}
if (mLayers.mAttachmentCount != aOther.mLayers.mAttachmentCount ||
mLayers.mClipCount != aOther.mLayers.mClipCount ||
mLayers.mOriginCount != aOther.mLayers.mOriginCount ||
mLayers.mRepeatCount != aOther.mLayers.mRepeatCount ||
mLayers.mPositionCount != aOther.mLayers.mPositionCount ||
mLayers.mSizeCount != aOther.mLayers.mSizeCount) {
return nsChangeHint_NeutralChange;
}
return NS_STYLE_HINT_NONE;
}
bool nsStyleBackground::HasFixedBackground() const
{
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mLayers) {
const nsStyleImageLayers::Layer &layer = mLayers.mLayers[i];
if (layer.mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
!layer.mImage.IsEmpty()) {
return true;
}
}
return false;
}
bool nsStyleBackground::IsTransparent() const
{
return BottomLayer().mImage.IsEmpty() &&
mLayers.mImageCount == 1 &&
NS_GET_A(mBackgroundColor) == 0;
}
// --------------------
// nsStyleDisplay
//

View File

@@ -398,29 +398,11 @@ struct nsStyleColor
nscolor mColor; // [inherited]
};
struct nsStyleBackground
{
nsStyleBackground();
nsStyleBackground(const nsStyleBackground& aOther);
~nsStyleBackground();
void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
return aContext->PresShell()->
AllocateByObjectID(mozilla::eArenaObjectID_nsStyleBackground, sz);
}
void Destroy(nsPresContext* aContext);
nsChangeHint CalcDifference(const nsStyleBackground& aOther) const;
static nsChangeHint MaxDifference() {
return nsChangeHint_UpdateEffects |
nsChangeHint_RepaintFrame |
nsChangeHint_SchedulePaint |
nsChangeHint_NeutralChange;
}
static nsChangeHint DifferenceAlwaysHandledForDescendants() {
// CalcDifference never returns the reflow hints that are sometimes
// handled for descendants at all.
return nsChangeHint(0);
struct nsStyleImageLayers {
nsStyleImageLayers();
nsStyleImageLayers(const nsStyleImageLayers &aSource);
~nsStyleImageLayers() {
MOZ_COUNT_DTOR(nsStyleImageLayers);
}
struct Position;
@@ -536,14 +518,24 @@ struct nsStyleBackground
struct Layer;
friend struct Layer;
struct Layer {
uint8_t mAttachment; // [reset] See nsStyleConsts.h
uint8_t mClip; // [reset] See nsStyleConsts.h
uint8_t mOrigin; // [reset] See nsStyleConsts.h
uint8_t mBlendMode; // [reset] See nsStyleConsts.h
Repeat mRepeat; // [reset] See nsStyleConsts.h
Position mPosition; // [reset]
nsStyleImage mImage; // [reset]
Size mSize; // [reset]
nsStyleImage mImage; // [reset]
Position mPosition; // [reset] See nsStyleConsts.h
Size mSize; // [reset]
uint8_t mClip; // [reset] See nsStyleConsts.h
uint8_t mOrigin; // [reset] See nsStyleConsts.h
uint8_t mAttachment; // [reset] See nsStyleConsts.h
// background-only property
// This property is used for background layer
// only. For a mask layer, it should always
// be the initial value, which is
// NS_STYLE_BG_ATTACHMENT_SCROLL.
uint8_t mBlendMode; // [reset] See nsStyleConsts.h
// background-only property
// This property is used for background layer
// only. For a mask layer, it should always
// be the initial value, which is
// NS_STYLE_BLEND_NORMAL.
Repeat mRepeat; // [reset] See nsStyleConsts.h
// Initializes only mImage
Layer();
@@ -560,8 +552,6 @@ struct nsStyleBackground
mImage.UntrackImage(aContext);
}
void SetInitialValues();
// True if the rendering of this layer might change when the size
// of the background positioning area changes. This is true for any
// non-solid-color background whose position or size depends on
@@ -590,6 +580,7 @@ struct nsStyleBackground
mImageCount,
mSizeCount,
mBlendModeCount;
// Layers are stored in an array, matching the top-to-bottom order in
// which they are specified in CSS. The number of layers to be used
// should come from the background-image property. We create
@@ -604,14 +595,46 @@ struct nsStyleBackground
const Layer& BottomLayer() const { return mLayers[mImageCount - 1]; }
#define NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(var_, stylebg_) \
for (uint32_t var_ = (stylebg_) ? (stylebg_)->mImageCount : 1; var_-- != 0; )
#define NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT_WITH_RANGE(var_, stylebg_, start_, count_) \
NS_ASSERTION((int32_t)(start_) >= 0 && (uint32_t)(start_) < ((stylebg_) ? (stylebg_)->mImageCount : 1), "Invalid layer start!"); \
void TrackImages(nsPresContext* aContext) {
for (uint32_t i = 0; i < mImageCount; ++i) {
mLayers[i].TrackImages(aContext);
}
}
void UntrackImages(nsPresContext* aContext) {
for (uint32_t i = 0; i < mImageCount; ++i)
mLayers[i].UntrackImages(aContext);
}
#define NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(var_, layers_) \
for (uint32_t var_ = (layers_).mImageCount; var_-- != 0; )
#define NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(var_, layers_, start_, count_) \
NS_ASSERTION((int32_t)(start_) >= 0 && (uint32_t)(start_) < (layers_).mImageCount, "Invalid layer start!"); \
NS_ASSERTION((count_) > 0 && (count_) <= (start_) + 1, "Invalid layer range!"); \
for (uint32_t var_ = (start_) + 1; var_-- != (uint32_t)((start_) + 1 - (count_)); )
};
nscolor mBackgroundColor; // [reset]
struct nsStyleBackground {
nsStyleBackground();
nsStyleBackground(const nsStyleBackground& aOther);
~nsStyleBackground();
void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
return aContext->PresShell()->
AllocateByObjectID(mozilla::eArenaObjectID_nsStyleBackground, sz);
}
void Destroy(nsPresContext* aContext);
nsChangeHint CalcDifference(const nsStyleBackground& aOther) const;
static nsChangeHint MaxDifference() {
return nsChangeHint_UpdateEffects |
nsChangeHint_RepaintFrame |
nsChangeHint_SchedulePaint |
nsChangeHint_NeutralChange;
}
static nsChangeHint DifferenceAlwaysHandledForDescendants() {
// CalcDifference never returns the reflow hints that are sometimes
// handled for descendants at all.
return nsChangeHint(0);
}
// True if this background is completely transparent.
bool IsTransparent() const;
@@ -621,6 +644,11 @@ struct nsStyleBackground
// Not inline because it uses an nsCOMPtr<imgIRequest>
// FIXME: Should be in nsStyleStructInlines.h.
bool HasFixedBackground() const;
const nsStyleImageLayers::Layer& BottomLayer() const { return mLayers.BottomLayer(); }
nsStyleImageLayers mLayers;
nscolor mBackgroundColor; // [reset]
};
// See https://bugzilla.mozilla.org/show_bug.cgi?id=271586#c43 for why
@@ -1448,9 +1476,9 @@ struct nsStylePosition
return nsChangeHint(0);
}
// XXXdholbert nsStyleBackground::Position should probably be moved to a
// XXXdholbert nsStyleImageLayers::Position should probably be moved to a
// different scope, since we're now using it in multiple style structs.
typedef nsStyleBackground::Position Position;
typedef nsStyleImageLayers::Position Position;
/**
* Return the computed value for 'align-content'.
@@ -2267,10 +2295,10 @@ struct nsStyleDisplay
return nsChangeHint(0);
}
// XXXdholbert, XXXkgilbert nsStyleBackground::Position should probably be
// XXXdholbert, XXXkgilbert nsStyleImageLayers::Position should probably be
// moved to a different scope, since we're now using it in multiple style
// structs.
typedef nsStyleBackground::Position Position;
typedef nsStyleImageLayers::Position Position;
// We guarantee that if mBinding is non-null, so are mBinding->GetURI() and
// mBinding->mOriginPrincipal.
@@ -3191,7 +3219,7 @@ public:
mFillRule = aFillRule;
}
typedef nsStyleBackground::Position Position;
typedef nsStyleImageLayers::Position Position;
Position& GetPosition() {
NS_ASSERTION(mType == eCircle || mType == eEllipse,
"expected circle or ellipse");

View File

@@ -675,7 +675,7 @@ nsStyleUtil::IsSignificantChild(nsIContent* aChild, bool aTextIsSignificant,
// For a replaced element whose concrete object size is no larger than the
// element's content-box, this method checks whether the given
// "object-position" coordinate might cause overflow in its dimension.
typedef nsStyleBackground::Position::PositionCoord PositionCoord;
typedef nsStyleImageLayers::Position::PositionCoord PositionCoord;
static bool
ObjectPositionCoordMightCauseOverflow(const PositionCoord& aCoord)
{
@@ -713,7 +713,7 @@ nsStyleUtil::ObjectPropsMightCauseOverflow(const nsStylePosition* aStylePos)
// Check each of our "object-position" coords to see if it could cause
// overflow in its dimension:
const nsStyleBackground::Position& objectPosistion = aStylePos->mObjectPosition;
const nsStyleImageLayers::Position& objectPosistion = aStylePos->mObjectPosition;
if (ObjectPositionCoordMightCauseOverflow(objectPosistion.mXPosition) ||
ObjectPositionCoordMightCauseOverflow(objectPosistion.mYPosition)) {
return true;

View File

@@ -122,9 +122,9 @@ TableBackgroundPainter::TableBackgroundData::ShouldSetBCBorder() const
return false;
}
const nsStyleBackground *bg = mFrame->StyleBackground();
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
if (!bg->mLayers[i].mImage.IsEmpty())
const nsStyleImageLayers& layers = mFrame->StyleBackground()->mLayers;
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, layers) {
if (!layers.mLayers[i].mImage.IsEmpty())
return true;
}
return false;