1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Daniel Holbert <dholbert@mozilla.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef NS_SVGMPATHELEMENT_H_
39 : #define NS_SVGMPATHELEMENT_H_
40 :
41 : #include "nsIDOMSVGMpathElement.h"
42 : #include "nsIDOMSVGURIReference.h"
43 : #include "nsSVGElement.h"
44 : #include "nsStubMutationObserver.h"
45 : #include "nsSVGPathElement.h"
46 : #include "nsSVGString.h"
47 : #include "nsReferencedElement.h"
48 :
49 :
50 : typedef nsSVGElement nsSVGMpathElementBase;
51 :
52 : class nsSVGMpathElement : public nsSVGMpathElementBase,
53 : public nsIDOMSVGMpathElement,
54 : public nsIDOMSVGURIReference,
55 : public nsStubMutationObserver
56 : {
57 : protected:
58 : friend nsresult NS_NewSVGMpathElement(nsIContent **aResult,
59 : already_AddRefed<nsINodeInfo> aNodeInfo);
60 : nsSVGMpathElement(already_AddRefed<nsINodeInfo> aNodeInfo);
61 : ~nsSVGMpathElement();
62 :
63 :
64 : public:
65 : // interfaces:
66 : NS_DECL_ISUPPORTS_INHERITED
67 : NS_DECL_NSIDOMSVGMPATHELEMENT
68 : NS_DECL_NSIDOMSVGURIREFERENCE
69 :
70 1464 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSVGMpathElement,
71 : nsSVGMpathElementBase)
72 :
73 : NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
74 :
75 : // Forward interface implementations to base class
76 0 : NS_FORWARD_NSIDOMNODE(nsSVGMpathElementBase::)
77 0 : NS_FORWARD_NSIDOMELEMENT(nsSVGMpathElementBase::)
78 0 : NS_FORWARD_NSIDOMSVGELEMENT(nsSVGMpathElementBase::)
79 :
80 : // nsIContent interface
81 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
82 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
83 : nsIContent* aBindingParent,
84 : bool aCompileEventHandlers);
85 : virtual void UnbindFromTree(bool aDeep, bool aNullParent);
86 :
87 : virtual nsresult UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aAttribute,
88 : bool aNotify);
89 : // nsGenericElement specializations
90 : virtual bool ParseAttribute(PRInt32 aNamespaceID,
91 : nsIAtom* aAttribute,
92 : const nsAString& aValue,
93 : nsAttrValue& aResult);
94 :
95 : // Public helper method: If our xlink:href attribute links to a <path>
96 : // element, this method returns a pointer to that element. Otherwise,
97 : // this returns nsnull.
98 : nsSVGPathElement* GetReferencedPath();
99 :
100 : virtual nsXPCClassInfo* GetClassInfo();
101 : protected:
102 0 : class PathReference : public nsReferencedElement {
103 : public:
104 0 : PathReference(nsSVGMpathElement* aMpathElement) :
105 0 : mMpathElement(aMpathElement) {}
106 : protected:
107 : // We need to be notified when target changes, in order to request a sample
108 : // (which will clear animation effects that used the old target-path
109 : // and recompute the animation effects using the new target-path).
110 0 : virtual void ElementChanged(Element* aFrom, Element* aTo) {
111 0 : nsReferencedElement::ElementChanged(aFrom, aTo);
112 0 : if (aFrom) {
113 0 : aFrom->RemoveMutationObserver(mMpathElement);
114 : }
115 0 : if (aTo) {
116 0 : aTo->AddMutationObserver(mMpathElement);
117 : }
118 0 : mMpathElement->NotifyParentOfMpathChange(mMpathElement->GetParent());
119 0 : }
120 :
121 : // We need to override IsPersistent to get persistent tracking (beyond the
122 : // first time the target changes)
123 0 : virtual bool IsPersistent() { return true; }
124 : private:
125 : nsSVGMpathElement* const mMpathElement;
126 : };
127 :
128 : virtual StringAttributesInfo GetStringInfo();
129 :
130 : void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
131 : void UnlinkHrefTarget(bool aNotifyParent);
132 : void NotifyParentOfMpathChange(nsIContent* aParent);
133 :
134 : enum { HREF };
135 : nsSVGString mStringAttributes[1];
136 : static StringInfo sStringInfo[1];
137 : PathReference mHrefTarget;
138 : };
139 :
140 : #endif // NS_SVGMPATHELEMENT_H_
|