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/. */
7 #include "SVGTransformableElement.h"
9 #include "DOMSVGAnimatedTransformList.h"
10 #include "mozilla/dom/MutationEventBinding.h"
11 #include "nsContentUtils.h"
14 using namespace mozilla::gfx
;
16 namespace mozilla::dom
{
18 already_AddRefed
<DOMSVGAnimatedTransformList
>
19 SVGTransformableElement::Transform() {
20 // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
21 // to allocate the DOMSVGAnimatedTransformList if it hasn't already done so:
22 return DOMSVGAnimatedTransformList::GetDOMWrapper(
23 GetAnimatedTransformList(DO_ALLOCATE
), this);
26 //----------------------------------------------------------------------
29 bool SVGTransformableElement::IsAttributeMapped(
30 const nsAtom
* aAttribute
) const {
31 return aAttribute
== nsGkAtoms::transform
||
32 SVGElement::IsAttributeMapped(aAttribute
);
35 bool SVGTransformableElement::IsEventAttributeNameInternal(nsAtom
* aName
) {
36 return nsContentUtils::IsEventAttributeName(aName
, EventNameType_SVGGraphic
);
39 //----------------------------------------------------------------------
40 // SVGElement overrides
42 const gfx::Matrix
* SVGTransformableElement::GetAnimateMotionTransform() const {
43 return mAnimateMotionTransform
.get();
46 void SVGTransformableElement::SetAnimateMotionTransform(
47 const gfx::Matrix
* aMatrix
) {
48 if ((!aMatrix
&& !mAnimateMotionTransform
) ||
49 (aMatrix
&& mAnimateMotionTransform
&&
50 aMatrix
->FuzzyEquals(*mAnimateMotionTransform
))) {
53 bool transformSet
= mTransforms
&& mTransforms
->IsExplicitlySet();
54 bool prevSet
= mAnimateMotionTransform
|| transformSet
;
55 mAnimateMotionTransform
=
56 aMatrix
? MakeUnique
<gfx::Matrix
>(*aMatrix
) : nullptr;
57 bool nowSet
= mAnimateMotionTransform
|| transformSet
;
59 if (prevSet
&& !nowSet
) {
60 modType
= MutationEvent_Binding::REMOVAL
;
61 } else if (!prevSet
&& nowSet
) {
62 modType
= MutationEvent_Binding::ADDITION
;
64 modType
= MutationEvent_Binding::MODIFICATION
;
66 DidAnimateTransformList(modType
);
67 nsIFrame
* frame
= GetPrimaryFrame();
69 // If the result of this transform and any other transforms on this frame
70 // is the identity matrix, then DoApplyRenderingChangeToTree won't handle
71 // our nsChangeHint_UpdateTransformLayer hint since aFrame->IsTransformed()
72 // will return false. That's fine, but we still need to schedule a repaint,
73 // and that won't otherwise happen. Since it's cheap to call SchedulePaint,
74 // we don't bother to check IsTransformed().
75 frame
->SchedulePaint();
79 SVGAnimatedTransformList
* SVGTransformableElement::GetAnimatedTransformList(
81 if (!mTransforms
&& (aFlags
& DO_ALLOCATE
)) {
82 mTransforms
= MakeUnique
<SVGAnimatedTransformList
>();
84 return mTransforms
.get();
87 } // namespace mozilla::dom