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: // Main header first: michael@0: #include "nsSVGGFrame.h" michael@0: michael@0: // Keep others in (case-insensitive) order: michael@0: #include "nsGkAtoms.h" michael@0: #include "SVGTransformableElement.h" michael@0: #include "nsIFrame.h" michael@0: #include "SVGGraphicsElement.h" michael@0: #include "nsSVGIntegrationUtils.h" michael@0: #include "nsSVGUtils.h" michael@0: michael@0: using namespace mozilla::dom; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Implementation michael@0: michael@0: nsIFrame* michael@0: NS_NewSVGGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsSVGGFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsSVGGFrame) michael@0: michael@0: #ifdef DEBUG michael@0: void michael@0: nsSVGGFrame::Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) michael@0: { michael@0: NS_ASSERTION(aContent->IsSVG() && michael@0: static_cast(aContent)->IsTransformable(), michael@0: "The element doesn't support nsIDOMSVGTransformable"); michael@0: michael@0: nsSVGGFrameBase::Init(aContent, aParent, aPrevInFlow); michael@0: } michael@0: #endif /* DEBUG */ michael@0: michael@0: nsIAtom * michael@0: nsSVGGFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::svgGFrame; michael@0: } michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsISVGChildFrame methods michael@0: michael@0: void michael@0: nsSVGGFrame::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: nsSVGGFrameBase::NotifySVGChanged(aFlags); michael@0: } michael@0: michael@0: gfxMatrix michael@0: nsSVGGFrame::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: SVGGraphicsElement *content = static_cast(mContent); 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: return *mCanvasTM; michael@0: } michael@0: michael@0: nsresult michael@0: nsSVGGFrame::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: }