SVGTransformableElement.cpp (2707B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "SVGTransformableElement.h" 8 9 #include "DOMSVGAnimatedTransformList.h" 10 #include "nsContentUtils.h" 11 #include "nsIFrame.h" 12 13 using namespace mozilla::gfx; 14 15 namespace mozilla::dom { 16 17 already_AddRefed<DOMSVGAnimatedTransformList> 18 SVGTransformableElement::Transform() { 19 // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList 20 // to allocate the DOMSVGAnimatedTransformList if it hasn't already done so: 21 return DOMSVGAnimatedTransformList::GetDOMWrapper( 22 GetAnimatedTransformList(DO_ALLOCATE), this); 23 } 24 25 //---------------------------------------------------------------------- 26 // nsIContent methods 27 28 bool SVGTransformableElement::IsAttributeMapped( 29 const nsAtom* aAttribute) const { 30 return aAttribute == nsGkAtoms::transform || 31 SVGElement::IsAttributeMapped(aAttribute); 32 } 33 34 bool SVGTransformableElement::IsEventAttributeNameInternal(nsAtom* aName) { 35 return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic); 36 } 37 38 //---------------------------------------------------------------------- 39 // SVGElement overrides 40 41 const gfx::Matrix* SVGTransformableElement::GetAnimateMotionTransform() const { 42 return mAnimateMotionTransform.get(); 43 } 44 45 void SVGTransformableElement::SetAnimateMotionTransform( 46 const gfx::Matrix* aMatrix) { 47 if ((!aMatrix && !mAnimateMotionTransform) || 48 (aMatrix && mAnimateMotionTransform && 49 aMatrix->FuzzyEquals(*mAnimateMotionTransform))) { 50 return; 51 } 52 mAnimateMotionTransform = 53 aMatrix ? MakeUnique<gfx::Matrix>(*aMatrix) : nullptr; 54 DidAnimateTransformList(); 55 nsIFrame* frame = GetPrimaryFrame(); 56 if (frame) { 57 // If the result of this transform and any other transforms on this frame 58 // is the identity matrix, then DoApplyRenderingChangeToTree won't handle 59 // our nsChangeHint_UpdateTransformLayer hint since aFrame->IsTransformed() 60 // will return false. That's fine, but we still need to schedule a repaint, 61 // and that won't otherwise happen. Since it's cheap to call SchedulePaint, 62 // we don't bother to check IsTransformed(). 63 frame->SchedulePaint(); 64 } 65 } 66 67 SVGAnimatedTransformList* SVGTransformableElement::GetAnimatedTransformList( 68 uint32_t aFlags) { 69 if (!mTransforms && (aFlags & DO_ALLOCATE)) { 70 mTransforms = MakeUnique<SVGAnimatedTransformList>(); 71 } 72 return mTransforms.get(); 73 } 74 75 } // namespace mozilla::dom