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 Mozilla SVG Project code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Jonathan Watt.
19 : * Portions created by the Initial Developer are Copyright (C) 2004
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Jonathan Watt <jonathan.watt@strath.ac.uk> (original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsSVGStylableElement.h"
40 : #include "nsIDOMSVGTitleElement.h"
41 :
42 : typedef nsSVGStylableElement nsSVGTitleElementBase;
43 :
44 : class nsSVGTitleElement : public nsSVGTitleElementBase,
45 : public nsIDOMSVGTitleElement,
46 : public nsStubMutationObserver
47 0 : {
48 : protected:
49 : friend nsresult NS_NewSVGTitleElement(nsIContent **aResult,
50 : already_AddRefed<nsINodeInfo> aNodeInfo);
51 : nsSVGTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
52 : nsresult Init();
53 :
54 : public:
55 : // interfaces:
56 :
57 : NS_DECL_ISUPPORTS_INHERITED
58 : NS_DECL_NSIDOMSVGTITLEELEMENT
59 :
60 : // xxx I wish we could use virtual inheritance
61 0 : NS_FORWARD_NSIDOMNODE(nsSVGTitleElementBase::)
62 0 : NS_FORWARD_NSIDOMELEMENT(nsSVGTitleElementBase::)
63 0 : NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTitleElementBase::)
64 :
65 : // nsIMutationObserver
66 : NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
67 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
68 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
69 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
70 :
71 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
72 :
73 : virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
74 : nsIContent *aBindingParent,
75 : bool aCompileEventHandlers);
76 :
77 : virtual void UnbindFromTree(bool aDeep = true,
78 : bool aNullParent = true);
79 :
80 : virtual void DoneAddingChildren(bool aHaveNotified);
81 :
82 : virtual nsXPCClassInfo* GetClassInfo();
83 : private:
84 : void SendTitleChangeEvent(bool aBound);
85 : };
86 :
87 0 : NS_IMPL_NS_NEW_SVG_ELEMENT(Title)
88 :
89 :
90 : //----------------------------------------------------------------------
91 : // nsISupports methods
92 :
93 0 : NS_IMPL_ADDREF_INHERITED(nsSVGTitleElement, nsSVGTitleElementBase)
94 0 : NS_IMPL_RELEASE_INHERITED(nsSVGTitleElement, nsSVGTitleElementBase)
95 :
96 0 : DOMCI_NODE_DATA(SVGTitleElement, nsSVGTitleElement)
97 :
98 0 : NS_INTERFACE_TABLE_HEAD(nsSVGTitleElement)
99 0 : NS_NODE_INTERFACE_TABLE5(nsSVGTitleElement, nsIDOMNode, nsIDOMElement,
100 : nsIDOMSVGElement, nsIDOMSVGTitleElement,
101 : nsIMutationObserver)
102 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGTitleElement)
103 0 : NS_INTERFACE_MAP_END_INHERITING(nsSVGTitleElementBase)
104 :
105 :
106 : //----------------------------------------------------------------------
107 : // Implementation
108 :
109 0 : nsSVGTitleElement::nsSVGTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
110 0 : : nsSVGTitleElementBase(aNodeInfo)
111 : {
112 0 : AddMutationObserver(this);
113 0 : }
114 :
115 : nsresult
116 0 : nsSVGTitleElement::Init()
117 : {
118 0 : return nsSVGTitleElementBase::Init();
119 : }
120 :
121 : void
122 0 : nsSVGTitleElement::CharacterDataChanged(nsIDocument *aDocument,
123 : nsIContent *aContent,
124 : CharacterDataChangeInfo *aInfo)
125 : {
126 0 : SendTitleChangeEvent(false);
127 0 : }
128 :
129 : void
130 0 : nsSVGTitleElement::ContentAppended(nsIDocument *aDocument,
131 : nsIContent *aContainer,
132 : nsIContent *aFirstNewContent,
133 : PRInt32 aNewIndexInContainer)
134 : {
135 0 : SendTitleChangeEvent(false);
136 0 : }
137 :
138 : void
139 0 : nsSVGTitleElement::ContentInserted(nsIDocument *aDocument,
140 : nsIContent *aContainer,
141 : nsIContent *aChild,
142 : PRInt32 aIndexInContainer)
143 : {
144 0 : SendTitleChangeEvent(false);
145 0 : }
146 :
147 : void
148 0 : nsSVGTitleElement::ContentRemoved(nsIDocument *aDocument,
149 : nsIContent *aContainer,
150 : nsIContent *aChild,
151 : PRInt32 aIndexInContainer,
152 : nsIContent *aPreviousSibling)
153 : {
154 0 : SendTitleChangeEvent(false);
155 0 : }
156 :
157 : nsresult
158 0 : nsSVGTitleElement::BindToTree(nsIDocument *aDocument,
159 : nsIContent *aParent,
160 : nsIContent *aBindingParent,
161 : bool aCompileEventHandlers)
162 : {
163 : // Let this fall through.
164 : nsresult rv = nsSVGTitleElementBase::BindToTree(aDocument, aParent,
165 : aBindingParent,
166 0 : aCompileEventHandlers);
167 0 : NS_ENSURE_SUCCESS(rv, rv);
168 :
169 0 : SendTitleChangeEvent(true);
170 :
171 0 : return NS_OK;
172 : }
173 :
174 : void
175 0 : nsSVGTitleElement::UnbindFromTree(bool aDeep, bool aNullParent)
176 : {
177 0 : SendTitleChangeEvent(false);
178 :
179 : // Let this fall through.
180 0 : nsSVGTitleElementBase::UnbindFromTree(aDeep, aNullParent);
181 0 : }
182 :
183 : void
184 0 : nsSVGTitleElement::DoneAddingChildren(bool aHaveNotified)
185 : {
186 0 : if (!aHaveNotified) {
187 0 : SendTitleChangeEvent(false);
188 : }
189 0 : }
190 :
191 : void
192 0 : nsSVGTitleElement::SendTitleChangeEvent(bool aBound)
193 : {
194 0 : nsIDocument* doc = GetCurrentDoc();
195 0 : if (doc) {
196 0 : doc->NotifyPossibleTitleChange(aBound);
197 : }
198 0 : }
199 :
200 : //----------------------------------------------------------------------
201 : // nsIDOMNode methods
202 :
203 0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGTitleElement)
|