2008-09-10 17:24:16 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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-10 17:24:16 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxDrawable.h"
|
2013-03-02 16:31:48 -08:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsDisplayList.h"
|
2014-02-24 07:22:58 -08:00
|
|
|
#include "nsFilterInstance.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2012-07-20 11:12:29 -07:00
|
|
|
#include "nsSVGElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2008-09-30 17:51:05 -07:00
|
|
|
#include "nsSVGMaskFrame.h"
|
2010-08-13 06:32:27 -07:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2012-07-17 10:03:51 -07:00
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "BasicLayers.h"
|
2013-12-29 15:35:52 -08:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2012-07-17 10:03:51 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
2008-09-10 17:24:16 -07:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2012-06-20 17:29:50 -07: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");
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual void AddBox(nsIFrame* aFrame) MOZ_OVERRIDE {
|
2012-06-20 17:29:50 -07: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-06 17:45:33 -08:00
|
|
|
// we can actually get here. All continuations and IB split siblings of a
|
2012-06-20 17:29:50 -07: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-06 17:45:33 -08:00
|
|
|
// nsCSSAnonBoxes::mozAnonymousBlock. These "IB split sibling" anonymous
|
2012-06-20 17:29:50 -07: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-15 21:38:33 -08:00
|
|
|
NS_ASSERTION(aFrame->GetParent()->StyleContext()->GetPseudo() ==
|
2012-06-20 17:29:50 -07: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-28 23:19:26 -07:00
|
|
|
bool
|
2008-09-10 17:24:16 -07:00
|
|
|
nsSVGIntegrationUtils::UsingEffectsForFrame(const nsIFrame* aFrame)
|
|
|
|
{
|
2012-07-20 11:12:29 -07: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-16 13:51:02 -08:00
|
|
|
const nsStyleSVGReset *style = aFrame->StyleSVGReset();
|
2014-02-09 20:31:03 -08:00
|
|
|
return (style->HasFilters() || style->mClipPath || style->mMask);
|
2008-09-10 17:24:16 -07: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 02:47:31 -07: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-10 17:24:16 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07: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 08:28:04 -07: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-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-19 08:28:04 -07:00
|
|
|
return nsLayoutUtils::GetAllInFlowRectsUnion(firstFrame, firstFrame).Size();
|
|
|
|
}
|
|
|
|
|
2013-12-29 15:35:52 -08:00
|
|
|
/* static */ gfx::Size
|
2012-06-19 08:28:04 -07:00
|
|
|
nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-19 08:28:04 -07:00
|
|
|
nsRect r = nsLayoutUtils::GetAllInFlowRectsUnion(firstFrame, firstFrame);
|
|
|
|
nsPresContext* presContext = firstFrame->PresContext();
|
2013-12-29 15:35:52 -08:00
|
|
|
return gfx::Size(presContext->AppUnitsToFloatCSSPixels(r.width),
|
|
|
|
presContext->AppUnitsToFloatCSSPixels(r.height));
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2012-06-20 17:29:50 -07:00
|
|
|
gfxRect
|
|
|
|
nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-06-20 17:29:50 -07:00
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-20 17:29:50 -07:00
|
|
|
// 'r' is in "user space":
|
2012-07-30 07:20:58 -07: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 02:47:31 -07:00
|
|
|
GetOffsetToBoundingBox(firstFrame));
|
2012-06-20 17:29:50 -07:00
|
|
|
return nsLayoutUtils::RectToGfxRect(r,
|
|
|
|
aNonSVGFrame->PresContext()->AppUnitsPerCSSPixel());
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2012-06-22 03:42:05 -07: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 02:47:31 -07:00
|
|
|
// GetOffsetToBoundingBox() and GetPreEffectsVisualOverflowUnion() calls will
|
2012-06-22 03:42:05 -07: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-14 21:29:12 -08:00
|
|
|
// ComputeEffectsRect when it has been called with
|
2012-06-22 03:42:05 -07: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-14 21:29:12 -08:00
|
|
|
// ComputeEffectsRect won't include continuation overflows, so
|
2012-06-22 03:42:05 -07: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-10 17:24:16 -07:00
|
|
|
nsRect
|
2012-06-20 17:29:50 -07:00
|
|
|
nsSVGIntegrationUtils::
|
|
|
|
ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame,
|
|
|
|
const nsRect& aPreEffectsOverflowRect)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-06-20 17:29:50 -07:00
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT),
|
|
|
|
"Don't call this on SVG child frames");
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
nsIFrame* firstFrame =
|
2014-02-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2008-09-10 17:24:16 -07:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
2014-02-24 07:22:58 -08:00
|
|
|
if (!effectProperties.HasValidFilter()) {
|
2012-06-20 17:29:50 -07:00
|
|
|
return aPreEffectsOverflowRect;
|
2014-02-24 07:22:58 -08:00
|
|
|
}
|
2012-06-20 17:29:50 -07:00
|
|
|
|
2012-06-22 03:42:05 -07: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 02:47:31 -07:00
|
|
|
nsPoint firstFrameToBoundingBox = GetOffsetToBoundingBox(firstFrame);
|
2012-06-22 20:01:36 -07:00
|
|
|
// overrideBBox is in "user space", in _CSS_ pixels:
|
2012-06-22 03:42:05 -07: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-22 20:01:36 -07: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 02:47:31 -07:00
|
|
|
firstFrameToBoundingBox),
|
2012-06-22 20:01:36 -07:00
|
|
|
aFrame->PresContext()->AppUnitsPerCSSPixel());
|
|
|
|
overrideBBox.RoundOut();
|
2012-06-20 17:29:50 -07:00
|
|
|
|
|
|
|
nsRect overflowRect =
|
2014-02-24 07:22:58 -08:00
|
|
|
nsFilterInstance::GetPostFilterBounds(firstFrame, &overrideBBox);
|
2012-06-20 17:29:50 -07: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 02:47:31 -07:00
|
|
|
return overflowRect - (aFrame->GetOffsetTo(firstFrame) + firstFrameToBoundingBox);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2014-04-24 01:25:17 -07:00
|
|
|
nsIntRegion
|
2012-06-20 17:29:50 -07:00
|
|
|
nsSVGIntegrationUtils::AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame,
|
2012-11-27 20:06:07 -08:00
|
|
|
const nsPoint& aToReferenceFrame,
|
2014-04-24 01:25:17 -07:00
|
|
|
const nsIntRegion& aInvalidRegion)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2014-04-24 01:25:17 -07:00
|
|
|
if (aInvalidRegion.IsEmpty()) {
|
2013-09-06 02:30:27 -07:00
|
|
|
return nsIntRect();
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
// Don't bother calling GetEffectProperties; the filter property should
|
|
|
|
// already have been set up during reflow/ComputeFrameEffectsRect
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2010-11-10 13:18:11 -08:00
|
|
|
nsSVGFilterProperty *prop = nsSVGEffects::GetFilterProperty(firstFrame);
|
2014-02-09 20:31:03 -08:00
|
|
|
if (!prop || !prop->IsInObserverLists()) {
|
2014-04-24 01:25:17 -07:00
|
|
|
return aInvalidRegion;
|
2010-11-09 21:50:29 -08:00
|
|
|
}
|
|
|
|
|
2012-08-28 22:39:33 -07:00
|
|
|
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2014-02-24 07:22:58 -08:00
|
|
|
if (!prop || !prop->ReferencesValidResources()) {
|
2008-12-12 00:25:16 -08:00
|
|
|
// The frame is either not there or not currently available,
|
|
|
|
// perhaps because we're in the middle of tearing stuff down.
|
2012-11-27 20:06:07 -08:00
|
|
|
// Be conservative, return our visual overflow rect relative
|
|
|
|
// to the reference frame.
|
|
|
|
nsRect overflow = aFrame->GetVisualOverflowRect() + aToReferenceFrame;
|
2012-08-28 22:39:33 -07:00
|
|
|
return overflow.ToOutsidePixels(appUnitsPerDevPixel);
|
2008-12-12 00:25:16 -08:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2014-04-24 01:25:17 -07: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 02:47:31 -07:00
|
|
|
nsPoint toBoundingBox =
|
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2012-11-27 20:06:07 -08: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 02:47:31 -07:00
|
|
|
toBoundingBox -= aToReferenceFrame;
|
2014-04-24 01:25:17 -07:00
|
|
|
nsRegion preEffectsRegion = aInvalidRegion.ToAppUnits(appUnitsPerDevPixel).MovedBy(toBoundingBox);
|
2012-06-19 08:28:04 -07:00
|
|
|
|
2012-11-27 20:06:07 -08:00
|
|
|
// Adjust the dirty area for effects, and shift it back to being relative to
|
|
|
|
// the reference frame.
|
2014-04-24 01:25:17 -07:00
|
|
|
nsRegion result = nsFilterInstance::GetPostFilterDirtyArea(firstFrame,
|
|
|
|
preEffectsRegion).MovedBy(-toBoundingBox);
|
2012-11-27 20:06:07 -08:00
|
|
|
// Return the result, in pixels relative to the reference frame.
|
2012-08-28 22:39:33 -07:00
|
|
|
return result.ToOutsidePixels(appUnitsPerDevPixel);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(nsIFrame* aFrame,
|
2012-06-19 08:28:04 -07:00
|
|
|
const nsRect& aDirtyRect)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
|
|
|
// Don't bother calling GetEffectProperties; the filter property should
|
|
|
|
// already have been set up during reflow/ComputeFrameEffectsRect
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2014-02-24 07:22:58 -08:00
|
|
|
nsSVGFilterProperty *prop = nsSVGEffects::GetFilterProperty(firstFrame);
|
|
|
|
if (!prop || !prop->ReferencesValidResources()) {
|
2012-06-19 08:28:04 -07:00
|
|
|
return aDirtyRect;
|
2014-02-24 07:22:58 -08:00
|
|
|
}
|
2014-07-31 17:37:35 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
// Convert aDirtyRect into "user space" in app units:
|
2012-06-19 08:28:04 -07: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 02:47:31 -07:00
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2012-06-26 03:49:23 -07:00
|
|
|
nsRect postEffectsRect = aDirtyRect + toUserSpace;
|
2012-06-19 08:28:04 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
// Return ther result, relative to aFrame, not in user space:
|
2014-04-24 01:25:17 -07:00
|
|
|
return nsFilterInstance::GetPreFilterNeededArea(firstFrame, postEffectsRect).GetBounds()
|
2014-02-24 07:22:58 -08:00
|
|
|
- toUserSpace;
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-09-10 17:24:16 -07:00
|
|
|
nsSVGIntegrationUtils::HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt)
|
|
|
|
{
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2012-06-19 08:28:04 -07:00
|
|
|
// Convert aPt to user space:
|
2013-01-04 03:48:12 -08: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 02:47:31 -07:00
|
|
|
// XXXmstange Isn't this wrong for svg:use and innerSVG frames?
|
2013-01-04 03:48:12 -08: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 02:47:31 -07:00
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2013-01-04 03:48:12 -08:00
|
|
|
}
|
2012-06-19 08:28:04 -07:00
|
|
|
nsPoint pt = aPt + toUserSpace;
|
2008-09-10 17:24:16 -07:00
|
|
|
return nsSVGUtils::HitTestClip(firstFrame, pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
class RegularFramePaintCallback : public nsSVGFilterPaintCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RegularFramePaintCallback(nsDisplayListBuilder* aBuilder,
|
2012-07-17 10:03:51 -07:00
|
|
|
LayerManager* aManager,
|
2008-09-10 17:24:16 -07:00
|
|
|
const nsPoint& aOffset)
|
2012-07-17 10:03:51 -07:00
|
|
|
: mBuilder(aBuilder), mLayerManager(aManager),
|
2010-03-10 12:55:05 -08:00
|
|
|
mOffset(aOffset) {}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
virtual void Paint(nsRenderingContext *aContext, nsIFrame *aTarget,
|
2014-02-24 06:41:56 -08:00
|
|
|
const nsIntRect* aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot) MOZ_OVERRIDE
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-07-17 10:03:51 -07:00
|
|
|
BasicLayerManager* basic = static_cast<BasicLayerManager*>(mLayerManager);
|
|
|
|
basic->SetTarget(aContext->ThebesContext());
|
2012-03-02 00:28:59 -08:00
|
|
|
nsRenderingContext::AutoPushTranslation push(aContext, -mOffset);
|
2012-07-17 10:03:51 -07:00
|
|
|
mLayerManager->EndTransaction(FrameLayerBuilder::DrawThebesLayer, mBuilder);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDisplayListBuilder* mBuilder;
|
2012-07-17 10:03:51 -07:00
|
|
|
LayerManager* mLayerManager;
|
2008-09-10 17:24:16 -07:00
|
|
|
nsPoint mOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(nsRenderingContext* aCtx,
|
2012-06-28 12:51:09 -07:00
|
|
|
nsIFrame* aFrame,
|
2008-09-10 17:24:16 -07:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2012-07-17 10:03:51 -07:00
|
|
|
LayerManager *aLayerManager)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2012-07-30 16:20:06 -07:00
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
|
2012-07-20 11:12:29 -07:00
|
|
|
(NS_SVGDisplayListPaintingEnabled() &&
|
2013-07-12 00:13:07 -07:00
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)),
|
2012-07-20 11:12:29 -07:00
|
|
|
"Should not use nsSVGIntegrationUtils on this SVG frame");
|
2009-01-12 11:20:59 -08:00
|
|
|
#endif
|
2008-09-10 17:24:16 -07: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 11:12:29 -07:00
|
|
|
const nsIContent* content = aFrame->GetContent();
|
|
|
|
bool hasSVGLayout = (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT);
|
|
|
|
if (hasSVGLayout) {
|
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
|
|
|
|
if (!svgChildFrame || !aFrame->GetContent()->IsSVG()) {
|
|
|
|
NS_ASSERTION(false, "why?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
return; // The SVG spec says not to draw _anything_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
float opacity = aFrame->StyleDisplay()->mOpacity;
|
2012-06-20 17:29:50 -07:00
|
|
|
if (opacity == 0.0f) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-20 11:12:29 -07:00
|
|
|
if (opacity != 1.0f &&
|
|
|
|
hasSVGLayout && nsSVGUtils::CanOptimizeOpacity(aFrame)) {
|
|
|
|
opacity = 1.0f;
|
|
|
|
}
|
2012-06-20 17:29:50 -07: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-06 17:45:31 -08:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2012-06-20 17:29:50 -07:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
2014-02-24 07:22:58 -08:00
|
|
|
bool isOK = effectProperties.HasNoFilterOrHasValidFilter();
|
2008-09-30 17:51:05 -07:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
nsSVGMaskFrame *maskFrame = effectProperties.GetMaskFrame(&isOK);
|
2008-09-10 17:24:16 -07:00
|
|
|
if (!isOK) {
|
2012-06-20 17:29:50 -07:00
|
|
|
return; // Some resource is missing. We shouldn't paint anything.
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2012-06-20 17:29:50 -07:00
|
|
|
bool isTrivialClip = clipPathFrame ? clipPathFrame->IsTrivial() : true;
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
gfxContext* gfx = aCtx->ThebesContext();
|
2012-06-14 20:02:27 -07:00
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(gfx);
|
2012-03-02 00:28:59 -08: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 02:47:31 -07:00
|
|
|
nsPoint firstFrameOffset = GetOffsetToBoundingBox(firstFrame);
|
2014-04-23 02:47:54 -07:00
|
|
|
nsPoint offsetToBoundingBox = aBuilder->ToReferenceFrame(firstFrame) - firstFrameOffset;
|
|
|
|
if (!firstFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2013-07-24 06:03:11 -07: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 02:47:54 -07:00
|
|
|
offsetToBoundingBox = nsPoint(
|
|
|
|
aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.x),
|
|
|
|
aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(offsetToBoundingBox.y));
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
|
|
|
|
2014-04-23 02:47:54 -07: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");
|
|
|
|
|
|
|
|
aCtx->Translate(offsetToUserSpace);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2012-06-28 12:51:09 -07:00
|
|
|
gfxMatrix cssPxToDevPxMatrix = GetCSSPxToDevPxMatrix(aFrame);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool complexEffects = false;
|
2008-09-10 17:24:16 -07:00
|
|
|
/* Check if we need to do additional operations on this child's
|
|
|
|
* rendering, which necessitates rendering into another surface. */
|
2013-09-14 20:40:11 -07:00
|
|
|
if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)
|
|
|
|
|| aFrame->StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
complexEffects = true;
|
2008-09-10 17:24:16 -07:00
|
|
|
gfx->Save();
|
2012-12-21 13:40:06 -08:00
|
|
|
aCtx->IntersectClip(aFrame->GetVisualOverflowRectRelativeToSelf() +
|
2014-04-23 02:47:54 -07:00
|
|
|
toUserSpace);
|
2014-01-23 10:26:40 -08:00
|
|
|
gfx->PushGroup(gfxContentType::COLOR_ALPHA);
|
2008-09-10 17:24:16 -07: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) {
|
|
|
|
gfx->Save();
|
2012-06-28 12:51:09 -07:00
|
|
|
clipPathFrame->ClipPaint(aCtx, aFrame, cssPxToDevPxMatrix);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint the child */
|
2014-02-24 07:22:58 -08:00
|
|
|
if (effectProperties.HasValidFilter()) {
|
2012-07-17 10:03:51 -07:00
|
|
|
RegularFramePaintCallback callback(aBuilder, aLayerManager,
|
2014-04-23 02:47:54 -07:00
|
|
|
offsetToUserSpace);
|
|
|
|
|
2014-04-24 01:25:17 -07:00
|
|
|
nsRegion dirtyRegion = aDirtyRect - offsetToBoundingBox;
|
|
|
|
nsFilterInstance::PaintFilteredFrame(aCtx, aFrame, &callback, &dirtyRegion);
|
2008-09-10 17:24:16 -07:00
|
|
|
} else {
|
2012-06-14 20:02:27 -07:00
|
|
|
gfx->SetMatrix(matrixAutoSaveRestore.Matrix());
|
2012-07-17 10:03:51 -07:00
|
|
|
aLayerManager->EndTransaction(FrameLayerBuilder::DrawThebesLayer, aBuilder);
|
2014-04-23 02:47:54 -07:00
|
|
|
aCtx->Translate(offsetToUserSpace);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clipPathFrame && isTrivialClip) {
|
|
|
|
gfx->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No more effects, we're done. */
|
|
|
|
if (!complexEffects) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx->PopGroupToSource();
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> maskSurface =
|
2014-06-22 21:45:31 -07:00
|
|
|
maskFrame ? maskFrame->GetMaskForMaskedFrame(aCtx->ThebesContext(),
|
|
|
|
aFrame, cssPxToDevPxMatrix,
|
|
|
|
opacity)
|
|
|
|
: nullptr;
|
2008-09-10 17:24:16 -07:00
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> clipMaskSurface;
|
|
|
|
if (clipPathFrame && !isTrivialClip) {
|
2014-01-23 10:26:40 -08:00
|
|
|
gfx->PushGroup(gfxContentType::COLOR_ALPHA);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2012-06-28 12:51:09 -07:00
|
|
|
nsresult rv = clipPathFrame->ClipPaint(aCtx, aFrame, cssPxToDevPxMatrix);
|
2008-09-10 17:24:16 -07:00
|
|
|
clipMaskSurface = gfx->PopGroup();
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && clipMaskSurface) {
|
|
|
|
// Still more set after clipping, so clip to another surface
|
|
|
|
if (maskSurface || opacity != 1.0f) {
|
2014-01-23 10:26:40 -08:00
|
|
|
gfx->PushGroup(gfxContentType::COLOR_ALPHA);
|
2008-09-10 17:24:16 -07:00
|
|
|
gfx->Mask(clipMaskSurface);
|
|
|
|
gfx->PopGroupToSource();
|
|
|
|
} else {
|
|
|
|
gfx->Mask(clipMaskSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maskSurface) {
|
|
|
|
gfx->Mask(maskSurface);
|
|
|
|
} else if (opacity != 1.0f) {
|
|
|
|
gfx->Paint(opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx->Restore();
|
|
|
|
}
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix
|
2012-06-20 17:29:50 -07:00
|
|
|
nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = aNonSVGFrame->PresContext()->AppUnitsPerDevPixel();
|
2008-09-10 17:24:16 -07:00
|
|
|
float devPxPerCSSPx =
|
|
|
|
1 / nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPixel);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
|
|
|
return gfxMatrix(devPxPerCSSPx, 0.0,
|
|
|
|
0.0, devPxPerCSSPx,
|
|
|
|
0.0, 0.0);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 06:32:27 -07:00
|
|
|
class PaintFrameCallback : public gfxDrawingCallback {
|
|
|
|
public:
|
|
|
|
PaintFrameCallback(nsIFrame* aFrame,
|
|
|
|
const nsSize aPaintServerSize,
|
2013-08-01 13:42:34 -07:00
|
|
|
const gfxIntSize aRenderSize,
|
|
|
|
uint32_t aFlags)
|
2010-08-13 06:32:27 -07:00
|
|
|
: mFrame(aFrame)
|
|
|
|
, mPaintServerSize(aPaintServerSize)
|
|
|
|
, mRenderSize(aRenderSize)
|
2013-08-01 13:42:34 -07:00
|
|
|
, mFlags (aFlags)
|
2010-08-13 06:32:27 -07:00
|
|
|
{}
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool operator()(gfxContext* aContext,
|
2010-08-13 06:32:27 -07:00
|
|
|
const gfxRect& aFillRect,
|
2013-10-01 14:01:19 -07:00
|
|
|
const GraphicsFilter& aFilter,
|
2014-02-24 06:41:56 -08:00
|
|
|
const gfxMatrix& aTransform) MOZ_OVERRIDE;
|
2010-08-13 06:32:27 -07:00
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nsSize mPaintServerSize;
|
|
|
|
gfxIntSize mRenderSize;
|
2013-08-01 13:42:34 -07:00
|
|
|
uint32_t mFlags;
|
2010-08-13 06:32:27 -07:00
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-13 06:32:27 -07:00
|
|
|
PaintFrameCallback::operator()(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
2013-10-01 14:01:19 -07:00
|
|
|
const GraphicsFilter& aFilter,
|
2010-08-13 06:32:27 -07:00
|
|
|
const gfxMatrix& aTransform)
|
|
|
|
{
|
|
|
|
if (mFrame->GetStateBits() & NS_FRAME_DRAWING_AS_PAINTSERVER)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-13 06:32:27 -07:00
|
|
|
|
|
|
|
mFrame->AddStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
|
|
|
|
2014-04-15 12:54:10 -07:00
|
|
|
nsRefPtr<nsRenderingContext> context(new nsRenderingContext());
|
|
|
|
context->Init(mFrame->PresContext()->DeviceContext(), aContext);
|
2010-08-13 06:32:27 -07:00
|
|
|
aContext->Save();
|
|
|
|
|
|
|
|
// Clip to aFillRect so that we don't paint outside.
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(aFillRect);
|
|
|
|
aContext->Clip();
|
|
|
|
|
2014-07-11 00:06:39 -07:00
|
|
|
gfxMatrix invmatrix = aTransform;
|
|
|
|
if (!invmatrix.Invert()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aContext->Multiply(invmatrix);
|
2010-08-13 06:32:27 -07: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 08:56:38 -07: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 02:47:31 -07:00
|
|
|
nsPoint offset = GetOffsetToBoundingBox(mFrame);
|
2012-06-19 08:28:04 -07:00
|
|
|
gfxPoint devPxOffset = gfxPoint(offset.x, offset.y) / appUnitsPerDevPixel;
|
|
|
|
aContext->Multiply(gfxMatrix().Translate(devPxOffset));
|
2010-08-13 06:32:27 -07: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;
|
|
|
|
gfxMatrix scaleMatrix = gfxMatrix().Scale(scaleX, scaleY);
|
|
|
|
aContext->Multiply(scaleMatrix);
|
|
|
|
|
|
|
|
// Draw.
|
2012-06-19 08:28:04 -07:00
|
|
|
nsRect dirty(-offset.x, -offset.y,
|
|
|
|
mPaintServerSize.width, mPaintServerSize.height);
|
2013-08-01 13:42:34 -07: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-04-15 12:54:10 -07:00
|
|
|
nsLayoutUtils::PaintFrame(context, mFrame,
|
2010-08-13 06:32:27 -07:00
|
|
|
dirty, NS_RGBA(0, 0, 0, 0),
|
2013-08-01 13:42:34 -07:00
|
|
|
flags);
|
2010-08-13 06:32:27 -07:00
|
|
|
|
|
|
|
aContext->Restore();
|
|
|
|
|
|
|
|
mFrame->RemoveStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-13 06:32:27 -07:00
|
|
|
}
|
|
|
|
|
2014-01-30 19:36:42 -08:00
|
|
|
/* static */ already_AddRefed<gfxDrawable>
|
|
|
|
nsSVGIntegrationUtils::DrawableFromPaintServer(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aTarget,
|
|
|
|
const nsSize& aPaintServerSize,
|
|
|
|
const gfxIntSize& aRenderSize,
|
|
|
|
const gfxMatrix& aContextMatrix,
|
|
|
|
uint32_t aFlags)
|
2010-08-13 06:32:27 -07: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 =
|
2012-07-13 16:18:38 -07:00
|
|
|
server->GetPaintServerPattern(aTarget, aContextMatrix,
|
|
|
|
&nsStyleSVG::mFill, 1.0, &overrideBounds);
|
2010-08-13 06:32:27 -07:00
|
|
|
|
2010-09-05 20:12:46 -07:00
|
|
|
if (!pattern)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-09-05 20:12:46 -07:00
|
|
|
|
2010-08-13 06:32:27 -07: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 00:07:07 -07:00
|
|
|
gfxMatrix scaleMatrix = gfxMatrix::Scaling(scaleX, scaleY);
|
|
|
|
pattern->SetMatrix(scaleMatrix * pattern->GetMatrix());
|
2010-08-13 06:32:27 -07: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-01 13:42:34 -07:00
|
|
|
new PaintFrameCallback(aFrame, aPaintServerSize, aRenderSize, aFlags);
|
2010-08-13 06:32:27 -07:00
|
|
|
nsRefPtr<gfxDrawable> drawable = new gfxCallbackDrawable(cb, aRenderSize);
|
|
|
|
return drawable.forget();
|
|
|
|
}
|