2007-03-22 10:30:00 -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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsSVGMarkerFrame.h"
|
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2008-10-10 06:14:05 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2013-01-29 14:11:44 -08:00
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-09 15:02:45 -08:00
|
|
|
using namespace mozilla::dom;
|
2013-12-29 22:50:07 -08:00
|
|
|
using namespace mozilla::gfx;
|
2013-01-09 15:02:45 -08:00
|
|
|
|
2014-05-24 15:20:40 -07:00
|
|
|
nsContainerFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGMarkerFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGMarkerFrame)
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGMarkerFrame::AttributeChanged(int32_t aNameSpaceID,
|
2008-10-10 06:14:05 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2008-10-10 06:14:05 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::markerUnits ||
|
|
|
|
aAttribute == nsGkAtoms::refX ||
|
|
|
|
aAttribute == nsGkAtoms::refY ||
|
|
|
|
aAttribute == nsGkAtoms::markerWidth ||
|
|
|
|
aAttribute == nsGkAtoms::markerHeight ||
|
|
|
|
aAttribute == nsGkAtoms::orient ||
|
|
|
|
aAttribute == nsGkAtoms::preserveAspectRatio ||
|
|
|
|
aAttribute == nsGkAtoms::viewBox)) {
|
2012-06-23 07:19:00 -07:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2008-10-10 06:14:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGMarkerFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSVGMarkerFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 10:31:34 -08:00
|
|
|
{
|
2013-02-18 14:48:54 -08:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::marker), "Content is not an SVG marker");
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsSVGMarkerFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 10:31:34 -08:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGMarkerFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgMarkerFrame;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGMarkerFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-28 21:31:34 -07:00
|
|
|
NS_ASSERTION(mMarkedFrame, "null nsSVGPathGeometry frame");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mInUse2) {
|
2009-04-28 21:31:34 -07:00
|
|
|
// We're going to be bailing drawing the marker, so return an identity.
|
|
|
|
return gfxMatrix();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 14:11:44 -08:00
|
|
|
SVGMarkerElement *content = static_cast<SVGMarkerElement*>(mContent);
|
2009-04-28 21:31:34 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mInUse2 = true;
|
2013-09-11 00:27:45 -07:00
|
|
|
gfxMatrix markedTM = mMarkedFrame->GetCanvasTM(aFor, aTransformRoot);
|
2011-10-17 07:59:28 -07:00
|
|
|
mInUse2 = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-29 22:50:08 -08:00
|
|
|
Matrix markerTM = content->GetMarkerTransform(mStrokeWidth, mX, mY,
|
|
|
|
mAutoAngle, mIsStart);
|
2013-12-29 22:50:17 -08:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-29 22:50:17 -08:00
|
|
|
return ThebesMatrix(viewBoxTM * markerTM) * markedTM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-15 22:06:29 -07:00
|
|
|
static nsIFrame*
|
|
|
|
GetAnonymousChildFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = aFrame->GetFirstPrincipalChild();
|
|
|
|
MOZ_ASSERT(kid && kid->GetType() == nsGkAtoms::svgMarkerAnonChildFrame,
|
|
|
|
"expected to find anonymous child of marker frame");
|
|
|
|
return kid;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGMarkerFrame::PaintMark(nsRenderingContext *aContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGPathGeometryFrame *aMarkedFrame,
|
|
|
|
nsSVGMark *aMark, float aStrokeWidth)
|
|
|
|
{
|
|
|
|
// If the flag is set when we get here, it means this marker frame
|
|
|
|
// has already been used painting the current mark, and the document
|
|
|
|
// has a marker reference loop.
|
|
|
|
if (mInUse)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-09-21 00:53:09 -07:00
|
|
|
AutoMarkerReferencer markerRef(this, aMarkedFrame);
|
2008-02-21 09:43:25 -08:00
|
|
|
|
2013-01-29 14:11:44 -08:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(mContent);
|
2014-03-05 13:28:12 -08:00
|
|
|
if (!marker->HasValidDimensions()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-21 09:43:25 -08:00
|
|
|
|
2011-09-21 00:53:09 -07:00
|
|
|
const nsSVGViewBoxRect viewBox = marker->GetViewBoxRect();
|
2008-02-21 09:43:25 -08:00
|
|
|
|
2011-09-21 00:53:09 -07:00
|
|
|
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
|
2008-02-21 09:43:25 -08:00
|
|
|
// We must disable rendering if the viewBox width or height are zero.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mStrokeWidth = aStrokeWidth;
|
|
|
|
mX = aMark->x;
|
|
|
|
mY = aMark->y;
|
2010-02-18 13:50:59 -08:00
|
|
|
mAutoAngle = aMark->angle;
|
2013-07-11 23:39:38 -07:00
|
|
|
mIsStart = aMark->type == nsSVGMark::eStart;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
gfxContext *gfx = aContext->ThebesContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->Save();
|
2009-06-17 13:51:40 -07:00
|
|
|
gfxRect clipRect =
|
2011-09-21 00:53:09 -07:00
|
|
|
nsSVGUtils::GetClipRectForFrame(this, viewBox.x, viewBox.y,
|
|
|
|
viewBox.width, viewBox.height);
|
2012-06-30 04:20:46 -07:00
|
|
|
nsSVGUtils::SetClipRect(gfx, GetCanvasTM(nsISVGChildFrame::FOR_PAINTING),
|
|
|
|
clipRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-15 22:06:29 -07:00
|
|
|
nsIFrame* kid = GetAnonymousChildFrame(this);
|
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
|
|
|
// The CTM of each frame referencing us may be different.
|
|
|
|
SVGFrame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
|
|
|
|
nsSVGUtils::PaintFrameWithEffects(aContext, nullptr, kid);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow())
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->Restore();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox
|
2013-12-29 22:50:07 -08:00
|
|
|
nsSVGMarkerFrame::GetMarkBBoxContribution(const Matrix &aToBBoxUserspace,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags,
|
2011-09-30 02:25:37 -07:00
|
|
|
nsSVGPathGeometryFrame *aMarkedFrame,
|
|
|
|
const nsSVGMark *aMark,
|
|
|
|
float aStrokeWidth)
|
|
|
|
{
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox bbox;
|
|
|
|
|
2011-09-30 02:25:37 -07:00
|
|
|
// If the flag is set when we get here, it means this marker frame
|
|
|
|
// has already been used in calculating the current mark bbox, and
|
|
|
|
// the document has a marker reference loop.
|
|
|
|
if (mInUse)
|
2012-04-16 01:23:48 -07:00
|
|
|
return bbox;
|
2011-09-30 02:25:37 -07:00
|
|
|
|
|
|
|
AutoMarkerReferencer markerRef(this, aMarkedFrame);
|
|
|
|
|
2013-01-29 14:11:44 -08:00
|
|
|
SVGMarkerElement *content = static_cast<SVGMarkerElement*>(mContent);
|
2014-03-05 13:28:12 -08:00
|
|
|
if (!content->HasValidDimensions()) {
|
|
|
|
return bbox;
|
|
|
|
}
|
2011-10-06 12:03:16 -07:00
|
|
|
|
|
|
|
const nsSVGViewBoxRect viewBox = content->GetViewBoxRect();
|
|
|
|
|
|
|
|
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
|
2012-04-16 01:23:48 -07:00
|
|
|
return bbox;
|
2011-10-06 12:03:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-30 02:25:37 -07:00
|
|
|
mStrokeWidth = aStrokeWidth;
|
|
|
|
mX = aMark->x;
|
|
|
|
mY = aMark->y;
|
|
|
|
mAutoAngle = aMark->angle;
|
2013-07-11 23:39:38 -07:00
|
|
|
mIsStart = aMark->type == nsSVGMark::eStart;
|
2011-09-30 02:25:37 -07:00
|
|
|
|
2013-12-29 22:50:08 -08:00
|
|
|
Matrix markerTM =
|
2013-07-11 23:39:38 -07:00
|
|
|
content->GetMarkerTransform(mStrokeWidth, mX, mY, mAutoAngle, mIsStart);
|
2013-12-29 22:50:17 -08:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2011-09-30 02:25:37 -07:00
|
|
|
|
2013-12-29 22:50:17 -08:00
|
|
|
Matrix tm = viewBoxTM * markerTM * aToBBoxUserspace;
|
2011-09-30 02:25:37 -07:00
|
|
|
|
2013-09-15 22:06:29 -07:00
|
|
|
nsISVGChildFrame* child = do_QueryFrame(GetAnonymousChildFrame(this));
|
|
|
|
// When we're being called to obtain the invalidation area, we need to
|
|
|
|
// pass down all the flags so that stroke is included. However, once DOM
|
|
|
|
// getBBox() accepts flags, maybe we should strip some of those here?
|
|
|
|
|
|
|
|
// We need to include zero width/height vertical/horizontal lines, so we have
|
|
|
|
// to use UnionEdges.
|
|
|
|
bbox.UnionEdges(child->GetBBoxContribution(tm, aFlags));
|
2011-09-30 02:25:37 -07:00
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2013-01-09 15:02:45 -08:00
|
|
|
nsSVGMarkerFrame::SetParentCoordCtxProvider(SVGSVGElement *aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-29 14:11:44 -08:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
marker->SetParentCoordCtxProvider(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper class
|
|
|
|
|
|
|
|
nsSVGMarkerFrame::AutoMarkerReferencer::AutoMarkerReferencer(
|
|
|
|
nsSVGMarkerFrame *aFrame,
|
2013-12-26 10:49:49 -08:00
|
|
|
nsSVGPathGeometryFrame *aMarkedFrame
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
2013-12-26 10:49:49 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2011-10-17 07:59:28 -07:00
|
|
|
mFrame->mInUse = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mFrame->mMarkedFrame = aMarkedFrame;
|
|
|
|
|
2013-01-09 15:02:45 -08:00
|
|
|
SVGSVGElement *ctx =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGElement*>(aMarkedFrame->GetContent())->GetCtx();
|
2007-03-22 10:30:00 -07:00
|
|
|
mFrame->SetParentCoordCtxProvider(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGMarkerFrame::AutoMarkerReferencer::~AutoMarkerReferencer()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame->SetParentCoordCtxProvider(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame->mMarkedFrame = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mFrame->mInUse = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-09-15 22:06:29 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation of nsSVGMarkerAnonChildFrame
|
|
|
|
|
2014-05-24 15:20:40 -07:00
|
|
|
nsContainerFrame*
|
2013-09-15 22:06:29 -07:00
|
|
|
NS_NewSVGMarkerAnonChildFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGMarkerAnonChildFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGMarkerAnonChildFrame)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSVGMarkerAnonChildFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2013-09-15 22:06:29 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aParent->GetType() == nsGkAtoms::svgMarkerFrame,
|
|
|
|
"Unexpected parent");
|
|
|
|
nsSVGMarkerAnonChildFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGMarkerAnonChildFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgMarkerAnonChildFrame;
|
|
|
|
}
|