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