2017-10-27 17:33:53 +00: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 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"
|
2019-04-16 07:24:49 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
2013-01-29 22:11:44 +00:00
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2016-12-18 11:11:47 +00:00
|
|
|
#include "SVGGeometryElement.h"
|
|
|
|
#include "SVGGeometryFrame.h"
|
2019-04-16 07:24:49 +00:00
|
|
|
#include "SVGObserverUtils.h"
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2018-11-12 22:20:52 +00:00
|
|
|
using namespace mozilla;
|
2013-01-09 23:02:45 +00:00
|
|
|
using namespace mozilla::dom;
|
2013-12-30 06:50:07 +00:00
|
|
|
using namespace mozilla::gfx;
|
2017-03-08 04:07:00 +00:00
|
|
|
using namespace mozilla::image;
|
2013-01-09 23:02:45 +00:00
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
nsContainerFrame* NS_NewSVGMarkerFrame(PresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 16:45:54 +00:00
|
|
|
return new (aPresShell)
|
|
|
|
nsSVGMarkerFrame(aStyle, aPresShell->GetPresContext());
|
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:
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult nsSVGMarkerFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* 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)) {
|
2017-08-30 14:58:31 +00:00
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(this);
|
2008-10-10 13:14:05 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 07:26:00 +00:00
|
|
|
return nsSVGContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2008-10-10 13:14:05 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
void nsSVGMarkerFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2015-03-03 11:08:59 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::marker),
|
|
|
|
"Content is not an SVG marker");
|
2009-01-19 18:31:34 +00:00
|
|
|
|
2016-04-18 07:26:00 +00:00
|
|
|
nsSVGContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 18:31:34 +00:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2004-12-09 03:16:15 +00:00
|
|
|
//----------------------------------------------------------------------
|
2006-06-01 15:31:15 +00:00
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
2014-09-08 11:28:50 +00:00
|
|
|
gfxMatrix nsSVGMarkerFrame::GetCanvasTM() {
|
2016-12-18 11:11:47 +00:00
|
|
|
NS_ASSERTION(mMarkedFrame, "null SVGGeometry frame");
|
2009-04-29 04:31:34 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-08-26 22:58:38 +00:00
|
|
|
SVGMarkerElement* content = static_cast<SVGMarkerElement*>(GetContent());
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInUse2 = true;
|
2014-09-08 11:28:50 +00:00
|
|
|
gfxMatrix markedTM = mMarkedFrame->GetCanvasTM();
|
2011-10-17 14:59:28 +00:00
|
|
|
mInUse2 = false;
|
2005-09-16 21:58:47 +00:00
|
|
|
|
2013-12-30 06:50:17 +00:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2017-06-08 05:17:07 +00:00
|
|
|
return ThebesMatrix(viewBoxTM * mMarkerTM) * markedTM;
|
2004-12-09 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 05:06:29 +00:00
|
|
|
static nsIFrame* GetAnonymousChildFrame(nsIFrame* aFrame) {
|
2016-01-29 14:42:14 +00:00
|
|
|
nsIFrame* kid = aFrame->PrincipalChildList().FirstChild();
|
2017-04-30 15:30:08 +00:00
|
|
|
MOZ_ASSERT(kid && kid->IsSVGMarkerAnonChildFrame(),
|
2013-09-16 05:06:29 +00:00
|
|
|
"expected to find anonymous child of marker frame");
|
|
|
|
return kid;
|
|
|
|
}
|
2004-12-09 03:16:15 +00:00
|
|
|
|
2014-10-31 20:08:54 +00:00
|
|
|
void nsSVGMarkerFrame::PaintMark(gfxContext& aContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aToMarkedFrameUserSpace,
|
2017-06-08 05:17:07 +00:00
|
|
|
SVGGeometryFrame* aMarkedFrame,
|
2019-01-26 13:01:31 +00:00
|
|
|
const SVGMark& aMark, float aStrokeWidth,
|
2017-05-18 20:03:41 +00:00
|
|
|
imgDrawingParams& aImgParams) {
|
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.
|
2017-03-27 04:33:53 +00:00
|
|
|
if (mInUse) {
|
2017-05-18 20:03:41 +00:00
|
|
|
return;
|
2017-03-27 04:33:53 +00:00
|
|
|
}
|
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
|
|
|
|
2017-08-26 22:58:38 +00:00
|
|
|
SVGMarkerElement* marker = static_cast<SVGMarkerElement*>(GetContent());
|
2014-03-05 21:28:12 +00:00
|
|
|
if (!marker->HasValidDimensions()) {
|
2017-05-18 20:03:41 +00:00
|
|
|
return;
|
2014-03-05 21:28:12 +00:00
|
|
|
}
|
2008-02-21 17:43:25 +00:00
|
|
|
|
2019-04-10 04:08:14 +00:00
|
|
|
const SVGViewBox viewBox = marker->GetViewBox();
|
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.
|
2017-05-18 20:03:41 +00:00
|
|
|
return;
|
2008-02-21 17:43:25 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 19:42:07 +00:00
|
|
|
Matrix viewBoxTM = marker->GetViewBoxTransform();
|
|
|
|
|
2017-06-08 05:17:07 +00:00
|
|
|
mMarkerTM = marker->GetMarkerTransform(aStrokeWidth, aMark);
|
2014-08-29 19:42:07 +00:00
|
|
|
|
2017-06-08 05:17:07 +00:00
|
|
|
gfxMatrix markTM = ThebesMatrix(viewBoxTM) * ThebesMatrix(mMarkerTM) *
|
2014-08-29 19:42:07 +00:00
|
|
|
aToMarkedFrameUserSpace;
|
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2014-10-31 20:08:54 +00:00
|
|
|
aContext.Save();
|
2011-09-21 07:53:09 +00:00
|
|
|
gfxRect clipRect = nsSVGUtils::GetClipRectForFrame(
|
|
|
|
this, viewBox.x, viewBox.y, viewBox.width, viewBox.height);
|
2014-10-31 20:08:54 +00:00
|
|
|
nsSVGUtils::SetClipRect(&aContext, markTM, clipRect);
|
2005-07-02 23:45:33 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 05:06:29 +00:00
|
|
|
nsIFrame* kid = GetAnonymousChildFrame(this);
|
2017-02-09 18:24:31 +00:00
|
|
|
nsSVGDisplayableFrame* SVGFrame = do_QueryFrame(kid);
|
2013-09-16 05:06:29 +00:00
|
|
|
// The CTM of each frame referencing us may be different.
|
2017-02-09 18:24:31 +00:00
|
|
|
SVGFrame->NotifySVGChanged(nsSVGDisplayableFrame::TRANSFORM_CHANGED);
|
2017-05-18 20:03:41 +00:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(kid, aContext, markTM, aImgParams);
|
2005-07-02 23:45:33 +00:00
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) aContext.Restore();
|
2004-12-09 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 05:17:07 +00:00
|
|
|
SVGBBox nsSVGMarkerFrame::GetMarkBBoxContribution(
|
|
|
|
const Matrix& aToBBoxUserspace, uint32_t aFlags,
|
2019-01-26 13:01:31 +00:00
|
|
|
SVGGeometryFrame* aMarkedFrame, const SVGMark& 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.
|
2018-12-12 06:32:44 +00:00
|
|
|
if (mInUse) {
|
|
|
|
return bbox;
|
|
|
|
}
|
2011-09-30 09:25:37 +00:00
|
|
|
|
|
|
|
AutoMarkerReferencer markerRef(this, aMarkedFrame);
|
|
|
|
|
2017-08-26 22:58:38 +00:00
|
|
|
SVGMarkerElement* content = static_cast<SVGMarkerElement*>(GetContent());
|
2014-03-05 21:28:12 +00:00
|
|
|
if (!content->HasValidDimensions()) {
|
|
|
|
return bbox;
|
|
|
|
}
|
2011-10-06 19:03:16 +00:00
|
|
|
|
2019-04-10 04:08:14 +00:00
|
|
|
const SVGViewBox viewBox = content->GetViewBox();
|
2011-10-06 19:03:16 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-08 05:17:07 +00:00
|
|
|
mMarkerTM = content->GetMarkerTransform(aStrokeWidth, aMark);
|
2013-12-30 06:50:17 +00:00
|
|
|
Matrix viewBoxTM = content->GetViewBoxTransform();
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2017-06-08 05:17:07 +00:00
|
|
|
Matrix tm = viewBoxTM * mMarkerTM * aToBBoxUserspace;
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2017-02-09 18:24:31 +00:00
|
|
|
nsSVGDisplayableFrame* child = do_QueryFrame(GetAnonymousChildFrame(this));
|
2013-09-16 05:06:29 +00: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 09:25:37 +00:00
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
2017-10-10 06:58:34 +00:00
|
|
|
void nsSVGMarkerFrame::SetParentCoordCtxProvider(SVGViewportElement* aContext) {
|
2017-08-26 22:58:38 +00:00
|
|
|
SVGMarkerElement* marker = static_cast<SVGMarkerElement*>(GetContent());
|
2006-12-07 09:32:13 +00:00
|
|
|
marker->SetParentCoordCtxProvider(aContext);
|
|
|
|
}
|
|
|
|
|
2017-06-16 09:22:33 +00:00
|
|
|
void nsSVGMarkerFrame::AppendDirectlyOwnedAnonBoxes(
|
|
|
|
nsTArray<OwnedAnonBox>& aResult) {
|
|
|
|
aResult.AppendElement(OwnedAnonBox(GetAnonymousChildFrame(this)));
|
2017-03-15 18:00:44 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 09:32:13 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper class
|
|
|
|
|
|
|
|
nsSVGMarkerFrame::AutoMarkerReferencer::AutoMarkerReferencer(
|
|
|
|
nsSVGMarkerFrame* aFrame,
|
2013-12-26 18:49:49 +00:00
|
|
|
SVGGeometryFrame* 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;
|
|
|
|
|
2017-10-10 06:58:34 +00:00
|
|
|
SVGViewportElement* ctx =
|
2018-12-21 08:58:14 +00:00
|
|
|
static_cast<SVGElement*>(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
|
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
nsContainerFrame* NS_NewSVGMarkerAnonChildFrame(PresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 16:45:54 +00:00
|
|
|
return new (aPresShell)
|
|
|
|
nsSVGMarkerAnonChildFrame(aStyle, aPresShell->GetPresContext());
|
2013-09-16 05:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGMarkerAnonChildFrame)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
void nsSVGMarkerAnonChildFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2017-04-30 15:30:08 +00:00
|
|
|
MOZ_ASSERT(aParent->IsSVGMarkerFrame(), "Unexpected parent");
|
2016-04-18 07:28:03 +00:00
|
|
|
nsSVGDisplayContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2013-09-16 05:06:29 +00:00
|
|
|
}
|
|
|
|
#endif
|