2008-09-11 04:24:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxDrawable.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsDisplayList.h"
|
2014-02-24 19:22:58 +04:00
|
|
|
#include "nsFilterInstance.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-07-20 22:12:29 +04:00
|
|
|
#include "nsSVGElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2008-10-01 04:51:05 +04:00
|
|
|
#include "nsSVGMaskFrame.h"
|
2010-08-13 17:32:27 +04:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2012-07-17 21:03:51 +04:00
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "BasicLayers.h"
|
2013-12-30 03:35:52 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2012-07-17 21:03:51 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
2014-09-12 11:20:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2012-06-21 04:29:50 +04:00
|
|
|
/**
|
|
|
|
* This class is used to get the pre-effects visual overflow rect of a frame,
|
|
|
|
* or, in the case of a frame with continuations, to collect the union of the
|
|
|
|
* pre-effects visual overflow rects of all the continuations. The result is
|
|
|
|
* relative to the origin (top left corner of the border box) of the frame, or,
|
|
|
|
* if the frame has continuations, the origin of the _first_ continuation.
|
|
|
|
*/
|
|
|
|
class PreEffectsVisualOverflowCollector : public nsLayoutUtils::BoxCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* If the pre-effects visual overflow rect of the frame being examined
|
|
|
|
* happens to be known, it can be passed in as aCurrentFrame and its
|
|
|
|
* pre-effects visual overflow rect can be passed in as
|
|
|
|
* aCurrentFrameOverflowArea. This is just an optimization to save a
|
|
|
|
* frame property lookup - these arguments are optional.
|
|
|
|
*/
|
|
|
|
PreEffectsVisualOverflowCollector(nsIFrame* aFirstContinuation,
|
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
const nsRect& aCurrentFrameOverflowArea)
|
|
|
|
: mFirstContinuation(aFirstContinuation)
|
|
|
|
, mCurrentFrame(aCurrentFrame)
|
|
|
|
, mCurrentFrameOverflowArea(aCurrentFrameOverflowArea)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mFirstContinuation->GetPrevContinuation(),
|
|
|
|
"We want the first continuation here");
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void AddBox(nsIFrame* aFrame) override {
|
2012-06-21 04:29:50 +04:00
|
|
|
nsRect overflow = (aFrame == mCurrentFrame) ?
|
|
|
|
mCurrentFrameOverflowArea : GetPreEffectsVisualOverflowRect(aFrame);
|
|
|
|
mResult.UnionRect(mResult, overflow + aFrame->GetOffsetTo(mFirstContinuation));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetResult() const {
|
|
|
|
return mResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static nsRect GetPreEffectsVisualOverflowRect(nsIFrame* aFrame) {
|
|
|
|
nsRect* r = static_cast<nsRect*>
|
|
|
|
(aFrame->Properties().Get(nsIFrame::PreEffectsBBoxProperty()));
|
|
|
|
if (r) {
|
|
|
|
return *r;
|
|
|
|
}
|
|
|
|
// Despite the fact that we're invoked for frames with SVG effects applied,
|
2014-02-07 05:45:33 +04:00
|
|
|
// we can actually get here. All continuations and IB split siblings of a
|
2012-06-21 04:29:50 +04:00
|
|
|
// frame with SVG effects applied will have the PreEffectsBBoxProperty
|
|
|
|
// property set on them. Therefore, the frames that are passed to us will
|
|
|
|
// always have that property set...well, with one exception. If the frames
|
|
|
|
// for an element with SVG effects applied have been subject to an "IB
|
|
|
|
// split", then the block frame(s) that caused the split will have been
|
|
|
|
// wrapped in anonymous, inline-block, nsBlockFrames of pseudo-type
|
2014-02-07 05:45:33 +04:00
|
|
|
// nsCSSAnonBoxes::mozAnonymousBlock. These "IB split sibling" anonymous
|
2012-06-21 04:29:50 +04:00
|
|
|
// blocks will have the PreEffectsBBoxProperty property set on them, but
|
|
|
|
// they will never be passed to us. Instead, we'll be passed the block
|
|
|
|
// children that they wrap, which don't have the PreEffectsBBoxProperty
|
|
|
|
// property set on them. This is actually okay. What we care about is
|
|
|
|
// collecting the _pre_ effects visual overflow rects of the frames to
|
|
|
|
// which the SVG effects have been applied. Since the IB split results in
|
|
|
|
// any overflow rect adjustments for transforms, effects, etc. taking
|
|
|
|
// place on the anonymous block wrappers, the wrapped children are left
|
|
|
|
// with their overflow rects unaffected. In other words, calling
|
|
|
|
// GetVisualOverflowRect() on the children will return their pre-effects
|
|
|
|
// visual overflow rects, just as we need.
|
|
|
|
//
|
|
|
|
// A couple of tests that demonstrate the IB split and cause us to get here
|
|
|
|
// are:
|
|
|
|
//
|
|
|
|
// * reftests/svg/svg-integration/clipPath-html-06.xhtml
|
|
|
|
// * reftests/svg/svg-integration/clipPath-html-06-extref.xhtml
|
|
|
|
//
|
|
|
|
// If we ever got passed a frame with the PreTransformOverflowAreasProperty
|
|
|
|
// property set, that would be bad, since then our GetVisualOverflowRect()
|
|
|
|
// call would give us the post-effects, and post-transform, overflow rect.
|
|
|
|
//
|
2013-02-16 09:38:33 +04:00
|
|
|
NS_ASSERTION(aFrame->GetParent()->StyleContext()->GetPseudo() ==
|
2012-06-21 04:29:50 +04:00
|
|
|
nsCSSAnonBoxes::mozAnonymousBlock,
|
|
|
|
"How did we getting here, then?");
|
|
|
|
NS_ASSERTION(!aFrame->Properties().Get(
|
|
|
|
aFrame->PreTransformOverflowAreasProperty()),
|
|
|
|
"GetVisualOverflowRect() won't return the pre-effects rect!");
|
|
|
|
return aFrame->GetVisualOverflowRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* mFirstContinuation;
|
|
|
|
nsIFrame* mCurrentFrame;
|
|
|
|
const nsRect& mCurrentFrameOverflowArea;
|
|
|
|
nsRect mResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the union of the pre-effects visual overflow rects of all of a frame's
|
|
|
|
* continuations, in "user space".
|
|
|
|
*/
|
|
|
|
static nsRect
|
|
|
|
GetPreEffectsVisualOverflowUnion(nsIFrame* aFirstContinuation,
|
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
const nsRect& aCurrentFramePreEffectsOverflow,
|
|
|
|
const nsPoint& aFirstContinuationToUserSpace)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aFirstContinuation->GetPrevContinuation(),
|
|
|
|
"Need first continuation here");
|
|
|
|
PreEffectsVisualOverflowCollector collector(aFirstContinuation,
|
|
|
|
aCurrentFrame,
|
|
|
|
aCurrentFramePreEffectsOverflow);
|
|
|
|
// Compute union of all overflow areas relative to aFirstContinuation:
|
|
|
|
nsLayoutUtils::GetAllInFlowBoxes(aFirstContinuation, &collector);
|
|
|
|
// Return the result in user space:
|
|
|
|
return collector.GetResult() + aFirstContinuationToUserSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGIntegrationUtils::UsingEffectsForFrame(const nsIFrame* aFrame)
|
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
// Even when SVG display lists are disabled, returning true for SVG frames
|
|
|
|
// does not adversely affect any of our callers. Therefore we don't bother
|
|
|
|
// checking the SDL prefs here, since we don't know if we're being called for
|
|
|
|
// painting or hit-testing anyway.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVGReset *style = aFrame->StyleSVGReset();
|
2014-09-28 03:56:00 +04:00
|
|
|
return (style->HasFilters() ||
|
|
|
|
style->mClipPath.GetType() != NS_STYLE_CLIP_PATH_NONE || style->mMask);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
// For non-SVG frames, this gives the offset to the frame's "user space".
|
|
|
|
// For SVG frames, this returns a zero offset.
|
|
|
|
static nsPoint
|
|
|
|
GetOffsetToBoundingBox(nsIFrame* aFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
|
|
|
// Do NOT call GetAllInFlowRectsUnion for SVG - it will get the
|
|
|
|
// covered region relative to the nsSVGOuterSVGFrame, which is absolutely
|
|
|
|
// not what we want. SVG frames are always in user space, so they have
|
|
|
|
// no offset adjustment to make.
|
|
|
|
return nsPoint();
|
|
|
|
}
|
2012-06-19 19:28:04 +04:00
|
|
|
// We could allow aFrame to be any continuation, but since that would require
|
|
|
|
// a GetPrevContinuation() virtual call and conditional returns, and since
|
|
|
|
// all our current consumers always pass in the first continuation, we don't
|
|
|
|
// currently bother.
|
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(), "Not first continuation");
|
|
|
|
|
|
|
|
// The GetAllInFlowRectsUnion() call gets the union of the frame border-box
|
|
|
|
// rects over all continuations, relative to the origin (top-left of the
|
|
|
|
// border box) of its second argument (here, aFrame, the first continuation).
|
|
|
|
return -nsLayoutUtils::GetAllInFlowRectsUnion(aFrame, aFrame).TopLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsSize
|
|
|
|
nsSVGIntegrationUtils::GetContinuationUnionSize(nsIFrame* aNonSVGFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
return nsLayoutUtils::GetAllInFlowRectsUnion(firstFrame, firstFrame).Size();
|
|
|
|
}
|
|
|
|
|
2013-12-30 03:35:52 +04:00
|
|
|
/* static */ gfx::Size
|
2012-06-19 19:28:04 +04:00
|
|
|
nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
nsRect r = nsLayoutUtils::GetAllInFlowRectsUnion(firstFrame, firstFrame);
|
|
|
|
nsPresContext* presContext = firstFrame->PresContext();
|
2013-12-30 03:35:52 +04:00
|
|
|
return gfx::Size(presContext->AppUnitsToFloatCSSPixels(r.width),
|
|
|
|
presContext->AppUnitsToFloatCSSPixels(r.height));
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 04:29:50 +04:00
|
|
|
gfxRect
|
|
|
|
nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-06-21 04:29:50 +04:00
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-21 04:29:50 +04:00
|
|
|
// 'r' is in "user space":
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRect r = GetPreEffectsVisualOverflowUnion(firstFrame, nullptr, nsRect(),
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
GetOffsetToBoundingBox(firstFrame));
|
2012-06-21 04:29:50 +04:00
|
|
|
return nsLayoutUtils::RectToGfxRect(r,
|
|
|
|
aNonSVGFrame->PresContext()->AppUnitsPerCSSPixel());
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2012-06-22 14:42:05 +04:00
|
|
|
// XXX Since we're called during reflow, this method is broken for frames with
|
|
|
|
// continuations. When we're called for a frame with continuations, we're
|
|
|
|
// called for each continuation in turn as it's reflowed. However, it isn't
|
|
|
|
// until the last continuation is reflowed that this method's
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
// GetOffsetToBoundingBox() and GetPreEffectsVisualOverflowUnion() calls will
|
2012-06-22 14:42:05 +04:00
|
|
|
// obtain valid border boxes for all the continuations. As a result, we'll
|
|
|
|
// end up returning bogus post-filter visual overflow rects for all the prior
|
|
|
|
// continuations. Unfortunately, by the time the last continuation is
|
|
|
|
// reflowed, it's too late to go back and set and propagate the overflow
|
|
|
|
// rects on the previous continuations.
|
|
|
|
//
|
|
|
|
// The reason that we need to pass an override bbox to
|
|
|
|
// GetPreEffectsVisualOverflowUnion rather than just letting it call into our
|
|
|
|
// GetSVGBBoxForNonSVGFrame method is because we get called by
|
2014-02-15 09:29:12 +04:00
|
|
|
// ComputeEffectsRect when it has been called with
|
2012-06-22 14:42:05 +04:00
|
|
|
// aStoreRectProperties set to false. In this case the pre-effects visual
|
|
|
|
// overflow rect that it has been passed may be different to that stored on
|
|
|
|
// aFrame, resulting in a different bbox.
|
|
|
|
//
|
|
|
|
// XXXjwatt The pre-effects visual overflow rect passed to
|
2014-02-15 09:29:12 +04:00
|
|
|
// ComputeEffectsRect won't include continuation overflows, so
|
2012-06-22 14:42:05 +04:00
|
|
|
// for frames with continuation the following filter analysis will likely end
|
|
|
|
// up being carried out with a bbox created as if the frame didn't have
|
|
|
|
// continuations.
|
|
|
|
//
|
|
|
|
// XXXjwatt Using aPreEffectsOverflowRect to create the bbox isn't really right
|
|
|
|
// for SVG frames, since for SVG frames the SVG spec defines the bbox to be
|
|
|
|
// something quite different to the pre-effects visual overflow rect. However,
|
|
|
|
// we're essentially calculating an invalidation area here, and using the
|
|
|
|
// pre-effects overflow rect will actually overestimate that area which, while
|
|
|
|
// being a bit wasteful, isn't otherwise a problem.
|
|
|
|
//
|
2008-09-11 04:24:16 +04:00
|
|
|
nsRect
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGIntegrationUtils::
|
|
|
|
ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame,
|
|
|
|
const nsRect& aPreEffectsOverflowRect)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-06-21 04:29:50 +04:00
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT),
|
|
|
|
"Don't call this on SVG child frames");
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
2014-02-24 19:22:58 +04:00
|
|
|
if (!effectProperties.HasValidFilter()) {
|
2012-06-21 04:29:50 +04:00
|
|
|
return aPreEffectsOverflowRect;
|
2014-02-24 19:22:58 +04:00
|
|
|
}
|
2012-06-21 04:29:50 +04:00
|
|
|
|
2012-06-22 14:42:05 +04:00
|
|
|
// Create an override bbox - see comment above:
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
nsPoint firstFrameToBoundingBox = GetOffsetToBoundingBox(firstFrame);
|
2012-06-23 07:01:36 +04:00
|
|
|
// overrideBBox is in "user space", in _CSS_ pixels:
|
2012-06-22 14:42:05 +04:00
|
|
|
// XXX Why are we rounding out to pixel boundaries? We don't do that in
|
|
|
|
// GetSVGBBoxForNonSVGFrame, and it doesn't appear to be necessary.
|
2012-06-23 07:01:36 +04:00
|
|
|
gfxRect overrideBBox =
|
|
|
|
nsLayoutUtils::RectToGfxRect(
|
|
|
|
GetPreEffectsVisualOverflowUnion(firstFrame, aFrame,
|
|
|
|
aPreEffectsOverflowRect,
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
firstFrameToBoundingBox),
|
2012-06-23 07:01:36 +04:00
|
|
|
aFrame->PresContext()->AppUnitsPerCSSPixel());
|
|
|
|
overrideBBox.RoundOut();
|
2012-06-21 04:29:50 +04:00
|
|
|
|
|
|
|
nsRect overflowRect =
|
2014-02-24 19:22:58 +04:00
|
|
|
nsFilterInstance::GetPostFilterBounds(firstFrame, &overrideBBox);
|
2012-06-21 04:29:50 +04:00
|
|
|
|
|
|
|
// Return overflowRect relative to aFrame, rather than "user space":
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
return overflowRect - (aFrame->GetOffsetTo(firstFrame) + firstFrameToBoundingBox);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2014-04-24 12:25:17 +04:00
|
|
|
nsIntRegion
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGIntegrationUtils::AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame,
|
2012-11-28 08:06:07 +04:00
|
|
|
const nsPoint& aToReferenceFrame,
|
2014-04-24 12:25:17 +04:00
|
|
|
const nsIntRegion& aInvalidRegion)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2014-04-24 12:25:17 +04:00
|
|
|
if (aInvalidRegion.IsEmpty()) {
|
2013-09-06 13:30:27 +04:00
|
|
|
return nsIntRect();
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
// Don't bother calling GetEffectProperties; the filter property should
|
|
|
|
// already have been set up during reflow/ComputeFrameEffectsRect
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2010-11-11 00:18:11 +03:00
|
|
|
nsSVGFilterProperty *prop = nsSVGEffects::GetFilterProperty(firstFrame);
|
2014-02-10 08:31:03 +04:00
|
|
|
if (!prop || !prop->IsInObserverLists()) {
|
2014-04-24 12:25:17 +04:00
|
|
|
return aInvalidRegion;
|
2010-11-10 08:50:29 +03:00
|
|
|
}
|
|
|
|
|
2012-08-29 09:39:33 +04:00
|
|
|
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
if (!prop || !prop->ReferencesValidResources()) {
|
2008-12-12 11:25:16 +03:00
|
|
|
// The frame is either not there or not currently available,
|
|
|
|
// perhaps because we're in the middle of tearing stuff down.
|
2012-11-28 08:06:07 +04:00
|
|
|
// Be conservative, return our visual overflow rect relative
|
|
|
|
// to the reference frame.
|
|
|
|
nsRect overflow = aFrame->GetVisualOverflowRect() + aToReferenceFrame;
|
2012-08-29 09:39:33 +04:00
|
|
|
return overflow.ToOutsidePixels(appUnitsPerDevPixel);
|
2008-12-12 11:25:16 +03:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-04-24 12:25:17 +04:00
|
|
|
// Convert aInvalidRegion into bounding box frame space in app units:
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
nsPoint toBoundingBox =
|
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2012-11-28 08:06:07 +04:00
|
|
|
// The initial rect was relative to the reference frame, so we need to
|
|
|
|
// remove that offset to get a rect relative to the current frame.
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
toBoundingBox -= aToReferenceFrame;
|
2014-04-24 12:25:17 +04:00
|
|
|
nsRegion preEffectsRegion = aInvalidRegion.ToAppUnits(appUnitsPerDevPixel).MovedBy(toBoundingBox);
|
2012-06-19 19:28:04 +04:00
|
|
|
|
2012-11-28 08:06:07 +04:00
|
|
|
// Adjust the dirty area for effects, and shift it back to being relative to
|
|
|
|
// the reference frame.
|
2014-04-24 12:25:17 +04:00
|
|
|
nsRegion result = nsFilterInstance::GetPostFilterDirtyArea(firstFrame,
|
|
|
|
preEffectsRegion).MovedBy(-toBoundingBox);
|
2012-11-28 08:06:07 +04:00
|
|
|
// Return the result, in pixels relative to the reference frame.
|
2012-08-29 09:39:33 +04:00
|
|
|
return result.ToOutsidePixels(appUnitsPerDevPixel);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(nsIFrame* aFrame,
|
2012-06-19 19:28:04 +04:00
|
|
|
const nsRect& aDirtyRect)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
// Don't bother calling GetEffectProperties; the filter property should
|
|
|
|
// already have been set up during reflow/ComputeFrameEffectsRect
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterProperty *prop = nsSVGEffects::GetFilterProperty(firstFrame);
|
|
|
|
if (!prop || !prop->ReferencesValidResources()) {
|
2012-06-19 19:28:04 +04:00
|
|
|
return aDirtyRect;
|
2014-02-24 19:22:58 +04:00
|
|
|
}
|
2014-08-01 04:37:35 +04:00
|
|
|
|
2012-06-26 14:49:23 +04:00
|
|
|
// Convert aDirtyRect into "user space" in app units:
|
2012-06-19 19:28:04 +04:00
|
|
|
nsPoint toUserSpace =
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2012-06-26 14:49:23 +04:00
|
|
|
nsRect postEffectsRect = aDirtyRect + toUserSpace;
|
2012-06-19 19:28:04 +04:00
|
|
|
|
2012-06-26 14:49:23 +04:00
|
|
|
// Return ther result, relative to aFrame, not in user space:
|
2014-04-24 12:25:17 +04:00
|
|
|
return nsFilterInstance::GetPreFilterNeededArea(firstFrame, postEffectsRect).GetBounds()
|
2014-02-24 19:22:58 +04:00
|
|
|
- toUserSpace;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGIntegrationUtils::HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt)
|
|
|
|
{
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
// Convert aPt to user space:
|
2013-01-04 15:48:12 +04:00
|
|
|
nsPoint toUserSpace;
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
// XXXmstange Isn't this wrong for svg:use and innerSVG frames?
|
2013-01-04 15:48:12 +04:00
|
|
|
toUserSpace = aFrame->GetPosition();
|
|
|
|
} else {
|
|
|
|
toUserSpace =
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2013-01-04 15:48:12 +04:00
|
|
|
}
|
2012-06-19 19:28:04 +04:00
|
|
|
nsPoint pt = aPt + toUserSpace;
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxPoint userSpacePt =
|
|
|
|
gfxPoint(pt.x, pt.y) / aFrame->PresContext()->AppUnitsPerCSSPixel();
|
|
|
|
return nsSVGUtils::HitTestClip(firstFrame, userSpacePt);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class RegularFramePaintCallback : public nsSVGFilterPaintCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RegularFramePaintCallback(nsDisplayListBuilder* aBuilder,
|
2012-07-17 21:03:51 +04:00
|
|
|
LayerManager* aManager,
|
2008-09-11 04:24:16 +04:00
|
|
|
const nsPoint& aOffset)
|
2012-07-17 21:03:51 +04:00
|
|
|
: mBuilder(aBuilder), mLayerManager(aManager),
|
2010-03-10 23:55:05 +03:00
|
|
|
mOffset(aOffset) {}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
virtual void Paint(gfxContext& aContext, nsIFrame *aTarget,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsIntRect* aDirtyRect) override
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-07-17 21:03:51 +04:00
|
|
|
BasicLayerManager* basic = static_cast<BasicLayerManager*>(mLayerManager);
|
2014-10-31 23:08:54 +03:00
|
|
|
basic->SetTarget(&aContext);
|
2014-09-11 10:48:09 +04:00
|
|
|
|
|
|
|
gfxPoint devPixelOffset =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(-mOffset,
|
|
|
|
aTarget->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore autoSR(&aContext);
|
|
|
|
aContext.SetMatrix(aContext.CurrentMatrix().Translate(devPixelOffset));
|
2014-09-11 10:48:09 +04:00
|
|
|
|
2014-09-26 21:06:08 +04:00
|
|
|
mLayerManager->EndTransaction(FrameLayerBuilder::DrawPaintedLayer, mBuilder);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDisplayListBuilder* mBuilder;
|
2012-07-17 21:03:51 +04:00
|
|
|
LayerManager* mLayerManager;
|
2008-09-11 04:24:16 +04:00
|
|
|
nsPoint mOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2014-10-31 23:08:54 +03:00
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(gfxContext& aContext,
|
2012-06-28 23:51:09 +04:00
|
|
|
nsIFrame* aFrame,
|
2008-09-11 04:24:16 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2012-07-17 21:03:51 +04:00
|
|
|
LayerManager *aLayerManager)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2012-07-31 03:20:06 +04:00
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
|
2012-07-20 22:12:29 +04:00
|
|
|
(NS_SVGDisplayListPaintingEnabled() &&
|
2013-07-12 11:13:07 +04:00
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)),
|
2012-07-20 22:12:29 +04:00
|
|
|
"Should not use nsSVGIntegrationUtils on this SVG frame");
|
2009-01-12 22:20:59 +03:00
|
|
|
#endif
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
/* SVG defines the following rendering model:
|
|
|
|
*
|
|
|
|
* 1. Render geometry
|
|
|
|
* 2. Apply filter
|
|
|
|
* 3. Apply clipping, masking, group opacity
|
|
|
|
*
|
|
|
|
* We follow this, but perform a couple of optimizations:
|
|
|
|
*
|
|
|
|
* + Use cairo's clipPath when representable natively (single object
|
|
|
|
* clip region).
|
|
|
|
*
|
|
|
|
* + Merge opacity and masking if both used together.
|
|
|
|
*/
|
|
|
|
|
2012-07-20 22:12:29 +04:00
|
|
|
const nsIContent* content = aFrame->GetContent();
|
|
|
|
bool hasSVGLayout = (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT);
|
|
|
|
if (hasSVGLayout) {
|
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!svgChildFrame || !aFrame->GetContent()->IsSVGElement()) {
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(false, "why?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
return; // The SVG spec says not to draw _anything_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
float opacity = aFrame->StyleDisplay()->mOpacity;
|
2012-06-21 04:29:50 +04:00
|
|
|
if (opacity == 0.0f) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-20 22:12:29 +04:00
|
|
|
if (opacity != 1.0f &&
|
|
|
|
hasSVGLayout && nsSVGUtils::CanOptimizeOpacity(aFrame)) {
|
|
|
|
opacity = 1.0f;
|
|
|
|
}
|
2012-06-21 04:29:50 +04:00
|
|
|
|
|
|
|
/* Properties are added lazily and may have been removed by a restyle,
|
|
|
|
so make sure all applicable ones are set again. */
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
bool isOK = effectProperties.HasNoFilterOrHasValidFilter();
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
nsSVGMaskFrame *maskFrame = effectProperties.GetMaskFrame(&isOK);
|
2008-09-11 04:24:16 +04:00
|
|
|
if (!isOK) {
|
2012-06-21 04:29:50 +04:00
|
|
|
return; // Some resource is missing. We shouldn't paint anything.
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 04:29:50 +04:00
|
|
|
bool isTrivialClip = clipPathFrame ? clipPathFrame->IsTrivial() : true;
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
DrawTarget* drawTarget = aContext.GetDrawTarget();
|
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(&aContext);
|
2012-03-02 12:28:59 +04:00
|
|
|
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
nsPoint firstFrameOffset = GetOffsetToBoundingBox(firstFrame);
|
2014-04-23 13:47:54 +04:00
|
|
|
nsPoint offsetToBoundingBox = aBuilder->ToReferenceFrame(firstFrame) - firstFrameOffset;
|
|
|
|
if (!firstFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2013-07-24 17:03:11 +04:00
|
|
|
/* Snap the offset if the reference frame is not a SVG frame,
|
|
|
|
* since other frames will be snapped to pixel when rendering. */
|
2014-04-23 13:47:54 +04:00
|
|
|
offsetToBoundingBox = nsPoint(
|
|
|
|
aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.x),
|
|
|
|
aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.y));
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:47:54 +04:00
|
|
|
// After applying only "offsetToBoundingBox", aCtx would have its origin at
|
|
|
|
// the top left corner of aFrame'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(aFrame);
|
|
|
|
nsPoint toUserSpace(nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.x)),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.y)));
|
|
|
|
nsPoint offsetToUserSpace = offsetToBoundingBox - toUserSpace;
|
|
|
|
|
|
|
|
NS_ASSERTION(hasSVGLayout || offsetToBoundingBox == offsetToUserSpace,
|
|
|
|
"For non-SVG frames there shouldn't be any additional offset");
|
|
|
|
|
2014-09-11 10:48:10 +04:00
|
|
|
gfxPoint devPixelOffsetToUserSpace =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(offsetToUserSpace,
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel());
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.SetMatrix(aContext.CurrentMatrix().Translate(devPixelOffsetToUserSpace));
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2012-06-28 23:51:09 +04:00
|
|
|
gfxMatrix cssPxToDevPxMatrix = GetCSSPxToDevPxMatrix(aFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool complexEffects = false;
|
2008-09-11 04:24:16 +04:00
|
|
|
/* Check if we need to do additional operations on this child's
|
|
|
|
* rendering, which necessitates rendering into another surface. */
|
2013-09-15 07:40:11 +04:00
|
|
|
if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)
|
|
|
|
|| aFrame->StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2011-10-17 18:59:28 +04:00
|
|
|
complexEffects = true;
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Save();
|
2014-10-20 13:55:48 +04:00
|
|
|
nsRect clipRect =
|
|
|
|
aFrame->GetVisualOverflowRectRelativeToSelf() + toUserSpace;
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Clip(NSRectToSnappedRect(clipRect,
|
2014-10-22 15:29:06 +04:00
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
*drawTarget));
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If this frame has only a trivial clipPath, set up cairo's clipping now so
|
|
|
|
* we can just do normal painting and get it clipped appropriately.
|
|
|
|
*/
|
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Save();
|
|
|
|
clipPathFrame->ApplyClipOrPaintClipMask(aContext, aFrame, cssPxToDevPxMatrix);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint the child */
|
2014-02-24 19:22:58 +04:00
|
|
|
if (effectProperties.HasValidFilter()) {
|
2012-07-17 21:03:51 +04:00
|
|
|
RegularFramePaintCallback callback(aBuilder, aLayerManager,
|
2014-04-23 13:47:54 +04:00
|
|
|
offsetToUserSpace);
|
|
|
|
|
2014-04-24 12:25:17 +04:00
|
|
|
nsRegion dirtyRegion = aDirtyRect - offsetToBoundingBox;
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix tm = nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
|
2014-10-31 23:08:54 +03:00
|
|
|
nsFilterInstance::PaintFilteredFrame(aFrame, aContext, tm, &callback, &dirtyRegion);
|
2008-09-11 04:24:16 +04:00
|
|
|
} else {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.SetMatrix(matrixAutoSaveRestore.Matrix());
|
2014-09-26 21:06:08 +04:00
|
|
|
aLayerManager->EndTransaction(FrameLayerBuilder::DrawPaintedLayer, aBuilder);
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.SetMatrix(aContext.CurrentMatrix().Translate(devPixelOffsetToUserSpace));
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Restore();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No more effects, we're done. */
|
|
|
|
if (!complexEffects) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.PopGroupToSource();
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-09-12 11:20:12 +04:00
|
|
|
Matrix maskTransform;
|
|
|
|
RefPtr<SourceSurface> maskSurface =
|
2014-10-31 23:08:54 +03:00
|
|
|
maskFrame ? maskFrame->GetMaskForMaskedFrame(&aContext,
|
2014-06-23 08:45:31 +04:00
|
|
|
aFrame, cssPxToDevPxMatrix,
|
2014-09-12 11:20:12 +04:00
|
|
|
opacity, &maskTransform)
|
2014-06-23 08:45:31 +04:00
|
|
|
: nullptr;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
if (clipPathFrame && !isTrivialClip) {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
nsresult rv = clipPathFrame->ApplyClipOrPaintClipMask(aContext, aFrame, cssPxToDevPxMatrix);
|
2014-09-12 11:20:12 +04:00
|
|
|
Matrix clippedMaskTransform;
|
2014-10-31 23:08:54 +03:00
|
|
|
RefPtr<SourceSurface> clipMaskSurface = aContext.PopGroupToSurface(&clippedMaskTransform);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && clipMaskSurface) {
|
|
|
|
// Still more set after clipping, so clip to another surface
|
|
|
|
if (maskSurface || opacity != 1.0f) {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
|
|
|
aContext.Mask(clipMaskSurface, clippedMaskTransform);
|
|
|
|
aContext.PopGroupToSource();
|
2008-09-11 04:24:16 +04:00
|
|
|
} else {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Mask(clipMaskSurface, clippedMaskTransform);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maskSurface) {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Mask(maskSurface, maskTransform);
|
2014-10-17 22:37:54 +04:00
|
|
|
} else if (opacity != 1.0f ||
|
|
|
|
aFrame->StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Paint(opacity);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
aContext.Restore();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2009-07-23 12:35:59 +04:00
|
|
|
gfxMatrix
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = aNonSVGFrame->PresContext()->AppUnitsPerDevPixel();
|
2008-09-11 04:24:16 +04:00
|
|
|
float devPxPerCSSPx =
|
|
|
|
1 / nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPixel);
|
2009-07-23 12:35:59 +04:00
|
|
|
|
|
|
|
return gfxMatrix(devPxPerCSSPx, 0.0,
|
|
|
|
0.0, devPxPerCSSPx,
|
|
|
|
0.0, 0.0);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 17:32:27 +04:00
|
|
|
class PaintFrameCallback : public gfxDrawingCallback {
|
|
|
|
public:
|
|
|
|
PaintFrameCallback(nsIFrame* aFrame,
|
|
|
|
const nsSize aPaintServerSize,
|
2013-08-02 00:42:34 +04:00
|
|
|
const gfxIntSize aRenderSize,
|
|
|
|
uint32_t aFlags)
|
2010-08-13 17:32:27 +04:00
|
|
|
: mFrame(aFrame)
|
|
|
|
, mPaintServerSize(aPaintServerSize)
|
|
|
|
, mRenderSize(aRenderSize)
|
2013-08-02 00:42:34 +04:00
|
|
|
, mFlags (aFlags)
|
2010-08-13 17:32:27 +04:00
|
|
|
{}
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool operator()(gfxContext* aContext,
|
2010-08-13 17:32:27 +04:00
|
|
|
const gfxRect& aFillRect,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2015-03-21 19:28:04 +03:00
|
|
|
const gfxMatrix& aTransform) override;
|
2010-08-13 17:32:27 +04:00
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nsSize mPaintServerSize;
|
|
|
|
gfxIntSize mRenderSize;
|
2013-08-02 00:42:34 +04:00
|
|
|
uint32_t mFlags;
|
2010-08-13 17:32:27 +04:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-13 17:32:27 +04:00
|
|
|
PaintFrameCallback::operator()(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
2013-10-02 01:01:19 +04:00
|
|
|
const GraphicsFilter& aFilter,
|
2010-08-13 17:32:27 +04:00
|
|
|
const gfxMatrix& aTransform)
|
|
|
|
{
|
|
|
|
if (mFrame->GetStateBits() & NS_FRAME_DRAWING_AS_PAINTSERVER)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
mFrame->AddStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
|
|
|
|
|
|
|
aContext->Save();
|
|
|
|
|
|
|
|
// Clip to aFillRect so that we don't paint outside.
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(aFillRect);
|
|
|
|
aContext->Clip();
|
|
|
|
|
2014-07-11 11:06:39 +04:00
|
|
|
gfxMatrix invmatrix = aTransform;
|
|
|
|
if (!invmatrix.Invert()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aContext->Multiply(invmatrix);
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
// nsLayoutUtils::PaintFrame will anchor its painting at mFrame. But we want
|
|
|
|
// to have it anchored at the top left corner of the bounding box of all of
|
|
|
|
// mFrame's continuations. So we add a translation transform.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
nsPoint offset = GetOffsetToBoundingBox(mFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
gfxPoint devPxOffset = gfxPoint(offset.x, offset.y) / appUnitsPerDevPixel;
|
2014-09-10 17:26:12 +04:00
|
|
|
aContext->Multiply(gfxMatrix::Translation(devPxOffset));
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
gfxSize paintServerSize =
|
|
|
|
gfxSize(mPaintServerSize.width, mPaintServerSize.height) /
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
// nsLayoutUtils::PaintFrame wants to render with paintServerSize, but we
|
|
|
|
// want it to render with mRenderSize, so we need to set up a scale transform.
|
|
|
|
gfxFloat scaleX = mRenderSize.width / paintServerSize.width;
|
|
|
|
gfxFloat scaleY = mRenderSize.height / paintServerSize.height;
|
2014-09-10 17:26:12 +04:00
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scaleX, scaleY));
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
// Draw.
|
2012-06-19 19:28:04 +04:00
|
|
|
nsRect dirty(-offset.x, -offset.y,
|
|
|
|
mPaintServerSize.width, mPaintServerSize.height);
|
2013-08-02 00:42:34 +04:00
|
|
|
|
|
|
|
uint32_t flags = nsLayoutUtils::PAINT_IN_TRANSFORM |
|
|
|
|
nsLayoutUtils::PAINT_ALL_CONTINUATIONS;
|
|
|
|
if (mFlags & nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES) {
|
|
|
|
flags |= nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES;
|
|
|
|
}
|
2014-10-31 23:08:49 +03:00
|
|
|
nsRenderingContext context(aContext);
|
|
|
|
nsLayoutUtils::PaintFrame(&context, mFrame,
|
2010-08-13 17:32:27 +04:00
|
|
|
dirty, NS_RGBA(0, 0, 0, 0),
|
2013-08-02 00:42:34 +04:00
|
|
|
flags);
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
aContext->Restore();
|
|
|
|
|
|
|
|
mFrame->RemoveStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-08-13 17:32:27 +04:00
|
|
|
}
|
|
|
|
|
2014-01-31 07:36:42 +04:00
|
|
|
/* static */ already_AddRefed<gfxDrawable>
|
|
|
|
nsSVGIntegrationUtils::DrawableFromPaintServer(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aTarget,
|
|
|
|
const nsSize& aPaintServerSize,
|
|
|
|
const gfxIntSize& aRenderSize,
|
2014-09-29 17:15:19 +04:00
|
|
|
const DrawTarget* aDrawTarget,
|
2014-01-31 07:36:42 +04:00
|
|
|
const gfxMatrix& aContextMatrix,
|
|
|
|
uint32_t aFlags)
|
2010-08-13 17:32:27 +04:00
|
|
|
{
|
|
|
|
// aPaintServerSize is the size that would be filled when using
|
|
|
|
// background-repeat:no-repeat and background-size:auto. For normal background
|
|
|
|
// images, this would be the intrinsic size of the image; for gradients and
|
|
|
|
// patterns this would be the whole target frame fill area.
|
|
|
|
// aRenderSize is what we will be actually filling after accounting for
|
|
|
|
// background-size.
|
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGPaintServer)) {
|
|
|
|
// aFrame is either a pattern or a gradient. These fill the whole target
|
|
|
|
// frame by default, so aPaintServerSize is the whole target background fill
|
|
|
|
// area.
|
|
|
|
nsSVGPaintServerFrame* server =
|
|
|
|
static_cast<nsSVGPaintServerFrame*>(aFrame);
|
|
|
|
|
|
|
|
gfxRect overrideBounds(0, 0,
|
|
|
|
aPaintServerSize.width, aPaintServerSize.height);
|
|
|
|
overrideBounds.ScaleInverse(aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
nsRefPtr<gfxPattern> pattern =
|
2014-09-29 17:15:19 +04:00
|
|
|
server->GetPaintServerPattern(aTarget, aDrawTarget,
|
|
|
|
aContextMatrix, &nsStyleSVG::mFill, 1.0,
|
|
|
|
&overrideBounds);
|
2010-08-13 17:32:27 +04:00
|
|
|
|
2010-09-06 07:12:46 +04:00
|
|
|
if (!pattern)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-06 07:12:46 +04:00
|
|
|
|
2010-08-13 17:32:27 +04:00
|
|
|
// pattern is now set up to fill aPaintServerSize. But we want it to
|
|
|
|
// fill aRenderSize, so we need to add a scaling transform.
|
|
|
|
// We couldn't just have set overrideBounds to aRenderSize - it would have
|
|
|
|
// worked for gradients, but for patterns it would result in a different
|
|
|
|
// pattern size.
|
|
|
|
gfxFloat scaleX = overrideBounds.Width() / aRenderSize.width;
|
|
|
|
gfxFloat scaleY = overrideBounds.Height() / aRenderSize.height;
|
2014-07-11 11:07:07 +04:00
|
|
|
gfxMatrix scaleMatrix = gfxMatrix::Scaling(scaleX, scaleY);
|
|
|
|
pattern->SetMatrix(scaleMatrix * pattern->GetMatrix());
|
2010-08-13 17:32:27 +04:00
|
|
|
nsRefPtr<gfxDrawable> drawable =
|
|
|
|
new gfxPatternDrawable(pattern, aRenderSize);
|
|
|
|
return drawable.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want to paint into a surface as long as we don't need to, so we
|
|
|
|
// set up a drawing callback.
|
|
|
|
nsRefPtr<gfxDrawingCallback> cb =
|
2013-08-02 00:42:34 +04:00
|
|
|
new PaintFrameCallback(aFrame, aPaintServerSize, aRenderSize, aFlags);
|
2010-08-13 17:32:27 +04:00
|
|
|
nsRefPtr<gfxDrawable> drawable = new gfxCallbackDrawable(cb, aRenderSize);
|
|
|
|
return drawable.forget();
|
|
|
|
}
|