Bug 1382534 - Move ComputeOffsetToUserSpace() from nsDisplayList.cpp to nsLayoutUtils. r=mstange
MozReview-Commit-ID: 8w9lDViJuAj
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -85,16 +85,17 @@
#include "gfxDrawable.h"
#include "gfxEnv.h"
#include "gfxUtils.h"
#include "nsDataHashtable.h"
#include "nsTableWrapperFrame.h"
#include "nsTextFrame.h"
#include "nsFontFaceList.h"
#include "nsFontInflationData.h"
+#include "nsSVGIntegrationUtils.h"
#include "nsSVGUtils.h"
#include "SVGImageContext.h"
#include "SVGTextFrame.h"
#include "nsStyleStructInlines.h"
#include "nsStyleTransformMatrix.h"
#include "nsIFrameInlines.h"
#include "ImageContainer.h"
#include "nsComputedDOMStyle.h"
@@ -10019,8 +10020,42 @@ nsLayoutUtils::ComputeGeometryBox(nsIFra
// element, which does have an associated CSS layout box. In this case we
// should still use ComputeHTMLReferenceRect for region computing.
nsRect r = (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)
? ComputeSVGReferenceRect(aFrame, aGeometryBox)
: ComputeHTMLReferenceRect(aFrame, aGeometryBox);
return r;
}
+
+/* static */ nsPoint
+nsLayoutUtils::ComputeOffsetToUserSpace(nsDisplayListBuilder* aBuilder,
+ nsIFrame* aFrame)
+{
+ nsPoint offsetToBoundingBox = aBuilder->ToReferenceFrame(aFrame) -
+ nsSVGIntegrationUtils::GetOffsetToBoundingBox(aFrame);
+ if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
+ // Snap the offset if the reference frame is not a SVG frame, since other
+ // frames will be snapped to pixel when rendering.
+ offsetToBoundingBox = nsPoint(
+ aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.x),
+ aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.y));
+ }
+
+ // During SVG painting, the offset computed here is applied to the gfxContext
+ // "ctx" used to paint the mask. After applying only "offsetToBoundingBox",
+ // "ctx" would have its origin at the top left corner of frame's bounding box
+ // (over all continuations).
+ // However, SVG painting needs the origin to be located at the origin of the
+ // SVG frame's "user space", i.e. the space in which, for example, the
+ // frame's BBox lives.
+ // SVG geometry frames and foreignObject frames apply their own offsets, so
+ // their position is relative to their user space. So for these frame types,
+ // if we want "ctx" to be in user space, we first need to subtract the
+ // frame's position so that SVG painting can later add it again and the
+ // frame is painted in the right place.
+ gfxPoint toUserSpaceGfx = nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(aFrame);
+ nsPoint toUserSpace =
+ nsPoint(nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.x)),
+ nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.y)));
+
+ return (offsetToBoundingBox - toUserSpace);
+}
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -3061,16 +3061,19 @@ public:
* @param aNextLineFrame assigned to first frame on the next line if such a
* next line exists, null otherwise.
*/
static bool IsInvisibleBreak(nsINode* aNode, nsIFrame** aNextLineFrame = nullptr);
static nsRect ComputeGeometryBox(nsIFrame* aFrame,
StyleGeometryBox aGeometryBox);
+ static nsPoint ComputeOffsetToUserSpace(nsDisplayListBuilder* aBuilder,
+ nsIFrame* aFrame);
+
private:
static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips;
static uint32_t sFontSizeInflationLineThreshold;
static int32_t sFontSizeInflationMappingIntercept;
static uint32_t sFontSizeInflationMaxRatio;
static bool sFontSizeInflationForceEnabled;
static bool sFontSizeInflationDisabledInMasterProcess;
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -9058,49 +9058,16 @@ ComputeClipExtsInDeviceSpace(gfxContext&
IntRect result;
ToRect(clippedFrameSurfaceRect).ToIntRect(&result);
return mozilla::gfx::Factory::CheckSurfaceSize(result.Size()) ? result
: IntRect();
}
typedef nsSVGIntegrationUtils::PaintFramesParams PaintFramesParams;
-static nsPoint
-ComputeOffsetToUserSpace(const PaintFramesParams& aParams)
-{
- nsIFrame* frame = aParams.frame;
- nsPoint offsetToBoundingBox = aParams.builder->ToReferenceFrame(frame) -
- nsSVGIntegrationUtils::GetOffsetToBoundingBox(frame);
- if (!frame->IsFrameOfType(nsIFrame::eSVG)) {
- // Snap the offset if the reference frame is not a SVG frame, since other
- // frames will be snapped to pixel when rendering.
- offsetToBoundingBox = nsPoint(
- frame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.x),
- frame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.y));
- }
-
- // After applying only "offsetToBoundingBox", aParams.ctx would have its
- // origin at the top left corner of frame's bounding box (over all
- // continuations).
- // However, SVG painting needs the origin to be located at the origin of the
- // SVG frame's "user space", i.e. the space in which, for example, the
- // frame's BBox lives.
- // SVG geometry frames and foreignObject frames apply their own offsets, so
- // their position is relative to their user space. So for these frame types,
- // if we want aCtx to be in user space, we first need to subtract the
- // frame's position so that SVG painting can later add it again and the
- // frame is painted in the right place.
- gfxPoint toUserSpaceGfx = nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(frame);
- nsPoint toUserSpace =
- nsPoint(nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.x)),
- nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.y)));
-
- return (offsetToBoundingBox - toUserSpace);
-}
-
static void
ComputeMaskGeometry(PaintFramesParams& aParams)
{
// Properties are added lazily and may have been removed by a restyle, so
// make sure all applicable ones are set again.
nsIFrame* firstFrame =
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aParams.frame);
@@ -9112,17 +9079,19 @@ ComputeMaskGeometry(PaintFramesParams& a
if (maskFrames.Length() == 0) {
return;
}
gfxContext& ctx = aParams.ctx;
nsIFrame* frame = aParams.frame;
- nsPoint offsetToUserSpace = ComputeOffsetToUserSpace(aParams);
+ nsPoint offsetToUserSpace =
+ nsLayoutUtils::ComputeOffsetToUserSpace(aParams.builder, aParams.frame);
+
gfxPoint devPixelOffsetToUserSpace =
nsLayoutUtils::PointToGfxPoint(offsetToUserSpace,
frame->PresContext()->AppUnitsPerDevPixel());
gfxContextMatrixAutoSaveRestore matSR(&ctx);
ctx.SetMatrix(ctx.CurrentMatrix().PreTranslate(devPixelOffsetToUserSpace));
// Convert boaderArea and dirtyRect to user space.