michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Keep in (case-insensitive) order: michael@0: #include "gfxMatrix.h" michael@0: #include "mozilla/dom/SVGAElement.h" michael@0: #include "nsSVGContainerFrame.h" michael@0: #include "nsSVGIntegrationUtils.h" michael@0: #include "nsSVGUtils.h" michael@0: #include "SVGLengthList.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: typedef nsSVGDisplayContainerFrame nsSVGAFrameBase; michael@0: michael@0: class nsSVGAFrame : public nsSVGAFrameBase michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: protected: michael@0: nsSVGAFrame(nsStyleContext* aContext) : michael@0: nsSVGAFrameBase(aContext) {} michael@0: michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: #ifdef DEBUG michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: // nsIFrame: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::svgAFrame michael@0: */ michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult); michael@0: } michael@0: #endif michael@0: // nsISVGChildFrame interface: michael@0: virtual void NotifySVGChanged(uint32_t aFlags) MOZ_OVERRIDE; michael@0: michael@0: // nsSVGContainerFrame methods: michael@0: virtual gfxMatrix GetCanvasTM(uint32_t aFor, michael@0: nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: nsAutoPtr mCanvasTM; michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Implementation michael@0: michael@0: nsIFrame* michael@0: NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsSVGAFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame) michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsIFrame methods michael@0: #ifdef DEBUG michael@0: void michael@0: nsSVGAFrame::Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) michael@0: { michael@0: NS_ASSERTION(aContent->IsSVG(nsGkAtoms::a), michael@0: "Trying to construct an SVGAFrame for a " michael@0: "content element that doesn't support the right interfaces"); michael@0: michael@0: nsSVGAFrameBase::Init(aContent, aParent, aPrevInFlow); michael@0: } michael@0: #endif /* DEBUG */ michael@0: michael@0: nsresult michael@0: nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) michael@0: { michael@0: if (aNameSpaceID == kNameSpaceID_None && michael@0: aAttribute == nsGkAtoms::transform) { michael@0: // We don't invalidate for transform changes (the layers code does that). michael@0: // Also note that SVGTransformableElement::GetAttributeChangeHint will michael@0: // return nsChangeHint_UpdateOverflow for "transform" attribute changes michael@0: // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call. michael@0: NotifySVGChanged(TRANSFORM_CHANGED); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsIAtom * michael@0: nsSVGAFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::svgAFrame; michael@0: } michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsISVGChildFrame methods michael@0: michael@0: void michael@0: nsSVGAFrame::NotifySVGChanged(uint32_t aFlags) michael@0: { michael@0: NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED), michael@0: "Invalidation logic may need adjusting"); michael@0: michael@0: if (aFlags & TRANSFORM_CHANGED) { michael@0: // make sure our cached transform matrix gets (lazily) updated michael@0: mCanvasTM = nullptr; michael@0: } michael@0: michael@0: nsSVGAFrameBase::NotifySVGChanged(aFlags); michael@0: } michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsSVGContainerFrame methods: michael@0: michael@0: gfxMatrix michael@0: nsSVGAFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot) michael@0: { michael@0: if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) { michael@0: if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) || michael@0: (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) { michael@0: return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this); michael@0: } michael@0: } michael@0: if (!mCanvasTM) { michael@0: NS_ASSERTION(mParent, "null parent"); michael@0: michael@0: nsSVGContainerFrame *parent = static_cast(mParent); michael@0: dom::SVGAElement *content = static_cast(mContent); michael@0: michael@0: gfxMatrix tm = content->PrependLocalTransformsTo( michael@0: this == aTransformRoot ? gfxMatrix() : michael@0: parent->GetCanvasTM(aFor, aTransformRoot)); michael@0: michael@0: mCanvasTM = new gfxMatrix(tm); michael@0: } michael@0: michael@0: return *mCanvasTM; michael@0: }