1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/nsSVGGFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// Main header first: 1.10 +#include "nsSVGGFrame.h" 1.11 + 1.12 +// Keep others in (case-insensitive) order: 1.13 +#include "nsGkAtoms.h" 1.14 +#include "SVGTransformableElement.h" 1.15 +#include "nsIFrame.h" 1.16 +#include "SVGGraphicsElement.h" 1.17 +#include "nsSVGIntegrationUtils.h" 1.18 +#include "nsSVGUtils.h" 1.19 + 1.20 +using namespace mozilla::dom; 1.21 + 1.22 +//---------------------------------------------------------------------- 1.23 +// Implementation 1.24 + 1.25 +nsIFrame* 1.26 +NS_NewSVGGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.27 +{ 1.28 + return new (aPresShell) nsSVGGFrame(aContext); 1.29 +} 1.30 + 1.31 +NS_IMPL_FRAMEARENA_HELPERS(nsSVGGFrame) 1.32 + 1.33 +#ifdef DEBUG 1.34 +void 1.35 +nsSVGGFrame::Init(nsIContent* aContent, 1.36 + nsIFrame* aParent, 1.37 + nsIFrame* aPrevInFlow) 1.38 +{ 1.39 + NS_ASSERTION(aContent->IsSVG() && 1.40 + static_cast<nsSVGElement*>(aContent)->IsTransformable(), 1.41 + "The element doesn't support nsIDOMSVGTransformable"); 1.42 + 1.43 + nsSVGGFrameBase::Init(aContent, aParent, aPrevInFlow); 1.44 +} 1.45 +#endif /* DEBUG */ 1.46 + 1.47 +nsIAtom * 1.48 +nsSVGGFrame::GetType() const 1.49 +{ 1.50 + return nsGkAtoms::svgGFrame; 1.51 +} 1.52 + 1.53 +//---------------------------------------------------------------------- 1.54 +// nsISVGChildFrame methods 1.55 + 1.56 +void 1.57 +nsSVGGFrame::NotifySVGChanged(uint32_t aFlags) 1.58 +{ 1.59 + NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED), 1.60 + "Invalidation logic may need adjusting"); 1.61 + 1.62 + if (aFlags & TRANSFORM_CHANGED) { 1.63 + // make sure our cached transform matrix gets (lazily) updated 1.64 + mCanvasTM = nullptr; 1.65 + } 1.66 + 1.67 + nsSVGGFrameBase::NotifySVGChanged(aFlags); 1.68 +} 1.69 + 1.70 +gfxMatrix 1.71 +nsSVGGFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot) 1.72 +{ 1.73 + if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) { 1.74 + if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) || 1.75 + (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) { 1.76 + return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this); 1.77 + } 1.78 + } 1.79 + if (!mCanvasTM) { 1.80 + NS_ASSERTION(mParent, "null parent"); 1.81 + 1.82 + nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent); 1.83 + SVGGraphicsElement *content = static_cast<SVGGraphicsElement*>(mContent); 1.84 + gfxMatrix tm = content->PrependLocalTransformsTo( 1.85 + this == aTransformRoot ? gfxMatrix() : 1.86 + parent->GetCanvasTM(aFor, aTransformRoot)); 1.87 + 1.88 + mCanvasTM = new gfxMatrix(tm); 1.89 + } 1.90 + return *mCanvasTM; 1.91 +} 1.92 + 1.93 +nsresult 1.94 +nsSVGGFrame::AttributeChanged(int32_t aNameSpaceID, 1.95 + nsIAtom* aAttribute, 1.96 + int32_t aModType) 1.97 +{ 1.98 + if (aNameSpaceID == kNameSpaceID_None && 1.99 + aAttribute == nsGkAtoms::transform) { 1.100 + // We don't invalidate for transform changes (the layers code does that). 1.101 + // Also note that SVGTransformableElement::GetAttributeChangeHint will 1.102 + // return nsChangeHint_UpdateOverflow for "transform" attribute changes 1.103 + // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call. 1.104 + NotifySVGChanged(TRANSFORM_CHANGED); 1.105 + } 1.106 + 1.107 + return NS_OK; 1.108 +}