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.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
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 : #ifndef nsIDocumentObserver_h___
38 : #define nsIDocumentObserver_h___
39 :
40 : #include "nsISupports.h"
41 : #include "nsIMutationObserver.h"
42 : #include "nsEventStates.h"
43 :
44 : class nsIAtom;
45 : class nsIContent;
46 : class nsIStyleSheet;
47 : class nsIStyleRule;
48 : class nsString;
49 : class nsIDocument;
50 :
51 : #define NS_IDOCUMENT_OBSERVER_IID \
52 : { 0x900bc4bc, 0x8b6c, 0x4cba, \
53 : { 0x82, 0xfa, 0x56, 0x8a, 0x80, 0xff, 0xfd, 0x3e } }
54 :
55 : typedef PRUint32 nsUpdateType;
56 :
57 : #define UPDATE_CONTENT_MODEL 0x00000001
58 : #define UPDATE_STYLE 0x00000002
59 : #define UPDATE_ALL (UPDATE_CONTENT_MODEL | UPDATE_STYLE)
60 :
61 : // Document observer interface
62 : class nsIDocumentObserver : public nsIMutationObserver
63 1051 : {
64 : public:
65 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_OBSERVER_IID)
66 :
67 : /**
68 : * Notify that a content model update is beginning. This call can be
69 : * nested.
70 : */
71 : virtual void BeginUpdate(nsIDocument *aDocument,
72 : nsUpdateType aUpdateType) = 0;
73 :
74 : /**
75 : * Notify that a content model update is finished. This call can be
76 : * nested.
77 : */
78 : virtual void EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType) = 0;
79 :
80 : /**
81 : * Notify the observer that a document load is beginning.
82 : */
83 : virtual void BeginLoad(nsIDocument *aDocument) = 0;
84 :
85 : /**
86 : * Notify the observer that a document load has finished. Note that
87 : * the associated reflow of the document will be done <b>before</b>
88 : * EndLoad is invoked, not after.
89 : */
90 : virtual void EndLoad(nsIDocument *aDocument) = 0;
91 :
92 : /**
93 : * Notification that the state of a content node has changed.
94 : * (ie: gained or lost focus, became active or hovered over)
95 : * This method is called automatically by content objects
96 : * when their state is changed (therefore there is normally
97 : * no need to invoke this method directly). The notification
98 : * is passed to any IDocumentObservers. The notification is
99 : * passed on to all of the document observers. <p>
100 : *
101 : * This notification is not sent when a piece of content is
102 : * added/removed from the document or the content itself changed
103 : * (the other notifications are used for that).
104 : *
105 : * @param aDocument The document being observed
106 : * @param aContent the piece of content that changed
107 : */
108 : virtual void ContentStateChanged(nsIDocument* aDocument,
109 : nsIContent* aContent,
110 : nsEventStates aStateMask) = 0;
111 :
112 : /**
113 : * Notification that the state of the document has changed.
114 : *
115 : * @param aDocument The document being observed
116 : * @param aStateMask the state that changed
117 : */
118 : virtual void DocumentStatesChanged(nsIDocument* aDocument,
119 : nsEventStates aStateMask) = 0;
120 :
121 : /**
122 : * A StyleSheet has just been added to the document. This method is
123 : * called automatically when a StyleSheet gets added to the
124 : * document, even if the stylesheet is not applicable. The
125 : * notification is passed on to all of the document observers.
126 : *
127 : * @param aDocument The document being observed
128 : * @param aStyleSheet the StyleSheet that has been added
129 : * @param aDocumentSheet True if sheet is in document's style sheet list,
130 : * false if sheet is not (i.e., UA or user sheet)
131 : */
132 : virtual void StyleSheetAdded(nsIDocument *aDocument,
133 : nsIStyleSheet* aStyleSheet,
134 : bool aDocumentSheet) = 0;
135 :
136 : /**
137 : * A StyleSheet has just been removed from the document. This
138 : * method is called automatically when a StyleSheet gets removed
139 : * from the document, even if the stylesheet is not applicable. The
140 : * notification is passed on to all of the document observers.
141 : *
142 : * @param aDocument The document being observed
143 : * @param aStyleSheet the StyleSheet that has been removed
144 : * @param aDocumentSheet True if sheet is in document's style sheet list,
145 : * false if sheet is not (i.e., UA or user sheet)
146 : */
147 : virtual void StyleSheetRemoved(nsIDocument *aDocument,
148 : nsIStyleSheet* aStyleSheet,
149 : bool aDocumentSheet) = 0;
150 :
151 : /**
152 : * A StyleSheet has just changed its applicable state.
153 : * This method is called automatically when the applicable state
154 : * of a StyleSheet gets changed. The style sheet passes this
155 : * notification to the document. The notification is passed on
156 : * to all of the document observers.
157 : *
158 : * @param aDocument The document being observed
159 : * @param aStyleSheet the StyleSheet that has changed state
160 : * @param aApplicable true if the sheet is applicable, false if
161 : * it is not applicable
162 : */
163 : virtual void StyleSheetApplicableStateChanged(nsIDocument *aDocument,
164 : nsIStyleSheet* aStyleSheet,
165 : bool aApplicable) = 0;
166 :
167 : /**
168 : * A StyleRule has just been modified within a style sheet.
169 : * This method is called automatically when the rule gets
170 : * modified. The style sheet passes this notification to
171 : * the document. The notification is passed on to all of
172 : * the document observers.
173 : *
174 : * Since nsIStyleRule objects are immutable, there is a new object
175 : * replacing the old one. However, the use of this method (rather
176 : * than StyleRuleAdded and StyleRuleRemoved) implies that the new rule
177 : * matches the same elements and has the same priority (weight,
178 : * origin, specificity) as the old one. (However, if it is a CSS
179 : * style rule, there may be a change in whether it has an important
180 : * rule.)
181 : *
182 : * @param aDocument The document being observed
183 : * @param aStyleSheet the StyleSheet that contians the rule
184 : * @param aOldStyleRule The rule being removed. This rule may not be
185 : * fully valid anymore -- however, it can still
186 : * be used for pointer comparison and
187 : * |QueryInterface|.
188 : * @param aNewStyleRule The rule being added.
189 : */
190 : virtual void StyleRuleChanged(nsIDocument *aDocument,
191 : nsIStyleSheet* aStyleSheet,
192 : nsIStyleRule* aOldStyleRule,
193 : nsIStyleRule* aNewStyleRule) = 0;
194 :
195 : /**
196 : * A StyleRule has just been added to a style sheet.
197 : * This method is called automatically when the rule gets
198 : * added to the sheet. The style sheet passes this
199 : * notification to the document. The notification is passed on
200 : * to all of the document observers.
201 : *
202 : * @param aDocument The document being observed
203 : * @param aStyleSheet the StyleSheet that has been modified
204 : * @param aStyleRule the rule that was added
205 : */
206 : virtual void StyleRuleAdded(nsIDocument *aDocument,
207 : nsIStyleSheet* aStyleSheet,
208 : nsIStyleRule* aStyleRule) = 0;
209 :
210 : /**
211 : * A StyleRule has just been removed from a style sheet.
212 : * This method is called automatically when the rule gets
213 : * removed from the sheet. The style sheet passes this
214 : * notification to the document. The notification is passed on
215 : * to all of the document observers.
216 : *
217 : * @param aDocument The document being observed
218 : * @param aStyleSheet the StyleSheet that has been modified
219 : * @param aStyleRule the rule that was removed
220 : */
221 : virtual void StyleRuleRemoved(nsIDocument *aDocument,
222 : nsIStyleSheet* aStyleSheet,
223 : nsIStyleRule* aStyleRule) = 0;
224 : };
225 :
226 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID)
227 :
228 : #define NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \
229 : virtual void BeginUpdate(nsIDocument* aDocument, \
230 : nsUpdateType aUpdateType);
231 :
232 : #define NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \
233 : virtual void EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType);
234 :
235 : #define NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \
236 : virtual void BeginLoad(nsIDocument* aDocument);
237 :
238 : #define NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \
239 : virtual void EndLoad(nsIDocument* aDocument);
240 :
241 : #define NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \
242 : virtual void ContentStateChanged(nsIDocument* aDocument, \
243 : nsIContent* aContent, \
244 : nsEventStates aStateMask);
245 :
246 : #define NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \
247 : virtual void DocumentStatesChanged(nsIDocument* aDocument, \
248 : nsEventStates aStateMask);
249 :
250 : #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \
251 : virtual void StyleSheetAdded(nsIDocument* aDocument, \
252 : nsIStyleSheet* aStyleSheet, \
253 : bool aDocumentSheet);
254 :
255 : #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \
256 : virtual void StyleSheetRemoved(nsIDocument* aDocument, \
257 : nsIStyleSheet* aStyleSheet, \
258 : bool aDocumentSheet);
259 :
260 : #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \
261 : virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument, \
262 : nsIStyleSheet* aStyleSheet,\
263 : bool aApplicable);
264 :
265 : #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \
266 : virtual void StyleRuleChanged(nsIDocument* aDocument, \
267 : nsIStyleSheet* aStyleSheet, \
268 : nsIStyleRule* aOldStyleRule, \
269 : nsIStyleRule* aNewStyleRule);
270 :
271 : #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \
272 : virtual void StyleRuleAdded(nsIDocument* aDocument, \
273 : nsIStyleSheet* aStyleSheet, \
274 : nsIStyleRule* aStyleRule);
275 :
276 : #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \
277 : virtual void StyleRuleRemoved(nsIDocument* aDocument, \
278 : nsIStyleSheet* aStyleSheet, \
279 : nsIStyleRule* aStyleRule);
280 :
281 : #define NS_DECL_NSIDOCUMENTOBSERVER \
282 : NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \
283 : NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \
284 : NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \
285 : NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \
286 : NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \
287 : NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \
288 : NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \
289 : NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \
290 : NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \
291 : NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \
292 : NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \
293 : NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \
294 : NS_DECL_NSIMUTATIONOBSERVER
295 :
296 :
297 : #define NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(_class) \
298 : void \
299 : _class::BeginUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \
300 : { \
301 : } \
302 : void \
303 : _class::EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \
304 : { \
305 : } \
306 : NS_IMPL_NSIMUTATIONOBSERVER_CORE_STUB(_class)
307 :
308 : #define NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(_class) \
309 : void \
310 : _class::BeginLoad(nsIDocument* aDocument) \
311 : { \
312 : } \
313 : void \
314 : _class::EndLoad(nsIDocument* aDocument) \
315 : { \
316 : }
317 :
318 : #define NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(_class) \
319 : void \
320 : _class::ContentStateChanged(nsIDocument* aDocument, \
321 : nsIContent* aContent, \
322 : nsEventStates aStateMask) \
323 : { \
324 : } \
325 : \
326 : void \
327 : _class::DocumentStatesChanged(nsIDocument* aDocument, \
328 : nsEventStates aStateMask) \
329 : { \
330 : }
331 :
332 : #define NS_IMPL_NSIDOCUMENTOBSERVER_CONTENT(_class) \
333 : NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class)
334 :
335 : #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \
336 : void \
337 : _class::StyleSheetAdded(nsIDocument* aDocument, \
338 : nsIStyleSheet* aStyleSheet, \
339 : bool aDocumentSheet) \
340 : { \
341 : } \
342 : void \
343 : _class::StyleSheetRemoved(nsIDocument* aDocument, \
344 : nsIStyleSheet* aStyleSheet, \
345 : bool aDocumentSheet) \
346 : { \
347 : } \
348 : void \
349 : _class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \
350 : nsIStyleSheet* aStyleSheet, \
351 : bool aApplicable) \
352 : { \
353 : } \
354 : void \
355 : _class::StyleRuleChanged(nsIDocument* aDocument, \
356 : nsIStyleSheet* aStyleSheet, \
357 : nsIStyleRule* aOldStyleRule, \
358 : nsIStyleRule* aNewStyleRule) \
359 : { \
360 : } \
361 : void \
362 : _class::StyleRuleAdded(nsIDocument* aDocument, \
363 : nsIStyleSheet* aStyleSheet, \
364 : nsIStyleRule* aStyleRule) \
365 : { \
366 : } \
367 : void \
368 : _class::StyleRuleRemoved(nsIDocument* aDocument, \
369 : nsIStyleSheet* aStyleSheet, \
370 : nsIStyleRule* aStyleRule) \
371 : { \
372 : }
373 :
374 : #endif /* nsIDocumentObserver_h___ */
|