Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / svg / base / src / nsSVGEffects.h
blob794e97f3c2a1199200d6bc64c3e6db2dd6e59c54
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
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/
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.
15 * The Original Code is the Mozilla SVG project.
17 * The Initial Developer of the Original Code is IBM Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * rocallahan@mozilla.com
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef NSSVGEFFECTS_H_
39 #define NSSVGEFFECTS_H_
41 #include "nsIContent.h"
42 #include "nsIFrame.h"
43 #include "nsReferencedElement.h"
44 #include "nsStubMutationObserver.h"
45 #include "nsSVGUtils.h"
46 #include "nsTHashtable.h"
48 class nsSVGClipPathFrame;
49 class nsSVGFilterFrame;
50 class nsSVGMaskFrame;
53 * SVG elements reference supporting resources by element ID. We need to
54 * track when those resources change and when the DOM changes in ways
55 * that affect which element is referenced by a given ID (e.g., when
56 * element IDs change). The code here is responsible for that.
58 * When a frame references a supporting resource, we create a property
59 * object derived from nsSVGRenderingObserver to manage the relationship. The
60 * property object is attached to the referencing frame.
62 class nsSVGRenderingObserver : public nsStubMutationObserver {
63 public:
64 nsSVGRenderingObserver(nsIURI* aURI, nsIFrame *aFrame);
65 virtual ~nsSVGRenderingObserver();
67 // nsISupports
68 NS_DECL_ISUPPORTS
70 // nsIMutationObserver
71 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
72 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
73 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
74 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
76 void InvalidateViaReferencedFrame();
78 nsIFrame* GetReferencedFrame();
79 /**
80 * @param aOK this is only for the convenience of callers. We set *aOK to false
81 * if this function returns null.
83 nsIFrame* GetReferencedFrame(nsIAtom* aFrameType, PRBool* aOK);
85 protected:
86 // This is called when the referenced resource changes.
87 virtual void DoUpdate();
89 class SourceReference : public nsReferencedElement {
90 public:
91 SourceReference(nsSVGRenderingObserver* aContainer) : mContainer(aContainer) {}
92 protected:
93 virtual void ContentChanged(nsIContent* aFrom, nsIContent* aTo) {
94 if (aFrom) {
95 aFrom->RemoveMutationObserver(mContainer);
97 nsReferencedElement::ContentChanged(aFrom, aTo);
98 if (aTo) {
99 aTo->AddMutationObserver(mContainer);
101 mContainer->DoUpdate();
104 * Override IsPersistent because we want to keep tracking the element
105 * for the ID even when it changes.
107 virtual PRBool IsPersistent() { return PR_TRUE; }
108 private:
109 nsSVGRenderingObserver* mContainer;
112 SourceReference mElement;
113 // The frame that this property is attached to
114 nsIFrame *mFrame;
115 // When a presshell is torn down, we don't delete the properties for
116 // each frame until after the frames are destroyed. So here we remember
117 // the presshell for the frames we care about and, before we use the frame,
118 // we test the presshell to see if it's destroying itself. If it is,
119 // then the frame pointer is not valid and we know the frame has gone away.
120 nsIPresShell *mFramePresShell;
121 nsIFrame *mReferencedFrame;
122 nsIPresShell *mReferencedFramePresShell;
125 class nsSVGFilterProperty :
126 public nsSVGRenderingObserver, public nsISVGFilterProperty {
127 public:
128 nsSVGFilterProperty(nsIURI *aURI, nsIFrame *aFilteredFrame)
129 : nsSVGRenderingObserver(aURI, aFilteredFrame) {}
132 * @return the filter frame, or null if there is no filter frame
134 nsSVGFilterFrame *GetFilterFrame();
136 // nsISupports
137 NS_DECL_ISUPPORTS
139 // nsISVGFilterProperty
140 virtual void Invalidate() { DoUpdate(); }
142 private:
143 // nsSVGRenderingObserver
144 virtual void DoUpdate();
147 class nsSVGMarkerProperty : public nsSVGRenderingObserver {
148 public:
149 nsSVGMarkerProperty(nsIURI *aURI, nsIFrame *aFrame)
150 : nsSVGRenderingObserver(aURI, aFrame) {}
152 protected:
153 virtual void DoUpdate();
156 class nsSVGTextPathProperty : public nsSVGRenderingObserver {
157 public:
158 nsSVGTextPathProperty(nsIURI *aURI, nsIFrame *aFrame)
159 : nsSVGRenderingObserver(aURI, aFrame) {}
161 protected:
162 virtual void DoUpdate();
165 class nsSVGPaintingProperty : public nsSVGRenderingObserver {
166 public:
167 nsSVGPaintingProperty(nsIURI *aURI, nsIFrame *aFrame)
168 : nsSVGRenderingObserver(aURI, aFrame) {}
170 protected:
171 virtual void DoUpdate();
175 * A manager for one-shot nsSVGRenderingObserver tracking.
176 * nsSVGRenderingObservers can be added or removed. They are not strongly
177 * referenced so an observer must be removed before it before it dies.
178 * When InvalidateAll is called, all outstanding references get
179 * InvalidateViaReferencedFrame()
180 * called on them and the list is cleared. The intent is that
181 * the observer will force repainting of whatever part of the document
182 * is needed, and then at paint time the observer will be re-added.
184 * InvalidateAll must be called before this object is destroyed, i.e.
185 * before the referenced frame is destroyed. This should normally happen
186 * via nsSVGContainerFrame::RemoveFrame, since only frames in the frame
187 * tree should be referenced.
189 class nsSVGRenderingObserverList {
190 public:
191 nsSVGRenderingObserverList() { mObservers.Init(5); }
192 ~nsSVGRenderingObserverList() { InvalidateAll(); }
194 void Add(nsSVGRenderingObserver* aObserver)
195 { mObservers.PutEntry(aObserver); }
196 void Remove(nsSVGRenderingObserver* aObserver)
197 { mObservers.RemoveEntry(aObserver); }
198 void InvalidateAll();
200 private:
201 nsTHashtable<nsVoidPtrHashKey> mObservers;
204 class nsSVGEffects {
205 public:
206 struct EffectProperties {
207 nsSVGFilterProperty* mFilter;
208 nsSVGPaintingProperty* mMask;
209 nsSVGPaintingProperty* mClipPath;
212 * @return the clip-path frame, or null if there is no clip-path frame
213 * @param aOK if a clip-path was specified but the designated element
214 * does not exist or is an element of the wrong type, *aOK is set
215 * to false. Otherwise *aOK is untouched.
217 nsSVGClipPathFrame *GetClipPathFrame(PRBool *aOK);
219 * @return the mask frame, or null if there is no mask frame
220 * @param aOK if a mask was specified but the designated element
221 * does not exist or is an element of the wrong type, *aOK is set
222 * to false. Otherwise *aOK is untouched.
224 nsSVGMaskFrame *GetMaskFrame(PRBool *aOK);
226 * @return the filter frame, or null if there is no filter frame
227 * @param aOK if a filter was specified but the designated element
228 * does not exist or is an element of the wrong type, *aOK is set
229 * to false. Otherwise *aOK is untouched.
231 nsSVGFilterFrame *GetFilterFrame(PRBool *aOK) {
232 if (!mFilter)
233 return nsnull;
234 nsSVGFilterFrame *filter = mFilter->GetFilterFrame();
235 if (!filter) {
236 *aOK = PR_FALSE;
238 return filter;
243 * @param aFrame should be the first continuation
245 static EffectProperties GetEffectProperties(nsIFrame *aFrame);
247 * Called by nsCSSFrameConstructor when style changes require the
248 * effect properties on aFrame to be updated
250 static void UpdateEffects(nsIFrame *aFrame);
252 * @param aFrame should be the first continuation
254 static nsSVGFilterProperty *GetFilterProperty(nsIFrame *aFrame);
255 static nsSVGFilterFrame *GetFilterFrame(nsIFrame *aFrame) {
256 nsSVGFilterProperty *prop = GetFilterProperty(aFrame);
257 return prop ? prop->GetFilterFrame() : nsnull;
261 * @param aFrame must be a first-continuation.
263 static void AddRenderingObserver(nsIFrame *aFrame, nsSVGRenderingObserver *aObserver);
265 * @param aFrame must be a first-continuation.
267 static void RemoveRenderingObserver(nsIFrame *aFrame, nsSVGRenderingObserver *aObserver);
269 * This can be called on any first-continuation frame. We walk up to
270 * the nearest observable frame and invalidate its observers.
272 static void InvalidateRenderingObservers(nsIFrame *aFrame);
274 * This can be called on any frame. Direct observers
275 * of this frame are all invalidated.
277 static void InvalidateDirectRenderingObservers(nsIFrame *aFrame);
280 * Get an nsSVGMarkerProperty for the frame, creating a fresh one if necessary
282 static nsSVGMarkerProperty *
283 GetMarkerProperty(nsIURI *aURI, nsIFrame *aFrame, nsIAtom *aProp);
285 * Get an nsSVGTextPathProperty for the frame, creating a fresh one if necessary
287 static nsSVGTextPathProperty *
288 GetTextPathProperty(nsIURI *aURI, nsIFrame *aFrame, nsIAtom *aProp);
290 * Get an nsSVGPaintingProperty for the frame, creating a fresh one if necessary
292 static nsSVGPaintingProperty *
293 GetPaintingProperty(nsIURI *aURI, nsIFrame *aFrame, nsIAtom *aProp);
296 #endif /*NSSVGEFFECTS_H_*/