2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2013-01-30 02:11:44 +04:00
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2016-12-18 14:11:47 +03:00
|
|
|
#include "SVGGeometryElement.h"
|
|
|
|
#include "SVGGeometryFrame.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;
|
2017-03-08 07:07:00 +03:00
|
|
|
using namespace mozilla::image;
|
2013-01-10 03:02:45 +04:00
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
nsContainerFrame*
|
2018-03-22 21:20:41 +03:00
|
|
|
NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle)
|
2004-12-09 06:16:15 +03:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
return new (aPresShell) nsSVGMarkerFrame(aStyle);
|
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,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* 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)) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::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 */
|
|
|
|
|
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 14:11:47 +03:00
|
|
|
NS_ASSERTION(mMarkedFrame, "null SVGGeometry 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
|
|
|
}
|
|
|
|
|
2017-08-27 01:58:38 +03:00
|
|
|
SVGMarkerElement *content = static_cast<SVGMarkerElement*>(GetContent());
|
2017-07-06 15:00:35 +03: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:17 +04:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2017-06-08 08:17:07 +03:00
|
|
|
return ThebesMatrix(viewBoxTM * mMarkerTM) * 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();
|
2017-04-30 18:30:08 +03:00
|
|
|
MOZ_ASSERT(kid && kid->IsSVGMarkerAnonChildFrame(),
|
2013-09-16 09:06:29 +04:00
|
|
|
"expected to find anonymous child of marker frame");
|
|
|
|
return kid;
|
|
|
|
}
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2017-05-18 23:03:41 +03:00
|
|
|
void
|
2014-10-31 23:08:54 +03:00
|
|
|
nsSVGMarkerFrame::PaintMark(gfxContext& aContext,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aToMarkedFrameUserSpace,
|
2017-06-08 08:17:07 +03:00
|
|
|
SVGGeometryFrame* aMarkedFrame,
|
|
|
|
const nsSVGMark& aMark, float aStrokeWidth,
|
2017-05-18 23:03:41 +03:00
|
|
|
imgDrawingParams& aImgParams)
|
2004-12-09 06:16:15 +03:00
|
|
|
{
|
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.
|
2017-03-27 07:33:53 +03:00
|
|
|
if (mInUse) {
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2017-03-27 07:33:53 +03:00
|
|
|
}
|
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
|
|
|
|
2017-08-27 01:58:38 +03:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(GetContent());
|
2014-03-06 01:28:12 +04:00
|
|
|
if (!marker->HasValidDimensions()) {
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2014-03-06 01:28:12 +04:00
|
|
|
}
|
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.
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2008-02-21 20:43:25 +03:00
|
|
|
}
|
|
|
|
|
2014-08-29 23:42:07 +04:00
|
|
|
Matrix viewBoxTM = marker->GetViewBoxTransform();
|
|
|
|
|
2017-06-08 08:17:07 +03:00
|
|
|
mMarkerTM = marker->GetMarkerTransform(aStrokeWidth, aMark);
|
2014-08-29 23:42:07 +04:00
|
|
|
|
2017-06-08 08:17:07 +03:00
|
|
|
gfxMatrix markTM = ThebesMatrix(viewBoxTM) * ThebesMatrix(mMarkerTM) *
|
2014-08-29 23:42:07 +04:00
|
|
|
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);
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* SVGFrame = do_QueryFrame(kid);
|
2013-09-16 09:06:29 +04:00
|
|
|
// The CTM of each frame referencing us may be different.
|
2017-02-09 21:24:31 +03:00
|
|
|
SVGFrame->NotifySVGChanged(nsSVGDisplayableFrame::TRANSFORM_CHANGED);
|
2017-05-18 23:03:41 +03:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(kid, aContext, markTM, aImgParams);
|
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();
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2012-04-16 12:23:48 +04:00
|
|
|
SVGBBox
|
2017-06-08 08:17:07 +03:00
|
|
|
nsSVGMarkerFrame::GetMarkBBoxContribution(const Matrix& aToBBoxUserspace,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags,
|
2017-06-08 08:17:07 +03:00
|
|
|
SVGGeometryFrame* aMarkedFrame,
|
|
|
|
const nsSVGMark& aMark,
|
2011-09-30 13:25:37 +04:00
|
|
|
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);
|
|
|
|
|
2017-08-27 01:58:38 +03:00
|
|
|
SVGMarkerElement *content = static_cast<SVGMarkerElement*>(GetContent());
|
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
|
|
|
}
|
|
|
|
|
2017-06-08 08:17:07 +03:00
|
|
|
mMarkerTM = content->GetMarkerTransform(aStrokeWidth, aMark);
|
2013-12-30 10:50:17 +04:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2011-09-30 13:25:37 +04:00
|
|
|
|
2017-06-08 08:17:07 +03:00
|
|
|
Matrix tm = viewBoxTM * mMarkerTM * aToBBoxUserspace;
|
2011-09-30 13:25:37 +04:00
|
|
|
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* child = do_QueryFrame(GetAnonymousChildFrame(this));
|
2013-09-16 09:06:29 +04:00
|
|
|
// 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
|
2017-10-10 09:58:34 +03:00
|
|
|
nsSVGMarkerFrame::SetParentCoordCtxProvider(SVGViewportElement *aContext)
|
2006-12-07 12:32:13 +03:00
|
|
|
{
|
2017-08-27 01:58:38 +03:00
|
|
|
SVGMarkerElement *marker = static_cast<SVGMarkerElement*>(GetContent());
|
2006-12-07 12:32:13 +03:00
|
|
|
marker->SetParentCoordCtxProvider(aContext);
|
|
|
|
}
|
|
|
|
|
2017-03-15 21:00:44 +03:00
|
|
|
void
|
2017-06-16 12:22:33 +03:00
|
|
|
nsSVGMarkerFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult)
|
2017-03-15 21:00:44 +03:00
|
|
|
{
|
2017-06-16 12:22:33 +03:00
|
|
|
aResult.AppendElement(OwnedAnonBox(GetAnonymousChildFrame(this)));
|
2017-03-15 21:00:44 +03:00
|
|
|
}
|
|
|
|
|
2006-12-07 12:32:13 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper class
|
|
|
|
|
|
|
|
nsSVGMarkerFrame::AutoMarkerReferencer::AutoMarkerReferencer(
|
|
|
|
nsSVGMarkerFrame *aFrame,
|
2016-12-18 14:11:47 +03:00
|
|
|
SVGGeometryFrame *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;
|
|
|
|
|
2017-10-10 09:58:34 +03:00
|
|
|
SVGViewportElement *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,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle)
|
2013-09-16 09:06:29 +04:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
return new (aPresShell) nsSVGMarkerAnonChildFrame(aStyle);
|
2013-09-16 09:06:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-04-30 18:30:08 +03:00
|
|
|
MOZ_ASSERT(aParent->IsSVGMarkerFrame(), "Unexpected parent");
|
2016-04-18 10:28:03 +03:00
|
|
|
nsSVGDisplayContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2013-09-16 09:06:29 +04:00
|
|
|
}
|
|
|
|
#endif
|