Bug 1352234 - Make nsImageRenderer.cpp and nsCSSRenderingGradients.h compile independent of build unification. r?rhunt
A few includes and namespace annotations are missing. And
nsImageRenderer.cpp is calling two functions that are static functions in
nsCSSRendering.cpp.
MozReview-Commit-ID: BLVPwpKB7On
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -2901,21 +2901,18 @@ nsCSSRendering::ComputeImageLayerPositio
}
}
}
*aAttachedToFrame = attachedToFrame;
return positionArea;
}
-// Implementation of the formula for computation of background-repeat round
-// See http://dev.w3.org/csswg/css3-background/#the-background-size
-// This function returns the adjusted size of the background image.
-static nscoord
-ComputeRoundedSize(nscoord aCurrentSize, nscoord aPositioningSize)
+/* static */ nscoord
+nsCSSRendering::ComputeRoundedSize(nscoord aCurrentSize, nscoord aPositioningSize)
{
float repeatCount = NS_roundf(float(aPositioningSize) / float(aCurrentSize));
if (repeatCount < 1.0f) {
return aPositioningSize;
}
return nscoord(NS_lround(float(aPositioningSize) / repeatCount));
}
@@ -2966,31 +2963,35 @@ ComputeDrawnSizeForBackground(const CSSS
// is 'auto' for the other dimension, then there is a third step: that other dimension
// is scaled so that the original aspect ratio is restored."
bool isRepeatRoundInBothDimensions = aXRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND &&
aYRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND;
// Calculate the rounded size only if the background-size computation
// returned a correct size for the image.
if (imageSize.width && aXRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND) {
- imageSize.width = ComputeRoundedSize(imageSize.width, aBgPositioningArea.width);
+ imageSize.width =
+ nsCSSRendering::ComputeRoundedSize(imageSize.width,
+ aBgPositioningArea.width);
if (!isRepeatRoundInBothDimensions &&
aLayerSize.mHeightType == nsStyleImageLayers::Size::DimensionType::eAuto) {
// Restore intrinsic rato
if (aIntrinsicSize.mRatio.width) {
float scale = float(aIntrinsicSize.mRatio.height) / aIntrinsicSize.mRatio.width;
imageSize.height = NSCoordSaturatingNonnegativeMultiply(imageSize.width, scale);
}
}
}
// Calculate the rounded size only if the background-size computation
// returned a correct size for the image.
if (imageSize.height && aYRepeat == NS_STYLE_IMAGELAYER_REPEAT_ROUND) {
- imageSize.height = ComputeRoundedSize(imageSize.height, aBgPositioningArea.height);
+ imageSize.height =
+ nsCSSRendering::ComputeRoundedSize(imageSize.height,
+ aBgPositioningArea.height);
if (!isRepeatRoundInBothDimensions &&
aLayerSize.mWidthType == nsStyleImageLayers::Size::DimensionType::eAuto) {
// Restore intrinsic rato
if (aIntrinsicSize.mRatio.height) {
float scale = float(aIntrinsicSize.mRatio.width) / aIntrinsicSize.mRatio.height;
imageSize.width = NSCoordSaturatingNonnegativeMultiply(imageSize.height, scale);
}
}
@@ -3015,26 +3016,20 @@ ComputeSpacedRepeatSize(nscoord aImageDi
aRepeat = false;
return aImageDimension;
} else {
aRepeat = true;
return (aAvailableSpace - aImageDimension) / (NSToIntFloor(ratio) - 1);
}
}
-/* ComputeBorderSpacedRepeatSize
- * aImageDimension: the image width/height
- * aAvailableSpace: the background positioning area width/height
- * aSpace: the space between each image
- * Returns the image size plus gap size of app units for use as spacing
- */
-static nscoord
-ComputeBorderSpacedRepeatSize(nscoord aImageDimension,
- nscoord aAvailableSpace,
- nscoord& aSpace)
+/* static */ nscoord
+nsCSSRendering::ComputeBorderSpacedRepeatSize(nscoord aImageDimension,
+ nscoord aAvailableSpace,
+ nscoord& aSpace)
{
int32_t count = aAvailableSpace / aImageDimension;
aSpace = (aAvailableSpace - aImageDimension * count) / (count + 1);
return aSpace + aImageDimension;
}
nsBackgroundLayerState
nsCSSRendering::PrepareImageLayer(nsPresContext* aPresContext,
--- a/layout/painting/nsCSSRendering.h
+++ b/layout/painting/nsCSSRendering.h
@@ -332,16 +332,33 @@ struct nsCSSRendering {
static nsRect
ComputeImageLayerPositioningArea(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsRect& aBorderArea,
const nsStyleImageLayers::Layer& aLayer,
nsIFrame** aAttachedToFrame,
bool* aOutTransformedFixed);
+ // Implementation of the formula for computation of background-repeat round
+ // See http://dev.w3.org/csswg/css3-background/#the-background-size
+ // This function returns the adjusted size of the background image.
+ static nscoord
+ ComputeRoundedSize(nscoord aCurrentSize, nscoord aPositioningSize);
+
+ /* ComputeBorderSpacedRepeatSize
+ * aImageDimension: the image width/height
+ * aAvailableSpace: the background positioning area width/height
+ * aSpace: the space between each image
+ * Returns the image size plus gap size of app units for use as spacing
+ */
+ static nscoord
+ ComputeBorderSpacedRepeatSize(nscoord aImageDimension,
+ nscoord aAvailableSpace,
+ nscoord& aSpace);
+
static nsBackgroundLayerState
PrepareImageLayer(nsPresContext* aPresContext,
nsIFrame* aForFrame,
uint32_t aFlags,
const nsRect& aBorderArea,
const nsRect& aBGClipRect,
const nsStyleImageLayers::Layer& aLayer,
bool* aOutIsTransformedFixed = nullptr);
--- a/layout/painting/nsCSSRenderingGradients.h
+++ b/layout/painting/nsCSSRenderingGradients.h
@@ -5,36 +5,37 @@
#ifndef nsCSSRenderingGradients_h__
#define nsCSSRenderingGradients_h__
#include "nsLayoutUtils.h"
#include "nsStyleStruct.h"
#include "Units.h"
#include "mozilla/Maybe.h"
+#include "mozilla/gfx/2D.h"
namespace mozilla {
namespace layers {
class WebRenderDisplayItemLayer;
} // namespace layers
namespace wr {
class DisplayListBuilder;
} // namespace wr
// A resolved color stop, with a specific position along the gradient line and
// a color.
struct ColorStop {
ColorStop(): mPosition(0), mIsMidpoint(false) {}
- ColorStop(double aPosition, bool aIsMidPoint, const Color& aColor) :
+ ColorStop(double aPosition, bool aIsMidPoint, const gfx::Color& aColor) :
mPosition(aPosition), mIsMidpoint(aIsMidPoint), mColor(aColor) {}
double mPosition; // along the gradient line; 0=start, 1=end
bool mIsMidpoint;
- Color mColor;
+ gfx::Color mColor;
};
class nsCSSGradientRenderer final {
public:
/**
* Render a gradient for an element.
* aDest is the rect for a single tile of the gradient on the destination.
* aFill is the rect on the destination to be covered by repeated tiling of
--- a/layout/painting/nsImageRenderer.cpp
+++ b/layout/painting/nsImageRenderer.cpp
@@ -1,19 +1,34 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// vim:cindent:ts=2:et:sw=2:
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* utility functions for drawing borders and backgrounds */
+#include "nsCSSRenderingGradients.h"
+
+#include "mozilla/webrender/WebRenderAPI.h"
+
+#include "gfxDrawable.h"
+#include "ImageOps.h"
+#include "nsContentUtils.h"
+#include "nsCSSRendering.h"
+#include "nsIFrame.h"
#include "nsImageRenderer.h"
-#include "nsCSSRenderingGradients.h"
-#include "mozilla/webrender/WebRenderAPI.h"
+#include "nsRenderingContext.h"
+#include "nsSVGEffects.h"
+#include "nsSVGIntegrationUtils.h"
+
+using namespace mozilla;
+using namespace mozilla::gfx;
+using namespace mozilla::image;
+using namespace mozilla::layers;
nsSize
CSSSizeOrRatio::ComputeConcreteSize() const
{
NS_ASSERTION(CanComputeConcreteSize(), "Cannot compute");
if (mHasWidth && mHasHeight) {
return nsSize(mWidth, mHeight);
}
@@ -714,24 +729,26 @@ ComputeTile(nsRect& aFill,
break;
case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
tile.x = aFill.x + aFill.width/2 - aUnitSize.width/2;
tile.width = aUnitSize.width;
aRepeatSize.width = tile.width;
break;
case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
tile.x = aFill.x;
- tile.width = ComputeRoundedSize(aUnitSize.width, aFill.width);
+ tile.width = nsCSSRendering::ComputeRoundedSize(aUnitSize.width,
+ aFill.width);
aRepeatSize.width = tile.width;
break;
case NS_STYLE_BORDER_IMAGE_REPEAT_SPACE:
{
nscoord space;
aRepeatSize.width =
- ComputeBorderSpacedRepeatSize(aUnitSize.width, aFill.width, space);
+ nsCSSRendering::ComputeBorderSpacedRepeatSize(aUnitSize.width,
+ aFill.width, space);
tile.x = aFill.x + space;
tile.width = aUnitSize.width;
aFill.x = tile.x;
aFill.width = aFill.width - space * 2;
}
break;
default:
NS_NOTREACHED("unrecognized border-image fill style");
@@ -745,24 +762,26 @@ ComputeTile(nsRect& aFill,
break;
case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
tile.y = aFill.y + aFill.height/2 - aUnitSize.height/2;
tile.height = aUnitSize.height;
aRepeatSize.height = tile.height;
break;
case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
tile.y = aFill.y;
- tile.height = ComputeRoundedSize(aUnitSize.height, aFill.height);
+ tile.height = nsCSSRendering::ComputeRoundedSize(aUnitSize.height,
+ aFill.height);
aRepeatSize.height = tile.height;
break;
case NS_STYLE_BORDER_IMAGE_REPEAT_SPACE:
{
nscoord space;
aRepeatSize.height =
- ComputeBorderSpacedRepeatSize(aUnitSize.height, aFill.height, space);
+ nsCSSRendering::ComputeBorderSpacedRepeatSize(aUnitSize.height,
+ aFill.height, space);
tile.y = aFill.y + space;
tile.height = aUnitSize.height;
aFill.y = tile.y;
aFill.height = aFill.height - space * 2;
}
break;
default:
NS_NOTREACHED("unrecognized border-image fill style");