2004-12-09 03:16:15 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Main header first:
|
2012-03-20 12:15:55 +00:00
|
|
|
#include "nsSVGMarkerFrame.h"
|
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
2012-03-20 12:15:55 +00:00
|
|
|
#include "nsRenderingContext.h"
|
2008-10-10 13:14:05 +00:00
|
|
|
#include "nsSVGEffects.h"
|
2013-01-29 22:11:44 +00:00
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2006-06-21 15:42:28 +00:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
using namespace mozilla::dom;
|
2013-12-30 06:50:07 +00:00
|
|
|
using namespace mozilla::gfx;
|
2013-01-09 23:02:45 +00:00
|
|
|
|
2005-11-11 02:36:29 +00:00
|
|
|
nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2004-12-09 03:16:15 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsSVGMarkerFrame(aContext);
|
2004-12-09 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGMarkerFrame)
|
|
|
|
|
2008-10-10 13:14:05 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGMarkerFrame::AttributeChanged(int32_t aNameSpaceID,
|
2008-10-10 13:14:05 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
2008-10-10 13:14:05 +00: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 14:19:00 +00:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2008-10-10 13:14:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGMarkerFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2009-01-19 18:31:34 +00:00
|
|
|
nsSVGMarkerFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-02-18 22:48:54 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::marker), "Content is not an SVG marker");
|
2009-01-19 18:31:34 +00:00
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
nsSVGMarkerFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 18:31:34 +00:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2008-10-10 13:14:05 +00:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGMarkerFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgMarkerFrame;
|
|
|
|
}
|
|
|
|
|
2004-12-09 03:16:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
2006-06-01 15:31:15 +00:00
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
2009-04-29 04:31:34 +00:00
|
|
|
gfxMatrix
|
2013-09-11 07:27:45 +00:00
|
|
|
nsSVGMarkerFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
|
2004-12-09 03:16:15 +00:00
|
|
|
{
|
2009-04-29 04:31:34 +00:00
|
|
|
NS_ASSERTION(mMarkedFrame, "null nsSVGPathGeometry frame");
|
|
|
|
|
2005-09-16 21:58:47 +00:00
|
|
|
if (mInUse2) {
|
2009-04-29 04:31:34 +00:00
|
|
|
// We're going to be bailing drawing the marker, so return an identity.
|
|
|
|
return gfxMatrix();
|
2005-09-16 21:58:47 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 22:11:44 +00:00
|
|
|
SVGMarkerElement *content = static_cast<SVGMarkerElement*>(mContent);
|
2009-04-29 04:31:34 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInUse2 = true;
|
2013-09-11 07:27:45 +00:00
|
|
|
gfxMatrix markedTM = mMarkedFrame->GetCanvasTM(aFor, aTransformRoot);
|
2011-10-17 14:59:28 +00:00
|
|
|
mInUse2 = false;
|
2005-09-16 21:58:47 +00:00
|
|
|
|
2013-12-30 06:50:08 +00:00
|
|
|
Matrix markerTM = content->GetMarkerTransform(mStrokeWidth, mX, mY,
|
|
|
|
mAutoAngle, mIsStart);
|
2013-12-30 06:50:17 +00:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2013-12-30 06:50:17 +00:00
|
|
|
return ThebesMatrix(viewBoxTM * markerTM) * markedTM;
|
2004-12-09 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 05:06:29 +00: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;
|
|
|
|
}
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2006-06-09 20:40:06 +00:00
|
|
|
nsresult
|
2012-03-02 08:28:59 +00:00
|
|
|
nsSVGMarkerFrame::PaintMark(nsRenderingContext *aContext,
|
2006-12-07 09:32:13 +00:00
|
|
|
nsSVGPathGeometryFrame *aMarkedFrame,
|
2004-12-09 03:16:15 +00:00
|
|
|
nsSVGMark *aMark, float aStrokeWidth)
|
|
|
|
{
|
2005-07-01 01:34:34 +00:00
|
|
|
// 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)
|
2006-01-20 16:21:37 +00:00
|
|
|
return NS_OK;
|
2005-07-01 01:34:34 +00:00
|
|
|
|
2011-09-21 07:53:09 +00:00
|
|
|
AutoMarkerReferencer markerRef(this, aMarkedFrame);
|
2008-02-21 17:43:25 +00:00
|
|
|
|
2013-01-29 22:11:44 +00:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(mContent);
|
2008-02-21 17:43:25 +00:00
|
|
|
|
2011-09-21 07:53:09 +00:00
|
|
|
const nsSVGViewBoxRect viewBox = marker->GetViewBoxRect();
|
2008-02-21 17:43:25 +00:00
|
|
|
|
2011-09-21 07:53:09 +00:00
|
|
|
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
|
2008-02-21 17:43:25 +00:00
|
|
|
// We must disable rendering if the viewBox width or height are zero.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-09 03:16:15 +00:00
|
|
|
mStrokeWidth = aStrokeWidth;
|
|
|
|
mX = aMark->x;
|
|
|
|
mY = aMark->y;
|
2010-02-18 21:50:59 +00:00
|
|
|
mAutoAngle = aMark->angle;
|
2013-07-12 06:39:38 +00:00
|
|
|
mIsStart = aMark->type == nsSVGMark::eStart;
|
2006-04-14 15:09:39 +00:00
|
|
|
|
2012-03-02 08:28:59 +00:00
|
|
|
gfxContext *gfx = aContext->ThebesContext();
|
2006-11-27 17:30:57 +00:00
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2006-11-27 17:30:57 +00:00
|
|
|
gfx->Save();
|
2009-06-17 20:51:40 +00:00
|
|
|
gfxRect clipRect =
|
2011-09-21 07:53:09 +00:00
|
|
|
nsSVGUtils::GetClipRectForFrame(this, viewBox.x, viewBox.y,
|
|
|
|
viewBox.width, viewBox.height);
|
2012-06-30 11:20:46 +00:00
|
|
|
nsSVGUtils::SetClipRect(gfx, GetCanvasTM(nsISVGChildFrame::FOR_PAINTING),
|
|
|
|
clipRect);
|
2005-07-02 23:45:33 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 05:06:29 +00: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);
|
2005-07-02 23:45:33 +00:00
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow())
|
2006-11-27 17:30:57 +00:00
|
|
|
gfx->Restore();
|
2005-07-02 23:45:33 +00:00
|
|
|
|
2006-01-20 16:21:37 +00:00
|
|
|
return NS_OK;
|
2004-12-09 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 08:23:48 +00:00
|
|
|
SVGBBox
|
2013-12-30 06:50:07 +00:00
|
|
|
nsSVGMarkerFrame::GetMarkBBoxContribution(const Matrix &aToBBoxUserspace,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags,
|
2011-09-30 09:25:37 +00:00
|
|
|
nsSVGPathGeometryFrame *aMarkedFrame,
|
|
|
|
const nsSVGMark *aMark,
|
|
|
|
float aStrokeWidth)
|
|
|
|
{
|
2012-04-16 08:23:48 +00:00
|
|
|
SVGBBox bbox;
|
|
|
|
|
2011-09-30 09:25:37 +00: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 08:23:48 +00:00
|
|
|
return bbox;
|
2011-09-30 09:25:37 +00:00
|
|
|
|
|
|
|
AutoMarkerReferencer markerRef(this, aMarkedFrame);
|
|
|
|
|
2013-01-29 22:11:44 +00:00
|
|
|
SVGMarkerElement *content = static_cast<SVGMarkerElement*>(mContent);
|
2011-10-06 19:03:16 +00:00
|
|
|
|
|
|
|
const nsSVGViewBoxRect viewBox = content->GetViewBoxRect();
|
|
|
|
|
|
|
|
if (viewBox.width <= 0.0f || viewBox.height <= 0.0f) {
|
2012-04-16 08:23:48 +00:00
|
|
|
return bbox;
|
2011-10-06 19:03:16 +00:00
|
|
|
}
|
|
|
|
|
2011-09-30 09:25:37 +00:00
|
|
|
mStrokeWidth = aStrokeWidth;
|
|
|
|
mX = aMark->x;
|
|
|
|
mY = aMark->y;
|
|
|
|
mAutoAngle = aMark->angle;
|
2013-07-12 06:39:38 +00:00
|
|
|
mIsStart = aMark->type == nsSVGMark::eStart;
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2013-12-30 06:50:08 +00:00
|
|
|
Matrix markerTM =
|
2013-07-12 06:39:38 +00:00
|
|
|
content->GetMarkerTransform(mStrokeWidth, mX, mY, mAutoAngle, mIsStart);
|
2013-12-30 06:50:17 +00:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2013-12-30 06:50:17 +00:00
|
|
|
Matrix tm = viewBoxTM * markerTM * aToBBoxUserspace;
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2013-09-16 05:06:29 +00: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 09:25:37 +00:00
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
2006-12-07 09:32:13 +00:00
|
|
|
void
|
2013-01-09 23:02:45 +00:00
|
|
|
nsSVGMarkerFrame::SetParentCoordCtxProvider(SVGSVGElement *aContext)
|
2006-12-07 09:32:13 +00:00
|
|
|
{
|
2013-01-29 22:11:44 +00:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(mContent);
|
2006-12-07 09:32:13 +00:00
|
|
|
marker->SetParentCoordCtxProvider(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper class
|
|
|
|
|
|
|
|
nsSVGMarkerFrame::AutoMarkerReferencer::AutoMarkerReferencer(
|
|
|
|
nsSVGMarkerFrame *aFrame,
|
2013-12-26 18:49:49 +00:00
|
|
|
nsSVGPathGeometryFrame *aMarkedFrame
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
2006-12-07 09:32:13 +00:00
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
2013-12-26 18:49:49 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2011-10-17 14:59:28 +00:00
|
|
|
mFrame->mInUse = true;
|
2006-12-07 09:32:13 +00:00
|
|
|
mFrame->mMarkedFrame = aMarkedFrame;
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
SVGSVGElement *ctx =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsSVGElement*>(aMarkedFrame->GetContent())->GetCtx();
|
2006-12-07 09:32:13 +00:00
|
|
|
mFrame->SetParentCoordCtxProvider(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGMarkerFrame::AutoMarkerReferencer::~AutoMarkerReferencer()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mFrame->SetParentCoordCtxProvider(nullptr);
|
2006-12-07 09:32:13 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mFrame->mMarkedFrame = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mFrame->mInUse = false;
|
2006-12-07 09:32:13 +00:00
|
|
|
}
|
2013-09-16 05:06:29 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation of nsSVGMarkerAnonChildFrame
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGMarkerAnonChildFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGMarkerAnonChildFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGMarkerAnonChildFrame)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsSVGMarkerAnonChildFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aParent->GetType() == nsGkAtoms::svgMarkerFrame,
|
|
|
|
"Unexpected parent");
|
|
|
|
nsSVGMarkerAnonChildFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGMarkerAnonChildFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgMarkerAnonChildFrame;
|
|
|
|
}
|